1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1
/* Copyright (C) 2000-2004 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
21
17
/* Function with list databases, tables or fields */
22
18
#include <drizzled/server_includes.h>
23
19
#include <drizzled/sql_select.h>
24
20
#include <drizzled/sql_show.h>
21
#include "repl_failsafe.h"
25
22
#include <mysys/my_dir.h>
26
#include <drizzled/gettext.h>
27
#include <drizzled/util/convert.h>
28
#include <drizzled/error.h>
30
#include <drizzled/tztime.h>
31
#include <drizzled/data_home.h>
23
#include <libdrizzle/gettext.h>
33
25
inline const char *
34
26
str_or_nil(const char *str)
39
31
/* Match the values of enum ha_choice */
40
32
static const char *ha_choice_values[] = {"", "0", "1"};
42
static void store_key_options(Session *session, String *packet, Table *table,
34
static void store_key_options(THD *thd, String *packet, Table *table,
177
169
table->field[7]->set_notnull();
179
return schema_table_store_record(session, table);
171
return schema_table_store_record(thd, table);
183
int fill_plugins(Session *session, TableList *tables, COND *)
175
int fill_plugins(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
185
177
Table *table= tables->table;
187
if (plugin_foreach_with_mask(session, show_plugins, DRIZZLE_ANY_PLUGIN,
179
if (plugin_foreach_with_mask(thd, show_plugins, DRIZZLE_ANY_PLUGIN,
188
180
~PLUGIN_IS_FREED, table))
314
mysqld_show_create(Session *session, TableList *table_list)
306
mysqld_show_create(THD *thd, TableList *table_list)
316
Protocol *protocol= session->protocol;
308
Protocol *protocol= thd->protocol;
318
310
String buffer(buff, sizeof(buff), system_charset_info);
320
312
/* Only one table for now, but VIEW can involve several tables */
321
if (open_normal_and_derived_tables(session, table_list, 0))
313
if (open_normal_and_derived_tables(thd, table_list, 0))
323
if (session->is_error() && session->main_da.sql_errno() != ER_VIEW_INVALID)
315
if (thd->is_error() && thd->main_da.sql_errno() != ER_VIEW_INVALID)
328
320
issue a warning with 'warning' level status in
329
321
case of invalid view and last error is ER_VIEW_INVALID
331
drizzle_reset_errors(session, true);
332
session->clear_error();
323
drizzle_reset_errors(thd, true);
335
327
buffer.length(0);
337
if (store_create_info(session, table_list, &buffer, NULL))
329
if (store_create_info(thd, table_list, &buffer, NULL))
340
332
List<Item> field_list;
342
334
field_list.push_back(new Item_empty_string("Table",NAME_CHAR_LEN));
343
335
// 1024 is for not to confuse old clients
344
336
field_list.push_back(new Item_empty_string("Create Table",
345
cmax(buffer.length(),(uint32_t)1024)));
337
max(buffer.length(),(uint32_t)1024)));
348
340
if (protocol->send_fields(&field_list,
362
354
if (protocol->write())
369
bool mysqld_show_create_db(Session *session, char *dbname,
361
bool mysqld_show_create_db(THD *thd, char *dbname,
370
362
HA_CREATE_INFO *create_info)
373
365
String buffer(buff, sizeof(buff), system_charset_info);
374
Protocol *protocol=session->protocol;
366
Protocol *protocol=thd->protocol;
376
if (store_db_create_info(session, dbname, &buffer, create_info))
368
if (store_db_create_info(thd, dbname, &buffer, create_info))
379
371
This assumes that the only reason for which store_db_create_info()
409
401
****************************************************************************/
412
mysqld_list_fields(Session *session, TableList *table_list, const char *wild)
404
mysqld_list_fields(THD *thd, TableList *table_list, const char *wild)
416
if (open_normal_and_derived_tables(session, table_list, 0))
408
if (open_normal_and_derived_tables(thd, table_list, 0))
418
410
table= table_list->table;
451
443
0 No conflicting character
454
static const char *require_quotes(const char *name, uint32_t name_length)
446
static const char *require_quotes(const char *name, uint name_length)
457
449
bool pure_digit= true;
458
450
const char *end= name + name_length;
460
452
for (; name < end ; name++)
462
unsigned char chr= (unsigned char) *name;
454
uchar chr= (uchar) *name;
463
455
length= my_mbcharlen(system_charset_info, chr);
464
456
if (length == 1 && !system_charset_info->ident_map[chr])
480
472
append_identifier()
481
session thread handler
482
474
packet target string
483
475
name the identifier to be appended
484
476
name_length length of the appending identifier
488
append_identifier(Session *session, String *packet, const char *name, uint32_t length)
480
append_identifier(THD *thd, String *packet, const char *name, uint length)
490
482
const char *name_end;
492
int q= get_quote_char_for_identifier(session, name, length);
484
int q= get_quote_char_for_identifier(thd, name, length);
505
packet->reserve(length*2 + 2);
497
VOID(packet->reserve(length*2 + 2));
506
498
quote_char= (char) q;
507
499
packet->append("e_char, 1, system_charset_info);
509
501
for (name_end= name+length ; name < name_end ; name+= length)
511
unsigned char chr= (unsigned char) *name;
503
uchar chr= (uchar) *name;
512
504
length= my_mbcharlen(system_charset_info, chr);
514
506
my_mbcharlen can return 0 on a wrong multibyte
550
542
# Quote character
553
int get_quote_char_for_identifier(Session *session, const char *name, uint32_t length)
545
int get_quote_char_for_identifier(THD *thd, const char *name, uint length)
556
548
!is_keyword(name,length) &&
557
549
!require_quotes(name, length) &&
558
!(session->options & OPTION_QUOTE_SHOW_CREATE))
550
!(thd->options & OPTION_QUOTE_SHOW_CREATE))
564
556
/* Append directory name (if exists) to CREATE INFO */
566
static void append_directory(Session *,
558
static void append_directory(THD *thd __attribute__((unused)),
567
559
String *packet, const char *dir_type,
568
const char *filename)
560
const char *filename)
572
uint32_t length= dirname_length(filename);
564
uint length= dirname_length(filename);
573
565
packet->append(' ');
574
566
packet->append(dir_type);
575
567
packet->append(STRING_WITH_LEN(" DIRECTORY='"));
661
int store_create_info(Session *session, TableList *table_list, String *packet,
653
int store_create_info(THD *thd, TableList *table_list, String *packet,
662
654
HA_CREATE_INFO *create_info_arg)
664
656
List<Item> field_list;
665
char tmp[MAX_FIELD_WIDTH], *for_str, def_value_buf[MAX_FIELD_WIDTH];
657
char tmp[MAX_FIELD_WIDTH], *for_str, buff[128], def_value_buf[MAX_FIELD_WIDTH];
666
658
const char *alias;
668
659
String type(tmp, sizeof(tmp), system_charset_info);
669
660
String def_value(def_value_buf, sizeof(def_value_buf), system_charset_info);
670
661
Field **ptr,*field;
671
uint32_t primary_key;
673
664
Table *table= table_list->table;
674
665
handler *file= table->file;
709
700
for (ptr=table->field ; (field= *ptr); ptr++)
711
uint32_t flags = field->flags;
702
uint flags = field->flags;
713
704
if (ptr != table->field)
714
705
packet->append(STRING_WITH_LEN(",\n"));
716
707
packet->append(STRING_WITH_LEN(" "));
717
append_identifier(session,packet,field->field_name, strlen(field->field_name));
708
append_identifier(thd,packet,field->field_name, strlen(field->field_name));
718
709
packet->append(' ');
719
710
// check for surprises from the previous call to Field::sql_type()
720
711
if (type.ptr() != tmp)
723
714
type.set_charset(system_charset_info);
725
if (field->vcol_info)
727
packet->append(STRING_WITH_LEN("VIRTUAL "));
730
716
field->sql_type(type);
731
717
packet->append(type.ptr(), type.length(), system_charset_info);
733
if (field->vcol_info)
735
packet->append(STRING_WITH_LEN(" AS ("));
736
packet->append(field->vcol_info->expr_str.str,
737
field->vcol_info->expr_str.length,
738
system_charset_info);
739
packet->append(STRING_WITH_LEN(")"));
740
if (field->is_stored)
741
packet->append(STRING_WITH_LEN(" STORED"));
744
719
if (field->has_charset())
746
721
if (field->charset() != share->table_charset)
836
810
packet->append(STRING_WITH_LEN("KEY "));
838
812
if (!found_primary)
839
append_identifier(session, packet, key_info->name, strlen(key_info->name));
813
append_identifier(thd, packet, key_info->name, strlen(key_info->name));
841
815
packet->append(STRING_WITH_LEN(" ("));
843
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
817
for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
846
820
packet->append(',');
848
822
if (key_part->field)
849
append_identifier(session,packet,key_part->field->field_name,
823
append_identifier(thd,packet,key_part->field->field_name,
850
824
strlen(key_part->field->field_name));
851
825
if (key_part->field &&
852
826
(key_part->length !=
853
827
table->field[key_part->fieldnr-1]->key_length()))
856
buff= to_string(buff, (int32_t) key_part->length /
857
key_part->field->charset()->mbmaxlen);
859
packet->append(buff.c_str(), buff.length());
831
end= int10_to_str((long) key_part->length /
832
key_part->field->charset()->mbmaxlen,
835
packet->append(buff,(uint) (end-buff));
862
838
packet->append(')');
863
store_key_options(session, packet, table, key_info);
839
store_key_options(thd, packet, table, key_info);
907
883
if (create_info.auto_increment_value > 1)
909
886
packet->append(STRING_WITH_LEN(" AUTO_INCREMENT="));
910
buff= to_string(create_info.auto_increment_value);
911
packet->append(buff.c_str(), buff.length());
887
end= int64_t10_to_str(create_info.auto_increment_value, buff,10);
888
packet->append(buff, (uint) (end - buff));
914
891
if (share->min_rows)
916
894
packet->append(STRING_WITH_LEN(" MIN_ROWS="));
917
buff= to_string(share->min_rows);
918
packet->append(buff.c_str(), buff.length());
895
end= int64_t10_to_str(share->min_rows, buff, 10);
896
packet->append(buff, (uint) (end- buff));
921
899
if (share->max_rows && !table_list->schema_table)
923
902
packet->append(STRING_WITH_LEN(" MAX_ROWS="));
924
buff= to_string(share->max_rows);
925
packet->append(buff.c_str(), buff.length());
903
end= int64_t10_to_str(share->max_rows, buff, 10);
904
packet->append(buff, (uint) (end - buff));
928
907
if (share->avg_row_length)
930
910
packet->append(STRING_WITH_LEN(" AVG_ROW_LENGTH="));
931
buff= to_string(share->avg_row_length);
932
packet->append(buff.c_str(), buff.length());
911
end= int64_t10_to_str(share->avg_row_length, buff,10);
912
packet->append(buff, (uint) (end - buff));
935
915
if (share->db_create_options & HA_OPTION_PACK_KEYS)
959
939
if (table->s->key_block_size)
961
942
packet->append(STRING_WITH_LEN(" KEY_BLOCK_SIZE="));
962
buff= to_string(table->s->key_block_size);
963
packet->append(buff.c_str(), buff.length());
943
end= int64_t10_to_str(table->s->key_block_size, buff, 10);
944
packet->append(buff, (uint) (end - buff));
965
946
if (share->block_size)
967
949
packet->append(STRING_WITH_LEN(" BLOCK_SIZE="));
968
buff= to_string(share->block_size);
969
packet->append(buff.c_str(), buff.length());
950
end= int64_t10_to_str(share->block_size, buff,10);
951
packet->append(buff, (uint) (end - buff));
971
953
table->file->append_create_info(packet);
972
954
if (share->comment.length)
979
961
packet->append(STRING_WITH_LEN(" CONNECTION="));
980
962
append_unescaped(packet, share->connect_string.str, share->connect_string.length);
982
append_directory(session, packet, "DATA", create_info.data_file_name);
983
append_directory(session, packet, "INDEX", create_info.index_file_name);
964
append_directory(thd, packet, "DATA", create_info.data_file_name);
965
append_directory(thd, packet, "INDEX", create_info.index_file_name);
985
967
table->restore_column_map(old_map);
999
981
the resulting CREATE statement contains "IF NOT EXISTS" clause. Other flags
1000
982
in @c create_options are ignored.
1002
@param session The current thread instance.
984
@param thd The current thread instance.
1003
985
@param dbname The name of the database.
1004
986
@param buffer A String instance where the statement is stored.
1005
987
@param create_info If not NULL, the options member influences the resulting
1008
990
@returns true if errors are detected, false otherwise.
1011
bool store_db_create_info(Session *session, const char *dbname, String *buffer,
993
bool store_db_create_info(THD *thd, const char *dbname, String *buffer,
1012
994
HA_CREATE_INFO *create_info)
1014
996
HA_CREATE_INFO create;
1015
uint32_t create_options = create_info ? create_info->options : 0;
997
uint create_options = create_info ? create_info->options : 0;
1017
999
if (!my_strcasecmp(system_charset_info, dbname,
1018
1000
INFORMATION_SCHEMA_NAME.str))
1036
1018
if (create_options & HA_LEX_CREATE_IF_NOT_EXISTS)
1037
1019
buffer->append(STRING_WITH_LEN("/*!32312 IF NOT EXISTS*/ "));
1039
append_identifier(session, buffer, dbname, strlen(dbname));
1021
append_identifier(thd, buffer, dbname, strlen(dbname));
1041
1023
if (create.default_table_charset)
1110
1093
template class I_List<thread_info>;
1113
void mysqld_list_processes(Session *session,const char *user, bool verbose)
1096
void mysqld_list_processes(THD *thd,const char *user, bool verbose)
1116
1099
List<Item> field_list;
1117
1100
I_List<thread_info> thread_infos;
1118
ulong max_query_length= (verbose ? session->variables.max_allowed_packet :
1101
ulong max_query_length= (verbose ? thd->variables.max_allowed_packet :
1119
1102
PROCESS_LIST_WIDTH);
1120
Protocol *protocol= session->protocol;
1103
Protocol *protocol= thd->protocol;
1122
1105
field_list.push_back(new Item_int("Id", 0, MY_INT32_NUM_DECIMAL_DIGITS));
1123
1106
field_list.push_back(new Item_empty_string("User",16));
1134
1117
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
1137
pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
1138
if (!session->killed)
1120
VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
1140
I_List_iterator<Session> it(threads);
1123
I_List_iterator<THD> it(threads);
1142
1125
while ((tmp=it++))
1144
1127
Security_context *tmp_sctx= tmp->security_ctx;
1145
1128
struct st_my_thread_var *mysys_var;
1146
1129
if ((tmp->vio_ok() || tmp->system_thread) && (!user || (tmp_sctx->user && !strcmp(tmp_sctx->user, user))))
1148
thread_info *session_info= new thread_info;
1131
thread_info *thd_info= new thread_info;
1150
session_info->thread_id=tmp->thread_id;
1151
session_info->user= session->strdup(tmp_sctx->user ? tmp_sctx->user :
1133
thd_info->thread_id=tmp->thread_id;
1134
thd_info->user= thd->strdup(tmp_sctx->user ? tmp_sctx->user :
1152
1135
(tmp->system_thread ?
1153
1136
"system user" : "unauthenticated user"));
1154
session_info->host= session->strdup(tmp_sctx->ip);
1155
if ((session_info->db=tmp->db)) // Safe test
1156
session_info->db=session->strdup(session_info->db);
1157
session_info->command=(int) tmp->command;
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;
1158
1141
if ((mysys_var= tmp->mysys_var))
1159
1142
pthread_mutex_lock(&mysys_var->mutex);
1160
session_info->proc_info= (char*) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0);
1161
session_info->state_info= (char*) (tmp->net.reading_or_writing ?
1143
thd_info->proc_info= (char*) (tmp->killed == THD::KILL_CONNECTION? "Killed" : 0);
1144
thd_info->state_info= (char*) (tmp->net.reading_or_writing ?
1162
1145
(tmp->net.reading_or_writing == 2 ?
1163
1146
"Writing to net" :
1164
session_info->command == COM_SLEEP ? NULL :
1147
thd_info->command == COM_SLEEP ? NullS :
1165
1148
"Reading from net") :
1166
1149
tmp->get_proc_info() ? tmp->get_proc_info() :
1167
1150
tmp->mysys_var &&
1168
1151
tmp->mysys_var->current_cond ?
1169
"Waiting on cond" : NULL);
1152
"Waiting on cond" : NullS);
1171
1154
pthread_mutex_unlock(&mysys_var->mutex);
1173
session_info->start_time= tmp->start_time;
1174
session_info->query=0;
1156
thd_info->start_time= tmp->start_time;
1175
1158
if (tmp->query)
1179
1162
the comment in sql_class.h why this prevents crashes in possible
1180
1163
races with query_length
1182
uint32_t length= cmin((uint32_t)max_query_length, tmp->query_length);
1183
session_info->query=(char*) session->strmake(tmp->query,length);
1165
uint length= min((uint32_t)max_query_length, tmp->query_length);
1166
thd_info->query=(char*) thd->strmake(tmp->query,length);
1185
thread_infos.append(session_info);
1168
thread_infos.append(thd_info);
1189
pthread_mutex_unlock(&LOCK_thread_count);
1172
VOID(pthread_mutex_unlock(&LOCK_thread_count));
1191
thread_info *session_info;
1174
thread_info *thd_info;
1192
1175
time_t now= my_time(0);
1193
while ((session_info=thread_infos.get()))
1176
while ((thd_info=thread_infos.get()))
1195
1178
protocol->prepare_for_resend();
1196
protocol->store((uint64_t) session_info->thread_id);
1197
protocol->store(session_info->user, system_charset_info);
1198
protocol->store(session_info->host, system_charset_info);
1199
protocol->store(session_info->db, system_charset_info);
1200
if (session_info->proc_info)
1201
protocol->store(session_info->proc_info, system_charset_info);
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);
1203
protocol->store(command_name[session_info->command].str, system_charset_info);
1204
if (session_info->start_time)
1205
protocol->store((uint32_t) (now - session_info->start_time));
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));
1207
1190
protocol->store_null();
1208
protocol->store(session_info->state_info, system_charset_info);
1209
protocol->store(session_info->query, system_charset_info);
1191
protocol->store(thd_info->state_info, system_charset_info);
1192
protocol->store(thd_info->query, system_charset_info);
1210
1193
if (protocol->write())
1211
1194
break; /* purecov: inspected */
1217
int fill_schema_processlist(Session* session, TableList* tables, COND*)
1200
int fill_schema_processlist(THD* thd, TableList* tables,
1201
COND* cond __attribute__((unused)))
1219
1203
Table *table= tables->table;
1220
1204
const CHARSET_INFO * const cs= system_charset_info;
1222
1206
time_t now= my_time(0);
1226
pthread_mutex_lock(&LOCK_thread_count);
1228
if (!session->killed)
1210
VOID(pthread_mutex_lock(&LOCK_thread_count));
1230
I_List_iterator<Session> it(threads);
1214
I_List_iterator<THD> it(threads);
1233
1217
while ((tmp= it++))
1270
1254
val= (char*) (tmp->net.reading_or_writing ?
1271
1255
(tmp->net.reading_or_writing == 2 ?
1272
1256
"Writing to net" :
1273
tmp->command == COM_SLEEP ? NULL :
1257
tmp->command == COM_SLEEP ? NullS :
1274
1258
"Reading from net") :
1275
1259
tmp->get_proc_info() ? tmp->get_proc_info() :
1276
1260
tmp->mysys_var &&
1277
1261
tmp->mysys_var->current_cond ?
1278
"Waiting on cond" : NULL);
1262
"Waiting on cond" : NullS);
1281
1265
table->field[6]->store(val, strlen(val), cs);
1289
1273
if (tmp->query)
1291
1275
table->field[7]->store(tmp->query,
1292
cmin((uint32_t)PROCESS_LIST_INFO_WIDTH,
1276
min((uint32_t)PROCESS_LIST_INFO_WIDTH,
1293
1277
tmp->query_length), cs);
1294
1278
table->field[7]->set_notnull();
1297
if (schema_table_store_record(session, table))
1281
if (schema_table_store_record(thd, table))
1299
pthread_mutex_unlock(&LOCK_thread_count);
1283
VOID(pthread_mutex_unlock(&LOCK_thread_count));
1305
pthread_mutex_unlock(&LOCK_thread_count);
1289
VOID(pthread_mutex_unlock(&LOCK_thread_count));
1371
1355
while (list->name)
1372
res|= insert_dynamic(&all_status_vars, (unsigned char*)list++);
1373
res|= insert_dynamic(&all_status_vars, (unsigned char*)list); // appending NULL-element
1356
res|= insert_dynamic(&all_status_vars, (uchar*)list++);
1357
res|= insert_dynamic(&all_status_vars, (uchar*)list); // appending NULL-element
1374
1358
all_status_vars.elements--; // but next insert_dynamic should overwite it
1375
1359
if (status_vars_inited)
1376
1360
sort_dynamic(&all_status_vars, show_var_cmp);
1485
1469
*buf= my_toupper(system_charset_info, *buf);
1488
static bool show_status_array(Session *session, const char *wild,
1472
static bool show_status_array(THD *thd, const char *wild,
1489
1473
SHOW_VAR *variables,
1490
1474
enum enum_var_type value_type,
1491
1475
struct system_status_var *status_var,
1504
1488
null_lex_str.str= 0; // For sys_var->value_ptr()
1505
1489
null_lex_str.length= 0;
1507
prefix_end=my_stpncpy(name_buffer, prefix, sizeof(name_buffer)-1);
1491
prefix_end=stpncpy(name_buffer, prefix, sizeof(name_buffer)-1);
1509
1493
*prefix_end++= '_';
1510
1494
len=name_buffer + sizeof(name_buffer) - prefix_end;
1512
1496
for (; variables->name; variables++)
1514
my_stpncpy(prefix_end, variables->name, len);
1498
stpncpy(prefix_end, variables->name, len);
1515
1499
name_buffer[sizeof(name_buffer)-1]=0; /* Safety */
1516
1500
if (ucase_names)
1517
1501
make_upper(name_buffer);
1521
1505
Repeat as necessary, if new var is again SHOW_FUNC
1523
1507
for (var=variables; var->type == SHOW_FUNC; var= &tmp)
1524
((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(session, &tmp, buff);
1508
((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(thd, &tmp, buff);
1526
1510
SHOW_TYPE show_type=var->type;
1527
1511
if (show_type == SHOW_ARRAY)
1529
show_status_array(session, wild, (SHOW_VAR *) var->value, value_type,
1513
show_status_array(thd, wild, (SHOW_VAR *) var->value, value_type,
1530
1514
status_var, name_buffer, table, ucase_names);
1576
1560
end= int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
1578
1562
case SHOW_BOOL:
1579
end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1563
end= stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1581
1565
case SHOW_MY_BOOL:
1582
end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1566
end= stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1585
1569
end= int10_to_str((long) *(uint32_t*) value, buff, 10);
1688
bool schema_table_store_record(Session *session, Table *table)
1672
bool schema_table_store_record(THD *thd, Table *table)
1691
1675
if ((error= table->file->ha_write_row(table->record[0])))
1693
1677
TMP_TABLE_PARAM *param= table->pos_in_table_list->schema_table_param;
1695
if (create_myisam_from_heap(session, table, param->start_recinfo,
1679
if (create_myisam_from_heap(thd, table, param->start_recinfo,
1696
1680
¶m->recinfo, error, 0))
1703
int make_table_list(Session *session, SELECT_LEX *sel,
1687
int make_table_list(THD *thd, SELECT_LEX *sel,
1704
1688
LEX_STRING *db_name, LEX_STRING *table_name)
1706
1690
Table_ident *table_ident;
1707
table_ident= new Table_ident(session, *db_name, *table_name, 1);
1691
table_ident= new Table_ident(thd, *db_name, *table_name, 1);
1708
1692
sel->init_query();
1709
if (!sel->add_table_to_list(session, table_ident, 0, 0, TL_READ))
1693
if (!sel->add_table_to_list(thd, table_ident, 0, 0, TL_READ))
1777
1761
/* Lookup value is database name */
1778
if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
1779
(unsigned char *) item_field->field_name,
1762
if (!cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
1763
(uchar *) item_field->field_name,
1780
1764
strlen(item_field->field_name), 0))
1782
session->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1766
thd->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1783
1767
tmp_str->length(), false);
1785
1769
/* Lookup value is table name */
1786
else if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name2,
1770
else if (!cs->coll->strnncollsp(cs, (uchar *) field_name2,
1787
1771
strlen(field_name2),
1788
(unsigned char *) item_field->field_name,
1772
(uchar *) item_field->field_name,
1789
1773
strlen(item_field->field_name), 0))
1791
session->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1775
thd->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1792
1776
tmp_str->length(), false);
1830
1814
if (item->type() == Item::FUNC_ITEM)
1832
if (get_lookup_value(session, (Item_func*)item, table, lookup_field_vals))
1816
if (get_lookup_value(thd, (Item_func*)item, table, lookup_field_vals))
1837
if (calc_lookup_values_from_cond(session, item, table, lookup_field_vals))
1821
if (calc_lookup_values_from_cond(thd, item, table, lookup_field_vals))
1870
1854
const char *field_name2= schema_table->idx_field2 >= 0 ?
1871
1855
field_info[schema_table->idx_field2].field_name : "";
1872
1856
if (table->table != item_field->field->table ||
1873
(cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
1874
(unsigned char *) item_field->field_name,
1857
(cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
1858
(uchar *) item_field->field_name,
1875
1859
strlen(item_field->field_name), 0) &&
1876
cs->coll->strnncollsp(cs, (unsigned char *) field_name2, strlen(field_name2),
1877
(unsigned char *) item_field->field_name,
1860
cs->coll->strnncollsp(cs, (uchar *) field_name2, strlen(field_name2),
1861
(uchar *) item_field->field_name,
1878
1862
strlen(item_field->field_name), 0)))
1962
1946
1 error, there can be no matching records for the condition
1965
bool get_lookup_field_values(Session *session, COND *cond, TableList *tables,
1949
bool get_lookup_field_values(THD *thd, COND *cond, TableList *tables,
1966
1950
LOOKUP_FIELD_VALUES *lookup_field_values)
1968
LEX *lex= session->lex;
1969
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1953
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
1970
1954
memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1971
1955
switch (lex->sql_command) {
1972
1956
case SQLCOM_SHOW_DATABASES:
2025
int make_db_list(Session *session, List<LEX_STRING> *files,
2009
int make_db_list(THD *thd, List<LEX_STRING> *files,
2026
2010
LOOKUP_FIELD_VALUES *lookup_field_vals,
2027
2011
bool *with_i_schema)
2029
2013
LEX_STRING *i_s_name_copy= 0;
2030
i_s_name_copy= session->make_lex_string(i_s_name_copy,
2014
i_s_name_copy= thd->make_lex_string(i_s_name_copy,
2031
2015
INFORMATION_SCHEMA_NAME.str,
2032
2016
INFORMATION_SCHEMA_NAME.length, true);
2033
2017
*with_i_schema= 0;
2047
2031
if (files->push_back(i_s_name_copy))
2050
return (find_files(session, files, NULL, mysql_data_home,
2034
return (find_files(thd, files, NullS, mysql_data_home,
2051
2035
lookup_field_vals->db_value.str, 1) != FIND_FILES_OK);
2078
2062
if (files->push_back(i_s_name_copy))
2080
2064
*with_i_schema= 1;
2081
return (find_files(session, files, NULL,
2082
mysql_data_home, NULL, 1) != FIND_FILES_OK);
2065
return (find_files(thd, files, NullS,
2066
mysql_data_home, NullS, 1) != FIND_FILES_OK);
2215
2199
if (with_i_schema)
2216
return (schema_tables_add(session, table_names,
2200
return (schema_tables_add(thd, table_names,
2217
2201
lookup_field_vals->table_value.str));
2219
find_files_result res= find_files(session, table_names, db_name->str, path,
2203
find_files_result res= find_files(thd, table_names, db_name->str, path,
2220
2204
lookup_field_vals->table_value.str, 0);
2221
2205
if (res != FIND_FILES_OK)
2259
fill_schema_show_cols_or_idxs(Session *session, TableList *tables,
2243
fill_schema_show_cols_or_idxs(THD *thd, TableList *tables,
2260
2244
ST_SCHEMA_TABLE *schema_table,
2261
2245
Open_tables_state *open_tables_state_backup)
2263
LEX *lex= session->lex;
2265
2249
LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
2266
2250
enum_sql_command save_sql_command= lex->sql_command;
2272
2256
lex->all_selects_list= tables->schema_select_lex;
2274
Restore session->temporary_tables to be able to process
2258
Restore thd->temporary_tables to be able to process
2275
2259
temporary tables(only for 'show index' & 'show columns').
2276
2260
This should be changed when processing of temporary tables for
2277
2261
I_S tables will be done.
2279
session->temporary_tables= open_tables_state_backup->temporary_tables;
2263
thd->temporary_tables= open_tables_state_backup->temporary_tables;
2281
2265
Let us set fake sql_command so views won't try to merge
2282
2266
themselves into main statement. If we don't do this,
2284
2268
SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
2286
2270
lex->sql_command= SQLCOM_SHOW_FIELDS;
2287
res= open_normal_and_derived_tables(session, show_table_list,
2271
res= open_normal_and_derived_tables(thd, show_table_list,
2288
2272
DRIZZLE_LOCK_IGNORE_FLUSH);
2289
2273
lex->sql_command= save_sql_command;
2298
2282
in this case(this part of code is used only for
2299
2283
'show columns' & 'show statistics' commands).
2301
table_name= session->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2285
table_name= thd->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2302
2286
strlen(show_table_list->alias), false);
2303
db_name= session->make_lex_string(&tmp_lex_string, show_table_list->db,
2287
db_name= thd->make_lex_string(&tmp_lex_string, show_table_list->db,
2304
2288
show_table_list->db_length, false);
2307
error= test(schema_table->process_table(session, show_table_list,
2291
error= test(schema_table->process_table(thd, show_table_list,
2308
2292
table, res, db_name,
2310
session->temporary_tables= 0;
2311
close_tables_for_reopen(session, &show_table_list);
2294
thd->temporary_tables= 0;
2295
close_tables_for_reopen(thd, &show_table_list);
2342
2326
char path[FN_REFLEN];
2343
2327
(void) build_table_filename(path, sizeof(path), db_name->str,
2344
2328
table_name->str, reg_ext, 0);
2345
if (mysql_frm_type(session, path, ¬_used))
2329
if (mysql_frm_type(thd, path, ¬_used))
2347
2331
table->field[3]->store(STRING_WITH_LEN("BASE Table"),
2348
2332
system_charset_info);
2422
2406
open_tables function for this table
2425
static int fill_schema_table_from_frm(Session *session,TableList *tables,
2409
static int fill_schema_table_from_frm(THD *thd,TableList *tables,
2426
2410
ST_SCHEMA_TABLE *schema_table,
2427
2411
LEX_STRING *db_name,
2428
2412
LEX_STRING *table_name,
2429
enum enum_schema_tables)
2413
enum enum_schema_tables schema_table_idx __attribute__((unused)))
2431
2415
Table *table= tables->table;
2432
2416
TABLE_SHARE *share;
2434
2418
TableList table_list;
2437
2421
char key[MAX_DBKEY_LENGTH];
2438
uint32_t key_length;
2440
2424
memset(&table_list, 0, sizeof(TableList));
2441
2425
memset(&tbl, 0, sizeof(Table));
2443
2427
table_list.table_name= table_name->str;
2444
2428
table_list.db= db_name->str;
2446
key_length= create_table_def_key(session, key, &table_list, 0);
2430
key_length= create_table_def_key(thd, key, &table_list, 0);
2447
2431
pthread_mutex_lock(&LOCK_open);
2448
share= get_table_share(session, &table_list, key,
2432
share= get_table_share(thd, &table_list, key,
2449
2433
key_length, 0, &error);
2505
2489
List<LEX_STRING> db_names;
2506
2490
List_iterator_fast<LEX_STRING> it(db_names);
2507
2491
COND *partial_cond= 0;
2508
uint32_t derived_tables= lex->derived_tables;
2492
uint derived_tables= lex->derived_tables;
2510
2494
Open_tables_state open_tables_state_backup;
2511
2495
Query_tables_list query_tables_list_backup;
2512
uint32_t table_open_method;
2513
bool old_value= session->no_warnings_for_error;
2496
uint table_open_method;
2497
bool old_value= thd->no_warnings_for_error;
2515
2499
lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
2532
2516
if (lsel && lsel->table_list.first)
2534
error= fill_schema_show_cols_or_idxs(session, tables, schema_table,
2518
error= fill_schema_show_cols_or_idxs(thd, tables, schema_table,
2535
2519
&open_tables_state_backup);
2539
if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
2523
if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2578
if (make_db_list(session, &db_names, &lookup_field_vals, &with_i_schema))
2562
if (make_db_list(thd, &db_names, &lookup_field_vals, &with_i_schema))
2580
2564
it.rewind(); /* To get access to new elements in basis list */
2581
2565
while ((db_name= it++))
2584
session->no_warnings_for_error= 1;
2568
thd->no_warnings_for_error= 1;
2585
2569
List<LEX_STRING> table_names;
2586
int res= make_table_name_list(session, &table_names, lex,
2570
int res= make_table_name_list(thd, &table_names, lex,
2587
2571
&lookup_field_vals,
2588
2572
with_i_schema, db_name);
2589
2573
if (res == 2) /* Not fatal error, continue */
2620
2604
/* SHOW Table NAMES command */
2621
2605
if (schema_table_idx == SCH_TABLE_NAMES)
2623
if (fill_schema_table_names(session, tables->table, db_name,
2607
if (fill_schema_table_names(thd, tables->table, db_name,
2624
2608
table_name, with_i_schema))
2629
2613
if (!(table_open_method & ~OPEN_FRM_ONLY) &&
2630
2614
!with_i_schema)
2632
if (!fill_schema_table_from_frm(session, tables, schema_table, db_name,
2616
if (!fill_schema_table_from_frm(thd, tables, schema_table, db_name,
2633
2617
table_name, schema_table_idx))
2640
2624
Set the parent lex of 'sel' because it is needed by
2641
2625
sel.init_query() which is called inside make_table_list.
2643
session->no_warnings_for_error= 1;
2627
thd->no_warnings_for_error= 1;
2644
2628
sel.parent_lex= lex;
2645
2629
/* db_name can be changed in make_table_list() func */
2646
if (!session->make_lex_string(&orig_db_name, db_name->str,
2630
if (!thd->make_lex_string(&orig_db_name, db_name->str,
2647
2631
db_name->length, false))
2649
if (make_table_list(session, &sel, db_name, table_name))
2633
if (make_table_list(thd, &sel, db_name, table_name))
2651
2635
TableList *show_table_list= (TableList*) sel.table_list.first;
2652
2636
lex->all_selects_list= &sel;
2654
2638
lex->sql_command= SQLCOM_SHOW_FIELDS;
2655
2639
show_table_list->i_s_requested_object=
2656
2640
schema_table->i_s_requested_object;
2657
res= open_normal_and_derived_tables(session, show_table_list,
2641
res= open_normal_and_derived_tables(thd, show_table_list,
2658
2642
DRIZZLE_LOCK_IGNORE_FLUSH);
2659
2643
lex->sql_command= save_sql_command;
2661
2645
XXX: show_table_list has a flag i_is_requested,
2662
2646
and when it's set, open_normal_and_derived_tables()
2663
2647
can return an error without setting an error message
2664
in Session, which is a hack. This is why we have to
2665
check for res, then for session->is_error() only then
2666
for session->main_da.sql_errno().
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().
2668
if (res && session->is_error() &&
2669
session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2652
if (res && thd->is_error() &&
2653
thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2672
2656
Hide error for not existing table.
2686
2670
to use alias because alias contains original table name
2689
session->make_lex_string(&tmp_lex_string, show_table_list->alias,
2673
thd->make_lex_string(&tmp_lex_string, show_table_list->alias,
2690
2674
strlen(show_table_list->alias), false);
2691
res= schema_table->process_table(session, show_table_list, table,
2675
res= schema_table->process_table(thd, show_table_list, table,
2692
2676
res, &orig_db_name,
2693
2677
&tmp_lex_string);
2694
close_tables_for_reopen(session, &show_table_list);
2678
close_tables_for_reopen(thd, &show_table_list);
2696
2680
assert(!lex->query_tables_own_last);
2712
session->restore_backup_open_tables_state(&open_tables_state_backup);
2696
thd->restore_backup_open_tables_state(&open_tables_state_backup);
2713
2697
lex->restore_backup_query_tables_list(&query_tables_list_backup);
2714
2698
lex->derived_tables= derived_tables;
2715
2699
lex->all_selects_list= old_all_select_lex;
2716
2700
lex->sql_command= save_sql_command;
2717
session->no_warnings_for_error= old_value;
2701
thd->no_warnings_for_error= old_value;
2722
bool store_schema_shemata(Session* session, Table *table, LEX_STRING *db_name,
2706
bool store_schema_shemata(THD* thd, Table *table, LEX_STRING *db_name,
2723
2707
const CHARSET_INFO * const cs)
2725
2709
restore_record(table, s->default_values);
2726
2710
table->field[1]->store(db_name->str, db_name->length, system_charset_info);
2727
2711
table->field[2]->store(cs->csname, strlen(cs->csname), system_charset_info);
2728
2712
table->field[3]->store(cs->name, strlen(cs->name), system_charset_info);
2729
return schema_table_store_record(session, table);
2713
return schema_table_store_record(thd, table);
2733
int fill_schema_schemata(Session *session, TableList *tables, COND *cond)
2717
int fill_schema_schemata(THD *thd, TableList *tables, COND *cond)
2736
2720
TODO: fill_schema_shemata() is called when new client is connected.
2744
2728
HA_CREATE_INFO create;
2745
2729
Table *table= tables->table;
2747
if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
2731
if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2749
if (make_db_list(session, &db_names, &lookup_field_vals,
2733
if (make_db_list(thd, &db_names, &lookup_field_vals,
2750
2734
&with_i_schema))
2774
2758
if (with_i_schema) // information schema name is always first in list
2776
if (store_schema_shemata(session, table, db_name,
2760
if (store_schema_shemata(thd, table, db_name,
2777
2761
system_charset_info))
2779
2763
with_i_schema= 0;
2783
load_db_opt_by_name(session, db_name->str, &create);
2784
if (store_schema_shemata(session, table, db_name,
2767
load_db_opt_by_name(thd, db_name->str, &create);
2768
if (store_schema_shemata(thd, table, db_name,
2785
2769
create.default_table_charset))
2808
2792
there was errors during opening tables
2810
const char *error= session->is_error() ? session->main_da.message() : "";
2794
const char *error= thd->is_error() ? thd->main_da.message() : "";
2811
2795
if (tables->schema_table)
2812
2796
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2814
2798
table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2815
2799
table->field[20]->store(error, strlen(error), cs);
2816
session->clear_error();
2842
2826
ptr=option_buff;
2843
2827
if (share->min_rows)
2845
ptr=my_stpcpy(ptr," min_rows=");
2829
ptr=stpcpy(ptr," min_rows=");
2846
2830
ptr=int64_t10_to_str(share->min_rows,ptr,10);
2848
2832
if (share->max_rows)
2850
ptr=my_stpcpy(ptr," max_rows=");
2834
ptr=stpcpy(ptr," max_rows=");
2851
2835
ptr=int64_t10_to_str(share->max_rows,ptr,10);
2853
2837
if (share->avg_row_length)
2855
ptr=my_stpcpy(ptr," avg_row_length=");
2839
ptr=stpcpy(ptr," avg_row_length=");
2856
2840
ptr=int64_t10_to_str(share->avg_row_length,ptr,10);
2858
2842
if (share->db_create_options & HA_OPTION_PACK_KEYS)
2859
ptr=my_stpcpy(ptr," pack_keys=1");
2843
ptr=stpcpy(ptr," pack_keys=1");
2860
2844
if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
2861
ptr=my_stpcpy(ptr," pack_keys=0");
2845
ptr=stpcpy(ptr," pack_keys=0");
2862
2846
/* We use CHECKSUM, instead of TABLE_CHECKSUM, for backward compability */
2863
2847
if (share->db_create_options & HA_OPTION_CHECKSUM)
2864
ptr=my_stpcpy(ptr," checksum=1");
2848
ptr=stpcpy(ptr," checksum=1");
2865
2849
if (share->page_checksum != HA_CHOICE_UNDEF)
2866
2850
ptr= strxmov(ptr, " page_checksum=",
2867
ha_choice_values[(uint) share->page_checksum], NULL);
2851
ha_choice_values[(uint) share->page_checksum], NullS);
2868
2852
if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
2869
ptr=my_stpcpy(ptr," delay_key_write=1");
2853
ptr=stpcpy(ptr," delay_key_write=1");
2870
2854
if (share->row_type != ROW_TYPE_DEFAULT)
2871
2855
ptr=strxmov(ptr, " row_format=",
2872
2856
ha_row_type[(uint) share->row_type],
2874
2858
if (share->block_size)
2876
ptr= my_stpcpy(ptr, " block_size=");
2860
ptr= stpcpy(ptr, " block_size=");
2877
2861
ptr= int64_t10_to_str(share->block_size, ptr, 10);
2882
2866
ptr= strxmov(ptr, " TRANSACTIONAL=",
2883
2867
(share->transactional == HA_CHOICE_YES ? "1" : "0"),
2886
2870
if (share->transactional != HA_CHOICE_UNDEF)
2887
2871
ptr= strxmov(ptr, " transactional=",
2888
ha_choice_values[(uint) share->transactional], NULL);
2872
ha_choice_values[(uint) share->transactional], NullS);
2889
2873
table->field[19]->store(option_buff+1,
2890
2874
(ptr == option_buff ? 0 :
2891
2875
(uint) (ptr-option_buff)-1), cs);
2953
2937
if (file->stats.create_time)
2955
session->variables.time_zone->gmt_sec_to_TIME(&time,
2939
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2956
2940
(my_time_t) file->stats.create_time);
2957
2941
table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2958
2942
table->field[14]->set_notnull();
2960
2944
if (file->stats.update_time)
2962
session->variables.time_zone->gmt_sec_to_TIME(&time,
2946
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2963
2947
(my_time_t) file->stats.update_time);
2964
2948
table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2965
2949
table->field[15]->set_notnull();
2967
2951
if (file->stats.check_time)
2969
session->variables.time_zone->gmt_sec_to_TIME(&time,
2953
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2970
2954
(my_time_t) file->stats.check_time);
2971
2955
table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2972
2956
table->field[16]->set_notnull();
3083
static int get_schema_column_record(Session *session, TableList *tables,
3069
static int get_schema_column_record(THD *thd, TableList *tables,
3084
3070
Table *table, bool res,
3085
3071
LEX_STRING *db_name,
3086
3072
LEX_STRING *table_name)
3088
LEX *lex= session->lex;
3089
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3075
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3090
3076
const CHARSET_INFO * const cs= system_charset_info;
3091
3077
Table *show_table;
3092
3078
TABLE_SHARE *show_table_share;
3101
3087
I.e. we are in SELECT FROM INFORMATION_SCHEMA.COLUMS
3102
3088
rather than in SHOW COLUMNS
3104
if (session->is_error())
3105
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3106
session->main_da.sql_errno(), session->main_da.message());
3107
session->clear_error();
3090
if (thd->is_error())
3091
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3092
thd->main_da.sql_errno(), thd->main_da.message());
3131
3117
if (!show_table->read_set)
3133
3119
/* to satisfy 'field->val_str' ASSERTs */
3134
unsigned char *bitmaps;
3135
uint32_t bitmap_size= show_table_share->column_bitmap_size;
3136
if (!(bitmaps= (unsigned char*) alloc_root(session->mem_root, bitmap_size)))
3121
uint bitmap_size= show_table_share->column_bitmap_size;
3122
if (!(bitmaps= (uchar*) alloc_root(thd->mem_root, bitmap_size)))
3138
3124
bitmap_init(&show_table->def_read_set,
3139
3125
(my_bitmap_map*) bitmaps, show_table_share->fields, false);
3146
3132
for (; (field= *ptr) ; ptr++)
3149
3135
char tmp[MAX_FIELD_WIDTH];
3150
3136
String type(tmp,sizeof(tmp), system_charset_info);
3153
3139
/* to satisfy 'field->val_str' ASSERTs */
3154
3140
field->table= show_table;
3155
show_table->in_use= session;
3141
show_table->in_use= thd;
3157
3143
if (wild && wild[0] &&
3158
3144
wild_case_compare(system_charset_info, field->field_name,wild))
3169
3155
table->field[4]->store((int64_t) count, true);
3171
if (get_field_default_value(session, timestamp_field, field, &type, 0))
3157
if (get_field_default_value(thd, timestamp_field, field, &type, 0))
3173
3159
table->field[5]->store(type.ptr(), type.length(), cs);
3174
3160
table->field[5]->set_notnull();
3176
pos=(unsigned char*) ((field->flags & NOT_NULL_FLAG) ? "NO" : "YES");
3162
pos=(uchar*) ((field->flags & NOT_NULL_FLAG) ? "NO" : "YES");
3177
3163
table->field[6]->store((const char*) pos,
3178
3164
strlen((const char*) pos), cs);
3179
3165
store_column_type(table, field, cs, 7);
3181
pos=(unsigned char*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
3167
pos=(uchar*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
3182
3168
(field->flags & UNIQUE_KEY_FLAG) ? "UNI" :
3183
3169
(field->flags & MULTIPLE_KEY_FLAG) ? "MUL":"");
3184
3170
table->field[15]->store((const char*) pos,
3191
3177
field->unireg_check != Field::TIMESTAMP_DN_FIELD)
3192
3178
table->field[16]->store(STRING_WITH_LEN("on update CURRENT_TIMESTAMP"),
3194
if (field->vcol_info)
3195
table->field[16]->store(STRING_WITH_LEN("VIRTUAL"), cs);
3196
3181
table->field[18]->store(field->comment.str, field->comment.length, cs);
3198
3183
enum column_format_type column_format= (enum column_format_type)
3199
3184
((field->flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
3200
pos=(unsigned char*)"Default";
3185
pos=(uchar*)"Default";
3201
3186
table->field[19]->store((const char*) pos,
3202
3187
strlen((const char*) pos), cs);
3203
pos=(unsigned char*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
3188
pos=(uchar*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
3204
3189
column_format == COLUMN_FORMAT_TYPE_FIXED ? "Fixed" :
3206
3191
table->field[20]->store((const char*) pos,
3207
3192
strlen((const char*) pos), cs);
3209
if (schema_table_store_record(session, table))
3194
if (schema_table_store_record(thd, table))
3217
int fill_schema_charsets(Session *session, TableList *tables, COND *)
3202
int fill_schema_charsets(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3219
3204
CHARSET_INFO **cs;
3220
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3205
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3221
3206
Table *table= tables->table;
3222
3207
const CHARSET_INFO * const scs= system_charset_info;
3248
int fill_schema_collation(Session *session, TableList *tables, COND *)
3233
int fill_schema_collation(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3250
3235
CHARSET_INFO **cs;
3251
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3236
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3252
3237
Table *table= tables->table;
3253
3238
const CHARSET_INFO * const scs= system_charset_info;
3254
3239
for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3308
3293
restore_record(table, s->default_values);
3309
3294
table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3310
3295
table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3311
if (schema_table_store_record(session, table))
3296
if (schema_table_store_record(thd, table))
3324
3309
const CHARSET_INFO * const cs= system_charset_info;
3327
if (session->lex->sql_command != SQLCOM_SHOW_KEYS)
3312
if (thd->lex->sql_command != SQLCOM_SHOW_KEYS)
3330
3315
I.e. we are in SELECT FROM INFORMATION_SCHEMA.STATISTICS
3331
3316
rather than in SHOW KEYS
3333
if (session->is_error())
3334
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3335
session->main_da.sql_errno(), session->main_da.message());
3336
session->clear_error();
3318
if (thd->is_error())
3319
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3320
thd->main_da.sql_errno(), thd->main_da.message());
3346
3331
show_table->file->info(HA_STATUS_VARIABLE |
3347
3332
HA_STATUS_NO_LOCK |
3348
3333
HA_STATUS_TIME);
3349
for (uint32_t i=0 ; i < show_table->s->keys ; i++,key_info++)
3334
for (uint i=0 ; i < show_table->s->keys ; i++,key_info++)
3351
3336
KEY_PART_INFO *key_part= key_info->key_part;
3352
3337
const char *str;
3353
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
3338
for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
3355
3340
restore_record(table, s->default_values);
3356
3341
table->field[1]->store(db_name->str, db_name->length, cs);
3391
3376
key_part->field->charset()->mbmaxlen, true);
3392
3377
table->field[10]->set_notnull();
3394
uint32_t flags= key_part->field ? key_part->field->flags : 0;
3379
uint flags= key_part->field ? key_part->field->flags : 0;
3395
3380
const char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES");
3396
3381
table->field[12]->store(pos, strlen(pos), cs);
3397
3382
if (!show_table->s->keys_in_use.is_set(i))
3416
bool store_constraints(Session *session, Table *table, LEX_STRING *db_name,
3401
bool store_constraints(THD *thd, Table *table, LEX_STRING *db_name,
3417
3402
LEX_STRING *table_name, const char *key_name,
3418
uint32_t key_len, const char *con_type, uint32_t con_len)
3403
uint key_len, const char *con_type, uint con_len)
3420
3405
const CHARSET_INFO * const cs= system_charset_info;
3421
3406
restore_record(table, s->default_values);
3424
3409
table->field[3]->store(db_name->str, db_name->length, cs);
3425
3410
table->field[4]->store(table_name->str, table_name->length, cs);
3426
3411
table->field[5]->store(con_type, con_len, cs);
3427
return schema_table_store_record(session, table);
3412
return schema_table_store_record(thd, table);
3431
static int get_schema_constraints_record(Session *session, TableList *tables,
3416
static int get_schema_constraints_record(THD *thd, TableList *tables,
3432
3417
Table *table, bool res,
3433
3418
LEX_STRING *db_name,
3434
3419
LEX_STRING *table_name)
3438
if (session->is_error())
3439
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3440
session->main_da.sql_errno(), session->main_da.message());
3441
session->clear_error();
3423
if (thd->is_error())
3424
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3425
thd->main_da.sql_errno(), thd->main_da.message());
3446
3431
List<FOREIGN_KEY_INFO> f_key_list;
3447
3432
Table *show_table= tables->table;
3448
3433
KEY *key_info=show_table->key_info;
3449
uint32_t primary_key= show_table->s->primary_key;
3434
uint primary_key= show_table->s->primary_key;
3450
3435
show_table->file->info(HA_STATUS_VARIABLE |
3451
3436
HA_STATUS_NO_LOCK |
3452
3437
HA_STATUS_TIME);
3453
for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
3438
for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
3455
3440
if (i != primary_key && !(key_info->flags & HA_NOSAME))
3458
3443
if (i == primary_key && !strcmp(key_info->name, primary_key_name))
3460
if (store_constraints(session, table, db_name, table_name, key_info->name,
3445
if (store_constraints(thd, table, db_name, table_name, key_info->name,
3461
3446
strlen(key_info->name),
3462
3447
STRING_WITH_LEN("PRIMARY KEY")))
3465
3450
else if (key_info->flags & HA_NOSAME)
3467
if (store_constraints(session, table, db_name, table_name, key_info->name,
3452
if (store_constraints(thd, table, db_name, table_name, key_info->name,
3468
3453
strlen(key_info->name),
3469
3454
STRING_WITH_LEN("UNIQUE")))
3474
show_table->file->get_foreign_key_list(session, &f_key_list);
3459
show_table->file->get_foreign_key_list(thd, &f_key_list);
3475
3460
FOREIGN_KEY_INFO *f_key_info;
3476
3461
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3477
3462
while ((f_key_info=it++))
3479
if (store_constraints(session, table, db_name, table_name,
3464
if (store_constraints(thd, table, db_name, table_name,
3480
3465
f_key_info->forein_id->str,
3481
3466
strlen(f_key_info->forein_id->str),
3482
3467
"FOREIGN KEY", 11))
3490
3475
void store_key_column_usage(Table *table, LEX_STRING *db_name,
3491
3476
LEX_STRING *table_name, const char *key_name,
3492
uint32_t key_len, const char *con_type, uint32_t con_len,
3477
uint key_len, const char *con_type, uint con_len,
3495
3480
const CHARSET_INFO * const cs= system_charset_info;
3521
3506
List<FOREIGN_KEY_INFO> f_key_list;
3522
3507
Table *show_table= tables->table;
3523
3508
KEY *key_info=show_table->key_info;
3524
uint32_t primary_key= show_table->s->primary_key;
3509
uint primary_key= show_table->s->primary_key;
3525
3510
show_table->file->info(HA_STATUS_VARIABLE |
3526
3511
HA_STATUS_NO_LOCK |
3527
3512
HA_STATUS_TIME);
3528
for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
3513
for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
3530
3515
if (i != primary_key && !(key_info->flags & HA_NOSAME))
3533
3518
KEY_PART_INFO *key_part= key_info->key_part;
3534
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
3519
for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
3536
3521
if (key_part->field)
3543
3528
key_part->field->field_name,
3544
3529
strlen(key_part->field->field_name),
3545
3530
(int64_t) f_idx);
3546
if (schema_table_store_record(session, table))
3531
if (schema_table_store_record(thd, table))
3552
show_table->file->get_foreign_key_list(session, &f_key_list);
3537
show_table->file->get_foreign_key_list(thd, &f_key_list);
3553
3538
FOREIGN_KEY_INFO *f_key_info;
3554
3539
List_iterator_fast<FOREIGN_KEY_INFO> fkey_it(f_key_list);
3555
3540
while ((f_key_info= fkey_it++))
3594
int fill_open_tables(Session *session, TableList *tables, COND *)
3579
int fill_open_tables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3596
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3581
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3597
3582
Table *table= tables->table;
3598
3583
const CHARSET_INFO * const cs= system_charset_info;
3599
3584
OPEN_TableList *open_list;
3600
if (!(open_list=list_open_tables(session,session->lex->select_lex.db, wild))
3601
&& session->is_fatal_error)
3585
if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3586
&& thd->is_fatal_error)
3604
3589
for (; open_list ; open_list=open_list->next)
3608
3593
table->field[1]->store(open_list->table, strlen(open_list->table), cs);
3609
3594
table->field[2]->store((int64_t) open_list->in_use, true);
3610
3595
table->field[3]->store((int64_t) open_list->locked, true);
3611
if (schema_table_store_record(session, table))
3596
if (schema_table_store_record(thd, table))
3618
int fill_variables(Session *session, TableList *tables, COND *)
3603
int fill_variables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3621
LEX *lex= session->lex;
3622
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3607
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3623
3608
enum enum_schema_tables schema_table_idx=
3624
3609
get_schema_table_idx(tables->schema_table);
3625
3610
enum enum_var_type option_type= OPT_SESSION;
3631
3616
option_type= OPT_GLOBAL;
3633
3618
rw_rdlock(&LOCK_system_variables_hash);
3634
res= show_status_array(session, wild, enumerate_sys_vars(session, sorted_vars),
3619
res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars),
3635
3620
option_type, NULL, "", tables->table, upper_case_names);
3636
3621
rw_unlock(&LOCK_system_variables_hash);
3641
int fill_status(Session *session, TableList *tables, COND *)
3626
int fill_status(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3643
LEX *lex= session->lex;
3644
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3629
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3646
3631
STATUS_VAR *tmp1, tmp;
3647
3632
enum enum_schema_tables schema_table_idx=
3667
3652
option_type= OPT_SESSION;
3668
tmp1= &session->status_var;
3653
tmp1= &thd->status_var;
3671
3656
pthread_mutex_lock(&LOCK_status);
3672
3657
if (option_type == OPT_GLOBAL)
3673
3658
calc_sum_of_all_status(&tmp);
3674
res= show_status_array(session, wild,
3659
res= show_status_array(thd, wild,
3675
3660
(SHOW_VAR *)all_status_vars.buffer,
3676
3661
option_type, tmp1, "", tables->table,
3677
3662
upper_case_names);
3927
3915
TMP_TABLE_PARAM *tmp_table_param =
3928
(TMP_TABLE_PARAM*) (session->alloc(sizeof(TMP_TABLE_PARAM)));
3916
(TMP_TABLE_PARAM*) (thd->alloc(sizeof(TMP_TABLE_PARAM)));
3929
3917
tmp_table_param->init();
3930
3918
tmp_table_param->table_charset= cs;
3931
3919
tmp_table_param->field_count= field_count;
3932
3920
tmp_table_param->schema_table= 1;
3933
SELECT_LEX *select_lex= session->lex->current_select;
3934
if (!(table= create_tmp_table(session, tmp_table_param,
3921
SELECT_LEX *select_lex= thd->lex->current_select;
3922
if (!(table= create_tmp_table(thd, tmp_table_param,
3935
3923
field_list, (order_st*) 0, 0, 0,
3936
(select_lex->options | session->options |
3924
(select_lex->options | thd->options |
3937
3925
TMP_TABLE_ALL_COLUMNS),
3938
3926
HA_POS_ERROR, table_list->alias)))
3940
3928
my_bitmap_map* bitmaps=
3941
(my_bitmap_map*) session->alloc(bitmap_buffer_size(field_count));
3929
(my_bitmap_map*) thd->alloc(bitmap_buffer_size(field_count));
3942
3930
bitmap_init(&table->def_read_set, (my_bitmap_map*) bitmaps, field_count,
3944
3932
table->read_set= &table->def_read_set;
3966
int make_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
3954
int make_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
3968
3956
ST_FIELD_INFO *field_info= schema_table->fields_info;
3969
Name_resolution_context *context= &session->lex->select_lex.context;
3957
Name_resolution_context *context= &thd->lex->select_lex.context;
3970
3958
for (; field_info->field_name; field_info++)
3972
3960
if (field_info->old_name)
3974
3962
Item_field *field= new Item_field(context,
3975
NULL, NULL, field_info->field_name);
3963
NullS, NullS, field_info->field_name);
3978
3966
field->set_name(field_info->old_name,
3979
3967
strlen(field_info->old_name),
3980
3968
system_charset_info);
3981
if (add_item_to_list(session, field))
3969
if (add_item_to_list(thd, field))
3999
3987
ST_FIELD_INFO *field_info= &schema_table->fields_info[1];
4000
3988
String buffer(tmp,sizeof(tmp), system_charset_info);
4001
3989
Item_field *field= new Item_field(context,
4002
NULL, NULL, field_info->field_name);
4003
if (!field || add_item_to_list(session, field))
3990
NullS, NullS, field_info->field_name);
3991
if (!field || add_item_to_list(thd, field))
4005
3993
buffer.length(0);
4006
3994
buffer.append(field_info->old_name);
4019
int make_table_names_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4007
int make_table_names_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
4022
String buffer(tmp,sizeof(tmp), session->charset());
4023
LEX *lex= session->lex;
4010
String buffer(tmp,sizeof(tmp), thd->charset());
4024
4012
Name_resolution_context *context= &lex->select_lex.context;
4026
4014
ST_FIELD_INFO *field_info= &schema_table->fields_info[2];
4034
4022
buffer.append(')');
4036
4024
Item_field *field= new Item_field(context,
4037
NULL, NULL, field_info->field_name);
4038
if (add_item_to_list(session, field))
4025
NullS, NullS, field_info->field_name);
4026
if (add_item_to_list(thd, field))
4040
4028
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4041
if (session->lex->verbose)
4029
if (thd->lex->verbose)
4043
4031
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4044
4032
field_info= &schema_table->fields_info[3];
4045
field= new Item_field(context, NULL, NULL, field_info->field_name);
4046
if (add_item_to_list(session, field))
4033
field= new Item_field(context, NullS, NullS, field_info->field_name);
4034
if (add_item_to_list(thd, field))
4048
4036
field->set_name(field_info->old_name, strlen(field_info->old_name),
4049
4037
system_charset_info);
4055
int make_columns_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4043
int make_columns_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
4057
4045
int fields_arr[]= {3, 14, 13, 6, 15, 5, 16, 17, 18, -1};
4058
4046
int *field_num= fields_arr;
4059
4047
ST_FIELD_INFO *field_info;
4060
Name_resolution_context *context= &session->lex->select_lex.context;
4048
Name_resolution_context *context= &thd->lex->select_lex.context;
4062
4050
for (; *field_num >= 0; field_num++)
4064
4052
field_info= &schema_table->fields_info[*field_num];
4065
if (!session->lex->verbose && (*field_num == 13 ||
4053
if (!thd->lex->verbose && (*field_num == 13 ||
4066
4054
*field_num == 17 ||
4067
4055
*field_num == 18))
4069
4057
Item_field *field= new Item_field(context,
4070
NULL, NULL, field_info->field_name);
4058
NullS, NullS, field_info->field_name);
4073
4061
field->set_name(field_info->old_name,
4074
4062
strlen(field_info->old_name),
4075
4063
system_charset_info);
4076
if (add_item_to_list(session, field))
4064
if (add_item_to_list(thd, field))
4084
int make_character_sets_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4072
int make_character_sets_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
4086
4074
int fields_arr[]= {0, 2, 1, 3, -1};
4087
4075
int *field_num= fields_arr;
4088
4076
ST_FIELD_INFO *field_info;
4089
Name_resolution_context *context= &session->lex->select_lex.context;
4077
Name_resolution_context *context= &thd->lex->select_lex.context;
4091
4079
for (; *field_num >= 0; field_num++)
4093
4081
field_info= &schema_table->fields_info[*field_num];
4094
4082
Item_field *field= new Item_field(context,
4095
NULL, NULL, field_info->field_name);
4083
NullS, NullS, field_info->field_name);
4098
4086
field->set_name(field_info->old_name,
4099
4087
strlen(field_info->old_name),
4100
4088
system_charset_info);
4101
if (add_item_to_list(session, field))
4089
if (add_item_to_list(thd, field))
4123
int mysql_schema_table(Session *session, LEX *lex, TableList *table_list)
4111
int mysql_schema_table(THD *thd, LEX *lex, TableList *table_list)
4126
if (!(table= table_list->schema_table->create_table(session, table_list)))
4114
if (!(table= table_list->schema_table->create_table(thd, table_list)))
4128
4116
table->s->tmp_table= SYSTEM_TMP_TABLE;
4140
4128
table_list->table_name= table->s->table_name.str;
4141
4129
table_list->table_name_length= table->s->table_name.length;
4142
4130
table_list->table= table;
4143
table->next= session->derived_tables;
4144
session->derived_tables= table;
4131
table->next= thd->derived_tables;
4132
thd->derived_tables= table;
4145
4133
table_list->select_lex->options |= OPTION_SCHEMA_TABLE;
4147
4135
if (table_list->schema_table_reformed) // show command
4156
4144
for (transl= table_list->field_translation; transl < end; transl++)
4158
4146
if (!transl->item->fixed &&
4159
transl->item->fix_fields(session, &transl->item))
4147
transl->item->fix_fields(thd, &transl->item))
4164
4152
List_iterator_fast<Item> it(sel->item_list);
4166
(Field_translator*)(session->alloc(sel->item_list.elements *
4154
(Field_translator*)(thd->stmt_arena->
4155
alloc(sel->item_list.elements *
4167
4156
sizeof(Field_translator)))))
4208
4197
We have to make non const db_name & table_name
4209
4198
because of lower_case_table_names
4211
session->make_lex_string(&db, INFORMATION_SCHEMA_NAME.str,
4200
thd->make_lex_string(&db, INFORMATION_SCHEMA_NAME.str,
4212
4201
INFORMATION_SCHEMA_NAME.length, 0);
4213
session->make_lex_string(&table, schema_table->table_name,
4202
thd->make_lex_string(&table, schema_table->table_name,
4214
4203
strlen(schema_table->table_name), 0);
4215
if (schema_table->old_format(session, schema_table) || /* Handle old syntax */
4216
!sel->add_table_to_list(session, new Table_ident(session, db, table, 0),
4204
if (schema_table->old_format(thd, schema_table) || /* Handle old syntax */
4205
!sel->add_table_to_list(thd, new Table_ident(thd, db, table, 0),
4217
4206
0, 0, TL_READ))