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(Session *session, String *packet, Table *table,
68
static vector<InfoSchemaTable *> all_schema_tables;
70
Table *create_schema_table(Session *session, TableList *table_list);
71
int make_old_format(Session *session, InfoSchemaTable *schema_table);
73
void add_infoschema_table(InfoSchemaTable *schema_table)
75
if (schema_table->create_table == NULL)
76
schema_table->create_table= create_schema_table;
77
if (schema_table->old_format == NULL)
78
schema_table->old_format= make_old_format;
79
if (schema_table->idx_field1 == 0)
80
schema_table->idx_field1= -1;
81
if (schema_table->idx_field2)
82
schema_table->idx_field2= -1;
84
all_schema_tables.push_back(schema_table);
87
void remove_infoschema_table(InfoSchemaTable *table)
89
all_schema_tables.erase(remove_if(all_schema_tables.begin(),
90
all_schema_tables.end(),
91
bind2nd(equal_to<InfoSchemaTable *>(),
93
all_schema_tables.end());
39
97
int wild_case_compare(const CHARSET_INFO * const cs, const char *str,const char *wildstr)
86
144
** List all table types supported
87
145
***************************************************************************/
89
static bool show_plugins(THD *thd, plugin_ref plugin,
147
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);
152
ShowPlugins(Session *session_arg, Table *table_arg)
153
: session(session_arg), table(table_arg) {}
155
result_type operator() (argument_type plugin)
157
struct drizzled_plugin_manifest *plug= plugin_decl(plugin);
158
const CHARSET_INFO * const cs= system_charset_info;
160
table->restoreRecordAsDefault();
162
table->field[0]->store(plugin_name(plugin)->str,
163
plugin_name(plugin)->length, cs);
167
table->field[1]->store(plug->version, strlen(plug->version), cs);
168
table->field[1]->set_notnull();
171
table->field[1]->set_null();
173
if (plugin->isInited)
174
table->field[2]->store(STRING_WITH_LEN("ACTIVE"), cs);
176
table->field[2]->store(STRING_WITH_LEN("INACTIVE"), cs);
180
table->field[3]->store(plug->author, strlen(plug->author), cs);
181
table->field[3]->set_notnull();
184
table->field[3]->set_null();
188
table->field[4]->store(plug->descr, strlen(plug->descr), cs);
189
table->field[4]->set_notnull();
192
table->field[4]->set_null();
194
switch (plug->license) {
195
case PLUGIN_LICENSE_GPL:
196
table->field[5]->store(PLUGIN_LICENSE_GPL_STRING,
197
strlen(PLUGIN_LICENSE_GPL_STRING), cs);
199
case PLUGIN_LICENSE_BSD:
200
table->field[5]->store(PLUGIN_LICENSE_BSD_STRING,
201
strlen(PLUGIN_LICENSE_BSD_STRING), cs);
203
case PLUGIN_LICENSE_LGPL:
204
table->field[5]->store(PLUGIN_LICENSE_LGPL_STRING,
205
strlen(PLUGIN_LICENSE_LGPL_STRING), cs);
208
table->field[5]->store(PLUGIN_LICENSE_PROPRIETARY_STRING,
209
strlen(PLUGIN_LICENSE_PROPRIETARY_STRING), cs);
142
212
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)))
214
return schema_table_store_record(session, table);
219
int fill_plugins(Session *session, TableList *tables, COND *)
177
221
Table *table= tables->table;
179
if (plugin_foreach_with_mask(thd, show_plugins, DRIZZLE_ANY_PLUGIN,
180
~PLUGIN_IS_FREED, table))
223
PluginRegistry ®istry= PluginRegistry::getPluginRegistry();
224
vector<st_plugin_int *> plugins= registry.get_list(true);
225
vector<st_plugin_int *>::iterator iter=
226
find_if(plugins.begin(), plugins.end(), ShowPlugins(session, table));
227
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))
320
// Return only .frm files which aren't temp files.
321
if (my_strcasecmp(system_charset_info, ext=fn_rext(file->name),".dfe") ||
322
is_prefix(file->name, TMP_FILE_PREFIX))
279
325
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))
328
if (lower_case_table_names)
330
if (wild_case_compare(files_charset_info, uname, wild))
333
else if (wild_compare(uname, wild, 0))
292
thd->make_lex_string(file_name, uname, file_name_len, true)) ||
338
session->make_lex_string(file_name, uname, file_name_len, true)) ||
293
339
files->push_back(file_name))
306
mysqld_show_create(THD *thd, TableList *table_list)
351
bool drizzled_show_create(Session *session, TableList *table_list)
308
Protocol *protocol= thd->protocol;
353
Protocol *protocol= session->protocol;
310
355
String buffer(buff, sizeof(buff), system_charset_info);
312
357
/* Only one table for now, but VIEW can involve several tables */
313
if (open_normal_and_derived_tables(thd, table_list, 0))
358
if (open_normal_and_derived_tables(session, table_list, 0))
315
if (thd->is_error() && thd->main_da.sql_errno() != ER_VIEW_INVALID)
360
if (session->is_error())
319
364
Clear all messages with 'error' level status and
320
issue a warning with 'warning' level status in
365
issue a warning with 'warning' level status in
321
366
case of invalid view and last error is ER_VIEW_INVALID
323
drizzle_reset_errors(thd, true);
368
drizzle_reset_errors(session, true);
369
session->clear_error();
327
372
buffer.length(0);
329
if (store_create_info(thd, table_list, &buffer, NULL))
374
if (store_create_info(session, table_list, &buffer, NULL))
332
377
List<Item> field_list;
354
401
if (protocol->write())
361
bool mysqld_show_create_db(THD *thd, char *dbname,
408
bool mysqld_show_create_db(Session *session, char *dbname,
362
409
HA_CREATE_INFO *create_info)
365
412
String buffer(buff, sizeof(buff), system_charset_info);
366
Protocol *protocol=thd->protocol;
413
Protocol *protocol=session->protocol;
368
if (store_db_create_info(thd, dbname, &buffer, create_info))
415
if (store_db_create_info(session, dbname, &buffer, create_info))
371
418
This assumes that the only reason for which store_db_create_info()
372
419
can fail is incorrect database name (which is the case now).
374
421
my_error(ER_BAD_DB_ERROR, MYF(0), dbname);
378
425
List<Item> field_list;
379
426
field_list.push_back(new Item_empty_string("Database",NAME_CHAR_LEN));
380
427
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))
429
if (protocol->sendFields(&field_list,
430
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
386
protocol->prepare_for_resend();
433
protocol->prepareForResend();
387
434
protocol->store(dbname, strlen(dbname), system_charset_info);
388
435
protocol->store(buffer.ptr(), buffer.length(), buffer.charset());
390
437
if (protocol->write())
414
461
Field **ptr,*field;
415
462
for (ptr=table->field ; (field= *ptr); ptr++)
417
if (!wild || !wild[0] ||
464
if (!wild || !wild[0] ||
418
465
!wild_case_compare(system_charset_info, field->field_name,wild))
420
467
field_list.push_back(new Item_field(field));
423
restore_record(table, s->default_values); // Get empty record
470
table->restoreRecordAsDefault(); // Get empty record
424
471
table->use_all_columns();
425
if (thd->protocol->send_fields(&field_list, Protocol::SEND_DEFAULTS))
472
if (session->protocol->sendFields(&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);
523
480
Get the quote character for displaying an identifier.
526
483
get_quote_char_for_identifier()
484
session Thread handler
528
485
name name to quote
529
486
length length of name
641
591
to tailor the format of the statement. Can be
642
592
NULL, in which case only SQL_MODE is considered
643
593
when building the statement.
646
596
Currently always return 0, but might return error code in the
653
int store_create_info(THD *thd, TableList *table_list, String *packet,
603
int store_create_info(Session *session, TableList *table_list, String *packet,
654
604
HA_CREATE_INFO *create_info_arg)
656
606
List<Item> field_list;
657
char tmp[MAX_FIELD_WIDTH], *for_str, buff[128], def_value_buf[MAX_FIELD_WIDTH];
607
char tmp[MAX_FIELD_WIDTH], *for_str, def_value_buf[MAX_FIELD_WIDTH];
658
608
const char *alias;
659
610
String type(tmp, sizeof(tmp), system_charset_info);
660
611
String def_value(def_value_buf, sizeof(def_value_buf), system_charset_info);
661
612
Field **ptr,*field;
820
769
packet->append(',');
822
771
if (key_part->field)
823
append_identifier(thd,packet,key_part->field->field_name,
824
strlen(key_part->field->field_name));
772
packet->append_identifier(key_part->field->field_name,
773
strlen(key_part->field->field_name));
825
774
if (key_part->field &&
826
775
(key_part->length !=
827
776
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));
779
buff= to_string(buff, (int32_t) key_part->length /
780
key_part->field->charset()->mbmaxlen);
782
packet->append(buff.c_str(), buff.length());
838
785
packet->append(')');
839
store_key_options(thd, packet, table, key_info);
786
store_key_options(session, packet, table, key_info);
883
830
if (create_info.auto_increment_value > 1)
886
832
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));
833
buff= to_string(create_info.auto_increment_value);
834
packet->append(buff.c_str(), buff.length());
891
837
if (share->min_rows)
894
839
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));
840
buff= to_string(share->min_rows);
841
packet->append(buff.c_str(), buff.length());
899
844
if (share->max_rows && !table_list->schema_table)
902
846
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));
847
buff= to_string(share->max_rows);
848
packet->append(buff.c_str(), buff.length());
907
851
if (share->avg_row_length)
910
853
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));
854
buff= to_string(share->avg_row_length);
855
packet->append(buff.c_str(), buff.length());
915
858
if (share->db_create_options & HA_OPTION_PACK_KEYS)
922
865
if (share->page_checksum != HA_CHOICE_UNDEF)
924
867
packet->append(STRING_WITH_LEN(" PAGE_CHECKSUM="));
925
packet->append(ha_choice_values[(uint) share->page_checksum], 1);
868
packet->append(ha_choice_values[(uint32_t) share->page_checksum], 1);
927
870
if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
928
871
packet->append(STRING_WITH_LEN(" DELAY_KEY_WRITE=1"));
929
872
if (create_info.row_type != ROW_TYPE_DEFAULT)
931
874
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);
875
packet->append(ha_row_type[(uint32_t) create_info.row_type]);
939
877
if (table->s->key_block_size)
942
879
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));
880
buff= to_string(table->s->key_block_size);
881
packet->append(buff.c_str(), buff.length());
946
883
if (share->block_size)
949
885
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));
886
buff= to_string(share->block_size);
887
packet->append(buff.c_str(), buff.length());
953
889
table->file->append_create_info(packet);
954
890
if (share->comment.length)
981
917
the resulting CREATE statement contains "IF NOT EXISTS" clause. Other flags
982
918
in @c create_options are ignored.
984
@param thd The current thread instance.
920
@param session The current thread instance.
985
921
@param dbname The name of the database.
986
922
@param buffer A String instance where the statement is stored.
987
@param create_info If not NULL, the options member influences the resulting
923
@param create_info If not NULL, the options member influences the resulting
990
926
@returns true if errors are detected, false otherwise.
993
bool store_db_create_info(THD *thd, const char *dbname, String *buffer,
929
bool store_db_create_info(Session *session, const char *dbname, String *buffer,
994
930
HA_CREATE_INFO *create_info)
996
932
HA_CREATE_INFO create;
997
933
uint32_t create_options = create_info ? create_info->options : 0;
999
935
if (!my_strcasecmp(system_charset_info, dbname,
1000
INFORMATION_SCHEMA_NAME.str))
936
INFORMATION_SCHEMA_NAME.c_str()))
1002
dbname= INFORMATION_SCHEMA_NAME.str;
938
dbname= INFORMATION_SCHEMA_NAME.c_str();
1003
939
create.default_table_charset= system_charset_info;
1016
952
buffer->append(STRING_WITH_LEN("CREATE DATABASE "));
1018
954
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(" */"));
955
buffer->append(STRING_WITH_LEN("IF NOT EXISTS "));
957
buffer->append_identifier(dbname, strlen(dbname));
1039
static void store_key_options(THD *thd __attribute__((unused)),
962
static void store_key_options(Session *,
1040
963
String *packet, Table *table,
1093
1015
template class I_List<thread_info>;
1096
void mysqld_list_processes(THD *thd,const char *user, bool verbose)
1018
void mysqld_list_processes(Session *session,const char *user, bool)
1099
1021
List<Item> field_list;
1100
1022
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;
1023
Protocol *protocol= session->protocol;
1105
1025
field_list.push_back(new Item_int("Id", 0, MY_INT32_NUM_DECIMAL_DIGITS));
1106
1026
field_list.push_back(new Item_empty_string("User",16));
1107
1027
field_list.push_back(new Item_empty_string("Host",LIST_PROCESS_HOST_LEN));
1108
1028
field_list.push_back(field=new Item_empty_string("db",NAME_CHAR_LEN));
1109
field->maybe_null=1;
1029
field->maybe_null= true;
1110
1030
field_list.push_back(new Item_empty_string("Command",16));
1111
1031
field_list.push_back(new Item_return_int("Time",7, DRIZZLE_TYPE_LONG));
1112
1032
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))
1033
field->maybe_null= true;
1034
field_list.push_back(field=new Item_empty_string("Info", PROCESS_LIST_WIDTH));
1035
field->maybe_null= true;
1036
if (protocol->sendFields(&field_list,
1037
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
1120
1040
pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
1041
if (!session->killed)
1123
I_List_iterator<THD> it(threads);
1043
I_List_iterator<Session> it(session_list);
1127
Security_context *tmp_sctx= tmp->security_ctx;
1047
Security_context *tmp_sctx= &tmp->security_ctx;
1128
1048
struct st_my_thread_var *mysys_var;
1129
if ((tmp->vio_ok() || tmp->system_thread) && (!user || (tmp_sctx->user && !strcmp(tmp_sctx->user, user))))
1049
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;
1051
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;
1053
session_info->thread_id=tmp->thread_id;
1054
session_info->user= session->strdup(tmp_sctx->user.c_str() ? tmp_sctx->user.c_str() : "unauthenticated user");
1055
session_info->host= session->strdup(tmp_sctx->ip.c_str());
1056
if ((session_info->db=tmp->db)) // Safe test
1057
session_info->db=session->strdup(session_info->db);
1058
session_info->command=(int) tmp->command;
1141
1059
if ((mysys_var= tmp->mysys_var))
1142
1060
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") :
1062
if (tmp->killed == Session::KILL_CONNECTION)
1063
session_info->proc_info= (char*) "Killed";
1065
session_info->proc_info= command_name[session_info->command].str;
1067
session_info->state_info= (char*) (tmp->protocol->isWriting() ?
1069
tmp->protocol->isReading() ?
1070
(session_info->command == COM_SLEEP ?
1071
NULL : "Reading from net") :
1149
1072
tmp->get_proc_info() ? tmp->get_proc_info() :
1150
1073
tmp->mysys_var &&
1151
1074
tmp->mysys_var->current_cond ?
1154
1077
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);
1079
session_info->start_time= tmp->start_time;
1080
session_info->query= NULL;
1081
if (tmp->process_list_info[0])
1082
session_info->query= session->strdup(tmp->process_list_info);
1083
thread_infos.append(session_info);
1172
1087
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()))
1089
thread_info *session_info;
1090
time_t now= time(NULL);
1091
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);
1093
protocol->prepareForResend();
1094
protocol->store((uint64_t) session_info->thread_id);
1095
protocol->store(session_info->user, system_charset_info);
1096
protocol->store(session_info->host, system_charset_info);
1097
protocol->store(session_info->db, system_charset_info);
1098
protocol->store(session_info->proc_info, system_charset_info);
1100
if (session_info->start_time)
1101
protocol->store((uint32_t) (now - session_info->start_time));
1105
protocol->store(session_info->state_info, system_charset_info);
1106
protocol->store(session_info->query, system_charset_info);
1193
1108
if (protocol->write())
1194
1109
break; /* purecov: inspected */
1200
int fill_schema_processlist(THD* thd, TableList* tables,
1201
COND* cond __attribute__((unused)))
1115
int fill_schema_processlist(Session* session, TableList* tables, COND*)
1203
1117
Table *table= tables->table;
1204
1118
const CHARSET_INFO * const cs= system_charset_info;
1206
time_t now= my_time(0);
1120
time_t now= time(NULL);
1123
if (now == (time_t)-1)
1210
1128
pthread_mutex_lock(&LOCK_thread_count);
1130
if (!session->killed)
1214
I_List_iterator<THD> it(threads);
1132
I_List_iterator<Session> it(session_list);
1217
1135
while ((tmp= it++))
1219
Security_context *tmp_sctx= tmp->security_ctx;
1137
Security_context *tmp_sctx= &tmp->security_ctx;
1220
1138
struct st_my_thread_var *mysys_var;
1221
1139
const char *val;
1223
if ((!tmp->vio_ok() && !tmp->system_thread))
1141
if (! tmp->protocol->isConnected())
1226
restore_record(table, s->default_values);
1144
table->restoreRecordAsDefault();
1228
1146
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");
1148
val= tmp_sctx->user.c_str() ? tmp_sctx->user.c_str() : "unauthenticated user";
1232
1149
table->field[1]->store(val, strlen(val), cs);
1234
table->field[2]->store(tmp_sctx->ip, strlen(tmp_sctx->ip), cs);
1151
table->field[2]->store(tmp_sctx->ip.c_str(), strlen(tmp_sctx->ip.c_str()), cs);
1294
1210
Status functions
1295
1211
*****************************************************************************/
1297
static DYNAMIC_ARRAY all_status_vars;
1213
static vector<SHOW_VAR *> all_status_vars;
1298
1214
static bool status_vars_inited= 0;
1299
static int show_var_cmp(const void *var1, const void *var2)
1215
int show_var_cmp(const void *var1, const void *var2)
1301
1217
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)
1220
class show_var_cmp_functor
1311
SHOW_VAR *all= dynamic_element(array, 0, SHOW_VAR *);
1223
show_var_cmp_functor() { }
1224
inline bool operator()(const SHOW_VAR *var1, const SHOW_VAR *var2) const
1226
int val= strcmp(var1->name, var2->name);
1313
for (a= b= 0; b < array->elements; b++)
1314
if (all[b].type != SHOW_UNDEF)
1231
class show_var_remove_if
1234
show_var_remove_if() { }
1235
inline bool operator()(const SHOW_VAR *curr) const
1318
memset(all+a, 0, sizeof(SHOW_VAR)); // writing NULL-element to the end
1237
return (curr->type == SHOW_UNDEF);
1321
else // array is completely empty - delete it
1322
delete_dynamic(array);
1326
1242
Adds an array of SHOW_VAR entries to the output of SHOW STATUS
1338
1254
As a special optimization, if add_status_vars() is called before
1339
1255
init_status_vars(), it assumes "startup mode" - neither concurrent access
1340
1256
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
1258
int add_status_vars(SHOW_VAR *list)
1347
1261
if (status_vars_inited)
1348
1262
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
1263
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
1264
all_status_vars.insert(all_status_vars.begin(), list++);
1359
1265
if (status_vars_inited)
1360
sort_dynamic(&all_status_vars, show_var_cmp);
1266
sort(all_status_vars.begin(), all_status_vars.end(),
1267
show_var_cmp_functor());
1362
1268
if (status_vars_inited)
1363
1269
pthread_mutex_unlock(&LOCK_status);
1469
1382
*buf= my_toupper(system_charset_info, *buf);
1472
static bool show_status_array(THD *thd, const char *wild,
1385
static bool show_status_array(Session *session, const char *wild,
1473
1386
SHOW_VAR *variables,
1474
1387
enum enum_var_type value_type,
1475
1388
struct system_status_var *status_var,
1476
1389
const char *prefix, Table *table,
1477
1390
bool ucase_names)
1479
MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, long);
1392
MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
1480
1393
char * const buff= (char *) &buff_data;
1481
1394
char *prefix_end;
1482
1395
/* the variable name should not be longer than 64 characters */
1483
1396
char name_buffer[64];
1485
LEX_STRING null_lex_str;
1486
1398
SHOW_VAR tmp, *var;
1488
null_lex_str.str= 0; // For sys_var->value_ptr()
1489
null_lex_str.length= 0;
1400
prefix_end= strncpy(name_buffer, prefix, sizeof(name_buffer)-1);
1401
prefix_end+= strlen(prefix);
1491
prefix_end=my_stpncpy(name_buffer, prefix, sizeof(name_buffer)-1);
1493
1404
*prefix_end++= '_';
1494
1405
len=name_buffer + sizeof(name_buffer) - prefix_end;
1496
1407
for (; variables->name; variables++)
1498
my_stpncpy(prefix_end, variables->name, len);
1409
strncpy(prefix_end, variables->name, len);
1499
1410
name_buffer[sizeof(name_buffer)-1]=0; /* Safety */
1500
1411
if (ucase_names)
1501
1412
make_upper(name_buffer);
1556
1465
case SHOW_LONGLONG:
1557
1466
end= int64_t10_to_str(*(int64_t*) value, buff, 10);
1470
stringstream ss (stringstream::in);
1471
ss << *(size_t*) value;
1473
string str= ss.str();
1474
strncpy(buff, str.c_str(), str.length());
1475
end= buff+ str.length();
1559
1478
case SHOW_HA_ROWS:
1560
1479
end= int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
1562
1481
case SHOW_BOOL:
1563
end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1482
end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
1565
1484
case SHOW_MY_BOOL:
1566
end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1485
end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
1488
case SHOW_INT_NOFLUSH: // the difference lies in refresh_status()
1569
1489
end= int10_to_str((long) *(uint32_t*) value, buff, 10);
1571
1491
case SHOW_HAVE:
1573
SHOW_COMP_OPTION tmp= *(SHOW_COMP_OPTION*) value;
1574
pos= show_comp_option_name[(int) tmp];
1493
SHOW_COMP_OPTION tmp_option= *(SHOW_COMP_OPTION *)value;
1494
pos= show_comp_option_name[(int) tmp_option];
1575
1495
end= strchr(pos, '\0');
1687
int make_table_list(THD *thd, SELECT_LEX *sel,
1607
int make_table_list(Session *session, Select_Lex *sel,
1688
1608
LEX_STRING *db_name, LEX_STRING *table_name)
1690
1610
Table_ident *table_ident;
1691
table_ident= new Table_ident(thd, *db_name, *table_name, 1);
1611
table_ident= new Table_ident(session, *db_name, *table_name, 1);
1692
1612
sel->init_query();
1693
if (!sel->add_table_to_list(thd, table_ident, 0, 0, TL_READ))
1613
if (!sel->add_table_to_list(session, table_ident, 0, 0, TL_READ))
1700
@brief Get lookup value from the part of 'WHERE' condition
1620
@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
1622
@details This function gets lookup value from
1623
the part of 'WHERE' condition if it's possible and
1704
1624
fill appropriate lookup_field_vals struct field
1705
1625
with this value.
1707
@param[in] thd thread handler
1627
@param[in] session thread handler
1708
1628
@param[in] item_func part of WHERE condition
1709
1629
@param[in] table I_S table
1710
@param[in, out] lookup_field_vals Struct which holds lookup values
1630
@param[in, out] lookup_field_vals Struct which holds lookup values
1714
1634
1 error, there can be no matching records for the condition
1717
bool get_lookup_value(THD *thd, Item_func *item_func,
1637
bool get_lookup_value(Session *session, Item_func *item_func,
1719
1639
LOOKUP_FIELD_VALUES *lookup_field_vals)
1721
ST_SCHEMA_TABLE *schema_table= table->schema_table;
1641
InfoSchemaTable *schema_table= table->schema_table;
1722
1642
ST_FIELD_INFO *field_info= schema_table->fields_info;
1723
1643
const char *field_name1= schema_table->idx_field1 >= 0 ?
1724
1644
field_info[schema_table->idx_field1].field_name : "";
1784
@brief Calculates lookup values from 'WHERE' condition
1704
@brief Calculates lookup values from 'WHERE' condition
1786
1706
@details This function calculates lookup value(database name, table name)
1787
from 'WHERE' condition if it's possible and
1707
from 'WHERE' condition if it's possible and
1788
1708
fill lookup_field_vals struct fields with these values.
1790
@param[in] thd thread handler
1710
@param[in] session thread handler
1791
1711
@param[in] cond WHERE condition
1792
1712
@param[in] table I_S table
1793
@param[in, out] lookup_field_vals Struct which holds lookup values
1713
@param[in, out] lookup_field_vals Struct which holds lookup values
1797
1717
1 error, there can be no matching records for the condition
1800
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TableList *table,
1720
bool calc_lookup_values_from_cond(Session *session, COND *cond, TableList *table,
1801
1721
LOOKUP_FIELD_VALUES *lookup_field_vals)
1936
1856
from LEX struct and fill lookup_field_vals struct field
1937
1857
with these values.
1939
@param[in] thd thread handler
1859
@param[in] session thread handler
1940
1860
@param[in] cond WHERE condition
1941
1861
@param[in] tables I_S table
1942
@param[in, out] lookup_field_values Struct which holds lookup values
1862
@param[in, out] lookup_field_values Struct which holds lookup values
1946
1866
1 error, there can be no matching records for the condition
1949
bool get_lookup_field_values(THD *thd, COND *cond, TableList *tables,
1869
bool get_lookup_field_values(Session *session, COND *cond, TableList *tables,
1950
1870
LOOKUP_FIELD_VALUES *lookup_field_values)
1872
LEX *lex= session->lex;
1953
1873
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1954
1874
memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1955
1875
switch (lex->sql_command) {
1916
session thread handler
1997
1917
files list of db names
1998
1918
wild wild string
1999
1919
idx_field_vals idx_field_vals->db_name contains db name or
2001
1921
with_i_schema returns 1 if we added 'IS' name to list
2009
int make_db_list(THD *thd, List<LEX_STRING> *files,
1929
int make_db_list(Session *session, List<LEX_STRING> *files,
2010
1930
LOOKUP_FIELD_VALUES *lookup_field_vals,
2011
1931
bool *with_i_schema)
2013
1933
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);
1934
i_s_name_copy= session->make_lex_string(i_s_name_copy,
1935
INFORMATION_SCHEMA_NAME.c_str(),
1936
INFORMATION_SCHEMA_NAME.length(), true);
2017
1937
*with_i_schema= 0;
2018
1938
if (lookup_field_vals->wild_db_value)
2062
1982
if (files->push_back(i_s_name_copy))
2064
1984
*with_i_schema= 1;
2065
return (find_files(thd, files, NULL,
2066
mysql_data_home, NULL, 1) != FIND_FILES_OK);
1985
return (find_files(session, files, NULL,
1986
drizzle_data_home, NULL, 1) != FIND_FILES_OK);
2070
struct st_add_schema_table
1990
struct st_add_schema_table
2072
1992
List<LEX_STRING> *files;
2073
1993
const char *wild;
2077
static bool add_schema_table(THD *thd, plugin_ref plugin,
1997
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)
2000
st_add_schema_table *data;
2002
AddSchemaTable(Session *session_arg, st_add_schema_table *data_arg)
2003
: session(session_arg), data(data_arg) {}
2004
result_type operator() (argument_type schema_table)
2090
if (lower_case_table_names)
2006
LEX_STRING *file_name= 0;
2007
List<LEX_STRING> *file_list= data->files;
2008
const char *wild= data->wild;
2010
if (schema_table->hidden)
2092
if (wild_case_compare(files_charset_info,
2093
schema_table->table_name,
2014
if (lower_case_table_names)
2016
if (wild_case_compare(files_charset_info,
2017
schema_table->table_name,
2021
else if (wild_compare(schema_table->table_name, wild, 0))
2097
else if (wild_compare(schema_table->table_name, wild, 0))
2025
if ((file_name= session->make_lex_string(file_name, schema_table->table_name,
2026
strlen(schema_table->table_name),
2028
!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)
2035
int schema_tables_add(Session *session, List<LEX_STRING> *files, const char *wild)
2112
2037
LEX_STRING *file_name= 0;
2113
ST_SCHEMA_TABLE *tmp_schema_table= schema_tables;
2038
InfoSchemaTable *tmp_schema_table= schema_tables;
2114
2039
st_add_schema_table add_data;
2116
2041
for (; tmp_schema_table->table_name; tmp_schema_table++)
2256
2182
lex->all_selects_list= tables->schema_select_lex;
2258
Restore thd->temporary_tables to be able to process
2184
Restore session->temporary_tables to be able to process
2259
2185
temporary tables(only for 'show index' & 'show columns').
2260
2186
This should be changed when processing of temporary tables for
2261
2187
I_S tables will be done.
2263
thd->temporary_tables= open_tables_state_backup->temporary_tables;
2189
session->temporary_tables= open_tables_state_backup->temporary_tables;
2265
2191
Let us set fake sql_command so views won't try to merge
2266
2192
themselves into main statement. If we don't do this,
2267
2193
SELECT * from information_schema.xxxx will cause problems.
2268
SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
2194
SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
2270
2196
lex->sql_command= SQLCOM_SHOW_FIELDS;
2271
res= open_normal_and_derived_tables(thd, show_table_list,
2197
res= open_normal_and_derived_tables(session, show_table_list,
2272
2198
DRIZZLE_LOCK_IGNORE_FLUSH);
2273
2199
lex->sql_command= save_sql_command;
2275
2201
get_all_tables() returns 1 on failure and 0 on success thus
2276
2202
return only these and not the result code of ::process_table()
2278
We should use show_table_list->alias instead of
2204
We should use show_table_list->alias instead of
2279
2205
show_table_list->table_name because table_name
2280
2206
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
2207
to use alias because alias contains original table name
2208
in this case(this part of code is used only for
2283
2209
'show columns' & 'show statistics' commands).
2285
table_name= thd->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2211
table_name= session->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2286
2212
strlen(show_table_list->alias), false);
2287
db_name= thd->make_lex_string(&tmp_lex_string, show_table_list->db,
2213
db_name= session->make_lex_string(&tmp_lex_string, show_table_list->db,
2288
2214
show_table_list->db_length, false);
2291
error= test(schema_table->process_table(thd, show_table_list,
2217
error= test(schema_table->process_table(session, show_table_list,
2292
2218
table, res, db_name,
2294
thd->temporary_tables= 0;
2295
close_tables_for_reopen(thd, &show_table_list);
2220
session->temporary_tables= 0;
2221
close_tables_for_reopen(session, &show_table_list);
2489
2407
List<LEX_STRING> db_names;
2490
2408
List_iterator_fast<LEX_STRING> it(db_names);
2491
2409
COND *partial_cond= 0;
2492
uint32_t derived_tables= lex->derived_tables;
2410
uint32_t derived_tables= lex->derived_tables;
2494
2412
Open_tables_state open_tables_state_backup;
2495
2413
Query_tables_list query_tables_list_backup;
2496
2414
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);
2415
bool old_value= session->no_warnings_for_error;
2502
2418
We should not introduce deadlocks even if we already have some
2503
2419
tables open and locked, since we won't lock tables which we will
2504
2420
open and will ignore possible name-locks for these tables.
2506
thd->reset_n_backup_open_tables_state(&open_tables_state_backup);
2422
session->reset_n_backup_open_tables_state(&open_tables_state_backup);
2508
2424
schema_table_idx= get_schema_table_idx(schema_table);
2509
2425
tables->table_open_method= table_open_method=
2510
2426
get_table_open_method(tables, schema_table, schema_table_idx);
2512
2428
this branch processes SHOW FIELDS, SHOW INDEXES commands.
2513
2429
see sql_parse.cc, prepare_schema_table() function where
2514
2430
this values are initialized
2516
2432
if (lsel && lsel->table_list.first)
2518
error= fill_schema_show_cols_or_idxs(thd, tables, schema_table,
2434
error= fill_schema_show_cols_or_idxs(session, tables, schema_table,
2519
2435
&open_tables_state_backup);
2523
if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2439
if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
2613
2529
if (!(table_open_method & ~OPEN_FRM_ONLY) &&
2614
2530
!with_i_schema)
2616
if (!fill_schema_table_from_frm(thd, tables, schema_table, db_name,
2532
if (!fill_schema_table_from_frm(session, tables, schema_table, db_name,
2617
2533
table_name, schema_table_idx))
2622
2537
LEX_STRING tmp_lex_string, orig_db_name;
2624
2539
Set the parent lex of 'sel' because it is needed by
2625
2540
sel.init_query() which is called inside make_table_list.
2627
thd->no_warnings_for_error= 1;
2542
session->no_warnings_for_error= 1;
2628
2543
sel.parent_lex= lex;
2629
2544
/* 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))
2545
if (!session->make_lex_string(&orig_db_name, db_name->str,
2546
db_name->length, false))
2633
if (make_table_list(thd, &sel, db_name, table_name))
2548
if (make_table_list(session, &sel, db_name, table_name))
2635
2550
TableList *show_table_list= (TableList*) sel.table_list.first;
2636
2551
lex->all_selects_list= &sel;
2638
2553
lex->sql_command= SQLCOM_SHOW_FIELDS;
2639
2554
show_table_list->i_s_requested_object=
2640
2555
schema_table->i_s_requested_object;
2641
res= open_normal_and_derived_tables(thd, show_table_list,
2556
res= open_normal_and_derived_tables(session, show_table_list,
2642
2557
DRIZZLE_LOCK_IGNORE_FLUSH);
2643
2558
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().
2560
XXX: show_table_list has a flag i_is_requested,
2561
and when it's set, open_normal_and_derived_tables()
2562
can return an error without setting an error message
2563
in Session, which is a hack. This is why we have to
2564
check for res, then for session->is_error() only then
2565
for session->main_da.sql_errno().
2652
if (res && thd->is_error() &&
2653
thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2567
if (res && session->is_error() &&
2568
session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2656
2571
Hide error for not existing table.
2659
2574
table does not exist.
2577
session->clear_error();
2667
We should use show_table_list->alias instead of
2582
We should use show_table_list->alias instead of
2668
2583
show_table_list->table_name because table_name
2669
2584
could be changed during opening of I_S tables. It's safe
2670
to use alias because alias contains original table name
2585
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,
2588
session->make_lex_string(&tmp_lex_string, show_table_list->alias,
2589
strlen(show_table_list->alias), false);
2590
res= schema_table->process_table(session, show_table_list, table,
2676
2591
res, &orig_db_name,
2677
2592
&tmp_lex_string);
2678
close_tables_for_reopen(thd, &show_table_list);
2593
close_tables_for_reopen(session, &show_table_list);
2680
2595
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);
2611
session->restore_backup_open_tables_state(&open_tables_state_backup);
2698
2612
lex->derived_tables= derived_tables;
2699
2613
lex->all_selects_list= old_all_select_lex;
2700
2614
lex->sql_command= save_sql_command;
2701
thd->no_warnings_for_error= old_value;
2615
session->no_warnings_for_error= old_value;
2706
bool store_schema_shemata(THD* thd, Table *table, LEX_STRING *db_name,
2620
bool store_schema_shemata(Session* session, Table *table, LEX_STRING *db_name,
2707
2621
const CHARSET_INFO * const cs)
2709
restore_record(table, s->default_values);
2623
table->restoreRecordAsDefault();
2710
2624
table->field[1]->store(db_name->str, db_name->length, system_charset_info);
2711
2625
table->field[2]->store(cs->csname, strlen(cs->csname), system_charset_info);
2712
2626
table->field[3]->store(cs->name, strlen(cs->name), system_charset_info);
2713
return schema_table_store_record(thd, table);
2627
return schema_table_store_record(session, table);
2717
int fill_schema_schemata(THD *thd, TableList *tables, COND *cond)
2631
int fill_schema_schemata(Session *session, TableList *tables, COND *cond)
2720
2634
TODO: fill_schema_shemata() is called when new client is connected.
2792
2707
there was errors during opening tables
2794
const char *error= thd->is_error() ? thd->main_da.message() : "";
2709
const char *error= session->is_error() ? session->main_da.message() : "";
2795
2710
if (tables->schema_table)
2796
2711
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2798
2713
table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2799
2714
table->field[20]->store(error, strlen(error), cs);
2715
session->clear_error();
2804
2719
char option_buff[400],*ptr;
2805
2720
Table *show_table= tables->table;
2806
TABLE_SHARE *share= show_table->s;
2721
TableShare *share= show_table->s;
2807
2722
handler *file= show_table->file;
2808
handlerton *tmp_db_type= share->db_type();
2723
StorageEngine *tmp_db_type= share->db_type();
2809
2724
if (share->tmp_table == SYSTEM_TMP_TABLE)
2810
2725
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2811
2726
else if (share->tmp_table)
2820
2735
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);
2737
string engine_name= ha_resolve_storage_engine_name(tmp_db_type);
2738
table->field[4]->store(engine_name.c_str(), engine_name.size(), cs);
2739
table->field[5]->store((int64_t) 0, true);
2826
2741
ptr=option_buff;
2827
2742
if (share->min_rows)
2829
ptr=my_stpcpy(ptr," min_rows=");
2830
ptr=int64_t10_to_str(share->min_rows,ptr,10);
2744
ptr= strcpy(ptr," min_rows=")+10;
2745
ptr= int64_t10_to_str(share->min_rows,ptr,10);
2832
2747
if (share->max_rows)
2834
ptr=my_stpcpy(ptr," max_rows=");
2835
ptr=int64_t10_to_str(share->max_rows,ptr,10);
2749
ptr= strcpy(ptr," max_rows=")+10;
2750
ptr= int64_t10_to_str(share->max_rows,ptr,10);
2837
2752
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);
2754
ptr= strcpy(ptr," avg_row_length=")+16;
2755
ptr= int64_t10_to_str(share->avg_row_length,ptr,10);
2842
2757
if (share->db_create_options & HA_OPTION_PACK_KEYS)
2843
ptr=my_stpcpy(ptr," pack_keys=1");
2758
ptr= strcpy(ptr," pack_keys=1")+12;
2844
2759
if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
2845
ptr=my_stpcpy(ptr," pack_keys=0");
2760
ptr= strcpy(ptr," pack_keys=0")+12;
2846
2761
/* We use CHECKSUM, instead of TABLE_CHECKSUM, for backward compability */
2847
2762
if (share->db_create_options & HA_OPTION_CHECKSUM)
2848
ptr=my_stpcpy(ptr," checksum=1");
2763
ptr= strcpy(ptr," checksum=1")+11;
2849
2764
if (share->page_checksum != HA_CHOICE_UNDEF)
2850
ptr= strxmov(ptr, " page_checksum=",
2851
ha_choice_values[(uint) share->page_checksum], NULL);
2765
ptr+= sprintf(ptr, " page_checksum=%s",
2766
ha_choice_values[(uint32_t) share->page_checksum]);
2852
2767
if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
2853
ptr=my_stpcpy(ptr," delay_key_write=1");
2768
ptr= strcpy(ptr," delay_key_write=1")+18;
2854
2769
if (share->row_type != ROW_TYPE_DEFAULT)
2855
ptr=strxmov(ptr, " row_format=",
2856
ha_row_type[(uint) share->row_type],
2770
ptr+= sprintf(ptr, " row_format=%s", ha_row_type[(uint32_t)share->row_type]);
2858
2771
if (share->block_size)
2860
ptr= my_stpcpy(ptr, " block_size=");
2773
ptr= strcpy(ptr, " block_size=")+12;
2861
2774
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
2777
table->field[19]->store(option_buff+1,
2874
(ptr == option_buff ? 0 :
2875
(uint) (ptr-option_buff)-1), cs);
2778
(ptr == option_buff ? 0 :
2779
(uint32_t) (ptr-option_buff)-1), cs);
2877
2781
tmp_buff= (share->table_charset ?
2878
2782
share->table_charset->name : "default");
2937
2841
if (file->stats.create_time)
2939
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2940
(my_time_t) file->stats.create_time);
2843
session->variables.time_zone->gmt_sec_to_TIME(&time,
2844
(time_t) file->stats.create_time);
2941
2845
table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2942
2846
table->field[14]->set_notnull();
2944
2848
if (file->stats.update_time)
2946
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2947
(my_time_t) file->stats.update_time);
2850
session->variables.time_zone->gmt_sec_to_TIME(&time,
2851
(time_t) file->stats.update_time);
2948
2852
table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2949
2853
table->field[15]->set_notnull();
2951
2855
if (file->stats.check_time)
2953
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2954
(my_time_t) file->stats.check_time);
2857
session->variables.time_zone->gmt_sec_to_TIME(&time,
2858
(time_t) file->stats.check_time);
2955
2859
table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2956
2860
table->field[16]->set_notnull();
3201
int fill_schema_charsets(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3103
int fill_schema_charsets(Session *session, TableList *tables, COND *)
3203
3105
CHARSET_INFO **cs;
3204
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3106
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3205
3107
Table *table= tables->table;
3206
3108
const CHARSET_INFO * const scs= system_charset_info;
3208
3110
for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
3210
3112
const CHARSET_INFO * const tmp_cs= cs[0];
3211
if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) &&
3113
if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) &&
3212
3114
(tmp_cs->state & MY_CS_AVAILABLE) &&
3213
3115
!(tmp_cs->state & MY_CS_HIDDEN) &&
3214
3116
!(wild && wild[0] &&
3215
3117
wild_case_compare(scs, tmp_cs->csname,wild)))
3217
3119
const char *comment;
3218
restore_record(table, s->default_values);
3120
table->restoreRecordAsDefault();
3219
3121
table->field[0]->store(tmp_cs->csname, strlen(tmp_cs->csname), scs);
3220
3122
table->field[1]->store(tmp_cs->name, strlen(tmp_cs->name), scs);
3221
3123
comment= tmp_cs->comment ? tmp_cs->comment : "";
3222
3124
table->field[2]->store(comment, strlen(comment), scs);
3223
3125
table->field[3]->store((int64_t) tmp_cs->mbmaxlen, true);
3224
if (schema_table_store_record(thd, table))
3126
if (schema_table_store_record(session, table))
3281
3183
CHARSET_INFO **cl;
3282
3184
const CHARSET_INFO *tmp_cs= cs[0];
3283
if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3185
if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3284
3186
!(tmp_cs->state & MY_CS_PRIMARY))
3286
3188
for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3288
3190
const CHARSET_INFO *tmp_cl= cl[0];
3289
if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3191
if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3290
3192
!my_charset_same(tmp_cs,tmp_cl))
3292
restore_record(table, s->default_values);
3194
table->restoreRecordAsDefault();
3293
3195
table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3294
3196
table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3295
if (schema_table_store_record(thd, table))
3197
if (schema_table_store_record(session, table))
3378
3280
uint32_t flags= key_part->field ? key_part->field->flags : 0;
3379
3281
const char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES");
3380
3282
table->field[12]->store(pos, strlen(pos), cs);
3381
if (!show_table->s->keys_in_use.is_set(i))
3283
if (!show_table->s->keys_in_use.test(i))
3382
3284
table->field[14]->store(STRING_WITH_LEN("disabled"), cs);
3384
3286
table->field[14]->store("", 0, cs);
3385
3287
table->field[14]->set_notnull();
3386
assert(test(key_info->flags & HA_USES_COMMENT) ==
3288
assert(test(key_info->flags & HA_USES_COMMENT) ==
3387
3289
(key_info->comment.length > 0));
3388
3290
if (key_info->flags & HA_USES_COMMENT)
3389
table->field[15]->store(key_info->comment.str,
3291
table->field[15]->store(key_info->comment.str,
3390
3292
key_info->comment.length, cs);
3391
if (schema_table_store_record(thd, table))
3293
if (schema_table_store_record(session, table))
3400
bool store_constraints(THD *thd, Table *table, LEX_STRING *db_name,
3302
bool store_constraints(Session *session, Table *table, LEX_STRING *db_name,
3401
3303
LEX_STRING *table_name, const char *key_name,
3402
3304
uint32_t key_len, const char *con_type, uint32_t con_len)
3404
3306
const CHARSET_INFO * const cs= system_charset_info;
3405
restore_record(table, s->default_values);
3307
table->restoreRecordAsDefault();
3406
3308
table->field[1]->store(db_name->str, db_name->length, cs);
3407
3309
table->field[2]->store(key_name, key_len, cs);
3408
3310
table->field[3]->store(db_name->str, db_name->length, cs);
3409
3311
table->field[4]->store(table_name->str, table_name->length, cs);
3410
3312
table->field[5]->store(con_type, con_len, cs);
3411
return schema_table_store_record(thd, table);
3313
return schema_table_store_record(session, table);
3415
static int get_schema_constraints_record(THD *thd, TableList *tables,
3317
static int get_schema_constraints_record(Session *session, TableList *tables,
3416
3318
Table *table, bool res,
3417
3319
LEX_STRING *db_name,
3418
3320
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());
3324
if (session->is_error())
3325
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3326
session->main_da.sql_errno(), session->main_da.message());
3327
session->clear_error();
3439
3341
if (i != primary_key && !(key_info->flags & HA_NOSAME))
3442
if (i == primary_key && !strcmp(key_info->name, primary_key_name))
3344
if (i == primary_key && is_primary_key(key_info))
3444
if (store_constraints(thd, table, db_name, table_name, key_info->name,
3346
if (store_constraints(session, table, db_name, table_name, key_info->name,
3445
3347
strlen(key_info->name),
3446
3348
STRING_WITH_LEN("PRIMARY KEY")))
3449
3351
else if (key_info->flags & HA_NOSAME)
3451
if (store_constraints(thd, table, db_name, table_name, key_info->name,
3353
if (store_constraints(session, table, db_name, table_name, key_info->name,
3452
3354
strlen(key_info->name),
3453
3355
STRING_WITH_LEN("UNIQUE")))
3458
show_table->file->get_foreign_key_list(thd, &f_key_list);
3360
show_table->file->get_foreign_key_list(session, &f_key_list);
3459
3361
FOREIGN_KEY_INFO *f_key_info;
3460
3362
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3461
3363
while ((f_key_info=it++))
3463
if (store_constraints(thd, table, db_name, table_name,
3365
if (store_constraints(session, table, db_name, table_name,
3464
3366
f_key_info->forein_id->str,
3465
3367
strlen(f_key_info->forein_id->str),
3466
3368
"FOREIGN KEY", 11))
3520
3422
if (key_part->field)
3523
restore_record(table, s->default_values);
3425
table->restoreRecordAsDefault();
3524
3426
store_key_column_usage(table, db_name, table_name,
3525
3427
key_info->name,
3526
strlen(key_info->name),
3527
key_part->field->field_name,
3428
strlen(key_info->name),
3429
key_part->field->field_name,
3528
3430
strlen(key_part->field->field_name),
3529
3431
(int64_t) f_idx);
3530
if (schema_table_store_record(thd, table))
3432
if (schema_table_store_record(session, table))
3536
show_table->file->get_foreign_key_list(thd, &f_key_list);
3438
show_table->file->get_foreign_key_list(session, &f_key_list);
3537
3439
FOREIGN_KEY_INFO *f_key_info;
3538
3440
List_iterator_fast<FOREIGN_KEY_INFO> fkey_it(f_key_list);
3539
3441
while ((f_key_info= fkey_it++))
3578
int fill_open_tables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3480
int fill_open_tables(Session *session, TableList *tables, COND *)
3580
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3482
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3581
3483
Table *table= tables->table;
3582
3484
const CHARSET_INFO * const cs= system_charset_info;
3583
3485
OPEN_TableList *open_list;
3584
if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3585
&& thd->is_fatal_error)
3486
if (!(open_list=list_open_tables(session->lex->select_lex.db, wild))
3487
&& session->is_fatal_error)
3588
3490
for (; open_list ; open_list=open_list->next)
3590
restore_record(table, s->default_values);
3492
table->restoreRecordAsDefault();
3591
3493
table->field[0]->store(open_list->db, strlen(open_list->db), cs);
3592
3494
table->field[1]->store(open_list->table, strlen(open_list->table), cs);
3593
3495
table->field[2]->store((int64_t) open_list->in_use, true);
3594
3496
table->field[3]->store((int64_t) open_list->locked, true);
3595
if (schema_table_store_record(thd, table))
3497
if (schema_table_store_record(session, table))
3602
int fill_variables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3504
int fill_variables(Session *session, TableList *tables, COND *)
3507
LEX *lex= session->lex;
3606
3508
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3607
3509
enum enum_schema_tables schema_table_idx=
3608
3510
get_schema_table_idx(tables->schema_table);
3614
3516
schema_table_idx == SCH_GLOBAL_VARIABLES)
3615
3517
option_type= OPT_GLOBAL;
3617
rw_rdlock(&LOCK_system_variables_hash);
3618
res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars),
3519
pthread_rwlock_rdlock(&LOCK_system_variables_hash);
3520
res= show_status_array(session, wild, enumerate_sys_vars(session, sorted_vars),
3619
3521
option_type, NULL, "", tables->table, upper_case_names);
3620
rw_unlock(&LOCK_system_variables_hash);
3522
pthread_rwlock_unlock(&LOCK_system_variables_hash);
3625
int fill_status(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3527
int fill_status(Session *session, TableList *tables, COND *)
3529
LEX *lex= session->lex;
3628
3530
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3630
3532
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());
3596
if (session->is_error())
3597
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3598
session->main_da.sql_errno(), session->main_da.message());
3599
session->clear_error();
3702
3604
List<FOREIGN_KEY_INFO> f_key_list;
3703
3605
Table *show_table= tables->table;
3704
show_table->file->info(HA_STATUS_VARIABLE |
3606
show_table->file->info(HA_STATUS_VARIABLE |
3705
3607
HA_STATUS_NO_LOCK |
3706
3608
HA_STATUS_TIME);
3708
show_table->file->get_foreign_key_list(thd, &f_key_list);
3610
show_table->file->get_foreign_key_list(session, &f_key_list);
3709
3611
FOREIGN_KEY_INFO *f_key_info;
3710
3612
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3711
3613
while ((f_key_info= it++))
3713
restore_record(table, s->default_values);
3615
table->restoreRecordAsDefault();
3714
3616
table->field[1]->store(db_name->str, db_name->length, cs);
3715
3617
table->field[9]->store(table_name->str, table_name->length, cs);
3716
3618
table->field[2]->store(f_key_info->forein_id->str,
3717
3619
f_key_info->forein_id->length, cs);
3718
table->field[4]->store(f_key_info->referenced_db->str,
3620
table->field[4]->store(f_key_info->referenced_db->str,
3719
3621
f_key_info->referenced_db->length, cs);
3720
table->field[10]->store(f_key_info->referenced_table->str,
3622
table->field[10]->store(f_key_info->referenced_table->str,
3721
3623
f_key_info->referenced_table->length, cs);
3722
3624
if (f_key_info->referenced_key_name)
3724
table->field[5]->store(f_key_info->referenced_key_name->str,
3626
table->field[5]->store(f_key_info->referenced_key_name->str,
3725
3627
f_key_info->referenced_key_name->length, cs);
3726
3628
table->field[5]->set_notnull();
3729
3631
table->field[5]->set_null();
3730
3632
table->field[6]->store(STRING_WITH_LEN("NONE"), cs);
3731
table->field[7]->store(f_key_info->update_method->str,
3633
table->field[7]->store(f_key_info->update_method->str,
3732
3634
f_key_info->update_method->length, cs);
3733
table->field[8]->store(f_key_info->delete_method->str,
3635
table->field[8]->store(f_key_info->delete_method->str,
3734
3636
f_key_info->delete_method->length, cs);
3735
if (schema_table_store_record(thd, table))
3637
if (schema_table_store_record(session, table))
3910
3785
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)));
3788
Tmp_Table_Param *tmp_table_param =
3789
(Tmp_Table_Param*) (session->alloc(sizeof(Tmp_Table_Param)));
3915
3790
tmp_table_param->init();
3916
3791
tmp_table_param->table_charset= cs;
3917
3792
tmp_table_param->field_count= field_count;
3918
3793
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 |
3794
Select_Lex *select_lex= session->lex->current_select;
3795
if (!(table= create_tmp_table(session, tmp_table_param,
3796
field_list, (order_st*) 0, 0, 0,
3797
(select_lex->options | session->options |
3923
3798
TMP_TABLE_ALL_COLUMNS),
3924
3799
HA_POS_ERROR, table_list->alias)))
3926
3801
my_bitmap_map* bitmaps=
3927
(my_bitmap_map*) thd->alloc(bitmap_buffer_size(field_count));
3802
(my_bitmap_map*) session->alloc(bitmap_buffer_size(field_count));
3928
3803
bitmap_init(&table->def_read_set, (my_bitmap_map*) bitmaps, field_count,
3930
3805
table->read_set= &table->def_read_set;
4022
3897
Item_field *field= new Item_field(context,
4023
3898
NULL, NULL, field_info->field_name);
4024
if (add_item_to_list(thd, field))
3899
if (session->add_item_to_list(field))
4026
3901
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4027
if (thd->lex->verbose)
3902
if (session->lex->verbose)
4029
3904
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4030
3905
field_info= &schema_table->fields_info[3];
4031
3906
field= new Item_field(context, NULL, NULL, field_info->field_name);
4032
if (add_item_to_list(thd, field))
3907
if (session->add_item_to_list(field))
4034
3909
field->set_name(field_info->old_name, strlen(field_info->old_name),
4035
3910
system_charset_info);
4126
4001
table_list->table_name= table->s->table_name.str;
4127
4002
table_list->table_name_length= table->s->table_name.length;
4128
4003
table_list->table= table;
4129
table->next= thd->derived_tables;
4130
thd->derived_tables= table;
4004
table->next= session->derived_tables;
4005
session->derived_tables= table;
4131
4006
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;
4188
int make_schema_select(THD *thd, SELECT_LEX *sel,
4026
int make_schema_select(Session *session, Select_Lex *sel,
4189
4027
enum enum_schema_tables schema_table_idx)
4191
ST_SCHEMA_TABLE *schema_table= get_schema_table(schema_table_idx);
4029
InfoSchemaTable *schema_table= get_schema_table(schema_table_idx);
4192
4030
LEX_STRING db, table;
4194
4032
We have to make non const db_name & table_name
4195
4033
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,
4035
session->make_lex_string(&db, INFORMATION_SCHEMA_NAME.c_str(),
4036
INFORMATION_SCHEMA_NAME.length(), 0);
4037
session->make_lex_string(&table, schema_table->table_name,
4200
4038
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),
4039
if (schema_table->old_format(session, schema_table) || /* Handle old syntax */
4040
!sel->add_table_to_list(session, new Table_ident(session, db, table, 0),
4203
4041
0, 0, TL_READ))
4320
4158
{"ROW_FORMAT", 10, DRIZZLE_TYPE_VARCHAR, 0, 1, "Row_format", OPEN_FULL_TABLE},
4321
4159
{"TABLE_ROWS", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4322
4160
(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,
4161
{"AVG_ROW_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4324
4162
(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,
4163
{"DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4326
4164
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Data_length", OPEN_FULL_TABLE},
4327
4165
{"MAX_DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4328
4166
(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,
4167
{"INDEX_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4330
4168
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Index_length", OPEN_FULL_TABLE},
4331
4169
{"DATA_FREE", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4332
4170
(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,
4171
{"AUTO_INCREMENT", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG, 0,
4334
4172
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Auto_increment", OPEN_FULL_TABLE},
4335
4173
{"CREATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Create_time", OPEN_FULL_TABLE},
4336
4174
{"UPDATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Update_time", OPEN_FULL_TABLE},
4530
4368
ST_FIELD_INFO plugin_fields_info[]=
4532
{"PLUGIN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name",
4370
{"PLUGIN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name",
4533
4371
SKIP_OPEN_TABLE},
4534
4372
{"PLUGIN_VERSION", 20, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4535
4373
{"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
4374
{"PLUGIN_AUTHOR", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4540
4375
{"PLUGIN_DESCRIPTION", 65535, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4541
4376
{"PLUGIN_LICENSE", 80, DRIZZLE_TYPE_VARCHAR, 0, 1, "License", SKIP_OPEN_TABLE},
4575
ST_SCHEMA_TABLE schema_tables[]=
4410
InfoSchemaTable schema_tables[]=
4577
{"CHARACTER_SETS", charsets_fields_info, create_schema_table,
4412
{"CHARACTER_SETS", charsets_fields_info, create_schema_table,
4578
4413
fill_schema_charsets, make_character_sets_old_format, 0, -1, -1, 0, 0},
4579
{"COLLATIONS", collation_fields_info, create_schema_table,
4414
{"COLLATIONS", collation_fields_info, create_schema_table,
4580
4415
fill_schema_collation, make_old_format, 0, -1, -1, 0, 0},
4581
4416
{"COLLATION_CHARACTER_SET_APPLICABILITY", coll_charset_app_fields_info,
4582
4417
create_schema_table, fill_schema_coll_charset_app, 0, 0, -1, -1, 0, 0},
4583
{"COLUMNS", columns_fields_info, create_schema_table,
4418
{"COLUMNS", columns_fields_info, create_schema_table,
4584
4419
get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2, 0,
4585
4420
OPTIMIZE_I_S_TABLE},
4586
4421
{"GLOBAL_STATUS", variables_fields_info, create_schema_table,
4605
4440
fill_status, make_old_format, 0, -1, -1, 0, 0},
4606
4441
{"SESSION_VARIABLES", variables_fields_info, create_schema_table,
4607
4442
fill_variables, make_old_format, 0, -1, -1, 0, 0},
4608
{"STATISTICS", stat_fields_info, create_schema_table,
4443
{"STATISTICS", stat_fields_info, create_schema_table,
4609
4444
get_all_tables, make_old_format, get_schema_stat_record, 1, 2, 0,
4610
4445
OPEN_TABLE_ONLY|OPTIMIZE_I_S_TABLE},
4611
{"STATUS", variables_fields_info, create_schema_table, fill_status,
4446
{"STATUS", variables_fields_info, create_schema_table, fill_status,
4612
4447
make_old_format, 0, -1, -1, 1, 0},
4613
{"TABLES", tables_fields_info, create_schema_table,
4448
{"TABLES", tables_fields_info, create_schema_table,
4614
4449
get_all_tables, make_old_format, get_schema_tables_record, 1, 2, 0,
4615
4450
OPTIMIZE_I_S_TABLE},
4616
4451
{"TABLE_CONSTRAINTS", table_constraints_fields_info, create_schema_table,
4622
4457
{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)