~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: Mats Kindahl
  • Date: 2008-08-25 11:54:47 UTC
  • mto: (489.1.2 codestyle)
  • mto: This revision was merged to the branch mainline in revision 372.
  • Revision ID: mats@mysql.com-20080825115447-tg73zkyjnldm7p4c
Hiding THD::proc_info field and providing a setter and getter.
Replacing use of swap_variables() in C++ code with std::swap().
Moving swap_variables() into C files where it is used.
Replacing some function-like macros with inline functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
#define MYSQL_LEX 1
17
 
#include "mysql_priv.h"
 
17
#include <drizzled/server_includes.h>
18
18
#include "sql_repl.h"
19
19
#include "rpl_filter.h"
20
20
#include "repl_failsafe.h"
21
 
#include <m_ctype.h>
22
 
#include <myisam.h>
23
 
#include <my_dir.h>
 
21
#include <drizzled/drizzled_error_messages.h>
24
22
 
25
23
/**
26
24
  @defgroup Runtime_Environment Runtime Environment
27
25
  @{
28
26
*/
29
27
 
30
 
static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables);
31
28
 
32
29
const char *any_db="*any*";     // Special symbol for check_access
33
30
 
34
 
const LEX_STRING command_name[]={
 
31
const LEX_STRING command_name[COM_END+1]={
35
32
  { C_STRING_WITH_LEN("Sleep") },
36
33
  { C_STRING_WITH_LEN("Quit") },
37
34
  { C_STRING_WITH_LEN("Init DB") },
41
38
  { C_STRING_WITH_LEN("Drop DB") },
42
39
  { C_STRING_WITH_LEN("Refresh") },
43
40
  { C_STRING_WITH_LEN("Shutdown") },
44
 
  { C_STRING_WITH_LEN("Statistics") },
45
41
  { C_STRING_WITH_LEN("Processlist") },
46
42
  { C_STRING_WITH_LEN("Connect") },
47
43
  { C_STRING_WITH_LEN("Kill") },
48
 
  { C_STRING_WITH_LEN("Debug") },
49
44
  { C_STRING_WITH_LEN("Ping") },
50
45
  { C_STRING_WITH_LEN("Time") },
51
 
  { C_STRING_WITH_LEN("Delayed insert") },
52
46
  { C_STRING_WITH_LEN("Change user") },
53
47
  { C_STRING_WITH_LEN("Binlog Dump") },
54
 
  { C_STRING_WITH_LEN("Table Dump") },
55
48
  { C_STRING_WITH_LEN("Connect Out") },
56
49
  { C_STRING_WITH_LEN("Register Slave") },
57
 
  { C_STRING_WITH_LEN("Prepare") },
58
 
  { C_STRING_WITH_LEN("Execute") },
59
 
  { C_STRING_WITH_LEN("Long Data") },
60
 
  { C_STRING_WITH_LEN("Close stmt") },
61
 
  { C_STRING_WITH_LEN("Reset stmt") },
62
50
  { C_STRING_WITH_LEN("Set option") },
63
 
  { C_STRING_WITH_LEN("Fetch") },
64
51
  { C_STRING_WITH_LEN("Daemon") },
65
52
  { C_STRING_WITH_LEN("Error") }  // Last command number
66
53
};
83
70
bool end_active_trans(THD *thd)
84
71
{
85
72
  int error=0;
86
 
  DBUG_ENTER("end_active_trans");
87
73
  if (unlikely(thd->in_sub_stmt))
88
74
  {
89
75
    my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
90
 
    DBUG_RETURN(1);
 
76
    return(1);
91
77
  }
92
78
  if (thd->transaction.xid_state.xa_state != XA_NOTR)
93
79
  {
94
80
    my_error(ER_XAER_RMFAIL, MYF(0),
95
81
             xa_state_names[thd->transaction.xid_state.xa_state]);
96
 
    DBUG_RETURN(1);
 
82
    return(1);
97
83
  }
98
84
  if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN |
99
85
                      OPTION_TABLE_LOCK))
100
86
  {
101
 
    DBUG_PRINT("info",("options: 0x%llx", thd->options));
102
87
    /* Safety if one did "drop table" on locked tables */
103
88
    if (!thd->locked_tables)
104
89
      thd->options&= ~OPTION_TABLE_LOCK;
107
92
      error=1;
108
93
  }
109
94
  thd->options&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
110
 
  thd->transaction.all.modified_non_trans_table= FALSE;
111
 
  DBUG_RETURN(error);
 
95
  thd->transaction.all.modified_non_trans_table= false;
 
96
  return(error);
112
97
}
113
98
 
114
99
 
139
124
  return error;
140
125
}
141
126
 
142
 
#ifdef HAVE_REPLICATION
143
127
/**
144
128
  Returns true if all tables should be ignored.
145
129
*/
148
132
  return rpl_filter->is_on() && tables &&
149
133
         !rpl_filter->tables_ok(thd->db, tables);
150
134
}
151
 
#endif
152
135
 
153
136
 
154
137
static bool some_non_temp_table_to_be_updated(THD *thd, TABLE_LIST *tables)
155
138
{
156
139
  for (TABLE_LIST *table= tables; table; table= table->next_global)
157
140
  {
158
 
    DBUG_ASSERT(table->db && table->table_name);
 
141
    assert(table->db && table->table_name);
159
142
    if (table->updating &&
160
143
        !find_temporary_table(thd, table->db, table->table_name))
161
144
      return 1;
181
164
 
182
165
void init_update_queries(void)
183
166
{
184
 
  bzero((uchar*) &sql_command_flags, sizeof(sql_command_flags));
 
167
  memset(&sql_command_flags, 0, sizeof(sql_command_flags));
185
168
 
186
169
  sql_command_flags[SQLCOM_CREATE_TABLE]=   CF_CHANGES_DATA;
187
170
  sql_command_flags[SQLCOM_CREATE_INDEX]=   CF_CHANGES_DATA;
211
194
  sql_command_flags[SQLCOM_SHOW_VARIABLES]=   CF_STATUS_COMMAND;
212
195
  sql_command_flags[SQLCOM_SHOW_CHARSETS]=    CF_STATUS_COMMAND;
213
196
  sql_command_flags[SQLCOM_SHOW_COLLATIONS]=  CF_STATUS_COMMAND;
214
 
  sql_command_flags[SQLCOM_SHOW_NEW_MASTER]= CF_STATUS_COMMAND;
215
197
  sql_command_flags[SQLCOM_SHOW_BINLOGS]= CF_STATUS_COMMAND;
216
198
  sql_command_flags[SQLCOM_SHOW_SLAVE_HOSTS]= CF_STATUS_COMMAND;
217
199
  sql_command_flags[SQLCOM_SHOW_BINLOG_EVENTS]= CF_STATUS_COMMAND;
218
200
  sql_command_flags[SQLCOM_SHOW_WARNS]= CF_STATUS_COMMAND;
219
201
  sql_command_flags[SQLCOM_SHOW_ERRORS]= CF_STATUS_COMMAND;
220
202
  sql_command_flags[SQLCOM_SHOW_ENGINE_STATUS]= CF_STATUS_COMMAND;
221
 
  sql_command_flags[SQLCOM_SHOW_ENGINE_MUTEX]= CF_STATUS_COMMAND;
222
 
  sql_command_flags[SQLCOM_SHOW_ENGINE_LOGS]= CF_STATUS_COMMAND;
223
203
  sql_command_flags[SQLCOM_SHOW_PROCESSLIST]= CF_STATUS_COMMAND;
224
204
  sql_command_flags[SQLCOM_SHOW_CREATE_DB]=  CF_STATUS_COMMAND;
225
205
  sql_command_flags[SQLCOM_SHOW_CREATE]=  CF_STATUS_COMMAND;
230
210
                                               CF_SHOW_TABLE_COMMAND);
231
211
  sql_command_flags[SQLCOM_SHOW_TABLE_STATUS]= (CF_STATUS_COMMAND |
232
212
                                                CF_SHOW_TABLE_COMMAND);
233
 
 
234
 
  /*
235
 
    The following is used to preserver CF_ROW_COUNT during the
236
 
    a CALL or EXECUTE statement, so the value generated by the
237
 
    last called (or executed) statement is preserved.
238
 
    See mysql_execute_command() for how CF_ROW_COUNT is used.
239
 
  */
240
 
  sql_command_flags[SQLCOM_EXECUTE]=            CF_HAS_ROW_COUNT;
241
 
 
242
213
  /*
243
214
    The following admin table operations are allowed
244
215
    on log tables.
251
222
 
252
223
bool is_update_query(enum enum_sql_command command)
253
224
{
254
 
  DBUG_ASSERT(command >= 0 && command <= SQLCOM_END);
 
225
  assert(command >= 0 && command <= SQLCOM_END);
255
226
  return (sql_command_flags[command] & CF_CHANGES_DATA) != 0;
256
227
}
257
228
 
269
240
  */
270
241
  rw_rdlock(var_mutex);
271
242
  save_client_capabilities= thd->client_capabilities;
272
 
  thd->client_capabilities|= CLIENT_MULTI_QUERIES;
 
243
  thd->client_capabilities|= CLIENT_MULTI_STATEMENTS;
273
244
  /*
274
245
    We don't need return result of execution to client side.
275
246
    To forbid this we should set thd->net.vio to 0.
284
255
  thd->net.vio= save_vio;
285
256
}
286
257
 
287
 
 
288
 
/**
289
 
  Execute commands from bootstrap_file.
290
 
 
291
 
  Used when creating the initial grant tables.
292
 
*/
293
 
 
294
 
pthread_handler_t handle_bootstrap(void *arg)
295
 
{
296
 
  THD *thd=(THD*) arg;
297
 
  FILE *file=bootstrap_file;
298
 
  char *buff;
299
 
  const char* found_semicolon= NULL;
300
 
 
301
 
  /* The following must be called before DBUG_ENTER */
302
 
  thd->thread_stack= (char*) &thd;
303
 
  if (my_thread_init() || thd->store_globals())
304
 
  {
305
 
    close_connection(thd, ER_OUT_OF_RESOURCES, 1);
306
 
    thd->fatal_error();
307
 
    goto end;
308
 
  }
309
 
  DBUG_ENTER("handle_bootstrap");
310
 
 
311
 
  pthread_detach_this_thread();
312
 
  thd->thread_stack= (char*) &thd;
313
 
 
314
 
  if (thd->variables.max_join_size == HA_POS_ERROR)
315
 
    thd->options |= OPTION_BIG_SELECTS;
316
 
 
317
 
  thd_proc_info(thd, 0);
318
 
  thd->version=refresh_version;
319
 
  thd->security_ctx->priv_user=
320
 
    thd->security_ctx->user= (char*) my_strdup("boot", MYF(MY_WME));
321
 
  thd->security_ctx->priv_host[0]=0;
322
 
  /*
323
 
    Make the "client" handle multiple results. This is necessary
324
 
    to enable stored procedures with SELECTs and Dynamic SQL
325
 
    in init-file.
326
 
  */
327
 
  thd->client_capabilities|= CLIENT_MULTI_RESULTS;
328
 
 
329
 
  buff= (char*) thd->net.buff;
330
 
  thd->init_for_queries();
331
 
  while (fgets(buff, thd->net.max_packet, file))
332
 
  {
333
 
    /* strlen() can't be deleted because fgets() doesn't return length */
334
 
    ulong length= (ulong) strlen(buff);
335
 
    while (buff[length-1] != '\n' && !feof(file))
336
 
    {
337
 
      /*
338
 
        We got only a part of the current string. Will try to increase
339
 
        net buffer then read the rest of the current string.
340
 
      */
341
 
      /* purecov: begin tested */
342
 
      if (net_realloc(&(thd->net), 2 * thd->net.max_packet))
343
 
      {
344
 
        net_end_statement(thd);
345
 
        bootstrap_error= 1;
346
 
        break;
347
 
      }
348
 
      buff= (char*) thd->net.buff;
349
 
      fgets(buff + length, thd->net.max_packet - length, file);
350
 
      length+= (ulong) strlen(buff + length);
351
 
      /* purecov: end */
352
 
    }
353
 
    if (bootstrap_error)
354
 
      break;                                    /* purecov: inspected */
355
 
 
356
 
    while (length && (my_isspace(thd->charset(), buff[length-1]) ||
357
 
                      buff[length-1] == ';'))
358
 
      length--;
359
 
    buff[length]=0;
360
 
 
361
 
    /* Skip lines starting with delimiter */
362
 
    if (strncmp(buff, STRING_WITH_LEN("delimiter")) == 0)
363
 
      continue;
364
 
 
365
 
    thd->query_length=length;
366
 
    thd->query= (char*) thd->memdup_w_gap(buff, length+1, 
367
 
                                          thd->db_length+1);
368
 
    thd->query[length] = '\0';
369
 
    DBUG_PRINT("query",("%-.4096s",thd->query));
370
 
 
371
 
    /*
372
 
      We don't need to obtain LOCK_thread_count here because in bootstrap
373
 
      mode we have only one thread.
374
 
    */
375
 
    thd->query_id=next_query_id();
376
 
    thd->set_time();
377
 
    mysql_parse(thd, thd->query, length, & found_semicolon);
378
 
    close_thread_tables(thd);                   // Free tables
379
 
 
380
 
    bootstrap_error= thd->is_error();
381
 
    net_end_statement(thd);
382
 
 
383
 
    if (bootstrap_error)
384
 
      break;
385
 
 
386
 
    free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
387
 
    free_root(&thd->transaction.mem_root,MYF(MY_KEEP_PREALLOC));
388
 
  }
389
 
 
390
 
end:
391
 
  net_end(&thd->net);
392
 
  thd->cleanup();
393
 
  delete thd;
394
 
 
395
 
  (void) pthread_mutex_lock(&LOCK_thread_count);
396
 
  thread_count--;
397
 
  (void) pthread_mutex_unlock(&LOCK_thread_count);
398
 
  (void) pthread_cond_broadcast(&COND_thread_count);
399
 
  my_thread_end();
400
 
  pthread_exit(0);
401
 
  DBUG_RETURN(0);
402
 
}
403
 
 
404
 
/* This works because items are allocated with sql_alloc() */
405
 
 
406
 
void free_items(Item *item)
407
 
{
408
 
  Item *next;
409
 
  DBUG_ENTER("free_items");
410
 
  for (; item ; item=next)
411
 
  {
412
 
    next=item->next;
413
 
    item->delete_self();
414
 
  }
415
 
  DBUG_VOID_RETURN;
416
 
}
417
 
 
418
 
/* This works because items are allocated with sql_alloc() */
419
 
 
420
 
void cleanup_items(Item *item)
421
 
{
422
 
  DBUG_ENTER("cleanup_items");
423
 
  for (; item ; item=item->next)
424
 
    item->cleanup();
425
 
  DBUG_VOID_RETURN;
426
 
}
427
 
 
428
258
/**
429
259
  Ends the current transaction and (maybe) begin the next.
430
260
 
439
269
{
440
270
  bool do_release= 0;
441
271
  int res= 0;
442
 
  DBUG_ENTER("end_trans");
443
272
 
444
273
  if (unlikely(thd->in_sub_stmt))
445
274
  {
446
275
    my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
447
 
    DBUG_RETURN(1);
 
276
    return(1);
448
277
  }
449
278
  if (thd->transaction.xid_state.xa_state != XA_NOTR)
450
279
  {
451
280
    my_error(ER_XAER_RMFAIL, MYF(0),
452
281
             xa_state_names[thd->transaction.xid_state.xa_state]);
453
 
    DBUG_RETURN(1);
 
282
    return(1);
454
283
  }
455
284
  switch (completion) {
456
285
  case COMMIT:
462
291
    thd->server_status&= ~SERVER_STATUS_IN_TRANS;
463
292
    res= ha_commit(thd);
464
293
    thd->options&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
465
 
    thd->transaction.all.modified_non_trans_table= FALSE;
 
294
    thd->transaction.all.modified_non_trans_table= false;
466
295
    break;
467
296
  case COMMIT_RELEASE:
468
297
    do_release= 1; /* fall through */
480
309
    if (ha_rollback(thd))
481
310
      res= -1;
482
311
    thd->options&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
483
 
    thd->transaction.all.modified_non_trans_table= FALSE;
 
312
    thd->transaction.all.modified_non_trans_table= false;
484
313
    if (!res && (completion == ROLLBACK_AND_CHAIN))
485
314
      res= begin_trans(thd);
486
315
    break;
488
317
  default:
489
318
    res= -1;
490
319
    my_error(ER_UNKNOWN_COM_ERROR, MYF(0));
491
 
    DBUG_RETURN(-1);
 
320
    return(-1);
492
321
  }
493
322
 
494
323
  if (res < 0)
496
325
  else if ((res == 0) && do_release)
497
326
    thd->killed= THD::KILL_CONNECTION;
498
327
 
499
 
  DBUG_RETURN(res);
 
328
  return(res);
500
329
}
501
330
 
502
331
 
519
348
  ulong packet_length;
520
349
  NET *net= &thd->net;
521
350
  enum enum_server_command command;
522
 
  DBUG_ENTER("do_command");
523
351
 
524
352
  /*
525
353
    indicator of uninitialized lex => normal flow of errors handling
547
375
  packet_length= my_net_read(net);
548
376
  if (packet_length == packet_error)
549
377
  {
550
 
    DBUG_PRINT("info",("Got error %d reading command from socket %s",
551
 
                       net->error,
552
 
                       vio_description(net->vio)));
553
 
 
554
378
    /* Check if we can continue without closing the connection */
555
379
 
556
380
    /* The error must be set. */
557
 
    DBUG_ASSERT(thd->is_error());
 
381
    assert(thd->is_error());
558
382
    net_end_statement(thd);
559
383
 
560
384
    if (net->error != 3)
561
385
    {
562
 
      return_value= TRUE;                       // We have to close it.
 
386
      return_value= true;                       // We have to close it.
563
387
      goto out;
564
388
    }
565
389
 
566
390
    net->error= 0;
567
 
    return_value= FALSE;
 
391
    return_value= false;
568
392
    goto out;
569
393
  }
570
394
 
591
415
  if (command >= COM_END)
592
416
    command= COM_END;                           // Wrong command
593
417
 
594
 
  DBUG_PRINT("info",("Command on %s = %d (%s)",
595
 
                     vio_description(net->vio), command,
596
 
                     command_name[command].str));
597
 
 
598
418
  /* Restore read timeout value */
599
419
  my_net_set_read_timeout(net, thd->variables.net_read_timeout);
600
420
 
601
 
  DBUG_ASSERT(packet_length);
 
421
  assert(packet_length);
602
422
  return_value= dispatch_command(command, thd, packet+1, (uint) (packet_length-1));
603
423
 
604
424
out:
605
 
  DBUG_RETURN(return_value);
 
425
  return(return_value);
606
426
}
607
427
 
608
428
/**
616
436
  @see mysql_execute_command
617
437
 
618
438
  @returns Status code
619
 
    @retval TRUE The statement should be denied.
620
 
    @retval FALSE The statement isn't updating any relevant tables.
 
439
    @retval true The statement should be denied.
 
440
    @retval false The statement isn't updating any relevant tables.
621
441
*/
622
442
 
623
 
static my_bool deny_updates_if_read_only_option(THD *thd,
 
443
static bool deny_updates_if_read_only_option(THD *thd,
624
444
                                                TABLE_LIST *all_tables)
625
445
{
626
 
  DBUG_ENTER("deny_updates_if_read_only_option");
627
 
 
628
446
  if (!opt_readonly)
629
 
    DBUG_RETURN(FALSE);
 
447
    return(false);
630
448
 
631
449
  LEX *lex= thd->lex;
632
450
 
633
451
  if (!(sql_command_flags[lex->sql_command] & CF_CHANGES_DATA))
634
 
    DBUG_RETURN(FALSE);
 
452
    return(false);
635
453
 
636
454
  /* Multi update is an exception and is dealt with later. */
637
455
  if (lex->sql_command == SQLCOM_UPDATE_MULTI)
638
 
    DBUG_RETURN(FALSE);
 
456
    return(false);
639
457
 
640
 
  const my_bool create_temp_tables= 
 
458
  const bool create_temp_tables= 
641
459
    (lex->sql_command == SQLCOM_CREATE_TABLE) &&
642
460
    (lex->create_info.options & HA_LEX_CREATE_TMP_TABLE);
643
461
 
644
 
  const my_bool drop_temp_tables= 
 
462
  const bool drop_temp_tables= 
645
463
    (lex->sql_command == SQLCOM_DROP_TABLE) &&
646
464
    lex->drop_temporary;
647
465
 
648
 
  const my_bool update_real_tables=
 
466
  const bool update_real_tables=
649
467
    some_non_temp_table_to_be_updated(thd, all_tables) &&
650
468
    !(create_temp_tables || drop_temp_tables);
651
469
 
652
470
 
653
 
  const my_bool create_or_drop_databases=
 
471
  const bool create_or_drop_databases=
654
472
    (lex->sql_command == SQLCOM_CREATE_DB) ||
655
473
    (lex->sql_command == SQLCOM_DROP_DB);
656
474
 
659
477
      /*
660
478
        An attempt was made to modify one or more non-temporary tables.
661
479
      */
662
 
      DBUG_RETURN(TRUE);
 
480
      return(true);
663
481
  }
664
482
 
665
483
 
666
484
  /* Assuming that only temporary tables are modified. */
667
 
  DBUG_RETURN(FALSE);
 
485
  return(false);
668
486
}
669
487
 
670
488
/**
693
511
{
694
512
  NET *net= &thd->net;
695
513
  bool error= 0;
696
 
  DBUG_ENTER("dispatch_command");
697
 
  DBUG_PRINT("info",("packet: '%*.s'; command: %d", packet_length, packet, command));
698
514
 
699
515
  thd->command=command;
700
516
  /*
701
517
    Commands which always take a long time are logged into
702
518
    the slow log only if opt_log_slow_admin_statements is set.
703
519
  */
704
 
  thd->enable_slow_log= TRUE;
 
520
  thd->enable_slow_log= true;
705
521
  thd->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
706
522
  thd->set_time();
707
523
  VOID(pthread_mutex_lock(&LOCK_thread_count));
709
525
 
710
526
  switch( command ) {
711
527
  /* Ignore these statements. */
712
 
  case COM_STATISTICS:
713
528
  case COM_PING:
714
529
    break;
715
 
  /* Only increase id on these statements but don't count them. */
716
 
  case COM_STMT_PREPARE: 
717
 
  case COM_STMT_CLOSE:
718
 
  case COM_STMT_RESET:
719
 
    next_query_id();
720
 
    break;
721
530
  /* Increase id and count all other statements. */
722
531
  default:
723
532
    statistic_increment(thd->status_var.questions, &LOCK_status);
737
546
    status_var_increment(thd->status_var.com_stat[SQLCOM_CHANGE_DB]);
738
547
    thd->convert_string(&tmp, system_charset_info,
739
548
                        packet, packet_length, thd->charset());
740
 
    if (!mysql_change_db(thd, &tmp, FALSE))
 
549
    if (!mysql_change_db(thd, &tmp, false))
741
550
    {
742
551
      general_log_write(thd, command, thd->db, thd->db_length);
743
552
      my_ok(thd);
757
566
    /* Safe because there is always a trailing \0 at the end of the packet */
758
567
    char *passwd= strend(user)+1;
759
568
 
 
569
 
760
570
    thd->clear_error();                         // if errors from rollback
761
571
 
762
572
    /*
832
642
 
833
643
    /* Clear variables that are allocated */
834
644
    thd->user_connect= 0;
835
 
    thd->security_ctx->priv_user= thd->security_ctx->user;
836
 
    res= check_user(thd, COM_CHANGE_USER, passwd, passwd_len, db, FALSE);
 
645
    res= check_user(thd, COM_CHANGE_USER, passwd, passwd_len, db, false);
837
646
 
838
647
    if (res)
839
648
    {
856
665
    }
857
666
    break;
858
667
  }
859
 
  case COM_STMT_EXECUTE:
860
 
  case COM_STMT_FETCH:
861
 
  case COM_STMT_SEND_LONG_DATA:
862
 
  case COM_STMT_PREPARE:
863
 
  case COM_STMT_CLOSE:
864
 
  case COM_STMT_RESET:
865
 
  {
866
 
    /* We should toss an error here */
867
 
    break;
868
 
  }
869
668
  case COM_QUERY:
870
669
  {
871
670
    if (alloc_query(thd, packet, packet_length))
872
671
      break;                                    // fatal error is set
873
672
    char *packet_end= thd->query + thd->query_length;
874
 
    /* 'b' stands for 'buffer' parameter', special for 'my_snprintf' */
875
673
    const char* end_of_stmt= NULL;
876
674
 
877
675
    general_log_write(thd, command, thd->query, thd->query_length);
878
 
    DBUG_PRINT("query",("%-.4096s",thd->query));
879
 
 
880
 
    if (!(specialflag & SPECIAL_NO_PRIOR))
881
 
    {
882
 
      struct sched_param tmp_sched_param;
883
 
 
884
 
      memset(&tmp_sched_param, 0, sizeof(tmp_sched_param));
885
 
      tmp_sched_param.sched_priority= QUERY_PRIOR;
886
 
      (void)pthread_setschedparam(pthread_self(), SCHED_OTHER, &tmp_sched_param);
887
 
    }
888
676
 
889
677
    mysql_parse(thd, thd->query, thd->query_length, &end_of_stmt);
890
678
 
922
710
 
923
711
      mysql_parse(thd, beginning_of_next_stmt, length, &end_of_stmt);
924
712
    }
925
 
 
926
 
    if (!(specialflag & SPECIAL_NO_PRIOR))
927
 
    {
928
 
      struct sched_param tmp_sched_param;
929
 
 
930
 
      memset(&tmp_sched_param, 0, sizeof(tmp_sched_param));
931
 
      tmp_sched_param.sched_priority= WAIT_PRIOR;
932
 
      (void)pthread_setschedparam(pthread_self(), SCHED_OTHER, &tmp_sched_param);
933
 
    }
934
 
    DBUG_PRINT("info",("query ready"));
935
713
    break;
936
714
  }
937
715
  case COM_FIELD_LIST:                          // This isn't actually needed
945
723
    lex_start(thd);
946
724
 
947
725
    status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_FIELDS]);
948
 
    bzero((char*) &table_list,sizeof(table_list));
 
726
    memset(&table_list, 0, sizeof(table_list));
949
727
    if (thd->copy_db_to(&table_list.db, &table_list.db_length))
950
728
      break;
951
729
    /*
995
773
    general_log_print(thd, command, NullS);
996
774
    net->error=0;                               // Don't give 'abort' message
997
775
    thd->main_da.disable_status();              // Don't send anything back
998
 
    error=TRUE;                                 // End server
 
776
    error=true;                                 // End server
999
777
    break;
1000
778
  case COM_BINLOG_DUMP:
1001
779
    {
1002
780
      ulong pos;
1003
781
      ushort flags;
1004
 
      uint32 slave_server_id;
 
782
      uint32_t slave_server_id;
1005
783
 
1006
784
      status_var_increment(thd->status_var.com_other);
1007
785
      thd->enable_slow_log= opt_log_slow_admin_statements;
1018
796
      mysql_binlog_send(thd, thd->strdup(packet + 10), (my_off_t) pos, flags);
1019
797
      unregister_slave(thd,1,1);
1020
798
      /*  fake COM_QUIT -- if we get here, the thread needs to terminate */
1021
 
      error = TRUE;
 
799
      error = true;
1022
800
      break;
1023
801
    }
1024
802
  case COM_SHUTDOWN:
1030
808
      SHUTDOWN_DEFAULT is 0. If client is >= 4.1.3, the shutdown level is in
1031
809
      packet[0].
1032
810
    */
1033
 
    enum mysql_enum_shutdown_level level=
1034
 
      (enum mysql_enum_shutdown_level) (uchar) packet[0];
 
811
    enum drizzle_enum_shutdown_level level=
 
812
      (enum drizzle_enum_shutdown_level) (uchar) packet[0];
1035
813
    if (level == SHUTDOWN_DEFAULT)
1036
814
      level= SHUTDOWN_WAIT_ALL_BUFFERS; // soon default will be configurable
1037
815
    else if (level != SHUTDOWN_WAIT_ALL_BUFFERS)
1039
817
      my_error(ER_NOT_SUPPORTED_YET, MYF(0), "this shutdown level");
1040
818
      break;
1041
819
    }
1042
 
    DBUG_PRINT("quit",("Got shutdown command for level %u", level));
1043
820
    general_log_print(thd, command, NullS);
1044
821
    my_eof(thd);
1045
822
    close_thread_tables(thd);                   // Free before kill
1046
823
    kill_mysql();
1047
 
    error=TRUE;
1048
 
    break;
1049
 
  }
1050
 
  case COM_STATISTICS:
1051
 
  {
1052
 
    STATUS_VAR current_global_status_var;
1053
 
    ulong uptime;
1054
 
    uint length;
1055
 
    ulonglong queries_per_second1000;
1056
 
    char buff[250];
1057
 
    uint buff_len= sizeof(buff);
1058
 
 
1059
 
    general_log_print(thd, command, NullS);
1060
 
    status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_STATUS]);
1061
 
    calc_sum_of_all_status(&current_global_status_var);
1062
 
    if (!(uptime= (ulong) (thd->start_time - server_start_time)))
1063
 
      queries_per_second1000= 0;
1064
 
    else
1065
 
      queries_per_second1000= thd->query_id * LL(1000) / uptime;
1066
 
 
1067
 
    length= my_snprintf((char*) buff, buff_len - 1,
1068
 
                        "Uptime: %lu  Threads: %d  Questions: %lu  "
1069
 
                        "Slow queries: %lu  Opens: %lu  Flush tables: %lu  "
1070
 
                        "Open tables: %u  Queries per second avg: %u.%u",
1071
 
                        uptime,
1072
 
                        (int) thread_count, (ulong) thd->query_id,
1073
 
                        current_global_status_var.long_query_count,
1074
 
                        current_global_status_var.opened_tables,
1075
 
                        refresh_version,
1076
 
                        cached_open_tables(),
1077
 
                        (uint) (queries_per_second1000 / 1000),
1078
 
                        (uint) (queries_per_second1000 % 1000));
1079
 
    /* Store the buffer in permanent memory */
1080
 
    my_ok(thd, 0, 0, buff);
1081
 
    VOID(my_net_write(net, (uchar*) buff, length));
1082
 
    VOID(net_flush(net));
1083
 
    thd->main_da.disable_status();
 
824
    error=true;
1084
825
    break;
1085
826
  }
1086
827
  case COM_PING:
1119
860
    }
1120
861
    break;
1121
862
  }
1122
 
  case COM_DEBUG:
1123
 
    status_var_increment(thd->status_var.com_other);
1124
 
    mysql_print_status();
1125
 
    general_log_print(thd, command, NullS);
1126
 
    my_eof(thd);
1127
 
    break;
1128
863
  case COM_SLEEP:
1129
864
  case COM_CONNECT:                             // Impossible here
1130
865
  case COM_TIME:                                // Impossible from client
1135
870
  }
1136
871
 
1137
872
  /* If commit fails, we should be able to reset the OK status. */
1138
 
  thd->main_da.can_overwrite_status= TRUE;
 
873
  thd->main_da.can_overwrite_status= true;
1139
874
  ha_autocommit_or_rollback(thd, thd->is_error());
1140
 
  thd->main_da.can_overwrite_status= FALSE;
 
875
  thd->main_da.can_overwrite_status= false;
1141
876
 
1142
877
  thd->transaction.stmt.reset();
1143
878
 
1156
891
 
1157
892
  net_end_statement(thd);
1158
893
 
1159
 
  thd->proc_info= "closing tables";
 
894
  thd->set_proc_info("closing tables");
1160
895
  /* Free tables */
1161
896
  close_thread_tables(thd);
1162
897
 
1172
907
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
1173
908
  thd->packet.shrink(thd->variables.net_buffer_length); // Reclaim some memory
1174
909
  free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
1175
 
  DBUG_RETURN(error);
 
910
  return(error);
1176
911
}
1177
912
 
1178
913
 
1179
914
void log_slow_statement(THD *thd)
1180
915
{
1181
 
  DBUG_ENTER("log_slow_statement");
1182
 
 
1183
916
  /*
1184
917
    The following should never be true with our current code base,
1185
918
    but better to keep this here so we don't accidently try to log a
1186
919
    statement in a trigger or stored function
1187
920
  */
1188
921
  if (unlikely(thd->in_sub_stmt))
1189
 
    DBUG_VOID_RETURN;                           // Don't set time for sub stmt
 
922
    return;                           // Don't set time for sub stmt
1190
923
 
1191
924
  /*
1192
925
    Do not log administrative statements unless the appropriate option is
1195
928
  if (thd->enable_slow_log && !thd->user_time)
1196
929
  {
1197
930
    thd_proc_info(thd, "logging slow query");
1198
 
    ulonglong end_utime_of_query= thd->current_utime();
 
931
    uint64_t end_utime_of_query= thd->current_utime();
1199
932
 
1200
933
    if (((end_utime_of_query - thd->utime_after_lock) >
1201
934
         thd->variables.long_query_time ||
1210
943
      slow_log_print(thd, thd->query, thd->query_length, end_utime_of_query);
1211
944
    }
1212
945
  }
1213
 
  DBUG_VOID_RETURN;
 
946
  return;
1214
947
}
1215
948
 
1216
949
 
1244
977
                         enum enum_schema_tables schema_table_idx)
1245
978
{
1246
979
  SELECT_LEX *schema_select_lex= NULL;
1247
 
  DBUG_ENTER("prepare_schema_table");
1248
980
 
1249
981
  switch (schema_table_idx) {
1250
982
  case SCH_SCHEMATA:
1257
989
      if (lex->select_lex.db == NULL &&
1258
990
          lex->copy_db_to(&lex->select_lex.db, &dummy))
1259
991
      {
1260
 
        DBUG_RETURN(1);
 
992
        return(1);
1261
993
      }
1262
994
      schema_select_lex= new SELECT_LEX();
1263
995
      db.str= schema_select_lex->db= lex->select_lex.db;
1267
999
      if (check_db_name(&db))
1268
1000
      {
1269
1001
        my_error(ER_WRONG_DB_NAME, MYF(0), db.str);
1270
 
        DBUG_RETURN(1);
 
1002
        return(1);
1271
1003
      }
1272
1004
      break;
1273
1005
    }
1274
1006
  case SCH_COLUMNS:
1275
1007
  case SCH_STATISTICS:
1276
1008
  {
1277
 
    DBUG_ASSERT(table_ident);
 
1009
    assert(table_ident);
1278
1010
    TABLE_LIST **query_tables_last= lex->query_tables_last;
1279
1011
    schema_select_lex= new SELECT_LEX();
1280
1012
    /* 'parent_lex' is used in init_query() so it must be before it. */
1281
1013
    schema_select_lex->parent_lex= lex;
1282
1014
    schema_select_lex->init_query();
1283
1015
    if (!schema_select_lex->add_table_to_list(thd, table_ident, 0, 0, TL_READ))
1284
 
      DBUG_RETURN(1);
 
1016
      return(1);
1285
1017
    lex->query_tables_last= query_tables_last;
1286
1018
    break;
1287
1019
  }
1301
1033
  assert(select_lex);
1302
1034
  if (make_schema_select(thd, select_lex, schema_table_idx))
1303
1035
  {
1304
 
    DBUG_RETURN(1);
 
1036
    return(1);
1305
1037
  }
1306
1038
  TABLE_LIST *table_list= (TABLE_LIST*) select_lex->table_list.first;
1307
1039
  assert(table_list);
1308
1040
  table_list->schema_select_lex= schema_select_lex;
1309
1041
  table_list->schema_table_reformed= 1;
1310
 
  DBUG_RETURN(0);
 
1042
  return(0);
1311
1043
}
1312
1044
 
1313
1045
 
1320
1052
  - query_length
1321
1053
 
1322
1054
  @retval
1323
 
    FALSE ok
 
1055
    false ok
1324
1056
  @retval
1325
 
    TRUE  error;  In this case thd->fatal_error is set
 
1057
    true  error;  In this case thd->fatal_error is set
1326
1058
*/
1327
1059
 
1328
1060
bool alloc_query(THD *thd, const char *packet, uint packet_length)
1345
1077
  if (!(thd->query= (char*) thd->memdup_w_gap((uchar*) (packet),
1346
1078
                                              packet_length,
1347
1079
                                              thd->db_length+ 1)))
1348
 
    return TRUE;
 
1080
    return true;
1349
1081
  thd->query[packet_length]=0;
1350
1082
  thd->query_length= packet_length;
1351
1083
 
1353
1085
  thd->packet.shrink(thd->variables.net_buffer_length);
1354
1086
  thd->convert_buffer.shrink(thd->variables.net_buffer_length);
1355
1087
 
1356
 
  return FALSE;
 
1088
  return false;
1357
1089
}
1358
1090
 
1359
1091
static void reset_one_shot_variables(THD *thd) 
1399
1131
    - SUSPEND and FOR MIGRATE are not supported yet. TODO
1400
1132
 
1401
1133
  @retval
1402
 
    FALSE       OK
 
1134
    false       OK
1403
1135
  @retval
1404
 
    TRUE        Error
 
1136
    true        Error
1405
1137
*/
1406
1138
 
1407
1139
int
1408
1140
mysql_execute_command(THD *thd)
1409
1141
{
1410
 
  int res= FALSE;
1411
 
  bool need_start_waiting= FALSE; // have protection against global read lock
 
1142
  int res= false;
 
1143
  bool need_start_waiting= false; // have protection against global read lock
1412
1144
  int  up_result= 0;
1413
1145
  LEX  *lex= thd->lex;
1414
1146
  /* first SELECT_LEX (have special meaning for many of non-SELECTcommands) */
1420
1152
  /* most outer SELECT_LEX_UNIT of query */
1421
1153
  SELECT_LEX_UNIT *unit= &lex->unit;
1422
1154
  /* Saved variable value */
1423
 
  DBUG_ENTER("mysql_execute_command");
1424
1155
 
1425
1156
  /*
1426
1157
    In many cases first table of main SELECT_LEX have special meaning =>
1434
1165
 
1435
1166
    Because of above in place where should be at least one table in most
1436
1167
    outer SELECT_LEX we have following check:
1437
 
    DBUG_ASSERT(first_table == all_tables);
1438
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
 
1168
    assert(first_table == all_tables);
 
1169
    assert(first_table == all_tables && first_table != 0);
1439
1170
  */
1440
1171
  lex->first_lists_tables_same();
1441
1172
  /* should be assigned after making first tables same */
1453
1184
    Don't reset warnings when executing a stored routine.
1454
1185
  */
1455
1186
  if (all_tables || !lex->is_single_level_stmt())
1456
 
    mysql_reset_errors(thd, 0);
 
1187
    drizzle_reset_errors(thd, 0);
1457
1188
 
1458
 
#ifdef HAVE_REPLICATION
1459
1189
  if (unlikely(thd->slave_thread))
1460
1190
  {
1461
1191
    /*
1496
1226
        */
1497
1227
        reset_one_shot_variables(thd);
1498
1228
      }
1499
 
      DBUG_RETURN(0);
 
1229
      return(0);
1500
1230
    }
1501
1231
  }
1502
1232
  else
1503
1233
  {
1504
 
#endif /* HAVE_REPLICATION */
1505
1234
    /*
1506
1235
      When option readonly is set deny operations which change non-temporary
1507
1236
      tables. Except for the replication thread and the 'super' users.
1509
1238
    if (deny_updates_if_read_only_option(thd, all_tables))
1510
1239
    {
1511
1240
      my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only");
1512
 
      DBUG_RETURN(-1);
 
1241
      return(-1);
1513
1242
    }
1514
 
#ifdef HAVE_REPLICATION
1515
1243
  } /* endif unlikely slave */
1516
 
#endif
1517
1244
  status_var_increment(thd->status_var.com_stat[lex->sql_command]);
1518
1245
 
1519
 
  DBUG_ASSERT(thd->transaction.stmt.modified_non_trans_table == FALSE);
 
1246
  assert(thd->transaction.stmt.modified_non_trans_table == false);
1520
1247
  
1521
1248
  switch (lex->sql_command) {
1522
1249
  case SQLCOM_SHOW_STATUS:
1553
1280
    res= execute_sqlcom_select(thd, all_tables);
1554
1281
    break;
1555
1282
  }
1556
 
  case SQLCOM_PREPARE:
1557
 
  {
1558
 
    break;
1559
 
  }
1560
 
  case SQLCOM_EXECUTE:
1561
 
  {
1562
 
    break;
1563
 
  }
1564
 
  case SQLCOM_DEALLOCATE_PREPARE:
1565
 
  {
1566
 
    break;
1567
 
  }
1568
1283
  case SQLCOM_EMPTY_QUERY:
1569
1284
    my_ok(thd);
1570
1285
    break;
1598
1313
  case SQLCOM_SHOW_WARNS:
1599
1314
  {
1600
1315
    res= mysqld_show_warnings(thd, (ulong)
1601
 
                              ((1L << (uint) MYSQL_ERROR::WARN_LEVEL_NOTE) |
1602
 
                               (1L << (uint) MYSQL_ERROR::WARN_LEVEL_WARN) |
1603
 
                               (1L << (uint) MYSQL_ERROR::WARN_LEVEL_ERROR)
 
1316
                              ((1L << (uint) DRIZZLE_ERROR::WARN_LEVEL_NOTE) |
 
1317
                               (1L << (uint) DRIZZLE_ERROR::WARN_LEVEL_WARN) |
 
1318
                               (1L << (uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR)
1604
1319
                               ));
1605
1320
    break;
1606
1321
  }
1607
1322
  case SQLCOM_SHOW_ERRORS:
1608
1323
  {
1609
1324
    res= mysqld_show_warnings(thd, (ulong)
1610
 
                              (1L << (uint) MYSQL_ERROR::WARN_LEVEL_ERROR));
1611
 
    break;
1612
 
  }
1613
 
  case SQLCOM_SHOW_NEW_MASTER:
1614
 
  {
1615
 
    /* This query don't work now. See comment in repl_failsafe.cc */
1616
 
#ifndef WORKING_NEW_MASTER
1617
 
    my_error(ER_NOT_SUPPORTED_YET, MYF(0), "SHOW NEW MASTER");
1618
 
    goto error;
1619
 
#else
1620
 
    res = show_new_master(thd);
1621
 
    break;
1622
 
#endif
1623
 
  }
1624
 
 
1625
 
#ifdef HAVE_REPLICATION
 
1325
                              (1L << (uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR));
 
1326
    break;
 
1327
  }
1626
1328
  case SQLCOM_SHOW_SLAVE_HOSTS:
1627
1329
  {
1628
1330
    res = show_slave_hosts(thd);
1633
1335
    res = mysql_show_binlog_events(thd);
1634
1336
    break;
1635
1337
  }
1636
 
#endif
1637
1338
 
1638
1339
  case SQLCOM_ASSIGN_TO_KEYCACHE:
1639
1340
  {
1640
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
 
1341
    assert(first_table == all_tables && first_table != 0);
1641
1342
    res= mysql_assign_to_keycache(thd, first_table, &lex->ident);
1642
1343
    break;
1643
1344
  }
1644
 
  case SQLCOM_PRELOAD_KEYS:
1645
 
  {
1646
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
1647
 
    res = mysql_preload_keys(thd, first_table);
1648
 
    break;
1649
 
  }
1650
 
#ifdef HAVE_REPLICATION
1651
1345
  case SQLCOM_CHANGE_MASTER:
1652
1346
  {
1653
1347
    pthread_mutex_lock(&LOCK_active_mi);
1664
1358
    }
1665
1359
    else
1666
1360
    {
1667
 
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
 
1361
      push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1668
1362
                   "the master info structure does not exist");
1669
1363
      my_ok(thd);
1670
1364
    }
1677
1371
    break;
1678
1372
  }
1679
1373
 
1680
 
#endif /* HAVE_REPLICATION */
1681
1374
  case SQLCOM_SHOW_ENGINE_STATUS:
1682
1375
    {
1683
1376
      res = ha_show_status(thd, lex->create_info.db_type, HA_ENGINE_STATUS);
1684
1377
      break;
1685
1378
    }
1686
 
  case SQLCOM_SHOW_ENGINE_MUTEX:
1687
 
    {
1688
 
      res = ha_show_status(thd, lex->create_info.db_type, HA_ENGINE_MUTEX);
1689
 
      break;
1690
 
    }
1691
1379
  case SQLCOM_CREATE_TABLE:
1692
1380
  {
1693
1381
    /* If CREATE TABLE of non-temporary table, do implicit commit */
1699
1387
        break;
1700
1388
      }
1701
1389
    }
1702
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
 
1390
    assert(first_table == all_tables && first_table != 0);
1703
1391
    bool link_to_local;
1704
1392
    // Skip first table, which is the table we are creating
1705
1393
    TABLE_LIST *create_table= lex->unlink_first_table(&link_to_local);
1779
1467
      select_lex->options|= SELECT_NO_UNLOCK;
1780
1468
      unit->set_limit(select_lex);
1781
1469
 
1782
 
      /*
1783
 
        Disable non-empty MERGE tables with CREATE...SELECT. Too
1784
 
        complicated. See Bug #26379. Empty MERGE tables are read-only
1785
 
        and don't allow CREATE...SELECT anyway.
1786
 
      */
1787
 
      if (create_info.used_fields & HA_CREATE_USED_UNION)
1788
 
      {
1789
 
        my_error(ER_WRONG_OBJECT, MYF(0), create_table->db,
1790
 
                 create_table->table_name, "BASE TABLE");
1791
 
        res= 1;
1792
 
        goto end_with_restore_list;
1793
 
      }
1794
 
 
1795
1470
      if (!(create_info.options & HA_LEX_CREATE_TMP_TABLE))
1796
1471
      {
1797
1472
        lex->link_first_table_back(create_table, link_to_local);
1798
 
        create_table->create= TRUE;
 
1473
        create_table->create= true;
1799
1474
      }
1800
1475
 
1801
1476
      if (!(res= open_and_lock_tables(thd, lex->query_tables)))
1815
1490
            goto end_with_restore_list;
1816
1491
          }
1817
1492
        }
1818
 
        /* If we create merge table, we have to test tables in merge, too */
1819
 
        if (create_info.used_fields & HA_CREATE_USED_UNION)
1820
 
        {
1821
 
          TABLE_LIST *tab;
1822
 
          for (tab= (TABLE_LIST*) create_info.merge_list.first;
1823
 
               tab;
1824
 
               tab= tab->next_local)
1825
 
          {
1826
 
            TABLE_LIST *duplicate;
1827
 
            if ((duplicate= unique_table(thd, tab, select_tables, 0)))
1828
 
            {
1829
 
              update_non_unique_table_error(tab, "CREATE", duplicate);
1830
 
              res= 1;
1831
 
              goto end_with_restore_list;
1832
 
            }
1833
 
          }
1834
 
        }
1835
1493
 
1836
1494
        /*
1837
1495
          select_create is currently not re-execution friendly and
1900
1558
    if (thd->is_fatal_error) /* out of memory creating a copy of alter_info */
1901
1559
      goto error;
1902
1560
 
1903
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
 
1561
    assert(first_table == all_tables && first_table != 0);
1904
1562
    if (end_active_trans(thd))
1905
1563
      goto error;
1906
1564
    /*
1910
1568
    */
1911
1569
    thd->enable_slow_log= opt_log_slow_admin_statements;
1912
1570
 
1913
 
    bzero((char*) &create_info, sizeof(create_info));
 
1571
    memset(&create_info, 0, sizeof(create_info));
1914
1572
    create_info.db_type= 0;
1915
1573
    create_info.row_type= ROW_TYPE_NOT_USED;
1916
1574
    create_info.default_table_charset= thd->variables.collation_database;
1920
1578
                           0, (ORDER*) 0, 0);
1921
1579
    break;
1922
1580
  }
1923
 
#ifdef HAVE_REPLICATION
1924
1581
  case SQLCOM_SLAVE_START:
1925
1582
  {
1926
1583
    pthread_mutex_lock(&LOCK_active_mi);
1954
1611
    pthread_mutex_unlock(&LOCK_active_mi);
1955
1612
    break;
1956
1613
  }
1957
 
#endif /* HAVE_REPLICATION */
1958
1614
 
1959
1615
  case SQLCOM_ALTER_TABLE:
1960
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
 
1616
    assert(first_table == all_tables && first_table != 0);
1961
1617
    {
1962
1618
      /*
1963
1619
        Code in mysql_alter_table() may modify its HA_CREATE_INFO argument,
1974
1630
      }
1975
1631
 
1976
1632
      /* Must be set in the parser */
1977
 
      DBUG_ASSERT(select_lex->db);
 
1633
      assert(select_lex->db);
1978
1634
 
1979
1635
      { // Rename of table
1980
1636
          TABLE_LIST tmp_table;
1981
 
          bzero((char*) &tmp_table,sizeof(tmp_table));
 
1637
          memset(&tmp_table, 0, sizeof(tmp_table));
1982
1638
          tmp_table.table_name= lex->name.str;
1983
1639
          tmp_table.db=select_lex->db;
1984
1640
      }
1985
1641
 
1986
1642
      /* Don't yet allow changing of symlinks with ALTER TABLE */
1987
1643
      if (create_info.data_file_name)
1988
 
        push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
 
1644
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1989
1645
                     "DATA DIRECTORY option ignored");
1990
1646
      if (create_info.index_file_name)
1991
 
        push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
 
1647
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 0,
1992
1648
                     "INDEX DIRECTORY option ignored");
1993
1649
      create_info.data_file_name= create_info.index_file_name= NULL;
1994
1650
      /* ALTER TABLE ends previous transaction */
2014
1670
    }
2015
1671
  case SQLCOM_RENAME_TABLE:
2016
1672
  {
2017
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
 
1673
    assert(first_table == all_tables && first_table != 0);
2018
1674
    TABLE_LIST *table;
2019
1675
    for (table= first_table; table; table= table->next_local->next_local)
2020
1676
    {
2039
1695
      break;
2040
1696
    }
2041
1697
  case SQLCOM_SHOW_CREATE:
2042
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
 
1698
    assert(first_table == all_tables && first_table != 0);
2043
1699
    {
2044
1700
      res= mysqld_show_create(thd, first_table);
2045
1701
      break;
2046
1702
    }
2047
1703
  case SQLCOM_CHECKSUM:
2048
1704
  {
2049
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
 
1705
    assert(first_table == all_tables && first_table != 0);
2050
1706
    res = mysql_checksum_table(thd, first_table, &lex->check_opt);
2051
1707
    break;
2052
1708
  }
2053
1709
  case SQLCOM_REPAIR:
2054
1710
  {
2055
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
 
1711
    assert(first_table == all_tables && first_table != 0);
2056
1712
    thd->enable_slow_log= opt_log_slow_admin_statements;
2057
1713
    res= mysql_repair_table(thd, first_table, &lex->check_opt);
2058
1714
    /* ! we write after unlocking the table */
2061
1717
      /*
2062
1718
        Presumably, REPAIR and binlog writing doesn't require synchronization
2063
1719
      */
2064
 
      write_bin_log(thd, TRUE, thd->query, thd->query_length);
 
1720
      write_bin_log(thd, true, thd->query, thd->query_length);
2065
1721
    }
2066
1722
    select_lex->table_list.first= (uchar*) first_table;
2067
1723
    lex->query_tables=all_tables;
2069
1725
  }
2070
1726
  case SQLCOM_CHECK:
2071
1727
  {
2072
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
 
1728
    assert(first_table == all_tables && first_table != 0);
2073
1729
    thd->enable_slow_log= opt_log_slow_admin_statements;
2074
1730
    res = mysql_check_table(thd, first_table, &lex->check_opt);
2075
1731
    select_lex->table_list.first= (uchar*) first_table;
2078
1734
  }
2079
1735
  case SQLCOM_ANALYZE:
2080
1736
  {
2081
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
 
1737
    assert(first_table == all_tables && first_table != 0);
2082
1738
    thd->enable_slow_log= opt_log_slow_admin_statements;
2083
1739
    res= mysql_analyze_table(thd, first_table, &lex->check_opt);
2084
1740
    /* ! we write after unlocking the table */
2087
1743
      /*
2088
1744
        Presumably, ANALYZE and binlog writing doesn't require synchronization
2089
1745
      */
2090
 
      write_bin_log(thd, TRUE, thd->query, thd->query_length);
 
1746
      write_bin_log(thd, true, thd->query, thd->query_length);
2091
1747
    }
2092
1748
    select_lex->table_list.first= (uchar*) first_table;
2093
1749
    lex->query_tables=all_tables;
2096
1752
 
2097
1753
  case SQLCOM_OPTIMIZE:
2098
1754
  {
2099
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
 
1755
    assert(first_table == all_tables && first_table != 0);
2100
1756
    thd->enable_slow_log= opt_log_slow_admin_statements;
2101
1757
    res= (specialflag & (SPECIAL_SAFE_MODE | SPECIAL_NO_NEW_FUNC)) ?
2102
1758
      mysql_recreate_table(thd, first_table) :
2107
1763
      /*
2108
1764
        Presumably, OPTIMIZE and binlog writing doesn't require synchronization
2109
1765
      */
2110
 
      write_bin_log(thd, TRUE, thd->query, thd->query_length);
 
1766
      write_bin_log(thd, true, thd->query, thd->query_length);
2111
1767
    }
2112
1768
    select_lex->table_list.first= (uchar*) first_table;
2113
1769
    lex->query_tables=all_tables;
2114
1770
    break;
2115
1771
  }
2116
1772
  case SQLCOM_UPDATE:
2117
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
 
1773
    assert(first_table == all_tables && first_table != 0);
2118
1774
    if (update_precheck(thd, all_tables))
2119
1775
      break;
2120
 
    DBUG_ASSERT(select_lex->offset_limit == 0);
 
1776
    assert(select_lex->offset_limit == 0);
2121
1777
    unit->set_limit(select_lex);
2122
1778
    res= (up_result= mysql_update(thd, all_tables,
2123
1779
                                  select_lex->item_list,
2133
1789
    /* Fall through */
2134
1790
  case SQLCOM_UPDATE_MULTI:
2135
1791
  {
2136
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
 
1792
    assert(first_table == all_tables && first_table != 0);
2137
1793
    /* if we switched from normal update, rights are checked */
2138
1794
    if (up_result != 2)
2139
1795
    {
2145
1801
 
2146
1802
    res= mysql_multi_update_prepare(thd);
2147
1803
 
2148
 
#ifdef HAVE_REPLICATION
2149
1804
    /* Check slave filtering rules */
2150
1805
    if (unlikely(thd->slave_thread))
2151
1806
    {
2165
1820
    }
2166
1821
    else
2167
1822
    {
2168
 
#endif /* HAVE_REPLICATION */
2169
1823
      if (res)
2170
1824
        break;
2171
1825
      if (opt_readonly &&
2174
1828
        my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only");
2175
1829
        break;
2176
1830
      }
2177
 
#ifdef HAVE_REPLICATION
2178
1831
    }  /* unlikely */
2179
 
#endif
2180
1832
 
2181
1833
    res= mysql_multi_update(thd, all_tables,
2182
1834
                            &select_lex->item_list,
2187
1839
    break;
2188
1840
  }
2189
1841
  case SQLCOM_REPLACE:
2190
 
#ifndef DBUG_OFF
2191
 
    if (mysql_bin_log.is_open())
2192
 
    {
2193
 
      /*
2194
 
        Generate an incident log event before writing the real event
2195
 
        to the binary log.  We put this event is before the statement
2196
 
        since that makes it simpler to check that the statement was
2197
 
        not executed on the slave (since incidents usually stop the
2198
 
        slave).
2199
 
 
2200
 
        Observe that any row events that are generated will be
2201
 
        generated before.
2202
 
 
2203
 
        This is only for testing purposes and will not be present in a
2204
 
        release build.
2205
 
      */
2206
 
 
2207
 
      Incident incident= INCIDENT_NONE;
2208
 
      DBUG_PRINT("debug", ("Just before generate_incident()"));
2209
 
      DBUG_EXECUTE_IF("incident_database_resync_on_replace",
2210
 
                      incident= INCIDENT_LOST_EVENTS;);
2211
 
      if (incident)
2212
 
      {
2213
 
        Incident_log_event ev(thd, incident);
2214
 
        mysql_bin_log.write(&ev);
2215
 
        mysql_bin_log.rotate_and_purge(RP_FORCE_ROTATE);
2216
 
      }
2217
 
      DBUG_PRINT("debug", ("Just after generate_incident()"));
2218
 
    }
2219
 
#endif
2220
1842
  case SQLCOM_INSERT:
2221
1843
  {
2222
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
 
1844
    assert(first_table == all_tables && first_table != 0);
2223
1845
    if ((res= insert_precheck(thd, all_tables)))
2224
1846
      break;
2225
1847
 
2240
1862
  case SQLCOM_INSERT_SELECT:
2241
1863
  {
2242
1864
    select_result *sel_result;
2243
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
 
1865
    assert(first_table == all_tables && first_table != 0);
2244
1866
    if ((res= insert_precheck(thd, all_tables)))
2245
1867
      break;
2246
1868
 
2305
1927
      res= -1;
2306
1928
      break;
2307
1929
    }
2308
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
 
1930
    assert(first_table == all_tables && first_table != 0);
2309
1931
    /*
2310
1932
      Don't allow this within a transaction because we want to use
2311
1933
      re-generate table
2322
1944
    break;
2323
1945
  case SQLCOM_DELETE:
2324
1946
  {
2325
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
2326
 
    DBUG_ASSERT(select_lex->offset_limit == 0);
 
1947
    assert(first_table == all_tables && first_table != 0);
 
1948
    assert(select_lex->offset_limit == 0);
2327
1949
    unit->set_limit(select_lex);
2328
1950
 
2329
1951
    if (!thd->locked_tables &&
2336
1958
    res = mysql_delete(thd, all_tables, select_lex->where,
2337
1959
                       &select_lex->order_list,
2338
1960
                       unit->select_limit_cnt, select_lex->options,
2339
 
                       FALSE);
 
1961
                       false);
2340
1962
    break;
2341
1963
  }
2342
1964
  case SQLCOM_DELETE_MULTI:
2343
1965
  {
2344
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
 
1966
    assert(first_table == all_tables && first_table != 0);
2345
1967
    TABLE_LIST *aux_tables=
2346
1968
      (TABLE_LIST *)thd->lex->auxiliary_table_list.first;
2347
1969
    multi_delete *del_result;
2356
1978
    if ((res= multi_delete_precheck(thd, all_tables)))
2357
1979
      break;
2358
1980
 
2359
 
    /* condition will be TRUE on SP re-excuting */
 
1981
    /* condition will be true on SP re-excuting */
2360
1982
    if (select_lex->item_list.elements != 0)
2361
1983
      select_lex->item_list.empty();
2362
1984
    if (add_item_to_list(thd, new Item_null()))
2389
2011
      delete del_result;
2390
2012
    }
2391
2013
    else
2392
 
      res= TRUE;                                // Error
 
2014
      res= true;                                // Error
2393
2015
    break;
2394
2016
  }
2395
2017
  case SQLCOM_DROP_TABLE:
2396
2018
  {
2397
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
 
2019
    assert(first_table == all_tables && first_table != 0);
2398
2020
    if (!lex->drop_temporary)
2399
2021
    {
2400
2022
      if (end_active_trans(thd))
2417
2039
      thd->options|= OPTION_KEEP_LOG;
2418
2040
    }
2419
2041
    /* DDL and binlog write order protected by LOCK_open */
2420
 
    res= mysql_rm_table(thd, first_table, lex->drop_if_exists,
2421
 
                        lex->drop_temporary);
 
2042
    res= mysql_rm_table(thd, first_table, lex->drop_if_exists, lex->drop_temporary);
2422
2043
  }
2423
2044
  break;
2424
2045
  case SQLCOM_SHOW_PROCESSLIST:
2433
2054
  {
2434
2055
    LEX_STRING db_str= { (char *) select_lex->db, strlen(select_lex->db) };
2435
2056
 
2436
 
    if (!mysql_change_db(thd, &db_str, FALSE))
 
2057
    if (!mysql_change_db(thd, &db_str, false))
2437
2058
      my_ok(thd);
2438
2059
 
2439
2060
    break;
2441
2062
 
2442
2063
  case SQLCOM_LOAD:
2443
2064
  {
2444
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
 
2065
    assert(first_table == all_tables && first_table != 0);
2445
2066
    if (lex->local_file)
2446
2067
    {
2447
2068
      if (!(thd->client_capabilities & CLIENT_LOCAL_FILES) ||
2519
2140
      - only transactional locks are requested (lex->lock_transactional) and
2520
2141
      - no non-transactional locks exist (!thd->locked_tables).
2521
2142
    */
2522
 
    DBUG_PRINT("lock_info", ("lex->lock_transactional: %d  "
2523
 
                             "thd->locked_tables: 0x%lx",
2524
 
                             lex->lock_transactional,
2525
 
                             (long) thd->locked_tables));
2526
2143
    if (lex->lock_transactional && !thd->locked_tables)
2527
2144
    {
2528
2145
      int rc;
2564
2181
    {
2565
2182
      thd->locked_tables=thd->lock;
2566
2183
      thd->lock=0;
2567
 
      (void) set_handler_table_locks(thd, all_tables, FALSE);
2568
 
      DBUG_PRINT("lock_info", ("thd->locked_tables: 0x%lx",
2569
 
                               (long) thd->locked_tables));
 
2184
      (void) set_handler_table_locks(thd, all_tables, false);
2570
2185
      my_ok(thd);
2571
2186
    }
2572
2187
    else
2639
2254
      do_db/ignore_db. And as this query involves no tables, tables_ok()
2640
2255
      above was not called. So we have to check rules again here.
2641
2256
    */
2642
 
#ifdef HAVE_REPLICATION
2643
2257
    if (thd->slave_thread && 
2644
2258
        (!rpl_filter->db_ok(lex->name.str) ||
2645
2259
         !rpl_filter->db_ok_with_wild_table(lex->name.str)))
2647
2261
      my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0));
2648
2262
      break;
2649
2263
    }
2650
 
#endif
2651
2264
    if (thd->locked_tables || thd->active_transaction())
2652
2265
    {
2653
2266
      my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
2657
2270
    res= mysql_rm_db(thd, lex->name.str, lex->drop_if_exists, 0);
2658
2271
    break;
2659
2272
  }
2660
 
  case SQLCOM_ALTER_DB_UPGRADE:
2661
 
  {
2662
 
    LEX_STRING *db= & lex->name;
2663
 
    if (end_active_trans(thd))
2664
 
    {
2665
 
      res= 1;
2666
 
      break;
2667
 
    }
2668
 
#ifdef HAVE_REPLICATION
2669
 
    if (thd->slave_thread && 
2670
 
       (!rpl_filter->db_ok(db->str) ||
2671
 
        !rpl_filter->db_ok_with_wild_table(db->str)))
2672
 
    {
2673
 
      res= 1;
2674
 
      my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0));
2675
 
      break;
2676
 
    }
2677
 
#endif
2678
 
    if (check_db_name(db))
2679
 
    {
2680
 
      my_error(ER_WRONG_DB_NAME, MYF(0), db->str);
2681
 
      break;
2682
 
    }
2683
 
    if (thd->locked_tables || thd->active_transaction())
2684
 
    {
2685
 
      res= 1;
2686
 
      my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
2687
 
                 ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
2688
 
      goto error;
2689
 
    }
2690
 
 
2691
 
    res= mysql_upgrade_db(thd, db);
2692
 
    if (!res)
2693
 
      my_ok(thd);
2694
 
    break;
2695
 
  }
2696
2273
  case SQLCOM_ALTER_DB:
2697
2274
  {
2698
2275
    LEX_STRING *db= &lex->name;
2709
2286
      do_db/ignore_db. And as this query involves no tables, tables_ok()
2710
2287
      above was not called. So we have to check rules again here.
2711
2288
    */
2712
 
#ifdef HAVE_REPLICATION
2713
2289
    if (thd->slave_thread &&
2714
2290
        (!rpl_filter->db_ok(db->str) ||
2715
2291
         !rpl_filter->db_ok_with_wild_table(db->str)))
2717
2293
      my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0));
2718
2294
      break;
2719
2295
    }
2720
 
#endif
2721
2296
    if (thd->locked_tables || thd->active_transaction())
2722
2297
    {
2723
2298
      my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
2729
2304
  }
2730
2305
  case SQLCOM_SHOW_CREATE_DB:
2731
2306
  {
2732
 
    DBUG_EXECUTE_IF("4x_server_emul",
2733
 
                    my_error(ER_UNKNOWN_ERROR, MYF(0)); goto error;);
2734
2307
    if (check_db_name(&lex->name))
2735
2308
    {
2736
2309
      my_error(ER_WRONG_DB_NAME, MYF(0), lex->name.str);
2764
2337
      */
2765
2338
      if (!lex->no_write_to_binlog && write_to_binlog)
2766
2339
      {
2767
 
        write_bin_log(thd, FALSE, thd->query, thd->query_length);
 
2340
        write_bin_log(thd, false, thd->query, thd->query_length);
2768
2341
      }
2769
2342
      my_ok(thd);
2770
2343
    } 
2830
2403
    if (sv)
2831
2404
    {
2832
2405
      if (ha_release_savepoint(thd, sv))
2833
 
        res= TRUE; // cannot happen
 
2406
        res= true; // cannot happen
2834
2407
      else
2835
2408
        my_ok(thd);
2836
2409
      thd->transaction.savepoints=sv->prev;
2852
2425
    if (sv)
2853
2426
    {
2854
2427
      if (ha_rollback_to_savepoint(thd, sv))
2855
 
        res= TRUE; // cannot happen
 
2428
        res= true; // cannot happen
2856
2429
      else
2857
2430
      {
2858
2431
        if (((thd->options & OPTION_KEEP_LOG) || 
2859
2432
             thd->transaction.all.modified_non_trans_table) &&
2860
2433
            !thd->slave_thread)
2861
 
          push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
 
2434
          push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
2862
2435
                       ER_WARNING_NOT_COMPLETE_ROLLBACK,
2863
2436
                       ER(ER_WARNING_NOT_COMPLETE_ROLLBACK));
2864
2437
        my_ok(thd);
2904
2477
        be free'd when transaction ends anyway
2905
2478
      */
2906
2479
      if (ha_savepoint(thd, newsv))
2907
 
        res= TRUE;
 
2480
        res= true;
2908
2481
      else
2909
2482
      {
2910
2483
        newsv->prev=thd->transaction.savepoints;
2919
2492
    break;
2920
2493
  }
2921
2494
  default:
2922
 
    DBUG_ASSERT(0);                             /* Impossible */
 
2495
    assert(0);                             /* Impossible */
2923
2496
    my_ok(thd);
2924
2497
    break;
2925
2498
  }
2950
2523
  goto finish;
2951
2524
 
2952
2525
error:
2953
 
  res= TRUE;
 
2526
  res= true;
2954
2527
 
2955
2528
finish:
2956
2529
  if (need_start_waiting)
2961
2534
    */
2962
2535
    start_waiting_global_read_lock(thd);
2963
2536
  }
2964
 
  DBUG_RETURN(res || thd->is_error());
 
2537
  return(res || thd->is_error());
2965
2538
}
2966
2539
 
2967
 
 
2968
 
static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables)
 
2540
bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables)
2969
2541
{
2970
2542
  LEX   *lex= thd->lex;
2971
2543
  select_result *result=lex->result;
2975
2547
    SELECT_LEX *param= lex->unit.global_parameters;
2976
2548
    if (!param->explicit_limit)
2977
2549
      param->select_limit=
2978
 
        new Item_int((ulonglong) thd->variables.select_limit);
 
2550
        new Item_int((uint64_t) thd->variables.select_limit);
2979
2551
  }
2980
2552
  if (!(res= open_and_lock_tables(thd, all_tables)))
2981
2553
  {
2994
2566
      if (lex->describe & DESCRIBE_EXTENDED)
2995
2567
      {
2996
2568
        char buff[1024];
2997
 
        String str(buff,(uint32) sizeof(buff), system_charset_info);
 
2569
        String str(buff,(uint32_t) sizeof(buff), system_charset_info);
2998
2570
        str.length(0);
2999
2571
        thd->lex->unit.print(&str, QT_ORDINARY);
3000
2572
        str.append('\0');
3001
 
        push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
2573
        push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
3002
2574
                     ER_YES, str.ptr());
3003
2575
      }
3004
2576
      if (res)
3028
2600
#define used_stack(A,B) (long) (B - A)
3029
2601
#endif
3030
2602
 
3031
 
#ifndef DBUG_OFF
3032
 
long max_stack_used;
3033
 
#endif
3034
 
 
3035
2603
/**
3036
2604
  @note
3037
2605
  Note: The 'buf' parameter is necessary, even if it is unused here.
3043
2611
                         uchar *buf __attribute__((unused)))
3044
2612
{
3045
2613
  long stack_used;
3046
 
  DBUG_ASSERT(thd == current_thd);
 
2614
  assert(thd == current_thd);
3047
2615
  if ((stack_used=used_stack(thd->thread_stack,(char*) &stack_used)) >=
3048
2616
      (long) (my_thread_stack_size - margin))
3049
2617
  {
3052
2620
    my_message(ER_STACK_OVERRUN_NEED_MORE,errbuff[0],MYF(ME_FATALERROR));
3053
2621
    return 1;
3054
2622
  }
3055
 
#ifndef DBUG_OFF
3056
 
  max_stack_used= max(max_stack_used, stack_used);
3057
 
#endif
3058
2623
  return 0;
3059
2624
}
3060
2625
 
3081
2646
    return 1;
3082
2647
  if (old_info)
3083
2648
  {                                             // Copy old info from stack
3084
 
    memcpy(lex->yacc_yyss, (uchar*) *yyss, old_info*sizeof(**yyss));
3085
 
    memcpy(lex->yacc_yyvs, (uchar*) *yyvs, old_info*sizeof(**yyvs));
 
2649
    memcpy(lex->yacc_yyss, *yyss, old_info*sizeof(**yyss));
 
2650
    memcpy(lex->yacc_yyvs, *yyvs, old_info*sizeof(**yyvs));
3086
2651
  }
3087
2652
  *yyss=(short*) lex->yacc_yyss;
3088
2653
  *yyvs=(YYSTYPE*) lex->yacc_yyvs;
3106
2671
 
3107
2672
void mysql_reset_thd_for_next_command(THD *thd)
3108
2673
{
3109
 
  DBUG_ENTER("mysql_reset_thd_for_next_command");
3110
 
  DBUG_ASSERT(! thd->in_sub_stmt);
 
2674
  assert(! thd->in_sub_stmt);
3111
2675
  thd->free_list= 0;
3112
2676
  thd->select_number= 1;
3113
2677
  /*
3130
2694
  if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
3131
2695
  {
3132
2696
    thd->options&= ~OPTION_KEEP_LOG;
3133
 
    thd->transaction.all.modified_non_trans_table= FALSE;
 
2697
    thd->transaction.all.modified_non_trans_table= false;
3134
2698
  }
3135
 
  DBUG_ASSERT(thd->security_ctx== &thd->main_security_ctx);
3136
 
  thd->thread_specific_used= FALSE;
 
2699
  assert(thd->security_ctx== &thd->main_security_ctx);
 
2700
  thd->thread_specific_used= false;
3137
2701
 
3138
2702
  if (opt_bin_log)
3139
2703
  {
3152
2716
  */
3153
2717
  thd->reset_current_stmt_binlog_row_based();
3154
2718
 
3155
 
  DBUG_VOID_RETURN;
 
2719
  return;
3156
2720
}
3157
2721
 
3158
2722
 
3164
2728
  lex->wild= 0;
3165
2729
  if (select_lex == &lex->select_lex)
3166
2730
  {
3167
 
    DBUG_ASSERT(lex->result == 0);
 
2731
    assert(lex->result == 0);
3168
2732
    lex->exchange= 0;
3169
2733
  }
3170
2734
}
3175
2739
{
3176
2740
  SELECT_LEX *select_lex;
3177
2741
  THD *thd= lex->thd;
3178
 
  DBUG_ENTER("mysql_new_select");
3179
2742
 
3180
2743
  if (!(select_lex= new (thd->mem_root) SELECT_LEX()))
3181
 
    DBUG_RETURN(1);
 
2744
    return(1);
3182
2745
  select_lex->select_number= ++thd->select_number;
3183
2746
  select_lex->parent_lex= lex; /* Used in init_query. */
3184
2747
  select_lex->init_query();
3187
2750
  if (lex->nest_level > (int) MAX_SELECT_NESTING)
3188
2751
  {
3189
2752
    my_error(ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT,MYF(0),MAX_SELECT_NESTING);
3190
 
    DBUG_RETURN(1);
 
2753
    return(1);
3191
2754
  }
3192
2755
  select_lex->nest_level= lex->nest_level;
3193
2756
  if (move_down)
3194
2757
  {
3195
2758
    SELECT_LEX_UNIT *unit;
3196
 
    lex->subqueries= TRUE;
 
2759
    lex->subqueries= true;
3197
2760
    /* first select_lex of subselect or derived table */
3198
2761
    if (!(unit= new (thd->mem_root) SELECT_LEX_UNIT()))
3199
 
      DBUG_RETURN(1);
 
2762
      return(1);
3200
2763
 
3201
2764
    unit->init_query();
3202
2765
    unit->init_select();
3217
2780
    if (lex->current_select->order_list.first && !lex->current_select->braces)
3218
2781
    {
3219
2782
      my_error(ER_WRONG_USAGE, MYF(0), "UNION", "ORDER BY");
3220
 
      DBUG_RETURN(1);
 
2783
      return(1);
3221
2784
    }
3222
2785
    select_lex->include_neighbour(lex->current_select);
3223
2786
    SELECT_LEX_UNIT *unit= select_lex->master_unit();                              
3224
2787
    if (!unit->fake_select_lex && unit->add_fake_select_lex(lex->thd))
3225
 
      DBUG_RETURN(1);
 
2788
      return(1);
3226
2789
    select_lex->context.outer_context= 
3227
2790
                unit->first_select()->context.outer_context;
3228
2791
  }
3234
2797
    in subquery is SELECT query and we allow resolution of names in SELECT
3235
2798
    list
3236
2799
  */
3237
 
  select_lex->context.resolve_in_select_list= TRUE;
3238
 
  DBUG_RETURN(0);
 
2800
  select_lex->context.resolve_in_select_list= true;
 
2801
  return(0);
3239
2802
}
3240
2803
 
3241
2804
/**
3255
2818
  LEX_STRING tmp, null_lex_string;
3256
2819
  Item *var;
3257
2820
  char buff[MAX_SYS_VAR_LENGTH*2+4+8], *end;
3258
 
  DBUG_ENTER("create_select_for_variable");
3259
2821
 
3260
2822
  thd= current_thd;
3261
2823
  lex= thd->lex;
3263
2825
  lex->sql_command= SQLCOM_SELECT;
3264
2826
  tmp.str= (char*) var_name;
3265
2827
  tmp.length=strlen(var_name);
3266
 
  bzero((char*) &null_lex_string.str, sizeof(null_lex_string));
 
2828
  memset(&null_lex_string.str, 0, sizeof(null_lex_string));
3267
2829
  /*
3268
2830
    We set the name of Item to @@session.var_name because that then is used
3269
2831
    as the column name in the output.
3274
2836
    var->set_name(buff, end-buff, system_charset_info);
3275
2837
    add_item_to_list(thd, var);
3276
2838
  }
3277
 
  DBUG_VOID_RETURN;
 
2839
  return;
3278
2840
}
3279
2841
 
3280
2842
 
3309
2871
void mysql_parse(THD *thd, const char *inBuf, uint length,
3310
2872
                 const char ** found_semicolon)
3311
2873
{
3312
 
  DBUG_ENTER("mysql_parse");
3313
 
 
3314
 
  DBUG_EXECUTE_IF("parser_debug", turn_parser_debug_on(););
3315
 
 
3316
2874
  /*
3317
2875
    Warning.
3318
2876
    The purpose of query_cache_send_result_to_client() is to lookup the
3337
2895
 
3338
2896
    Lex_input_stream lip(thd, inBuf, length);
3339
2897
 
3340
 
    bool err= parse_sql(thd, &lip, NULL);
 
2898
    bool err= parse_sql(thd, &lip);
3341
2899
    *found_semicolon= lip.found_semicolon;
3342
2900
 
3343
2901
    if (!err)
3365
2923
    }
3366
2924
    else
3367
2925
    {
3368
 
      DBUG_ASSERT(thd->is_error());
3369
 
      DBUG_PRINT("info",("Command aborted. Fatal_error: %d",
3370
 
                         thd->is_fatal_error));
 
2926
      assert(thd->is_error());
3371
2927
    }
3372
2928
    lex->unit.cleanup();
3373
2929
    thd_proc_info(thd, "freeing items");
3374
2930
    thd->end_statement();
3375
2931
    thd->cleanup_after_query();
3376
 
    DBUG_ASSERT(thd->change_list.is_empty());
 
2932
    assert(thd->change_list.is_empty());
3377
2933
  }
3378
2934
 
3379
 
  DBUG_VOID_RETURN;
 
2935
  return;
3380
2936
}
3381
2937
 
3382
2938
 
3383
 
#ifdef HAVE_REPLICATION
3384
2939
/*
3385
2940
  Usable by the replication SQL thread only: just parse a query to know if it
3386
2941
  can be ignored because of replicate-*-table rules.
3395
2950
{
3396
2951
  LEX *lex= thd->lex;
3397
2952
  bool error= 0;
3398
 
  DBUG_ENTER("mysql_test_parse_for_slave");
3399
2953
 
3400
2954
  Lex_input_stream lip(thd, inBuf, length);
3401
2955
  lex_start(thd);
3402
2956
  mysql_reset_thd_for_next_command(thd);
3403
2957
 
3404
 
  if (!parse_sql(thd, &lip, NULL) &&
 
2958
  if (!parse_sql(thd, &lip) &&
3405
2959
      all_tables_not_ok(thd,(TABLE_LIST*) lex->select_lex.table_list.first))
3406
2960
    error= 1;                  /* Ignore question */
3407
2961
  thd->end_statement();
3408
2962
  thd->cleanup_after_query();
3409
 
  DBUG_RETURN(error);
 
2963
  return(error);
3410
2964
}
3411
 
#endif
3412
2965
 
3413
2966
 
3414
2967
 
3422
2975
bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum_field_types type,
3423
2976
                       char *length, char *decimals,
3424
2977
                       uint type_modifier,
3425
 
                       enum ha_storage_media storage_type,
3426
2978
                       enum column_format_type column_format,
3427
2979
                       Item *default_value, Item *on_update_value,
3428
2980
                       LEX_STRING *comment,
3429
2981
                       char *change,
3430
 
                       List<String> *interval_list, CHARSET_INFO *cs)
 
2982
                       List<String> *interval_list, const CHARSET_INFO * const cs)
3431
2983
{
3432
2984
  register Create_field *new_field;
3433
2985
  LEX  *lex= thd->lex;
3434
 
  DBUG_ENTER("add_field_to_list");
3435
2986
 
3436
2987
  if (check_identifier_name(field_name, ER_TOO_LONG_IDENT))
3437
 
    DBUG_RETURN(1);                             /* purecov: inspected */
 
2988
    return(1);                          /* purecov: inspected */
3438
2989
 
3439
2990
  if (type_modifier & PRI_KEY_FLAG)
3440
2991
  {
3468
3019
    */
3469
3020
    if (default_value->type() == Item::FUNC_ITEM && 
3470
3021
        !(((Item_func*)default_value)->functype() == Item_func::NOW_FUNC &&
3471
 
         type == MYSQL_TYPE_TIMESTAMP))
 
3022
         type == DRIZZLE_TYPE_TIMESTAMP))
3472
3023
    {
3473
3024
      my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
3474
 
      DBUG_RETURN(1);
 
3025
      return(1);
3475
3026
    }
3476
3027
    else if (default_value->type() == Item::NULL_ITEM)
3477
3028
    {
3480
3031
          NOT_NULL_FLAG)
3481
3032
      {
3482
3033
        my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
3483
 
        DBUG_RETURN(1);
 
3034
        return(1);
3484
3035
      }
3485
3036
    }
3486
3037
    else if (type_modifier & AUTO_INCREMENT_FLAG)
3487
3038
    {
3488
3039
      my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
3489
 
      DBUG_RETURN(1);
 
3040
      return(1);
3490
3041
    }
3491
3042
  }
3492
3043
 
3493
 
  if (on_update_value && type != MYSQL_TYPE_TIMESTAMP)
 
3044
  if (on_update_value && type != DRIZZLE_TYPE_TIMESTAMP)
3494
3045
  {
3495
3046
    my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name->str);
3496
 
    DBUG_RETURN(1);
 
3047
    return(1);
3497
3048
  }
3498
3049
 
3499
3050
  if (!(new_field= new Create_field()) ||
3500
3051
      new_field->init(thd, field_name->str, type, length, decimals, type_modifier,
3501
3052
                      default_value, on_update_value, comment, change,
3502
 
                      interval_list, cs, 0,
3503
 
                      storage_type, column_format))
3504
 
    DBUG_RETURN(1);
 
3053
                      interval_list, cs, 0, column_format))
 
3054
    return(1);
3505
3055
 
3506
3056
  lex->alter_info.create_list.push_back(new_field);
3507
3057
  lex->last_field=new_field;
3508
 
  DBUG_RETURN(0);
 
3058
  return(0);
3509
3059
}
3510
3060
 
3511
3061
 
3540
3090
bool add_to_list(THD *thd, SQL_LIST &list,Item *item,bool asc)
3541
3091
{
3542
3092
  ORDER *order;
3543
 
  DBUG_ENTER("add_to_list");
3544
3093
  if (!(order = (ORDER *) thd->alloc(sizeof(ORDER))))
3545
 
    DBUG_RETURN(1);
 
3094
    return(1);
3546
3095
  order->item_ptr= item;
3547
3096
  order->item= &order->item_ptr;
3548
3097
  order->asc = asc;
3550
3099
  order->used=0;
3551
3100
  order->counter_used= 0;
3552
3101
  list.link_in_list((uchar*) order,(uchar**) &order->next);
3553
 
  DBUG_RETURN(0);
 
3102
  return(0);
3554
3103
}
3555
3104
 
3556
3105
 
3576
3125
TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
3577
3126
                                             Table_ident *table,
3578
3127
                                             LEX_STRING *alias,
3579
 
                                             ulong table_options,
 
3128
                                             uint32_t table_options,
3580
3129
                                             thr_lock_type lock_type,
3581
3130
                                             List<Index_hint> *index_hints_arg,
3582
3131
                                             LEX_STRING *option)
3585
3134
  TABLE_LIST *previous_table_ref; /* The table preceding the current one. */
3586
3135
  char *alias_str;
3587
3136
  LEX *lex= thd->lex;
3588
 
  DBUG_ENTER("add_table_to_list");
3589
3137
 
3590
3138
  if (!table)
3591
 
    DBUG_RETURN(0);                             // End of memory
 
3139
    return(0);                          // End of memory
3592
3140
  alias_str= alias ? alias->str : table->table.str;
3593
3141
  if (!test(table_options & TL_OPTION_ALIAS) && 
3594
3142
      check_table_name(table->table.str, table->table.length))
3595
3143
  {
3596
3144
    my_error(ER_WRONG_TABLE_NAME, MYF(0), table->table.str);
3597
 
    DBUG_RETURN(0);
 
3145
    return(0);
3598
3146
  }
3599
3147
 
3600
 
  if (table->is_derived_table() == FALSE && table->db.str &&
 
3148
  if (table->is_derived_table() == false && table->db.str &&
3601
3149
      check_db_name(&table->db))
3602
3150
  {
3603
3151
    my_error(ER_WRONG_DB_NAME, MYF(0), table->db.str);
3604
 
    DBUG_RETURN(0);
 
3152
    return(0);
3605
3153
  }
3606
3154
 
3607
3155
  if (!alias)                                   /* Alias is case sensitive */
3610
3158
    {
3611
3159
      my_message(ER_DERIVED_MUST_HAVE_ALIAS,
3612
3160
                 ER(ER_DERIVED_MUST_HAVE_ALIAS), MYF(0));
3613
 
      DBUG_RETURN(0);
 
3161
      return(0);
3614
3162
    }
3615
3163
    if (!(alias_str= (char*) thd->memdup(alias_str,table->table.length+1)))
3616
 
      DBUG_RETURN(0);
 
3164
      return(0);
3617
3165
  }
3618
3166
  if (!(ptr = (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST))))
3619
 
    DBUG_RETURN(0);                             /* purecov: inspected */
 
3167
    return(0);                          /* purecov: inspected */
3620
3168
  if (table->db.str)
3621
3169
  {
3622
 
    ptr->is_fqtn= TRUE;
 
3170
    ptr->is_fqtn= true;
3623
3171
    ptr->db= table->db.str;
3624
3172
    ptr->db_length= table->db.length;
3625
3173
  }
3626
3174
  else if (lex->copy_db_to(&ptr->db, &ptr->db_length))
3627
 
    DBUG_RETURN(0);
 
3175
    return(0);
3628
3176
  else
3629
 
    ptr->is_fqtn= FALSE;
 
3177
    ptr->is_fqtn= false;
3630
3178
 
3631
3179
  ptr->alias= alias_str;
3632
 
  ptr->is_alias= alias ? TRUE : FALSE;
 
3180
  ptr->is_alias= alias ? true : false;
3633
3181
  if (lower_case_table_names && table->table.length)
3634
3182
    table->table.length= my_casedn_str(files_charset_info, table->table.str);
3635
3183
  ptr->table_name=table->table.str;
3656
3204
    {
3657
3205
      my_error(ER_UNKNOWN_TABLE, MYF(0),
3658
3206
               ptr->table_name, INFORMATION_SCHEMA_NAME.str);
3659
 
      DBUG_RETURN(0);
 
3207
      return(0);
3660
3208
    }
3661
3209
    ptr->schema_table_name= ptr->table_name;
3662
3210
    ptr->schema_table= schema_table;
3677
3225
          !strcmp(ptr->db, tables->db))
3678
3226
      {
3679
3227
        my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str); /* purecov: tested */
3680
 
        DBUG_RETURN(0);                         /* purecov: tested */
 
3228
        return(0);                              /* purecov: tested */
3681
3229
      }
3682
3230
    }
3683
3231
  }
3712
3260
  ptr->next_name_resolution_table= NULL;
3713
3261
  /* Link table in global list (all used tables) */
3714
3262
  lex->add_to_query_tables(ptr);
3715
 
  DBUG_RETURN(ptr);
 
3263
  return(ptr);
3716
3264
}
3717
3265
 
3718
3266
 
3739
3287
{
3740
3288
  TABLE_LIST *ptr;
3741
3289
  NESTED_JOIN *nested_join;
3742
 
  DBUG_ENTER("init_nested_join");
3743
3290
 
3744
3291
  if (!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+
3745
3292
                                       sizeof(NESTED_JOIN))))
3746
 
    DBUG_RETURN(1);
 
3293
    return(1);
3747
3294
  nested_join= ptr->nested_join=
3748
3295
    ((NESTED_JOIN*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TABLE_LIST))));
3749
3296
 
3754
3301
  embedding= ptr;
3755
3302
  join_list= &nested_join->join_list;
3756
3303
  join_list->empty();
3757
 
  DBUG_RETURN(0);
 
3304
  return(0);
3758
3305
}
3759
3306
 
3760
3307
 
3772
3319
    - 0, otherwise
3773
3320
*/
3774
3321
 
3775
 
TABLE_LIST *st_select_lex::end_nested_join(THD *thd)
 
3322
TABLE_LIST *st_select_lex::end_nested_join(THD *thd __attribute__((unused)))
3776
3323
{
3777
3324
  TABLE_LIST *ptr;
3778
3325
  NESTED_JOIN *nested_join;
3779
 
  DBUG_ENTER("end_nested_join");
3780
3326
 
3781
 
  DBUG_ASSERT(embedding);
 
3327
  assert(embedding);
3782
3328
  ptr= embedding;
3783
3329
  join_list= ptr->join_list;
3784
3330
  embedding= ptr->embedding;
3797
3343
    join_list->pop();
3798
3344
    ptr= 0;                                     // return value
3799
3345
  }
3800
 
  DBUG_RETURN(ptr);
 
3346
  return(ptr);
3801
3347
}
3802
3348
 
3803
3349
 
3819
3365
  TABLE_LIST *ptr;
3820
3366
  NESTED_JOIN *nested_join;
3821
3367
  List<TABLE_LIST> *embedded_list;
3822
 
  DBUG_ENTER("nest_last_join");
3823
3368
 
3824
3369
  if (!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+
3825
3370
                                       sizeof(NESTED_JOIN))))
3826
 
    DBUG_RETURN(0);
 
3371
    return(0);
3827
3372
  nested_join= ptr->nested_join=
3828
3373
    ((NESTED_JOIN*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TABLE_LIST))));
3829
3374
 
3841
3386
    embedded_list->push_back(table);
3842
3387
    if (table->natural_join)
3843
3388
    {
3844
 
      ptr->is_natural_join= TRUE;
 
3389
      ptr->is_natural_join= true;
3845
3390
      /*
3846
3391
        If this is a JOIN ... USING, move the list of joined fields to the
3847
3392
        table reference that describes the join.
3852
3397
  }
3853
3398
  join_list->push_front(ptr);
3854
3399
  nested_join->used_tables= nested_join->not_null_tables= (table_map) 0;
3855
 
  DBUG_RETURN(ptr);
 
3400
  return(ptr);
3856
3401
}
3857
3402
 
3858
3403
 
3872
3417
 
3873
3418
void st_select_lex::add_joined_table(TABLE_LIST *table)
3874
3419
{
3875
 
  DBUG_ENTER("add_joined_table");
3876
3420
  join_list->push_front(table);
3877
3421
  table->join_list= join_list;
3878
3422
  table->embedding= embedding;
3879
 
  DBUG_VOID_RETURN;
 
3423
  return;
3880
3424
}
3881
3425
 
3882
3426
 
3915
3459
{
3916
3460
  TABLE_LIST *tab2= join_list->pop();
3917
3461
  TABLE_LIST *tab1= join_list->pop();
3918
 
  DBUG_ENTER("convert_right_join");
3919
3462
 
3920
3463
  join_list->push_front(tab2);
3921
3464
  join_list->push_front(tab1);
3922
3465
  tab1->outer_join|= JOIN_TYPE_RIGHT;
3923
3466
 
3924
 
  DBUG_RETURN(tab1);
 
3467
  return(tab1);
3925
3468
}
3926
3469
 
3927
3470
/**
3938
3481
void st_select_lex::set_lock_for_tables(thr_lock_type lock_type)
3939
3482
{
3940
3483
  bool for_update= lock_type >= TL_READ_NO_INSERT;
3941
 
  DBUG_ENTER("set_lock_for_tables");
3942
 
  DBUG_PRINT("enter", ("lock_type: %d  for_update: %d", lock_type,
3943
 
                       for_update));
3944
3484
 
3945
3485
  for (TABLE_LIST *tables= (TABLE_LIST*) table_list.first;
3946
3486
       tables;
3949
3489
    tables->lock_type= lock_type;
3950
3490
    tables->updating=  for_update;
3951
3491
  }
3952
 
  DBUG_VOID_RETURN;
 
3492
  return;
3953
3493
}
3954
3494
 
3955
3495
 
3982
3522
bool st_select_lex_unit::add_fake_select_lex(THD *thd_arg)
3983
3523
{
3984
3524
  SELECT_LEX *first_sl= first_select();
3985
 
  DBUG_ENTER("add_fake_select_lex");
3986
 
  DBUG_ASSERT(!fake_select_lex);
 
3525
  assert(!fake_select_lex);
3987
3526
 
3988
3527
  if (!(fake_select_lex= new (thd_arg->mem_root) SELECT_LEX()))
3989
 
      DBUG_RETURN(1);
 
3528
      return(1);
3990
3529
  fake_select_lex->include_standalone(this, 
3991
3530
                                      (SELECT_LEX_NODE**)&fake_select_lex);
3992
3531
  fake_select_lex->select_number= INT_MAX;
3997
3536
 
3998
3537
  fake_select_lex->context.outer_context=first_sl->context.outer_context;
3999
3538
  /* allow item list resolving in fake select for ORDER BY */
4000
 
  fake_select_lex->context.resolve_in_select_list= TRUE;
 
3539
  fake_select_lex->context.resolve_in_select_list= true;
4001
3540
  fake_select_lex->context.select_lex= fake_select_lex;
4002
3541
 
4003
3542
  if (!is_union())
4013
3552
    thd_arg->lex->current_select= fake_select_lex;
4014
3553
  }
4015
3554
  thd_arg->lex->pop_context();
4016
 
  DBUG_RETURN(0);
 
3555
  return(0);
4017
3556
}
4018
3557
 
4019
3558
 
4031
3570
  @param right_op  rigth operand of the JOIN
4032
3571
 
4033
3572
  @retval
4034
 
    FALSE  if all is OK
 
3573
    false  if all is OK
4035
3574
  @retval
4036
 
    TRUE   if a memory allocation error occured
 
3575
    true   if a memory allocation error occured
4037
3576
*/
4038
3577
 
4039
3578
bool
4042
3581
{
4043
3582
  Name_resolution_context *on_context;
4044
3583
  if (!(on_context= new (thd->mem_root) Name_resolution_context))
4045
 
    return TRUE;
 
3584
    return true;
4046
3585
  on_context->init();
4047
3586
  on_context->first_name_resolution_table=
4048
3587
    left_op->first_leaf_for_name_resolution();
4061
3600
  @param expr  the condition to be added to the ON clause
4062
3601
 
4063
3602
  @retval
4064
 
    FALSE  if there was some error
 
3603
    false  if there was some error
4065
3604
  @retval
4066
 
    TRUE   if all is OK
 
3605
    true   if all is OK
4067
3606
*/
4068
3607
 
4069
3608
void add_join_on(TABLE_LIST *b, Item *expr)
4153
3692
  select_errors=0;                              /* Write if more errors */
4154
3693
  bool tmp_write_to_binlog= 1;
4155
3694
 
4156
 
  DBUG_ASSERT(!thd || !thd->in_sub_stmt);
 
3695
  assert(!thd || !thd->in_sub_stmt);
4157
3696
 
4158
3697
  if (options & REFRESH_LOG)
4159
3698
  {
4220
3759
      tmp_write_to_binlog= 0;
4221
3760
      if (lock_global_read_lock(thd))
4222
3761
        return 1;                               // Killed
4223
 
      result= close_cached_tables(thd, tables, FALSE, (options & REFRESH_FAST) ?
4224
 
                                  FALSE : TRUE, TRUE);
 
3762
      result= close_cached_tables(thd, tables, false, (options & REFRESH_FAST) ?
 
3763
                                  false : true, true);
4225
3764
      if (make_global_read_lock_block_commit(thd)) // Killed
4226
3765
      {
4227
3766
        /* Don't leave things in a half-locked state */
4230
3769
      }
4231
3770
    }
4232
3771
    else
4233
 
      result= close_cached_tables(thd, tables, FALSE, (options & REFRESH_FAST) ?
4234
 
                                  FALSE : TRUE, FALSE);
 
3772
      result= close_cached_tables(thd, tables, false, (options & REFRESH_FAST) ?
 
3773
                                  false : true, false);
4235
3774
    my_dbopt_cleanup();
4236
3775
  }
4237
3776
  if (thd && (options & REFRESH_STATUS))
4240
3779
    flush_thread_cache();
4241
3780
  if (options & REFRESH_MASTER)
4242
3781
  {
4243
 
    DBUG_ASSERT(thd);
 
3782
    assert(thd);
4244
3783
    tmp_write_to_binlog= 0;
4245
3784
    if (reset_master(thd))
4246
3785
    {
4271
3810
    This is written such that we have a short lock on LOCK_thread_count
4272
3811
*/
4273
3812
 
4274
 
uint kill_one_thread(THD *thd, ulong id, bool only_kill_query)
 
3813
static unsigned int
 
3814
kill_one_thread(THD *thd __attribute__((unused)),
 
3815
                ulong id, bool only_kill_query)
4275
3816
{
4276
3817
  THD *tmp;
4277
3818
  uint error=ER_NO_SUCH_THREAD;
4278
 
  DBUG_ENTER("kill_one_thread");
4279
 
  DBUG_PRINT("enter", ("id=%lu only_kill=%d", id, only_kill_query));
4280
3819
  VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
4281
3820
  I_List_iterator<THD> it(threads);
4282
3821
  while ((tmp=it++))
4296
3835
    error=0;
4297
3836
    pthread_mutex_unlock(&tmp->LOCK_delete);
4298
3837
  }
4299
 
  DBUG_PRINT("exit", ("%d", error));
4300
 
  DBUG_RETURN(error);
 
3838
  return(error);
4301
3839
}
4302
3840
 
4303
3841
 
4338
3876
    return 1;
4339
3877
  }
4340
3878
  /* Fix is using unix filename format on dos */
4341
 
  strmov(buff,*filename_ptr);
 
3879
  stpcpy(buff,*filename_ptr);
4342
3880
  end=convert_dirname(buff, *filename_ptr, NullS);
4343
3881
  if (!(ptr= (char*) thd->alloc((size_t) (end-buff) + strlen(table_name)+1)))
4344
3882
    return 1;                                   // End of memory
4366
3904
    char command[80];
4367
3905
    Lex_input_stream *lip= thd->m_lip;
4368
3906
    strmake(command, lip->yylval->symbol.str,
4369
 
            min(lip->yylval->symbol.length, sizeof(command)-1));
 
3907
            min((ulong)lip->yylval->symbol.length, sizeof(command)-1));
4370
3908
    my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command);
4371
3909
    return 1;
4372
3910
  }
4448
3986
  @param tables Global/local table list (have to be the same)
4449
3987
 
4450
3988
  @retval
4451
 
    FALSE OK
 
3989
    false OK
4452
3990
  @retval
4453
 
    TRUE  Error
 
3991
    true  Error
4454
3992
*/
4455
3993
 
4456
 
bool multi_update_precheck(THD *thd, TABLE_LIST *tables)
 
3994
bool multi_update_precheck(THD *thd,
 
3995
                           TABLE_LIST *tables __attribute__((unused)))
4457
3996
{
4458
3997
  const char *msg= 0;
4459
3998
  LEX *lex= thd->lex;
4460
3999
  SELECT_LEX *select_lex= &lex->select_lex;
4461
 
  DBUG_ENTER("multi_update_precheck");
4462
4000
 
4463
4001
  if (select_lex->item_list.elements != lex->value_list.elements)
4464
4002
  {
4465
4003
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
4466
 
    DBUG_RETURN(TRUE);
 
4004
    return(true);
4467
4005
  }
4468
4006
 
4469
4007
  if (select_lex->order_list.elements)
4473
4011
  if (msg)
4474
4012
  {
4475
4013
    my_error(ER_WRONG_USAGE, MYF(0), "UPDATE", msg);
4476
 
    DBUG_RETURN(TRUE);
 
4014
    return(true);
4477
4015
  }
4478
 
  DBUG_RETURN(FALSE);
 
4016
  return(false);
4479
4017
}
4480
4018
 
4481
4019
/**
4485
4023
  @param tables         Global/local table list
4486
4024
 
4487
4025
  @retval
4488
 
    FALSE OK
 
4026
    false OK
4489
4027
  @retval
4490
 
    TRUE  error
 
4028
    true  error
4491
4029
*/
4492
4030
 
4493
 
bool multi_delete_precheck(THD *thd, TABLE_LIST *tables)
 
4031
bool multi_delete_precheck(THD *thd,
 
4032
                           TABLE_LIST *tables __attribute__((unused)))
4494
4033
{
4495
4034
  SELECT_LEX *select_lex= &thd->lex->select_lex;
4496
4035
  TABLE_LIST **save_query_tables_own_last= thd->lex->query_tables_own_last;
4497
 
  DBUG_ENTER("multi_delete_precheck");
4498
4036
 
4499
4037
  thd->lex->query_tables_own_last= 0;
4500
4038
  thd->lex->query_tables_own_last= save_query_tables_own_last;
4503
4041
  {
4504
4042
    my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE,
4505
4043
               ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0));
4506
 
    DBUG_RETURN(TRUE);
 
4044
    return(true);
4507
4045
  }
4508
 
  DBUG_RETURN(FALSE);
 
4046
  return(false);
4509
4047
}
4510
4048
 
4511
4049
 
4526
4064
  @return Matching table, NULL otherwise.
4527
4065
*/
4528
4066
 
4529
 
static TABLE_LIST *multi_delete_table_match(LEX *lex, TABLE_LIST *tbl,
 
4067
static TABLE_LIST *multi_delete_table_match(LEX *lex __attribute__((unused)),
 
4068
                                            TABLE_LIST *tbl,
4530
4069
                                            TABLE_LIST *tables)
4531
4070
{
4532
4071
  TABLE_LIST *match= NULL;
4533
 
  DBUG_ENTER("multi_delete_table_match");
4534
4072
 
4535
4073
  for (TABLE_LIST *elem= tables; elem; elem= elem->next_local)
4536
4074
  {
4553
4091
    if (match)
4554
4092
    {
4555
4093
      my_error(ER_NONUNIQ_TABLE, MYF(0), elem->alias);
4556
 
      DBUG_RETURN(NULL);
 
4094
      return(NULL);
4557
4095
    }
4558
4096
 
4559
4097
    match= elem;
4562
4100
  if (!match)
4563
4101
    my_error(ER_UNKNOWN_TABLE, MYF(0), tbl->table_name, "MULTI DELETE");
4564
4102
 
4565
 
  DBUG_RETURN(match);
 
4103
  return(match);
4566
4104
}
4567
4105
 
4568
4106
 
4573
4111
  @param lex   pointer to LEX representing multi-delete
4574
4112
 
4575
4113
  @retval
4576
 
    FALSE   success
 
4114
    false   success
4577
4115
  @retval
4578
 
    TRUE    error
 
4116
    true    error
4579
4117
*/
4580
4118
 
4581
4119
bool multi_delete_set_locks_and_link_aux_tables(LEX *lex)
4582
4120
{
4583
4121
  TABLE_LIST *tables= (TABLE_LIST*)lex->select_lex.table_list.first;
4584
4122
  TABLE_LIST *target_tbl;
4585
 
  DBUG_ENTER("multi_delete_set_locks_and_link_aux_tables");
4586
4123
 
4587
4124
  lex->table_count= 0;
4588
4125
 
4593
4130
    /* All tables in aux_tables must be found in FROM PART */
4594
4131
    TABLE_LIST *walk= multi_delete_table_match(lex, target_tbl, tables);
4595
4132
    if (!walk)
4596
 
      DBUG_RETURN(TRUE);
 
4133
      return(true);
4597
4134
    if (!walk->derived)
4598
4135
    {
4599
4136
      target_tbl->table_name= walk->table_name;
4603
4140
    walk->lock_type= target_tbl->lock_type;
4604
4141
    target_tbl->correspondent_table= walk;      // Remember corresponding table
4605
4142
  }
4606
 
  DBUG_RETURN(FALSE);
 
4143
  return(false);
4607
4144
}
4608
4145
 
4609
4146
 
4614
4151
  @param tables Global table list
4615
4152
 
4616
4153
  @retval
4617
 
    FALSE OK
 
4154
    false OK
4618
4155
  @retval
4619
 
    TRUE  Error
 
4156
    true  Error
4620
4157
*/
4621
4158
 
4622
 
bool update_precheck(THD *thd, TABLE_LIST *tables)
 
4159
bool update_precheck(THD *thd, TABLE_LIST *tables __attribute__((unused)))
4623
4160
{
4624
 
  DBUG_ENTER("update_precheck");
4625
4161
  if (thd->lex->select_lex.item_list.elements != thd->lex->value_list.elements)
4626
4162
  {
4627
4163
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
4628
 
    DBUG_RETURN(TRUE);
 
4164
    return(true);
4629
4165
  }
4630
 
  DBUG_RETURN(FALSE);
 
4166
  return(false);
4631
4167
}
4632
4168
 
4633
4169
 
4638
4174
  @param tables Global table list
4639
4175
 
4640
4176
  @retval
4641
 
    FALSE  OK
 
4177
    false  OK
4642
4178
  @retval
4643
 
    TRUE   error
 
4179
    true   error
4644
4180
*/
4645
4181
 
4646
 
bool insert_precheck(THD *thd, TABLE_LIST *tables)
 
4182
bool insert_precheck(THD *thd, TABLE_LIST *tables __attribute__((unused)))
4647
4183
{
4648
4184
  LEX *lex= thd->lex;
4649
 
  DBUG_ENTER("insert_precheck");
4650
4185
 
4651
4186
  /*
4652
4187
    Check that we have modify privileges for the first table and
4655
4190
  if (lex->update_list.elements != lex->value_list.elements)
4656
4191
  {
4657
4192
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
4658
 
    DBUG_RETURN(TRUE);
 
4193
    return(true);
4659
4194
  }
4660
 
  DBUG_RETURN(FALSE);
 
4195
  return(false);
4661
4196
}
4662
4197
 
4663
4198
 
4669
4204
  @param create_table           Table which will be created
4670
4205
 
4671
4206
  @retval
4672
 
    FALSE   OK
 
4207
    false   OK
4673
4208
  @retval
4674
 
    TRUE   Error
 
4209
    true   Error
4675
4210
*/
4676
4211
 
4677
 
bool create_table_precheck(THD *thd, TABLE_LIST *tables,
 
4212
bool create_table_precheck(THD *thd,
 
4213
                           TABLE_LIST *tables __attribute__((unused)),
4678
4214
                           TABLE_LIST *create_table)
4679
4215
{
4680
4216
  LEX *lex= thd->lex;
4681
4217
  SELECT_LEX *select_lex= &lex->select_lex;
4682
 
  bool error= TRUE;                                 // Error message is given
4683
 
  DBUG_ENTER("create_table_precheck");
 
4218
  bool error= true;                                 // Error message is given
4684
4219
 
4685
4220
  if (create_table && (strcmp(create_table->db, "information_schema") == 0))
4686
4221
  {
4687
4222
    my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.str);
4688
 
    DBUG_RETURN(TRUE);
 
4223
    return(true);
4689
4224
  }
4690
4225
 
4691
4226
  if (select_lex->item_list.elements)
4708
4243
          find_table_in_global_list(tables, create_table->db,
4709
4244
                                    create_table->table_name))
4710
4245
      {
4711
 
        error= FALSE;
 
4246
        error= false;
4712
4247
        goto err;
4713
4248
      }
4714
4249
    }
4715
4250
#endif
4716
4251
  }
4717
 
  error= FALSE;
 
4252
  error= false;
4718
4253
 
4719
 
  DBUG_RETURN(error);
 
4254
  return(error);
4720
4255
}
4721
4256
 
4722
4257
 
4762
4297
  @param max_length  max length
4763
4298
 
4764
4299
  @retval
4765
 
    FALSE   the passed string is not longer than max_length
 
4300
    false   the passed string is not longer than max_length
4766
4301
  @retval
4767
 
    TRUE    the passed string is longer than max_length
 
4302
    true    the passed string is longer than max_length
4768
4303
 
4769
4304
  NOTE
4770
4305
    The function is not used in existing code but can be useful later?
4774
4309
                              uint max_byte_length)
4775
4310
{
4776
4311
  if (str->length <= max_byte_length)
4777
 
    return FALSE;
 
4312
    return false;
4778
4313
 
4779
4314
  my_error(ER_WRONG_STRING_LENGTH, MYF(0), str->str, err_msg, max_byte_length);
4780
4315
 
4781
 
  return TRUE;
 
4316
  return true;
4782
4317
}
4783
4318
 
4784
4319
 
4793
4328
      cs               string charset
4794
4329
 
4795
4330
  RETURN
4796
 
    FALSE   the passed string is not longer than max_char_length
4797
 
    TRUE    the passed string is longer than max_char_length
 
4331
    false   the passed string is not longer than max_char_length
 
4332
    true    the passed string is longer than max_char_length
4798
4333
*/
4799
4334
 
4800
4335
 
4801
4336
bool check_string_char_length(LEX_STRING *str, const char *err_msg,
4802
 
                              uint max_char_length, CHARSET_INFO *cs,
 
4337
                              uint max_char_length, const CHARSET_INFO * const cs,
4803
4338
                              bool no_error)
4804
4339
{
4805
4340
  int well_formed_error;
4807
4342
                                      max_char_length, &well_formed_error);
4808
4343
 
4809
4344
  if (!well_formed_error &&  str->length == res)
4810
 
    return FALSE;
 
4345
    return false;
4811
4346
 
4812
4347
  if (!no_error)
4813
4348
    my_error(ER_WRONG_STRING_LENGTH, MYF(0), str->str, err_msg, max_char_length);
4814
 
  return TRUE;
 
4349
  return true;
4815
4350
}
4816
4351
 
4817
4352
 
4824
4359
    so they should be prohibited until such support is done.
4825
4360
    This is why we use the 3-byte utf8 to check well-formedness here.
4826
4361
  */
4827
 
  CHARSET_INFO *cs= &my_charset_utf8mb3_general_ci;
 
4362
  const CHARSET_INFO * const cs= &my_charset_utf8mb3_general_ci;
4828
4363
#else
4829
 
  CHARSET_INFO *cs= system_charset_info;
 
4364
  const CHARSET_INFO * const cs= system_charset_info;
4830
4365
#endif
4831
4366
  int well_formed_error;
4832
4367
  uint res= cs->cset->well_formed_len(cs, str->str, str->str + str->length,
4835
4370
  if (well_formed_error)
4836
4371
  {
4837
4372
    my_error(ER_INVALID_CHARACTER_STRING, MYF(0), "identifier", str->str);
4838
 
    return TRUE;
 
4373
    return true;
4839
4374
  }
4840
4375
  
4841
4376
  if (str->length == res)
4842
 
    return FALSE;
 
4377
    return false;
4843
4378
 
4844
4379
  switch (err_code)
4845
4380
  {
4852
4387
    my_error(err_code, MYF(0), str->str);
4853
4388
    break;
4854
4389
  default:
4855
 
    DBUG_ASSERT(0);
 
4390
    assert(0);
4856
4391
    break;
4857
4392
  }
4858
 
  return TRUE;
 
4393
  return true;
4859
4394
}
4860
4395
 
4861
4396
 
4876
4411
{
4877
4412
  char path[FN_REFLEN], conv_path[FN_REFLEN];
4878
4413
  uint dir_len, home_dir_len= strlen(mysql_unpacked_real_data_home);
4879
 
  DBUG_ENTER("test_if_data_home_dir");
4880
4414
 
4881
4415
  if (!dir)
4882
 
    DBUG_RETURN(0);
 
4416
    return(0);
4883
4417
 
4884
4418
  (void) fn_format(path, dir, "", "",
4885
4419
                   (MY_RETURN_REAL_PATH|MY_RESOLVE_SYMLINKS));
4887
4421
 
4888
4422
  if (home_dir_len < dir_len)
4889
4423
  {
4890
 
    if (lower_case_file_system)
4891
 
    {
4892
 
      if (!my_strnncoll(character_set_filesystem,
4893
 
                        (const uchar*) conv_path, home_dir_len,
4894
 
                        (const uchar*) mysql_unpacked_real_data_home,
4895
 
                        home_dir_len))
4896
 
        DBUG_RETURN(1);
4897
 
    }
4898
 
    else if (!memcmp(conv_path, mysql_unpacked_real_data_home, home_dir_len))
4899
 
      DBUG_RETURN(1);
 
4424
    if (!my_strnncoll(character_set_filesystem,
 
4425
                      (const uchar*) conv_path, home_dir_len,
 
4426
                      (const uchar*) mysql_unpacked_real_data_home,
 
4427
                      home_dir_len))
 
4428
      return(1);
4900
4429
  }
4901
 
  DBUG_RETURN(0);
 
4430
  return(0);
4902
4431
}
4903
4432
 
4904
4433
 
4911
4440
 
4912
4441
  @param thd Thread context.
4913
4442
  @param lip Lexer context.
4914
 
  @param creation_ctx Object creation context.
4915
4443
 
4916
4444
  @return Error status.
4917
 
    @retval FALSE on success.
4918
 
    @retval TRUE on parsing error.
 
4445
    @retval false on success.
 
4446
    @retval true on parsing error.
4919
4447
*/
4920
4448
 
4921
 
bool parse_sql(THD *thd,
4922
 
               Lex_input_stream *lip,
4923
 
               Object_creation_ctx *creation_ctx)
 
4449
bool parse_sql(THD *thd, Lex_input_stream *lip)
4924
4450
{
4925
 
  DBUG_ASSERT(thd->m_lip == NULL);
4926
 
 
4927
 
  /* Backup creation context. */
4928
 
 
4929
 
  Object_creation_ctx *backup_ctx= NULL;
4930
 
 
4931
 
  if (creation_ctx)
4932
 
    backup_ctx= creation_ctx->set_n_backup(thd);
 
4451
  assert(thd->m_lip == NULL);
4933
4452
 
4934
4453
  /* Set Lex_input_stream. */
4935
4454
 
4941
4460
 
4942
4461
  /* Check that if MYSQLparse() failed, thd->is_error() is set. */
4943
4462
 
4944
 
  DBUG_ASSERT(!mysql_parse_status || thd->is_error());
 
4463
  assert(!mysql_parse_status || thd->is_error());
4945
4464
 
4946
4465
  /* Reset Lex_input_stream. */
4947
4466
 
4948
4467
  thd->m_lip= NULL;
4949
4468
 
4950
 
  /* Restore creation context. */
4951
 
 
4952
 
  if (creation_ctx)
4953
 
    creation_ctx->restore_env(thd, backup_ctx);
4954
 
 
4955
4469
  /* That's it. */
4956
4470
 
4957
4471
  return mysql_parse_status || thd->is_fatal_error;