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>
24
#define STR_OR_NIL(S) ((S) ? (S) : "<nil>")
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/cmpfunc.h>
32
#include <drizzled/item/return_int.h>
33
#include <drizzled/item/empty_string.h>
34
#include <drizzled/item/return_date_time.h>
35
#include <drizzled/virtual_column_info.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>
51
str_or_nil(const char *str)
53
return str ? str : "<nil>";
26
56
/* Match the values of enum ha_choice */
27
57
static const char *ha_choice_values[] = {"", "0", "1"};
29
static void store_key_options(THD *thd, String *packet, TABLE *table,
59
static void store_key_options(Session *session, String *packet, Table *table,
150
180
switch (plug->license) {
151
181
case PLUGIN_LICENSE_GPL:
152
table->field[7]->store(PLUGIN_LICENSE_GPL_STRING,
182
table->field[7]->store(PLUGIN_LICENSE_GPL_STRING,
153
183
strlen(PLUGIN_LICENSE_GPL_STRING), cs);
155
185
case PLUGIN_LICENSE_BSD:
156
table->field[7]->store(PLUGIN_LICENSE_BSD_STRING,
186
table->field[7]->store(PLUGIN_LICENSE_BSD_STRING,
157
187
strlen(PLUGIN_LICENSE_BSD_STRING), cs);
160
table->field[7]->store(PLUGIN_LICENSE_PROPRIETARY_STRING,
190
table->field[7]->store(PLUGIN_LICENSE_PROPRIETARY_STRING,
161
191
strlen(PLUGIN_LICENSE_PROPRIETARY_STRING), cs);
164
194
table->field[7]->set_notnull();
166
return schema_table_store_record(thd, table);
196
return schema_table_store_record(session, table);
170
int fill_plugins(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
200
int fill_plugins(Session *session, TableList *tables, COND *)
172
TABLE *table= tables->table;
202
Table *table= tables->table;
174
if (plugin_foreach_with_mask(thd, show_plugins, DRIZZLE_ANY_PLUGIN,
204
if (plugin_foreach_with_mask(session, show_plugins, DRIZZLE_ANY_PLUGIN,
175
205
~PLUGIN_IS_FREED, table))
301
mysqld_show_create(THD *thd, TABLE_LIST *table_list)
331
mysqld_show_create(Session *session, TableList *table_list)
303
Protocol *protocol= thd->protocol;
333
Protocol *protocol= session->protocol;
305
335
String buffer(buff, sizeof(buff), system_charset_info);
307
337
/* Only one table for now, but VIEW can involve several tables */
308
if (open_normal_and_derived_tables(thd, table_list, 0))
338
if (open_normal_and_derived_tables(session, table_list, 0))
310
if (thd->is_error() && thd->main_da.sql_errno() != ER_VIEW_INVALID)
340
if (session->is_error())
314
344
Clear all messages with 'error' level status and
315
issue a warning with 'warning' level status in
345
issue a warning with 'warning' level status in
316
346
case of invalid view and last error is ER_VIEW_INVALID
318
drizzle_reset_errors(thd, true);
348
drizzle_reset_errors(session, true);
349
session->clear_error();
322
352
buffer.length(0);
324
if (store_create_info(thd, table_list, &buffer, NULL))
354
if (store_create_info(session, table_list, &buffer, NULL))
327
357
List<Item> field_list;
537
567
# Quote character
540
int get_quote_char_for_identifier(THD *thd, const char *name, uint length)
570
int get_quote_char_for_identifier(Session *session, const char *name, uint32_t length)
543
573
!is_keyword(name,length) &&
544
574
!require_quotes(name, length) &&
545
!(thd->options & OPTION_QUOTE_SHOW_CREATE))
575
!(session->options & OPTION_QUOTE_SHOW_CREATE))
551
581
/* Append directory name (if exists) to CREATE INFO */
553
static void append_directory(THD *thd __attribute__((unused)),
583
static void append_directory(Session *,
554
584
String *packet, const char *dir_type,
555
const char *filename)
585
const char *filename)
559
uint length= dirname_length(filename);
589
uint32_t length= dirname_length(filename);
560
590
packet->append(' ');
561
591
packet->append(dir_type);
562
592
packet->append(STRING_WITH_LEN(" DIRECTORY='"));
636
666
to tailor the format of the statement. Can be
637
667
NULL, in which case only SQL_MODE is considered
638
668
when building the statement.
641
671
Currently always return 0, but might return error code in the
648
int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
678
int store_create_info(Session *session, TableList *table_list, String *packet,
649
679
HA_CREATE_INFO *create_info_arg)
651
681
List<Item> field_list;
652
char tmp[MAX_FIELD_WIDTH], *for_str, buff[128], def_value_buf[MAX_FIELD_WIDTH];
682
char tmp[MAX_FIELD_WIDTH], *for_str, def_value_buf[MAX_FIELD_WIDTH];
653
683
const char *alias;
654
685
String type(tmp, sizeof(tmp), system_charset_info);
655
686
String def_value(def_value_buf, sizeof(def_value_buf), system_charset_info);
656
687
Field **ptr,*field;
688
uint32_t primary_key;
659
TABLE *table= table_list->table;
690
Table *table= table_list->table;
660
691
handler *file= table->file;
661
692
TABLE_SHARE *share= table->s;
662
693
HA_CREATE_INFO create_info;
683
714
alias= share->table_name.str;
686
append_identifier(thd, packet, alias, strlen(alias));
717
append_identifier(session, packet, alias, strlen(alias));
687
718
packet->append(STRING_WITH_LEN(" (\n"));
689
720
We need this to get default values from the table
690
721
We have to restore the read_set if we are called from insert in case
691
722
of row based replication.
693
old_map= tmp_use_all_columns(table, table->read_set);
724
old_map= table->use_all_columns(table->read_set);
695
726
for (ptr=table->field ; (field= *ptr); ptr++)
697
uint flags = field->flags;
728
uint32_t flags = field->flags;
699
730
if (ptr != table->field)
700
731
packet->append(STRING_WITH_LEN(",\n"));
702
733
packet->append(STRING_WITH_LEN(" "));
703
append_identifier(thd,packet,field->field_name, strlen(field->field_name));
734
append_identifier(session,packet,field->field_name, strlen(field->field_name));
704
735
packet->append(' ');
705
736
// check for surprises from the previous call to Field::sql_type()
706
737
if (type.ptr() != tmp)
805
853
packet->append(STRING_WITH_LEN("KEY "));
807
855
if (!found_primary)
808
append_identifier(thd, packet, key_info->name, strlen(key_info->name));
856
append_identifier(session, packet, key_info->name, strlen(key_info->name));
810
858
packet->append(STRING_WITH_LEN(" ("));
812
for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
860
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
815
863
packet->append(',');
817
865
if (key_part->field)
818
append_identifier(thd,packet,key_part->field->field_name,
866
append_identifier(session,packet,key_part->field->field_name,
819
867
strlen(key_part->field->field_name));
820
868
if (key_part->field &&
821
869
(key_part->length !=
822
870
table->field[key_part->fieldnr-1]->key_length()))
826
end= int10_to_str((long) key_part->length /
827
key_part->field->charset()->mbmaxlen,
830
packet->append(buff,(uint) (end-buff));
873
buff= to_string(buff, (int32_t) key_part->length /
874
key_part->field->charset()->mbmaxlen);
876
packet->append(buff.c_str(), buff.length());
833
879
packet->append(')');
834
store_key_options(thd, packet, table, key_info);
880
store_key_options(session, packet, table, key_info);
878
924
if (create_info.auto_increment_value > 1)
881
926
packet->append(STRING_WITH_LEN(" AUTO_INCREMENT="));
882
end= int64_t10_to_str(create_info.auto_increment_value, buff,10);
883
packet->append(buff, (uint) (end - buff));
887
if (share->table_charset)
891
THEN add DEFAULT CHARSET only if it was used when creating the table
893
if (!create_info_arg ||
894
(create_info_arg->used_fields & HA_CREATE_USED_DEFAULT_CHARSET))
896
packet->append(STRING_WITH_LEN(" DEFAULT CHARSET="));
897
packet->append(share->table_charset->csname);
898
if (!(share->table_charset->state & MY_CS_PRIMARY))
900
packet->append(STRING_WITH_LEN(" COLLATE="));
901
packet->append(table->s->table_charset->name);
927
buff= to_string(create_info.auto_increment_value);
928
packet->append(buff.c_str(), buff.length());
906
931
if (share->min_rows)
909
933
packet->append(STRING_WITH_LEN(" MIN_ROWS="));
910
end= int64_t10_to_str(share->min_rows, buff, 10);
911
packet->append(buff, (uint) (end- buff));
934
buff= to_string(share->min_rows);
935
packet->append(buff.c_str(), buff.length());
914
938
if (share->max_rows && !table_list->schema_table)
917
940
packet->append(STRING_WITH_LEN(" MAX_ROWS="));
918
end= int64_t10_to_str(share->max_rows, buff, 10);
919
packet->append(buff, (uint) (end - buff));
941
buff= to_string(share->max_rows);
942
packet->append(buff.c_str(), buff.length());
922
945
if (share->avg_row_length)
925
947
packet->append(STRING_WITH_LEN(" AVG_ROW_LENGTH="));
926
end= int64_t10_to_str(share->avg_row_length, buff,10);
927
packet->append(buff, (uint) (end - buff));
948
buff= to_string(share->avg_row_length);
949
packet->append(buff.c_str(), buff.length());
930
952
if (share->db_create_options & HA_OPTION_PACK_KEYS)
996
1016
the resulting CREATE statement contains "IF NOT EXISTS" clause. Other flags
997
1017
in @c create_options are ignored.
999
@param thd The current thread instance.
1019
@param session The current thread instance.
1000
1020
@param dbname The name of the database.
1001
1021
@param buffer A String instance where the statement is stored.
1002
@param create_info If not NULL, the options member influences the resulting
1022
@param create_info If not NULL, the options member influences the resulting
1003
1023
CRATE statement.
1005
1025
@returns true if errors are detected, false otherwise.
1008
bool store_db_create_info(THD *thd, const char *dbname, String *buffer,
1028
bool store_db_create_info(Session *session, const char *dbname, String *buffer,
1009
1029
HA_CREATE_INFO *create_info)
1011
1031
HA_CREATE_INFO create;
1012
uint create_options = create_info ? create_info->options : 0;
1032
uint32_t create_options = create_info ? create_info->options : 0;
1014
1034
if (!my_strcasecmp(system_charset_info, dbname,
1015
INFORMATION_SCHEMA_NAME.str))
1035
INFORMATION_SCHEMA_NAME.c_str()))
1017
dbname= INFORMATION_SCHEMA_NAME.str;
1037
dbname= INFORMATION_SCHEMA_NAME.c_str();
1018
1038
create.default_table_charset= system_charset_info;
1132
1151
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
1135
VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
1154
pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
1155
if (!session->killed)
1138
I_List_iterator<THD> it(threads);
1157
I_List_iterator<Session> it(threads);
1140
1159
while ((tmp=it++))
1142
Security_context *tmp_sctx= tmp->security_ctx;
1161
Security_context *tmp_sctx= &tmp->security_ctx;
1143
1162
struct st_my_thread_var *mysys_var;
1144
if ((tmp->vio_ok() || tmp->system_thread) && (!user || (tmp_sctx->user && !strcmp(tmp_sctx->user, user))))
1163
if ((tmp->vio_ok() || tmp->system_thread) && (!user || (tmp_sctx->user.c_str() && !strcmp(tmp_sctx->user.c_str(), user))))
1146
thread_info *thd_info= new thread_info;
1165
thread_info *session_info= new thread_info;
1148
thd_info->thread_id=tmp->thread_id;
1149
thd_info->user= thd->strdup(tmp_sctx->user ? tmp_sctx->user :
1167
session_info->thread_id=tmp->thread_id;
1168
session_info->user= session->strdup(tmp_sctx->user.c_str() ? tmp_sctx->user.c_str() :
1150
1169
(tmp->system_thread ?
1151
1170
"system user" : "unauthenticated user"));
1152
thd_info->host= thd->strdup(tmp_sctx->ip);
1153
if ((thd_info->db=tmp->db)) // Safe test
1154
thd_info->db=thd->strdup(thd_info->db);
1155
thd_info->command=(int) tmp->command;
1171
session_info->host= session->strdup(tmp_sctx->ip.c_str());
1172
if ((session_info->db=tmp->db)) // Safe test
1173
session_info->db=session->strdup(session_info->db);
1174
session_info->command=(int) tmp->command;
1156
1175
if ((mysys_var= tmp->mysys_var))
1157
1176
pthread_mutex_lock(&mysys_var->mutex);
1158
thd_info->proc_info= (char*) (tmp->killed == THD::KILL_CONNECTION? "Killed" : 0);
1159
thd_info->state_info= (char*) (tmp->net.reading_or_writing ?
1177
session_info->proc_info= (char*) (tmp->killed == Session::KILL_CONNECTION? "Killed" : 0);
1178
session_info->state_info= (char*) (tmp->net.reading_or_writing ?
1160
1179
(tmp->net.reading_or_writing == 2 ?
1161
1180
"Writing to net" :
1162
thd_info->command == COM_SLEEP ? NullS :
1181
session_info->command == COM_SLEEP ? NULL :
1163
1182
"Reading from net") :
1164
tmp->proc_info ? tmp->proc_info :
1183
tmp->get_proc_info() ? tmp->get_proc_info() :
1165
1184
tmp->mysys_var &&
1166
1185
tmp->mysys_var->current_cond ?
1167
"Waiting on cond" : NullS);
1186
"Waiting on cond" : NULL);
1169
1188
pthread_mutex_unlock(&mysys_var->mutex);
1171
thd_info->start_time= tmp->start_time;
1190
session_info->start_time= tmp->start_time;
1191
session_info->query=0;
1173
1192
if (tmp->query)
1176
1195
query_length is always set to 0 when we set query = NULL; see
1177
the comment in sql_class.h why this prevents crashes in possible
1196
the comment in session.h why this prevents crashes in possible
1178
1197
races with query_length
1180
uint length= min((uint32_t)max_query_length, tmp->query_length);
1181
thd_info->query=(char*) thd->strmake(tmp->query,length);
1199
uint32_t length= cmin((uint32_t)max_query_length, tmp->query_length);
1200
session_info->query=(char*) session->strmake(tmp->query,length);
1183
thread_infos.append(thd_info);
1202
thread_infos.append(session_info);
1187
VOID(pthread_mutex_unlock(&LOCK_thread_count));
1206
pthread_mutex_unlock(&LOCK_thread_count);
1189
thread_info *thd_info;
1190
time_t now= my_time(0);
1191
while ((thd_info=thread_infos.get()))
1208
thread_info *session_info;
1209
time_t now= time(NULL);
1210
while ((session_info=thread_infos.get()))
1193
1212
protocol->prepare_for_resend();
1194
protocol->store((uint64_t) thd_info->thread_id);
1195
protocol->store(thd_info->user, system_charset_info);
1196
protocol->store(thd_info->host, system_charset_info);
1197
protocol->store(thd_info->db, system_charset_info);
1198
if (thd_info->proc_info)
1199
protocol->store(thd_info->proc_info, system_charset_info);
1213
protocol->store((uint64_t) session_info->thread_id);
1214
protocol->store(session_info->user, system_charset_info);
1215
protocol->store(session_info->host, system_charset_info);
1216
protocol->store(session_info->db, system_charset_info);
1217
if (session_info->proc_info)
1218
protocol->store(session_info->proc_info, system_charset_info);
1201
protocol->store(command_name[thd_info->command].str, system_charset_info);
1202
if (thd_info->start_time)
1203
protocol->store((uint32_t) (now - thd_info->start_time));
1220
protocol->store(command_name[session_info->command].str, system_charset_info);
1221
if (session_info->start_time)
1222
protocol->store((uint32_t) (now - session_info->start_time));
1205
1224
protocol->store_null();
1206
protocol->store(thd_info->state_info, system_charset_info);
1207
protocol->store(thd_info->query, system_charset_info);
1225
protocol->store(session_info->state_info, system_charset_info);
1226
protocol->store(session_info->query, system_charset_info);
1208
1227
if (protocol->write())
1209
1228
break; /* purecov: inspected */
1215
int fill_schema_processlist(THD* thd, TABLE_LIST* tables,
1216
COND* cond __attribute__((unused)))
1234
int fill_schema_processlist(Session* session, TableList* tables, COND*)
1218
TABLE *table= tables->table;
1236
Table *table= tables->table;
1219
1237
const CHARSET_INFO * const cs= system_charset_info;
1221
time_t now= my_time(0);
1225
VOID(pthread_mutex_lock(&LOCK_thread_count));
1239
time_t now= time(NULL);
1241
if (now == (time_t)-1)
1246
pthread_mutex_lock(&LOCK_thread_count);
1248
if (!session->killed)
1229
I_List_iterator<THD> it(threads);
1250
I_List_iterator<Session> it(threads);
1232
1253
while ((tmp= it++))
1234
Security_context *tmp_sctx= tmp->security_ctx;
1255
Security_context *tmp_sctx= &tmp->security_ctx;
1235
1256
struct st_my_thread_var *mysys_var;
1236
1257
const char *val;
1702
int make_table_list(THD *thd, SELECT_LEX *sel,
1734
int make_table_list(Session *session, SELECT_LEX *sel,
1703
1735
LEX_STRING *db_name, LEX_STRING *table_name)
1705
1737
Table_ident *table_ident;
1706
table_ident= new Table_ident(thd, *db_name, *table_name, 1);
1738
table_ident= new Table_ident(session, *db_name, *table_name, 1);
1707
1739
sel->init_query();
1708
if (!sel->add_table_to_list(thd, table_ident, 0, 0, TL_READ))
1740
if (!sel->add_table_to_list(session, table_ident, 0, 0, TL_READ))
1715
@brief Get lookup value from the part of 'WHERE' condition
1747
@brief Get lookup value from the part of 'WHERE' condition
1717
@details This function gets lookup value from
1718
the part of 'WHERE' condition if it's possible and
1749
@details This function gets lookup value from
1750
the part of 'WHERE' condition if it's possible and
1719
1751
fill appropriate lookup_field_vals struct field
1720
1752
with this value.
1722
@param[in] thd thread handler
1754
@param[in] session thread handler
1723
1755
@param[in] item_func part of WHERE condition
1724
1756
@param[in] table I_S table
1725
@param[in, out] lookup_field_vals Struct which holds lookup values
1757
@param[in, out] lookup_field_vals Struct which holds lookup values
1729
1761
1 error, there can be no matching records for the condition
1732
bool get_lookup_value(THD *thd, Item_func *item_func,
1764
bool get_lookup_value(Session *session, Item_func *item_func,
1734
1766
LOOKUP_FIELD_VALUES *lookup_field_vals)
1736
1768
ST_SCHEMA_TABLE *schema_table= table->schema_table;
1776
1808
/* Lookup value is database name */
1777
if (!cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
1778
(uchar *) item_field->field_name,
1809
if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
1810
(unsigned char *) item_field->field_name,
1779
1811
strlen(item_field->field_name), 0))
1781
thd->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1813
session->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1782
1814
tmp_str->length(), false);
1784
1816
/* Lookup value is table name */
1785
else if (!cs->coll->strnncollsp(cs, (uchar *) field_name2,
1817
else if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name2,
1786
1818
strlen(field_name2),
1787
(uchar *) item_field->field_name,
1819
(unsigned char *) item_field->field_name,
1788
1820
strlen(item_field->field_name), 0))
1790
thd->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1822
session->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1791
1823
tmp_str->length(), false);
1799
@brief Calculates lookup values from 'WHERE' condition
1831
@brief Calculates lookup values from 'WHERE' condition
1801
1833
@details This function calculates lookup value(database name, table name)
1802
from 'WHERE' condition if it's possible and
1834
from 'WHERE' condition if it's possible and
1803
1835
fill lookup_field_vals struct fields with these values.
1805
@param[in] thd thread handler
1837
@param[in] session thread handler
1806
1838
@param[in] cond WHERE condition
1807
1839
@param[in] table I_S table
1808
@param[in, out] lookup_field_vals Struct which holds lookup values
1840
@param[in, out] lookup_field_vals Struct which holds lookup values
1812
1844
1 error, there can be no matching records for the condition
1815
bool calc_lookup_values_from_cond(THD *thd, COND *cond, TABLE_LIST *table,
1847
bool calc_lookup_values_from_cond(Session *session, COND *cond, TableList *table,
1816
1848
LOOKUP_FIELD_VALUES *lookup_field_vals)
1869
1901
const char *field_name2= schema_table->idx_field2 >= 0 ?
1870
1902
field_info[schema_table->idx_field2].field_name : "";
1871
1903
if (table->table != item_field->field->table ||
1872
(cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
1873
(uchar *) item_field->field_name,
1904
(cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
1905
(unsigned char *) item_field->field_name,
1874
1906
strlen(item_field->field_name), 0) &&
1875
cs->coll->strnncollsp(cs, (uchar *) field_name2, strlen(field_name2),
1876
(uchar *) item_field->field_name,
1907
cs->coll->strnncollsp(cs, (unsigned char *) field_name2, strlen(field_name2),
1908
(unsigned char *) item_field->field_name,
1877
1909
strlen(item_field->field_name), 0)))
1951
1983
from LEX struct and fill lookup_field_vals struct field
1952
1984
with these values.
1954
@param[in] thd thread handler
1986
@param[in] session thread handler
1955
1987
@param[in] cond WHERE condition
1956
1988
@param[in] tables I_S table
1957
@param[in, out] lookup_field_values Struct which holds lookup values
1989
@param[in, out] lookup_field_values Struct which holds lookup values
1961
1993
1 error, there can be no matching records for the condition
1964
bool get_lookup_field_values(THD *thd, COND *cond, TABLE_LIST *tables,
1996
bool get_lookup_field_values(Session *session, COND *cond, TableList *tables,
1965
1997
LOOKUP_FIELD_VALUES *lookup_field_values)
1968
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
1999
LEX *lex= session->lex;
2000
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1969
2001
memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1970
2002
switch (lex->sql_command) {
1971
2003
case SQLCOM_SHOW_DATABASES:
2043
session thread handler
2012
2044
files list of db names
2013
2045
wild wild string
2014
2046
idx_field_vals idx_field_vals->db_name contains db name or
2016
2048
with_i_schema returns 1 if we added 'IS' name to list
2024
int make_db_list(THD *thd, List<LEX_STRING> *files,
2056
int make_db_list(Session *session, List<LEX_STRING> *files,
2025
2057
LOOKUP_FIELD_VALUES *lookup_field_vals,
2026
2058
bool *with_i_schema)
2028
2060
LEX_STRING *i_s_name_copy= 0;
2029
i_s_name_copy= thd->make_lex_string(i_s_name_copy,
2030
INFORMATION_SCHEMA_NAME.str,
2031
INFORMATION_SCHEMA_NAME.length, true);
2061
i_s_name_copy= session->make_lex_string(i_s_name_copy,
2062
INFORMATION_SCHEMA_NAME.c_str(),
2063
INFORMATION_SCHEMA_NAME.length(), true);
2032
2064
*with_i_schema= 0;
2033
2065
if (lookup_field_vals->wild_db_value)
2254
2286
@retval 1 error
2258
fill_schema_show_cols_or_idxs(THD *thd, TABLE_LIST *tables,
2290
fill_schema_show_cols_or_idxs(Session *session, TableList *tables,
2259
2291
ST_SCHEMA_TABLE *schema_table,
2260
2292
Open_tables_state *open_tables_state_backup)
2294
LEX *lex= session->lex;
2264
2296
LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
2265
2297
enum_sql_command save_sql_command= lex->sql_command;
2266
TABLE_LIST *show_table_list= (TABLE_LIST*) tables->schema_select_lex->
2298
TableList *show_table_list= (TableList*) tables->schema_select_lex->
2267
2299
table_list.first;
2268
TABLE *table= tables->table;
2300
Table *table= tables->table;
2271
2303
lex->all_selects_list= tables->schema_select_lex;
2273
Restore thd->temporary_tables to be able to process
2305
Restore session->temporary_tables to be able to process
2274
2306
temporary tables(only for 'show index' & 'show columns').
2275
2307
This should be changed when processing of temporary tables for
2276
2308
I_S tables will be done.
2278
thd->temporary_tables= open_tables_state_backup->temporary_tables;
2310
session->temporary_tables= open_tables_state_backup->temporary_tables;
2280
2312
Let us set fake sql_command so views won't try to merge
2281
2313
themselves into main statement. If we don't do this,
2282
2314
SELECT * from information_schema.xxxx will cause problems.
2283
SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
2315
SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
2285
2317
lex->sql_command= SQLCOM_SHOW_FIELDS;
2286
res= open_normal_and_derived_tables(thd, show_table_list,
2318
res= open_normal_and_derived_tables(session, show_table_list,
2287
2319
DRIZZLE_LOCK_IGNORE_FLUSH);
2288
2320
lex->sql_command= save_sql_command;
2290
2322
get_all_tables() returns 1 on failure and 0 on success thus
2291
2323
return only these and not the result code of ::process_table()
2293
We should use show_table_list->alias instead of
2325
We should use show_table_list->alias instead of
2294
2326
show_table_list->table_name because table_name
2295
2327
could be changed during opening of I_S tables. It's safe
2296
to use alias because alias contains original table name
2297
in this case(this part of code is used only for
2328
to use alias because alias contains original table name
2329
in this case(this part of code is used only for
2298
2330
'show columns' & 'show statistics' commands).
2300
table_name= thd->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2332
table_name= session->make_lex_string(&tmp_lex_string1, show_table_list->alias,
2301
2333
strlen(show_table_list->alias), false);
2302
db_name= thd->make_lex_string(&tmp_lex_string, show_table_list->db,
2334
db_name= session->make_lex_string(&tmp_lex_string, show_table_list->db,
2303
2335
show_table_list->db_length, false);
2306
error= test(schema_table->process_table(thd, show_table_list,
2338
error= test(schema_table->process_table(session, show_table_list,
2307
2339
table, res, db_name,
2309
thd->temporary_tables= 0;
2310
close_tables_for_reopen(thd, &show_table_list);
2341
session->temporary_tables= 0;
2342
close_tables_for_reopen(session, &show_table_list);
2316
@brief Fill I_S table for SHOW TABLE NAMES commands
2348
@brief Fill I_S table for SHOW Table NAMES commands
2318
@param[in] thd thread handler
2319
@param[in] table TABLE struct for I_S table
2350
@param[in] session thread handler
2351
@param[in] table Table struct for I_S table
2320
2352
@param[in] db_name database name
2321
2353
@param[in] table_name table name
2322
2354
@param[in] with_i_schema I_S table if true
2340
enum legacy_db_type not_used;
2341
2372
char path[FN_REFLEN];
2342
(void) build_table_filename(path, sizeof(path), db_name->str,
2373
(void) build_table_filename(path, sizeof(path), db_name->str,
2343
2374
table_name->str, reg_ext, 0);
2344
switch (mysql_frm_type(thd, path, ¬_used)) {
2346
table->field[3]->store(STRING_WITH_LEN("ERROR"),
2347
system_charset_info);
2350
table->field[3]->store(STRING_WITH_LEN("BASE TABLE"),
2351
system_charset_info);
2356
if (thd->is_error() && thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2376
table->field[3]->store(STRING_WITH_LEN("BASE Table"),
2377
system_charset_info);
2379
if (session->is_error() && session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2381
session->clear_error();
2362
if (schema_table_store_record(thd, table))
2385
if (schema_table_store_record(session, table))
2422
2445
open_tables function for this table
2425
static int fill_schema_table_from_frm(THD *thd,TABLE_LIST *tables,
2448
static int fill_schema_table_from_frm(Session *session,TableList *tables,
2426
2449
ST_SCHEMA_TABLE *schema_table,
2427
2450
LEX_STRING *db_name,
2428
2451
LEX_STRING *table_name,
2429
enum enum_schema_tables schema_table_idx __attribute__((unused)))
2452
enum enum_schema_tables)
2431
TABLE *table= tables->table;
2454
Table *table= tables->table;
2432
2455
TABLE_SHARE *share;
2434
TABLE_LIST table_list;
2457
TableList table_list;
2437
2460
char key[MAX_DBKEY_LENGTH];
2461
uint32_t key_length;
2440
memset(&table_list, 0, sizeof(TABLE_LIST));
2441
memset(&tbl, 0, sizeof(TABLE));
2463
memset(&table_list, 0, sizeof(TableList));
2464
memset(&tbl, 0, sizeof(Table));
2443
2466
table_list.table_name= table_name->str;
2444
2467
table_list.db= db_name->str;
2446
key_length= create_table_def_key(thd, key, &table_list, 0);
2469
key_length= create_table_def_key(session, key, &table_list, 0);
2447
2470
pthread_mutex_lock(&LOCK_open);
2448
share= get_table_share(thd, &table_list, key,
2449
key_length, OPEN_VIEW, &error);
2471
share= get_table_share(session, &table_list, key,
2472
key_length, 0, &error);
2505
2528
List<LEX_STRING> db_names;
2506
2529
List_iterator_fast<LEX_STRING> it(db_names);
2507
2530
COND *partial_cond= 0;
2508
uint derived_tables= lex->derived_tables;
2531
uint32_t derived_tables= lex->derived_tables;
2510
2533
Open_tables_state open_tables_state_backup;
2511
2534
Query_tables_list query_tables_list_backup;
2512
uint table_open_method;
2513
bool old_value= thd->no_warnings_for_error;
2515
lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
2535
uint32_t table_open_method;
2536
bool old_value= session->no_warnings_for_error;
2518
2539
We should not introduce deadlocks even if we already have some
2519
2540
tables open and locked, since we won't lock tables which we will
2520
2541
open and will ignore possible name-locks for these tables.
2522
thd->reset_n_backup_open_tables_state(&open_tables_state_backup);
2543
session->reset_n_backup_open_tables_state(&open_tables_state_backup);
2524
2545
schema_table_idx= get_schema_table_idx(schema_table);
2525
2546
tables->table_open_method= table_open_method=
2526
2547
get_table_open_method(tables, schema_table, schema_table_idx);
2528
2549
this branch processes SHOW FIELDS, SHOW INDEXES commands.
2529
2550
see sql_parse.cc, prepare_schema_table() function where
2530
2551
this values are initialized
2532
2553
if (lsel && lsel->table_list.first)
2534
error= fill_schema_show_cols_or_idxs(thd, tables, schema_table,
2555
error= fill_schema_show_cols_or_idxs(session, tables, schema_table,
2535
2556
&open_tables_state_backup);
2539
if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2560
if (get_lookup_field_values(session, cond, tables, &lookup_field_vals))
2640
2661
Set the parent lex of 'sel' because it is needed by
2641
2662
sel.init_query() which is called inside make_table_list.
2643
thd->no_warnings_for_error= 1;
2664
session->no_warnings_for_error= 1;
2644
2665
sel.parent_lex= lex;
2645
2666
/* db_name can be changed in make_table_list() func */
2646
if (!thd->make_lex_string(&orig_db_name, db_name->str,
2667
if (!session->make_lex_string(&orig_db_name, db_name->str,
2647
2668
db_name->length, false))
2649
if (make_table_list(thd, &sel, db_name, table_name))
2670
if (make_table_list(session, &sel, db_name, table_name))
2651
TABLE_LIST *show_table_list= (TABLE_LIST*) sel.table_list.first;
2672
TableList *show_table_list= (TableList*) sel.table_list.first;
2652
2673
lex->all_selects_list= &sel;
2653
2674
lex->derived_tables= 0;
2654
2675
lex->sql_command= SQLCOM_SHOW_FIELDS;
2655
2676
show_table_list->i_s_requested_object=
2656
2677
schema_table->i_s_requested_object;
2657
res= open_normal_and_derived_tables(thd, show_table_list,
2678
res= open_normal_and_derived_tables(session, show_table_list,
2658
2679
DRIZZLE_LOCK_IGNORE_FLUSH);
2659
2680
lex->sql_command= save_sql_command;
2661
2682
XXX: show_table_list has a flag i_is_requested,
2662
2683
and when it's set, open_normal_and_derived_tables()
2663
2684
can return an error without setting an error message
2664
in THD, which is a hack. This is why we have to
2665
check for res, then for thd->is_error() only then
2666
for thd->main_da.sql_errno().
2685
in Session, which is a hack. This is why we have to
2686
check for res, then for session->is_error() only then
2687
for session->main_da.sql_errno().
2668
if (res && thd->is_error() &&
2669
thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2689
if (res && session->is_error() &&
2690
session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2672
2693
Hide error for not existing table.
2675
2696
table does not exist.
2699
session->clear_error();
2683
We should use show_table_list->alias instead of
2704
We should use show_table_list->alias instead of
2684
2705
show_table_list->table_name because table_name
2685
2706
could be changed during opening of I_S tables. It's safe
2686
to use alias because alias contains original table name
2707
to use alias because alias contains original table name
2689
thd->make_lex_string(&tmp_lex_string, show_table_list->alias,
2710
session->make_lex_string(&tmp_lex_string, show_table_list->alias,
2690
2711
strlen(show_table_list->alias), false);
2691
res= schema_table->process_table(thd, show_table_list, table,
2712
res= schema_table->process_table(session, show_table_list, table,
2692
2713
res, &orig_db_name,
2693
2714
&tmp_lex_string);
2694
close_tables_for_reopen(thd, &show_table_list);
2715
close_tables_for_reopen(session, &show_table_list);
2696
2717
assert(!lex->query_tables_own_last);
2712
thd->restore_backup_open_tables_state(&open_tables_state_backup);
2713
lex->restore_backup_query_tables_list(&query_tables_list_backup);
2733
session->restore_backup_open_tables_state(&open_tables_state_backup);
2714
2734
lex->derived_tables= derived_tables;
2715
2735
lex->all_selects_list= old_all_select_lex;
2716
2736
lex->sql_command= save_sql_command;
2717
thd->no_warnings_for_error= old_value;
2737
session->no_warnings_for_error= old_value;
2722
bool store_schema_shemata(THD* thd, TABLE *table, LEX_STRING *db_name,
2742
bool store_schema_shemata(Session* session, Table *table, LEX_STRING *db_name,
2723
2743
const CHARSET_INFO * const cs)
2725
2745
restore_record(table, s->default_values);
2726
2746
table->field[1]->store(db_name->str, db_name->length, system_charset_info);
2727
2747
table->field[2]->store(cs->csname, strlen(cs->csname), system_charset_info);
2728
2748
table->field[3]->store(cs->name, strlen(cs->name), system_charset_info);
2729
return schema_table_store_record(thd, table);
2749
return schema_table_store_record(session, table);
2733
int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond)
2753
int fill_schema_schemata(Session *session, TableList *tables, COND *cond)
2736
2756
TODO: fill_schema_shemata() is called when new client is connected.
2838
2858
tmp_buff= (char *) ha_resolve_storage_engine_name(tmp_db_type);
2839
2859
table->field[4]->store(tmp_buff, strlen(tmp_buff), cs);
2840
table->field[5]->store((int64_t) share->frm_version, true);
2860
table->field[5]->store((int64_t) 0, true);
2842
2862
ptr=option_buff;
2843
2863
if (share->min_rows)
2845
ptr=stpcpy(ptr," min_rows=");
2846
ptr=int64_t10_to_str(share->min_rows,ptr,10);
2865
ptr= strcpy(ptr," min_rows=")+10;
2866
ptr= int64_t10_to_str(share->min_rows,ptr,10);
2848
2868
if (share->max_rows)
2850
ptr=stpcpy(ptr," max_rows=");
2851
ptr=int64_t10_to_str(share->max_rows,ptr,10);
2870
ptr= strcpy(ptr," max_rows=")+10;
2871
ptr= int64_t10_to_str(share->max_rows,ptr,10);
2853
2873
if (share->avg_row_length)
2855
ptr=stpcpy(ptr," avg_row_length=");
2856
ptr=int64_t10_to_str(share->avg_row_length,ptr,10);
2875
ptr= strcpy(ptr," avg_row_length=")+16;
2876
ptr= int64_t10_to_str(share->avg_row_length,ptr,10);
2858
2878
if (share->db_create_options & HA_OPTION_PACK_KEYS)
2859
ptr=stpcpy(ptr," pack_keys=1");
2879
ptr= strcpy(ptr," pack_keys=1")+12;
2860
2880
if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
2861
ptr=stpcpy(ptr," pack_keys=0");
2881
ptr= strcpy(ptr," pack_keys=0")+12;
2862
2882
/* We use CHECKSUM, instead of TABLE_CHECKSUM, for backward compability */
2863
2883
if (share->db_create_options & HA_OPTION_CHECKSUM)
2864
ptr=stpcpy(ptr," checksum=1");
2884
ptr= strcpy(ptr," checksum=1")+11;
2865
2885
if (share->page_checksum != HA_CHOICE_UNDEF)
2866
ptr= strxmov(ptr, " page_checksum=",
2867
ha_choice_values[(uint) share->page_checksum], NullS);
2886
ptr+= sprintf(ptr, " page_checksum=%s",
2887
ha_choice_values[(uint) share->page_checksum]);
2868
2888
if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
2869
ptr=stpcpy(ptr," delay_key_write=1");
2889
ptr= strcpy(ptr," delay_key_write=1")+18;
2870
2890
if (share->row_type != ROW_TYPE_DEFAULT)
2871
ptr=strxmov(ptr, " row_format=",
2872
ha_row_type[(uint) share->row_type],
2891
ptr+= sprintf(ptr, " row_format=%s", ha_row_type[(uint)share->row_type]);
2874
2892
if (share->block_size)
2876
ptr= stpcpy(ptr, " block_size=");
2894
ptr= strcpy(ptr, " block_size=")+12;
2877
2895
ptr= int64_t10_to_str(share->block_size, ptr, 10);
2880
2898
if (share->transactional != HA_CHOICE_UNDEF)
2882
ptr= strxmov(ptr, " TRANSACTIONAL=",
2883
(share->transactional == HA_CHOICE_YES ? "1" : "0"),
2900
ptr+= sprintf(ptr, " TRANSACTIONAL=%s",
2901
(share->transactional == HA_CHOICE_YES ? "1" : "0"));
2886
2903
if (share->transactional != HA_CHOICE_UNDEF)
2887
ptr= strxmov(ptr, " transactional=",
2888
ha_choice_values[(uint) share->transactional], NullS);
2904
ptr+= sprintf(ptr, " transactional=%s",
2905
ha_choice_values[(uint) share->transactional]);
2889
2906
table->field[19]->store(option_buff+1,
2890
(ptr == option_buff ? 0 :
2907
(ptr == option_buff ? 0 :
2891
2908
(uint) (ptr-option_buff)-1), cs);
2893
2910
tmp_buff= (share->table_charset ?
2953
2970
if (file->stats.create_time)
2955
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2956
(my_time_t) file->stats.create_time);
2972
session->variables.time_zone->gmt_sec_to_TIME(&time,
2973
(time_t) file->stats.create_time);
2957
2974
table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2958
2975
table->field[14]->set_notnull();
2960
2977
if (file->stats.update_time)
2962
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2963
(my_time_t) file->stats.update_time);
2979
session->variables.time_zone->gmt_sec_to_TIME(&time,
2980
(time_t) file->stats.update_time);
2964
2981
table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2965
2982
table->field[15]->set_notnull();
2967
2984
if (file->stats.check_time)
2969
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2970
(my_time_t) file->stats.check_time);
2986
session->variables.time_zone->gmt_sec_to_TIME(&time,
2987
(time_t) file->stats.check_time);
2971
2988
table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2972
2989
table->field[16]->set_notnull();
3171
3186
table->field[4]->store((int64_t) count, true);
3173
if (get_field_default_value(thd, timestamp_field, field, &type, 0))
3188
if (get_field_default_value(session, timestamp_field, field, &type, 0))
3175
3190
table->field[5]->store(type.ptr(), type.length(), cs);
3176
3191
table->field[5]->set_notnull();
3178
pos=(uchar*) ((field->flags & NOT_NULL_FLAG) ? "NO" : "YES");
3193
pos=(unsigned char*) ((field->flags & NOT_NULL_FLAG) ? "NO" : "YES");
3179
3194
table->field[6]->store((const char*) pos,
3180
3195
strlen((const char*) pos), cs);
3181
3196
store_column_type(table, field, cs, 7);
3183
pos=(uchar*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
3198
pos=(unsigned char*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
3184
3199
(field->flags & UNIQUE_KEY_FLAG) ? "UNI" :
3185
3200
(field->flags & MULTIPLE_KEY_FLAG) ? "MUL":"");
3186
3201
table->field[15]->store((const char*) pos,
3193
3208
field->unireg_check != Field::TIMESTAMP_DN_FIELD)
3194
3209
table->field[16]->store(STRING_WITH_LEN("on update CURRENT_TIMESTAMP"),
3211
if (field->vcol_info)
3212
table->field[16]->store(STRING_WITH_LEN("VIRTUAL"), cs);
3197
3213
table->field[18]->store(field->comment.str, field->comment.length, cs);
3199
3215
enum column_format_type column_format= (enum column_format_type)
3200
3216
((field->flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
3201
pos=(uchar*)"Default";
3217
pos=(unsigned char*)"Default";
3202
3218
table->field[19]->store((const char*) pos,
3203
3219
strlen((const char*) pos), cs);
3204
pos=(uchar*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
3220
pos=(unsigned char*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
3205
3221
column_format == COLUMN_FORMAT_TYPE_FIXED ? "Fixed" :
3207
3223
table->field[20]->store((const char*) pos,
3208
3224
strlen((const char*) pos), cs);
3210
if (schema_table_store_record(thd, table))
3226
if (schema_table_store_record(session, table))
3291
int fill_schema_coll_charset_app(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3307
int fill_schema_coll_charset_app(Session *session, TableList *tables, COND *)
3293
3309
CHARSET_INFO **cs;
3294
TABLE *table= tables->table;
3310
Table *table= tables->table;
3295
3311
const CHARSET_INFO * const scs= system_charset_info;
3296
3312
for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3298
3314
CHARSET_INFO **cl;
3299
3315
const CHARSET_INFO *tmp_cs= cs[0];
3300
if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3316
if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3301
3317
!(tmp_cs->state & MY_CS_PRIMARY))
3303
3319
for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3305
3321
const CHARSET_INFO *tmp_cl= cl[0];
3306
if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3322
if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3307
3323
!my_charset_same(tmp_cs,tmp_cl))
3309
3325
restore_record(table, s->default_values);
3310
3326
table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3311
3327
table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3312
if (schema_table_store_record(thd, table))
3328
if (schema_table_store_record(session, table))
3320
static int get_schema_stat_record(THD *thd, TABLE_LIST *tables,
3321
TABLE *table, bool res,
3336
static int get_schema_stat_record(Session *session, TableList *tables,
3337
Table *table, bool res,
3322
3338
LEX_STRING *db_name,
3323
3339
LEX_STRING *table_name)
3325
3341
const CHARSET_INFO * const cs= system_charset_info;
3328
if (thd->lex->sql_command != SQLCOM_SHOW_KEYS)
3344
if (session->lex->sql_command != SQLCOM_SHOW_KEYS)
3331
3347
I.e. we are in SELECT FROM INFORMATION_SCHEMA.STATISTICS
3332
3348
rather than in SHOW KEYS
3334
if (thd->is_error())
3335
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3336
thd->main_da.sql_errno(), thd->main_da.message());
3350
if (session->is_error())
3351
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3352
session->main_da.sql_errno(), session->main_da.message());
3353
session->clear_error();
3344
TABLE *show_table= tables->table;
3360
Table *show_table= tables->table;
3345
3361
KEY *key_info=show_table->s->key_info;
3346
3362
if (show_table->file)
3347
3363
show_table->file->info(HA_STATUS_VARIABLE |
3348
3364
HA_STATUS_NO_LOCK |
3349
3365
HA_STATUS_TIME);
3350
for (uint i=0 ; i < show_table->s->keys ; i++,key_info++)
3366
for (uint32_t i=0 ; i < show_table->s->keys ; i++,key_info++)
3352
3368
KEY_PART_INFO *key_part= key_info->key_part;
3353
3369
const char *str;
3354
for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
3370
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
3356
3372
restore_record(table, s->default_values);
3357
3373
table->field[1]->store(db_name->str, db_name->length, cs);
3425
3441
table->field[3]->store(db_name->str, db_name->length, cs);
3426
3442
table->field[4]->store(table_name->str, table_name->length, cs);
3427
3443
table->field[5]->store(con_type, con_len, cs);
3428
return schema_table_store_record(thd, table);
3444
return schema_table_store_record(session, table);
3432
static int get_schema_constraints_record(THD *thd, TABLE_LIST *tables,
3433
TABLE *table, bool res,
3448
static int get_schema_constraints_record(Session *session, TableList *tables,
3449
Table *table, bool res,
3434
3450
LEX_STRING *db_name,
3435
3451
LEX_STRING *table_name)
3439
if (thd->is_error())
3440
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3441
thd->main_da.sql_errno(), thd->main_da.message());
3455
if (session->is_error())
3456
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3457
session->main_da.sql_errno(), session->main_da.message());
3458
session->clear_error();
3447
3463
List<FOREIGN_KEY_INFO> f_key_list;
3448
TABLE *show_table= tables->table;
3464
Table *show_table= tables->table;
3449
3465
KEY *key_info=show_table->key_info;
3450
uint primary_key= show_table->s->primary_key;
3451
show_table->file->info(HA_STATUS_VARIABLE |
3466
uint32_t primary_key= show_table->s->primary_key;
3467
show_table->file->info(HA_STATUS_VARIABLE |
3452
3468
HA_STATUS_NO_LOCK |
3453
3469
HA_STATUS_TIME);
3454
for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
3470
for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
3456
3472
if (i != primary_key && !(key_info->flags & HA_NOSAME))
3459
if (i == primary_key && !strcmp(key_info->name, primary_key_name))
3475
if (i == primary_key && is_primary_key(key_info))
3461
if (store_constraints(thd, table, db_name, table_name, key_info->name,
3477
if (store_constraints(session, table, db_name, table_name, key_info->name,
3462
3478
strlen(key_info->name),
3463
3479
STRING_WITH_LEN("PRIMARY KEY")))
3466
3482
else if (key_info->flags & HA_NOSAME)
3468
if (store_constraints(thd, table, db_name, table_name, key_info->name,
3484
if (store_constraints(session, table, db_name, table_name, key_info->name,
3469
3485
strlen(key_info->name),
3470
3486
STRING_WITH_LEN("UNIQUE")))
3475
show_table->file->get_foreign_key_list(thd, &f_key_list);
3491
show_table->file->get_foreign_key_list(session, &f_key_list);
3476
3492
FOREIGN_KEY_INFO *f_key_info;
3477
3493
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3478
3494
while ((f_key_info=it++))
3480
if (store_constraints(thd, table, db_name, table_name,
3496
if (store_constraints(session, table, db_name, table_name,
3481
3497
f_key_info->forein_id->str,
3482
3498
strlen(f_key_info->forein_id->str),
3483
3499
"FOREIGN KEY", 11))
3506
static int get_schema_key_column_usage_record(THD *thd,
3508
TABLE *table, bool res,
3522
static int get_schema_key_column_usage_record(Session *session,
3524
Table *table, bool res,
3509
3525
LEX_STRING *db_name,
3510
3526
LEX_STRING *table_name)
3514
if (thd->is_error())
3515
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3516
thd->main_da.sql_errno(), thd->main_da.message());
3530
if (session->is_error())
3531
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3532
session->main_da.sql_errno(), session->main_da.message());
3533
session->clear_error();
3522
3538
List<FOREIGN_KEY_INFO> f_key_list;
3523
TABLE *show_table= tables->table;
3539
Table *show_table= tables->table;
3524
3540
KEY *key_info=show_table->key_info;
3525
uint primary_key= show_table->s->primary_key;
3526
show_table->file->info(HA_STATUS_VARIABLE |
3541
uint32_t primary_key= show_table->s->primary_key;
3542
show_table->file->info(HA_STATUS_VARIABLE |
3527
3543
HA_STATUS_NO_LOCK |
3528
3544
HA_STATUS_TIME);
3529
for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
3545
for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
3531
3547
if (i != primary_key && !(key_info->flags & HA_NOSAME))
3534
3550
KEY_PART_INFO *key_part= key_info->key_part;
3535
for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
3551
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
3537
3553
if (key_part->field)
3631
3647
schema_table_idx == SCH_GLOBAL_VARIABLES)
3632
3648
option_type= OPT_GLOBAL;
3634
rw_rdlock(&LOCK_system_variables_hash);
3635
res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars),
3650
pthread_rwlock_rdlock(&LOCK_system_variables_hash);
3651
res= show_status_array(session, wild, enumerate_sys_vars(session, sorted_vars),
3636
3652
option_type, NULL, "", tables->table, upper_case_names);
3637
rw_unlock(&LOCK_system_variables_hash);
3653
pthread_rwlock_unlock(&LOCK_system_variables_hash);
3642
int fill_status(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3658
int fill_status(Session *session, TableList *tables, COND *)
3645
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3660
LEX *lex= session->lex;
3661
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3647
3663
STATUS_VAR *tmp1, tmp;
3648
3664
enum enum_schema_tables schema_table_idx=
3703
get_referential_constraints_record(THD *thd, TABLE_LIST *tables,
3704
TABLE *table, bool res,
3719
get_referential_constraints_record(Session *session, TableList *tables,
3720
Table *table, bool res,
3705
3721
LEX_STRING *db_name, LEX_STRING *table_name)
3707
3723
const CHARSET_INFO * const cs= system_charset_info;
3711
if (thd->is_error())
3712
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3713
thd->main_da.sql_errno(), thd->main_da.message());
3727
if (session->is_error())
3728
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3729
session->main_da.sql_errno(), session->main_da.message());
3730
session->clear_error();
3719
3735
List<FOREIGN_KEY_INFO> f_key_list;
3720
TABLE *show_table= tables->table;
3721
show_table->file->info(HA_STATUS_VARIABLE |
3736
Table *show_table= tables->table;
3737
show_table->file->info(HA_STATUS_VARIABLE |
3722
3738
HA_STATUS_NO_LOCK |
3723
3739
HA_STATUS_TIME);
3725
show_table->file->get_foreign_key_list(thd, &f_key_list);
3741
show_table->file->get_foreign_key_list(session, &f_key_list);
3726
3742
FOREIGN_KEY_INFO *f_key_info;
3727
3743
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3728
3744
while ((f_key_info= it++))
3732
3748
table->field[9]->store(table_name->str, table_name->length, cs);
3733
3749
table->field[2]->store(f_key_info->forein_id->str,
3734
3750
f_key_info->forein_id->length, cs);
3735
table->field[4]->store(f_key_info->referenced_db->str,
3751
table->field[4]->store(f_key_info->referenced_db->str,
3736
3752
f_key_info->referenced_db->length, cs);
3737
table->field[10]->store(f_key_info->referenced_table->str,
3753
table->field[10]->store(f_key_info->referenced_table->str,
3738
3754
f_key_info->referenced_table->length, cs);
3739
3755
if (f_key_info->referenced_key_name)
3741
table->field[5]->store(f_key_info->referenced_key_name->str,
3757
table->field[5]->store(f_key_info->referenced_key_name->str,
3742
3758
f_key_info->referenced_key_name->length, cs);
3743
3759
table->field[5]->set_notnull();
3746
3762
table->field[5]->set_null();
3747
3763
table->field[6]->store(STRING_WITH_LEN("NONE"), cs);
3748
table->field[7]->store(f_key_info->update_method->str,
3764
table->field[7]->store(f_key_info->update_method->str,
3749
3765
f_key_info->update_method->length, cs);
3750
table->field[8]->store(f_key_info->delete_method->str,
3766
table->field[8]->store(f_key_info->delete_method->str,
3751
3767
f_key_info->delete_method->length, cs);
3752
if (schema_table_store_record(thd, table))
3768
if (schema_table_store_record(session, table))
3931
3944
TMP_TABLE_PARAM *tmp_table_param =
3932
(TMP_TABLE_PARAM*) (thd->alloc(sizeof(TMP_TABLE_PARAM)));
3945
(TMP_TABLE_PARAM*) (session->alloc(sizeof(TMP_TABLE_PARAM)));
3933
3946
tmp_table_param->init();
3934
3947
tmp_table_param->table_charset= cs;
3935
3948
tmp_table_param->field_count= field_count;
3936
3949
tmp_table_param->schema_table= 1;
3937
SELECT_LEX *select_lex= thd->lex->current_select;
3938
if (!(table= create_tmp_table(thd, tmp_table_param,
3939
field_list, (ORDER*) 0, 0, 0,
3940
(select_lex->options | thd->options |
3950
SELECT_LEX *select_lex= session->lex->current_select;
3951
if (!(table= create_tmp_table(session, tmp_table_param,
3952
field_list, (order_st*) 0, 0, 0,
3953
(select_lex->options | session->options |
3941
3954
TMP_TABLE_ALL_COLUMNS),
3942
3955
HA_POS_ERROR, table_list->alias)))
3944
3957
my_bitmap_map* bitmaps=
3945
(my_bitmap_map*) thd->alloc(bitmap_buffer_size(field_count));
3958
(my_bitmap_map*) session->alloc(bitmap_buffer_size(field_count));
3946
3959
bitmap_init(&table->def_read_set, (my_bitmap_map*) bitmaps, field_count,
3948
3961
table->read_set= &table->def_read_set;
3970
int make_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
3983
int make_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
3972
3985
ST_FIELD_INFO *field_info= schema_table->fields_info;
3973
Name_resolution_context *context= &thd->lex->select_lex.context;
3986
Name_resolution_context *context= &session->lex->select_lex.context;
3974
3987
for (; field_info->field_name; field_info++)
3976
3989
if (field_info->old_name)
3978
3991
Item_field *field= new Item_field(context,
3979
NullS, NullS, field_info->field_name);
3992
NULL, NULL, field_info->field_name);
3982
3995
field->set_name(field_info->old_name,
3983
3996
strlen(field_info->old_name),
3984
3997
system_charset_info);
3985
if (add_item_to_list(thd, field))
3998
if (add_item_to_list(session, field))
4038
4051
buffer.append(')');
4040
4053
Item_field *field= new Item_field(context,
4041
NullS, NullS, field_info->field_name);
4042
if (add_item_to_list(thd, field))
4054
NULL, NULL, field_info->field_name);
4055
if (add_item_to_list(session, field))
4044
4057
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4045
if (thd->lex->verbose)
4058
if (session->lex->verbose)
4047
4060
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4048
4061
field_info= &schema_table->fields_info[3];
4049
field= new Item_field(context, NullS, NullS, field_info->field_name);
4050
if (add_item_to_list(thd, field))
4062
field= new Item_field(context, NULL, NULL, field_info->field_name);
4063
if (add_item_to_list(session, field))
4052
4065
field->set_name(field_info->old_name, strlen(field_info->old_name),
4053
4066
system_charset_info);
4059
int make_columns_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
4072
int make_columns_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4061
4074
int fields_arr[]= {3, 14, 13, 6, 15, 5, 16, 17, 18, -1};
4062
4075
int *field_num= fields_arr;
4063
4076
ST_FIELD_INFO *field_info;
4064
Name_resolution_context *context= &thd->lex->select_lex.context;
4077
Name_resolution_context *context= &session->lex->select_lex.context;
4066
4079
for (; *field_num >= 0; field_num++)
4068
4081
field_info= &schema_table->fields_info[*field_num];
4069
if (!thd->lex->verbose && (*field_num == 13 ||
4082
if (!session->lex->verbose && (*field_num == 13 ||
4070
4083
*field_num == 17 ||
4071
4084
*field_num == 18))
4073
4086
Item_field *field= new Item_field(context,
4074
NullS, NullS, field_info->field_name);
4087
NULL, NULL, field_info->field_name);
4077
4090
field->set_name(field_info->old_name,
4078
4091
strlen(field_info->old_name),
4079
4092
system_charset_info);
4080
if (add_item_to_list(thd, field))
4093
if (add_item_to_list(session, field))
4088
int make_character_sets_old_format(THD *thd, ST_SCHEMA_TABLE *schema_table)
4101
int make_character_sets_old_format(Session *session, ST_SCHEMA_TABLE *schema_table)
4090
4103
int fields_arr[]= {0, 2, 1, 3, -1};
4091
4104
int *field_num= fields_arr;
4092
4105
ST_FIELD_INFO *field_info;
4093
Name_resolution_context *context= &thd->lex->select_lex.context;
4106
Name_resolution_context *context= &session->lex->select_lex.context;
4095
4108
for (; *field_num >= 0; field_num++)
4097
4110
field_info= &schema_table->fields_info[*field_num];
4098
4111
Item_field *field= new Item_field(context,
4099
NullS, NullS, field_info->field_name);
4112
NULL, NULL, field_info->field_name);
4102
4115
field->set_name(field_info->old_name,
4103
4116
strlen(field_info->old_name),
4104
4117
system_charset_info);
4105
if (add_item_to_list(thd, field))
4118
if (add_item_to_list(session, field))
4213
4225
We have to make non const db_name & table_name
4214
4226
because of lower_case_table_names
4216
thd->make_lex_string(&db, INFORMATION_SCHEMA_NAME.str,
4217
INFORMATION_SCHEMA_NAME.length, 0);
4218
thd->make_lex_string(&table, schema_table->table_name,
4228
session->make_lex_string(&db, INFORMATION_SCHEMA_NAME.c_str(),
4229
INFORMATION_SCHEMA_NAME.length(), 0);
4230
session->make_lex_string(&table, schema_table->table_name,
4219
4231
strlen(schema_table->table_name), 0);
4220
if (schema_table->old_format(thd, schema_table) || /* Handle old syntax */
4221
!sel->add_table_to_list(thd, new Table_ident(thd, db, table, 0),
4232
if (schema_table->old_format(session, schema_table) || /* Handle old syntax */
4233
!sel->add_table_to_list(session, new Table_ident(session, db, table, 0),
4222
4234
0, 0, TL_READ))
4339
4351
{"ROW_FORMAT", 10, DRIZZLE_TYPE_VARCHAR, 0, 1, "Row_format", OPEN_FULL_TABLE},
4340
4352
{"TABLE_ROWS", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4341
4353
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Rows", OPEN_FULL_TABLE},
4342
{"AVG_ROW_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4354
{"AVG_ROW_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4343
4355
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Avg_row_length", OPEN_FULL_TABLE},
4344
{"DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4356
{"DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4345
4357
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Data_length", OPEN_FULL_TABLE},
4346
4358
{"MAX_DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4347
4359
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Max_data_length", OPEN_FULL_TABLE},
4348
{"INDEX_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4360
{"INDEX_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4349
4361
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Index_length", OPEN_FULL_TABLE},
4350
4362
{"DATA_FREE", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4351
4363
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Data_free", OPEN_FULL_TABLE},
4352
{"AUTO_INCREMENT", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG, 0,
4364
{"AUTO_INCREMENT", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG, 0,
4353
4365
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Auto_increment", OPEN_FULL_TABLE},
4354
4366
{"CREATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Create_time", OPEN_FULL_TABLE},
4355
4367
{"UPDATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Update_time", OPEN_FULL_TABLE},
4594
4606
ST_SCHEMA_TABLE schema_tables[]=
4596
{"CHARACTER_SETS", charsets_fields_info, create_schema_table,
4608
{"CHARACTER_SETS", charsets_fields_info, create_schema_table,
4597
4609
fill_schema_charsets, make_character_sets_old_format, 0, -1, -1, 0, 0},
4598
{"COLLATIONS", collation_fields_info, create_schema_table,
4610
{"COLLATIONS", collation_fields_info, create_schema_table,
4599
4611
fill_schema_collation, make_old_format, 0, -1, -1, 0, 0},
4600
4612
{"COLLATION_CHARACTER_SET_APPLICABILITY", coll_charset_app_fields_info,
4601
4613
create_schema_table, fill_schema_coll_charset_app, 0, 0, -1, -1, 0, 0},
4602
{"COLUMNS", columns_fields_info, create_schema_table,
4614
{"COLUMNS", columns_fields_info, create_schema_table,
4603
4615
get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2, 0,
4604
OPTIMIZE_I_S_TABLE|OPEN_VIEW_FULL},
4616
OPTIMIZE_I_S_TABLE},
4605
4617
{"GLOBAL_STATUS", variables_fields_info, create_schema_table,
4606
4618
fill_status, make_old_format, 0, -1, -1, 0, 0},
4607
4619
{"GLOBAL_VARIABLES", variables_fields_info, create_schema_table,
4624
4636
fill_status, make_old_format, 0, -1, -1, 0, 0},
4625
4637
{"SESSION_VARIABLES", variables_fields_info, create_schema_table,
4626
4638
fill_variables, make_old_format, 0, -1, -1, 0, 0},
4627
{"STATISTICS", stat_fields_info, create_schema_table,
4639
{"STATISTICS", stat_fields_info, create_schema_table,
4628
4640
get_all_tables, make_old_format, get_schema_stat_record, 1, 2, 0,
4629
4641
OPEN_TABLE_ONLY|OPTIMIZE_I_S_TABLE},
4630
{"STATUS", variables_fields_info, create_schema_table, fill_status,
4642
{"STATUS", variables_fields_info, create_schema_table, fill_status,
4631
4643
make_old_format, 0, -1, -1, 1, 0},
4632
{"TABLES", tables_fields_info, create_schema_table,
4644
{"TABLES", tables_fields_info, create_schema_table,
4633
4645
get_all_tables, make_old_format, get_schema_tables_record, 1, 2, 0,
4634
4646
OPTIMIZE_I_S_TABLE},
4635
4647
{"TABLE_CONSTRAINTS", table_constraints_fields_info, create_schema_table,
4652
4664
ST_SCHEMA_TABLE *schema_table;
4654
if (!(schema_table= (ST_SCHEMA_TABLE *)my_malloc(sizeof(ST_SCHEMA_TABLE),
4655
MYF(MY_WME | MY_ZEROFILL))))
4666
if ((schema_table= new ST_SCHEMA_TABLE) == NULL)
4668
memset(schema_table, 0, sizeof(ST_SCHEMA_TABLE));
4657
4670
/* Historical Requirement */
4658
4671
plugin->data= schema_table; // shortcut for the future
4659
4672
if (plugin->plugin->init)
4661
4674
schema_table->create_table= create_schema_table;
4662
4675
schema_table->old_format= make_old_format;
4663
schema_table->idx_field1= -1,
4664
schema_table->idx_field2= -1;
4676
schema_table->idx_field1= -1,
4677
schema_table->idx_field2= -1;
4666
4679
/* Make the name available to the init() function. */
4667
4680
schema_table->table_name= plugin->name.str;
4669
4682
if (plugin->plugin->init(schema_table))
4671
sql_print_error("Plugin '%s' init function returned error.",
4684
sql_print_error(_("Plugin '%s' init function returned error."),
4672
4685
plugin->name.str);
4676
4689
/* Make sure the plugin name is not set inside the init() function. */
4677
4690
schema_table->table_name= plugin->name.str;
4682
my_free(schema_table, MYF(0));
4695
delete schema_table;
4686
4700
int finalize_schema_table(st_plugin_int *plugin)