Commit c101051c authored by unknown's avatar unknown

fix for #1344

handling of init-file option added to embedded library
main problem was killing of output (resulting recordsets etc)
i added checks for empty output in Protocol:: methods
better solution could be special Protocol_nul class to redirect
results to nowhere


libmysqld/lib_sql.cc:
  code was added to call read_init_file
  Protocol methods now can support output to nowhere
sql/mysqld.cc:
  bootstrap function extended to work in embedded library
sql/sql_parse.cc:
  handle_bootstrap modified to work in embedded library
parent 1a4637fa
......@@ -389,6 +389,15 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups)
sql_print_error("Warning: Can't create thread to manage maintenance");
}
if (opt_init_file)
{
if (read_init_file(opt_init_file))
{
mysql_server_end();
return 1;
}
}
/*
Update mysqld variables from client variables if set
The client variables are set also by get_one_option() in mysqld.cc
......@@ -516,6 +525,9 @@ bool Protocol::send_fields(List<Item> *list, uint flag)
DBUG_ENTER("send_fields");
if (!mysql) // bootstrap file handling
DBUG_RETURN(0);
field_count= list->elements;
field_alloc= &mysql->field_alloc;
if (!(client_field= thd->mysql->fields=
......@@ -577,6 +589,9 @@ bool Protocol::send_records_num(List<Item> *list, ulonglong records)
bool Protocol::write()
{
if (!thd->mysql) // bootstrap file handling
return false;
*next_field= 0;
return false;
}
......@@ -622,12 +637,12 @@ send_ok(THD *thd,ha_rows affected_rows,ulonglong id,const char *message)
{
DBUG_ENTER("send_ok");
MYSQL *mysql= current_thd->mysql;
if (!mysql) // bootstrap file handling
DBUG_VOID_RETURN;
mysql->affected_rows= affected_rows;
mysql->insert_id= id;
if (message)
{
strmake(thd->net.last_error, message, sizeof(thd->net.last_error)-1);
}
DBUG_VOID_RETURN;
}
......@@ -684,6 +699,9 @@ bool Protocol_simple::store_null()
bool Protocol::net_store_data(const char *from, uint length)
{
char *field_buf;
if (!thd->mysql) // bootstrap file handling
return false;
if (!(field_buf=alloc_root(alloc, length + sizeof(uint) + 1)))
return true;
*(uint *)field_buf= length;
......
......@@ -2769,7 +2769,6 @@ static int bootstrap(FILE *file)
{
int error= 0;
DBUG_ENTER("bootstrap");
#ifndef EMBEDDED_LIBRARY // TODO: Enable this
THD *thd= new THD;
thd->bootstrap=1;
......@@ -2781,6 +2780,7 @@ static int bootstrap(FILE *file)
thread_count++;
bootstrap_file=file;
#ifndef EMBEDDED_LIBRARY // TODO: Enable this
if (pthread_create(&thd->real_id,&connection_attrib,handle_bootstrap,
(void*) thd))
{
......@@ -2795,11 +2795,17 @@ static int bootstrap(FILE *file)
DBUG_PRINT("quit",("One thread died (count=%u)",thread_count));
}
(void) pthread_mutex_unlock(&LOCK_thread_count);
#else
thd->mysql= 0;
handle_bootstrap((void *)thd);
#endif
error= thd->is_fatal_error;
#ifndef EMBEDDED_LIBRARY
net_end(&thd->net);
#endif
thd->cleanup();
delete thd;
#endif /* EMBEDDED_LIBRARY */
DBUG_RETURN(error);
}
......
......@@ -932,6 +932,8 @@ pthread_handler_decl(handle_one_connection,arg)
return(0); /* purecov: deadcode */
}
#endif /* EMBEDDED_LIBRARY */
/*
Execute commands from bootstrap_file.
Used when creating the initial grant tables
......@@ -946,12 +948,15 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg)
/* The following must be called before DBUG_ENTER */
if (my_thread_init() || thd->store_globals())
{
#ifndef EMBEDDED_LIBRARY
close_connection(thd, ER_OUT_OF_RESOURCES, 1);
#endif
thd->fatal_error();
goto end;
}
DBUG_ENTER("handle_bootstrap");
#ifndef EMBEDDED_LIBRARY
pthread_detach_this_thread();
thd->thread_stack= (char*) &thd;
#if !defined(__WIN__) && !defined(OS2) && !defined(__NETWARE__)
......@@ -959,6 +964,7 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg)
VOID(sigemptyset(&set)); // Get mask in use
VOID(pthread_sigmask(SIG_UNBLOCK,&set,&thd->block_signals));
#endif
#endif /* EMBEDDED_LIBRARY */
if (thd->variables.max_join_size == HA_POS_ERROR)
thd->options |= OPTION_BIG_SELECTS;
......@@ -980,6 +986,7 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg)
thd->query= thd->memdup_w_gap(buff, length+1, thd->db_length+1);
thd->query[length] = '\0';
thd->query_id=query_id++;
#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (mqh_used && thd->user_connect && check_mqh(thd, SQLCOM_END))
{
thd->net.error = 0;
......@@ -987,6 +994,7 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg)
free_root(&thd->mem_root,MYF(MY_KEEP_PREALLOC));
break;
}
#endif
mysql_parse(thd,thd->query,length);
close_thread_tables(thd); // Free tables
if (thd->is_fatal_error)
......@@ -997,17 +1005,17 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg)
/* thd->fatal_error should be set in case something went wrong */
end:
#ifndef EMBEDDED_LIBRARY
(void) pthread_mutex_lock(&LOCK_thread_count);
thread_count--;
(void) pthread_mutex_unlock(&LOCK_thread_count);
(void) pthread_cond_broadcast(&COND_thread_count);
my_thread_end();
pthread_exit(0);
#endif
DBUG_RETURN(0); // Never reached
}
#endif /* EMBEDDED_LIBRARY */
/* This works because items are allocated with sql_alloc() */
void free_items(Item *item)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment