lib_sql.cc 29 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * Copyright (c)  2000
 * SWsoft  company
 *
 * This material is provided "as is", with absolutely no warranty expressed
 * or implied. Any use is at your own risk.
 *
 * Permission to use or copy this software for any purpose is hereby granted 
 * without fee, provided the above notices are retained on all copies.
 * Permission to modify the code and to distribute modified code is granted,
 * provided the above notices are retained, and a notice that the code was
 * modified is included with the above copyright notice.
 *
14 15 16

  This code was modified by the MySQL team
*/
17

18 19 20 21
/*
  The following is needed to not cause conflicts when we include mysqld.cc
*/

22 23 24 25
#define main main1
#define mysql_unix_port mysql_inix_port1
#define mysql_port mysql_port1

26 27
extern "C"
{
monty@mysql.com's avatar
monty@mysql.com committed
28
  extern unsigned long max_allowed_packet, net_buffer_length;
29 30
}

31
#include "../sql/mysqld.cc"
32

33
C_MODE_START
serg@serg.mylan's avatar
serg@serg.mylan committed
34

35
#include <mysql.h>
hf@deer.(none)'s avatar
hf@deer.(none) committed
36
#undef ER
37
#include "errmsg.h"
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
38
#include <sql_common.h>
39
#include "embedded_priv.h"
40

41 42
extern unsigned int mysql_server_last_errno;
extern char mysql_server_last_error[MYSQL_ERRMSG_SIZE];
43 44 45
static my_bool emb_read_query_result(MYSQL *mysql);


46 47 48 49 50 51 52 53 54
extern "C" void unireg_clear(int exit_code)
{
  DBUG_ENTER("unireg_clear");
  clean_up(!opt_help && (exit_code || !opt_bootstrap)); /* purecov: inspected */
  my_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
  DBUG_VOID_RETURN;
}


55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
/*
  Reads error information from the MYSQL_DATA and puts
  it into proper MYSQL members

  SYNOPSIS
    embedded_get_error()
    mysql        connection handler
    data         query result

  NOTES
    after that function error information will be accessible
       with usual functions like mysql_error()
    data is my_free-d in this function
    most of the data is stored in data->embedded_info structure
*/

void embedded_get_error(MYSQL *mysql, MYSQL_DATA *data)
{
  NET *net= &mysql->net;
  struct embedded_query_result *ei= data->embedded_info;
75 76
  net->last_errno= ei->last_errno;
  strmake(net->last_error, ei->info, sizeof(net->last_error)-1);
77
  memcpy(net->sqlstate, ei->sqlstate, sizeof(net->sqlstate));
78
  mysql->server_status= ei->server_status;
79
  my_free(data, MYF(0));
80 81
}

82
static my_bool
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
83
emb_advanced_command(MYSQL *mysql, enum enum_server_command command,
84 85
		     const uchar *header, ulong header_length,
		     const uchar *arg, ulong arg_length, my_bool skip_check,
86
                     MYSQL_STMT *stmt)
87
{
88
  my_bool result= 1;
89
  THD *thd=(THD *) mysql->thd;
hf@deer.(none)'s avatar
hf@deer.(none) committed
90
  NET *net= &mysql->net;
91 92 93 94 95 96 97 98 99
  my_bool stmt_skip= stmt ? stmt->state != MYSQL_STMT_INIT_DONE : FALSE;

  if (!thd)
  {
    /* Do "reconnect" if possible */
    if (mysql_reconnect(mysql) || stmt_skip)
      return 1;
    thd= (THD *) mysql->thd;
  }
100

101 102 103 104
#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
  thd->profiling.start_new_query();
#endif

105
  thd->clear_data_list();
106 107 108
  /* Check that we are calling the client functions in right order */
  if (mysql->status != MYSQL_STATUS_READY)
  {
109
    set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
110 111 112 113
    return 1;
  }

  /* Clear result variables */
114
  thd->clear_error();
115
  thd->main_da.reset_diagnostics_area();
116
  mysql->affected_rows= ~(my_ulonglong) 0;
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
117
  mysql->field_count= 0;
118
  net_clear_error(net);
119
  thd->current_stmt= stmt;
120

121
  thd->store_globals();				// Fix if more than one connect
122
  lex_start(thd);
hf@deer.(none)'s avatar
hf@deer.(none) committed
123 124 125 126 127 128
  /* 
     We have to call free_old_query before we start to fill mysql->fields 
     for new query. In the case of embedded server we collect field data
     during query execution (not during data retrieval as it is in remote
     client). So we have to call free_old_query here
  */
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
129
  free_old_query(mysql);
hf@deer.(none)'s avatar
hf@deer.(none) committed
130 131 132 133

  thd->extra_length= arg_length;
  thd->extra_data= (char *)arg;
  if (header)
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
134 135 136 137 138
  {
    arg= header;
    arg_length= header_length;
  }

139
  result= dispatch_command(command, thd, (char *) arg, arg_length);
140
  thd->cur_data= 0;
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
141

hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
142
  if (!skip_check)
143
    result= thd->is_error() ? -1 : 0;
144

145 146 147
#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
  thd->profiling.finish_current_query();
#endif
148
  return result;
149 150
}

151 152
static void emb_flush_use_result(MYSQL *mysql)
{
153 154
  THD *thd= (THD*) mysql->thd;
  if (thd->cur_data)
155
  {
156 157 158 159 160 161 162
    free_rows(thd->cur_data);
    thd->cur_data= 0;
  }
  else if (thd->first_data)
  {
    MYSQL_DATA *data= thd->first_data;
    thd->first_data= data->embedded_info->next;
163 164 165 166
    free_rows(data);
  }
}

167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182

/*
  reads dataset from the next query result

  SYNOPSIS
  emb_read_rows()
  mysql		connection handle
  other parameters are not used

  NOTES
    It just gets next MYSQL_DATA from the result's queue

  RETURN
    pointer to MYSQL_DATA with the coming recordset
*/

183
static MYSQL_DATA *
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
184
emb_read_rows(MYSQL *mysql, MYSQL_FIELD *mysql_fields __attribute__((unused)),
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
185
	      unsigned int fields __attribute__((unused)))
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
186
{
187 188 189
  MYSQL_DATA *result= ((THD*)mysql->thd)->cur_data;
  ((THD*)mysql->thd)->cur_data= 0;
  if (result->embedded_info->last_errno)
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
190
  {
191 192 193 194
    embedded_get_error(mysql, result);
    return NULL;
  }
  *result->embedded_info->prev_ptr= NULL;
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
195 196 197
  return result;
}

198

199
static MYSQL_FIELD *emb_list_fields(MYSQL *mysql)
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
200
{
201 202 203 204 205 206
  MYSQL_DATA *res;
  if (emb_read_query_result(mysql))
    return 0;
  res= ((THD*) mysql->thd)->cur_data;
  ((THD*) mysql->thd)->cur_data= 0;
  mysql->field_alloc= res->alloc;
207
  my_free(res,MYF(0));
208
  mysql->status= MYSQL_STATUS_READY;
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
209 210 211
  return mysql->fields;
}

212
static my_bool emb_read_prepare_result(MYSQL *mysql, MYSQL_STMT *stmt)
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
213
{
214 215 216
  THD *thd= (THD*) mysql->thd;
  MYSQL_DATA *res;

hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
217 218
  stmt->stmt_id= thd->client_stmt_id;
  stmt->param_count= thd->client_param_count;
219
  stmt->field_count= 0;
220
  mysql->warning_count= thd->total_warn_count;
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
221

222
  if (thd->first_data)
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
223
  {
224 225 226 227 228 229
    if (emb_read_query_result(mysql))
      return 1;
    stmt->field_count= mysql->field_count;
    mysql->status= MYSQL_STATUS_READY;
    res= thd->cur_data;
    thd->cur_data= NULL;
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
230 231 232 233
    if (!(mysql->server_status & SERVER_STATUS_AUTOCOMMIT))
      mysql->server_status|= SERVER_STATUS_IN_TRANS;

    stmt->fields= mysql->fields;
234
    stmt->mem_root= res->alloc;
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
235
    mysql->fields= NULL;
236
    my_free(res,MYF(0));
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
237
  }
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
238

hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
239 240 241 242 243 244 245 246 247
  return 0;
}

/**************************************************************************
  Get column lengths of the current row
  If one uses mysql_use_result, res->lengths contains the length information,
  else the lengths are calculated from the offset between pointers.
**************************************************************************/

248 249
static void emb_fetch_lengths(ulong *to, MYSQL_ROW column,
			      unsigned int field_count)
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
250 251 252 253 254 255 256
{ 
  MYSQL_ROW end;

  for (end=column + field_count; column != end ; column++,to++)
    *to= *column ? *(uint *)((*column) - sizeof(uint)) : 0;
}

257
static my_bool emb_read_query_result(MYSQL *mysql)
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
258
{
259 260 261 262 263 264 265 266 267 268 269 270 271 272
  THD *thd= (THD*) mysql->thd;
  MYSQL_DATA *res= thd->first_data;
  DBUG_ASSERT(!thd->cur_data);
  thd->first_data= res->embedded_info->next;
  if (res->embedded_info->last_errno &&
      !res->embedded_info->fields_list)
  {
    embedded_get_error(mysql, res);
    return 1;
  }

  mysql->warning_count= res->embedded_info->warning_count;
  mysql->server_status= res->embedded_info->server_status;
  mysql->field_count= res->fields;
273 274 275 276 277
  if (!(mysql->fields= res->embedded_info->fields_list))
  {
    mysql->affected_rows= res->embedded_info->affected_rows;
    mysql->insert_id= res->embedded_info->insert_id;
  }
278
  net_clear_error(&mysql->net);
279 280 281 282 283 284 285
  mysql->info= 0;

  if (res->embedded_info->info[0])
  {
    strmake(mysql->info_buffer, res->embedded_info->info, MYSQL_ERRMSG_SIZE-1);
    mysql->info= mysql->info_buffer;
  }
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
286

287 288
  if (res->embedded_info->fields_list)
  {
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
289
    mysql->status=MYSQL_STATUS_GET_RESULT;
290 291 292
    thd->cur_data= res;
  }
  else
293
    my_free(res, MYF(0));
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
294 295 296 297

  return 0;
}

298
static int emb_stmt_execute(MYSQL_STMT *stmt)
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
299 300
{
  DBUG_ENTER("emb_stmt_execute");
301
  uchar header[5];
302
  THD *thd;
303
  my_bool res;
304

305
  int4store(header, stmt->stmt_id);
306
  header[4]= (uchar) stmt->flags;
307
  thd= (THD*)stmt->mysql->thd;
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
308
  thd->client_param_count= stmt->param_count;
hf@deer.(none)'s avatar
hf@deer.(none) committed
309
  thd->client_params= stmt->params;
310

311
  res= test(emb_advanced_command(stmt->mysql, COM_STMT_EXECUTE, 0, 0,
312
                                 header, sizeof(header), 1, stmt) ||
313
            emb_read_query_result(stmt->mysql));
314 315
  stmt->affected_rows= stmt->mysql->affected_rows;
  stmt->insert_id= stmt->mysql->insert_id;
316
  stmt->server_status= stmt->mysql->server_status;
317
  if (res)
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
318 319
  {
    NET *net= &stmt->mysql->net;
320
    set_stmt_errmsg(stmt, net);
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
321 322 323 324 325
    DBUG_RETURN(1);
  }
  DBUG_RETURN(0);
}

326
int emb_read_binary_rows(MYSQL_STMT *stmt)
hf@deer.(none)'s avatar
hf@deer.(none) committed
327
{
328 329
  MYSQL_DATA *data;
  if (!(data= emb_read_rows(stmt->mysql, 0, 0)))
330
  {
331
    set_stmt_errmsg(stmt, &stmt->mysql->net);
332
    return 1;
333
  }
334 335
  stmt->result= *data;
  my_free((char *) data, MYF(0));
336
  set_stmt_errmsg(stmt, &stmt->mysql->net);
337
  return 0;
hf@deer.(none)'s avatar
hf@deer.(none) committed
338 339
}

340 341 342 343 344 345 346 347 348 349
int emb_read_rows_from_cursor(MYSQL_STMT *stmt)
{
  MYSQL *mysql= stmt->mysql;
  THD *thd= (THD*) mysql->thd;
  MYSQL_DATA *res= thd->first_data;
  DBUG_ASSERT(!thd->first_data->embedded_info->next);
  thd->first_data= 0;
  if (res->embedded_info->last_errno)
  {
    embedded_get_error(mysql, res);
350
    set_stmt_errmsg(stmt, &mysql->net);
351 352 353 354 355 356
    return 1;
  }

  thd->cur_data= res;
  mysql->warning_count= res->embedded_info->warning_count;
  mysql->server_status= res->embedded_info->server_status;
357
  net_clear_error(&mysql->net);
358 359 360 361

  return emb_read_binary_rows(stmt);
}

362
int emb_unbuffered_fetch(MYSQL *mysql, char **row)
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
363
{
364 365 366 367 368 369 370 371
  THD *thd= (THD*) mysql->thd;
  MYSQL_DATA *data= thd->cur_data;
  if (data && data->embedded_info->last_errno)
  {
    embedded_get_error(mysql, data);
    thd->cur_data= 0;
    return 1;
  }
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
372 373 374 375 376
  if (!data || !data->data)
  {
    *row= NULL;
    if (data)
    {
377 378
      thd->cur_data= thd->first_data;
      thd->first_data= data->embedded_info->next;
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
379 380 381 382 383 384 385 386 387 388 389
      free_rows(data);
    }
  }
  else
  {
    *row= (char *)data->data->data;
    data->data= data->data->next;
  }
  return 0;
}

390
static void emb_free_embedded_thd(MYSQL *mysql)
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
391 392
{
  THD *thd= (THD*)mysql->thd;
393
  thd->clear_data_list();
hf@deer.(none)'s avatar
hf@deer.(none) committed
394
  thread_count--;
395
  thd->store_globals();
396
  thd->unlink();
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
397
  delete thd;
398
  my_pthread_setspecific_ptr(THR_THD,  0);
399
  mysql->thd=0;
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
400 401
}

konstantin@oak.local's avatar
konstantin@oak.local committed
402
static const char * emb_read_statistics(MYSQL *mysql)
hf@deer.(none)'s avatar
hf@deer.(none) committed
403 404
{
  THD *thd= (THD*)mysql->thd;
405
  return thd->is_error() ? thd->main_da.message() : "";
hf@deer.(none)'s avatar
hf@deer.(none) committed
406 407
}

408

409
static MYSQL_RES * emb_store_result(MYSQL *mysql)
410 411 412 413
{
  return mysql_store_result(mysql);
}

414 415 416 417 418 419 420
int emb_read_change_user_result(MYSQL *mysql, 
				char *buff __attribute__((unused)),
				const char *passwd __attribute__((unused)))
{
  return mysql_errno(mysql);
}

hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
421 422
MYSQL_METHODS embedded_methods= 
{
423
  emb_read_query_result,
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
424 425
  emb_advanced_command,
  emb_read_rows,
426
  emb_store_result,
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
427
  emb_fetch_lengths, 
428
  emb_flush_use_result,
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
429
  emb_list_fields,
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
430
  emb_read_prepare_result,
hf@deer.(none)'s avatar
hf@deer.(none) committed
431
  emb_stmt_execute,
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
432
  emb_read_binary_rows,
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
433
  emb_unbuffered_fetch,
hf@deer.(none)'s avatar
hf@deer.(none) committed
434
  emb_free_embedded_thd,
konstantin@oak.local's avatar
konstantin@oak.local committed
435
  emb_read_statistics,
436 437 438
  emb_read_query_result,
  emb_read_change_user_result,
  emb_read_rows_from_cursor
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
439 440
};

441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
/*
  Make a copy of array and the strings array points to
*/

char **copy_arguments(int argc, char **argv)
{
  uint length= 0;
  char **from, **res, **end= argv+argc;

  for (from=argv ; from != end ; from++)
    length+= strlen(*from);

  if ((res= (char**) my_malloc(sizeof(argv)*(argc+1)+length+argc,
			       MYF(MY_WME))))
  {
    char **to= res, *to_str= (char*) (res+argc+1);
    for (from=argv ; from != end ;)
    {
      *to++= to_str;
      to_str= strmov(to_str, *from++)+1;
    }
    *to= 0;					// Last ptr should be null
  }
  return res;
}

serg@serg.mylan's avatar
serg@serg.mylan committed
467
char **		copy_arguments_ptr= 0;
468

469
int init_embedded_server(int argc, char **argv, char **groups)
hf@genie.(none)'s avatar
hf@genie.(none) committed
470
{
471 472 473 474
  /*
    This mess is to allow people to call the init function without
    having to mess with a fake argv
   */
hf@genie.(none)'s avatar
hf@genie.(none) committed
475 476 477 478 479
  int *argcp;
  char ***argvp;
  int fake_argc = 1;
  char *fake_argv[] = { (char *)"", 0 };
  const char *fake_groups[] = { "server", "embedded", 0 };
480
  my_bool acl_error;
hf@genie.(none)'s avatar
hf@genie.(none) committed
481 482
  if (argc)
  {
483 484
    argcp= &argc;
    argvp= (char***) &argv;
hf@genie.(none)'s avatar
hf@genie.(none) committed
485 486 487
  }
  else
  {
488 489
    argcp= &fake_argc;
    argvp= (char ***) &fake_argv;
hf@genie.(none)'s avatar
hf@genie.(none) committed
490 491
  }
  if (!groups)
492
    groups= (char**) fake_groups;
hf@genie.(none)'s avatar
hf@genie.(none) committed
493

494
  my_progname= (char *)"mysql_embedded";
hf@genie.(none)'s avatar
hf@genie.(none) committed
495

496 497 498 499 500 501
  /*
    Perform basic logger initialization logger. Should be called after
    MY_INIT, as it initializes mutexes. Log tables are inited later.
  */
  logger.init_base();

hf@deer.(none)'s avatar
hf@deer.(none) committed
502
  if (init_common_variables("my", *argcp, *argvp, (const char **)groups))
hf@genie.(none)'s avatar
hf@genie.(none) committed
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
  {
    mysql_server_end();
    return 1;
  }
    
  /* Get default temporary directory */
  opt_mysql_tmpdir=getenv("TMPDIR");	/* Use this if possible */
#if defined( __WIN__) || defined(OS2)
  if (!opt_mysql_tmpdir)
    opt_mysql_tmpdir=getenv("TEMP");
  if (!opt_mysql_tmpdir)
    opt_mysql_tmpdir=getenv("TMP");
#endif
  if (!opt_mysql_tmpdir || !opt_mysql_tmpdir[0])
    opt_mysql_tmpdir=(char*) P_tmpdir;		/* purecov: inspected */

  umask(((~my_umask) & 0666));
  if (init_server_components())
  {
    mysql_server_end();
    return 1;
  }

  error_handler_hook = my_message_sql;

528
  acl_error= 0;
hf@deer.(none)'s avatar
hf@deer.(none) committed
529
#ifndef NO_EMBEDDED_ACCESS_CHECKS
530
  if (!(acl_error= acl_init(opt_noacl)) &&
531
      !opt_noacl)
532
    (void) grant_init();
533 534
#endif
  if (acl_error || my_tz_init((THD *)0, default_tz_name, opt_bootstrap))
hf@genie.(none)'s avatar
hf@genie.(none) committed
535 536 537 538
  {
    mysql_server_end();
    return 1;
  }
hf@deer.(none)'s avatar
hf@deer.(none) committed
539

hf@genie.(none)'s avatar
hf@genie.(none) committed
540 541 542 543
  init_max_user_conn();
  init_update_queries();

#ifdef HAVE_DLOPEN
hf@deer.(none)'s avatar
hf@deer.(none) committed
544
#ifndef NO_EMBEDDED_ACCESS_CHECKS
hf@genie.(none)'s avatar
hf@genie.(none) committed
545
  if (!opt_noacl)
hf@deer.(none)'s avatar
hf@deer.(none) committed
546
#endif
hf@genie.(none)'s avatar
hf@genie.(none) committed
547 548 549 550 551
    udf_init();
#endif

  (void) thr_setconcurrency(concurrency);	// 10 by default

552
  start_handle_manager();
hf@genie.(none)'s avatar
hf@genie.(none) committed
553

554 555 556 557 558
  // FIXME initialize binlog_filter and rpl_filter if not already done
  //       corresponding delete is in clean_up()
  if(!binlog_filter) binlog_filter = new Rpl_filter;
  if(!rpl_filter) rpl_filter = new Rpl_filter;

hf@deer.(none)'s avatar
hf@deer.(none) committed
559 560 561 562 563 564 565 566 567
  if (opt_init_file)
  {
    if (read_init_file(opt_init_file))
    {
      mysql_server_end();
      return 1;
    }
  }

568
  execute_ddl_log_recovery();
hf@genie.(none)'s avatar
hf@genie.(none) committed
569 570 571
  return 0;
}

572
void end_embedded_server()
573
{
574 575
  my_free((char*) copy_arguments_ptr, MYF(MY_ALLOW_ZERO_PTR));
  copy_arguments_ptr=0;
576
  clean_up(0);
tim@black.box's avatar
tim@black.box committed
577 578
}

579

580
void init_embedded_mysql(MYSQL *mysql, int client_flag)
581
{
582
  THD *thd = (THD *)mysql->thd;
583
  thd->mysql= mysql;
hf@deer.(none)'s avatar
hf@deer.(none) committed
584
  mysql->server_version= server_version;
585
  init_alloc_root(&mysql->field_alloc, 8192, 0);
586
}
587

588 589 590 591 592 593 594 595 596 597 598
/**
  @brief Initialize a new THD for a connection in the embedded server

  @param client_flag  Client capabilities which this thread supports
  @return pointer to the created THD object

  @todo
  This function copies code from several places in the server, including
  create_new_thread(), and prepare_new_connection_state().  This should
  be refactored to avoid code duplication.
*/
599
void *create_embedded_thd(int client_flag)
600 601
{
  THD * thd= new THD;
602
  thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
603

604
  thd->thread_stack= (char*) &thd;
605 606 607
  if (thd->store_globals())
  {
    fprintf(stderr,"store_globals failed.\n");
608
    goto err;
609
  }
610
  lex_start(thd);
611

612
  /* TODO - add init_connect command execution */
613

614 615
  if (thd->variables.max_join_size == HA_POS_ERROR)
    thd->options |= OPTION_BIG_SELECTS;
616 617 618 619
  thd->proc_info=0;				// Remove 'login'
  thd->command=COM_SLEEP;
  thd->version=refresh_version;
  thd->set_time();
620
  thd->init_for_queries();
621
  thd->client_capabilities= client_flag;
622
  thd->real_id= pthread_self();
623

624 625
  thd->db= NULL;
  thd->db_length= 0;
hf@deer.(none)'s avatar
hf@deer.(none) committed
626
#ifndef NO_EMBEDDED_ACCESS_CHECKS
627 628
  thd->security_ctx->db_access= DB_ACLS;
  thd->security_ctx->master_access= ~NO_ACCESS;
hf@deer.(none)'s avatar
hf@deer.(none) committed
629
#endif
630 631 632 633
  thd->cur_data= 0;
  thd->first_data= 0;
  thd->data_tail= &thd->first_data;
  bzero((char*) &thd->net, sizeof(thd->net));
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
634

hf@deer.(none)'s avatar
hf@deer.(none) committed
635
  thread_count++;
636
  threads.append(thd);
637
  return thd;
638 639 640
err:
  delete(thd);
  return NULL;
641
}
642

643

644
#ifdef NO_EMBEDDED_ACCESS_CHECKS
645
int check_embedded_connection(MYSQL *mysql, const char *db)
646
{
647
  int result;
648
  THD *thd= (THD*)mysql->thd;
649 650
  thd_init_client_charset(thd, mysql->charset->number);
  thd->update_charset();
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
651
  Security_context *sctx= thd->security_ctx;
652 653
  sctx->host_or_ip= sctx->host= (char*) my_localhost;
  strmake(sctx->priv_host, (char*) my_localhost,  MAX_HOSTNAME-1);
654
  sctx->priv_user= sctx->user= my_strdup(mysql->user, MYF(0));
655
  result= check_user(thd, COM_CONNECT, NULL, 0, db, true);
656
  net_end_statement(thd);
657 658
  emb_read_query_result(mysql);
  return result;
659 660 661
}

#else
662
int check_embedded_connection(MYSQL *mysql, const char *db)
hf@deer.(none)'s avatar
hf@deer.(none) committed
663 664
{
  THD *thd= (THD*)mysql->thd;
665
  Security_context *sctx= thd->security_ctx;
hf@deer.(none)'s avatar
hf@deer.(none) committed
666 667 668 669
  int result;
  char scramble_buff[SCRAMBLE_LENGTH];
  int passwd_len;

670 671
  thd_init_client_charset(thd, mysql->charset->number);
  thd->update_charset();
672 673
  if (mysql->options.client_ip)
  {
674 675
    sctx->host= my_strdup(mysql->options.client_ip, MYF(0));
    sctx->ip= my_strdup(sctx->host, MYF(0));
676 677
  }
  else
678 679
    sctx->host= (char*)my_localhost;
  sctx->host_or_ip= sctx->host;
hf@deer.(none)'s avatar
hf@deer.(none) committed
680

681
  if (acl_check_host(sctx->host, sctx->ip))
hf@deer.(none)'s avatar
hf@deer.(none) committed
682 683 684 685 686
  {
    result= ER_HOST_NOT_PRIVILEGED;
    goto err;
  }

687
  sctx->user= my_strdup(mysql->user, MYF(0));
hf@deer.(none)'s avatar
hf@deer.(none) committed
688 689 690 691 692 693 694 695 696 697 698
  if (mysql->passwd && mysql->passwd[0])
  {
    memset(thd->scramble, 55, SCRAMBLE_LENGTH); // dummy scramble
    thd->scramble[SCRAMBLE_LENGTH]= 0;
    scramble(scramble_buff, thd->scramble, mysql->passwd);
    passwd_len= SCRAMBLE_LENGTH;
  }
  else
    passwd_len= 0;

  if((result= check_user(thd, COM_CONNECT, 
699
			 scramble_buff, passwd_len, db, true)))
hf@deer.(none)'s avatar
hf@deer.(none) committed
700 701 702 703 704 705
     goto err;

  return 0;
err:
  {
    NET *net= &mysql->net;
706
    strmake(net->last_error, thd->main_da.message(), sizeof(net->last_error)-1);
707 708 709
    memcpy(net->sqlstate,
           mysql_errno_to_sqlstate(thd->main_da.sql_errno()),
           sizeof(net->sqlstate)-1);
hf@deer.(none)'s avatar
hf@deer.(none) committed
710 711 712 713 714
  }
  return result;
}
#endif

715
C_MODE_END
716

serg@serg.mylan's avatar
serg@serg.mylan committed
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731
void THD::clear_data_list()
{
  while (first_data)
  {
    MYSQL_DATA *data= first_data;
    first_data= data->embedded_info->next;
    free_rows(data);
  }
  data_tail= &first_data;
  free_rows(cur_data);
  cur_data= 0;
}

void THD::clear_error()
{
732 733
  if (main_da.is_error())
    main_da.reset_diagnostics_area();
serg@serg.mylan's avatar
serg@serg.mylan committed
734 735
}

736 737 738 739 740 741 742 743 744 745 746 747 748
static char *dup_str_aux(MEM_ROOT *root, const char *from, uint length,
			 CHARSET_INFO *fromcs, CHARSET_INFO *tocs)
{
  uint32 dummy32;
  uint dummy_err;
  char *result;

  /* 'tocs' is set 0 when client issues SET character_set_results=NULL */
  if (tocs && String::needs_conversion(0, fromcs, tocs, &dummy32))
  {
    uint new_len= (tocs->mbmaxlen * length) / fromcs->mbminlen + 1;
    result= (char *)alloc_root(root, new_len);
    length= copy_and_convert(result, new_len,
hf@deer.(none)'s avatar
hf@deer.(none) committed
749
                             tocs, from, length, fromcs, &dummy_err);
750 751 752 753 754 755 756 757 758 759 760 761
  }
  else
  {
    result= (char *)alloc_root(root, length + 1);
    memcpy(result, from, length);
  }

  result[length]= 0;
  return result;
}


762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
/*
  creates new result and hooks it to the list

  SYNOPSIS
  alloc_new_dataset()

  NOTES
    allocs the MYSQL_DATA + embedded_query_result couple
    to store the next query result,
    links these two and attach it to the THD::data_tail

  RETURN
    pointer to the newly created query result
*/

MYSQL_DATA *THD::alloc_new_dataset()
{
  MYSQL_DATA *data;
  struct embedded_query_result *emb_data;
  if (!my_multi_malloc(MYF(MY_WME | MY_ZEROFILL),
                       &data, sizeof(*data),
                       &emb_data, sizeof(*emb_data),
                       NULL))
    return NULL;

  emb_data->prev_ptr= &data->data;
  cur_data= data;
  *data_tail= data;
  data_tail= &emb_data->next;
  data->embedded_info= emb_data;
  return data;
}


796 797 798
/**
  Stores server_status and warning_count in the current
  query result structures.
799

800
  @param thd            current thread
801

802
  @note Should be called after we get the recordset-result.
803 804
*/

805 806 807
static
void
write_eof_packet(THD *thd, uint server_status, uint total_warn_count)
808
{
809 810
  if (!thd->mysql)            // bootstrap file handling
    return;
811 812 813 814 815 816 817
  /*
    The following test should never be true, but it's better to do it
    because if 'is_fatal_error' is set the server is not going to execute
    other queries (see the if test in dispatch_command / COM_QUERY)
  */
  if (thd->is_fatal_error)
    thd->server_status&= ~SERVER_MORE_RESULTS_EXISTS;
818
  thd->cur_data->embedded_info->server_status= server_status;
819 820 821 822 823
  /*
    Don't send warn count during SP execution, as the warn_list
    is cleared between substatements, and mysqltest gets confused
  */
  thd->cur_data->embedded_info->warning_count=
824
    (thd->spcont ? 0 : min(total_warn_count, 65535));
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854
}


/*
  allocs new query result and initialises Protocol::alloc

  SYNOPSIS
  Protocol::begin_dataset()

  RETURN
    0 if success
    1 if memory allocation failed
*/

int Protocol::begin_dataset()
{
  MYSQL_DATA *data= thd->alloc_new_dataset();
  if (!data)
    return 1;
  alloc= &data->alloc;
  init_alloc_root(alloc,8192,0);	/* Assume rowlength < 8192 */
  alloc->min_malloc=sizeof(MYSQL_ROWS);
  return 0;
}


/*
  remove last row of current recordset

  SYNOPSIS
855
  Protocol_text::remove_last_row()
856 857 858 859 860 861 862

  NOTES
    does the loop from the beginning of the current recordset to
    the last record and cuts it off.
    Not supposed to be frequently called.
*/

863
void Protocol_text::remove_last_row()
864 865 866
{
  MYSQL_DATA *data= thd->cur_data;
  MYSQL_ROWS **last_row_hook= &data->data;
867
  my_ulonglong count= data->rows;
868
  DBUG_ENTER("Protocol_text::remove_last_row");
869 870 871 872 873 874 875 876 877 878 879
  while (--count)
    last_row_hook= &(*last_row_hook)->next;

  *last_row_hook= 0;
  data->embedded_info->prev_ptr= last_row_hook;
  data->rows--;

  DBUG_VOID_RETURN;
}


monty@mysql.com's avatar
monty@mysql.com committed
880
bool Protocol::send_fields(List<Item> *list, uint flags)
hf@deer.mysql.r18.ru's avatar
hf@deer.mysql.r18.ru committed
881 882 883
{
  List_iterator_fast<Item> it(*list);
  Item                     *item;
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
884 885
  MYSQL_FIELD              *client_field;
  MEM_ROOT                 *field_alloc;
886 887
  CHARSET_INFO             *thd_cs= thd->variables.character_set_results;
  CHARSET_INFO             *cs= system_charset_info;
888
  MYSQL_DATA               *data;
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
889
  DBUG_ENTER("send_fields");
hf@deer.mysql.r18.ru's avatar
hf@deer.mysql.r18.ru committed
890

891
  if (!thd->mysql)            // bootstrap file handling
hf@deer.(none)'s avatar
hf@deer.(none) committed
892 893
    DBUG_RETURN(0);

894 895 896 897 898 899 900 901 902
  if (begin_dataset())
    goto err;

  data= thd->cur_data;
  data->fields= field_count= list->elements;
  field_alloc= &data->alloc;

  if (!(client_field= data->embedded_info->fields_list= 
	(MYSQL_FIELD*)alloc_root(field_alloc, sizeof(MYSQL_FIELD)*field_count)))
hf@deer.mysql.r18.ru's avatar
hf@deer.mysql.r18.ru committed
903 904 905 906 907 908 909
    goto err;

  while ((item= it++))
  {
    Send_field server_field;
    item->make_field(&server_field);

910 911 912 913
    /* Keep things compatible for old clients */
    if (server_field.type == MYSQL_TYPE_VARCHAR)
      server_field.type= MYSQL_TYPE_VAR_STRING;

914
    client_field->db= dup_str_aux(field_alloc, server_field.db_name,
hf@deer.(none)'s avatar
hf@deer.(none) committed
915
                                  strlen(server_field.db_name), cs, thd_cs);
916
    client_field->table= dup_str_aux(field_alloc, server_field.table_name,
hf@deer.(none)'s avatar
hf@deer.(none) committed
917
                                     strlen(server_field.table_name), cs, thd_cs);
918
    client_field->name= dup_str_aux(field_alloc, server_field.col_name,
hf@deer.(none)'s avatar
hf@deer.(none) committed
919
                                    strlen(server_field.col_name), cs, thd_cs);
920
    client_field->org_table= dup_str_aux(field_alloc, server_field.org_table_name,
hf@deer.(none)'s avatar
hf@deer.(none) committed
921
                                         strlen(server_field.org_table_name), cs, thd_cs);
922
    client_field->org_name= dup_str_aux(field_alloc, server_field.org_col_name,
hf@deer.(none)'s avatar
hf@deer.(none) committed
923
                                        strlen(server_field.org_col_name), cs, thd_cs);
924 925 926 927 928 929 930 931
    if (item->collation.collation == &my_charset_bin || thd_cs == NULL)
    {
      /* No conversion */
      client_field->charsetnr= server_field.charsetnr;
      client_field->length= server_field.length;
    }
    else
    {
932
      uint max_char_len;
933 934
      /* With conversion */
      client_field->charsetnr= thd_cs->number;
935 936 937 938 939
      max_char_len= (server_field.type >= (int) MYSQL_TYPE_TINY_BLOB &&
                     server_field.type <= (int) MYSQL_TYPE_BLOB) ?
                     server_field.length / item->collation.collation->mbminlen :
                     server_field.length / item->collation.collation->mbmaxlen;
      client_field->length= max_char_len * thd_cs->mbmaxlen;
940
    }
hf@deer.mysql.r18.ru's avatar
hf@deer.mysql.r18.ru committed
941 942 943
    client_field->type=   server_field.type;
    client_field->flags= server_field.flags;
    client_field->decimals= server_field.decimals;
944 945 946 947 948
    client_field->db_length=		strlen(client_field->db);
    client_field->table_length=		strlen(client_field->table);
    client_field->name_length=		strlen(client_field->name);
    client_field->org_name_length=	strlen(client_field->org_name);
    client_field->org_table_length=	strlen(client_field->org_table);
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
949

950
    client_field->catalog= dup_str_aux(field_alloc, "def", 3, cs, thd_cs);
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
951
    client_field->catalog_length= 3;
952

hf@deer.mysql.r18.ru's avatar
hf@deer.mysql.r18.ru committed
953 954 955
    if (INTERNAL_NUM_FIELD(client_field))
      client_field->flags|= NUM_FLAG;

956
    if (flags & (int) Protocol::SEND_DEFAULTS)
hf@deer.mysql.r18.ru's avatar
hf@deer.mysql.r18.ru committed
957 958 959 960 961
    {
      char buff[80];
      String tmp(buff, sizeof(buff), default_charset_info), *res;

      if (!(res=item->val_str(&tmp)))
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
962 963
      {
	client_field->def_length= 0;
964
	client_field->def= strmake_root(field_alloc, "",0);
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
965
      }
hf@deer.mysql.r18.ru's avatar
hf@deer.mysql.r18.ru committed
966
      else
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
967
      {
968
	client_field->def_length= res->length();
969 970
	client_field->def= strmake_root(field_alloc, res->ptr(),
					client_field->def_length);
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
971
      }
hf@deer.mysql.r18.ru's avatar
hf@deer.mysql.r18.ru committed
972 973 974 975 976 977
    }
    else
      client_field->def=0;
    client_field->max_length= 0;
    ++client_field;
  }
978 979

  if (flags & SEND_EOF)
980
    write_eof_packet(thd, thd->server_status, thd->total_warn_count);
hf@deer.mysql.r18.ru's avatar
hf@deer.mysql.r18.ru committed
981

hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
982
  DBUG_RETURN(prepare_for_send(list));
hf@deer.mysql.r18.ru's avatar
hf@deer.mysql.r18.ru committed
983
 err:
bell@sanja.is.com.ua's avatar
bell@sanja.is.com.ua committed
984
  my_error(ER_OUT_OF_RESOURCES, MYF(0));        /* purecov: inspected */
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
985
  DBUG_RETURN(1);				/* purecov: inspected */
hf@deer.mysql.r18.ru's avatar
hf@deer.mysql.r18.ru committed
986 987
}

hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
988
bool Protocol::write()
hf@genie.(none)'s avatar
hf@genie.(none) committed
989
{
hf@deer.(none)'s avatar
hf@deer.(none) committed
990 991 992
  if (!thd->mysql)            // bootstrap file handling
    return false;

hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
993 994
  *next_field= 0;
  return false;
hf@genie.(none)'s avatar
hf@genie.(none) committed
995
}
996

997
bool Protocol_binary::write()
hf@deer.(none)'s avatar
hf@deer.(none) committed
998 999
{
  MYSQL_ROWS *cur;
1000
  MYSQL_DATA *data= thd->cur_data;
hf@deer.(none)'s avatar
hf@deer.(none) committed
1001 1002

  data->rows++;
1003 1004
  if (!(cur= (MYSQL_ROWS *)alloc_root(alloc,
                                      sizeof(MYSQL_ROWS)+packet->length())))
hf@deer.(none)'s avatar
hf@deer.(none) committed
1005 1006 1007 1008 1009
  {
    my_error(ER_OUT_OF_RESOURCES,MYF(0));
    return true;
  }
  cur->data= (MYSQL_ROW)(((char *)cur) + sizeof(MYSQL_ROWS));
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
1010
  memcpy(cur->data, packet->ptr()+1, packet->length()-1);
1011
  cur->length= packet->length();       /* To allow us to do sanity checks */
hf@deer.(none)'s avatar
hf@deer.(none) committed
1012

1013 1014
  *data->embedded_info->prev_ptr= cur;
  data->embedded_info->prev_ptr= &cur->next;
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
1015 1016
  cur->next= 0;
  
hf@deer.(none)'s avatar
hf@deer.(none) committed
1017 1018 1019
  return false;
}

1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037

/**
  Embedded library implementation of OK response.

  This function is used by the server to write 'OK' packet to
  the "network" when the server is compiled as an embedded library.
  Since there is no network in the embedded configuration,
  a different implementation is necessary.
  Instead of marshalling response parameters to a network representation
  and then writing it to the socket, here we simply copy the data to the
  corresponding client-side connection structures. 

  @sa Server implementation of net_send_ok in protocol.cc for
  description of the arguments.

  @return The function does not return errors.
*/

1038
void
1039 1040 1041
net_send_ok(THD *thd,
            uint server_status, uint total_warn_count,
            ha_rows affected_rows, ulonglong id, const char *message)
1042
{
1043
  DBUG_ENTER("emb_net_send_ok");
1044 1045
  MYSQL_DATA *data;
  MYSQL *mysql= thd->mysql;
1046

hf@deer.(none)'s avatar
hf@deer.(none) committed
1047 1048
  if (!mysql)            // bootstrap file handling
    DBUG_VOID_RETURN;
1049 1050 1051 1052
  if (!(data= thd->alloc_new_dataset()))
    return;
  data->embedded_info->affected_rows= affected_rows;
  data->embedded_info->insert_id= id;
1053
  if (message)
1054 1055 1056
    strmake(data->embedded_info->info, message,
            sizeof(data->embedded_info->info)-1);

1057
  write_eof_packet(thd, server_status, total_warn_count);
1058
  thd->cur_data= 0;
1059 1060 1061
  DBUG_VOID_RETURN;
}

1062 1063 1064 1065 1066 1067 1068 1069 1070

/**
  Embedded library implementation of EOF response.

  @sa net_send_ok

  @return This function does not return errors.
*/

1071
void
1072
net_send_eof(THD *thd, uint server_status, uint total_warn_count)
1073
{
1074
  write_eof_packet(thd, server_status, total_warn_count);
1075
  thd->cur_data= 0;
1076 1077
}

1078 1079 1080 1081 1082 1083 1084 1085 1086

void net_send_error_packet(THD *thd, uint sql_errno, const char *err)
{
  MYSQL_DATA *data= thd->cur_data ? thd->cur_data : thd->alloc_new_dataset();
  struct embedded_query_result *ei= data->embedded_info;

  ei->last_errno= sql_errno;
  strmake(ei->info, err, sizeof(ei->info)-1);
  strmov(ei->sqlstate, mysql_errno_to_sqlstate(sql_errno));
1087
  ei->server_status= thd->server_status;
1088 1089 1090 1091
  thd->cur_data= 0;
}


1092
void Protocol_text::prepare_for_resend()
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
1093
{
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
1094
  MYSQL_ROWS *cur;
1095
  MYSQL_DATA *data= thd->cur_data;
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
1096 1097
  DBUG_ENTER("send_data");

1098 1099 1100
  if (!thd->mysql)            // bootstrap file handling
    DBUG_VOID_RETURN;

hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
1101
  data->rows++;
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
1102 1103 1104 1105 1106 1107 1108
  if (!(cur= (MYSQL_ROWS *)alloc_root(alloc, sizeof(MYSQL_ROWS)+(field_count + 1) * sizeof(char *))))
  {
    my_error(ER_OUT_OF_RESOURCES,MYF(0));
    DBUG_VOID_RETURN;
  }
  cur->data= (MYSQL_ROW)(((char *)cur) + sizeof(MYSQL_ROWS));

1109 1110
  *data->embedded_info->prev_ptr= cur;
  data->embedded_info->prev_ptr= &cur->next;
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
1111
  next_field=cur->data;
1112
  next_mysql_field= data->embedded_info->fields_list;
1113 1114 1115
#ifndef DBUG_OFF
  field_pos= 0;
#endif
1116

hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
1117 1118 1119
  DBUG_VOID_RETURN;
}

1120
bool Protocol_text::store_null()
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
1121 1122 1123 1124 1125 1126
{
  *(next_field++)= NULL;
  ++next_mysql_field;
  return false;
}

1127
bool Protocol::net_store_data(const uchar *from, size_t length)
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
1128
{
hf@deer.(none)'s avatar
hf@deer.(none) committed
1129
  char *field_buf;
hf@deer.(none)'s avatar
hf@deer.(none) committed
1130
  if (!thd->mysql)            // bootstrap file handling
1131
    return FALSE;
hf@deer.(none)'s avatar
hf@deer.(none) committed
1132

1133 1134
  if (!(field_buf= (char*) alloc_root(alloc, length + sizeof(uint) + 1)))
    return TRUE;
hf@deer.(none)'s avatar
hf@deer.(none) committed
1135 1136
  *(uint *)field_buf= length;
  *next_field= field_buf + sizeof(uint);
1137
  memcpy((uchar*) *next_field, from, length);
hf@deer.(none)'s avatar
SCRUM  
hf@deer.(none) committed
1138
  (*next_field)[length]= 0;
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
1139 1140 1141 1142
  if (next_mysql_field->max_length < length)
    next_mysql_field->max_length=length;
  ++next_field;
  ++next_mysql_field;
1143
  return FALSE;
hf@deer.mysql.r18.ru's avatar
SCRUM  
hf@deer.mysql.r18.ru committed
1144 1145
}

1146 1147 1148
#if defined(_MSC_VER) && _MSC_VER < 1400
#define vsnprintf _vsnprintf
#endif
1149

1150
int vprint_msg_to_log(enum loglevel level __attribute__((unused)),
1151 1152 1153 1154 1155
                       const char *format, va_list argsi)
{
  vsnprintf(mysql_server_last_error, sizeof(mysql_server_last_error),
           format, argsi);
  mysql_server_last_errno= CR_UNKNOWN_ERROR;
1156
  return 0;
1157
}