18
18
#include <drizzled/server_includes.h>
19
19
#include <drizzled/sql_select.h>
20
20
#include <drizzled/sql_show.h>
21
#include "repl_failsafe.h"
22
21
#include <mysys/my_dir.h>
23
#include <libdrizzle/gettext.h>
22
#include <drizzled/gettext.h>
23
#include <drizzled/util/convert.h>
24
#include <drizzled/error.h>
25
27
inline const char *
26
28
str_or_nil(const char *str)
31
33
/* Match the values of enum ha_choice */
32
34
static const char *ha_choice_values[] = {"", "0", "1"};
34
static void store_key_options(THD *thd, String *packet, Table *table,
36
static void store_key_options(Session *session, String *packet, Table *table,
86
88
** List all table types supported
87
89
***************************************************************************/
89
static bool show_plugins(THD *thd, plugin_ref plugin,
91
static bool show_plugins(Session *session, plugin_ref plugin,
92
94
Table *table= (Table*) arg;
169
171
table->field[7]->set_notnull();
171
return schema_table_store_record(thd, table);
173
return schema_table_store_record(session, table);
175
int fill_plugins(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
177
int fill_plugins(Session *session, TableList *tables, COND *cond __attribute__((unused)))
177
179
Table *table= tables->table;
179
if (plugin_foreach_with_mask(thd, show_plugins, DRIZZLE_ANY_PLUGIN,
181
if (plugin_foreach_with_mask(session, show_plugins, DRIZZLE_ANY_PLUGIN,
180
182
~PLUGIN_IS_FREED, table))
207
209
find_files_result
208
find_files(THD *thd, List<LEX_STRING> *files, const char *db,
210
find_files(Session *session, List<LEX_STRING> *files, const char *db,
209
211
const char *path, const char *wild, bool dir)
263
265
if (wild && wild_compare(uname, wild, 0))
266
thd->make_lex_string(file_name, uname, file_name_len, true)))
268
session->make_lex_string(file_name, uname, file_name_len, true)))
269
271
return(FIND_FILES_OOM);
306
mysqld_show_create(THD *thd, TableList *table_list)
308
mysqld_show_create(Session *session, TableList *table_list)
308
Protocol *protocol= thd->protocol;
310
Protocol *protocol= session->protocol;
310
312
String buffer(buff, sizeof(buff), system_charset_info);
312
314
/* Only one table for now, but VIEW can involve several tables */
313
if (open_normal_and_derived_tables(thd, table_list, 0))
315
if (open_normal_and_derived_tables(session, table_list, 0))
315
if (thd->is_error() && thd->main_da.sql_errno() != ER_VIEW_INVALID)
317
if (session->is_error() && session->main_da.sql_errno() != ER_VIEW_INVALID)
320
322
issue a warning with 'warning' level status in
321
323
case of invalid view and last error is ER_VIEW_INVALID
323
drizzle_reset_errors(thd, true);
325
drizzle_reset_errors(session, true);
326
session->clear_error();
327
329
buffer.length(0);
329
if (store_create_info(thd, table_list, &buffer, NULL))
331
if (store_create_info(session, table_list, &buffer, NULL))
332
334
List<Item> field_list;
354
356
if (protocol->write())
361
bool mysqld_show_create_db(THD *thd, char *dbname,
363
bool mysqld_show_create_db(Session *session, char *dbname,
362
364
HA_CREATE_INFO *create_info)
365
367
String buffer(buff, sizeof(buff), system_charset_info);
366
Protocol *protocol=thd->protocol;
368
Protocol *protocol=session->protocol;
368
if (store_db_create_info(thd, dbname, &buffer, create_info))
370
if (store_db_create_info(session, dbname, &buffer, create_info))
371
373
This assumes that the only reason for which store_db_create_info()
401
403
****************************************************************************/
404
mysqld_list_fields(THD *thd, TableList *table_list, const char *wild)
406
mysqld_list_fields(Session *session, TableList *table_list, const char *wild)
408
if (open_normal_and_derived_tables(thd, table_list, 0))
410
if (open_normal_and_derived_tables(session, table_list, 0))
410
412
table= table_list->table;
472
474
append_identifier()
475
session thread handler
474
476
packet target string
475
477
name the identifier to be appended
476
478
name_length length of the appending identifier
480
append_identifier(THD *thd, String *packet, const char *name, uint32_t length)
482
append_identifier(Session *session, String *packet, const char *name, uint32_t length)
482
484
const char *name_end;
484
int q= get_quote_char_for_identifier(thd, name, length);
486
int q= get_quote_char_for_identifier(session, name, length);
542
544
# Quote character
545
int get_quote_char_for_identifier(THD *thd, const char *name, uint32_t length)
547
int get_quote_char_for_identifier(Session *session, const char *name, uint32_t length)
548
550
!is_keyword(name,length) &&
549
551
!require_quotes(name, length) &&
550
!(thd->options & OPTION_QUOTE_SHOW_CREATE))
552
!(session->options & OPTION_QUOTE_SHOW_CREATE))
556
558
/* Append directory name (if exists) to CREATE INFO */
558
static void append_directory(THD *thd __attribute__((unused)),
560
static void append_directory(Session *session __attribute__((unused)),
559
561
String *packet, const char *dir_type,
560
562
const char *filename)
653
int store_create_info(THD *thd, TableList *table_list, String *packet,
655
int store_create_info(Session *session, TableList *table_list, String *packet,
654
656
HA_CREATE_INFO *create_info_arg)
656
658
List<Item> field_list;
657
char tmp[MAX_FIELD_WIDTH], *for_str, buff[128], def_value_buf[MAX_FIELD_WIDTH];
659
char tmp[MAX_FIELD_WIDTH], *for_str, def_value_buf[MAX_FIELD_WIDTH];
658
660
const char *alias;
659
662
String type(tmp, sizeof(tmp), system_charset_info);
660
663
String def_value(def_value_buf, sizeof(def_value_buf), system_charset_info);
661
664
Field **ptr,*field;
688
691
alias= share->table_name.str;
691
append_identifier(thd, packet, alias, strlen(alias));
694
append_identifier(session, packet, alias, strlen(alias));
692
695
packet->append(STRING_WITH_LEN(" (\n"));
694
697
We need this to get default values from the table
705
708
packet->append(STRING_WITH_LEN(",\n"));
707
710
packet->append(STRING_WITH_LEN(" "));
708
append_identifier(thd,packet,field->field_name, strlen(field->field_name));
711
append_identifier(session,packet,field->field_name, strlen(field->field_name));
709
712
packet->append(' ');
710
713
// check for surprises from the previous call to Field::sql_type()
711
714
if (type.ptr() != tmp)
714
717
type.set_charset(system_charset_info);
719
if (field->vcol_info)
721
packet->append(STRING_WITH_LEN("VIRTUAL "));
716
724
field->sql_type(type);
717
725
packet->append(type.ptr(), type.length(), system_charset_info);
727
if (field->vcol_info)
729
packet->append(STRING_WITH_LEN(" AS ("));
730
packet->append(field->vcol_info->expr_str.str,
731
field->vcol_info->expr_str.length,
732
system_charset_info);
733
packet->append(STRING_WITH_LEN(")"));
734
if (field->is_stored)
735
packet->append(STRING_WITH_LEN(" STORED"));
719
738
if (field->has_charset())
721
740
if (field->charset() != share->table_charset)
810
830
packet->append(STRING_WITH_LEN("KEY "));
812
832
if (!found_primary)
813
append_identifier(thd, packet, key_info->name, strlen(key_info->name));
833
append_identifier(session, packet, key_info->name, strlen(key_info->name));
815
835
packet->append(STRING_WITH_LEN(" ("));
820
840
packet->append(',');
822
842
if (key_part->field)
823
append_identifier(thd,packet,key_part->field->field_name,
843
append_identifier(session,packet,key_part->field->field_name,
824
844
strlen(key_part->field->field_name));
825
845
if (key_part->field &&
826
846
(key_part->length !=
827
847
table->field[key_part->fieldnr-1]->key_length()))
831
end= int10_to_str((long) key_part->length /
832
key_part->field->charset()->mbmaxlen,
835
packet->append(buff,(uint) (end-buff));
850
buff= to_string(buff, (int32_t) key_part->length /
851
key_part->field->charset()->mbmaxlen);
853
packet->append(buff.c_str(), buff.length());
838
856
packet->append(')');
839
store_key_options(thd, packet, table, key_info);
857
store_key_options(session, packet, table, key_info);
883
901
if (create_info.auto_increment_value > 1)
886
903
packet->append(STRING_WITH_LEN(" AUTO_INCREMENT="));
887
end= int64_t10_to_str(create_info.auto_increment_value, buff,10);
888
packet->append(buff, (uint) (end - buff));
904
buff= to_string(create_info.auto_increment_value);
905
packet->append(buff.c_str(), buff.length());
891
908
if (share->min_rows)
894
910
packet->append(STRING_WITH_LEN(" MIN_ROWS="));
895
end= int64_t10_to_str(share->min_rows, buff, 10);
896
packet->append(buff, (uint) (end- buff));
911
buff= to_string(share->min_rows);
912
packet->append(buff.c_str(), buff.length());
899
915
if (share->max_rows && !table_list->schema_table)
902
917
packet->append(STRING_WITH_LEN(" MAX_ROWS="));
903
end= int64_t10_to_str(share->max_rows, buff, 10);
904
packet->append(buff, (uint) (end - buff));
918
buff= to_string(share->max_rows);
919
packet->append(buff.c_str(), buff.length());
907
922
if (share->avg_row_length)
910
924
packet->append(STRING_WITH_LEN(" AVG_ROW_LENGTH="));
911
end= int64_t10_to_str(share->avg_row_length, buff,10);
912
packet->append(buff, (uint) (end - buff));
925
buff= to_string(share->avg_row_length);
926
packet->append(buff.c_str(), buff.length());
915
929
if (share->db_create_options & HA_OPTION_PACK_KEYS)
939
953
if (table->s->key_block_size)
942
955
packet->append(STRING_WITH_LEN(" KEY_BLOCK_SIZE="));
943
end= int64_t10_to_str(table->s->key_block_size, buff, 10);
944
packet->append(buff, (uint) (end - buff));
956
buff= to_string(table->s->key_block_size);
957
packet->append(buff.c_str(), buff.length());
946
959
if (share->block_size)
949
961
packet->append(STRING_WITH_LEN(" BLOCK_SIZE="));
950
end= int64_t10_to_str(share->block_size, buff,10);
951
packet->append(buff, (uint) (end - buff));
962
buff= to_string(share->block_size);
963
packet->append(buff.c_str(), buff.length());
953
965
table->file->append_create_info(packet);
954
966
if (share->comment.length)
961
973
packet->append(STRING_WITH_LEN(" CONNECTION="));
962
974
append_unescaped(packet, share->connect_string.str, share->connect_string.length);
964
append_directory(thd, packet, "DATA", create_info.data_file_name);
965
append_directory(thd, packet, "INDEX", create_info.index_file_name);
976
append_directory(session, packet, "DATA", create_info.data_file_name);
977
append_directory(session, packet, "INDEX", create_info.index_file_name);
967
979
table->restore_column_map(old_map);
981
993
the resulting CREATE statement contains "IF NOT EXISTS" clause. Other flags
982
994
in @c create_options are ignored.
984
@param thd The current thread instance.
996
@param session The current thread instance.
985
997
@param dbname The name of the database.
986
998
@param buffer A String instance where the statement is stored.
987
999
@param create_info If not NULL, the options member influences the resulting
990
1002
@returns true if errors are detected, false otherwise.
993
bool store_db_create_info(THD *thd, const char *dbname, String *buffer,
1005
bool store_db_create_info(Session *session, const char *dbname, String *buffer,
994
1006
HA_CREATE_INFO *create_info)
996
1008
HA_CREATE_INFO create;
1018
1030
if (create_options & HA_LEX_CREATE_IF_NOT_EXISTS)
1019
1031
buffer->append(STRING_WITH_LEN("/*!32312 IF NOT EXISTS*/ "));
1021
append_identifier(thd, buffer, dbname, strlen(dbname));
1033
append_identifier(session, buffer, dbname, strlen(dbname));
1023
1035
if (create.default_table_charset)
1093
1105
template class I_List<thread_info>;
1096
void mysqld_list_processes(THD *thd,const char *user, bool verbose)
1108
void mysqld_list_processes(Session *session,const char *user, bool verbose)
1099
1111
List<Item> field_list;
1100
1112
I_List<thread_info> thread_infos;
1101
ulong max_query_length= (verbose ? thd->variables.max_allowed_packet :
1113
ulong max_query_length= (verbose ? session->variables.max_allowed_packet :
1102
1114
PROCESS_LIST_WIDTH);
1103
Protocol *protocol= thd->protocol;
1115
Protocol *protocol= session->protocol;
1105
1117
field_list.push_back(new Item_int("Id", 0, MY_INT32_NUM_DECIMAL_DIGITS));
1106
1118
field_list.push_back(new Item_empty_string("User",16));
1120
1132
pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
1133
if (!session->killed)
1123
I_List_iterator<THD> it(threads);
1135
I_List_iterator<Session> it(threads);
1125
1137
while ((tmp=it++))
1127
1139
Security_context *tmp_sctx= tmp->security_ctx;
1128
1140
struct st_my_thread_var *mysys_var;
1129
1141
if ((tmp->vio_ok() || tmp->system_thread) && (!user || (tmp_sctx->user && !strcmp(tmp_sctx->user, user))))
1131
thread_info *thd_info= new thread_info;
1143
thread_info *session_info= new thread_info;
1133
thd_info->thread_id=tmp->thread_id;
1134
thd_info->user= thd->strdup(tmp_sctx->user ? tmp_sctx->user :
1145
session_info->thread_id=tmp->thread_id;
1146
session_info->user= session->strdup(tmp_sctx->user ? tmp_sctx->user :
1135
1147
(tmp->system_thread ?
1136
1148
"system user" : "unauthenticated user"));
1137
thd_info->host= thd->strdup(tmp_sctx->ip);
1138
if ((thd_info->db=tmp->db)) // Safe test
1139
thd_info->db=thd->strdup(thd_info->db);
1140
thd_info->command=(int) tmp->command;
1149
session_info->host= session->strdup(tmp_sctx->ip);
1150
if ((session_info->db=tmp->db)) // Safe test
1151
session_info->db=session->strdup(session_info->db);
1152
session_info->command=(int) tmp->command;
1141
1153
if ((mysys_var= tmp->mysys_var))
1142
1154
pthread_mutex_lock(&mysys_var->mutex);
1143
thd_info->proc_info= (char*) (tmp->killed == THD::KILL_CONNECTION? "Killed" : 0);
1144
thd_info->state_info= (char*) (tmp->net.reading_or_writing ?
1155
session_info->proc_info= (char*) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0);
1156
session_info->state_info= (char*) (tmp->net.reading_or_writing ?
1145
1157
(tmp->net.reading_or_writing == 2 ?
1146
1158
"Writing to net" :
1147
thd_info->command == COM_SLEEP ? NULL :
1159
session_info->command == COM_SLEEP ? NULL :
1148
1160
"Reading from net") :
1149
1161
tmp->get_proc_info() ? tmp->get_proc_info() :
1150
1162
tmp->mysys_var &&
1163
1175
races with query_length
1165
1177
uint32_t length= cmin((uint32_t)max_query_length, tmp->query_length);
1166
thd_info->query=(char*) thd->strmake(tmp->query,length);
1178
session_info->query=(char*) session->strmake(tmp->query,length);
1168
thread_infos.append(thd_info);
1180
thread_infos.append(session_info);
1172
1184
pthread_mutex_unlock(&LOCK_thread_count);
1174
thread_info *thd_info;
1186
thread_info *session_info;
1175
1187
time_t now= my_time(0);
1176
while ((thd_info=thread_infos.get()))
1188
while ((session_info=thread_infos.get()))
1178
1190
protocol->prepare_for_resend();
1179
protocol->store((uint64_t) thd_info->thread_id);
1180
protocol->store(thd_info->user, system_charset_info);
1181
protocol->store(thd_info->host, system_charset_info);
1182
protocol->store(thd_info->db, system_charset_info);
1183
if (thd_info->proc_info)
1184
protocol->store(thd_info->proc_info, system_charset_info);
1191
protocol->store((uint64_t) session_info->thread_id);
1192
protocol->store(session_info->user, system_charset_info);
1193
protocol->store(session_info->host, system_charset_info);
1194
protocol->store(session_info->db, system_charset_info);
1195
if (session_info->proc_info)
1196
protocol->store(session_info->proc_info, system_charset_info);
1186
protocol->store(command_name[thd_info->command].str, system_charset_info);
1187
if (thd_info->start_time)
1188
protocol->store((uint32_t) (now - thd_info->start_time));
1198
protocol->store(command_name[session_info->command].str, system_charset_info);
1199
if (session_info->start_time)
1200
protocol->store((uint32_t) (now - session_info->start_time));
1190
1202
protocol->store_null();
1191
protocol->store(thd_info->state_info, system_charset_info);
1192
protocol->store(thd_info->query, system_charset_info);
1203
protocol->store(session_info->state_info, system_charset_info);
1204
protocol->store(session_info->query, system_charset_info);
1193
1205
if (protocol->write())
1194
1206
break; /* purecov: inspected */
1200
int fill_schema_processlist(THD* thd, TableList* tables,
1212
int fill_schema_processlist(Session* session, TableList* tables,
1201
1213
COND* cond __attribute__((unused)))
1203
1215
Table *table= tables->table;
1242
1254
if ((mysys_var= tmp->mysys_var))
1243
1255
pthread_mutex_lock(&mysys_var->mutex);
1245
if ((val= (char *) (tmp->killed == THD::KILL_CONNECTION? "Killed" : 0)))
1257
if ((val= (char *) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0)))
1246
1258
table->field[4]->store(val, strlen(val), cs);
1248
1260
table->field[4]->store(command_name[tmp->command].str,
1469
1481
*buf= my_toupper(system_charset_info, *buf);
1472
static bool show_status_array(THD *thd, const char *wild,
1484
static bool show_status_array(Session *session, const char *wild,
1473
1485
SHOW_VAR *variables,
1474
1486
enum enum_var_type value_type,
1475
1487
struct system_status_var *status_var,
1505
1517
Repeat as necessary, if new var is again SHOW_FUNC
1507
1519
for (var=variables; var->type == SHOW_FUNC; var= &tmp)
1508
((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(thd, &tmp, buff);
1520
((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(session, &tmp, buff);
1510
1522
SHOW_TYPE show_type=var->type;
1511
1523
if (show_type == SHOW_ARRAY)
1513
show_status_array(thd, wild, (SHOW_VAR *) var->value, value_type,
1525
show_status_array(session, wild, (SHOW_VAR *) var->value, value_type,
1514
1526
status_var, name_buffer, table, ucase_names);
1672
bool schema_table_store_record(THD *thd, Table *table)
1684
bool schema_table_store_record(Session *session, Table *table)
1675
1687
if ((error= table->file->ha_write_row(table->record[0])))
1677
1689
TMP_TABLE_PARAM *param= table->pos_in_table_list->schema_table_param;
1679
if (create_myisam_from_heap(thd, table, param->start_recinfo,
1691
if (create_myisam_from_heap(session, table, param->start_recinfo,
1680
1692
¶m->recinfo, error, 0))
1687
int make_table_list(THD *thd, SELECT_LEX *sel,
1699
int make_table_list(Session *session, SELECT_LEX *sel,
1688
1700
LEX_STRING *db_name, LEX_STRING *table_name)
1690
1702
Table_ident *table_ident;
1691
table_ident= new Table_ident(thd, *db_name, *table_name, 1);
1703
table_ident= new Table_ident(session, *db_name, *table_name, 1);
1692
1704
sel->init_query();
1693
if (!sel->add_table_to_list(thd, table_ident, 0, 0, TL_READ))
1705
if (!sel->add_table_to_list(session, table_ident, 0, 0, TL_READ))
1704
1716
fill appropriate lookup_field_vals struct field
1705
1717
with this value.
1707
@param[in] thd thread handler
1719
@param[in] session thread handler
1708
1720
@param[in] item_func part of WHERE condition
1709
1721
@param[in] table I_S table
1710
1722
@param[in, out] lookup_field_vals Struct which holds lookup values
1714
1726
1 error, there can be no matching records for the condition
1717
bool get_lookup_value(THD *thd, Item_func *item_func,
1729
bool get_lookup_value(Session *session, Item_func *item_func,
1718
1730
TableList *table,
1719
1731
LOOKUP_FIELD_VALUES *lookup_field_vals)
1763
1775
(unsigned char *) item_field->field_name,
1764
1776
strlen(item_field->field_name), 0))
1766
thd->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1778
session->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1767
1779
tmp_str->length(), false);
1769
1781
/* Lookup value is table name */
1772
1784
(unsigned char *) item_field->field_name,
1773
1785
strlen(item_field->field_name), 0))
1775
thd->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1787
session->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1776
1788
tmp_str->length(), false);
1787
1799
from 'WHERE' condition if it's possible and
1788
1800
fill lookup_field_vals struct fields with these values.
1790
@param[in] thd thread handler
1802
@param[in] session thread handler
1791
1803
@param[in] cond WHERE condition
1792
1804
@param[in] table I_S table
1793
1805
@param[in, out] lookup_field_vals Struct which holds lookup values
1797
1809
1 error, there can be no matching records for the condition
1800
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TableList *table,
1812
bool calc_lookup_values_from_cond(Session *session, COND *cond, TableList *table,
1801
1813
LOOKUP_FIELD_VALUES *lookup_field_vals)
1814
1826
if (item->type() == Item::FUNC_ITEM)
1816
if (get_lookup_value(thd, (Item_func*)item, table, lookup_field_vals))
1828
if (get_lookup_value(session, (Item_func*)item, table, lookup_field_vals))
1821
if (calc_lookup_values_from_cond(thd, item, table, lookup_field_vals))
1833
if (calc_lookup_values_from_cond(session, item, table, lookup_field_vals))
1936
1948
from LEX struct and fill lookup_field_vals struct field
1937
1949
with these values.
1939
@param[in] thd thread handler
1951
@param[in] session thread handler
1940
1952
@param[in] cond WHERE condition
1941
1953
@param[in] tables I_S table
1942
1954
@param[in, out] lookup_field_values Struct which holds lookup values
1946
1958
1 error, there can be no matching records for the condition
1949
bool get_lookup_field_values(THD *thd, COND *cond, TableList *tables,
1961
bool get_lookup_field_values(Session *session, COND *cond, TableList *tables,
1950
1962
LOOKUP_FIELD_VALUES *lookup_field_values)
1964
LEX *lex= session->lex;
1953
1965
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1954
1966
memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1955
1967
switch (lex->sql_command) {
1977
1989
The "default" is for queries over I_S.
1978
1990
All previous cases handle SHOW commands.
1980
return calc_lookup_values_from_cond(thd, cond, tables, lookup_field_values);
1992
return calc_lookup_values_from_cond(session, cond, tables, lookup_field_values);
2009
int make_db_list(THD *thd, List<LEX_STRING> *files,
2021
int make_db_list(Session *session, List<LEX_STRING> *files,
2010
2022
LOOKUP_FIELD_VALUES *lookup_field_vals,
2011
2023
bool *with_i_schema)
2013
2025
LEX_STRING *i_s_name_copy= 0;
2014
i_s_name_copy= thd->make_lex_string(i_s_name_copy,
2026
i_s_name_copy= session->make_lex_string(i_s_name_copy,
2015
2027
INFORMATION_SCHEMA_NAME.str,
2016
2028
INFORMATION_SCHEMA_NAME.length, true);
2017
2029
*with_i_schema= 0;
2031
2043
if (files->push_back(i_s_name_copy))
2034
return (find_files(thd, files, NULL, mysql_data_home,
2046
return (find_files(session, files, NULL, mysql_data_home,
2035
2047
lookup_field_vals->db_value.str, 1) != FIND_FILES_OK);
2062
2074
if (files->push_back(i_s_name_copy))
2064
2076
*with_i_schema= 1;
2065
return (find_files(thd, files, NULL,
2077
return (find_files(session, files, NULL,
2066
2078
mysql_data_home, NULL, 1) != FIND_FILES_OK);
2101
if ((file_name= thd->make_lex_string(file_name, schema_table->table_name,
2113
if ((file_name= session->make_lex_string(file_name, schema_table->table_name,
2102
2114
strlen(schema_table->table_name),
2104
2116
!file_list->push_back(file_name))
2110
int schema_tables_add(THD *thd, List<LEX_STRING> *files, const char *wild)
2122
int schema_tables_add(Session *session, List<LEX_STRING> *files, const char *wild)
2112
2124
LEX_STRING *file_name= 0;
2113
2125
ST_SCHEMA_TABLE *tmp_schema_table= schema_tables;
2132
2144
if ((file_name=
2133
thd->make_lex_string(file_name, tmp_schema_table->table_name,
2145
session->make_lex_string(file_name, tmp_schema_table->table_name,
2134
2146
strlen(tmp_schema_table->table_name), true)) &&
2135
2147
!files->push_back(file_name))
2153
2165
@details The function creates the list of table names in
2156
@param[in] thd thread handler
2168
@param[in] session thread handler
2157
2169
@param[in] table_names List of table names in database
2158
2170
@param[in] lex pointer to LEX struct
2159
2171
@param[in] lookup_field_vals pointer to LOOKUP_FIELD_VALUE struct
2170
make_table_name_list(THD *thd, List<LEX_STRING> *table_names, LEX *lex,
2182
make_table_name_list(Session *session, List<LEX_STRING> *table_names, LEX *lex,
2171
2183
LOOKUP_FIELD_VALUES *lookup_field_vals,
2172
2184
bool with_i_schema, LEX_STRING *db_name)
2199
2211
if (with_i_schema)
2200
return (schema_tables_add(thd, table_names,
2212
return (schema_tables_add(session, table_names,
2201
2213
lookup_field_vals->table_value.str));
2203
find_files_result res= find_files(thd, table_names, db_name->str, path,
2215
find_files_result res= find_files(session, table_names, db_name->str, path,
2204
2216
lookup_field_vals->table_value.str, 0);
2205
2217
if (res != FIND_FILES_OK)
2227
2239
@brief Fill I_S table for SHOW COLUMNS|INDEX commands
2229
@param[in] thd thread handler
2241
@param[in] session thread handler
2230
2242
@param[in] tables TableList for I_S table
2231
2243
@param[in] schema_table pointer to I_S structure
2232
2244
@param[in] open_tables_state_backup pointer to Open_tables_state object
2243
fill_schema_show_cols_or_idxs(THD *thd, TableList *tables,
2255
fill_schema_show_cols_or_idxs(Session *session, TableList *tables,
2244
2256
ST_SCHEMA_TABLE *schema_table,
2245
2257
Open_tables_state *open_tables_state_backup)
2259
LEX *lex= session->lex;
2249
2261
LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
2250
2262
enum_sql_command save_sql_command= lex->sql_command;
2256
2268
lex->all_selects_list= tables->schema_select_lex;
2258
Restore thd->temporary_tables to be able to process
2270
Restore session->temporary_tables to be able to process
2259
2271
temporary tables(only for 'show index' & 'show columns').
2260
2272
This should be changed when processing of temporary tables for
2261
2273
I_S tables will be done.
2263
thd->temporary_tables= open_tables_state_backup->temporary_tables;
2275
session->temporary_tables= open_tables_state_backup->temporary_tables;
2265
2277
Let us set fake sql_command so views won't try to merge
2266
2278
themselves into main statement. If we don't do this,
2268
2280
SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
2270
2282
lex->sql_command= SQLCOM_SHOW_FIELDS;
2271
res= open_normal_and_derived_tables(thd, show_table_list,
2283
res= open_normal_and_derived_tables(session, show_table_list,
2272
2284
DRIZZLE_LOCK_IGNORE_FLUSH);
2273
2285
lex->sql_command= save_sql_command;
2282
2294
in this case(this part of code is used only for
2283
2295
'show columns' & 'show statistics' commands).
2285
table_name= thd->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2297
table_name= session->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2286
2298
strlen(show_table_list->alias), false);
2287
db_name= thd->make_lex_string(&tmp_lex_string, show_table_list->db,
2299
db_name= session->make_lex_string(&tmp_lex_string, show_table_list->db,
2288
2300
show_table_list->db_length, false);
2291
error= test(schema_table->process_table(thd, show_table_list,
2303
error= test(schema_table->process_table(session, show_table_list,
2292
2304
table, res, db_name,
2294
thd->temporary_tables= 0;
2295
close_tables_for_reopen(thd, &show_table_list);
2306
session->temporary_tables= 0;
2307
close_tables_for_reopen(session, &show_table_list);
2301
2313
@brief Fill I_S table for SHOW Table NAMES commands
2303
@param[in] thd thread handler
2315
@param[in] session thread handler
2304
2316
@param[in] table Table struct for I_S table
2305
2317
@param[in] db_name database name
2306
2318
@param[in] table_name table name
2326
2338
char path[FN_REFLEN];
2327
2339
(void) build_table_filename(path, sizeof(path), db_name->str,
2328
2340
table_name->str, reg_ext, 0);
2329
if (mysql_frm_type(thd, path, ¬_used))
2341
if (mysql_frm_type(session, path, ¬_used))
2331
2343
table->field[3]->store(STRING_WITH_LEN("BASE Table"),
2332
2344
system_charset_info);
2393
2405
@brief Fill I_S table with data from FRM file only
2395
@param[in] thd thread handler
2407
@param[in] session thread handler
2396
2408
@param[in] table Table struct for I_S table
2397
2409
@param[in] schema_table I_S table struct
2398
2410
@param[in] db_name database name
2406
2418
open_tables function for this table
2409
static int fill_schema_table_from_frm(THD *thd,TableList *tables,
2421
static int fill_schema_table_from_frm(Session *session,TableList *tables,
2410
2422
ST_SCHEMA_TABLE *schema_table,
2411
2423
LEX_STRING *db_name,
2412
2424
LEX_STRING *table_name,
2427
2439
table_list.table_name= table_name->str;
2428
2440
table_list.db= db_name->str;
2430
key_length= create_table_def_key(thd, key, &table_list, 0);
2442
key_length= create_table_def_key(session, key, &table_list, 0);
2431
2443
pthread_mutex_lock(&LOCK_open);
2432
share= get_table_share(thd, &table_list, key,
2444
share= get_table_share(session, &table_list, key,
2433
2445
key_length, 0, &error);
2442
2454
table_list.table= &tbl;
2443
res= schema_table->process_table(thd, &table_list, table,
2455
res= schema_table->process_table(session, &table_list, table,
2444
2456
res, db_name, table_name);
2473
2485
@retval 1 error
2476
int get_all_tables(THD *thd, TableList *tables, COND *cond)
2488
int get_all_tables(Session *session, TableList *tables, COND *cond)
2490
LEX *lex= session->lex;
2479
2491
Table *table= tables->table;
2480
2492
SELECT_LEX *old_all_select_lex= lex->all_selects_list;
2481
2493
enum_sql_command save_sql_command= lex->sql_command;
2494
2506
Open_tables_state open_tables_state_backup;
2495
2507
Query_tables_list query_tables_list_backup;
2496
2508
uint32_t table_open_method;
2497
bool old_value= thd->no_warnings_for_error;
2509
bool old_value= session->no_warnings_for_error;
2499
2511
lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
2503
2515
tables open and locked, since we won't lock tables which we will
2504
2516
open and will ignore possible name-locks for these tables.
2506
thd->reset_n_backup_open_tables_state(&open_tables_state_backup);
2518
session->reset_n_backup_open_tables_state(&open_tables_state_backup);
2508
2520
schema_table_idx= get_schema_table_idx(schema_table);
2509
2521
tables->table_open_method= table_open_method=
2516
2528
if (lsel && lsel->table_list.first)
2518
error= fill_schema_show_cols_or_idxs(thd, tables, schema_table,
2530
error= fill_schema_show_cols_or_idxs(session, tables, schema_table,
2519
2531
&open_tables_state_backup);
2523
if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2535
if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
2562
if (make_db_list(thd, &db_names, &lookup_field_vals, &with_i_schema))
2574
if (make_db_list(session, &db_names, &lookup_field_vals, &with_i_schema))
2564
2576
it.rewind(); /* To get access to new elements in basis list */
2565
2577
while ((db_name= it++))
2568
thd->no_warnings_for_error= 1;
2580
session->no_warnings_for_error= 1;
2569
2581
List<LEX_STRING> table_names;
2570
int res= make_table_name_list(thd, &table_names, lex,
2582
int res= make_table_name_list(session, &table_names, lex,
2571
2583
&lookup_field_vals,
2572
2584
with_i_schema, db_name);
2573
2585
if (res == 2) /* Not fatal error, continue */
2604
2616
/* SHOW Table NAMES command */
2605
2617
if (schema_table_idx == SCH_TABLE_NAMES)
2607
if (fill_schema_table_names(thd, tables->table, db_name,
2619
if (fill_schema_table_names(session, tables->table, db_name,
2608
2620
table_name, with_i_schema))
2613
2625
if (!(table_open_method & ~OPEN_FRM_ONLY) &&
2614
2626
!with_i_schema)
2616
if (!fill_schema_table_from_frm(thd, tables, schema_table, db_name,
2628
if (!fill_schema_table_from_frm(session, tables, schema_table, db_name,
2617
2629
table_name, schema_table_idx))
2624
2636
Set the parent lex of 'sel' because it is needed by
2625
2637
sel.init_query() which is called inside make_table_list.
2627
thd->no_warnings_for_error= 1;
2639
session->no_warnings_for_error= 1;
2628
2640
sel.parent_lex= lex;
2629
2641
/* db_name can be changed in make_table_list() func */
2630
if (!thd->make_lex_string(&orig_db_name, db_name->str,
2642
if (!session->make_lex_string(&orig_db_name, db_name->str,
2631
2643
db_name->length, false))
2633
if (make_table_list(thd, &sel, db_name, table_name))
2645
if (make_table_list(session, &sel, db_name, table_name))
2635
2647
TableList *show_table_list= (TableList*) sel.table_list.first;
2636
2648
lex->all_selects_list= &sel;
2638
2650
lex->sql_command= SQLCOM_SHOW_FIELDS;
2639
2651
show_table_list->i_s_requested_object=
2640
2652
schema_table->i_s_requested_object;
2641
res= open_normal_and_derived_tables(thd, show_table_list,
2653
res= open_normal_and_derived_tables(session, show_table_list,
2642
2654
DRIZZLE_LOCK_IGNORE_FLUSH);
2643
2655
lex->sql_command= save_sql_command;
2645
2657
XXX: show_table_list has a flag i_is_requested,
2646
2658
and when it's set, open_normal_and_derived_tables()
2647
2659
can return an error without setting an error message
2648
in THD, which is a hack. This is why we have to
2649
check for res, then for thd->is_error() only then
2650
for thd->main_da.sql_errno().
2660
in Session, which is a hack. This is why we have to
2661
check for res, then for session->is_error() only then
2662
for session->main_da.sql_errno().
2652
if (res && thd->is_error() &&
2653
thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2664
if (res && session->is_error() &&
2665
session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2656
2668
Hide error for not existing table.
2670
2682
to use alias because alias contains original table name
2673
thd->make_lex_string(&tmp_lex_string, show_table_list->alias,
2685
session->make_lex_string(&tmp_lex_string, show_table_list->alias,
2674
2686
strlen(show_table_list->alias), false);
2675
res= schema_table->process_table(thd, show_table_list, table,
2687
res= schema_table->process_table(session, show_table_list, table,
2676
2688
res, &orig_db_name,
2677
2689
&tmp_lex_string);
2678
close_tables_for_reopen(thd, &show_table_list);
2690
close_tables_for_reopen(session, &show_table_list);
2680
2692
assert(!lex->query_tables_own_last);
2696
thd->restore_backup_open_tables_state(&open_tables_state_backup);
2708
session->restore_backup_open_tables_state(&open_tables_state_backup);
2697
2709
lex->restore_backup_query_tables_list(&query_tables_list_backup);
2698
2710
lex->derived_tables= derived_tables;
2699
2711
lex->all_selects_list= old_all_select_lex;
2700
2712
lex->sql_command= save_sql_command;
2701
thd->no_warnings_for_error= old_value;
2713
session->no_warnings_for_error= old_value;
2706
bool store_schema_shemata(THD* thd, Table *table, LEX_STRING *db_name,
2718
bool store_schema_shemata(Session* session, Table *table, LEX_STRING *db_name,
2707
2719
const CHARSET_INFO * const cs)
2709
2721
restore_record(table, s->default_values);
2710
2722
table->field[1]->store(db_name->str, db_name->length, system_charset_info);
2711
2723
table->field[2]->store(cs->csname, strlen(cs->csname), system_charset_info);
2712
2724
table->field[3]->store(cs->name, strlen(cs->name), system_charset_info);
2713
return schema_table_store_record(thd, table);
2725
return schema_table_store_record(session, table);
2717
int fill_schema_schemata(THD *thd, TableList *tables, COND *cond)
2729
int fill_schema_schemata(Session *session, TableList *tables, COND *cond)
2720
2732
TODO: fill_schema_shemata() is called when new client is connected.
2728
2740
HA_CREATE_INFO create;
2729
2741
Table *table= tables->table;
2731
if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2743
if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
2733
if (make_db_list(thd, &db_names, &lookup_field_vals,
2745
if (make_db_list(session, &db_names, &lookup_field_vals,
2734
2746
&with_i_schema))
2758
2770
if (with_i_schema) // information schema name is always first in list
2760
if (store_schema_shemata(thd, table, db_name,
2772
if (store_schema_shemata(session, table, db_name,
2761
2773
system_charset_info))
2763
2775
with_i_schema= 0;
2767
load_db_opt_by_name(thd, db_name->str, &create);
2768
if (store_schema_shemata(thd, table, db_name,
2779
load_db_opt_by_name(session, db_name->str, &create);
2780
if (store_schema_shemata(session, table, db_name,
2769
2781
create.default_table_charset))
2792
2804
there was errors during opening tables
2794
const char *error= thd->is_error() ? thd->main_da.message() : "";
2806
const char *error= session->is_error() ? session->main_da.message() : "";
2795
2807
if (tables->schema_table)
2796
2808
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2798
2810
table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2799
2811
table->field[20]->store(error, strlen(error), cs);
2812
session->clear_error();
2937
2949
if (file->stats.create_time)
2939
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2951
session->variables.time_zone->gmt_sec_to_TIME(&time,
2940
2952
(my_time_t) file->stats.create_time);
2941
2953
table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2942
2954
table->field[14]->set_notnull();
2944
2956
if (file->stats.update_time)
2946
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2958
session->variables.time_zone->gmt_sec_to_TIME(&time,
2947
2959
(my_time_t) file->stats.update_time);
2948
2960
table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2949
2961
table->field[15]->set_notnull();
2951
2963
if (file->stats.check_time)
2953
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2965
session->variables.time_zone->gmt_sec_to_TIME(&time,
2954
2966
(my_time_t) file->stats.check_time);
2955
2967
table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2956
2968
table->field[16]->set_notnull();
3068
static int get_schema_column_record(THD *thd, TableList *tables,
3079
static int get_schema_column_record(Session *session, TableList *tables,
3069
3080
Table *table, bool res,
3070
3081
LEX_STRING *db_name,
3071
3082
LEX_STRING *table_name)
3084
LEX *lex= session->lex;
3074
3085
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3075
3086
const CHARSET_INFO * const cs= system_charset_info;
3076
3087
Table *show_table;
3086
3097
I.e. we are in SELECT FROM INFORMATION_SCHEMA.COLUMS
3087
3098
rather than in SHOW COLUMNS
3089
if (thd->is_error())
3090
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3091
thd->main_da.sql_errno(), thd->main_da.message());
3100
if (session->is_error())
3101
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3102
session->main_da.sql_errno(), session->main_da.message());
3103
session->clear_error();
3118
3129
/* to satisfy 'field->val_str' ASSERTs */
3119
3130
unsigned char *bitmaps;
3120
3131
uint32_t bitmap_size= show_table_share->column_bitmap_size;
3121
if (!(bitmaps= (unsigned char*) alloc_root(thd->mem_root, bitmap_size)))
3132
if (!(bitmaps= (unsigned char*) alloc_root(session->mem_root, bitmap_size)))
3123
3134
bitmap_init(&show_table->def_read_set,
3124
3135
(my_bitmap_map*) bitmaps, show_table_share->fields, false);
3154
3165
table->field[4]->store((int64_t) count, true);
3156
if (get_field_default_value(thd, timestamp_field, field, &type, 0))
3167
if (get_field_default_value(session, timestamp_field, field, &type, 0))
3158
3169
table->field[5]->store(type.ptr(), type.length(), cs);
3159
3170
table->field[5]->set_notnull();
3176
3187
field->unireg_check != Field::TIMESTAMP_DN_FIELD)
3177
3188
table->field[16]->store(STRING_WITH_LEN("on update CURRENT_TIMESTAMP"),
3190
if (field->vcol_info)
3191
table->field[16]->store(STRING_WITH_LEN("VIRTUAL"), cs);
3180
3192
table->field[18]->store(field->comment.str, field->comment.length, cs);
3182
3194
enum column_format_type column_format= (enum column_format_type)
3201
int fill_schema_charsets(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3213
int fill_schema_charsets(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3203
3215
CHARSET_INFO **cs;
3204
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3216
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3205
3217
Table *table= tables->table;
3206
3218
const CHARSET_INFO * const scs= system_charset_info;
3221
3233
comment= tmp_cs->comment ? tmp_cs->comment : "";
3222
3234
table->field[2]->store(comment, strlen(comment), scs);
3223
3235
table->field[3]->store((int64_t) tmp_cs->mbmaxlen, true);
3224
if (schema_table_store_record(thd, table))
3236
if (schema_table_store_record(session, table))
3232
int fill_schema_collation(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3244
int fill_schema_collation(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3234
3246
CHARSET_INFO **cs;
3235
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3247
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3236
3248
Table *table= tables->table;
3237
3249
const CHARSET_INFO * const scs= system_charset_info;
3238
3250
for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3262
3274
tmp_buff= (tmp_cl->state & MY_CS_COMPILED)? "Yes" : "";
3263
3275
table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
3264
3276
table->field[5]->store((int64_t) tmp_cl->strxfrm_multiply, true);
3265
if (schema_table_store_record(thd, table))
3277
if (schema_table_store_record(session, table))
3292
3304
restore_record(table, s->default_values);
3293
3305
table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3294
3306
table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3295
if (schema_table_store_record(thd, table))
3307
if (schema_table_store_record(session, table))
3308
3320
const CHARSET_INFO * const cs= system_charset_info;
3311
if (thd->lex->sql_command != SQLCOM_SHOW_KEYS)
3323
if (session->lex->sql_command != SQLCOM_SHOW_KEYS)
3314
3326
I.e. we are in SELECT FROM INFORMATION_SCHEMA.STATISTICS
3315
3327
rather than in SHOW KEYS
3317
if (thd->is_error())
3318
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3319
thd->main_da.sql_errno(), thd->main_da.message());
3329
if (session->is_error())
3330
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3331
session->main_da.sql_errno(), session->main_da.message());
3332
session->clear_error();
3388
3400
if (key_info->flags & HA_USES_COMMENT)
3389
3401
table->field[15]->store(key_info->comment.str,
3390
3402
key_info->comment.length, cs);
3391
if (schema_table_store_record(thd, table))
3403
if (schema_table_store_record(session, table))
3400
bool store_constraints(THD *thd, Table *table, LEX_STRING *db_name,
3412
bool store_constraints(Session *session, Table *table, LEX_STRING *db_name,
3401
3413
LEX_STRING *table_name, const char *key_name,
3402
3414
uint32_t key_len, const char *con_type, uint32_t con_len)
3408
3420
table->field[3]->store(db_name->str, db_name->length, cs);
3409
3421
table->field[4]->store(table_name->str, table_name->length, cs);
3410
3422
table->field[5]->store(con_type, con_len, cs);
3411
return schema_table_store_record(thd, table);
3423
return schema_table_store_record(session, table);
3415
static int get_schema_constraints_record(THD *thd, TableList *tables,
3427
static int get_schema_constraints_record(Session *session, TableList *tables,
3416
3428
Table *table, bool res,
3417
3429
LEX_STRING *db_name,
3418
3430
LEX_STRING *table_name)
3422
if (thd->is_error())
3423
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3424
thd->main_da.sql_errno(), thd->main_da.message());
3434
if (session->is_error())
3435
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3436
session->main_da.sql_errno(), session->main_da.message());
3437
session->clear_error();
3442
3454
if (i == primary_key && !strcmp(key_info->name, primary_key_name))
3444
if (store_constraints(thd, table, db_name, table_name, key_info->name,
3456
if (store_constraints(session, table, db_name, table_name, key_info->name,
3445
3457
strlen(key_info->name),
3446
3458
STRING_WITH_LEN("PRIMARY KEY")))
3449
3461
else if (key_info->flags & HA_NOSAME)
3451
if (store_constraints(thd, table, db_name, table_name, key_info->name,
3463
if (store_constraints(session, table, db_name, table_name, key_info->name,
3452
3464
strlen(key_info->name),
3453
3465
STRING_WITH_LEN("UNIQUE")))
3458
show_table->file->get_foreign_key_list(thd, &f_key_list);
3470
show_table->file->get_foreign_key_list(session, &f_key_list);
3459
3471
FOREIGN_KEY_INFO *f_key_info;
3460
3472
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3461
3473
while ((f_key_info=it++))
3463
if (store_constraints(thd, table, db_name, table_name,
3475
if (store_constraints(session, table, db_name, table_name,
3464
3476
f_key_info->forein_id->str,
3465
3477
strlen(f_key_info->forein_id->str),
3466
3478
"FOREIGN KEY", 11))
3497
if (thd->is_error())
3498
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3499
thd->main_da.sql_errno(), thd->main_da.message());
3509
if (session->is_error())
3510
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3511
session->main_da.sql_errno(), session->main_da.message());
3512
session->clear_error();
3527
3539
key_part->field->field_name,
3528
3540
strlen(key_part->field->field_name),
3529
3541
(int64_t) f_idx);
3530
if (schema_table_store_record(thd, table))
3542
if (schema_table_store_record(session, table))
3536
show_table->file->get_foreign_key_list(thd, &f_key_list);
3548
show_table->file->get_foreign_key_list(session, &f_key_list);
3537
3549
FOREIGN_KEY_INFO *f_key_info;
3538
3550
List_iterator_fast<FOREIGN_KEY_INFO> fkey_it(f_key_list);
3539
3551
while ((f_key_info= fkey_it++))
3578
int fill_open_tables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3590
int fill_open_tables(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3580
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3592
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3581
3593
Table *table= tables->table;
3582
3594
const CHARSET_INFO * const cs= system_charset_info;
3583
3595
OPEN_TableList *open_list;
3584
if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3585
&& thd->is_fatal_error)
3596
if (!(open_list=list_open_tables(session,session->lex->select_lex.db, wild))
3597
&& session->is_fatal_error)
3588
3600
for (; open_list ; open_list=open_list->next)
3592
3604
table->field[1]->store(open_list->table, strlen(open_list->table), cs);
3593
3605
table->field[2]->store((int64_t) open_list->in_use, true);
3594
3606
table->field[3]->store((int64_t) open_list->locked, true);
3595
if (schema_table_store_record(thd, table))
3607
if (schema_table_store_record(session, table))
3602
int fill_variables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3614
int fill_variables(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3617
LEX *lex= session->lex;
3606
3618
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3607
3619
enum enum_schema_tables schema_table_idx=
3608
3620
get_schema_table_idx(tables->schema_table);
3615
3627
option_type= OPT_GLOBAL;
3617
3629
rw_rdlock(&LOCK_system_variables_hash);
3618
res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars),
3630
res= show_status_array(session, wild, enumerate_sys_vars(session, sorted_vars),
3619
3631
option_type, NULL, "", tables->table, upper_case_names);
3620
3632
rw_unlock(&LOCK_system_variables_hash);
3625
int fill_status(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3637
int fill_status(Session *session, TableList *tables, COND *cond __attribute__((unused)))
3639
LEX *lex= session->lex;
3628
3640
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3630
3642
STATUS_VAR *tmp1, tmp;
3651
3663
option_type= OPT_SESSION;
3652
tmp1= &thd->status_var;
3664
tmp1= &session->status_var;
3655
3667
pthread_mutex_lock(&LOCK_status);
3656
3668
if (option_type == OPT_GLOBAL)
3657
3669
calc_sum_of_all_status(&tmp);
3658
res= show_status_array(thd, wild,
3670
res= show_status_array(session, wild,
3659
3671
(SHOW_VAR *)all_status_vars.buffer,
3660
3672
option_type, tmp1, "", tables->table,
3661
3673
upper_case_names);
3694
if (thd->is_error())
3695
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3696
thd->main_da.sql_errno(), thd->main_da.message());
3706
if (session->is_error())
3707
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3708
session->main_da.sql_errno(), session->main_da.message());
3709
session->clear_error();
3705
3717
HA_STATUS_NO_LOCK |
3706
3718
HA_STATUS_TIME);
3708
show_table->file->get_foreign_key_list(thd, &f_key_list);
3720
show_table->file->get_foreign_key_list(session, &f_key_list);
3709
3721
FOREIGN_KEY_INFO *f_key_info;
3710
3722
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3711
3723
while ((f_key_info= it++))
3732
3744
f_key_info->update_method->length, cs);
3733
3745
table->field[8]->store(f_key_info->delete_method->str,
3734
3746
f_key_info->delete_method->length, cs);
3735
if (schema_table_store_record(thd, table))
3747
if (schema_table_store_record(session, table))
3792
3804
# pointer to 'schema_tables' element
3795
ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name)
3807
ST_SCHEMA_TABLE *find_schema_table(Session *session, const char* table_name)
3797
3809
schema_table_ref schema_table_a;
3798
3810
ST_SCHEMA_TABLE *schema_table= schema_tables;
3808
3820
schema_table_a.table_name= table_name;
3809
if (plugin_foreach(thd, find_schema_table_in_plugin,
3821
if (plugin_foreach(session, find_schema_table_in_plugin,
3810
3822
DRIZZLE_INFORMATION_SCHEMA_PLUGIN, &schema_table_a))
3811
3823
return(schema_table_a.schema_table);
3913
3924
TMP_TABLE_PARAM *tmp_table_param =
3914
(TMP_TABLE_PARAM*) (thd->alloc(sizeof(TMP_TABLE_PARAM)));
3925
(TMP_TABLE_PARAM*) (session->alloc(sizeof(TMP_TABLE_PARAM)));
3915
3926
tmp_table_param->init();
3916
3927
tmp_table_param->table_charset= cs;
3917
3928
tmp_table_param->field_count= field_count;
3918
3929
tmp_table_param->schema_table= 1;
3919
SELECT_LEX *select_lex= thd->lex->current_select;
3920
if (!(table= create_tmp_table(thd, tmp_table_param,
3930
SELECT_LEX *select_lex= session->lex->current_select;
3931
if (!(table= create_tmp_table(session, tmp_table_param,
3921
3932
field_list, (order_st*) 0, 0, 0,
3922
(select_lex->options | thd->options |
3933
(select_lex->options | session->options |
3923
3934
TMP_TABLE_ALL_COLUMNS),
3924
3935
HA_POS_ERROR, table_list->alias)))
3926
3937
my_bitmap_map* bitmaps=
3927
(my_bitmap_map*) thd->alloc(bitmap_buffer_size(field_count));
3938
(my_bitmap_map*) session->alloc(bitmap_buffer_size(field_count));
3928
3939
bitmap_init(&table->def_read_set, (my_bitmap_map*) bitmaps, field_count,
3930
3941
table->read_set= &table->def_read_set;
3952
int make_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
3963
int make_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
3954
3965
ST_FIELD_INFO *field_info= schema_table->fields_info;
3955
Name_resolution_context *context= &thd->lex->select_lex.context;
3966
Name_resolution_context *context= &session->lex->select_lex.context;
3956
3967
for (; field_info->field_name; field_info++)
3958
3969
if (field_info->old_name)
3986
3997
String buffer(tmp,sizeof(tmp), system_charset_info);
3987
3998
Item_field *field= new Item_field(context,
3988
3999
NULL, NULL, field_info->field_name);
3989
if (!field || add_item_to_list(thd, field))
4000
if (!field || add_item_to_list(session, field))
3991
4002
buffer.length(0);
3992
4003
buffer.append(field_info->old_name);
4005
int make_table_names_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
4016
int make_table_names_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4008
String buffer(tmp,sizeof(tmp), thd->charset());
4019
String buffer(tmp,sizeof(tmp), session->charset());
4020
LEX *lex= session->lex;
4010
4021
Name_resolution_context *context= &lex->select_lex.context;
4012
4023
ST_FIELD_INFO *field_info= &schema_table->fields_info[2];
4022
4033
Item_field *field= new Item_field(context,
4023
4034
NULL, NULL, field_info->field_name);
4024
if (add_item_to_list(thd, field))
4035
if (add_item_to_list(session, field))
4026
4037
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4027
if (thd->lex->verbose)
4038
if (session->lex->verbose)
4029
4040
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4030
4041
field_info= &schema_table->fields_info[3];
4031
4042
field= new Item_field(context, NULL, NULL, field_info->field_name);
4032
if (add_item_to_list(thd, field))
4043
if (add_item_to_list(session, field))
4034
4045
field->set_name(field_info->old_name, strlen(field_info->old_name),
4035
4046
system_charset_info);
4041
int make_columns_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
4052
int make_columns_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4043
4054
int fields_arr[]= {3, 14, 13, 6, 15, 5, 16, 17, 18, -1};
4044
4055
int *field_num= fields_arr;
4045
4056
ST_FIELD_INFO *field_info;
4046
Name_resolution_context *context= &thd->lex->select_lex.context;
4057
Name_resolution_context *context= &session->lex->select_lex.context;
4048
4059
for (; *field_num >= 0; field_num++)
4050
4061
field_info= &schema_table->fields_info[*field_num];
4051
if (!thd->lex->verbose && (*field_num == 13 ||
4062
if (!session->lex->verbose && (*field_num == 13 ||
4052
4063
*field_num == 17 ||
4053
4064
*field_num == 18))
4070
int make_character_sets_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
4081
int make_character_sets_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4072
4083
int fields_arr[]= {0, 2, 1, 3, -1};
4073
4084
int *field_num= fields_arr;
4074
4085
ST_FIELD_INFO *field_info;
4075
Name_resolution_context *context= &thd->lex->select_lex.context;
4086
Name_resolution_context *context= &session->lex->select_lex.context;
4077
4088
for (; *field_num >= 0; field_num++)
4109
int mysql_schema_table(THD *thd, LEX *lex, TableList *table_list)
4120
int mysql_schema_table(Session *session, LEX *lex, TableList *table_list)
4112
if (!(table= table_list->schema_table->create_table(thd, table_list)))
4123
if (!(table= table_list->schema_table->create_table(session, table_list)))
4114
4125
table->s->tmp_table= SYSTEM_TMP_TABLE;
4126
4137
table_list->table_name= table->s->table_name.str;
4127
4138
table_list->table_name_length= table->s->table_name.length;
4128
4139
table_list->table= table;
4129
table->next= thd->derived_tables;
4130
thd->derived_tables= table;
4140
table->next= session->derived_tables;
4141
session->derived_tables= table;
4131
4142
table_list->select_lex->options |= OPTION_SCHEMA_TABLE;
4133
4144
if (table_list->schema_table_reformed) // show command
4142
4153
for (transl= table_list->field_translation; transl < end; transl++)
4144
4155
if (!transl->item->fixed &&
4145
transl->item->fix_fields(thd, &transl->item))
4156
transl->item->fix_fields(session, &transl->item))
4150
4161
List_iterator_fast<Item> it(sel->item_list);
4152
(Field_translator*)(thd->alloc(sel->item_list.elements *
4163
(Field_translator*)(session->alloc(sel->item_list.elements *
4153
4164
sizeof(Field_translator)))))
4194
4205
We have to make non const db_name & table_name
4195
4206
because of lower_case_table_names
4197
thd->make_lex_string(&db, INFORMATION_SCHEMA_NAME.str,
4208
session->make_lex_string(&db, INFORMATION_SCHEMA_NAME.str,
4198
4209
INFORMATION_SCHEMA_NAME.length, 0);
4199
thd->make_lex_string(&table, schema_table->table_name,
4210
session->make_lex_string(&table, schema_table->table_name,
4200
4211
strlen(schema_table->table_name), 0);
4201
if (schema_table->old_format(thd, schema_table) || /* Handle old syntax */
4202
!sel->add_table_to_list(thd, new Table_ident(thd, db, table, 0),
4212
if (schema_table->old_format(session, schema_table) || /* Handle old syntax */
4213
!sel->add_table_to_list(session, new Table_ident(session, db, table, 0),
4203
4214
0, 0, TL_READ))
4225
4236
enum enum_schema_table_state executed_place)
4227
4238
JOIN_TAB *tmp_join_tab= join->join_tab+join->tables;
4228
THD *thd= join->thd;
4239
Session *session= join->session;
4240
LEX *lex= session->lex;
4230
4241
bool result= 0;
4232
thd->no_warnings_for_error= 1;
4243
session->no_warnings_for_error= 1;
4233
4244
for (JOIN_TAB *tab= join->join_tab; tab < tmp_join_tab; tab++)
4235
4246
if (!tab->table || !tab->table->pos_in_table_list)