Commit 2be6f272 authored by hf@genie.(none)'s avatar hf@genie.(none)

Changes in order to trim embedded library code

parent 55866b06
...@@ -314,6 +314,10 @@ int mysql_rpl_parse_enabled(MYSQL* mysql __attribute__((unused))) { return 1; } ...@@ -314,6 +314,10 @@ int mysql_rpl_parse_enabled(MYSQL* mysql __attribute__((unused))) { return 1; }
my_bool mysql_rpl_probe(MYSQL *mysql __attribute__((unused))) { return 1; } my_bool mysql_rpl_probe(MYSQL *mysql __attribute__((unused))) { return 1; }
#endif #endif
#ifdef EMBEDDED_LIBRARY
#define mysql_send_query mysql_real_query
#endif
#define MAX_SERVER_ARGS 20 #define MAX_SERVER_ARGS 20
static int embedded_server_arg_count=0; static int embedded_server_arg_count=0;
......
...@@ -26,9 +26,9 @@ C_MODE_START ...@@ -26,9 +26,9 @@ C_MODE_START
extern void start_embedded_connection(NET * net); extern void start_embedded_connection(NET * net);
extern void end_embedded_connection(NET * net); extern void end_embedded_connection(NET * net);
extern void lib_connection_phase(NET *net, int phase); extern void lib_connection_phase(NET *net, int phase);
extern bool lib_dispatch_command(enum enum_server_command command, NET *net,
const char *arg, ulong length);
extern void init_embedded_mysql(MYSQL *mysql, int client_flag, char *db); extern void init_embedded_mysql(MYSQL *mysql, int client_flag, char *db);
extern void *create_embedded_thd(Vio *vio, unsigned char *buff, int client_flag, char *db); extern void *create_embedded_thd(Vio *vio, unsigned char *buff, int client_flag, char *db);
extern NET *get_mysql_net(MYSQL *mysql); extern NET *get_mysql_net(MYSQL *mysql);
extern my_bool simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg,
ulong length, my_bool skipp_check);
C_MODE_END C_MODE_END
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#define SCRAMBLE_LENGTH 8 #define SCRAMBLE_LENGTH 8
C_MODE_START C_MODE_START
#include "lib_vio.c" #include "lib_vio.c"
#include "errmsg.h"
static int check_connections1(THD * thd); static int check_connections1(THD * thd);
static int check_connections2(THD * thd); static int check_connections2(THD * thd);
...@@ -41,16 +42,41 @@ static bool check_user(THD *thd, enum_server_command command, ...@@ -41,16 +42,41 @@ static bool check_user(THD *thd, enum_server_command command,
char * get_mysql_home(){ return mysql_home;}; char * get_mysql_home(){ return mysql_home;};
char * get_mysql_real_data_home(){ return mysql_real_data_home;}; char * get_mysql_real_data_home(){ return mysql_real_data_home;};
bool lib_dispatch_command(enum enum_server_command command, NET *net, my_bool simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg,
const char *arg, ulong length) ulong length, my_bool skipp_check)
{ {
NET *net= &mysql->net;
my_bool result= 1;
THD *thd=(THD *) net->vio->dest_thd; THD *thd=(THD *) net->vio->dest_thd;
/* Check that we are calling the client functions in right order */
if (mysql->status != MYSQL_STATUS_READY)
{
strmov(net->last_error,ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC));
return 1;
}
/* Clear result variables */
mysql->net.last_error[0]=0;
mysql->net.last_errno=0;
mysql->info=0;
mysql->affected_rows= ~(my_ulonglong) 0;
/* Clear receive buffer and vio packet list */
net_clear(net);
vio_reset(net->vio);
thd->store_globals(); // Fix if more than one connect thd->store_globals(); // Fix if more than one connect
thd->net.last_error[0]=0; // Clear error message // thd->net.last_error[0]=0; // Clear error message
thd->net.last_errno=0; // thd->net.last_errno=0;
net_new_transaction(net);
result= dispatch_command(command, thd, (char *) arg, length + 1);
net_new_transaction(&thd->net); if (!skipp_check)
return dispatch_command(command, thd, (char *) arg, length + 1); result= net->last_errno ? -1 : 0;
return result;
} }
#ifdef _DUMMY #ifdef _DUMMY
...@@ -604,6 +630,7 @@ void end_embedded_connection(NET * net) ...@@ -604,6 +630,7 @@ void end_embedded_connection(NET * net)
} /* extern "C" */ } /* extern "C" */
C_MODE_START
NET *get_mysql_net(MYSQL *mysql) NET *get_mysql_net(MYSQL *mysql)
{ {
return &((THD *)mysql->net.vio->dest_thd)->net; return &((THD *)mysql->net.vio->dest_thd)->net;
...@@ -626,6 +653,7 @@ void init_embedded_mysql(MYSQL *mysql, int client_flag, char *db) ...@@ -626,6 +653,7 @@ void init_embedded_mysql(MYSQL *mysql, int client_flag, char *db)
mysql->db= db; mysql->db= db;
thd->mysql= mysql; thd->mysql= mysql;
} }
C_MODE_END
static int embedded_thd_net_init(NET *net, unsigned char *buff) static int embedded_thd_net_init(NET *net, unsigned char *buff)
{ {
...@@ -636,7 +664,7 @@ static int embedded_thd_net_init(NET *net, unsigned char *buff) ...@@ -636,7 +664,7 @@ static int embedded_thd_net_init(NET *net, unsigned char *buff)
net->vio= NULL; net->vio= NULL;
net->no_send_ok= 0; net->no_send_ok= 0;
net->error=0; net->return_errno=0; net->return_status=0; net->error=0; net->return_errno=0; net->return_status=0;
net->timeout=(uint) net_read_timeout; /* Timeout for read */ // net->timeout=(uint) net_read_timeout; /* Timeout for read */
net->pkt_nr= net->compress_pkt_nr=0; net->pkt_nr= net->compress_pkt_nr=0;
net->write_pos= net->read_pos = net->buff; net->write_pos= net->read_pos = net->buff;
net->last_error[0]= 0; net->last_error[0]= 0;
...@@ -648,6 +676,8 @@ static int embedded_thd_net_init(NET *net, unsigned char *buff) ...@@ -648,6 +676,8 @@ static int embedded_thd_net_init(NET *net, unsigned char *buff)
return 0; return 0;
} }
C_MODE_START
void *create_embedded_thd(Vio *vio, unsigned char *buff, int client_flag, char *db) void *create_embedded_thd(Vio *vio, unsigned char *buff, int client_flag, char *db)
{ {
THD * thd= new THD; THD * thd= new THD;
...@@ -667,8 +697,8 @@ void *create_embedded_thd(Vio *vio, unsigned char *buff, int client_flag, char * ...@@ -667,8 +697,8 @@ void *create_embedded_thd(Vio *vio, unsigned char *buff, int client_flag, char *
thd->dbug_thread_id= my_thread_id(); thd->dbug_thread_id= my_thread_id();
thd->thread_stack= (char*) &thd; thd->thread_stack= (char*) &thd;
if (thd->max_join_size == HA_POS_ERROR) // if (thd->max_join_size == HA_POS_ERROR)
thd->options |= OPTION_BIG_SELECTS; // thd->options |= OPTION_BIG_SELECTS;
thd->proc_info=0; // Remove 'login' thd->proc_info=0; // Remove 'login'
thd->command=COM_SLEEP; thd->command=COM_SLEEP;
...@@ -676,11 +706,11 @@ void *create_embedded_thd(Vio *vio, unsigned char *buff, int client_flag, char * ...@@ -676,11 +706,11 @@ void *create_embedded_thd(Vio *vio, unsigned char *buff, int client_flag, char *
thd->set_time(); thd->set_time();
init_sql_alloc(&thd->mem_root,8192,8192); init_sql_alloc(&thd->mem_root,8192,8192);
thd->client_capabilities= client_flag; thd->client_capabilities= client_flag;
thd->max_packet_length= max_allowed_packet; // thd->max_packet_length= max_allowed_packet;
thd->net.vio = vio; thd->net.vio = vio;
if (thd->client_capabilities & CLIENT_INTERACTIVE) // if (thd->client_capabilities & CLIENT_INTERACTIVE)
thd->inactive_timeout= net_interactive_timeout; // thd->inactive_timeout= net_interactive_timeout;
if (thd->client_capabilities & CLIENT_TRANSACTIONS) if (thd->client_capabilities & CLIENT_TRANSACTIONS)
thd->net.return_status= &thd->server_status; thd->net.return_status= &thd->server_status;
...@@ -691,6 +721,7 @@ void *create_embedded_thd(Vio *vio, unsigned char *buff, int client_flag, char * ...@@ -691,6 +721,7 @@ void *create_embedded_thd(Vio *vio, unsigned char *buff, int client_flag, char *
return thd; return thd;
} }
C_MODE_END
bool send_fields(THD *thd, List<Item> &list, uint flag) bool send_fields(THD *thd, List<Item> &list, uint flag)
{ {
...@@ -762,7 +793,7 @@ bool send_fields(THD *thd, List<Item> &list, uint flag) ...@@ -762,7 +793,7 @@ bool send_fields(THD *thd, List<Item> &list, uint flag)
return 0; return 0;
err: err:
send_error(&thd->net,ER_OUT_OF_RESOURCES); /* purecov: inspected */ send_error(thd, ER_OUT_OF_RESOURCES); /* purecov: inspected */
return 1; /* purecov: inspected */ return 1; /* purecov: inspected */
} }
...@@ -886,8 +917,8 @@ bool do_command(THD *thd) ...@@ -886,8 +917,8 @@ bool do_command(THD *thd)
thd->current_tablenr=0; thd->current_tablenr=0;
packet=0; packet=0;
old_timeout=net->timeout; // old_timeout=net->timeout;
net->timeout=(uint) thd->inactive_timeout; // Wait max for 8 hours // net->timeout=(uint) thd->inactive_timeout; // Wait max for 8 hours
net->last_error[0]=0; // Clear error message net->last_error[0]=0; // Clear error message
net->last_errno=0; net->last_errno=0;
...@@ -901,18 +932,20 @@ bool do_command(THD *thd) ...@@ -901,18 +932,20 @@ bool do_command(THD *thd)
else else
{ {
packet=(char*) net->read_pos; packet=(char*) net->read_pos;
command = (enum enum_server_command) (uchar) packet[0];
command = (enum enum_server_command) (uchar) packet[0];
DBUG_PRINT("info",("Command on %s = %d (%s)", DBUG_PRINT("info",("Command on %s = %d (%s)",
vio_description(net->vio), command, vio_description(net->vio), command,
command_name[command])); command_name[command]));
} }
net->timeout=old_timeout; // Timeout for writing // net->timeout=old_timeout; // Timeout for writing
DBUG_RETURN(dispatch_command(command,thd, packet+1, (uint) packet_length)); DBUG_RETURN(dispatch_command(command,thd, packet+1, (uint) packet_length));
} }
void void
send_ok(NET *net,ha_rows affected_rows,ulonglong id,const char *message) send_ok(THD *thd,ha_rows affected_rows,ulonglong id,const char *message)
{ {
NET *net= &thd->net;
if (net->no_send_ok) // hack for re-parsing queries if (net->no_send_ok) // hack for re-parsing queries
return; return;
...@@ -930,6 +963,36 @@ send_ok(NET *net,ha_rows affected_rows,ulonglong id,const char *message) ...@@ -930,6 +963,36 @@ send_ok(NET *net,ha_rows affected_rows,ulonglong id,const char *message)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
void
send_eof(THD *thd, bool no_flush)
{
/* static char eof_buff[1]= { (char) 254 };
NET *net= &thd->net;
DBUG_ENTER("send_eof");
if (net->vio != 0)
{
if (!no_flush && (thd->client_capabilities & CLIENT_PROTOCOL_41))
{
char buff[5];
uint tmp= min(thd->total_warn_count, 65535);
buff[0]=254;
int2store(buff+1, tmp);
int2store(buff+3, 0); // No flags yet
VOID(my_net_write(net,buff,5));
VOID(net_flush(net));
}
else
{
VOID(my_net_write(net,eof_buff,1));
if (!no_flush)
VOID(net_flush(net));
}
}
DBUG_VOID_RETURN;
*/
}
int embedded_send_row(THD *thd, int n_fields, char *data, int data_len) int embedded_send_row(THD *thd, int n_fields, char *data, int data_len)
{ {
MYSQL *mysql= thd->mysql; MYSQL *mysql= thd->mysql;
......
...@@ -212,39 +212,6 @@ static void free_rows(MYSQL_DATA *cur) ...@@ -212,39 +212,6 @@ static void free_rows(MYSQL_DATA *cur)
} }
} }
my_bool
simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg,
ulong length, my_bool skipp_check)
{
NET *net= &mysql->net;
my_bool result= 1;
/* Check that we are calling the client functions in right order */
if (mysql->status != MYSQL_STATUS_READY)
{
strmov(net->last_error,ER(mysql->net.last_errno=CR_COMMANDS_OUT_OF_SYNC));
goto end;
}
/* Clear result variables */
mysql->net.last_error[0]=0;
mysql->net.last_errno=0;
mysql->info=0;
mysql->affected_rows= ~(my_ulonglong) 0;
/* Clear receive buffer and vio packet list */
net_clear(net);
vio_reset(net->vio);
result = lib_dispatch_command(command, net, arg,length);
if (!skipp_check)
result= mysql->net.last_errno ? -1 : 0;
end:
return result;
}
static void free_old_query(MYSQL *mysql) static void free_old_query(MYSQL *mysql)
{ {
DBUG_ENTER("free_old_query"); DBUG_ENTER("free_old_query");
...@@ -1046,22 +1013,6 @@ mysql_query(MYSQL *mysql, const char *query) ...@@ -1046,22 +1013,6 @@ mysql_query(MYSQL *mysql, const char *query)
return mysql_real_query(mysql,query, (ulong) strlen(query)); return mysql_real_query(mysql,query, (ulong) strlen(query));
} }
int STDCALL
mysql_send_query(MYSQL* mysql, const char* query, ulong length)
{
if (mysql->options.separate_thread)
{
return -1;
}
mysql->result= NULL;
free_old_query(mysql); /* Free old result */
return simple_command(mysql, COM_QUERY, query, length, 1);
}
my_bool STDCALL my_bool STDCALL
mysql_read_query_result(MYSQL *mysql) mysql_read_query_result(MYSQL *mysql)
{ {
...@@ -1180,6 +1131,23 @@ my_bool my_connect(my_socket s, const struct sockaddr *name, uint namelen, ...@@ -1180,6 +1131,23 @@ my_bool my_connect(my_socket s, const struct sockaddr *name, uint namelen,
#endif #endif
} }
/*
int STDCALL
mysql_send_query(MYSQL* mysql, const char* query, ulong length)
{
if (mysql->options.separate_thread)
{
return -1;
}
mysql->result= NULL;
free_old_query(mysql);
return simple_command(mysql, COM_QUERY, query, length, 1);
}
*/
int STDCALL int STDCALL
mysql_real_query(MYSQL *mysql, const char *query, ulong length) mysql_real_query(MYSQL *mysql, const char *query, ulong length)
...@@ -1187,16 +1155,17 @@ mysql_real_query(MYSQL *mysql, const char *query, ulong length) ...@@ -1187,16 +1155,17 @@ mysql_real_query(MYSQL *mysql, const char *query, ulong length)
DBUG_ENTER("mysql_real_query"); DBUG_ENTER("mysql_real_query");
DBUG_PRINT("enter",("handle: %lx",mysql)); DBUG_PRINT("enter",("handle: %lx",mysql));
DBUG_PRINT("query",("Query = \"%s\"",query)); DBUG_PRINT("query",("Query = \"%s\"",query));
/* if (mysql->options.separate_thread)
if (mysql->options.separate_thread)
{ {
DBUG_RETURN(0); return -1;
} }
mysql->result= NULL; mysql->result= NULL;
free_old_query(mysql); free_old_query(mysql); /* Free old result */
*/
if (mysql_send_query(mysql, query, length)) if (simple_command(mysql, COM_QUERY, query, length, 1))
DBUG_RETURN(-1); DBUG_RETURN(-1);
DBUG_RETURN(mysql_read_query_result(mysql)); DBUG_RETURN(mysql_read_query_result(mysql));
......
...@@ -253,7 +253,6 @@ send_ok(THD *thd, ha_rows affected_rows, ulonglong id, const char *message) ...@@ -253,7 +253,6 @@ send_ok(THD *thd, ha_rows affected_rows, ulonglong id, const char *message)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
#endif /* EMBEDDED_LIBRARY */
/* /*
Send eof (= end of result set) to the client Send eof (= end of result set) to the client
...@@ -304,6 +303,7 @@ send_eof(THD *thd, bool no_flush) ...@@ -304,6 +303,7 @@ send_eof(THD *thd, bool no_flush)
} }
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
#endif /* EMBEDDED_LIBRARY */
/**************************************************************************** /****************************************************************************
......
...@@ -86,7 +86,7 @@ mysqld_show_dbs(THD *thd,const char *wild) ...@@ -86,7 +86,7 @@ mysqld_show_dbs(THD *thd,const char *wild)
packet->length(0); packet->length(0);
net_store_data(packet, thd->variables.convert_set, file_name); net_store_data(packet, thd->variables.convert_set, file_name);
if (SEND_ROW(thd, &thd->net, field_list.elements, if (SEND_ROW(thd, &thd->net, field_list.elements,
(char *)packet.ptr(), packet.length())) (char *)packet->ptr(), packet->length()))
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
} }
...@@ -126,7 +126,7 @@ int mysqld_show_open_tables(THD *thd,const char *wild) ...@@ -126,7 +126,7 @@ int mysqld_show_open_tables(THD *thd,const char *wild)
net_store_data(packet,open_list->in_use); net_store_data(packet,open_list->in_use);
net_store_data(packet,open_list->locked); net_store_data(packet,open_list->locked);
if (SEND_ROW(thd, &thd->net, field_list.elements, if (SEND_ROW(thd, &thd->net, field_list.elements,
(char *)packet.ptr(), packet.length())) (char *)packet->ptr(), packet->length()))
{ {
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
...@@ -169,7 +169,7 @@ int mysqld_show_tables(THD *thd,const char *db,const char *wild) ...@@ -169,7 +169,7 @@ int mysqld_show_tables(THD *thd,const char *db,const char *wild)
packet->length(0); packet->length(0);
net_store_data(packet, thd->variables.convert_set, file_name); net_store_data(packet, thd->variables.convert_set, file_name);
if (SEND_ROW(thd, &thd->net, field_list.elements, if (SEND_ROW(thd, &thd->net, field_list.elements,
(char *)packet.ptr(), packet.length())) (char *)packet->ptr(), packet->length()))
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
send_eof(thd); send_eof(thd);
...@@ -636,7 +636,7 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild) ...@@ -636,7 +636,7 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild)
close_thread_tables(thd,0); close_thread_tables(thd,0);
} }
if (SEND_ROW(thd, &thd->net, field_list.elements, if (SEND_ROW(thd, &thd->net, field_list.elements,
(char *)thd->packet.ptr(), thd->packet.length())) (char *)packet->ptr(), packet->length()))
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
send_eof(thd); send_eof(thd);
...@@ -763,7 +763,7 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild, ...@@ -763,7 +763,7 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
net_store_data(packet, field->comment.str,field->comment.length); net_store_data(packet, field->comment.str,field->comment.length);
} }
if (SEND_ROW(thd, &thd->net, field_list.elements, if (SEND_ROW(thd, &thd->net, field_list.elements,
(char *)thd->packet.ptr(), thd->packet.length())) (char *)packet->ptr(), packet->length()))
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
} }
...@@ -834,7 +834,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) ...@@ -834,7 +834,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
// now we are in business :-) // now we are in business :-)
if (SEND_ROW(thd, &thd->net, field_list.elements, if (SEND_ROW(thd, &thd->net, field_list.elements,
(char *)thd->packet.ptr(), thd->packet.length())) (char *)packet->ptr(), packet->length()))
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
send_eof(thd); send_eof(thd);
...@@ -958,7 +958,7 @@ mysqld_show_keys(THD *thd, TABLE_LIST *table_list) ...@@ -958,7 +958,7 @@ mysqld_show_keys(THD *thd, TABLE_LIST *table_list)
/* Comment */ /* Comment */
net_store_data(packet,convert,""); net_store_data(packet,convert,"");
if (SEND_ROW(thd, &thd->net, field_list.elements, if (SEND_ROW(thd, &thd->net, field_list.elements,
(char *)thd->packet.ptr(), thd->packet.length())) (char *)packet->ptr(), packet->length()))
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
} }
...@@ -1387,7 +1387,7 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) ...@@ -1387,7 +1387,7 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose)
else else
net_store_null(packet); net_store_null(packet);
if (SEND_ROW(thd, &thd->net, field_list.elements, if (SEND_ROW(thd, &thd->net, field_list.elements,
(char *)thd->packet.ptr(), thd->packet.length())) (char *)packet->ptr(), packet->length()))
break; break;
} }
send_eof(thd); send_eof(thd);
......
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