Commit cda34818 authored by unknown's avatar unknown

Some code improvements


libmysqld/lib_sql.cc:
  embedded_send_row function trimmed
libmysqld/libmysqld.c:
  code trimming process
sql/ha_myisam.cc:
  SEND_ROW simplified
sql/mysql_priv.h:
  SEND_ROW simplified
sql/mysqld.cc:
  main() code trimming
sql/sql_handler.cc:
  SEND_ROW macro simplified
sql/sql_show.cc:
  SEND_ROW macro simplified
sql/sql_table.cc:
  SEND_ROW macro simplified
parent a62ee220
...@@ -23,6 +23,11 @@ ...@@ -23,6 +23,11 @@
#define mysql_unix_port mysql_inix_port1 #define mysql_unix_port mysql_inix_port1
#define mysql_port mysql_port1 #define mysql_port mysql_port1
static int fake_argc= 1;
static char *fake_argv[]= {(char *)"", 0};
static const char *fake_groups[] = { "server", "embedded", 0 };
static char inited, org_my_init_done;
#if defined (__WIN__) #if defined (__WIN__)
#include "../sql/mysqld.cpp" #include "../sql/mysqld.cpp"
#else #else
...@@ -302,9 +307,9 @@ static bool check_user(THD *thd,enum_server_command command, const char *user, ...@@ -302,9 +307,9 @@ static bool check_user(THD *thd,enum_server_command command, const char *user,
extern "C" extern "C"
{ {
static my_bool inited, org_my_init_done;
ulong max_allowed_packet, net_buffer_length; ulong max_allowed_packet, net_buffer_length;
int STDCALL mysql_server_init(int argc, char **argv, char **groups) int STDCALL mysql_server_init(int argc, char **argv, char **groups)
{ {
char glob_hostname[FN_REFLEN]; char glob_hostname[FN_REFLEN];
...@@ -587,7 +592,6 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups) ...@@ -587,7 +592,6 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups)
return 0; return 0;
} }
void STDCALL mysql_server_end() void STDCALL mysql_server_end()
{ {
clean_up(0); clean_up(0);
...@@ -1009,14 +1013,12 @@ int embedded_send_row(THD *thd, int n_fields, char *data, int data_len) ...@@ -1009,14 +1013,12 @@ int embedded_send_row(THD *thd, int n_fields, char *data, int data_len)
DBUG_ENTER("embedded_send_row"); DBUG_ENTER("embedded_send_row");
result->rows++; result->rows++;
if (!(cur= (MYSQL_ROWS *)alloc_root(alloc, sizeof(MYSQL_ROWS))) || if (!(cur= (MYSQL_ROWS *)alloc_root(alloc, sizeof(MYSQL_ROWS) + (n_fields + 1) * sizeof(char *) + data_len)))
!(cur->data=
(MYSQL_ROW)alloc_root(alloc,
(n_fields + 1) * sizeof(char *) + data_len)))
{ {
my_error(ER_OUT_OF_RESOURCES,MYF(0)); my_error(ER_OUT_OF_RESOURCES,MYF(0));
DBUG_RETURN(1); DBUG_RETURN(1);
} }
cur->data= (MYSQL_ROW)((char *)cur) + sizeof(MYSQL_ROWS);
*result->prev_ptr= cur; *result->prev_ptr= cur;
result->prev_ptr= &cur->next; result->prev_ptr= &cur->next;
...@@ -1024,7 +1026,7 @@ int embedded_send_row(THD *thd, int n_fields, char *data, int data_len) ...@@ -1024,7 +1026,7 @@ int embedded_send_row(THD *thd, int n_fields, char *data, int data_len)
cp= (uchar *)data; cp= (uchar *)data;
end_field= cur->data + n_fields; end_field= cur->data + n_fields;
for (cur_field=cur->data; cur_field<end_field; ++cur_field, ++mysql_fields) for (cur_field=cur->data; cur_field<end_field; cur_field++, mysql_fields++)
{ {
if ((len= (ulong) net_field_length(&cp)) == NULL_LENGTH) if ((len= (ulong) net_field_length(&cp)) == NULL_LENGTH)
{ {
......
...@@ -723,6 +723,7 @@ static void mysql_once_init() ...@@ -723,6 +723,7 @@ static void mysql_once_init()
if (!mysql_client_init) if (!mysql_client_init)
{ {
mysql_client_init=1; mysql_client_init=1;
my_init(); /* Will init threads */ my_init(); /* Will init threads */
init_client_errs(); init_client_errs();
mysql_port = MYSQL_PORT; mysql_port = MYSQL_PORT;
...@@ -1131,24 +1132,6 @@ my_bool my_connect(my_socket s, const struct sockaddr *name, uint namelen, ...@@ -1131,24 +1132,6 @@ 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)
{ {
...@@ -1250,12 +1233,6 @@ mysql_store_result(MYSQL *mysql) ...@@ -1250,12 +1233,6 @@ mysql_store_result(MYSQL *mysql)
return result; return result;
} }
void _0dummy()
{
send_file_to_server(NULL, NULL);
net_field_length_ll(NULL);
}
/************************************************************************** /**************************************************************************
** Alloc struct for use with unbuffered reads. Data is fetched by domand ** Alloc struct for use with unbuffered reads. Data is fetched by domand
** when calling to mysql_fetch_row. ** when calling to mysql_fetch_row.
......
...@@ -79,7 +79,7 @@ static void mi_check_print_msg(MI_CHECK *param, const char* msg_type, ...@@ -79,7 +79,7 @@ static void mi_check_print_msg(MI_CHECK *param, const char* msg_type,
net_store_data(packet, msg_type); net_store_data(packet, msg_type);
net_store_data(packet, msgbuf); net_store_data(packet, msgbuf);
if (SEND_ROW(thd, &thd->net, 4, (char*)thd->packet.ptr(), thd->packet.length())) if (SEND_ROW(thd, 4, (char*)thd->packet.ptr(), thd->packet.length()))
sql_print_error("Failed on my_net_write, writing to stderr instead: %s\n", sql_print_error("Failed on my_net_write, writing to stderr instead: %s\n",
msgbuf); msgbuf);
return; return;
......
...@@ -872,10 +872,10 @@ inline void mark_as_null_row(TABLE *table) ...@@ -872,10 +872,10 @@ inline void mark_as_null_row(TABLE *table)
#ifdef EMBEDDED_LIBRARY #ifdef EMBEDDED_LIBRARY
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);
#define SEND_ROW(thd, net, n_fields, data, data_len)\ #define SEND_ROW(thd, n_fields, data, data_len)\
embedded_send_row(thd, n_fields, data, data_len) embedded_send_row(thd, n_fields, data, data_len)
#else #else
#define SEND_ROW(thd, net, n_fields, data, data_len)\ #define SEND_ROW(thd, n_fields, data, data_len)\
my_net_write(net, data, data_len) my_net_write(&thd->net, data, data_len)
#endif #endif
This diff is collapsed.
...@@ -233,7 +233,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables, ...@@ -233,7 +233,7 @@ int mysql_ha_read(THD *thd, TABLE_LIST *tables,
goto err; goto err;
} }
} }
SEND_ROW(thd, &thd->net, list.elements, (char*)packet->ptr(), packet->length()); SEND_ROW(thd, list.elements, (char*)packet->ptr(), packet->length());
} }
} }
num_rows++; num_rows++;
......
...@@ -85,7 +85,7 @@ mysqld_show_dbs(THD *thd,const char *wild) ...@@ -85,7 +85,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, field_list.elements,
(char *)packet->ptr(), packet->length())) (char *)packet->ptr(), packet->length()))
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
...@@ -125,7 +125,7 @@ int mysqld_show_open_tables(THD *thd,const char *wild) ...@@ -125,7 +125,7 @@ int mysqld_show_open_tables(THD *thd,const char *wild)
net_store_data(packet,convert, open_list->table); net_store_data(packet,convert, open_list->table);
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, field_list.elements,
(char *)packet->ptr(), packet->length())) (char *)packet->ptr(), packet->length()))
{ {
DBUG_RETURN(-1); DBUG_RETURN(-1);
...@@ -168,7 +168,7 @@ int mysqld_show_tables(THD *thd,const char *db,const char *wild) ...@@ -168,7 +168,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, field_list.elements,
(char *)packet->ptr(), packet->length())) (char *)packet->ptr(), packet->length()))
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
...@@ -635,7 +635,7 @@ int mysqld_extend_show_tables(THD *thd,const char *db,const char *wild) ...@@ -635,7 +635,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, field_list.elements,
(char *)packet->ptr(), packet->length())) (char *)packet->ptr(), packet->length()))
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
...@@ -762,7 +762,7 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild, ...@@ -762,7 +762,7 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild,
net_store_data(packet,convert, tmp+1,end == tmp ? 0 : (uint) (end-tmp-1)); net_store_data(packet,convert, tmp+1,end == tmp ? 0 : (uint) (end-tmp-1));
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, field_list.elements,
(char *)packet->ptr(), packet->length())) (char *)packet->ptr(), packet->length()))
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
...@@ -833,7 +833,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list) ...@@ -833,7 +833,7 @@ mysqld_show_create(THD *thd, TABLE_LIST *table_list)
int3store(p, create_len); int3store(p, create_len);
// now we are in business :-) // now we are in business :-)
if (SEND_ROW(thd, &thd->net, field_list.elements, if (SEND_ROW(thd, field_list.elements,
(char *)packet->ptr(), packet->length())) (char *)packet->ptr(), packet->length()))
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
...@@ -957,7 +957,7 @@ mysqld_show_keys(THD *thd, TABLE_LIST *table_list) ...@@ -957,7 +957,7 @@ mysqld_show_keys(THD *thd, TABLE_LIST *table_list)
net_store_data(packet,convert,table->file->index_type(i)); net_store_data(packet,convert,table->file->index_type(i));
/* 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, field_list.elements,
(char *)packet->ptr(), packet->length())) (char *)packet->ptr(), packet->length()))
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
...@@ -1386,7 +1386,7 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) ...@@ -1386,7 +1386,7 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose)
net_store_data(packet,convert,thd_info->query); net_store_data(packet,convert,thd_info->query);
else else
net_store_null(packet); net_store_null(packet);
if (SEND_ROW(thd, &thd->net, field_list.elements, if (SEND_ROW(thd, field_list.elements,
(char *)packet->ptr(), packet->length())) (char *)packet->ptr(), packet->length()))
break; break;
} }
...@@ -1687,7 +1687,7 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables, ...@@ -1687,7 +1687,7 @@ int mysqld_show(THD *thd, const char *wild, show_var_st *variables,
net_store_data(&packet2, ""); // Safety net_store_data(&packet2, ""); // Safety
break; break;
} }
if (SEND_ROW(thd, &thd->net, field_list.elements, if (SEND_ROW(thd, field_list.elements,
(char *)packet2.ptr(), packet2.length())) (char *)packet2.ptr(), packet2.length()))
goto err; goto err;
} }
......
...@@ -1017,7 +1017,7 @@ static int send_check_errmsg(THD* thd, TABLE_LIST* table, ...@@ -1017,7 +1017,7 @@ static int send_check_errmsg(THD* thd, TABLE_LIST* table,
net_store_data(packet, "error"); net_store_data(packet, "error");
net_store_data(packet, errmsg); net_store_data(packet, errmsg);
thd->net.last_error[0]=0; thd->net.last_error[0]=0;
if (SEND_ROW(thd, &thd->net, 4, (char*) thd->packet.ptr(), packet->length())) if (SEND_ROW(thd, 4, (char*) thd->packet.ptr(), packet->length()))
return -1; return -1;
return 1; return 1;
} }
...@@ -1211,7 +1211,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables, ...@@ -1211,7 +1211,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables,
err_msg=ER(ER_CHECK_NO_SUCH_TABLE); err_msg=ER(ER_CHECK_NO_SUCH_TABLE);
net_store_data(packet, err_msg); net_store_data(packet, err_msg);
thd->net.last_error[0]=0; thd->net.last_error[0]=0;
if (SEND_ROW(thd, &thd->net, field_list.elements, (char*) thd->packet.ptr(), if (SEND_ROW(thd, field_list.elements, (char*) thd->packet.ptr(),
packet->length())) packet->length()))
goto err; goto err;
continue; continue;
...@@ -1226,7 +1226,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables, ...@@ -1226,7 +1226,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables,
net_store_data(packet, buff); net_store_data(packet, buff);
close_thread_tables(thd); close_thread_tables(thd);
table->table=0; // For query cache table->table=0; // For query cache
if (SEND_ROW(thd, &thd->net, field_list.elements, (char*) thd->packet.ptr(), if (SEND_ROW(thd, field_list.elements, (char*) thd->packet.ptr(),
packet->length())) packet->length()))
goto err; goto err;
continue; continue;
...@@ -1313,7 +1313,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables, ...@@ -1313,7 +1313,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables,
} }
close_thread_tables(thd); close_thread_tables(thd);
table->table=0; // For query cache table->table=0; // For query cache
if (SEND_ROW(thd, &thd->net, field_list.elements, if (SEND_ROW(thd, field_list.elements,
(char *)thd->packet.ptr(), thd->packet.length())) (char *)thd->packet.ptr(), thd->packet.length()))
goto err; goto err;
} }
......
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