24 extern unsigned long max_allowed_packet, net_buffer_length;
27 #include "../sql/mysqld.cc"
34 #include "embedded_priv.h"
45 extern unsigned int mysql_server_last_errno;
46 extern char mysql_server_last_error[MYSQL_ERRMSG_SIZE];
47 static my_bool emb_read_query_result(
MYSQL *mysql);
50 void unireg_clear(
int exit_code)
52 DBUG_ENTER(
"unireg_clear");
53 clean_up(!opt_help && (exit_code || !opt_bootstrap));
54 my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
63 static void embedded_error_handler(uint error,
const char *str, myf MyFlags)
65 DBUG_ENTER(
"embedded_error_handler");
72 DBUG_RETURN(current_thd ? my_message_sql(error, str, MyFlags):
73 my_message_stderr(error, str, MyFlags));
95 NET *net= &mysql->net;
97 net->last_errno= ei->last_errno;
100 mysql->server_status= ei->server_status;
105 emb_advanced_command(
MYSQL *mysql,
enum enum_server_command command,
106 const uchar *header, ulong header_length,
107 const uchar *arg, ulong arg_length, my_bool skip_check,
111 THD *thd=(THD *) mysql->thd;
112 NET *net= &mysql->net;
113 my_bool stmt_skip= stmt ? stmt->state != MYSQL_STMT_INIT_DONE : FALSE;
118 if (mysql_reconnect(mysql) || stmt_skip)
120 thd= (THD *) mysql->thd;
123 #if defined(ENABLED_PROFILING)
124 thd->profiling.start_new_query();
127 thd->clear_data_list();
129 if (mysql->status != MYSQL_STATUS_READY)
131 set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
138 thd->get_stmt_da()->reset_diagnostics_area();
139 mysql->affected_rows= ~(my_ulonglong) 0;
140 mysql->field_count= 0;
141 net_clear_error(net);
142 thd->current_stmt= stmt;
144 thd->thread_stack= (
char*) &thd;
145 thd->store_globals();
152 free_old_query(mysql);
154 thd->extra_length= arg_length;
155 thd->extra_data= (
char *)arg;
159 arg_length= header_length;
164 thd->mysys_var= NULL;
167 result= thd->is_error() ? -1 : 0;
171 #if defined(ENABLED_PROFILING)
172 thd->profiling.finish_current_query();
176 thd->restore_globals();
180 static void emb_flush_use_result(
MYSQL *mysql, my_bool)
182 THD *thd= (THD*) mysql->thd;
185 free_rows(thd->cur_data);
188 else if (thd->first_data)
191 thd->first_data= data->embedded_info->next;
213 emb_read_rows(
MYSQL *mysql,
MYSQL_FIELD *mysql_fields __attribute__((unused)),
214 unsigned int fields __attribute__((unused)))
216 MYSQL_DATA *result= ((THD*)mysql->thd)->cur_data;
217 ((THD*)mysql->thd)->cur_data= 0;
218 if (result->embedded_info->last_errno)
220 embedded_get_error(mysql, result);
223 *result->embedded_info->prev_ptr= NULL;
231 if (emb_read_query_result(mysql))
233 res= ((THD*) mysql->thd)->cur_data;
234 ((THD*) mysql->thd)->cur_data= 0;
235 mysql->field_alloc= res->alloc;
237 mysql->status= MYSQL_STATUS_READY;
238 return mysql->fields;
243 THD *thd= (THD*) mysql->thd;
246 stmt->stmt_id= thd->client_stmt_id;
247 stmt->param_count= thd->client_param_count;
248 stmt->field_count= 0;
249 mysql->warning_count= thd->get_stmt_da()->current_statement_warn_count();
253 if (emb_read_query_result(mysql))
255 stmt->field_count= mysql->field_count;
256 mysql->status= MYSQL_STATUS_READY;
259 if (!(mysql->server_status & SERVER_STATUS_AUTOCOMMIT))
260 mysql->server_status|= SERVER_STATUS_IN_TRANS;
262 stmt->fields= mysql->fields;
263 stmt->mem_root= res->alloc;
277 static void emb_fetch_lengths(ulong *
to, MYSQL_ROW column,
278 unsigned int field_count)
282 for (end=column + field_count; column != end ; column++,to++)
283 *to= *column ? *(uint *)((*column) -
sizeof(uint)) : 0;
286 static my_bool emb_read_query_result(
MYSQL *mysql)
288 THD *thd= (THD*) mysql->thd;
290 DBUG_ASSERT(!thd->cur_data);
291 thd->first_data= res->embedded_info->next;
292 if (res->embedded_info->last_errno &&
293 !res->embedded_info->fields_list)
295 embedded_get_error(mysql, res);
299 mysql->warning_count= res->embedded_info->warning_count;
300 mysql->server_status= res->embedded_info->server_status;
301 mysql->field_count= res->fields;
302 if (!(mysql->fields= res->embedded_info->fields_list))
304 mysql->affected_rows= res->embedded_info->affected_rows;
305 mysql->insert_id= res->embedded_info->insert_id;
307 net_clear_error(&mysql->net);
310 if (res->embedded_info->info[0])
312 strmake(mysql->info_buffer, res->embedded_info->info, MYSQL_ERRMSG_SIZE-1);
313 mysql->info= mysql->info_buffer;
316 if (res->embedded_info->fields_list)
318 mysql->status=MYSQL_STATUS_GET_RESULT;
329 DBUG_ENTER(
"emb_stmt_execute");
334 int4store(header, stmt->stmt_id);
335 header[4]= (uchar) stmt->flags;
336 thd= (THD*)stmt->mysql->thd;
337 thd->client_param_count= stmt->param_count;
338 thd->client_params= stmt->params;
340 res=
test(emb_advanced_command(stmt->mysql, COM_STMT_EXECUTE, 0, 0,
341 header,
sizeof(header), 1, stmt) ||
342 emb_read_query_result(stmt->mysql));
343 stmt->affected_rows= stmt->mysql->affected_rows;
344 stmt->insert_id= stmt->mysql->insert_id;
345 stmt->server_status= stmt->mysql->server_status;
348 NET *net= &stmt->mysql->net;
349 set_stmt_errmsg(stmt, net);
352 else if (stmt->mysql->status == MYSQL_STATUS_GET_RESULT)
353 stmt->mysql->status= MYSQL_STATUS_STATEMENT_GET_RESULT;
360 if (!(data= emb_read_rows(stmt->mysql, 0, 0)))
362 set_stmt_errmsg(stmt, &stmt->mysql->net);
367 set_stmt_errmsg(stmt, &stmt->mysql->net);
371 int emb_read_rows_from_cursor(
MYSQL_STMT *stmt)
373 MYSQL *mysql= stmt->mysql;
374 THD *thd= (THD*) mysql->thd;
376 DBUG_ASSERT(!thd->first_data->embedded_info->next);
378 if (res->embedded_info->last_errno)
380 embedded_get_error(mysql, res);
381 set_stmt_errmsg(stmt, &mysql->net);
386 mysql->warning_count= res->embedded_info->warning_count;
387 mysql->server_status= res->embedded_info->server_status;
388 net_clear_error(&mysql->net);
390 return emb_read_binary_rows(stmt);
393 int emb_unbuffered_fetch(
MYSQL *mysql,
char **row)
395 THD *thd= (THD*) mysql->thd;
397 if (data && data->embedded_info->last_errno)
399 embedded_get_error(mysql, data);
403 if (!data || !data->data)
408 thd->cur_data= thd->first_data;
409 thd->first_data= data->embedded_info->next;
415 *row= (
char *)data->data->data;
416 data->data= data->data->next;
421 static void emb_free_embedded_thd(
MYSQL *mysql)
423 THD *thd= (THD*)mysql->thd;
424 thd->clear_data_list();
425 thd->store_globals();
426 thd->release_resources();
429 remove_global_thread(thd);
433 my_pthread_setspecific_ptr(THR_THD, 0);
437 static const char * emb_read_statistics(
MYSQL *mysql)
439 THD *thd= (THD*)mysql->thd;
440 return thd->is_error() ? thd->get_stmt_da()->message() :
"";
446 return mysql_store_result(mysql);
449 int emb_read_change_user_result(
MYSQL *mysql)
451 mysql->net.read_pos= (uchar*)
"";
452 return mysql_errno(mysql) ?
static_cast<int>packet_error :
458 emb_read_query_result,
459 emb_advanced_command,
463 emb_flush_use_result,
464 emb_read_change_user_result,
466 emb_read_prepare_result,
468 emb_read_binary_rows,
469 emb_unbuffered_fetch,
470 emb_free_embedded_thd,
472 emb_read_query_result,
473 emb_read_rows_from_cursor
480 char **copy_arguments(
int argc,
char **argv)
483 char **from, **res, **end= argv+argc;
485 for (from=argv ; from != end ; from++)
486 length+= strlen(*from);
488 if ((res= (
char**) my_malloc(
sizeof(argv)*(argc+1)+length+argc,
491 char **to= res, *to_str= (
char*) (res+argc+1);
492 for (from=argv ; from != end ;)
495 to_str= strmov(to_str, *from++)+1;
502 char ** copy_arguments_ptr= 0;
504 int init_embedded_server(
int argc,
char **argv,
char **groups)
514 char **foo= &fake_argv[0];
515 char fake_server[]=
"server";
516 char fake_embedded[]=
"embedded";
517 char *fake_groups[]= { fake_server, fake_embedded, NULL };
518 char fake_name[]=
"fake_name";
521 if (my_thread_init())
531 fake_argv[0]= fake_name;
540 my_progname=
"mysql_embedded";
550 if (load_defaults(
"my", (
const char **)groups, argcp, argvp))
552 defaults_argc= *argcp;
553 defaults_argv= *argvp;
554 remaining_argc= *argcp;
555 remaining_argv= *argvp;
558 system_charset_info= &my_charset_utf8_general_ci;
561 int ho_error= handle_early_options();
564 buffered_logs.print();
565 buffered_logs.cleanup();
569 ulong requested_open_files_dummy;
570 adjust_related_options(&requested_open_files_dummy);
572 if (init_common_variables())
578 mysql_data_home= mysql_real_data_home;
579 mysql_data_home_len= mysql_real_data_home_len;
582 opt_mysql_tmpdir=getenv(
"TMPDIR");
584 if (!opt_mysql_tmpdir)
585 opt_mysql_tmpdir=getenv(
"TEMP");
586 if (!opt_mysql_tmpdir)
587 opt_mysql_tmpdir=getenv(
"TMP");
589 if (!opt_mysql_tmpdir || !opt_mysql_tmpdir[0])
590 opt_mysql_tmpdir=(
char*) P_tmpdir;
593 umask(((~my_umask) & 0666));
594 if (init_server_components())
604 if (!opt_bootstrap && init_server_auto_options())
613 error_handler_hook= embedded_error_handler;
616 #ifndef NO_EMBEDDED_ACCESS_CHECKS
617 if (!(acl_error= acl_init(opt_noacl)) &&
621 if (acl_error || my_tz_init((THD *)0, default_tz_name, opt_bootstrap))
627 init_max_user_conn();
628 init_update_queries();
634 #ifndef NO_EMBEDDED_ACCESS_CHECKS
640 (void) thr_setconcurrency(concurrency);
642 start_handle_manager();
646 if(!binlog_filter) binlog_filter =
new Rpl_filter;
651 if (read_init_file(opt_init_file))
658 execute_ddl_log_recovery();
662 mysqld_server_started= 1;
666 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
668 if (ndb_wait_setup_func && ndb_wait_setup_func(opt_ndb_wait_setup))
670 sql_print_warning(
"NDB : Tables not available after %lu seconds."
671 " Consider increasing --ndb-wait-setup value",
679 void end_embedded_server()
681 my_free(copy_arguments_ptr);
682 copy_arguments_ptr=0;
687 void init_embedded_mysql(
MYSQL *mysql,
int client_flag)
689 THD *thd = (THD *)mysql->thd;
691 mysql->server_version= server_version;
692 mysql->client_flag= client_flag;
693 init_alloc_root(&mysql->field_alloc, 8192, 0);
707 void *create_embedded_thd(
int client_flag)
710 thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
712 thd->thread_stack= (
char*) &thd;
713 if (thd->store_globals())
715 fprintf(stderr,
"store_globals failed.\n");
722 if (thd->variables.max_join_size == HA_POS_ERROR)
723 thd->variables.option_bits |= OPTION_BIG_SELECTS;
725 thd->set_command(COM_SLEEP);
727 thd->init_for_queries();
728 thd->client_capabilities= client_flag;
729 thd->real_id= pthread_self();
733 #ifndef NO_EMBEDDED_ACCESS_CHECKS
734 thd->security_ctx->db_access= DB_ACLS;
735 thd->security_ctx->master_access= ~NO_ACCESS;
739 thd->data_tail= &thd->first_data;
740 memset(&thd->net, 0,
sizeof(thd->net));
743 add_global_thread(thd);
754 emb_transfer_connect_attrs(
MYSQL *mysql)
756 #ifdef HAVE_PSI_THREAD_INTERFACE
757 if (mysql->options.extension &&
758 mysql->options.extension->connection_attributes_length)
761 THD *thd= (THD*)mysql->thd;
762 size_t length= mysql->options.extension->connection_attributes_length;
765 ptr= buf= (uchar *) my_alloca(length + 9);
766 send_client_connect_attrs(mysql, buf);
767 net_field_length_ll(&ptr);
768 PSI_THREAD_CALL(set_thread_connect_attrs)((
char *) ptr, length, thd->charset());
775 #ifdef NO_EMBEDDED_ACCESS_CHECKS
776 int check_embedded_connection(
MYSQL *mysql,
const char *db)
779 LEX_STRING db_str = { (
char*)db, db ? strlen(db) : 0 };
780 THD *thd= (THD*)mysql->thd;
783 mysql->server_capabilities= mysql->client_flag;
785 thd_init_client_charset(thd, mysql->charset->number);
786 thd->update_charset();
787 Security_context *sctx= thd->security_ctx;
788 sctx->set_host(my_localhost);
789 sctx->host_or_ip= sctx->get_host()->ptr();
790 strmake(sctx->priv_host, (
char*) my_localhost, MAX_HOSTNAME-1);
791 strmake(sctx->priv_user, mysql->user, USERNAME_LENGTH-1);
792 sctx->user= my_strdup(mysql->user, MYF(0));
793 sctx->proxy_user[0]= 0;
794 sctx->master_access= GLOBAL_ACLS;
795 emb_transfer_connect_attrs(mysql);
797 if (!(result= (db && db[0] && mysql_change_db(thd, &db_str, FALSE))))
799 thd->protocol->end_statement();
800 emb_read_query_result(mysql);
805 int check_embedded_connection(
MYSQL *mysql,
const char *db)
812 NET *net= &mysql->net;
813 THD *thd= (THD*)mysql->thd;
814 Security_context *sctx= thd->security_ctx;
815 size_t connect_attrs_len=
816 (mysql->server_capabilities & CLIENT_CONNECT_ATTRS &&
817 mysql->options.extension) ?
818 mysql->options.extension->connection_attributes_length : 0;
820 buf= my_alloca(USERNAME_LENGTH + SCRAMBLE_LENGTH + 1 + 2*NAME_LEN + 2 +
821 connect_attrs_len + 2);
822 if (mysql->options.client_ip)
824 sctx->set_host(my_strdup(mysql->options.client_ip, MYF(0)));
825 sctx->set_ip(my_strdup(sctx->get_host()->ptr(), MYF(0)));
828 sctx->set_host((
char*)my_localhost);
829 sctx->host_or_ip= sctx->host->ptr();
831 if (acl_check_host(sctx->get_host()->ptr(), sctx->get_ip()->ptr()))
835 end= strmake(buf, mysql->user, USERNAME_LENGTH) + 1;
837 memset(thd->scramble, 55, SCRAMBLE_LENGTH);
838 thd->scramble[SCRAMBLE_LENGTH]= 0;
840 if (mysql->passwd && mysql->passwd[0])
842 *end++= SCRAMBLE_LENGTH;
843 scramble(end, thd->scramble, mysql->passwd);
844 end+= SCRAMBLE_LENGTH;
849 end= strmake(end, db ? db :
"", NAME_LEN) + 1;
851 int2store(end, (ushort) mysql->charset->number);
854 end= strmake(end,
"mysql_native_password", NAME_LEN) + 1;
857 mysql->server_capabilities= mysql->client_flag;
859 end= (
char *) send_client_connect_attrs(mysql, (uchar *) end);
862 thd->net.read_pos= (uchar*)buf;
864 if (acl_authenticate(thd, 0, end - buf))
866 x_free(thd->security_ctx->user);
874 mysql_errno_to_sqlstate(thd->main_da.sql_errno()),
884 void THD::clear_data_list()
889 first_data= data->embedded_info->next;
892 data_tail= &first_data;
898 static char *dup_str_aux(
MEM_ROOT *root,
const char *from, uint length,
906 if (tocs && String::needs_conversion(0, fromcs, tocs, &dummy32))
908 uint new_len= (tocs->mbmaxlen * length) / fromcs->mbminlen + 1;
909 result= (
char *)alloc_root(root, new_len);
910 length= copy_and_convert(result, new_len,
911 tocs, from, length, fromcs, &dummy_err);
915 result= (
char *)alloc_root(root, length + 1);
916 memcpy(result, from, length);
943 if (!my_multi_malloc(MYF(MY_WME | MY_ZEROFILL),
944 &data,
sizeof(*data),
945 &emb_data,
sizeof(*emb_data),
949 emb_data->prev_ptr= &data->data;
952 data_tail= &emb_data->next;
953 data->embedded_info= emb_data;
969 write_eof_packet(THD *thd, uint server_status, uint statement_warn_count)
978 if (thd->is_fatal_error)
979 thd->server_status&= ~SERVER_MORE_RESULTS_EXISTS;
980 thd->cur_data->embedded_info->server_status= server_status;
985 thd->cur_data->embedded_info->warning_count=
986 (thd->sp_runtime_ctx ? 0 : min(statement_warn_count, 65535
U));
1002 int Protocol::begin_dataset()
1007 alloc= &data->alloc;
1008 init_alloc_root(alloc,8192,0);
1026 void Protocol_text::remove_last_row()
1030 my_ulonglong count= data->rows;
1031 DBUG_ENTER(
"Protocol_text::remove_last_row");
1033 last_row_hook= &(*last_row_hook)->next;
1036 data->embedded_info->prev_ptr= last_row_hook;
1049 const CHARSET_INFO *thd_cs= thd->variables.character_set_results;
1052 DBUG_ENTER(
"send_result_set_metadata");
1057 if (begin_dataset())
1060 data= thd->cur_data;
1061 data->fields= field_count= list->elements;
1062 field_alloc= &data->alloc;
1064 if (!(client_field= data->embedded_info->fields_list=
1068 while ((item= it++))
1071 item->make_field(&server_field);
1074 if (server_field.type == MYSQL_TYPE_VARCHAR)
1075 server_field.type= MYSQL_TYPE_VAR_STRING;
1077 client_field->db= dup_str_aux(field_alloc, server_field.db_name,
1078 strlen(server_field.db_name), cs, thd_cs);
1079 client_field->table= dup_str_aux(field_alloc, server_field.table_name,
1080 strlen(server_field.table_name), cs, thd_cs);
1081 client_field->name= dup_str_aux(field_alloc, server_field.col_name,
1082 strlen(server_field.col_name), cs, thd_cs);
1083 client_field->org_table= dup_str_aux(field_alloc, server_field.org_table_name,
1084 strlen(server_field.org_table_name), cs, thd_cs);
1085 client_field->org_name= dup_str_aux(field_alloc, server_field.org_col_name,
1086 strlen(server_field.org_col_name), cs, thd_cs);
1087 if (item->charset_for_protocol() == &my_charset_bin || thd_cs == NULL)
1090 client_field->charsetnr= item->charset_for_protocol()->number;
1091 client_field->length= server_field.length;
1097 client_field->charsetnr= thd_cs->number;
1098 max_char_len= (server_field.type >= (int) MYSQL_TYPE_TINY_BLOB &&
1099 server_field.type <= (
int) MYSQL_TYPE_BLOB) ?
1100 server_field.length / item->collation.collation->mbminlen :
1101 server_field.length / item->collation.collation->mbmaxlen;
1102 client_field->length= char_to_byte_length_safe(max_char_len,
1105 client_field->type= server_field.type;
1106 client_field->flags= server_field.flags;
1107 client_field->decimals= server_field.decimals;
1108 client_field->db_length= strlen(client_field->db);
1109 client_field->table_length= strlen(client_field->table);
1110 client_field->name_length= strlen(client_field->name);
1111 client_field->org_name_length= strlen(client_field->org_name);
1112 client_field->org_table_length= strlen(client_field->org_table);
1114 client_field->catalog= dup_str_aux(field_alloc,
"def", 3, cs, thd_cs);
1115 client_field->catalog_length= 3;
1117 if (IS_NUM(client_field->type))
1118 client_field->flags|= NUM_FLAG;
1120 if (flags & (
int) Protocol::SEND_DEFAULTS)
1123 String tmp(buff,
sizeof(buff), default_charset_info), *res;
1125 if (!(res=item->val_str(&tmp)))
1127 client_field->def_length= 0;
1128 client_field->def= strmake_root(field_alloc,
"",0);
1132 client_field->def_length= res->length();
1133 client_field->def= strmake_root(field_alloc, res->ptr(),
1134 client_field->def_length);
1138 client_field->def=0;
1139 client_field->max_length= 0;
1143 if (flags & SEND_EOF)
1144 write_eof_packet(thd, thd->server_status,
1145 thd->get_stmt_da()->current_statement_warn_count());
1147 DBUG_RETURN(prepare_for_send(list->elements));
1149 my_error(ER_OUT_OF_RESOURCES, MYF(0));
1153 bool Protocol::write()
1162 bool Protocol_binary::write()
1171 my_error(ER_OUT_OF_RESOURCES,MYF(0));
1174 cur->data= (MYSQL_ROW)(((
char *)cur) +
sizeof(
MYSQL_ROWS));
1175 memcpy(cur->data, packet->ptr()+1, packet->length()-1);
1176 cur->length= packet->length();
1178 *data->embedded_info->prev_ptr= cur;
1179 data->embedded_info->prev_ptr= &cur->next;
1207 uint server_status, uint statement_warn_count,
1208 ulonglong affected_rows, ulonglong
id,
const char *
message)
1210 DBUG_ENTER(
"emb_net_send_ok");
1212 MYSQL *mysql= thd->mysql;
1216 if (!(data= thd->alloc_new_dataset()))
1218 data->embedded_info->affected_rows= affected_rows;
1219 data->embedded_info->insert_id=
id;
1221 strmake(data->embedded_info->info, message,
1222 sizeof(data->embedded_info->info)-1);
1224 bool error= write_eof_packet(thd, server_status, statement_warn_count);
1241 net_send_eof(THD *thd, uint server_status, uint statement_warn_count)
1243 bool error= write_eof_packet(thd, server_status, statement_warn_count);
1250 const char *sqlstate)
1253 char converted_err[MYSQL_ERRMSG_SIZE];
1259 fprintf(stderr,
"ERROR: %d %s\n", sql_errno, err);
1264 data= thd->alloc_new_dataset();
1266 ei= data->embedded_info;
1267 ei->last_errno= sql_errno;
1268 convert_error_message(converted_err,
sizeof(converted_err),
1269 thd->variables.character_set_results,
1271 system_charset_info, &error);
1273 strmake(ei->info, converted_err,
sizeof(ei->info)-1);
1274 strmov(ei->sqlstate, sqlstate);
1275 ei->server_status= thd->server_status;
1281 void Protocol_text::prepare_for_resend()
1285 DBUG_ENTER(
"send_data");
1291 if (!(cur= (
MYSQL_ROWS *)alloc_root(alloc,
sizeof(
MYSQL_ROWS)+(field_count + 1) *
sizeof(
char *))))
1293 my_error(ER_OUT_OF_RESOURCES,MYF(0));
1296 cur->data= (MYSQL_ROW)(((
char *)cur) +
sizeof(
MYSQL_ROWS));
1298 *data->embedded_info->prev_ptr= cur;
1299 data->embedded_info->prev_ptr= &cur->next;
1300 next_field=cur->data;
1301 next_mysql_field= data->embedded_info->fields_list;
1309 bool Protocol_text::store_null()
1311 *(next_field++)= NULL;
1316 bool Protocol::net_store_data(
const uchar *from,
size_t length)
1322 if (!(field_buf= (
char*) alloc_root(alloc, length +
sizeof(uint) + 1)))
1324 *(uint *)field_buf= length;
1325 *next_field= field_buf +
sizeof(uint);
1326 memcpy((uchar*) *next_field, from, length);
1327 (*next_field)[length]= 0;
1328 if (next_mysql_field->max_length < length)
1329 next_mysql_field->max_length=length;
1335 #if defined(_MSC_VER) && _MSC_VER < 1400
1336 #define vsnprintf _vsnprintf
1340 const char *format, va_list argsi)
1342 my_vsnprintf(mysql_server_last_error,
sizeof(mysql_server_last_error),
1344 mysql_server_last_errno= CR_UNKNOWN_ERROR;
1349 bool Protocol::net_store_data(
const uchar *from,
size_t length,
1353 uint conv_length= to_cs->mbmaxlen * length / from_cs->mbminlen;
1359 if (!(field_buf= (
char*) alloc_root(alloc, conv_length +
sizeof(uint) + 1)))
1361 *next_field= field_buf +
sizeof(uint);
1362 length= copy_and_convert(*next_field, conv_length, to_cs,
1363 (
const char*) from, length, from_cs, &dummy_error);
1364 *(uint *) field_buf= length;
1365 (*next_field)[length]= 0;
1366 if (next_mysql_field->max_length < length)
1367 next_mysql_field->max_length= length;