14
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
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 <drizzled/drizzled_error_messages.h>
26
24
@defgroup Runtime_Environment Runtime Environment
30
static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables);
32
29
const char *any_db="*any*"; // Special symbol for check_access
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
83
70
bool end_active_trans(THD *thd)
86
DBUG_ENTER("end_active_trans");
87
73
if (unlikely(thd->in_sub_stmt))
89
75
my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
92
78
if (thd->transaction.xid_state.xa_state != XA_NOTR)
94
80
my_error(ER_XAER_RMFAIL, MYF(0),
95
81
xa_state_names[thd->transaction.xid_state.xa_state]);
98
84
if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN |
99
85
OPTION_TABLE_LOCK))
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;
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;
284
255
thd->net.vio= save_vio;
289
Execute commands from bootstrap_file.
291
Used when creating the initial grant tables.
294
pthread_handler_t handle_bootstrap(void *arg)
297
FILE *file=bootstrap_file;
299
const char* found_semicolon= NULL;
301
/* The following must be called before DBUG_ENTER */
302
thd->thread_stack= (char*) &thd;
303
if (my_thread_init() || thd->store_globals())
305
close_connection(thd, ER_OUT_OF_RESOURCES, 1);
309
DBUG_ENTER("handle_bootstrap");
311
pthread_detach_this_thread();
312
thd->thread_stack= (char*) &thd;
314
if (thd->variables.max_join_size == HA_POS_ERROR)
315
thd->options |= OPTION_BIG_SELECTS;
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;
323
Make the "client" handle multiple results. This is necessary
324
to enable stored procedures with SELECTs and Dynamic SQL
327
thd->client_capabilities|= CLIENT_MULTI_RESULTS;
329
buff= (char*) thd->net.buff;
330
thd->init_for_queries();
331
while (fgets(buff, thd->net.max_packet, file))
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))
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.
341
/* purecov: begin tested */
342
if (net_realloc(&(thd->net), 2 * thd->net.max_packet))
344
net_end_statement(thd);
348
buff= (char*) thd->net.buff;
349
fgets(buff + length, thd->net.max_packet - length, file);
350
length+= (ulong) strlen(buff + length);
354
break; /* purecov: inspected */
356
while (length && (my_isspace(thd->charset(), buff[length-1]) ||
357
buff[length-1] == ';'))
361
/* Skip lines starting with delimiter */
362
if (strncmp(buff, STRING_WITH_LEN("delimiter")) == 0)
365
thd->query_length=length;
366
thd->query= (char*) thd->memdup_w_gap(buff, length+1,
368
thd->query[length] = '\0';
369
DBUG_PRINT("query",("%-.4096s",thd->query));
372
We don't need to obtain LOCK_thread_count here because in bootstrap
373
mode we have only one thread.
375
thd->query_id=next_query_id();
377
mysql_parse(thd, thd->query, length, & found_semicolon);
378
close_thread_tables(thd); // Free tables
380
bootstrap_error= thd->is_error();
381
net_end_statement(thd);
386
free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
387
free_root(&thd->transaction.mem_root,MYF(MY_KEEP_PREALLOC));
395
(void) pthread_mutex_lock(&LOCK_thread_count);
397
(void) pthread_mutex_unlock(&LOCK_thread_count);
398
(void) pthread_cond_broadcast(&COND_thread_count);
404
/* This works because items are allocated with sql_alloc() */
406
void free_items(Item *item)
409
DBUG_ENTER("free_items");
410
for (; item ; item=next)
418
/* This works because items are allocated with sql_alloc() */
420
void cleanup_items(Item *item)
422
DBUG_ENTER("cleanup_items");
423
for (; item ; item=item->next)
429
259
Ends the current transaction and (maybe) begin the next.
591
415
if (command >= COM_END)
592
416
command= COM_END; // Wrong command
594
DBUG_PRINT("info",("Command on %s = %d (%s)",
595
vio_description(net->vio), command,
596
command_name[command].str));
598
418
/* Restore read timeout value */
599
419
my_net_set_read_timeout(net, thd->variables.net_read_timeout);
601
DBUG_ASSERT(packet_length);
421
assert(packet_length);
602
422
return_value= dispatch_command(command, thd, packet+1, (uint) (packet_length-1));
605
DBUG_RETURN(return_value);
425
return(return_value);
616
436
@see mysql_execute_command
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.
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)
626
DBUG_ENTER("deny_updates_if_read_only_option");
628
446
if (!opt_readonly)
631
449
LEX *lex= thd->lex;
633
451
if (!(sql_command_flags[lex->sql_command] & CF_CHANGES_DATA))
636
454
/* Multi update is an exception and is dealt with later. */
637
455
if (lex->sql_command == SQLCOM_UPDATE_MULTI)
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);
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;
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);
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);
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))
742
551
general_log_write(thd, command, thd->db, thd->db_length);
859
case COM_STMT_EXECUTE:
861
case COM_STMT_SEND_LONG_DATA:
862
case COM_STMT_PREPARE:
866
/* We should toss an error here */
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;
877
675
general_log_write(thd, command, thd->query, thd->query_length);
878
DBUG_PRINT("query",("%-.4096s",thd->query));
880
if (!(specialflag & SPECIAL_NO_PRIOR))
882
struct sched_param tmp_sched_param;
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);
889
677
mysql_parse(thd, thd->query, thd->query_length, &end_of_stmt);
923
711
mysql_parse(thd, beginning_of_next_stmt, length, &end_of_stmt);
926
if (!(specialflag & SPECIAL_NO_PRIOR))
928
struct sched_param tmp_sched_param;
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);
934
DBUG_PRINT("info",("query ready"));
937
715
case COM_FIELD_LIST: // This isn't actually needed
1039
817
my_error(ER_NOT_SUPPORTED_YET, MYF(0), "this shutdown level");
1042
DBUG_PRINT("quit",("Got shutdown command for level %u", level));
1043
820
general_log_print(thd, command, NullS);
1045
822
close_thread_tables(thd); // Free before kill
1050
case COM_STATISTICS:
1052
STATUS_VAR current_global_status_var;
1055
ulonglong queries_per_second1000;
1057
uint buff_len= sizeof(buff);
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(¤t_global_status_var);
1062
if (!(uptime= (ulong) (thd->start_time - server_start_time)))
1063
queries_per_second1000= 0;
1065
queries_per_second1000= thd->query_id * LL(1000) / uptime;
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",
1072
(int) thread_count, (ulong) thd->query_id,
1073
current_global_status_var.long_query_count,
1074
current_global_status_var.opened_tables,
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();
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));
1179
914
void log_slow_statement(THD *thd)
1181
DBUG_ENTER("log_slow_statement");
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
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
1192
925
Do not log administrative statements unless the appropriate option is
1267
999
if (check_db_name(&db))
1269
1001
my_error(ER_WRONG_DB_NAME, MYF(0), db.str);
1274
1006
case SCH_COLUMNS:
1275
1007
case SCH_STATISTICS:
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))
1285
1017
lex->query_tables_last= query_tables_last;
1598
1313
case SQLCOM_SHOW_WARNS:
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)
1607
1322
case SQLCOM_SHOW_ERRORS:
1609
1324
res= mysqld_show_warnings(thd, (ulong)
1610
(1L << (uint) MYSQL_ERROR::WARN_LEVEL_ERROR));
1613
case SQLCOM_SHOW_NEW_MASTER:
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");
1620
res = show_new_master(thd);
1625
#ifdef HAVE_REPLICATION
1325
(1L << (uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR));
1626
1328
case SQLCOM_SHOW_SLAVE_HOSTS:
1628
1330
res = show_slave_hosts(thd);
1633
1335
res = mysql_show_binlog_events(thd);
1638
1339
case SQLCOM_ASSIGN_TO_KEYCACHE:
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);
1644
case SQLCOM_PRELOAD_KEYS:
1646
DBUG_ASSERT(first_table == all_tables && first_table != 0);
1647
res = mysql_preload_keys(thd, first_table);
1650
#ifdef HAVE_REPLICATION
1651
1345
case SQLCOM_CHANGE_MASTER:
1653
1347
pthread_mutex_lock(&LOCK_active_mi);
1779
1467
select_lex->options|= SELECT_NO_UNLOCK;
1780
1468
unit->set_limit(select_lex);
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.
1787
if (create_info.used_fields & HA_CREATE_USED_UNION)
1789
my_error(ER_WRONG_OBJECT, MYF(0), create_table->db,
1790
create_table->table_name, "BASE TABLE");
1792
goto end_with_restore_list;
1795
1470
if (!(create_info.options & HA_LEX_CREATE_TMP_TABLE))
1797
1472
lex->link_first_table_back(create_table, link_to_local);
1798
create_table->create= TRUE;
1473
create_table->create= true;
1801
1476
if (!(res= open_and_lock_tables(thd, lex->query_tables)))
1815
1490
goto end_with_restore_list;
1818
/* If we create merge table, we have to test tables in merge, too */
1819
if (create_info.used_fields & HA_CREATE_USED_UNION)
1822
for (tab= (TABLE_LIST*) create_info.merge_list.first;
1824
tab= tab->next_local)
1826
TABLE_LIST *duplicate;
1827
if ((duplicate= unique_table(thd, tab, select_tables, 0)))
1829
update_non_unique_table_error(tab, "CREATE", duplicate);
1831
goto end_with_restore_list;
1837
1495
select_create is currently not re-execution friendly and
1976
1632
/* Must be set in the parser */
1977
DBUG_ASSERT(select_lex->db);
1633
assert(select_lex->db);
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;
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 */
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);
2044
1700
res= mysqld_show_create(thd, first_table);
2047
1703
case SQLCOM_CHECKSUM:
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);
2053
1709
case SQLCOM_REPAIR:
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 */
2108
1764
Presumably, OPTIMIZE and binlog writing doesn't require synchronization
2110
write_bin_log(thd, TRUE, thd->query, thd->query_length);
1766
write_bin_log(thd, true, thd->query, thd->query_length);
2112
1768
select_lex->table_list.first= (uchar*) first_table;
2113
1769
lex->query_tables=all_tables;
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))
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,
2189
1841
case SQLCOM_REPLACE:
2191
if (mysql_bin_log.is_open())
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
2200
Observe that any row events that are generated will be
2203
This is only for testing purposes and will not be present in a
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;);
2213
Incident_log_event ev(thd, incident);
2214
mysql_bin_log.write(&ev);
2215
mysql_bin_log.rotate_and_purge(RP_FORCE_ROTATE);
2217
DBUG_PRINT("debug", ("Just after generate_incident()"));
2220
1842
case SQLCOM_INSERT:
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)))
2657
2270
res= mysql_rm_db(thd, lex->name.str, lex->drop_if_exists, 0);
2660
case SQLCOM_ALTER_DB_UPGRADE:
2662
LEX_STRING *db= & lex->name;
2663
if (end_active_trans(thd))
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)))
2674
my_message(ER_SLAVE_IGNORED_TABLE, ER(ER_SLAVE_IGNORED_TABLE), MYF(0));
2678
if (check_db_name(db))
2680
my_error(ER_WRONG_DB_NAME, MYF(0), db->str);
2683
if (thd->locked_tables || thd->active_transaction())
2686
my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
2687
ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
2691
res= mysql_upgrade_db(thd, db);
2696
2273
case SQLCOM_ALTER_DB:
2698
2275
LEX_STRING *db= &lex->name;
2854
2427
if (ha_rollback_to_savepoint(thd, sv))
2855
res= TRUE; // cannot happen
2428
res= true; // cannot happen
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));
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));
3087
2652
*yyss=(short*) lex->yacc_yyss;
3088
2653
*yyvs=(YYSTYPE*) lex->yacc_yyvs;
3396
2951
LEX *lex= thd->lex;
3398
DBUG_ENTER("mysql_test_parse_for_slave");
3400
2954
Lex_input_stream lip(thd, inBuf, length);
3401
2955
lex_start(thd);
3402
2956
mysql_reset_thd_for_next_command(thd);
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();
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,
3430
List<String> *interval_list, CHARSET_INFO *cs)
2982
List<String> *interval_list, const CHARSET_INFO * const cs)
3432
2984
register Create_field *new_field;
3433
2985
LEX *lex= thd->lex;
3434
DBUG_ENTER("add_field_to_list");
3436
2987
if (check_identifier_name(field_name, ER_TOO_LONG_IDENT))
3437
DBUG_RETURN(1); /* purecov: inspected */
2988
return(1); /* purecov: inspected */
3439
2990
if (type_modifier & PRI_KEY_FLAG)
3482
3033
my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
3486
3037
else if (type_modifier & AUTO_INCREMENT_FLAG)
3488
3039
my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
3493
if (on_update_value && type != MYSQL_TYPE_TIMESTAMP)
3044
if (on_update_value && type != DRIZZLE_TYPE_TIMESTAMP)
3495
3046
my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name->str);
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))
3053
interval_list, cs, 0, column_format))
3506
3056
lex->alter_info.create_list.push_back(new_field);
3507
3057
lex->last_field=new_field;
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");
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))
3596
3144
my_error(ER_WRONG_TABLE_NAME, MYF(0), table->table.str);
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))
3603
3151
my_error(ER_WRONG_DB_NAME, MYF(0), table->db.str);
3607
3155
if (!alias) /* Alias is case sensitive */
3611
3159
my_message(ER_DERIVED_MUST_HAVE_ALIAS,
3612
3160
ER(ER_DERIVED_MUST_HAVE_ALIAS), MYF(0));
3615
3163
if (!(alias_str= (char*) thd->memdup(alias_str,table->table.length+1)))
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)
3623
3171
ptr->db= table->db.str;
3624
3172
ptr->db_length= table->db.length;
3626
3174
else if (lex->copy_db_to(&ptr->db, &ptr->db_length))
3629
ptr->is_fqtn= FALSE;
3177
ptr->is_fqtn= false;
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;
4271
3810
This is written such that we have a short lock on LOCK_thread_count
4274
uint kill_one_thread(THD *thd, ulong id, bool only_kill_query)
3814
kill_one_thread(THD *thd __attribute__((unused)),
3815
ulong id, bool only_kill_query)
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++))
4448
3986
@param tables Global/local table list (have to be the same)
4456
bool multi_update_precheck(THD *thd, TABLE_LIST *tables)
3994
bool multi_update_precheck(THD *thd,
3995
TABLE_LIST *tables __attribute__((unused)))
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");
4463
4001
if (select_lex->item_list.elements != lex->value_list.elements)
4465
4003
my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
4469
4007
if (select_lex->order_list.elements)
4669
4204
@param create_table Table which will be created
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)
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
4685
4220
if (create_table && (strcmp(create_table->db, "information_schema") == 0))
4687
4222
my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.str);
4691
4226
if (select_lex->item_list.elements)
4888
4422
if (home_dir_len < dir_len)
4890
if (lower_case_file_system)
4892
if (!my_strnncoll(character_set_filesystem,
4893
(const uchar*) conv_path, home_dir_len,
4894
(const uchar*) mysql_unpacked_real_data_home,
4898
else if (!memcmp(conv_path, mysql_unpacked_real_data_home, home_dir_len))
4424
if (!my_strnncoll(character_set_filesystem,
4425
(const uchar*) conv_path, home_dir_len,
4426
(const uchar*) mysql_unpacked_real_data_home,
4912
4441
@param thd Thread context.
4913
4442
@param lip Lexer context.
4914
@param creation_ctx Object creation context.
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.
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)
4925
DBUG_ASSERT(thd->m_lip == NULL);
4927
/* Backup creation context. */
4929
Object_creation_ctx *backup_ctx= NULL;
4932
backup_ctx= creation_ctx->set_n_backup(thd);
4451
assert(thd->m_lip == NULL);
4934
4453
/* Set Lex_input_stream. */