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 */
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
17
21
/* Function with list databases, tables or fields */
18
22
#include <drizzled/server_includes.h>
19
23
#include <drizzled/sql_select.h>
20
#include <drizzled/sql_show.h>
21
#include "repl_failsafe.h"
24
#include <drizzled/show.h>
22
25
#include <mysys/my_dir.h>
23
#include <libdrizzle/gettext.h>
26
#include <drizzled/gettext.h>
27
#include <drizzled/util/convert.h>
28
#include <drizzled/error.h>
29
#include <drizzled/tztime.h>
30
#include <drizzled/data_home.h>
31
#include <drizzled/item/blob.h>
32
#include <drizzled/item/cmpfunc.h>
33
#include <drizzled/item/return_int.h>
34
#include <drizzled/item/empty_string.h>
35
#include <drizzled/item/return_date_time.h>
36
#include <drizzled/sql_base.h>
37
#include <drizzled/db.h>
38
#include <drizzled/field/timestamp.h>
39
#include <drizzled/field/decimal.h>
40
#include <drizzled/lock.h>
41
#include <drizzled/item/return_date_time.h>
42
#include <drizzled/item/empty_string.h>
43
#include "drizzled/plugin_registry.h"
54
int show_var_cmp(const void *var1, const void *var2);
25
56
inline const char *
26
57
str_or_nil(const char *str)
31
62
/* Match the values of enum ha_choice */
32
63
static const char *ha_choice_values[] = {"", "0", "1"};
34
static void store_key_options(THD *thd, String *packet, Table *table,
65
static void store_key_options(String *packet, Table *table, KEY *key_info);
67
static vector<InfoSchemaTable *> all_schema_tables;
69
Table *create_schema_table(Session *session, TableList *table_list);
70
int make_old_format(Session *session, InfoSchemaTable *schema_table);
72
void add_infoschema_table(InfoSchemaTable *schema_table)
74
if (schema_table->create_table == NULL)
75
schema_table->create_table= create_schema_table;
76
if (schema_table->old_format == NULL)
77
schema_table->old_format= make_old_format;
78
if (schema_table->idx_field1 == 0)
79
schema_table->idx_field1= -1;
80
if (schema_table->idx_field2)
81
schema_table->idx_field2= -1;
83
all_schema_tables.push_back(schema_table);
86
void remove_infoschema_table(InfoSchemaTable *table)
88
all_schema_tables.erase(remove_if(all_schema_tables.begin(),
89
all_schema_tables.end(),
90
bind2nd(equal_to<InfoSchemaTable *>(),
92
all_schema_tables.end());
39
96
int wild_case_compare(const CHARSET_INFO * const cs, const char *str,const char *wildstr)
86
143
** List all table types supported
87
144
***************************************************************************/
89
static bool show_plugins(THD *thd, plugin_ref plugin,
146
class ShowPlugins : public unary_function<st_plugin_int *, bool>
92
Table *table= (Table*) arg;
93
struct st_mysql_plugin *plug= plugin_decl(plugin);
94
struct st_plugin_dl *plugin_dl= plugin_dlib(plugin);
95
const CHARSET_INFO * const cs= system_charset_info;
97
restore_record(table, s->default_values);
99
table->field[0]->store(plugin_name(plugin)->str,
100
plugin_name(plugin)->length, cs);
104
table->field[1]->store(plug->version, strlen(plug->version), cs);
105
table->field[1]->set_notnull();
108
table->field[1]->set_null();
110
switch (plugin_state(plugin)) {
111
/* case PLUGIN_IS_FREED: does not happen */
112
case PLUGIN_IS_DELETED:
113
table->field[2]->store(STRING_WITH_LEN("DELETED"), cs);
115
case PLUGIN_IS_UNINITIALIZED:
116
table->field[2]->store(STRING_WITH_LEN("INACTIVE"), cs);
118
case PLUGIN_IS_READY:
119
table->field[2]->store(STRING_WITH_LEN("ACTIVE"), cs);
125
table->field[3]->store(plugin_type_names[plug->type].str,
126
plugin_type_names[plug->type].length,
131
table->field[4]->store(plugin_dl->dl.str, plugin_dl->dl.length, cs);
132
table->field[4]->set_notnull();
136
table->field[4]->set_null();
141
table->field[5]->store(plug->author, strlen(plug->author), cs);
151
ShowPlugins(Session *session_arg, Table *table_arg)
152
: session(session_arg), table(table_arg) {}
154
result_type operator() (argument_type plugin)
156
struct drizzled_plugin_manifest *plug= plugin_decl(plugin);
157
const CHARSET_INFO * const cs= system_charset_info;
159
table->restoreRecordAsDefault();
161
table->field[0]->store(plugin_name(plugin)->str,
162
plugin_name(plugin)->length, cs);
166
table->field[1]->store(plug->version, strlen(plug->version), cs);
167
table->field[1]->set_notnull();
170
table->field[1]->set_null();
172
if (plugin->isInited)
173
table->field[2]->store(STRING_WITH_LEN("ACTIVE"), cs);
175
table->field[2]->store(STRING_WITH_LEN("INACTIVE"), cs);
179
table->field[3]->store(plug->author, strlen(plug->author), cs);
180
table->field[3]->set_notnull();
183
table->field[3]->set_null();
187
table->field[4]->store(plug->descr, strlen(plug->descr), cs);
188
table->field[4]->set_notnull();
191
table->field[4]->set_null();
193
switch (plug->license) {
194
case PLUGIN_LICENSE_GPL:
195
table->field[5]->store(PLUGIN_LICENSE_GPL_STRING,
196
strlen(PLUGIN_LICENSE_GPL_STRING), cs);
198
case PLUGIN_LICENSE_BSD:
199
table->field[5]->store(PLUGIN_LICENSE_BSD_STRING,
200
strlen(PLUGIN_LICENSE_BSD_STRING), cs);
202
case PLUGIN_LICENSE_LGPL:
203
table->field[5]->store(PLUGIN_LICENSE_LGPL_STRING,
204
strlen(PLUGIN_LICENSE_LGPL_STRING), cs);
207
table->field[5]->store(PLUGIN_LICENSE_PROPRIETARY_STRING,
208
strlen(PLUGIN_LICENSE_PROPRIETARY_STRING), cs);
142
211
table->field[5]->set_notnull();
145
table->field[5]->set_null();
149
table->field[6]->store(plug->descr, strlen(plug->descr), cs);
150
table->field[6]->set_notnull();
153
table->field[6]->set_null();
155
switch (plug->license) {
156
case PLUGIN_LICENSE_GPL:
157
table->field[7]->store(PLUGIN_LICENSE_GPL_STRING,
158
strlen(PLUGIN_LICENSE_GPL_STRING), cs);
160
case PLUGIN_LICENSE_BSD:
161
table->field[7]->store(PLUGIN_LICENSE_BSD_STRING,
162
strlen(PLUGIN_LICENSE_BSD_STRING), cs);
165
table->field[7]->store(PLUGIN_LICENSE_PROPRIETARY_STRING,
166
strlen(PLUGIN_LICENSE_PROPRIETARY_STRING), cs);
169
table->field[7]->set_notnull();
171
return schema_table_store_record(thd, table);
175
int fill_plugins(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
213
return schema_table_store_record(session, table);
218
int fill_plugins(Session *session, TableList *tables, COND *)
177
220
Table *table= tables->table;
179
if (plugin_foreach_with_mask(thd, show_plugins, DRIZZLE_ANY_PLUGIN,
180
~PLUGIN_IS_FREED, table))
222
PluginRegistry ®istry= PluginRegistry::getPluginRegistry();
223
vector<st_plugin_int *> plugins= registry.get_list(true);
224
vector<st_plugin_int *>::iterator iter=
225
find_if(plugins.begin(), plugins.end(), ShowPlugins(session, table));
226
if (iter != plugins.end())
274
// Return only .frm files which aren't temp files.
275
if (my_strcasecmp(system_charset_info, ext=fn_rext(file->name),reg_ext) ||
276
is_prefix(file->name, tmp_file_prefix))
317
// Return only .frm files which aren't temp files.
318
if (my_strcasecmp(system_charset_info, ext=fn_rext(file->name),".dfe") ||
319
is_prefix(file->name, TMP_FILE_PREFIX))
279
322
file_name_len= filename_to_tablename(file->name, uname, sizeof(uname));
282
if (lower_case_table_names)
284
if (wild_case_compare(files_charset_info, uname, wild))
287
else if (wild_compare(uname, wild, 0))
325
if (wild_case_compare(files_charset_info, uname, wild))
292
thd->make_lex_string(file_name, uname, file_name_len, true)) ||
330
session->make_lex_string(file_name, uname, file_name_len, true)) ||
293
331
files->push_back(file_name))
306
mysqld_show_create(THD *thd, TableList *table_list)
343
bool drizzled_show_create(Session *session, TableList *table_list)
308
Protocol *protocol= thd->protocol;
345
Protocol *protocol= session->protocol;
310
347
String buffer(buff, sizeof(buff), system_charset_info);
312
349
/* Only one table for now, but VIEW can involve several tables */
313
if (open_normal_and_derived_tables(thd, table_list, 0))
350
if (open_normal_and_derived_tables(session, table_list, 0))
315
if (thd->is_error() && thd->main_da.sql_errno() != ER_VIEW_INVALID)
352
if (session->is_error())
319
356
Clear all messages with 'error' level status and
320
issue a warning with 'warning' level status in
357
issue a warning with 'warning' level status in
321
358
case of invalid view and last error is ER_VIEW_INVALID
323
drizzle_reset_errors(thd, true);
360
drizzle_reset_errors(session, true);
361
session->clear_error();
327
364
buffer.length(0);
329
if (store_create_info(thd, table_list, &buffer, NULL))
366
if (store_create_info(table_list, &buffer, NULL))
332
369
List<Item> field_list;
337
374
cmax(buffer.length(),(uint32_t)1024)));
340
if (protocol->send_fields(&field_list,
341
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
343
protocol->prepare_for_resend();
377
if (protocol->sendFields(&field_list,
378
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
382
protocol->prepareForResend();
345
384
if (table_list->schema_table)
346
protocol->store(table_list->schema_table->table_name,
347
system_charset_info);
385
protocol->store(table_list->schema_table->table_name);
349
protocol->store(table_list->table->alias, system_charset_info);
387
protocol->store(table_list->table->alias);
352
protocol->store(buffer.ptr(), buffer.length(), buffer.charset());
390
protocol->store(buffer.ptr(), buffer.length());
354
392
if (protocol->write())
361
bool mysqld_show_create_db(THD *thd, char *dbname,
399
bool mysqld_show_create_db(Session *session, char *dbname,
362
400
HA_CREATE_INFO *create_info)
365
403
String buffer(buff, sizeof(buff), system_charset_info);
366
Protocol *protocol=thd->protocol;
404
Protocol *protocol=session->protocol;
368
if (store_db_create_info(thd, dbname, &buffer, create_info))
406
if (store_db_create_info(dbname, &buffer, create_info))
371
409
This assumes that the only reason for which store_db_create_info()
372
410
can fail is incorrect database name (which is the case now).
374
412
my_error(ER_BAD_DB_ERROR, MYF(0), dbname);
378
416
List<Item> field_list;
379
417
field_list.push_back(new Item_empty_string("Database",NAME_CHAR_LEN));
380
418
field_list.push_back(new Item_empty_string("Create Database",1024));
382
if (protocol->send_fields(&field_list,
383
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
420
if (protocol->sendFields(&field_list,
421
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
386
protocol->prepare_for_resend();
387
protocol->store(dbname, strlen(dbname), system_charset_info);
388
protocol->store(buffer.ptr(), buffer.length(), buffer.charset());
424
protocol->prepareForResend();
425
protocol->store(dbname, strlen(dbname));
426
protocol->store(buffer.ptr(), buffer.length());
390
428
if (protocol->write())
414
452
Field **ptr,*field;
415
453
for (ptr=table->field ; (field= *ptr); ptr++)
417
if (!wild || !wild[0] ||
455
if (!wild || !wild[0] ||
418
456
!wild_case_compare(system_charset_info, field->field_name,wild))
420
458
field_list.push_back(new Item_field(field));
423
restore_record(table, s->default_values); // Get empty record
461
table->restoreRecordAsDefault(); // Get empty record
424
462
table->use_all_columns();
425
if (thd->protocol->send_fields(&field_list, Protocol::SEND_DEFAULTS))
433
Go through all character combinations and ensure that sql_lex.cc can
434
parse it as an identifier.
439
name_length length of name
442
# Pointer to conflicting character
443
0 No conflicting character
446
static const char *require_quotes(const char *name, uint32_t name_length)
449
bool pure_digit= true;
450
const char *end= name + name_length;
452
for (; name < end ; name++)
454
unsigned char chr= (unsigned char) *name;
455
length= my_mbcharlen(system_charset_info, chr);
456
if (length == 1 && !system_charset_info->ident_map[chr])
458
if (length == 1 && (chr < '0' || chr > '9'))
468
Quote the given identifier if needed and append it to the target string.
469
If the given identifier is empty, it will be quoted.
475
name the identifier to be appended
476
name_length length of the appending identifier
480
append_identifier(THD *thd, String *packet, const char *name, uint32_t length)
482
const char *name_end;
484
int q= get_quote_char_for_identifier(thd, name, length);
488
packet->append(name, length, packet->charset());
493
The identifier must be quoted as it includes a quote character or
497
packet->reserve(length*2 + 2);
498
quote_char= (char) q;
499
packet->append("e_char, 1, system_charset_info);
501
for (name_end= name+length ; name < name_end ; name+= length)
503
unsigned char chr= (unsigned char) *name;
504
length= my_mbcharlen(system_charset_info, chr);
506
my_mbcharlen can return 0 on a wrong multibyte
507
sequence. It is possible when upgrading from 4.0,
508
and identifier contains some accented characters.
509
The manual says it does not work. So we'll just
510
change length to 1 not to hang in the endless loop.
514
if (length == 1 && chr == (unsigned char) quote_char)
515
packet->append("e_char, 1, system_charset_info);
516
packet->append(name, length, system_charset_info);
518
packet->append("e_char, 1, system_charset_info);
463
if (session->protocol->sendFields(&field_list, Protocol::SEND_DEFAULTS))
641
575
to tailor the format of the statement. Can be
642
576
NULL, in which case only SQL_MODE is considered
643
577
when building the statement.
646
580
Currently always return 0, but might return error code in the
653
int store_create_info(THD *thd, TableList *table_list, String *packet,
654
HA_CREATE_INFO *create_info_arg)
587
int store_create_info(TableList *table_list, String *packet, HA_CREATE_INFO *create_info_arg)
656
589
List<Item> field_list;
657
char tmp[MAX_FIELD_WIDTH], *for_str, buff[128], def_value_buf[MAX_FIELD_WIDTH];
590
char tmp[MAX_FIELD_WIDTH], *for_str, def_value_buf[MAX_FIELD_WIDTH];
658
591
const char *alias;
659
593
String type(tmp, sizeof(tmp), system_charset_info);
660
594
String def_value(def_value_buf, sizeof(def_value_buf), system_charset_info);
661
595
Field **ptr,*field;
820
747
packet->append(',');
822
749
if (key_part->field)
823
append_identifier(thd,packet,key_part->field->field_name,
824
strlen(key_part->field->field_name));
750
packet->append_identifier(key_part->field->field_name,
751
strlen(key_part->field->field_name));
825
752
if (key_part->field &&
826
753
(key_part->length !=
827
754
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));
757
buff.append(to_string((int32_t) key_part->length /
758
key_part->field->charset()->mbmaxlen));
760
packet->append(buff.c_str(), buff.length());
838
763
packet->append(')');
839
store_key_options(thd, packet, table, key_info);
764
store_key_options(packet, table, key_info);
883
808
if (create_info.auto_increment_value > 1)
886
810
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));
811
buff= to_string(create_info.auto_increment_value);
812
packet->append(buff.c_str(), buff.length());
891
815
if (share->min_rows)
894
817
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));
818
buff= to_string(share->min_rows);
819
packet->append(buff.c_str(), buff.length());
899
822
if (share->max_rows && !table_list->schema_table)
902
824
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));
825
buff= to_string(share->max_rows);
826
packet->append(buff.c_str(), buff.length());
907
829
if (share->avg_row_length)
910
831
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));
832
buff= to_string(share->avg_row_length);
833
packet->append(buff.c_str(), buff.length());
915
836
if (share->db_create_options & HA_OPTION_PACK_KEYS)
922
843
if (share->page_checksum != HA_CHOICE_UNDEF)
924
845
packet->append(STRING_WITH_LEN(" PAGE_CHECKSUM="));
925
packet->append(ha_choice_values[(uint) share->page_checksum], 1);
846
packet->append(ha_choice_values[(uint32_t) share->page_checksum], 1);
927
848
if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
928
849
packet->append(STRING_WITH_LEN(" DELAY_KEY_WRITE=1"));
929
850
if (create_info.row_type != ROW_TYPE_DEFAULT)
931
852
packet->append(STRING_WITH_LEN(" ROW_FORMAT="));
932
packet->append(ha_row_type[(uint) create_info.row_type]);
934
if (share->transactional != HA_CHOICE_UNDEF)
936
packet->append(STRING_WITH_LEN(" TRANSACTIONAL="));
937
packet->append(ha_choice_values[(uint) share->transactional], 1);
853
packet->append(ha_row_type[(uint32_t) create_info.row_type]);
939
855
if (table->s->key_block_size)
942
857
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));
858
buff= to_string(table->s->key_block_size);
859
packet->append(buff.c_str(), buff.length());
946
861
if (share->block_size)
949
863
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));
864
buff= to_string(share->block_size);
865
packet->append(buff.c_str(), buff.length());
953
867
table->file->append_create_info(packet);
954
868
if (share->comment.length)
981
895
the resulting CREATE statement contains "IF NOT EXISTS" clause. Other flags
982
896
in @c create_options are ignored.
984
@param thd The current thread instance.
898
@param session The current thread instance.
985
899
@param dbname The name of the database.
986
900
@param buffer A String instance where the statement is stored.
987
@param create_info If not NULL, the options member influences the resulting
901
@param create_info If not NULL, the options member influences the resulting
990
904
@returns true if errors are detected, false otherwise.
993
bool store_db_create_info(THD *thd, const char *dbname, String *buffer,
994
HA_CREATE_INFO *create_info)
907
bool store_db_create_info(const char *dbname, String *buffer, HA_CREATE_INFO *create_info)
996
909
HA_CREATE_INFO create;
997
910
uint32_t create_options = create_info ? create_info->options : 0;
999
912
if (!my_strcasecmp(system_charset_info, dbname,
1000
INFORMATION_SCHEMA_NAME.str))
913
INFORMATION_SCHEMA_NAME.c_str()))
1002
dbname= INFORMATION_SCHEMA_NAME.str;
915
dbname= INFORMATION_SCHEMA_NAME.c_str();
1003
916
create.default_table_charset= system_charset_info;
1007
920
if (check_db_dir_existence(dbname))
1010
load_db_opt_by_name(thd, dbname, &create);
923
load_db_opt_by_name(dbname, &create);
1013
926
buffer->length(0);
1016
929
buffer->append(STRING_WITH_LEN("CREATE DATABASE "));
1018
931
if (create_options & HA_LEX_CREATE_IF_NOT_EXISTS)
1019
buffer->append(STRING_WITH_LEN("/*!32312 IF NOT EXISTS*/ "));
1021
append_identifier(thd, buffer, dbname, strlen(dbname));
1023
if (create.default_table_charset)
1025
buffer->append(STRING_WITH_LEN(" /*!40100"));
1026
buffer->append(STRING_WITH_LEN(" DEFAULT CHARACTER SET "));
1027
buffer->append(create.default_table_charset->csname);
1028
if (!(create.default_table_charset->state & MY_CS_PRIMARY))
1030
buffer->append(STRING_WITH_LEN(" COLLATE "));
1031
buffer->append(create.default_table_charset->name);
1033
buffer->append(STRING_WITH_LEN(" */"));
932
buffer->append(STRING_WITH_LEN("IF NOT EXISTS "));
934
buffer->append_identifier(dbname, strlen(dbname));
1039
static void store_key_options(THD *thd __attribute__((unused)),
1040
String *packet, Table *table,
939
static void store_key_options(String *packet, Table *table, KEY *key_info)
1043
941
char *end, buff[32];
1093
990
template class I_List<thread_info>;
1096
void mysqld_list_processes(THD *thd,const char *user, bool verbose)
993
void mysqld_list_processes(Session *session,const char *user, bool)
1099
996
List<Item> field_list;
1100
997
I_List<thread_info> thread_infos;
1101
ulong max_query_length= (verbose ? thd->variables.max_allowed_packet :
1102
PROCESS_LIST_WIDTH);
1103
Protocol *protocol= thd->protocol;
998
Protocol *protocol= session->protocol;
1105
1000
field_list.push_back(new Item_int("Id", 0, MY_INT32_NUM_DECIMAL_DIGITS));
1106
1001
field_list.push_back(new Item_empty_string("User",16));
1107
1002
field_list.push_back(new Item_empty_string("Host",LIST_PROCESS_HOST_LEN));
1108
1003
field_list.push_back(field=new Item_empty_string("db",NAME_CHAR_LEN));
1109
field->maybe_null=1;
1004
field->maybe_null= true;
1110
1005
field_list.push_back(new Item_empty_string("Command",16));
1111
1006
field_list.push_back(new Item_return_int("Time",7, DRIZZLE_TYPE_LONG));
1112
1007
field_list.push_back(field=new Item_empty_string("State",30));
1113
field->maybe_null=1;
1114
field_list.push_back(field=new Item_empty_string("Info",max_query_length));
1115
field->maybe_null=1;
1116
if (protocol->send_fields(&field_list,
1117
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
1008
field->maybe_null= true;
1009
field_list.push_back(field=new Item_empty_string("Info", PROCESS_LIST_WIDTH));
1010
field->maybe_null= true;
1011
if (protocol->sendFields(&field_list,
1012
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
1120
1015
pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
1016
if (!session->killed)
1123
I_List_iterator<THD> it(threads);
1019
for( vector<Session*>::iterator it= session_list.begin(); it != session_list.end(); ++it )
1127
Security_context *tmp_sctx= tmp->security_ctx;
1022
Security_context *tmp_sctx= &tmp->security_ctx;
1128
1023
struct st_my_thread_var *mysys_var;
1129
if ((tmp->vio_ok() || tmp->system_thread) && (!user || (tmp_sctx->user && !strcmp(tmp_sctx->user, user))))
1024
if (tmp->protocol->isConnected() && (!user || (tmp_sctx->user.c_str() && !strcmp(tmp_sctx->user.c_str(), user))))
1131
thread_info *thd_info= new thread_info;
1026
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 :
1135
(tmp->system_thread ?
1136
"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;
1028
session_info->thread_id=tmp->thread_id;
1029
session_info->user= session->strdup(tmp_sctx->user.c_str() ? tmp_sctx->user.c_str() : "unauthenticated user");
1030
session_info->host= session->strdup(tmp_sctx->ip.c_str());
1031
if ((session_info->db=tmp->db)) // Safe test
1032
session_info->db=session->strdup(session_info->db);
1033
session_info->command=(int) tmp->command;
1141
1034
if ((mysys_var= tmp->mysys_var))
1142
1035
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 ?
1145
(tmp->net.reading_or_writing == 2 ?
1147
thd_info->command == COM_SLEEP ? NULL :
1148
"Reading from net") :
1037
if (tmp->killed == Session::KILL_CONNECTION)
1038
session_info->proc_info= (char*) "Killed";
1040
session_info->proc_info= command_name[session_info->command].str;
1042
session_info->state_info= (char*) (tmp->protocol->isWriting() ?
1044
tmp->protocol->isReading() ?
1045
(session_info->command == COM_SLEEP ?
1046
NULL : "Reading from net") :
1149
1047
tmp->get_proc_info() ? tmp->get_proc_info() :
1150
1048
tmp->mysys_var &&
1151
1049
tmp->mysys_var->current_cond ?
1154
1052
pthread_mutex_unlock(&mysys_var->mutex);
1156
thd_info->start_time= tmp->start_time;
1161
query_length is always set to 0 when we set query = NULL; see
1162
the comment in sql_class.h why this prevents crashes in possible
1163
races with query_length
1165
uint32_t length= cmin((uint32_t)max_query_length, tmp->query_length);
1166
thd_info->query=(char*) thd->strmake(tmp->query,length);
1168
thread_infos.append(thd_info);
1054
session_info->start_time= tmp->start_time;
1055
session_info->query= NULL;
1056
if (tmp->process_list_info[0])
1057
session_info->query= session->strdup(tmp->process_list_info);
1058
thread_infos.append(session_info);
1172
1062
pthread_mutex_unlock(&LOCK_thread_count);
1174
thread_info *thd_info;
1175
time_t now= my_time(0);
1176
while ((thd_info=thread_infos.get()))
1064
thread_info *session_info;
1065
time_t now= time(NULL);
1066
while ((session_info=thread_infos.get()))
1178
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);
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));
1190
protocol->store_null();
1191
protocol->store(thd_info->state_info, system_charset_info);
1192
protocol->store(thd_info->query, system_charset_info);
1068
protocol->prepareForResend();
1069
protocol->store((uint64_t) session_info->thread_id);
1070
protocol->store(session_info->user);
1071
protocol->store(session_info->host);
1072
protocol->store(session_info->db);
1073
protocol->store(session_info->proc_info);
1075
if (session_info->start_time)
1076
protocol->store((uint32_t) (now - session_info->start_time));
1080
protocol->store(session_info->state_info);
1081
protocol->store(session_info->query);
1193
1083
if (protocol->write())
1194
1084
break; /* purecov: inspected */
1200
int fill_schema_processlist(THD* thd, TableList* tables,
1201
COND* cond __attribute__((unused)))
1090
int fill_schema_processlist(Session* session, TableList* tables, COND*)
1203
1092
Table *table= tables->table;
1204
1093
const CHARSET_INFO * const cs= system_charset_info;
1206
time_t now= my_time(0);
1095
time_t now= time(NULL);
1098
if (now == (time_t)-1)
1210
1103
pthread_mutex_lock(&LOCK_thread_count);
1105
if (!session->killed)
1214
I_List_iterator<THD> it(threads);
1109
for( vector<Session*>::iterator it= session_list.begin(); it != session_list.end(); ++it )
1219
Security_context *tmp_sctx= tmp->security_ctx;
1112
Security_context *tmp_sctx= &tmp->security_ctx;
1220
1113
struct st_my_thread_var *mysys_var;
1221
1114
const char *val;
1223
if ((!tmp->vio_ok() && !tmp->system_thread))
1116
if (! tmp->protocol->isConnected())
1226
restore_record(table, s->default_values);
1119
table->restoreRecordAsDefault();
1228
1121
table->field[0]->store((int64_t) tmp->thread_id, true);
1230
val= tmp_sctx->user ? tmp_sctx->user :
1231
(tmp->system_thread ? "system user" : "unauthenticated user");
1123
val= tmp_sctx->user.c_str() ? tmp_sctx->user.c_str() : "unauthenticated user";
1232
1124
table->field[1]->store(val, strlen(val), cs);
1234
table->field[2]->store(tmp_sctx->ip, strlen(tmp_sctx->ip), cs);
1126
table->field[2]->store(tmp_sctx->ip.c_str(), strlen(tmp_sctx->ip.c_str()), cs);
1294
1185
Status functions
1295
1186
*****************************************************************************/
1297
static DYNAMIC_ARRAY all_status_vars;
1188
static vector<SHOW_VAR *> all_status_vars;
1298
1189
static bool status_vars_inited= 0;
1299
static int show_var_cmp(const void *var1, const void *var2)
1190
int show_var_cmp(const void *var1, const void *var2)
1301
1192
return strcmp(((SHOW_VAR*)var1)->name, ((SHOW_VAR*)var2)->name);
1305
deletes all the SHOW_UNDEF elements from the array and calls
1306
delete_dynamic() if it's completely empty.
1308
static void shrink_var_array(DYNAMIC_ARRAY *array)
1195
class show_var_cmp_functor
1311
SHOW_VAR *all= dynamic_element(array, 0, SHOW_VAR *);
1198
show_var_cmp_functor() { }
1199
inline bool operator()(const SHOW_VAR *var1, const SHOW_VAR *var2) const
1201
int val= strcmp(var1->name, var2->name);
1313
for (a= b= 0; b < array->elements; b++)
1314
if (all[b].type != SHOW_UNDEF)
1206
class show_var_remove_if
1209
show_var_remove_if() { }
1210
inline bool operator()(const SHOW_VAR *curr) const
1318
memset(all+a, 0, sizeof(SHOW_VAR)); // writing NULL-element to the end
1212
return (curr->type == SHOW_UNDEF);
1321
else // array is completely empty - delete it
1322
delete_dynamic(array);
1326
1217
Adds an array of SHOW_VAR entries to the output of SHOW STATUS
1338
1229
As a special optimization, if add_status_vars() is called before
1339
1230
init_status_vars(), it assumes "startup mode" - neither concurrent access
1340
1231
to the array nor SHOW STATUS are possible (thus it skips locks and qsort)
1342
The last entry of the all_status_vars[] should always be {0,0,SHOW_UNDEF}
1344
1233
int add_status_vars(SHOW_VAR *list)
1347
1236
if (status_vars_inited)
1348
1237
pthread_mutex_lock(&LOCK_status);
1349
if (!all_status_vars.buffer && // array is not allocated yet - do it now
1350
my_init_dynamic_array(&all_status_vars, sizeof(SHOW_VAR), 200, 20))
1355
1238
while (list->name)
1356
res|= insert_dynamic(&all_status_vars, (unsigned char*)list++);
1357
res|= insert_dynamic(&all_status_vars, (unsigned char*)list); // appending NULL-element
1358
all_status_vars.elements--; // but next insert_dynamic should overwite it
1239
all_status_vars.insert(all_status_vars.begin(), list++);
1359
1240
if (status_vars_inited)
1360
sort_dynamic(&all_status_vars, show_var_cmp);
1241
sort(all_status_vars.begin(), all_status_vars.end(),
1242
show_var_cmp_functor());
1362
1243
if (status_vars_inited)
1363
1244
pthread_mutex_unlock(&LOCK_status);
1469
1357
*buf= my_toupper(system_charset_info, *buf);
1472
static bool show_status_array(THD *thd, const char *wild,
1360
static bool show_status_array(Session *session, const char *wild,
1473
1361
SHOW_VAR *variables,
1474
1362
enum enum_var_type value_type,
1475
1363
struct system_status_var *status_var,
1476
1364
const char *prefix, Table *table,
1477
1365
bool ucase_names)
1479
MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, long);
1367
MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
1480
1368
char * const buff= (char *) &buff_data;
1481
1369
char *prefix_end;
1482
1370
/* the variable name should not be longer than 64 characters */
1483
1371
char name_buffer[64];
1485
LEX_STRING null_lex_str;
1486
1373
SHOW_VAR tmp, *var;
1488
null_lex_str.str= 0; // For sys_var->value_ptr()
1489
null_lex_str.length= 0;
1375
prefix_end= strncpy(name_buffer, prefix, sizeof(name_buffer)-1);
1376
prefix_end+= strlen(prefix);
1491
prefix_end=my_stpncpy(name_buffer, prefix, sizeof(name_buffer)-1);
1493
1379
*prefix_end++= '_';
1494
1380
len=name_buffer + sizeof(name_buffer) - prefix_end;
1496
1382
for (; variables->name; variables++)
1498
my_stpncpy(prefix_end, variables->name, len);
1384
strncpy(prefix_end, variables->name, len);
1499
1385
name_buffer[sizeof(name_buffer)-1]=0; /* Safety */
1500
1386
if (ucase_names)
1501
1387
make_upper(name_buffer);
1556
1440
case SHOW_LONGLONG:
1557
1441
end= int64_t10_to_str(*(int64_t*) value, buff, 10);
1445
stringstream ss (stringstream::in);
1446
ss << *(size_t*) value;
1448
string str= ss.str();
1449
strncpy(buff, str.c_str(), str.length());
1450
end= buff+ str.length();
1559
1453
case SHOW_HA_ROWS:
1560
1454
end= int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
1562
1456
case SHOW_BOOL:
1563
end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1457
end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
1565
1459
case SHOW_MY_BOOL:
1566
end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1460
end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
1463
case SHOW_INT_NOFLUSH: // the difference lies in refresh_status()
1569
1464
end= int10_to_str((long) *(uint32_t*) value, buff, 10);
1571
1466
case SHOW_HAVE:
1573
SHOW_COMP_OPTION tmp= *(SHOW_COMP_OPTION*) value;
1574
pos= show_comp_option_name[(int) tmp];
1468
SHOW_COMP_OPTION tmp_option= *(SHOW_COMP_OPTION *)value;
1469
pos= show_comp_option_name[(int) tmp_option];
1575
1470
end= strchr(pos, '\0');
1672
bool schema_table_store_record(THD *thd, Table *table)
1565
bool schema_table_store_record(Session *session, Table *table)
1675
1568
if ((error= table->file->ha_write_row(table->record[0])))
1677
TMP_TABLE_PARAM *param= table->pos_in_table_list->schema_table_param;
1570
Tmp_Table_Param *param= table->pos_in_table_list->schema_table_param;
1679
if (create_myisam_from_heap(thd, table, param->start_recinfo,
1572
if (create_myisam_from_heap(session, table, param->start_recinfo,
1680
1573
¶m->recinfo, error, 0))
1687
int make_table_list(THD *thd, SELECT_LEX *sel,
1580
int make_table_list(Session *session, Select_Lex *sel,
1688
1581
LEX_STRING *db_name, LEX_STRING *table_name)
1690
1583
Table_ident *table_ident;
1691
table_ident= new Table_ident(thd, *db_name, *table_name, 1);
1584
table_ident= new Table_ident(session, *db_name, *table_name, 1);
1692
1585
sel->init_query();
1693
if (!sel->add_table_to_list(thd, table_ident, 0, 0, TL_READ))
1586
if (!sel->add_table_to_list(session, table_ident, 0, 0, TL_READ))
1700
@brief Get lookup value from the part of 'WHERE' condition
1593
@brief Get lookup value from the part of 'WHERE' condition
1702
@details This function gets lookup value from
1703
the part of 'WHERE' condition if it's possible and
1595
@details This function gets lookup value from
1596
the part of 'WHERE' condition if it's possible and
1704
1597
fill appropriate lookup_field_vals struct field
1705
1598
with this value.
1707
@param[in] thd thread handler
1600
@param[in] session thread handler
1708
1601
@param[in] item_func part of WHERE condition
1709
1602
@param[in] table I_S table
1710
@param[in, out] lookup_field_vals Struct which holds lookup values
1603
@param[in, out] lookup_field_vals Struct which holds lookup values
1714
1607
1 error, there can be no matching records for the condition
1717
bool get_lookup_value(THD *thd, Item_func *item_func,
1610
bool get_lookup_value(Session *session, Item_func *item_func,
1719
1612
LOOKUP_FIELD_VALUES *lookup_field_vals)
1721
ST_SCHEMA_TABLE *schema_table= table->schema_table;
1614
InfoSchemaTable *schema_table= table->schema_table;
1722
1615
ST_FIELD_INFO *field_info= schema_table->fields_info;
1723
1616
const char *field_name1= schema_table->idx_field1 >= 0 ?
1724
1617
field_info[schema_table->idx_field1].field_name : "";
1784
@brief Calculates lookup values from 'WHERE' condition
1677
@brief Calculates lookup values from 'WHERE' condition
1786
1679
@details This function calculates lookup value(database name, table name)
1787
from 'WHERE' condition if it's possible and
1680
from 'WHERE' condition if it's possible and
1788
1681
fill lookup_field_vals struct fields with these values.
1790
@param[in] thd thread handler
1683
@param[in] session thread handler
1791
1684
@param[in] cond WHERE condition
1792
1685
@param[in] table I_S table
1793
@param[in, out] lookup_field_vals Struct which holds lookup values
1686
@param[in, out] lookup_field_vals Struct which holds lookup values
1797
1690
1 error, there can be no matching records for the condition
1800
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TableList *table,
1693
bool calc_lookup_values_from_cond(Session *session, COND *cond, TableList *table,
1801
1694
LOOKUP_FIELD_VALUES *lookup_field_vals)
1936
1829
from LEX struct and fill lookup_field_vals struct field
1937
1830
with these values.
1939
@param[in] thd thread handler
1832
@param[in] session thread handler
1940
1833
@param[in] cond WHERE condition
1941
1834
@param[in] tables I_S table
1942
@param[in, out] lookup_field_values Struct which holds lookup values
1835
@param[in, out] lookup_field_values Struct which holds lookup values
1946
1839
1 error, there can be no matching records for the condition
1949
bool get_lookup_field_values(THD *thd, COND *cond, TableList *tables,
1842
bool get_lookup_field_values(Session *session, COND *cond, TableList *tables,
1950
1843
LOOKUP_FIELD_VALUES *lookup_field_values)
1845
LEX *lex= session->lex;
1953
1846
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1954
1847
memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1955
1848
switch (lex->sql_command) {
1889
session thread handler
1997
1890
files list of db names
1998
1891
wild wild string
1999
1892
idx_field_vals idx_field_vals->db_name contains db name or
2001
1894
with_i_schema returns 1 if we added 'IS' name to list
2009
int make_db_list(THD *thd, List<LEX_STRING> *files,
1902
int make_db_list(Session *session, List<LEX_STRING> *files,
2010
1903
LOOKUP_FIELD_VALUES *lookup_field_vals,
2011
1904
bool *with_i_schema)
2013
1906
LEX_STRING *i_s_name_copy= 0;
2014
i_s_name_copy= thd->make_lex_string(i_s_name_copy,
2015
INFORMATION_SCHEMA_NAME.str,
2016
INFORMATION_SCHEMA_NAME.length, true);
1907
i_s_name_copy= session->make_lex_string(i_s_name_copy,
1908
INFORMATION_SCHEMA_NAME.c_str(),
1909
INFORMATION_SCHEMA_NAME.length(), true);
2017
1910
*with_i_schema= 0;
2018
1911
if (lookup_field_vals->wild_db_value)
2062
1955
if (files->push_back(i_s_name_copy))
2064
1957
*with_i_schema= 1;
2065
return (find_files(thd, files, NULL,
2066
mysql_data_home, NULL, 1) != FIND_FILES_OK);
1958
return (find_files(session, files, NULL,
1959
drizzle_data_home, NULL, 1) != FIND_FILES_OK);
2070
struct st_add_schema_table
1963
struct st_add_schema_table
2072
1965
List<LEX_STRING> *files;
2073
1966
const char *wild;
2077
static bool add_schema_table(THD *thd, plugin_ref plugin,
1970
class AddSchemaTable : public unary_function<InfoSchemaTable *, bool>
2080
LEX_STRING *file_name= 0;
2081
st_add_schema_table *data= (st_add_schema_table *)p_data;
2082
List<LEX_STRING> *file_list= data->files;
2083
const char *wild= data->wild;
2084
ST_SCHEMA_TABLE *schema_table= plugin_data(plugin, ST_SCHEMA_TABLE *);
2086
if (schema_table->hidden)
1973
st_add_schema_table *data;
1975
AddSchemaTable(Session *session_arg, st_add_schema_table *data_arg)
1976
: session(session_arg), data(data_arg) {}
1977
result_type operator() (argument_type schema_table)
2090
if (lower_case_table_names)
1979
LEX_STRING *file_name= 0;
1980
List<LEX_STRING> *file_list= data->files;
1981
const char *wild= data->wild;
1983
if (schema_table->hidden)
2092
1987
if (wild_case_compare(files_charset_info,
2093
1988
schema_table->table_name,
2097
else if (wild_compare(schema_table->table_name, wild, 0))
1993
if ((file_name= session->make_lex_string(file_name, schema_table->table_name,
1994
strlen(schema_table->table_name),
1996
!file_list->push_back(file_name))
2101
if ((file_name= thd->make_lex_string(file_name, schema_table->table_name,
2102
strlen(schema_table->table_name),
2104
!file_list->push_back(file_name))
2110
int schema_tables_add(THD *thd, List<LEX_STRING> *files, const char *wild)
2003
int schema_tables_add(Session *session, List<LEX_STRING> *files, const char *wild)
2112
2005
LEX_STRING *file_name= 0;
2113
ST_SCHEMA_TABLE *tmp_schema_table= schema_tables;
2006
InfoSchemaTable *tmp_schema_table= schema_tables;
2114
2007
st_add_schema_table add_data;
2116
2009
for (; tmp_schema_table->table_name; tmp_schema_table++)
2170
make_table_name_list(THD *thd, List<LEX_STRING> *table_names, LEX *lex,
2059
make_table_name_list(Session *session, List<LEX_STRING> *table_names, LEX *lex,
2171
2060
LOOKUP_FIELD_VALUES *lookup_field_vals,
2172
2061
bool with_i_schema, LEX_STRING *db_name)
2174
2063
char path[FN_REFLEN];
2175
build_table_filename(path, sizeof(path), db_name->str, "", "", 0);
2064
build_table_filename(path, sizeof(path), db_name->str, "", false);
2176
2065
if (!lookup_field_vals->wild_table_value &&
2177
2066
lookup_field_vals->table_value.str)
2179
2068
if (with_i_schema)
2181
if (find_schema_table(thd, lookup_field_vals->table_value.str))
2070
if (find_schema_table(lookup_field_vals->table_value.str))
2183
2072
if (table_names->push_back(&lookup_field_vals->table_value))
2189
2078
if (table_names->push_back(&lookup_field_vals->table_value))
2256
2145
lex->all_selects_list= tables->schema_select_lex;
2258
Restore thd->temporary_tables to be able to process
2147
Restore session->temporary_tables to be able to process
2259
2148
temporary tables(only for 'show index' & 'show columns').
2260
2149
This should be changed when processing of temporary tables for
2261
2150
I_S tables will be done.
2263
thd->temporary_tables= open_tables_state_backup->temporary_tables;
2152
session->temporary_tables= open_tables_state_backup->temporary_tables;
2265
2154
Let us set fake sql_command so views won't try to merge
2266
2155
themselves into main statement. If we don't do this,
2267
2156
SELECT * from information_schema.xxxx will cause problems.
2268
SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
2157
SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
2270
2159
lex->sql_command= SQLCOM_SHOW_FIELDS;
2271
res= open_normal_and_derived_tables(thd, show_table_list,
2160
res= open_normal_and_derived_tables(session, show_table_list,
2272
2161
DRIZZLE_LOCK_IGNORE_FLUSH);
2273
2162
lex->sql_command= save_sql_command;
2275
2164
get_all_tables() returns 1 on failure and 0 on success thus
2276
2165
return only these and not the result code of ::process_table()
2278
We should use show_table_list->alias instead of
2167
We should use show_table_list->alias instead of
2279
2168
show_table_list->table_name because table_name
2280
2169
could be changed during opening of I_S tables. It's safe
2281
to use alias because alias contains original table name
2282
in this case(this part of code is used only for
2170
to use alias because alias contains original table name
2171
in this case(this part of code is used only for
2283
2172
'show columns' & 'show statistics' commands).
2285
table_name= thd->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2174
table_name= session->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2286
2175
strlen(show_table_list->alias), false);
2287
db_name= thd->make_lex_string(&tmp_lex_string, show_table_list->db,
2176
db_name= session->make_lex_string(&tmp_lex_string, show_table_list->db,
2288
2177
show_table_list->db_length, false);
2291
error= test(schema_table->process_table(thd, show_table_list,
2180
error= test(schema_table->process_table(session, show_table_list,
2292
2181
table, res, db_name,
2294
thd->temporary_tables= 0;
2295
close_tables_for_reopen(thd, &show_table_list);
2183
session->temporary_tables= 0;
2184
session->close_tables_for_reopen(&show_table_list);
2489
2370
List<LEX_STRING> db_names;
2490
2371
List_iterator_fast<LEX_STRING> it(db_names);
2491
2372
COND *partial_cond= 0;
2492
uint32_t derived_tables= lex->derived_tables;
2373
uint32_t derived_tables= lex->derived_tables;
2494
2375
Open_tables_state open_tables_state_backup;
2495
2376
Query_tables_list query_tables_list_backup;
2496
2377
uint32_t table_open_method;
2497
bool old_value= thd->no_warnings_for_error;
2499
lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
2378
bool old_value= session->no_warnings_for_error;
2502
2381
We should not introduce deadlocks even if we already have some
2503
2382
tables open and locked, since we won't lock tables which we will
2504
2383
open and will ignore possible name-locks for these tables.
2506
thd->reset_n_backup_open_tables_state(&open_tables_state_backup);
2385
session->reset_n_backup_open_tables_state(&open_tables_state_backup);
2508
2387
schema_table_idx= get_schema_table_idx(schema_table);
2509
2388
tables->table_open_method= table_open_method=
2510
2389
get_table_open_method(tables, schema_table, schema_table_idx);
2512
2391
this branch processes SHOW FIELDS, SHOW INDEXES commands.
2513
2392
see sql_parse.cc, prepare_schema_table() function where
2514
2393
this values are initialized
2516
2395
if (lsel && lsel->table_list.first)
2518
error= fill_schema_show_cols_or_idxs(thd, tables, schema_table,
2397
error= fill_schema_show_cols_or_idxs(session, tables, schema_table,
2519
2398
&open_tables_state_backup);
2523
if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2402
if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
2613
2492
if (!(table_open_method & ~OPEN_FRM_ONLY) &&
2614
2493
!with_i_schema)
2616
if (!fill_schema_table_from_frm(thd, tables, schema_table, db_name,
2495
if (!fill_schema_table_from_frm(session, tables, schema_table, db_name,
2617
2496
table_name, schema_table_idx))
2622
2500
LEX_STRING tmp_lex_string, orig_db_name;
2624
2502
Set the parent lex of 'sel' because it is needed by
2625
2503
sel.init_query() which is called inside make_table_list.
2627
thd->no_warnings_for_error= 1;
2505
session->no_warnings_for_error= 1;
2628
2506
sel.parent_lex= lex;
2629
2507
/* db_name can be changed in make_table_list() func */
2630
if (!thd->make_lex_string(&orig_db_name, db_name->str,
2631
db_name->length, false))
2508
if (!session->make_lex_string(&orig_db_name, db_name->str,
2509
db_name->length, false))
2633
if (make_table_list(thd, &sel, db_name, table_name))
2511
if (make_table_list(session, &sel, db_name, table_name))
2635
2513
TableList *show_table_list= (TableList*) sel.table_list.first;
2636
2514
lex->all_selects_list= &sel;
2638
2516
lex->sql_command= SQLCOM_SHOW_FIELDS;
2639
2517
show_table_list->i_s_requested_object=
2640
2518
schema_table->i_s_requested_object;
2641
res= open_normal_and_derived_tables(thd, show_table_list,
2519
res= open_normal_and_derived_tables(session, show_table_list,
2642
2520
DRIZZLE_LOCK_IGNORE_FLUSH);
2643
2521
lex->sql_command= save_sql_command;
2645
XXX: show_table_list has a flag i_is_requested,
2646
and when it's set, open_normal_and_derived_tables()
2647
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().
2523
XXX: show_table_list has a flag i_is_requested,
2524
and when it's set, open_normal_and_derived_tables()
2525
can return an error without setting an error message
2526
in Session, which is a hack. This is why we have to
2527
check for res, then for session->is_error() only then
2528
for session->main_da.sql_errno().
2652
if (res && thd->is_error() &&
2653
thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2530
if (res && session->is_error() &&
2531
session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2656
2534
Hide error for not existing table.
2659
2537
table does not exist.
2540
session->clear_error();
2667
We should use show_table_list->alias instead of
2545
We should use show_table_list->alias instead of
2668
2546
show_table_list->table_name because table_name
2669
2547
could be changed during opening of I_S tables. It's safe
2670
to use alias because alias contains original table name
2548
to use alias because alias contains original table name
2673
thd->make_lex_string(&tmp_lex_string, show_table_list->alias,
2674
strlen(show_table_list->alias), false);
2675
res= schema_table->process_table(thd, show_table_list, table,
2551
session->make_lex_string(&tmp_lex_string, show_table_list->alias,
2552
strlen(show_table_list->alias), false);
2553
res= schema_table->process_table(session, show_table_list, table,
2676
2554
res, &orig_db_name,
2677
2555
&tmp_lex_string);
2678
close_tables_for_reopen(thd, &show_table_list);
2556
session->close_tables_for_reopen(&show_table_list);
2680
2558
assert(!lex->query_tables_own_last);
2696
thd->restore_backup_open_tables_state(&open_tables_state_backup);
2697
lex->restore_backup_query_tables_list(&query_tables_list_backup);
2574
session->restore_backup_open_tables_state(&open_tables_state_backup);
2698
2575
lex->derived_tables= derived_tables;
2699
2576
lex->all_selects_list= old_all_select_lex;
2700
2577
lex->sql_command= save_sql_command;
2701
thd->no_warnings_for_error= old_value;
2578
session->no_warnings_for_error= old_value;
2706
bool store_schema_shemata(THD* thd, Table *table, LEX_STRING *db_name,
2583
bool store_schema_shemata(Session* session, Table *table, LEX_STRING *db_name,
2707
2584
const CHARSET_INFO * const cs)
2709
restore_record(table, s->default_values);
2586
table->restoreRecordAsDefault();
2710
2587
table->field[1]->store(db_name->str, db_name->length, system_charset_info);
2711
2588
table->field[2]->store(cs->csname, strlen(cs->csname), system_charset_info);
2712
2589
table->field[3]->store(cs->name, strlen(cs->name), system_charset_info);
2713
return schema_table_store_record(thd, table);
2590
return schema_table_store_record(session, table);
2717
int fill_schema_schemata(THD *thd, TableList *tables, COND *cond)
2594
int fill_schema_schemata(Session *session, TableList *tables, COND *cond)
2720
2597
TODO: fill_schema_shemata() is called when new client is connected.
2792
2670
there was errors during opening tables
2794
const char *error= thd->is_error() ? thd->main_da.message() : "";
2672
const char *error= session->is_error() ? session->main_da.message() : "";
2795
2673
if (tables->schema_table)
2796
2674
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2798
2676
table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2799
2677
table->field[20]->store(error, strlen(error), cs);
2678
session->clear_error();
2804
2682
char option_buff[400],*ptr;
2805
2683
Table *show_table= tables->table;
2806
TABLE_SHARE *share= show_table->s;
2684
TableShare *share= show_table->s;
2807
2685
handler *file= show_table->file;
2808
handlerton *tmp_db_type= share->db_type();
2686
StorageEngine *tmp_db_type= share->db_type();
2809
2687
if (share->tmp_table == SYSTEM_TMP_TABLE)
2810
2688
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2811
2689
else if (share->tmp_table)
2820
2698
table->field[i]->set_notnull();
2822
tmp_buff= (char *) ha_resolve_storage_engine_name(tmp_db_type);
2823
table->field[4]->store(tmp_buff, strlen(tmp_buff), cs);
2824
table->field[5]->store((int64_t) share->frm_version, true);
2700
string engine_name= ha_resolve_storage_engine_name(tmp_db_type);
2701
table->field[4]->store(engine_name.c_str(), engine_name.size(), cs);
2702
table->field[5]->store((int64_t) 0, true);
2826
2704
ptr=option_buff;
2827
2705
if (share->min_rows)
2829
ptr=my_stpcpy(ptr," min_rows=");
2830
ptr=int64_t10_to_str(share->min_rows,ptr,10);
2707
ptr= strcpy(ptr," min_rows=")+10;
2708
ptr= int64_t10_to_str(share->min_rows,ptr,10);
2832
2710
if (share->max_rows)
2834
ptr=my_stpcpy(ptr," max_rows=");
2835
ptr=int64_t10_to_str(share->max_rows,ptr,10);
2712
ptr= strcpy(ptr," max_rows=")+10;
2713
ptr= int64_t10_to_str(share->max_rows,ptr,10);
2837
2715
if (share->avg_row_length)
2839
ptr=my_stpcpy(ptr," avg_row_length=");
2840
ptr=int64_t10_to_str(share->avg_row_length,ptr,10);
2717
ptr= strcpy(ptr," avg_row_length=")+16;
2718
ptr= int64_t10_to_str(share->avg_row_length,ptr,10);
2842
2720
if (share->db_create_options & HA_OPTION_PACK_KEYS)
2843
ptr=my_stpcpy(ptr," pack_keys=1");
2721
ptr= strcpy(ptr," pack_keys=1")+12;
2844
2722
if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
2845
ptr=my_stpcpy(ptr," pack_keys=0");
2723
ptr= strcpy(ptr," pack_keys=0")+12;
2846
2724
/* We use CHECKSUM, instead of TABLE_CHECKSUM, for backward compability */
2847
2725
if (share->db_create_options & HA_OPTION_CHECKSUM)
2848
ptr=my_stpcpy(ptr," checksum=1");
2726
ptr= strcpy(ptr," checksum=1")+11;
2849
2727
if (share->page_checksum != HA_CHOICE_UNDEF)
2850
ptr= strxmov(ptr, " page_checksum=",
2851
ha_choice_values[(uint) share->page_checksum], NULL);
2728
ptr+= sprintf(ptr, " page_checksum=%s",
2729
ha_choice_values[(uint32_t) share->page_checksum]);
2852
2730
if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
2853
ptr=my_stpcpy(ptr," delay_key_write=1");
2731
ptr= strcpy(ptr," delay_key_write=1")+18;
2854
2732
if (share->row_type != ROW_TYPE_DEFAULT)
2855
ptr=strxmov(ptr, " row_format=",
2856
ha_row_type[(uint) share->row_type],
2733
ptr+= sprintf(ptr, " row_format=%s", ha_row_type[(uint32_t)share->row_type]);
2858
2734
if (share->block_size)
2860
ptr= my_stpcpy(ptr, " block_size=");
2736
ptr= strcpy(ptr, " block_size=")+12;
2861
2737
ptr= int64_t10_to_str(share->block_size, ptr, 10);
2864
if (share->transactional != HA_CHOICE_UNDEF)
2866
ptr= strxmov(ptr, " TRANSACTIONAL=",
2867
(share->transactional == HA_CHOICE_YES ? "1" : "0"),
2870
if (share->transactional != HA_CHOICE_UNDEF)
2871
ptr= strxmov(ptr, " transactional=",
2872
ha_choice_values[(uint) share->transactional], NULL);
2873
2740
table->field[19]->store(option_buff+1,
2874
(ptr == option_buff ? 0 :
2875
(uint) (ptr-option_buff)-1), cs);
2741
(ptr == option_buff ? 0 :
2742
(uint32_t) (ptr-option_buff)-1), cs);
2877
2744
tmp_buff= (share->table_charset ?
2878
2745
share->table_charset->name : "default");
2937
2804
if (file->stats.create_time)
2939
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2940
(my_time_t) file->stats.create_time);
2806
session->variables.time_zone->gmt_sec_to_TIME(&time,
2807
(time_t) file->stats.create_time);
2941
2808
table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2942
2809
table->field[14]->set_notnull();
2944
2811
if (file->stats.update_time)
2946
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2947
(my_time_t) file->stats.update_time);
2813
session->variables.time_zone->gmt_sec_to_TIME(&time,
2814
(time_t) file->stats.update_time);
2948
2815
table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2949
2816
table->field[15]->set_notnull();
2951
2818
if (file->stats.check_time)
2953
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2954
(my_time_t) file->stats.check_time);
2820
session->variables.time_zone->gmt_sec_to_TIME(&time,
2821
(time_t) file->stats.check_time);
2955
2822
table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2956
2823
table->field[16]->set_notnull();
3201
int fill_schema_charsets(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3066
int fill_schema_charsets(Session *session, TableList *tables, COND *)
3203
3068
CHARSET_INFO **cs;
3204
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3069
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3205
3070
Table *table= tables->table;
3206
3071
const CHARSET_INFO * const scs= system_charset_info;
3208
3073
for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
3210
3075
const CHARSET_INFO * const tmp_cs= cs[0];
3211
if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) &&
3076
if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) &&
3212
3077
(tmp_cs->state & MY_CS_AVAILABLE) &&
3213
3078
!(tmp_cs->state & MY_CS_HIDDEN) &&
3214
3079
!(wild && wild[0] &&
3215
3080
wild_case_compare(scs, tmp_cs->csname,wild)))
3217
3082
const char *comment;
3218
restore_record(table, s->default_values);
3083
table->restoreRecordAsDefault();
3219
3084
table->field[0]->store(tmp_cs->csname, strlen(tmp_cs->csname), scs);
3220
3085
table->field[1]->store(tmp_cs->name, strlen(tmp_cs->name), scs);
3221
3086
comment= tmp_cs->comment ? tmp_cs->comment : "";
3222
3087
table->field[2]->store(comment, strlen(comment), scs);
3223
3088
table->field[3]->store((int64_t) tmp_cs->mbmaxlen, true);
3224
if (schema_table_store_record(thd, table))
3089
if (schema_table_store_record(session, table))
3281
3146
CHARSET_INFO **cl;
3282
3147
const CHARSET_INFO *tmp_cs= cs[0];
3283
if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3148
if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3284
3149
!(tmp_cs->state & MY_CS_PRIMARY))
3286
3151
for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3288
3153
const CHARSET_INFO *tmp_cl= cl[0];
3289
if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3154
if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3290
3155
!my_charset_same(tmp_cs,tmp_cl))
3292
restore_record(table, s->default_values);
3157
table->restoreRecordAsDefault();
3293
3158
table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3294
3159
table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3295
if (schema_table_store_record(thd, table))
3160
if (schema_table_store_record(session, table))
3378
3243
uint32_t flags= key_part->field ? key_part->field->flags : 0;
3379
3244
const char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES");
3380
3245
table->field[12]->store(pos, strlen(pos), cs);
3381
if (!show_table->s->keys_in_use.is_set(i))
3246
if (!show_table->s->keys_in_use.test(i))
3382
3247
table->field[14]->store(STRING_WITH_LEN("disabled"), cs);
3384
3249
table->field[14]->store("", 0, cs);
3385
3250
table->field[14]->set_notnull();
3386
assert(test(key_info->flags & HA_USES_COMMENT) ==
3251
assert(test(key_info->flags & HA_USES_COMMENT) ==
3387
3252
(key_info->comment.length > 0));
3388
3253
if (key_info->flags & HA_USES_COMMENT)
3389
table->field[15]->store(key_info->comment.str,
3254
table->field[15]->store(key_info->comment.str,
3390
3255
key_info->comment.length, cs);
3391
if (schema_table_store_record(thd, table))
3256
if (schema_table_store_record(session, table))
3400
bool store_constraints(THD *thd, Table *table, LEX_STRING *db_name,
3265
bool store_constraints(Session *session, Table *table, LEX_STRING *db_name,
3401
3266
LEX_STRING *table_name, const char *key_name,
3402
3267
uint32_t key_len, const char *con_type, uint32_t con_len)
3404
3269
const CHARSET_INFO * const cs= system_charset_info;
3405
restore_record(table, s->default_values);
3270
table->restoreRecordAsDefault();
3406
3271
table->field[1]->store(db_name->str, db_name->length, cs);
3407
3272
table->field[2]->store(key_name, key_len, cs);
3408
3273
table->field[3]->store(db_name->str, db_name->length, cs);
3409
3274
table->field[4]->store(table_name->str, table_name->length, cs);
3410
3275
table->field[5]->store(con_type, con_len, cs);
3411
return schema_table_store_record(thd, table);
3276
return schema_table_store_record(session, table);
3415
static int get_schema_constraints_record(THD *thd, TableList *tables,
3280
static int get_schema_constraints_record(Session *session, TableList *tables,
3416
3281
Table *table, bool res,
3417
3282
LEX_STRING *db_name,
3418
3283
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());
3287
if (session->is_error())
3288
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3289
session->main_da.sql_errno(), session->main_da.message());
3290
session->clear_error();
3439
3304
if (i != primary_key && !(key_info->flags & HA_NOSAME))
3442
if (i == primary_key && !strcmp(key_info->name, primary_key_name))
3307
if (i == primary_key && is_primary_key(key_info))
3444
if (store_constraints(thd, table, db_name, table_name, key_info->name,
3309
if (store_constraints(session, table, db_name, table_name, key_info->name,
3445
3310
strlen(key_info->name),
3446
3311
STRING_WITH_LEN("PRIMARY KEY")))
3449
3314
else if (key_info->flags & HA_NOSAME)
3451
if (store_constraints(thd, table, db_name, table_name, key_info->name,
3316
if (store_constraints(session, table, db_name, table_name, key_info->name,
3452
3317
strlen(key_info->name),
3453
3318
STRING_WITH_LEN("UNIQUE")))
3458
show_table->file->get_foreign_key_list(thd, &f_key_list);
3323
show_table->file->get_foreign_key_list(session, &f_key_list);
3459
3324
FOREIGN_KEY_INFO *f_key_info;
3460
3325
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3461
3326
while ((f_key_info=it++))
3463
if (store_constraints(thd, table, db_name, table_name,
3328
if (store_constraints(session, table, db_name, table_name,
3464
3329
f_key_info->forein_id->str,
3465
3330
strlen(f_key_info->forein_id->str),
3466
3331
"FOREIGN KEY", 11))
3520
3385
if (key_part->field)
3523
restore_record(table, s->default_values);
3388
table->restoreRecordAsDefault();
3524
3389
store_key_column_usage(table, db_name, table_name,
3525
3390
key_info->name,
3526
strlen(key_info->name),
3527
key_part->field->field_name,
3391
strlen(key_info->name),
3392
key_part->field->field_name,
3528
3393
strlen(key_part->field->field_name),
3529
3394
(int64_t) f_idx);
3530
if (schema_table_store_record(thd, table))
3395
if (schema_table_store_record(session, table))
3536
show_table->file->get_foreign_key_list(thd, &f_key_list);
3401
show_table->file->get_foreign_key_list(session, &f_key_list);
3537
3402
FOREIGN_KEY_INFO *f_key_info;
3538
3403
List_iterator_fast<FOREIGN_KEY_INFO> fkey_it(f_key_list);
3539
3404
while ((f_key_info= fkey_it++))
3578
int fill_open_tables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3443
int fill_open_tables(Session *session, TableList *tables, COND *)
3580
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3445
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3581
3446
Table *table= tables->table;
3582
3447
const CHARSET_INFO * const cs= system_charset_info;
3583
3448
OPEN_TableList *open_list;
3584
if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3585
&& thd->is_fatal_error)
3449
if (!(open_list=list_open_tables(session->lex->select_lex.db, wild))
3450
&& session->is_fatal_error)
3588
3453
for (; open_list ; open_list=open_list->next)
3590
restore_record(table, s->default_values);
3455
table->restoreRecordAsDefault();
3591
3456
table->field[0]->store(open_list->db, strlen(open_list->db), cs);
3592
3457
table->field[1]->store(open_list->table, strlen(open_list->table), cs);
3593
3458
table->field[2]->store((int64_t) open_list->in_use, true);
3594
3459
table->field[3]->store((int64_t) open_list->locked, true);
3595
if (schema_table_store_record(thd, table))
3460
if (schema_table_store_record(session, table))
3602
int fill_variables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3467
int fill_variables(Session *session, TableList *tables, COND *)
3470
LEX *lex= session->lex;
3606
3471
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3607
3472
enum enum_schema_tables schema_table_idx=
3608
3473
get_schema_table_idx(tables->schema_table);
3614
3479
schema_table_idx == SCH_GLOBAL_VARIABLES)
3615
3480
option_type= OPT_GLOBAL;
3617
rw_rdlock(&LOCK_system_variables_hash);
3618
res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars),
3482
pthread_rwlock_rdlock(&LOCK_system_variables_hash);
3483
res= show_status_array(session, wild, enumerate_sys_vars(session, sorted_vars),
3619
3484
option_type, NULL, "", tables->table, upper_case_names);
3620
rw_unlock(&LOCK_system_variables_hash);
3485
pthread_rwlock_unlock(&LOCK_system_variables_hash);
3625
int fill_status(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3490
int fill_status(Session *session, TableList *tables, COND *)
3492
LEX *lex= session->lex;
3628
3493
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3630
3495
STATUS_VAR *tmp1, tmp;
3694
if (thd->is_error())
3695
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3696
thd->main_da.sql_errno(), thd->main_da.message());
3559
if (session->is_error())
3560
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3561
session->main_da.sql_errno(), session->main_da.message());
3562
session->clear_error();
3702
3567
List<FOREIGN_KEY_INFO> f_key_list;
3703
3568
Table *show_table= tables->table;
3704
show_table->file->info(HA_STATUS_VARIABLE |
3569
show_table->file->info(HA_STATUS_VARIABLE |
3705
3570
HA_STATUS_NO_LOCK |
3706
3571
HA_STATUS_TIME);
3708
show_table->file->get_foreign_key_list(thd, &f_key_list);
3573
show_table->file->get_foreign_key_list(session, &f_key_list);
3709
3574
FOREIGN_KEY_INFO *f_key_info;
3710
3575
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3711
3576
while ((f_key_info= it++))
3713
restore_record(table, s->default_values);
3578
table->restoreRecordAsDefault();
3714
3579
table->field[1]->store(db_name->str, db_name->length, cs);
3715
3580
table->field[9]->store(table_name->str, table_name->length, cs);
3716
3581
table->field[2]->store(f_key_info->forein_id->str,
3717
3582
f_key_info->forein_id->length, cs);
3718
table->field[4]->store(f_key_info->referenced_db->str,
3583
table->field[4]->store(f_key_info->referenced_db->str,
3719
3584
f_key_info->referenced_db->length, cs);
3720
table->field[10]->store(f_key_info->referenced_table->str,
3585
table->field[10]->store(f_key_info->referenced_table->str,
3721
3586
f_key_info->referenced_table->length, cs);
3722
3587
if (f_key_info->referenced_key_name)
3724
table->field[5]->store(f_key_info->referenced_key_name->str,
3589
table->field[5]->store(f_key_info->referenced_key_name->str,
3725
3590
f_key_info->referenced_key_name->length, cs);
3726
3591
table->field[5]->set_notnull();
3729
3594
table->field[5]->set_null();
3730
3595
table->field[6]->store(STRING_WITH_LEN("NONE"), cs);
3731
table->field[7]->store(f_key_info->update_method->str,
3596
table->field[7]->store(f_key_info->update_method->str,
3732
3597
f_key_info->update_method->length, cs);
3733
table->field[8]->store(f_key_info->delete_method->str,
3598
table->field[8]->store(f_key_info->delete_method->str,
3734
3599
f_key_info->delete_method->length, cs);
3735
if (schema_table_store_record(thd, table))
3600
if (schema_table_store_record(session, table))
3910
3747
item->maybe_null= (fields_info->field_flags & MY_I_S_MAYBE_NULL);
3913
TMP_TABLE_PARAM *tmp_table_param =
3914
(TMP_TABLE_PARAM*) (thd->alloc(sizeof(TMP_TABLE_PARAM)));
3750
Tmp_Table_Param *tmp_table_param =
3751
(Tmp_Table_Param*) (session->alloc(sizeof(Tmp_Table_Param)));
3915
3752
tmp_table_param->init();
3916
3753
tmp_table_param->table_charset= cs;
3917
3754
tmp_table_param->field_count= field_count;
3918
3755
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,
3921
field_list, (order_st*) 0, 0, 0,
3922
(select_lex->options | thd->options |
3756
Select_Lex *select_lex= session->lex->current_select;
3757
if (!(table= create_tmp_table(session, tmp_table_param,
3758
field_list, (order_st*) 0, 0, 0,
3759
(select_lex->options | session->options |
3923
3760
TMP_TABLE_ALL_COLUMNS),
3924
3761
HA_POS_ERROR, table_list->alias)))
3926
3763
my_bitmap_map* bitmaps=
3927
(my_bitmap_map*) thd->alloc(bitmap_buffer_size(field_count));
3928
bitmap_init(&table->def_read_set, (my_bitmap_map*) bitmaps, field_count,
3764
(my_bitmap_map*) session->alloc(bitmap_buffer_size(field_count));
3765
bitmap_init(&table->def_read_set, (my_bitmap_map*) bitmaps, field_count);
3930
3766
table->read_set= &table->def_read_set;
3931
3767
bitmap_clear_all(table->read_set);
3932
3768
table_list->schema_table_param= tmp_table_param;
4022
3858
Item_field *field= new Item_field(context,
4023
3859
NULL, NULL, field_info->field_name);
4024
if (add_item_to_list(thd, field))
3860
if (session->add_item_to_list(field))
4026
3862
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4027
if (thd->lex->verbose)
3863
if (session->lex->verbose)
4029
3865
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4030
3866
field_info= &schema_table->fields_info[3];
4031
3867
field= new Item_field(context, NULL, NULL, field_info->field_name);
4032
if (add_item_to_list(thd, field))
3868
if (session->add_item_to_list(field))
4034
3870
field->set_name(field_info->old_name, strlen(field_info->old_name),
4035
3871
system_charset_info);
4126
3961
table_list->table_name= table->s->table_name.str;
4127
3962
table_list->table_name_length= table->s->table_name.length;
4128
3963
table_list->table= table;
4129
table->next= thd->derived_tables;
4130
thd->derived_tables= table;
3964
table->next= session->derived_tables;
3965
session->derived_tables= table;
4131
3966
table_list->select_lex->options |= OPTION_SCHEMA_TABLE;
4133
if (table_list->schema_table_reformed) // show command
4135
SELECT_LEX *sel= lex->current_select;
4137
Field_translator *transl, *org_transl;
4139
if (table_list->field_translation)
4141
Field_translator *end= table_list->field_translation_end;
4142
for (transl= table_list->field_translation; transl < end; transl++)
4144
if (!transl->item->fixed &&
4145
transl->item->fix_fields(thd, &transl->item))
4150
List_iterator_fast<Item> it(sel->item_list);
4152
(Field_translator*)(thd->alloc(sel->item_list.elements *
4153
sizeof(Field_translator)))))
4157
for (org_transl= transl; (item= it++); transl++)
4160
transl->name= item->name;
4161
if (!item->fixed && item->fix_fields(thd, &transl->item))
4166
table_list->field_translation= org_transl;
4167
table_list->field_translation_end= transl;
4178
3976
make_schema_select()
4180
sel pointer to SELECT_LEX
3977
session thread handler
3978
sel pointer to Select_Lex
4181
3979
schema_table_idx index of 'schema_tables' element
4188
int make_schema_select(THD *thd, SELECT_LEX *sel,
4189
enum enum_schema_tables schema_table_idx)
3985
bool make_schema_select(Session *session, Select_Lex *sel,
3986
enum enum_schema_tables schema_table_idx)
4191
ST_SCHEMA_TABLE *schema_table= get_schema_table(schema_table_idx);
3988
InfoSchemaTable *schema_table= get_schema_table(schema_table_idx);
4192
3989
LEX_STRING db, table;
4194
3991
We have to make non const db_name & table_name
4195
3992
because of lower_case_table_names
4197
thd->make_lex_string(&db, INFORMATION_SCHEMA_NAME.str,
4198
INFORMATION_SCHEMA_NAME.length, 0);
4199
thd->make_lex_string(&table, schema_table->table_name,
3994
session->make_lex_string(&db, INFORMATION_SCHEMA_NAME.c_str(),
3995
INFORMATION_SCHEMA_NAME.length(), 0);
3996
session->make_lex_string(&table, schema_table->table_name,
4200
3997
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),
3998
if (schema_table->old_format(session, schema_table) || /* Handle old syntax */
3999
!sel->add_table_to_list(session, new Table_ident(session, db, table, 0),
4203
4000
0, 0, TL_READ))
4320
4117
{"ROW_FORMAT", 10, DRIZZLE_TYPE_VARCHAR, 0, 1, "Row_format", OPEN_FULL_TABLE},
4321
4118
{"TABLE_ROWS", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4322
4119
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Rows", OPEN_FULL_TABLE},
4323
{"AVG_ROW_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4120
{"AVG_ROW_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4324
4121
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Avg_row_length", OPEN_FULL_TABLE},
4325
{"DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4122
{"DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4326
4123
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Data_length", OPEN_FULL_TABLE},
4327
4124
{"MAX_DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4328
4125
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Max_data_length", OPEN_FULL_TABLE},
4329
{"INDEX_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4126
{"INDEX_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4330
4127
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Index_length", OPEN_FULL_TABLE},
4331
4128
{"DATA_FREE", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4332
4129
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Data_free", OPEN_FULL_TABLE},
4333
{"AUTO_INCREMENT", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG, 0,
4130
{"AUTO_INCREMENT", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG, 0,
4334
4131
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Auto_increment", OPEN_FULL_TABLE},
4335
4132
{"CREATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Create_time", OPEN_FULL_TABLE},
4336
4133
{"UPDATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Update_time", OPEN_FULL_TABLE},
4530
4327
ST_FIELD_INFO plugin_fields_info[]=
4532
{"PLUGIN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name",
4329
{"PLUGIN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name",
4533
4330
SKIP_OPEN_TABLE},
4534
4331
{"PLUGIN_VERSION", 20, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4535
4332
{"PLUGIN_STATUS", 10, DRIZZLE_TYPE_VARCHAR, 0, 0, "Status", SKIP_OPEN_TABLE},
4536
{"PLUGIN_TYPE", 80, DRIZZLE_TYPE_VARCHAR, 0, 0, "Type", SKIP_OPEN_TABLE},
4537
{"PLUGIN_LIBRARY", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, "Library",
4539
4333
{"PLUGIN_AUTHOR", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4540
4334
{"PLUGIN_DESCRIPTION", 65535, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4541
4335
{"PLUGIN_LICENSE", 80, DRIZZLE_TYPE_VARCHAR, 0, 1, "License", SKIP_OPEN_TABLE},
4575
ST_SCHEMA_TABLE schema_tables[]=
4369
InfoSchemaTable schema_tables[]=
4577
{"CHARACTER_SETS", charsets_fields_info, create_schema_table,
4371
{"CHARACTER_SETS", charsets_fields_info, create_schema_table,
4578
4372
fill_schema_charsets, make_character_sets_old_format, 0, -1, -1, 0, 0},
4579
{"COLLATIONS", collation_fields_info, create_schema_table,
4373
{"COLLATIONS", collation_fields_info, create_schema_table,
4580
4374
fill_schema_collation, make_old_format, 0, -1, -1, 0, 0},
4581
4375
{"COLLATION_CHARACTER_SET_APPLICABILITY", coll_charset_app_fields_info,
4582
4376
create_schema_table, fill_schema_coll_charset_app, 0, 0, -1, -1, 0, 0},
4583
{"COLUMNS", columns_fields_info, create_schema_table,
4377
{"COLUMNS", columns_fields_info, create_schema_table,
4584
4378
get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2, 0,
4585
4379
OPTIMIZE_I_S_TABLE},
4586
4380
{"GLOBAL_STATUS", variables_fields_info, create_schema_table,
4605
4399
fill_status, make_old_format, 0, -1, -1, 0, 0},
4606
4400
{"SESSION_VARIABLES", variables_fields_info, create_schema_table,
4607
4401
fill_variables, make_old_format, 0, -1, -1, 0, 0},
4608
{"STATISTICS", stat_fields_info, create_schema_table,
4402
{"STATISTICS", stat_fields_info, create_schema_table,
4609
4403
get_all_tables, make_old_format, get_schema_stat_record, 1, 2, 0,
4610
4404
OPEN_TABLE_ONLY|OPTIMIZE_I_S_TABLE},
4611
{"STATUS", variables_fields_info, create_schema_table, fill_status,
4405
{"STATUS", variables_fields_info, create_schema_table, fill_status,
4612
4406
make_old_format, 0, -1, -1, 1, 0},
4613
{"TABLES", tables_fields_info, create_schema_table,
4407
{"TABLES", tables_fields_info, create_schema_table,
4614
4408
get_all_tables, make_old_format, get_schema_tables_record, 1, 2, 0,
4615
4409
OPTIMIZE_I_S_TABLE},
4616
4410
{"TABLE_CONSTRAINTS", table_constraints_fields_info, create_schema_table,
4622
4416
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
4626
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
4627
template class List_iterator_fast<char>;
4628
template class List<char>;
4631
int initialize_schema_table(st_plugin_int *plugin)
4633
ST_SCHEMA_TABLE *schema_table;
4635
if (!(schema_table= (ST_SCHEMA_TABLE *)my_malloc(sizeof(ST_SCHEMA_TABLE),
4636
MYF(MY_WME | MY_ZEROFILL))))
4638
/* Historical Requirement */
4639
plugin->data= schema_table; // shortcut for the future
4640
if (plugin->plugin->init)
4642
schema_table->create_table= create_schema_table;
4643
schema_table->old_format= make_old_format;
4644
schema_table->idx_field1= -1,
4645
schema_table->idx_field2= -1;
4647
/* Make the name available to the init() function. */
4648
schema_table->table_name= plugin->name.str;
4650
if (plugin->plugin->init(schema_table))
4652
sql_print_error(_("Plugin '%s' init function returned error."),
4657
/* Make sure the plugin name is not set inside the init() function. */
4658
schema_table->table_name= plugin->name.str;
4667
int finalize_schema_table(st_plugin_int *plugin)
4669
ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data;
4671
if (schema_table && plugin->plugin->deinit)