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/virtual_column_info.h>
37
#include <drizzled/sql_base.h>
38
#include <drizzled/db.h>
39
#include <drizzled/field/timestamp.h>
40
#include <drizzled/field/decimal.h>
41
#include <drizzled/lock.h>
42
#include <drizzled/item/return_date_time.h>
43
#include <drizzled/item/empty_string.h>
52
int show_var_cmp(const void *var1, const void *var2);
25
54
inline const char *
26
55
str_or_nil(const char *str)
155
183
switch (plug->license) {
156
184
case PLUGIN_LICENSE_GPL:
157
table->field[7]->store(PLUGIN_LICENSE_GPL_STRING,
185
table->field[7]->store(PLUGIN_LICENSE_GPL_STRING,
158
186
strlen(PLUGIN_LICENSE_GPL_STRING), cs);
160
188
case PLUGIN_LICENSE_BSD:
161
table->field[7]->store(PLUGIN_LICENSE_BSD_STRING,
189
table->field[7]->store(PLUGIN_LICENSE_BSD_STRING,
162
190
strlen(PLUGIN_LICENSE_BSD_STRING), cs);
165
table->field[7]->store(PLUGIN_LICENSE_PROPRIETARY_STRING,
193
table->field[7]->store(PLUGIN_LICENSE_PROPRIETARY_STRING,
166
194
strlen(PLUGIN_LICENSE_PROPRIETARY_STRING), cs);
169
197
table->field[7]->set_notnull();
171
return schema_table_store_record(thd, table);
199
return schema_table_store_record(session, table);
175
int fill_plugins(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
203
int fill_plugins(Session *session, TableList *tables, COND *)
177
205
Table *table= tables->table;
179
if (plugin_foreach_with_mask(thd, show_plugins, DRIZZLE_ANY_PLUGIN,
207
if (plugin_foreach_with_mask(session, show_plugins, DRIZZLE_ANY_PLUGIN,
180
208
~PLUGIN_IS_FREED, table))
274
302
// Return only .frm files which aren't temp files.
275
303
if (my_strcasecmp(system_charset_info, ext=fn_rext(file->name),reg_ext) ||
276
is_prefix(file->name, tmp_file_prefix))
304
is_prefix(file->name, TMP_FILE_PREFIX))
279
307
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))
310
if (lower_case_table_names)
312
if (wild_case_compare(files_charset_info, uname, wild))
315
else if (wild_compare(uname, wild, 0))
292
thd->make_lex_string(file_name, uname, file_name_len, true)) ||
320
session->make_lex_string(file_name, uname, file_name_len, true)) ||
293
321
files->push_back(file_name))
306
mysqld_show_create(THD *thd, TableList *table_list)
333
bool drizzled_show_create(Session *session, TableList *table_list)
308
Protocol *protocol= thd->protocol;
335
Protocol *protocol= session->protocol;
310
337
String buffer(buff, sizeof(buff), system_charset_info);
312
339
/* Only one table for now, but VIEW can involve several tables */
313
if (open_normal_and_derived_tables(thd, table_list, 0))
340
if (open_normal_and_derived_tables(session, table_list, 0))
315
if (thd->is_error() && thd->main_da.sql_errno() != ER_VIEW_INVALID)
342
if (session->is_error())
319
346
Clear all messages with 'error' level status and
320
issue a warning with 'warning' level status in
347
issue a warning with 'warning' level status in
321
348
case of invalid view and last error is ER_VIEW_INVALID
323
drizzle_reset_errors(thd, true);
350
drizzle_reset_errors(session, true);
351
session->clear_error();
327
354
buffer.length(0);
329
if (store_create_info(thd, table_list, &buffer, NULL))
356
if (store_create_info(session, table_list, &buffer, NULL))
332
359
List<Item> field_list;
354
383
if (protocol->write())
361
bool mysqld_show_create_db(THD *thd, char *dbname,
390
bool mysqld_show_create_db(Session *session, char *dbname,
362
391
HA_CREATE_INFO *create_info)
365
394
String buffer(buff, sizeof(buff), system_charset_info);
366
Protocol *protocol=thd->protocol;
395
Protocol *protocol=session->protocol;
368
if (store_db_create_info(thd, dbname, &buffer, create_info))
397
if (store_db_create_info(session, dbname, &buffer, create_info))
371
400
This assumes that the only reason for which store_db_create_info()
372
401
can fail is incorrect database name (which is the case now).
374
403
my_error(ER_BAD_DB_ERROR, MYF(0), dbname);
378
407
List<Item> field_list;
423
452
restore_record(table, s->default_values); // Get empty record
424
453
table->use_all_columns();
425
if (thd->protocol->send_fields(&field_list, Protocol::SEND_DEFAULTS))
454
if (session->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);
523
462
Get the quote character for displaying an identifier.
526
465
get_quote_char_for_identifier()
466
session Thread handler
528
467
name name to quote
529
468
length length of name
542
481
# Quote character
545
int get_quote_char_for_identifier(THD *thd, const char *name, uint32_t length)
484
int get_quote_char_for_identifier(Session *, const char *, uint32_t)
548
!is_keyword(name,length) &&
549
!require_quotes(name, length) &&
550
!(thd->options & OPTION_QUOTE_SHOW_CREATE))
556
490
/* Append directory name (if exists) to CREATE INFO */
558
static void append_directory(THD *thd __attribute__((unused)),
492
static void append_directory(Session *,
559
493
String *packet, const char *dir_type,
560
const char *filename)
494
const char *filename)
641
573
to tailor the format of the statement. Can be
642
574
NULL, in which case only SQL_MODE is considered
643
575
when building the statement.
646
578
Currently always return 0, but might return error code in the
653
int store_create_info(THD *thd, TableList *table_list, String *packet,
585
int store_create_info(Session *session, TableList *table_list, String *packet,
654
586
HA_CREATE_INFO *create_info_arg)
656
588
List<Item> field_list;
657
char tmp[MAX_FIELD_WIDTH], *for_str, buff[128], def_value_buf[MAX_FIELD_WIDTH];
589
char tmp[MAX_FIELD_WIDTH], *for_str, def_value_buf[MAX_FIELD_WIDTH];
658
590
const char *alias;
659
592
String type(tmp, sizeof(tmp), system_charset_info);
660
593
String def_value(def_value_buf, sizeof(def_value_buf), system_charset_info);
661
594
Field **ptr,*field;
714
645
type.set_charset(system_charset_info);
647
if (field->vcol_info)
649
packet->append(STRING_WITH_LEN("VIRTUAL "));
716
652
field->sql_type(type);
717
653
packet->append(type.ptr(), type.length(), system_charset_info);
655
if (field->vcol_info)
657
packet->append(STRING_WITH_LEN(" AS ("));
658
packet->append(field->vcol_info->expr_str.str,
659
field->vcol_info->expr_str.length,
660
system_charset_info);
661
packet->append(STRING_WITH_LEN(")"));
662
if (field->is_stored)
663
packet->append(STRING_WITH_LEN(" STORED"));
719
666
if (field->has_charset())
721
668
if (field->charset() != share->table_charset)
723
packet->append(STRING_WITH_LEN(" CHARACTER SET "));
724
packet->append(field->charset()->csname);
670
packet->append(STRING_WITH_LEN(" CHARACTER SET "));
671
packet->append(field->charset()->csname);
727
For string types dump collation name only if
728
collation is not primary for the given charset
675
For string types dump collation name only if
676
collation is not primary for the given charset
730
678
if (!(field->charset()->state & MY_CS_PRIMARY))
732
packet->append(STRING_WITH_LEN(" COLLATE "));
733
packet->append(field->charset()->name);
680
packet->append(STRING_WITH_LEN(" COLLATE "));
681
packet->append(field->charset()->name);
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)
931
874
packet->append(STRING_WITH_LEN(" ROW_FORMAT="));
932
875
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);
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)
961
897
packet->append(STRING_WITH_LEN(" CONNECTION="));
962
898
append_unescaped(packet, share->connect_string.str, share->connect_string.length);
964
append_directory(thd, packet, "DATA", create_info.data_file_name);
965
append_directory(thd, packet, "INDEX", create_info.index_file_name);
900
append_directory(session, packet, "DATA", create_info.data_file_name);
901
append_directory(session, packet, "INDEX", create_info.index_file_name);
967
903
table->restore_column_map(old_map);
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 verbose)
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 :
1023
ulong max_query_length= (verbose ? session->variables.max_allowed_packet :
1102
1024
PROCESS_LIST_WIDTH);
1103
Protocol *protocol= thd->protocol;
1025
Protocol *protocol= session->protocol;
1105
1027
field_list.push_back(new Item_int("Id", 0, MY_INT32_NUM_DECIMAL_DIGITS));
1106
1028
field_list.push_back(new Item_empty_string("User",16));
1120
1042
pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
1043
if (!session->killed)
1123
I_List_iterator<THD> it(threads);
1045
I_List_iterator<Session> it(threads);
1125
1047
while ((tmp=it++))
1127
Security_context *tmp_sctx= tmp->security_ctx;
1049
Security_context *tmp_sctx= &tmp->security_ctx;
1128
1050
struct st_my_thread_var *mysys_var;
1129
if ((tmp->vio_ok() || tmp->system_thread) && (!user || (tmp_sctx->user && !strcmp(tmp_sctx->user, user))))
1051
if ((tmp->drizzleclient_vio_ok() || tmp->system_thread) && (!user || (tmp_sctx->user.c_str() && !strcmp(tmp_sctx->user.c_str(), user))))
1131
thread_info *thd_info= new thread_info;
1053
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 :
1055
session_info->thread_id=tmp->thread_id;
1056
session_info->user= session->strdup(tmp_sctx->user.c_str() ? tmp_sctx->user.c_str() :
1135
1057
(tmp->system_thread ?
1136
1058
"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;
1059
session_info->host= session->strdup(tmp_sctx->ip.c_str());
1060
if ((session_info->db=tmp->db)) // Safe test
1061
session_info->db=session->strdup(session_info->db);
1062
session_info->command=(int) tmp->command;
1141
1063
if ((mysys_var= tmp->mysys_var))
1142
1064
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 ?
1065
session_info->proc_info= (char*) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0);
1066
session_info->state_info= (char*) (tmp->net.reading_or_writing ?
1145
1067
(tmp->net.reading_or_writing == 2 ?
1146
1068
"Writing to net" :
1147
thd_info->command == COM_SLEEP ? NULL :
1069
session_info->command == COM_SLEEP ? NULL :
1148
1070
"Reading from net") :
1149
1071
tmp->get_proc_info() ? tmp->get_proc_info() :
1150
1072
tmp->mysys_var &&
1154
1076
pthread_mutex_unlock(&mysys_var->mutex);
1156
thd_info->start_time= tmp->start_time;
1078
session_info->start_time= tmp->start_time;
1079
session_info->query=0;
1158
1080
if (tmp->query)
1161
1083
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
1084
the comment in session.h why this prevents crashes in possible
1163
1085
races with query_length
1165
1087
uint32_t length= cmin((uint32_t)max_query_length, tmp->query_length);
1166
thd_info->query=(char*) thd->strmake(tmp->query,length);
1088
session_info->query=(char*) session->strmake(tmp->query,length);
1168
thread_infos.append(thd_info);
1090
thread_infos.append(session_info);
1172
1094
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()))
1096
thread_info *session_info;
1097
time_t now= time(NULL);
1098
while ((session_info=thread_infos.get()))
1178
1100
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);
1101
protocol->store((uint64_t) session_info->thread_id);
1102
protocol->store(session_info->user, system_charset_info);
1103
protocol->store(session_info->host, system_charset_info);
1104
protocol->store(session_info->db, system_charset_info);
1105
if (session_info->proc_info)
1106
protocol->store(session_info->proc_info, system_charset_info);
1186
protocol->store(command_name[thd_info->command].str, system_charset_info);
1187
if (thd_info->start_time)
1188
protocol->store((uint32_t) (now - thd_info->start_time));
1108
protocol->store(command_name[session_info->command].str, system_charset_info);
1109
if (session_info->start_time)
1110
protocol->store((uint32_t) (now - session_info->start_time));
1190
1112
protocol->store_null();
1191
protocol->store(thd_info->state_info, system_charset_info);
1192
protocol->store(thd_info->query, system_charset_info);
1113
protocol->store(session_info->state_info, system_charset_info);
1114
protocol->store(session_info->query, system_charset_info);
1193
1115
if (protocol->write())
1194
1116
break; /* purecov: inspected */
1200
int fill_schema_processlist(THD* thd, TableList* tables,
1201
COND* cond __attribute__((unused)))
1122
int fill_schema_processlist(Session* session, TableList* tables, COND*)
1203
1124
Table *table= tables->table;
1204
1125
const CHARSET_INFO * const cs= system_charset_info;
1206
time_t now= my_time(0);
1127
time_t now= time(NULL);
1129
if (now == (time_t)-1)
1210
1134
pthread_mutex_lock(&LOCK_thread_count);
1136
if (!session->killed)
1214
I_List_iterator<THD> it(threads);
1138
I_List_iterator<Session> it(threads);
1217
1141
while ((tmp= it++))
1219
Security_context *tmp_sctx= tmp->security_ctx;
1143
Security_context *tmp_sctx= &tmp->security_ctx;
1220
1144
struct st_my_thread_var *mysys_var;
1221
1145
const char *val;
1223
if ((!tmp->vio_ok() && !tmp->system_thread))
1147
if ((!tmp->drizzleclient_vio_ok() && !tmp->system_thread))
1226
1150
restore_record(table, s->default_values);
1228
1152
table->field[0]->store((int64_t) tmp->thread_id, true);
1230
val= tmp_sctx->user ? tmp_sctx->user :
1154
val= tmp_sctx->user.c_str() ? tmp_sctx->user.c_str() :
1231
1155
(tmp->system_thread ? "system user" : "unauthenticated user");
1232
1156
table->field[1]->store(val, strlen(val), cs);
1234
table->field[2]->store(tmp_sctx->ip, strlen(tmp_sctx->ip), cs);
1158
table->field[2]->store(tmp_sctx->ip.c_str(), strlen(tmp_sctx->ip.c_str()), cs);
1469
1393
*buf= my_toupper(system_charset_info, *buf);
1472
static bool show_status_array(THD *thd, const char *wild,
1396
static bool show_status_array(Session *session, const char *wild,
1473
1397
SHOW_VAR *variables,
1474
1398
enum enum_var_type value_type,
1475
1399
struct system_status_var *status_var,
1476
1400
const char *prefix, Table *table,
1477
1401
bool ucase_names)
1479
MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, long);
1403
MY_ALIGNED_BYTE_ARRAY(buff_data, SHOW_VAR_FUNC_BUFF_SIZE, int64_t);
1480
1404
char * const buff= (char *) &buff_data;
1481
1405
char *prefix_end;
1482
1406
/* the variable name should not be longer than 64 characters */
1483
1407
char name_buffer[64];
1485
LEX_STRING null_lex_str;
1486
1409
SHOW_VAR tmp, *var;
1488
null_lex_str.str= 0; // For sys_var->value_ptr()
1489
null_lex_str.length= 0;
1411
prefix_end= strncpy(name_buffer, prefix, sizeof(name_buffer)-1);
1412
prefix_end+= strlen(prefix);
1491
prefix_end=my_stpncpy(name_buffer, prefix, sizeof(name_buffer)-1);
1493
1415
*prefix_end++= '_';
1494
1416
len=name_buffer + sizeof(name_buffer) - prefix_end;
1496
1418
for (; variables->name; variables++)
1498
my_stpncpy(prefix_end, variables->name, len);
1420
strncpy(prefix_end, variables->name, len);
1499
1421
name_buffer[sizeof(name_buffer)-1]=0; /* Safety */
1500
1422
if (ucase_names)
1501
1423
make_upper(name_buffer);
1505
1427
Repeat as necessary, if new var is again SHOW_FUNC
1507
1429
for (var=variables; var->type == SHOW_FUNC; var= &tmp)
1508
((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(thd, &tmp, buff);
1430
((mysql_show_var_func)((st_show_var_func_container *)var->value)->func)(session, &tmp, buff);
1510
1432
SHOW_TYPE show_type=var->type;
1511
1433
if (show_type == SHOW_ARRAY)
1513
show_status_array(thd, wild, (SHOW_VAR *) var->value, value_type,
1435
show_status_array(session, wild, (SHOW_VAR *) var->value, value_type,
1514
1436
status_var, name_buffer, table, ucase_names);
1556
1477
case SHOW_LONGLONG:
1557
1478
end= int64_t10_to_str(*(int64_t*) value, buff, 10);
1482
stringstream ss (stringstream::in);
1483
ss << *(size_t*) value;
1485
string str= ss.str();
1486
strncpy(buff, str.c_str(), str.length());
1487
end= buff+ str.length();
1559
1490
case SHOW_HA_ROWS:
1560
1491
end= int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
1562
1493
case SHOW_BOOL:
1563
end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1494
end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
1565
1496
case SHOW_MY_BOOL:
1566
end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1497
end+= sprintf(buff,"%s", *(bool*) value ? "ON" : "OFF");
1569
1500
end= int10_to_str((long) *(uint32_t*) value, buff, 10);
1571
1502
case SHOW_HAVE:
1573
SHOW_COMP_OPTION tmp= *(SHOW_COMP_OPTION*) value;
1574
pos= show_comp_option_name[(int) tmp];
1504
SHOW_COMP_OPTION tmp_option= *(SHOW_COMP_OPTION *)value;
1505
pos= show_comp_option_name[(int) tmp_option];
1575
1506
end= strchr(pos, '\0');
1672
bool schema_table_store_record(THD *thd, Table *table)
1603
bool schema_table_store_record(Session *session, Table *table)
1675
1606
if ((error= table->file->ha_write_row(table->record[0])))
1677
TMP_TABLE_PARAM *param= table->pos_in_table_list->schema_table_param;
1608
Tmp_Table_Param *param= table->pos_in_table_list->schema_table_param;
1679
if (create_myisam_from_heap(thd, table, param->start_recinfo,
1610
if (create_myisam_from_heap(session, table, param->start_recinfo,
1680
1611
¶m->recinfo, error, 0))
1687
int make_table_list(THD *thd, SELECT_LEX *sel,
1618
int make_table_list(Session *session, Select_Lex *sel,
1688
1619
LEX_STRING *db_name, LEX_STRING *table_name)
1690
1621
Table_ident *table_ident;
1691
table_ident= new Table_ident(thd, *db_name, *table_name, 1);
1622
table_ident= new Table_ident(session, *db_name, *table_name, 1);
1692
1623
sel->init_query();
1693
if (!sel->add_table_to_list(thd, table_ident, 0, 0, TL_READ))
1624
if (!sel->add_table_to_list(session, table_ident, 0, 0, TL_READ))
1700
@brief Get lookup value from the part of 'WHERE' condition
1631
@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
1633
@details This function gets lookup value from
1634
the part of 'WHERE' condition if it's possible and
1704
1635
fill appropriate lookup_field_vals struct field
1705
1636
with this value.
1707
@param[in] thd thread handler
1638
@param[in] session thread handler
1708
1639
@param[in] item_func part of WHERE condition
1709
1640
@param[in] table I_S table
1710
@param[in, out] lookup_field_vals Struct which holds lookup values
1641
@param[in, out] lookup_field_vals Struct which holds lookup values
1714
1645
1 error, there can be no matching records for the condition
1717
bool get_lookup_value(THD *thd, Item_func *item_func,
1648
bool get_lookup_value(Session *session, Item_func *item_func,
1719
1650
LOOKUP_FIELD_VALUES *lookup_field_vals)
1721
1652
ST_SCHEMA_TABLE *schema_table= table->schema_table;
1784
@brief Calculates lookup values from 'WHERE' condition
1715
@brief Calculates lookup values from 'WHERE' condition
1786
1717
@details This function calculates lookup value(database name, table name)
1787
from 'WHERE' condition if it's possible and
1718
from 'WHERE' condition if it's possible and
1788
1719
fill lookup_field_vals struct fields with these values.
1790
@param[in] thd thread handler
1721
@param[in] session thread handler
1791
1722
@param[in] cond WHERE condition
1792
1723
@param[in] table I_S table
1793
@param[in, out] lookup_field_vals Struct which holds lookup values
1724
@param[in, out] lookup_field_vals Struct which holds lookup values
1797
1728
1 error, there can be no matching records for the condition
1800
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TableList *table,
1731
bool calc_lookup_values_from_cond(Session *session, COND *cond, TableList *table,
1801
1732
LOOKUP_FIELD_VALUES *lookup_field_vals)
1936
1867
from LEX struct and fill lookup_field_vals struct field
1937
1868
with these values.
1939
@param[in] thd thread handler
1870
@param[in] session thread handler
1940
1871
@param[in] cond WHERE condition
1941
1872
@param[in] tables I_S table
1942
@param[in, out] lookup_field_values Struct which holds lookup values
1873
@param[in, out] lookup_field_values Struct which holds lookup values
1946
1877
1 error, there can be no matching records for the condition
1949
bool get_lookup_field_values(THD *thd, COND *cond, TableList *tables,
1880
bool get_lookup_field_values(Session *session, COND *cond, TableList *tables,
1950
1881
LOOKUP_FIELD_VALUES *lookup_field_values)
1883
LEX *lex= session->lex;
1953
1884
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1954
1885
memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1955
1886
switch (lex->sql_command) {
1927
session thread handler
1997
1928
files list of db names
1998
1929
wild wild string
1999
1930
idx_field_vals idx_field_vals->db_name contains db name or
2001
1932
with_i_schema returns 1 if we added 'IS' name to list
2009
int make_db_list(THD *thd, List<LEX_STRING> *files,
1940
int make_db_list(Session *session, List<LEX_STRING> *files,
2010
1941
LOOKUP_FIELD_VALUES *lookup_field_vals,
2011
1942
bool *with_i_schema)
2013
1944
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);
1945
i_s_name_copy= session->make_lex_string(i_s_name_copy,
1946
INFORMATION_SCHEMA_NAME.c_str(),
1947
INFORMATION_SCHEMA_NAME.length(), true);
2017
1948
*with_i_schema= 0;
2018
1949
if (lookup_field_vals->wild_db_value)
2023
1954
LIKE clause (see also get_index_field_values() function)
2025
1956
if (!lookup_field_vals->db_value.str ||
2026
!wild_case_compare(system_charset_info,
2027
INFORMATION_SCHEMA_NAME.str,
1957
!wild_case_compare(system_charset_info,
1958
INFORMATION_SCHEMA_NAME.c_str(),
2028
1959
lookup_field_vals->db_value.str))
2030
1961
*with_i_schema= 1;
2031
1962
if (files->push_back(i_s_name_copy))
2034
return (find_files(thd, files, NULL, mysql_data_home,
1965
return (find_files(session, files, NULL, drizzle_data_home,
2035
1966
lookup_field_vals->db_value.str, 1) != FIND_FILES_OK);
2062
1993
if (files->push_back(i_s_name_copy))
2064
1995
*with_i_schema= 1;
2065
return (find_files(thd, files, NULL,
2066
mysql_data_home, NULL, 1) != FIND_FILES_OK);
1996
return (find_files(session, files, NULL,
1997
drizzle_data_home, NULL, 1) != FIND_FILES_OK);
2070
struct st_add_schema_table
2001
struct st_add_schema_table
2072
2003
List<LEX_STRING> *files;
2073
2004
const char *wild;
2077
static bool add_schema_table(THD *thd, plugin_ref plugin,
2008
static bool add_schema_table(Session *session, plugin_ref plugin,
2080
2011
LEX_STRING *file_name= 0;
2199
2130
if (with_i_schema)
2200
return (schema_tables_add(thd, table_names,
2131
return (schema_tables_add(session, table_names,
2201
2132
lookup_field_vals->table_value.str));
2203
find_files_result res= find_files(thd, table_names, db_name->str, path,
2134
find_files_result res= find_files(session, table_names, db_name->str, path,
2204
2135
lookup_field_vals->table_value.str, 0);
2205
2136
if (res != FIND_FILES_OK)
2256
2187
lex->all_selects_list= tables->schema_select_lex;
2258
Restore thd->temporary_tables to be able to process
2189
Restore session->temporary_tables to be able to process
2259
2190
temporary tables(only for 'show index' & 'show columns').
2260
2191
This should be changed when processing of temporary tables for
2261
2192
I_S tables will be done.
2263
thd->temporary_tables= open_tables_state_backup->temporary_tables;
2194
session->temporary_tables= open_tables_state_backup->temporary_tables;
2265
2196
Let us set fake sql_command so views won't try to merge
2266
2197
themselves into main statement. If we don't do this,
2267
2198
SELECT * from information_schema.xxxx will cause problems.
2268
SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
2199
SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
2270
2201
lex->sql_command= SQLCOM_SHOW_FIELDS;
2271
res= open_normal_and_derived_tables(thd, show_table_list,
2202
res= open_normal_and_derived_tables(session, show_table_list,
2272
2203
DRIZZLE_LOCK_IGNORE_FLUSH);
2273
2204
lex->sql_command= save_sql_command;
2275
2206
get_all_tables() returns 1 on failure and 0 on success thus
2276
2207
return only these and not the result code of ::process_table()
2278
We should use show_table_list->alias instead of
2209
We should use show_table_list->alias instead of
2279
2210
show_table_list->table_name because table_name
2280
2211
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
2212
to use alias because alias contains original table name
2213
in this case(this part of code is used only for
2283
2214
'show columns' & 'show statistics' commands).
2285
table_name= thd->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2216
table_name= session->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2286
2217
strlen(show_table_list->alias), false);
2287
db_name= thd->make_lex_string(&tmp_lex_string, show_table_list->db,
2218
db_name= session->make_lex_string(&tmp_lex_string, show_table_list->db,
2288
2219
show_table_list->db_length, false);
2291
error= test(schema_table->process_table(thd, show_table_list,
2222
error= test(schema_table->process_table(session, show_table_list,
2292
2223
table, res, db_name,
2294
thd->temporary_tables= 0;
2295
close_tables_for_reopen(thd, &show_table_list);
2225
session->temporary_tables= 0;
2226
close_tables_for_reopen(session, &show_table_list);
2325
enum legacy_db_type not_used;
2326
2256
char path[FN_REFLEN];
2327
(void) build_table_filename(path, sizeof(path), db_name->str,
2257
(void) build_table_filename(path, sizeof(path), db_name->str,
2328
2258
table_name->str, reg_ext, 0);
2329
if (mysql_frm_type(thd, path, ¬_used))
2331
2260
table->field[3]->store(STRING_WITH_LEN("BASE Table"),
2332
2261
system_charset_info);
2336
table->field[3]->store(STRING_WITH_LEN("ERROR"),
2337
system_charset_info);
2340
if (thd->is_error() && thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2263
if (session->is_error() && session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2265
session->clear_error();
2346
if (schema_table_store_record(thd, table))
2269
if (schema_table_store_record(session, table))
2427
2350
table_list.table_name= table_name->str;
2428
2351
table_list.db= db_name->str;
2430
key_length= create_table_def_key(thd, key, &table_list, 0);
2353
key_length= create_table_def_key(session, key, &table_list, 0);
2431
2354
pthread_mutex_lock(&LOCK_open);
2432
share= get_table_share(thd, &table_list, key,
2355
share= get_table_share(session, &table_list, key,
2433
2356
key_length, 0, &error);
2473
2396
@retval 1 error
2476
int get_all_tables(THD *thd, TableList *tables, COND *cond)
2399
int get_all_tables(Session *session, TableList *tables, COND *cond)
2401
LEX *lex= session->lex;
2479
2402
Table *table= tables->table;
2480
SELECT_LEX *old_all_select_lex= lex->all_selects_list;
2403
Select_Lex *old_all_select_lex= lex->all_selects_list;
2481
2404
enum_sql_command save_sql_command= lex->sql_command;
2482
SELECT_LEX *lsel= tables->schema_select_lex;
2405
Select_Lex *lsel= tables->schema_select_lex;
2483
2406
ST_SCHEMA_TABLE *schema_table= tables->schema_table;
2485
2408
LOOKUP_FIELD_VALUES lookup_field_vals;
2486
2409
LEX_STRING *db_name, *table_name;
2487
2410
bool with_i_schema;
2489
2412
List<LEX_STRING> db_names;
2490
2413
List_iterator_fast<LEX_STRING> it(db_names);
2491
2414
COND *partial_cond= 0;
2492
uint32_t derived_tables= lex->derived_tables;
2415
uint32_t derived_tables= lex->derived_tables;
2494
2417
Open_tables_state open_tables_state_backup;
2495
2418
Query_tables_list query_tables_list_backup;
2496
2419
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);
2420
bool old_value= session->no_warnings_for_error;
2502
2423
We should not introduce deadlocks even if we already have some
2503
2424
tables open and locked, since we won't lock tables which we will
2504
2425
open and will ignore possible name-locks for these tables.
2506
thd->reset_n_backup_open_tables_state(&open_tables_state_backup);
2427
session->reset_n_backup_open_tables_state(&open_tables_state_backup);
2508
2429
schema_table_idx= get_schema_table_idx(schema_table);
2509
2430
tables->table_open_method= table_open_method=
2510
2431
get_table_open_method(tables, schema_table, schema_table_idx);
2512
2433
this branch processes SHOW FIELDS, SHOW INDEXES commands.
2513
2434
see sql_parse.cc, prepare_schema_table() function where
2514
2435
this values are initialized
2516
2437
if (lsel && lsel->table_list.first)
2518
error= fill_schema_show_cols_or_idxs(thd, tables, schema_table,
2439
error= fill_schema_show_cols_or_idxs(session, tables, schema_table,
2519
2440
&open_tables_state_backup);
2523
if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2444
if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
2562
if (make_db_list(thd, &db_names, &lookup_field_vals, &with_i_schema))
2483
if (make_db_list(session, &db_names, &lookup_field_vals, &with_i_schema))
2564
2485
it.rewind(); /* To get access to new elements in basis list */
2565
2486
while ((db_name= it++))
2568
thd->no_warnings_for_error= 1;
2489
session->no_warnings_for_error= 1;
2569
2490
List<LEX_STRING> table_names;
2570
int res= make_table_name_list(thd, &table_names, lex,
2491
int res= make_table_name_list(session, &table_names, lex,
2571
2492
&lookup_field_vals,
2572
2493
with_i_schema, db_name);
2573
2494
if (res == 2) /* Not fatal error, continue */
2613
2534
if (!(table_open_method & ~OPEN_FRM_ONLY) &&
2614
2535
!with_i_schema)
2616
if (!fill_schema_table_from_frm(thd, tables, schema_table, db_name,
2537
if (!fill_schema_table_from_frm(session, tables, schema_table, db_name,
2617
2538
table_name, schema_table_idx))
2622
2542
LEX_STRING tmp_lex_string, orig_db_name;
2624
2544
Set the parent lex of 'sel' because it is needed by
2625
2545
sel.init_query() which is called inside make_table_list.
2627
thd->no_warnings_for_error= 1;
2547
session->no_warnings_for_error= 1;
2628
2548
sel.parent_lex= lex;
2629
2549
/* 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))
2550
if (!session->make_lex_string(&orig_db_name, db_name->str,
2551
db_name->length, false))
2633
if (make_table_list(thd, &sel, db_name, table_name))
2553
if (make_table_list(session, &sel, db_name, table_name))
2635
2555
TableList *show_table_list= (TableList*) sel.table_list.first;
2636
2556
lex->all_selects_list= &sel;
2638
2558
lex->sql_command= SQLCOM_SHOW_FIELDS;
2639
2559
show_table_list->i_s_requested_object=
2640
2560
schema_table->i_s_requested_object;
2641
res= open_normal_and_derived_tables(thd, show_table_list,
2561
res= open_normal_and_derived_tables(session, show_table_list,
2642
2562
DRIZZLE_LOCK_IGNORE_FLUSH);
2643
2563
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().
2565
XXX: show_table_list has a flag i_is_requested,
2566
and when it's set, open_normal_and_derived_tables()
2567
can return an error without setting an error message
2568
in Session, which is a hack. This is why we have to
2569
check for res, then for session->is_error() only then
2570
for session->main_da.sql_errno().
2652
if (res && thd->is_error() &&
2653
thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2572
if (res && session->is_error() &&
2573
session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2656
2576
Hide error for not existing table.
2659
2579
table does not exist.
2582
session->clear_error();
2667
We should use show_table_list->alias instead of
2587
We should use show_table_list->alias instead of
2668
2588
show_table_list->table_name because table_name
2669
2589
could be changed during opening of I_S tables. It's safe
2670
to use alias because alias contains original table name
2590
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,
2593
session->make_lex_string(&tmp_lex_string, show_table_list->alias,
2594
strlen(show_table_list->alias), false);
2595
res= schema_table->process_table(session, show_table_list, table,
2676
2596
res, &orig_db_name,
2677
2597
&tmp_lex_string);
2678
close_tables_for_reopen(thd, &show_table_list);
2598
close_tables_for_reopen(session, &show_table_list);
2680
2600
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);
2616
session->restore_backup_open_tables_state(&open_tables_state_backup);
2698
2617
lex->derived_tables= derived_tables;
2699
2618
lex->all_selects_list= old_all_select_lex;
2700
2619
lex->sql_command= save_sql_command;
2701
thd->no_warnings_for_error= old_value;
2620
session->no_warnings_for_error= old_value;
2706
bool store_schema_shemata(THD* thd, Table *table, LEX_STRING *db_name,
2625
bool store_schema_shemata(Session* session, Table *table, LEX_STRING *db_name,
2707
2626
const CHARSET_INFO * const cs)
2709
2628
restore_record(table, s->default_values);
2710
2629
table->field[1]->store(db_name->str, db_name->length, system_charset_info);
2711
2630
table->field[2]->store(cs->csname, strlen(cs->csname), system_charset_info);
2712
2631
table->field[3]->store(cs->name, strlen(cs->name), system_charset_info);
2713
return schema_table_store_record(thd, table);
2632
return schema_table_store_record(session, table);
2717
int fill_schema_schemata(THD *thd, TableList *tables, COND *cond)
2636
int fill_schema_schemata(Session *session, TableList *tables, COND *cond)
2720
2639
TODO: fill_schema_shemata() is called when new client is connected.
2758
2676
if (with_i_schema) // information schema name is always first in list
2760
if (store_schema_shemata(thd, table, db_name,
2678
if (store_schema_shemata(session, table, db_name,
2761
2679
system_charset_info))
2763
2681
with_i_schema= 0;
2767
load_db_opt_by_name(thd, db_name->str, &create);
2768
if (store_schema_shemata(thd, table, db_name,
2685
HA_CREATE_INFO create;
2686
load_db_opt_by_name(session, db_name->str, &create);
2688
if (store_schema_shemata(session, table, db_name,
2769
2689
create.default_table_charset))
2822
2742
tmp_buff= (char *) ha_resolve_storage_engine_name(tmp_db_type);
2823
2743
table->field[4]->store(tmp_buff, strlen(tmp_buff), cs);
2824
table->field[5]->store((int64_t) share->frm_version, true);
2744
table->field[5]->store((int64_t) 0, true);
2826
2746
ptr=option_buff;
2827
2747
if (share->min_rows)
2829
ptr=my_stpcpy(ptr," min_rows=");
2830
ptr=int64_t10_to_str(share->min_rows,ptr,10);
2749
ptr= strcpy(ptr," min_rows=")+10;
2750
ptr= int64_t10_to_str(share->min_rows,ptr,10);
2832
2752
if (share->max_rows)
2834
ptr=my_stpcpy(ptr," max_rows=");
2835
ptr=int64_t10_to_str(share->max_rows,ptr,10);
2754
ptr= strcpy(ptr," max_rows=")+10;
2755
ptr= int64_t10_to_str(share->max_rows,ptr,10);
2837
2757
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);
2759
ptr= strcpy(ptr," avg_row_length=")+16;
2760
ptr= int64_t10_to_str(share->avg_row_length,ptr,10);
2842
2762
if (share->db_create_options & HA_OPTION_PACK_KEYS)
2843
ptr=my_stpcpy(ptr," pack_keys=1");
2763
ptr= strcpy(ptr," pack_keys=1")+12;
2844
2764
if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
2845
ptr=my_stpcpy(ptr," pack_keys=0");
2765
ptr= strcpy(ptr," pack_keys=0")+12;
2846
2766
/* We use CHECKSUM, instead of TABLE_CHECKSUM, for backward compability */
2847
2767
if (share->db_create_options & HA_OPTION_CHECKSUM)
2848
ptr=my_stpcpy(ptr," checksum=1");
2768
ptr= strcpy(ptr," checksum=1")+11;
2849
2769
if (share->page_checksum != HA_CHOICE_UNDEF)
2850
ptr= strxmov(ptr, " page_checksum=",
2851
ha_choice_values[(uint) share->page_checksum], NULL);
2770
ptr+= sprintf(ptr, " page_checksum=%s",
2771
ha_choice_values[(uint) share->page_checksum]);
2852
2772
if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
2853
ptr=my_stpcpy(ptr," delay_key_write=1");
2773
ptr= strcpy(ptr," delay_key_write=1")+18;
2854
2774
if (share->row_type != ROW_TYPE_DEFAULT)
2855
ptr=strxmov(ptr, " row_format=",
2856
ha_row_type[(uint) share->row_type],
2775
ptr+= sprintf(ptr, " row_format=%s", ha_row_type[(uint)share->row_type]);
2858
2776
if (share->block_size)
2860
ptr= my_stpcpy(ptr, " block_size=");
2778
ptr= strcpy(ptr, " block_size=")+12;
2861
2779
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
2782
table->field[19]->store(option_buff+1,
2874
(ptr == option_buff ? 0 :
2783
(ptr == option_buff ? 0 :
2875
2784
(uint) (ptr-option_buff)-1), cs);
2877
2786
tmp_buff= (share->table_charset ?
2937
2846
if (file->stats.create_time)
2939
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2940
(my_time_t) file->stats.create_time);
2848
session->variables.time_zone->gmt_sec_to_TIME(&time,
2849
(time_t) file->stats.create_time);
2941
2850
table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2942
2851
table->field[14]->set_notnull();
2944
2853
if (file->stats.update_time)
2946
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2947
(my_time_t) file->stats.update_time);
2855
session->variables.time_zone->gmt_sec_to_TIME(&time,
2856
(time_t) file->stats.update_time);
2948
2857
table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2949
2858
table->field[15]->set_notnull();
2951
2860
if (file->stats.check_time)
2953
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2954
(my_time_t) file->stats.check_time);
2862
session->variables.time_zone->gmt_sec_to_TIME(&time,
2863
(time_t) file->stats.check_time);
2955
2864
table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2956
2865
table->field[16]->set_notnull();
3201
int fill_schema_charsets(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3110
int fill_schema_charsets(Session *session, TableList *tables, COND *)
3203
3112
CHARSET_INFO **cs;
3204
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3113
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3205
3114
Table *table= tables->table;
3206
3115
const CHARSET_INFO * const scs= system_charset_info;
3208
3117
for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
3210
3119
const CHARSET_INFO * const tmp_cs= cs[0];
3211
if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) &&
3120
if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) &&
3212
3121
(tmp_cs->state & MY_CS_AVAILABLE) &&
3213
3122
!(tmp_cs->state & MY_CS_HIDDEN) &&
3214
3123
!(wild && wild[0] &&
3281
3190
CHARSET_INFO **cl;
3282
3191
const CHARSET_INFO *tmp_cs= cs[0];
3283
if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3192
if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3284
3193
!(tmp_cs->state & MY_CS_PRIMARY))
3286
3195
for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3288
3197
const CHARSET_INFO *tmp_cl= cl[0];
3289
if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3198
if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3290
3199
!my_charset_same(tmp_cs,tmp_cl))
3292
3201
restore_record(table, s->default_values);
3293
3202
table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3294
3203
table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3295
if (schema_table_store_record(thd, table))
3204
if (schema_table_store_record(session, table))
3384
3293
table->field[14]->store("", 0, cs);
3385
3294
table->field[14]->set_notnull();
3386
assert(test(key_info->flags & HA_USES_COMMENT) ==
3295
assert(test(key_info->flags & HA_USES_COMMENT) ==
3387
3296
(key_info->comment.length > 0));
3388
3297
if (key_info->flags & HA_USES_COMMENT)
3389
table->field[15]->store(key_info->comment.str,
3298
table->field[15]->store(key_info->comment.str,
3390
3299
key_info->comment.length, cs);
3391
if (schema_table_store_record(thd, table))
3300
if (schema_table_store_record(session, table))
3408
3317
table->field[3]->store(db_name->str, db_name->length, cs);
3409
3318
table->field[4]->store(table_name->str, table_name->length, cs);
3410
3319
table->field[5]->store(con_type, con_len, cs);
3411
return schema_table_store_record(thd, table);
3320
return schema_table_store_record(session, table);
3415
static int get_schema_constraints_record(THD *thd, TableList *tables,
3324
static int get_schema_constraints_record(Session *session, TableList *tables,
3416
3325
Table *table, bool res,
3417
3326
LEX_STRING *db_name,
3418
3327
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());
3331
if (session->is_error())
3332
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3333
session->main_da.sql_errno(), session->main_da.message());
3334
session->clear_error();
3439
3348
if (i != primary_key && !(key_info->flags & HA_NOSAME))
3442
if (i == primary_key && !strcmp(key_info->name, primary_key_name))
3351
if (i == primary_key && is_primary_key(key_info))
3444
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,
3445
3354
strlen(key_info->name),
3446
3355
STRING_WITH_LEN("PRIMARY KEY")))
3449
3358
else if (key_info->flags & HA_NOSAME)
3451
if (store_constraints(thd, table, db_name, table_name, key_info->name,
3360
if (store_constraints(session, table, db_name, table_name, key_info->name,
3452
3361
strlen(key_info->name),
3453
3362
STRING_WITH_LEN("UNIQUE")))
3458
show_table->file->get_foreign_key_list(thd, &f_key_list);
3367
show_table->file->get_foreign_key_list(session, &f_key_list);
3459
3368
FOREIGN_KEY_INFO *f_key_info;
3460
3369
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3461
3370
while ((f_key_info=it++))
3463
if (store_constraints(thd, table, db_name, table_name,
3372
if (store_constraints(session, table, db_name, table_name,
3464
3373
f_key_info->forein_id->str,
3465
3374
strlen(f_key_info->forein_id->str),
3466
3375
"FOREIGN KEY", 11))
3523
3432
restore_record(table, s->default_values);
3524
3433
store_key_column_usage(table, db_name, table_name,
3525
3434
key_info->name,
3526
strlen(key_info->name),
3527
key_part->field->field_name,
3435
strlen(key_info->name),
3436
key_part->field->field_name,
3528
3437
strlen(key_part->field->field_name),
3529
3438
(int64_t) f_idx);
3530
if (schema_table_store_record(thd, table))
3439
if (schema_table_store_record(session, table))
3536
show_table->file->get_foreign_key_list(thd, &f_key_list);
3445
show_table->file->get_foreign_key_list(session, &f_key_list);
3537
3446
FOREIGN_KEY_INFO *f_key_info;
3538
3447
List_iterator_fast<FOREIGN_KEY_INFO> fkey_it(f_key_list);
3539
3448
while ((f_key_info= fkey_it++))
3560
3469
system_charset_info);
3561
3470
table->field[9]->set_notnull();
3562
3471
table->field[10]->store(f_key_info->referenced_table->str,
3563
f_key_info->referenced_table->length,
3472
f_key_info->referenced_table->length,
3564
3473
system_charset_info);
3565
3474
table->field[10]->set_notnull();
3566
3475
table->field[11]->store(r_info->str, r_info->length,
3567
3476
system_charset_info);
3568
3477
table->field[11]->set_notnull();
3569
if (schema_table_store_record(thd, table))
3478
if (schema_table_store_record(session, table))
3578
int fill_open_tables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3487
int fill_open_tables(Session *session, TableList *tables, COND *)
3580
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3489
const char *wild= session->lex->wild ? session->lex->wild->ptr() : NULL;
3581
3490
Table *table= tables->table;
3582
3491
const CHARSET_INFO * const cs= system_charset_info;
3583
3492
OPEN_TableList *open_list;
3584
if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3585
&& thd->is_fatal_error)
3493
if (!(open_list=list_open_tables(session->lex->select_lex.db, wild))
3494
&& session->is_fatal_error)
3588
3497
for (; open_list ; open_list=open_list->next)
3592
3501
table->field[1]->store(open_list->table, strlen(open_list->table), cs);
3593
3502
table->field[2]->store((int64_t) open_list->in_use, true);
3594
3503
table->field[3]->store((int64_t) open_list->locked, true);
3595
if (schema_table_store_record(thd, table))
3504
if (schema_table_store_record(session, table))
3602
int fill_variables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3511
int fill_variables(Session *session, TableList *tables, COND *)
3514
LEX *lex= session->lex;
3606
3515
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3607
3516
enum enum_schema_tables schema_table_idx=
3608
3517
get_schema_table_idx(tables->schema_table);
3614
3523
schema_table_idx == SCH_GLOBAL_VARIABLES)
3615
3524
option_type= OPT_GLOBAL;
3617
rw_rdlock(&LOCK_system_variables_hash);
3618
res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars),
3526
pthread_rwlock_rdlock(&LOCK_system_variables_hash);
3527
res= show_status_array(session, wild, enumerate_sys_vars(session, sorted_vars),
3619
3528
option_type, NULL, "", tables->table, upper_case_names);
3620
rw_unlock(&LOCK_system_variables_hash);
3529
pthread_rwlock_unlock(&LOCK_system_variables_hash);
3625
int fill_status(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3534
int fill_status(Session *session, TableList *tables, COND *)
3536
LEX *lex= session->lex;
3628
3537
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3630
3539
STATUS_VAR *tmp1, tmp;
3651
3560
option_type= OPT_SESSION;
3652
tmp1= &thd->status_var;
3561
tmp1= &session->status_var;
3655
3564
pthread_mutex_lock(&LOCK_status);
3656
3565
if (option_type == OPT_GLOBAL)
3657
3566
calc_sum_of_all_status(&tmp);
3658
res= show_status_array(thd, wild,
3567
res= show_status_array(session, wild,
3659
3568
(SHOW_VAR *)all_status_vars.buffer,
3660
3569
option_type, tmp1, "", tables->table,
3661
3570
upper_case_names);
3694
if (thd->is_error())
3695
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3696
thd->main_da.sql_errno(), thd->main_da.message());
3603
if (session->is_error())
3604
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3605
session->main_da.sql_errno(), session->main_da.message());
3606
session->clear_error();
3702
3611
List<FOREIGN_KEY_INFO> f_key_list;
3703
3612
Table *show_table= tables->table;
3704
show_table->file->info(HA_STATUS_VARIABLE |
3613
show_table->file->info(HA_STATUS_VARIABLE |
3705
3614
HA_STATUS_NO_LOCK |
3706
3615
HA_STATUS_TIME);
3708
show_table->file->get_foreign_key_list(thd, &f_key_list);
3617
show_table->file->get_foreign_key_list(session, &f_key_list);
3709
3618
FOREIGN_KEY_INFO *f_key_info;
3710
3619
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3711
3620
while ((f_key_info= it++))
3715
3624
table->field[9]->store(table_name->str, table_name->length, cs);
3716
3625
table->field[2]->store(f_key_info->forein_id->str,
3717
3626
f_key_info->forein_id->length, cs);
3718
table->field[4]->store(f_key_info->referenced_db->str,
3627
table->field[4]->store(f_key_info->referenced_db->str,
3719
3628
f_key_info->referenced_db->length, cs);
3720
table->field[10]->store(f_key_info->referenced_table->str,
3629
table->field[10]->store(f_key_info->referenced_table->str,
3721
3630
f_key_info->referenced_table->length, cs);
3722
3631
if (f_key_info->referenced_key_name)
3724
table->field[5]->store(f_key_info->referenced_key_name->str,
3633
table->field[5]->store(f_key_info->referenced_key_name->str,
3725
3634
f_key_info->referenced_key_name->length, cs);
3726
3635
table->field[5]->set_notnull();
3729
3638
table->field[5]->set_null();
3730
3639
table->field[6]->store(STRING_WITH_LEN("NONE"), cs);
3731
table->field[7]->store(f_key_info->update_method->str,
3640
table->field[7]->store(f_key_info->update_method->str,
3732
3641
f_key_info->update_method->length, cs);
3733
table->field[8]->store(f_key_info->delete_method->str,
3642
table->field[8]->store(f_key_info->delete_method->str,
3734
3643
f_key_info->delete_method->length, cs);
3735
if (schema_table_store_record(thd, table))
3644
if (schema_table_store_record(session, table))
3910
3817
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)));
3820
Tmp_Table_Param *tmp_table_param =
3821
(Tmp_Table_Param*) (session->alloc(sizeof(Tmp_Table_Param)));
3915
3822
tmp_table_param->init();
3916
3823
tmp_table_param->table_charset= cs;
3917
3824
tmp_table_param->field_count= field_count;
3918
3825
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 |
3826
Select_Lex *select_lex= session->lex->current_select;
3827
if (!(table= create_tmp_table(session, tmp_table_param,
3828
field_list, (order_st*) 0, 0, 0,
3829
(select_lex->options | session->options |
3923
3830
TMP_TABLE_ALL_COLUMNS),
3924
3831
HA_POS_ERROR, table_list->alias)))
3926
3833
my_bitmap_map* bitmaps=
3927
(my_bitmap_map*) thd->alloc(bitmap_buffer_size(field_count));
3834
(my_bitmap_map*) session->alloc(bitmap_buffer_size(field_count));
3928
3835
bitmap_init(&table->def_read_set, (my_bitmap_map*) bitmaps, field_count,
3930
3837
table->read_set= &table->def_read_set;
4022
3929
Item_field *field= new Item_field(context,
4023
3930
NULL, NULL, field_info->field_name);
4024
if (add_item_to_list(thd, field))
3931
if (session->add_item_to_list(field))
4026
3933
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4027
if (thd->lex->verbose)
3934
if (session->lex->verbose)
4029
3936
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4030
3937
field_info= &schema_table->fields_info[3];
4031
3938
field= new Item_field(context, NULL, NULL, field_info->field_name);
4032
if (add_item_to_list(thd, field))
3939
if (session->add_item_to_list(field))
4034
3941
field->set_name(field_info->old_name, strlen(field_info->old_name),
4035
3942
system_charset_info);
4041
int make_columns_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
3948
int make_columns_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4043
3950
int fields_arr[]= {3, 14, 13, 6, 15, 5, 16, 17, 18, -1};
4044
3951
int *field_num= fields_arr;
4045
3952
ST_FIELD_INFO *field_info;
4046
Name_resolution_context *context= &thd->lex->select_lex.context;
3953
Name_resolution_context *context= &session->lex->select_lex.context;
4048
3955
for (; *field_num >= 0; field_num++)
4050
3957
field_info= &schema_table->fields_info[*field_num];
4051
if (!thd->lex->verbose && (*field_num == 13 ||
3958
if (!session->lex->verbose && (*field_num == 13 ||
4052
3959
*field_num == 17 ||
4053
3960
*field_num == 18))
4126
4033
table_list->table_name= table->s->table_name.str;
4127
4034
table_list->table_name_length= table->s->table_name.length;
4128
4035
table_list->table= table;
4129
table->next= thd->derived_tables;
4130
thd->derived_tables= table;
4036
table->next= session->derived_tables;
4037
session->derived_tables= table;
4131
4038
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;
4194
4064
We have to make non const db_name & table_name
4195
4065
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,
4067
session->make_lex_string(&db, INFORMATION_SCHEMA_NAME.c_str(),
4068
INFORMATION_SCHEMA_NAME.length(), 0);
4069
session->make_lex_string(&table, schema_table->table_name,
4200
4070
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),
4071
if (schema_table->old_format(session, schema_table) || /* Handle old syntax */
4072
!sel->add_table_to_list(session, new Table_ident(session, db, table, 0),
4203
4073
0, 0, TL_READ))
4320
4190
{"ROW_FORMAT", 10, DRIZZLE_TYPE_VARCHAR, 0, 1, "Row_format", OPEN_FULL_TABLE},
4321
4191
{"TABLE_ROWS", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4322
4192
(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,
4193
{"AVG_ROW_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4324
4194
(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,
4195
{"DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4326
4196
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Data_length", OPEN_FULL_TABLE},
4327
4197
{"MAX_DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4328
4198
(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,
4199
{"INDEX_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4330
4200
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Index_length", OPEN_FULL_TABLE},
4331
4201
{"DATA_FREE", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4332
4202
(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,
4203
{"AUTO_INCREMENT", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG, 0,
4334
4204
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Auto_increment", OPEN_FULL_TABLE},
4335
4205
{"CREATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Create_time", OPEN_FULL_TABLE},
4336
4206
{"UPDATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Update_time", OPEN_FULL_TABLE},
4530
4400
ST_FIELD_INFO plugin_fields_info[]=
4532
{"PLUGIN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name",
4402
{"PLUGIN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name",
4533
4403
SKIP_OPEN_TABLE},
4534
4404
{"PLUGIN_VERSION", 20, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4535
4405
{"PLUGIN_STATUS", 10, DRIZZLE_TYPE_VARCHAR, 0, 0, "Status", SKIP_OPEN_TABLE},
4575
4445
ST_SCHEMA_TABLE schema_tables[]=
4577
{"CHARACTER_SETS", charsets_fields_info, create_schema_table,
4447
{"CHARACTER_SETS", charsets_fields_info, create_schema_table,
4578
4448
fill_schema_charsets, make_character_sets_old_format, 0, -1, -1, 0, 0},
4579
{"COLLATIONS", collation_fields_info, create_schema_table,
4449
{"COLLATIONS", collation_fields_info, create_schema_table,
4580
4450
fill_schema_collation, make_old_format, 0, -1, -1, 0, 0},
4581
4451
{"COLLATION_CHARACTER_SET_APPLICABILITY", coll_charset_app_fields_info,
4582
4452
create_schema_table, fill_schema_coll_charset_app, 0, 0, -1, -1, 0, 0},
4583
{"COLUMNS", columns_fields_info, create_schema_table,
4453
{"COLUMNS", columns_fields_info, create_schema_table,
4584
4454
get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2, 0,
4585
4455
OPTIMIZE_I_S_TABLE},
4586
4456
{"GLOBAL_STATUS", variables_fields_info, create_schema_table,
4605
4475
fill_status, make_old_format, 0, -1, -1, 0, 0},
4606
4476
{"SESSION_VARIABLES", variables_fields_info, create_schema_table,
4607
4477
fill_variables, make_old_format, 0, -1, -1, 0, 0},
4608
{"STATISTICS", stat_fields_info, create_schema_table,
4478
{"STATISTICS", stat_fields_info, create_schema_table,
4609
4479
get_all_tables, make_old_format, get_schema_stat_record, 1, 2, 0,
4610
4480
OPEN_TABLE_ONLY|OPTIMIZE_I_S_TABLE},
4611
{"STATUS", variables_fields_info, create_schema_table, fill_status,
4481
{"STATUS", variables_fields_info, create_schema_table, fill_status,
4612
4482
make_old_format, 0, -1, -1, 1, 0},
4613
{"TABLES", tables_fields_info, create_schema_table,
4483
{"TABLES", tables_fields_info, create_schema_table,
4614
4484
get_all_tables, make_old_format, get_schema_tables_record, 1, 2, 0,
4615
4485
OPTIMIZE_I_S_TABLE},
4616
4486
{"TABLE_CONSTRAINTS", table_constraints_fields_info, create_schema_table,
4633
4503
ST_SCHEMA_TABLE *schema_table;
4635
if (!(schema_table= (ST_SCHEMA_TABLE *)my_malloc(sizeof(ST_SCHEMA_TABLE),
4636
MYF(MY_WME | MY_ZEROFILL))))
4505
if ((schema_table= new ST_SCHEMA_TABLE) == NULL)
4507
memset(schema_table, 0, sizeof(ST_SCHEMA_TABLE));
4638
4509
/* Historical Requirement */
4639
4510
plugin->data= schema_table; // shortcut for the future
4640
4511
if (plugin->plugin->init)
4642
4513
schema_table->create_table= create_schema_table;
4643
4514
schema_table->old_format= make_old_format;
4644
schema_table->idx_field1= -1,
4645
schema_table->idx_field2= -1;
4515
schema_table->idx_field1= -1,
4516
schema_table->idx_field2= -1;
4647
4518
/* Make the name available to the init() function. */
4648
4519
schema_table->table_name= plugin->name.str;
4650
4521
if (plugin->plugin->init(schema_table))
4652
sql_print_error(_("Plugin '%s' init function returned error."),
4523
errmsg_printf(ERRMSG_LVL_ERROR,
4524
_("Plugin '%s' init function returned error."),
4657
4529
/* Make sure the plugin name is not set inside the init() function. */
4658
4530
schema_table->table_name= plugin->name.str;
4533
plugin->state= PLUGIN_IS_READY;
4537
delete schema_table;
4667
4542
int finalize_schema_table(st_plugin_int *plugin)