17
17
/* Function with list databases, tables or fields */
18
#include <drizzled/server_includes.h>
19
#include <drizzled/sql_select.h>
20
#include <drizzled/sql_show.h>
19
#include "mysql_priv.h"
20
#include "sql_select.h" // For select_describe
21
22
#include "repl_failsafe.h"
22
23
#include <mysys/my_dir.h>
23
#include <libdrizzle/gettext.h>
26
str_or_nil(const char *str)
28
return str ? str : "<nil>";
25
#define STR_OR_NIL(S) ((S) ? (S) : "<nil>")
31
27
/* Match the values of enum ha_choice */
32
28
static const char *ha_choice_values[] = {"", "0", "1"};
34
static void store_key_options(THD *thd, String *packet, Table *table,
30
static void store_key_options(THD *thd, String *packet, TABLE *table,
39
int wild_case_compare(const CHARSET_INFO * const cs, const char *str,const char *wildstr)
35
int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *wildstr)
89
85
static bool show_plugins(THD *thd, plugin_ref plugin,
92
Table *table= (Table*) arg;
88
TABLE *table= (TABLE*) arg;
93
89
struct st_mysql_plugin *plug= plugin_decl(plugin);
94
90
struct st_plugin_dl *plugin_dl= plugin_dlib(plugin);
95
const CHARSET_INFO * const cs= system_charset_info;
91
CHARSET_INFO *cs= system_charset_info;
97
93
restore_record(table, s->default_values);
175
int fill_plugins(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
171
int fill_plugins(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
177
Table *table= tables->table;
173
TABLE *table= tables->table;
179
if (plugin_foreach_with_mask(thd, show_plugins, DRIZZLE_ANY_PLUGIN,
175
if (plugin_foreach_with_mask(thd, show_plugins, MYSQL_ANY_PLUGIN,
180
176
~PLUGIN_IS_FREED, table))
443
439
0 No conflicting character
446
static const char *require_quotes(const char *name, uint32_t name_length)
442
static const char *require_quotes(const char *name, uint name_length)
449
445
bool pure_digit= true;
450
446
const char *end= name + name_length;
452
448
for (; name < end ; name++)
454
unsigned char chr= (unsigned char) *name;
450
uchar chr= (uchar) *name;
455
451
length= my_mbcharlen(system_charset_info, chr);
456
452
if (length == 1 && !system_charset_info->ident_map[chr])
497
packet->reserve(length*2 + 2);
493
VOID(packet->reserve(length*2 + 2));
498
494
quote_char= (char) q;
499
495
packet->append("e_char, 1, system_charset_info);
501
497
for (name_end= name+length ; name < name_end ; name+= length)
503
unsigned char chr= (unsigned char) *name;
499
uchar chr= (uchar) *name;
504
500
length= my_mbcharlen(system_charset_info, chr);
506
502
my_mbcharlen can return 0 on a wrong multibyte
659
655
String type(tmp, sizeof(tmp), system_charset_info);
660
656
String def_value(def_value_buf, sizeof(def_value_buf), system_charset_info);
661
657
Field **ptr,*field;
662
uint32_t primary_key;
664
Table *table= table_list->table;
660
TABLE *table= table_list->table;
665
661
handler *file= table->file;
666
662
TABLE_SHARE *share= table->s;
667
663
HA_CREATE_INFO create_info;
695
691
We have to restore the read_set if we are called from insert in case
696
692
of row based replication.
698
old_map= table->use_all_columns(table->read_set);
694
old_map= tmp_use_all_columns(table, table->read_set);
700
696
for (ptr=table->field ; (field= *ptr); ptr++)
702
uint32_t flags = field->flags;
698
uint flags = field->flags;
704
700
if (ptr != table->field)
705
701
packet->append(STRING_WITH_LEN(",\n"));
785
781
key_info= table->key_info;
786
memset(&create_info, 0, sizeof(create_info));
782
memset((char*) &create_info, 0, sizeof(create_info));
787
783
/* Allow update_create_info to update row type */
788
784
create_info.row_type= share->row_type;
789
785
file->update_create_info(&create_info);
790
786
primary_key= share->primary_key;
792
for (uint32_t i=0 ; i < share->keys ; i++,key_info++)
788
for (uint i=0 ; i < share->keys ; i++,key_info++)
794
790
KEY_PART_INFO *key_part= key_info->key_part;
795
791
bool found_primary=0;
888
884
packet->append(buff, (uint) (end - buff));
888
if (share->table_charset)
892
THEN add DEFAULT CHARSET only if it was used when creating the table
894
if (!create_info_arg ||
895
(create_info_arg->used_fields & HA_CREATE_USED_DEFAULT_CHARSET))
897
packet->append(STRING_WITH_LEN(" DEFAULT CHARSET="));
898
packet->append(share->table_charset->csname);
899
if (!(share->table_charset->state & MY_CS_PRIMARY))
901
packet->append(STRING_WITH_LEN(" COLLATE="));
902
packet->append(table->s->table_charset->name);
891
907
if (share->min_rows)
943
959
end= int64_t10_to_str(table->s->key_block_size, buff, 10);
944
960
packet->append(buff, (uint) (end - buff));
946
if (share->block_size)
949
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));
953
962
table->file->append_create_info(packet);
954
963
if (share->comment.length)
1144
1155
thd_info->state_info= (char*) (tmp->net.reading_or_writing ?
1145
1156
(tmp->net.reading_or_writing == 2 ?
1146
1157
"Writing to net" :
1147
thd_info->command == COM_SLEEP ? NULL :
1158
thd_info->command == COM_SLEEP ? NullS :
1148
1159
"Reading from net") :
1149
tmp->get_proc_info() ? tmp->get_proc_info() :
1160
tmp->proc_info ? tmp->proc_info :
1150
1161
tmp->mysys_var &&
1151
1162
tmp->mysys_var->current_cond ?
1152
"Waiting on cond" : NULL);
1163
"Waiting on cond" : NullS);
1154
1165
pthread_mutex_unlock(&mysys_var->mutex);
1162
1173
the comment in sql_class.h why this prevents crashes in possible
1163
1174
races with query_length
1165
uint32_t length= cmin((uint32_t)max_query_length, tmp->query_length);
1176
uint length= min(max_query_length, tmp->query_length);
1166
1177
thd_info->query=(char*) thd->strmake(tmp->query,length);
1168
1179
thread_infos.append(thd_info);
1172
pthread_mutex_unlock(&LOCK_thread_count);
1183
VOID(pthread_mutex_unlock(&LOCK_thread_count));
1174
1185
thread_info *thd_info;
1175
1186
time_t now= my_time(0);
1200
int fill_schema_processlist(THD* thd, TableList* tables,
1211
int fill_schema_processlist(THD* thd, TABLE_LIST* tables,
1201
1212
COND* cond __attribute__((unused)))
1203
Table *table= tables->table;
1204
const CHARSET_INFO * const cs= system_charset_info;
1214
TABLE *table= tables->table;
1215
CHARSET_INFO *cs= system_charset_info;
1206
1217
time_t now= my_time(0);
1210
pthread_mutex_lock(&LOCK_thread_count);
1221
VOID(pthread_mutex_lock(&LOCK_thread_count));
1212
1223
if (!thd->killed)
1254
1266
val= (char*) (tmp->net.reading_or_writing ?
1255
1267
(tmp->net.reading_or_writing == 2 ?
1256
1268
"Writing to net" :
1257
tmp->command == COM_SLEEP ? NULL :
1269
tmp->command == COM_SLEEP ? NullS :
1258
1270
"Reading from net") :
1259
tmp->get_proc_info() ? tmp->get_proc_info() :
1271
tmp->proc_info ? tmp->proc_info :
1260
1272
tmp->mysys_var &&
1261
1273
tmp->mysys_var->current_cond ?
1262
"Waiting on cond" : NULL);
1274
"Waiting on cond" : NullS);
1265
1277
table->field[6]->store(val, strlen(val), cs);
1273
1285
if (tmp->query)
1275
1287
table->field[7]->store(tmp->query,
1276
cmin((uint32_t)PROCESS_LIST_INFO_WIDTH,
1288
min(PROCESS_LIST_INFO_WIDTH,
1277
1289
tmp->query_length), cs);
1278
1290
table->field[7]->set_notnull();
1281
1293
if (schema_table_store_record(thd, table))
1283
pthread_mutex_unlock(&LOCK_thread_count);
1295
VOID(pthread_mutex_unlock(&LOCK_thread_count));
1289
pthread_mutex_unlock(&LOCK_thread_count);
1301
VOID(pthread_mutex_unlock(&LOCK_thread_count));
1355
1367
while (list->name)
1356
res|= insert_dynamic(&all_status_vars, (unsigned char*)list++);
1357
res|= insert_dynamic(&all_status_vars, (unsigned char*)list); // appending NULL-element
1368
res|= insert_dynamic(&all_status_vars, (uchar*)list++);
1369
res|= insert_dynamic(&all_status_vars, (uchar*)list); // appending NULL-element
1358
1370
all_status_vars.elements--; // but next insert_dynamic should overwite it
1359
1371
if (status_vars_inited)
1360
1372
sort_dynamic(&all_status_vars, show_var_cmp);
1488
1500
null_lex_str.str= 0; // For sys_var->value_ptr()
1489
1501
null_lex_str.length= 0;
1491
prefix_end=my_stpncpy(name_buffer, prefix, sizeof(name_buffer)-1);
1503
prefix_end=strnmov(name_buffer, prefix, sizeof(name_buffer)-1);
1493
1505
*prefix_end++= '_';
1494
1506
len=name_buffer + sizeof(name_buffer) - prefix_end;
1496
1508
for (; variables->name; variables++)
1498
my_stpncpy(prefix_end, variables->name, len);
1510
strnmov(prefix_end, variables->name, len);
1499
1511
name_buffer[sizeof(name_buffer)-1]=0; /* Safety */
1500
1512
if (ucase_names)
1501
1513
make_upper(name_buffer);
1560
1572
end= int64_t10_to_str((int64_t) *(ha_rows*) value, buff, 10);
1562
1574
case SHOW_BOOL:
1563
end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1575
end= strmov(buff, *(bool*) value ? "ON" : "OFF");
1565
1577
case SHOW_MY_BOOL:
1566
end= my_stpcpy(buff, *(bool*) value ? "ON" : "OFF");
1578
end= strmov(buff, *(bool*) value ? "ON" : "OFF");
1569
1581
end= int10_to_str((long) *(uint32_t*) value, buff, 10);
1761
1773
/* Lookup value is database name */
1762
if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
1763
(unsigned char *) item_field->field_name,
1774
if (!cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
1775
(uchar *) item_field->field_name,
1764
1776
strlen(item_field->field_name), 0))
1766
1778
thd->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1767
1779
tmp_str->length(), false);
1769
1781
/* Lookup value is table name */
1770
else if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name2,
1782
else if (!cs->coll->strnncollsp(cs, (uchar *) field_name2,
1771
1783
strlen(field_name2),
1772
(unsigned char *) item_field->field_name,
1784
(uchar *) item_field->field_name,
1773
1785
strlen(item_field->field_name), 0))
1775
1787
thd->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1835
bool uses_only_table_name_fields(Item *item, TableList *table)
1847
bool uses_only_table_name_fields(Item *item, TABLE_LIST *table)
1837
1849
if (item->type() == Item::FUNC_ITEM)
1839
1851
Item_func *item_func= (Item_func*)item;
1840
for (uint32_t i=0; i<item_func->argument_count(); i++)
1852
for (uint i=0; i<item_func->argument_count(); i++)
1842
1854
if (!uses_only_table_name_fields(item_func->arguments()[i], table))
1854
1866
const char *field_name2= schema_table->idx_field2 >= 0 ?
1855
1867
field_info[schema_table->idx_field2].field_name : "";
1856
1868
if (table->table != item_field->field->table ||
1857
(cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
1858
(unsigned char *) item_field->field_name,
1869
(cs->coll->strnncollsp(cs, (uchar *) field_name1, strlen(field_name1),
1870
(uchar *) item_field->field_name,
1859
1871
strlen(item_field->field_name), 0) &&
1860
cs->coll->strnncollsp(cs, (unsigned char *) field_name2, strlen(field_name2),
1861
(unsigned char *) item_field->field_name,
1872
cs->coll->strnncollsp(cs, (uchar *) field_name2, strlen(field_name2),
1873
(uchar *) item_field->field_name,
1862
1874
strlen(item_field->field_name), 0)))
1946
1958
1 error, there can be no matching records for the condition
1949
bool get_lookup_field_values(THD *thd, COND *cond, TableList *tables,
1961
bool get_lookup_field_values(THD *thd, COND *cond, TABLE_LIST *tables,
1950
1962
LOOKUP_FIELD_VALUES *lookup_field_values)
1952
1964
LEX *lex= thd->lex;
1953
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1954
memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1965
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
1966
memset((char*) lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1955
1967
switch (lex->sql_command) {
1956
1968
case SQLCOM_SHOW_DATABASES:
2062
2074
if (files->push_back(i_s_name_copy))
2064
2076
*with_i_schema= 1;
2065
return (find_files(thd, files, NULL,
2066
mysql_data_home, NULL, 1) != FIND_FILES_OK);
2077
return (find_files(thd, files, NullS,
2078
mysql_data_home, NullS, 1) != FIND_FILES_OK);
2249
2261
LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
2250
2262
enum_sql_command save_sql_command= lex->sql_command;
2251
TableList *show_table_list= (TableList*) tables->schema_select_lex->
2263
TABLE_LIST *show_table_list= (TABLE_LIST*) tables->schema_select_lex->
2252
2264
table_list.first;
2253
Table *table= tables->table;
2265
TABLE *table= tables->table;
2256
2268
lex->all_selects_list= tables->schema_select_lex;
2326
2338
char path[FN_REFLEN];
2327
2339
(void) build_table_filename(path, sizeof(path), db_name->str,
2328
2340
table_name->str, reg_ext, 0);
2329
if (mysql_frm_type(thd, path, ¬_used))
2331
table->field[3]->store(STRING_WITH_LEN("BASE Table"),
2332
system_charset_info);
2341
switch (mysql_frm_type(thd, path, ¬_used)) {
2336
2343
table->field[3]->store(STRING_WITH_LEN("ERROR"),
2337
2344
system_charset_info);
2347
table->field[3]->store(STRING_WITH_LEN("BASE TABLE"),
2348
system_charset_info);
2340
2353
if (thd->is_error() && thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2342
2355
thd->clear_error();
2406
2419
open_tables function for this table
2409
static int fill_schema_table_from_frm(THD *thd,TableList *tables,
2422
static int fill_schema_table_from_frm(THD *thd,TABLE_LIST *tables,
2410
2423
ST_SCHEMA_TABLE *schema_table,
2411
2424
LEX_STRING *db_name,
2412
2425
LEX_STRING *table_name,
2413
2426
enum enum_schema_tables schema_table_idx __attribute__((unused)))
2415
Table *table= tables->table;
2428
TABLE *table= tables->table;
2416
2429
TABLE_SHARE *share;
2418
TableList table_list;
2431
TABLE_LIST table_list;
2421
2434
char key[MAX_DBKEY_LENGTH];
2422
uint32_t key_length;
2424
memset(&table_list, 0, sizeof(TableList));
2425
memset(&tbl, 0, sizeof(Table));
2437
memset((char*) &table_list, 0, sizeof(TABLE_LIST));
2438
memset((char*) &tbl, 0, sizeof(TABLE));
2427
2440
table_list.table_name= table_name->str;
2428
2441
table_list.db= db_name->str;
2473
2486
@retval 1 error
2476
int get_all_tables(THD *thd, TableList *tables, COND *cond)
2489
int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
2478
2491
LEX *lex= thd->lex;
2479
Table *table= tables->table;
2492
TABLE *table= tables->table;
2480
2493
SELECT_LEX *old_all_select_lex= lex->all_selects_list;
2481
2494
enum_sql_command save_sql_command= lex->sql_command;
2482
2495
SELECT_LEX *lsel= tables->schema_select_lex;
2489
2502
List<LEX_STRING> db_names;
2490
2503
List_iterator_fast<LEX_STRING> it(db_names);
2491
2504
COND *partial_cond= 0;
2492
uint32_t derived_tables= lex->derived_tables;
2505
uint derived_tables= lex->derived_tables;
2494
2507
Open_tables_state open_tables_state_backup;
2495
2508
Query_tables_list query_tables_list_backup;
2496
uint32_t table_open_method;
2509
uint table_open_method;
2497
2510
bool old_value= thd->no_warnings_for_error;
2499
2512
lex->reset_n_backup_query_tables_list(&query_tables_list_backup);
2633
2646
if (make_table_list(thd, &sel, db_name, table_name))
2635
TableList *show_table_list= (TableList*) sel.table_list.first;
2648
TABLE_LIST *show_table_list= (TABLE_LIST*) sel.table_list.first;
2636
2649
lex->all_selects_list= &sel;
2637
2650
lex->derived_tables= 0;
2638
2651
lex->sql_command= SQLCOM_SHOW_FIELDS;
2639
2652
show_table_list->i_s_requested_object=
2640
2653
schema_table->i_s_requested_object;
2641
2654
res= open_normal_and_derived_tables(thd, show_table_list,
2642
DRIZZLE_LOCK_IGNORE_FLUSH);
2655
MYSQL_LOCK_IGNORE_FLUSH);
2643
2656
lex->sql_command= save_sql_command;
2645
2658
XXX: show_table_list has a flag i_is_requested,
2706
bool store_schema_shemata(THD* thd, Table *table, LEX_STRING *db_name,
2707
const CHARSET_INFO * const cs)
2719
bool store_schema_shemata(THD* thd, TABLE *table, LEX_STRING *db_name,
2709
2722
restore_record(table, s->default_values);
2710
2723
table->field[1]->store(db_name->str, db_name->length, system_charset_info);
2777
static int get_schema_tables_record(THD *thd, TableList *tables,
2778
Table *table, bool res,
2790
static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
2791
TABLE *table, bool res,
2779
2792
LEX_STRING *db_name,
2780
2793
LEX_STRING *table_name)
2782
2795
const char *tmp_buff;
2783
2796
DRIZZLE_TIME time;
2784
const CHARSET_INFO * const cs= system_charset_info;
2797
CHARSET_INFO *cs= system_charset_info;
2786
2799
restore_record(table, s->default_values);
2787
2800
table->field[1]->store(db_name->str, db_name->length, cs);
2795
2808
if (tables->schema_table)
2796
2809
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2798
table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2811
table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
2799
2812
table->field[20]->store(error, strlen(error), cs);
2800
2813
thd->clear_error();
2804
char option_buff[400],*ptr;
2805
Table *show_table= tables->table;
2817
char option_buff[350],*ptr;
2818
TABLE *show_table= tables->table;
2806
2819
TABLE_SHARE *share= show_table->s;
2807
2820
handler *file= show_table->file;
2808
2821
handlerton *tmp_db_type= share->db_type();
2826
2839
ptr=option_buff;
2827
2840
if (share->min_rows)
2829
ptr=my_stpcpy(ptr," min_rows=");
2842
ptr=strmov(ptr," min_rows=");
2830
2843
ptr=int64_t10_to_str(share->min_rows,ptr,10);
2832
2845
if (share->max_rows)
2834
ptr=my_stpcpy(ptr," max_rows=");
2847
ptr=strmov(ptr," max_rows=");
2835
2848
ptr=int64_t10_to_str(share->max_rows,ptr,10);
2837
2850
if (share->avg_row_length)
2839
ptr=my_stpcpy(ptr," avg_row_length=");
2852
ptr=strmov(ptr," avg_row_length=");
2840
2853
ptr=int64_t10_to_str(share->avg_row_length,ptr,10);
2842
2855
if (share->db_create_options & HA_OPTION_PACK_KEYS)
2843
ptr=my_stpcpy(ptr," pack_keys=1");
2856
ptr=strmov(ptr," pack_keys=1");
2844
2857
if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
2845
ptr=my_stpcpy(ptr," pack_keys=0");
2858
ptr=strmov(ptr," pack_keys=0");
2846
2859
/* We use CHECKSUM, instead of TABLE_CHECKSUM, for backward compability */
2847
2860
if (share->db_create_options & HA_OPTION_CHECKSUM)
2848
ptr=my_stpcpy(ptr," checksum=1");
2861
ptr=strmov(ptr," checksum=1");
2849
2862
if (share->page_checksum != HA_CHOICE_UNDEF)
2850
2863
ptr= strxmov(ptr, " page_checksum=",
2851
ha_choice_values[(uint) share->page_checksum], NULL);
2864
ha_choice_values[(uint) share->page_checksum], NullS);
2852
2865
if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
2853
ptr=my_stpcpy(ptr," delay_key_write=1");
2866
ptr=strmov(ptr," delay_key_write=1");
2854
2867
if (share->row_type != ROW_TYPE_DEFAULT)
2855
2868
ptr=strxmov(ptr, " row_format=",
2856
2869
ha_row_type[(uint) share->row_type],
2858
if (share->block_size)
2860
ptr= my_stpcpy(ptr, " block_size=");
2861
ptr= int64_t10_to_str(share->block_size, ptr, 10);
2864
2871
if (share->transactional != HA_CHOICE_UNDEF)
2866
2873
ptr= strxmov(ptr, " TRANSACTIONAL=",
2867
2874
(share->transactional == HA_CHOICE_YES ? "1" : "0"),
2870
2877
if (share->transactional != HA_CHOICE_UNDEF)
2871
2878
ptr= strxmov(ptr, " transactional=",
2872
ha_choice_values[(uint) share->transactional], NULL);
2879
ha_choice_values[(uint) share->transactional], NullS);
2873
2880
table->field[19]->store(option_buff+1,
2874
2881
(ptr == option_buff ? 0 :
2875
2882
(uint) (ptr-option_buff)-1), cs);
3068
static int get_schema_column_record(THD *thd, TableList *tables,
3069
Table *table, bool res,
3076
static int get_schema_column_record(THD *thd, TABLE_LIST *tables,
3077
TABLE *table, bool res,
3070
3078
LEX_STRING *db_name,
3071
3079
LEX_STRING *table_name)
3073
3081
LEX *lex= thd->lex;
3074
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3075
const CHARSET_INFO * const cs= system_charset_info;
3082
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3083
CHARSET_INFO *cs= system_charset_info;
3077
3085
TABLE_SHARE *show_table_share;
3078
3086
Field **ptr, *field, *timestamp_field;
3116
3124
if (!show_table->read_set)
3118
3126
/* to satisfy 'field->val_str' ASSERTs */
3119
unsigned char *bitmaps;
3120
uint32_t bitmap_size= show_table_share->column_bitmap_size;
3121
if (!(bitmaps= (unsigned char*) alloc_root(thd->mem_root, bitmap_size)))
3128
uint bitmap_size= show_table_share->column_bitmap_size;
3129
if (!(bitmaps= (uchar*) alloc_root(thd->mem_root, bitmap_size)))
3123
3131
bitmap_init(&show_table->def_read_set,
3124
3132
(my_bitmap_map*) bitmaps, show_table_share->fields, false);
3158
3166
table->field[5]->store(type.ptr(), type.length(), cs);
3159
3167
table->field[5]->set_notnull();
3161
pos=(unsigned char*) ((field->flags & NOT_NULL_FLAG) ? "NO" : "YES");
3169
pos=(uchar*) ((field->flags & NOT_NULL_FLAG) ? "NO" : "YES");
3162
3170
table->field[6]->store((const char*) pos,
3163
3171
strlen((const char*) pos), cs);
3164
3172
store_column_type(table, field, cs, 7);
3166
pos=(unsigned char*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
3174
pos=(uchar*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
3167
3175
(field->flags & UNIQUE_KEY_FLAG) ? "UNI" :
3168
3176
(field->flags & MULTIPLE_KEY_FLAG) ? "MUL":"");
3169
3177
table->field[15]->store((const char*) pos,
3182
3190
enum column_format_type column_format= (enum column_format_type)
3183
3191
((field->flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
3184
pos=(unsigned char*)"Default";
3192
pos=(uchar*)"Default";
3185
3193
table->field[19]->store((const char*) pos,
3186
3194
strlen((const char*) pos), cs);
3187
pos=(unsigned char*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
3195
pos=(uchar*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
3188
3196
column_format == COLUMN_FORMAT_TYPE_FIXED ? "Fixed" :
3190
3198
table->field[20]->store((const char*) pos,
3201
int fill_schema_charsets(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3209
int fill_schema_charsets(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3203
3211
CHARSET_INFO **cs;
3204
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3205
Table *table= tables->table;
3206
const CHARSET_INFO * const scs= system_charset_info;
3212
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3213
TABLE *table= tables->table;
3214
CHARSET_INFO *scs= system_charset_info;
3208
3216
for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
3210
const CHARSET_INFO * const tmp_cs= cs[0];
3218
CHARSET_INFO *tmp_cs= cs[0];
3211
3219
if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) &&
3212
3220
(tmp_cs->state & MY_CS_AVAILABLE) &&
3213
3221
!(tmp_cs->state & MY_CS_HIDDEN) &&
3214
3222
!(wild && wild[0] &&
3215
wild_case_compare(scs, tmp_cs->csname,wild)))
3223
wild_case_compare(scs, tmp_cs->csname,wild)))
3217
3225
const char *comment;
3218
3226
restore_record(table, s->default_values);
3232
int fill_schema_collation(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3240
int fill_schema_collation(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3234
3242
CHARSET_INFO **cs;
3235
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3236
Table *table= tables->table;
3237
const CHARSET_INFO * const scs= system_charset_info;
3243
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3244
TABLE *table= tables->table;
3245
CHARSET_INFO *scs= system_charset_info;
3238
3246
for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3240
3248
CHARSET_INFO **cl;
3241
const CHARSET_INFO *tmp_cs= cs[0];
3249
CHARSET_INFO *tmp_cs= cs[0];
3242
3250
if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3243
3251
(tmp_cs->state & MY_CS_HIDDEN) ||
3244
3252
!(tmp_cs->state & MY_CS_PRIMARY))
3246
3254
for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3248
const CHARSET_INFO *tmp_cl= cl[0];
3256
CHARSET_INFO *tmp_cl= cl[0];
3249
3257
if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3250
3258
!my_charset_same(tmp_cs, tmp_cl))
3252
3260
if (!(wild && wild[0] &&
3253
wild_case_compare(scs, tmp_cl->name,wild)))
3261
wild_case_compare(scs, tmp_cl->name,wild)))
3255
const char *tmp_buff;
3256
restore_record(table, s->default_values);
3257
table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3263
const char *tmp_buff;
3264
restore_record(table, s->default_values);
3265
table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3258
3266
table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3259
3267
table->field[2]->store((int64_t) tmp_cl->number, true);
3260
3268
tmp_buff= (tmp_cl->state & MY_CS_PRIMARY) ? "Yes" : "";
3261
table->field[3]->store(tmp_buff, strlen(tmp_buff), scs);
3269
table->field[3]->store(tmp_buff, strlen(tmp_buff), scs);
3262
3270
tmp_buff= (tmp_cl->state & MY_CS_COMPILED)? "Yes" : "";
3263
table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
3271
table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
3264
3272
table->field[5]->store((int64_t) tmp_cl->strxfrm_multiply, true);
3265
3273
if (schema_table_store_record(thd, table))
3274
int fill_schema_coll_charset_app(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3282
int fill_schema_coll_charset_app(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3276
3284
CHARSET_INFO **cs;
3277
Table *table= tables->table;
3278
const CHARSET_INFO * const scs= system_charset_info;
3285
TABLE *table= tables->table;
3286
CHARSET_INFO *scs= system_charset_info;
3279
3287
for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3281
3289
CHARSET_INFO **cl;
3282
const CHARSET_INFO *tmp_cs= cs[0];
3290
CHARSET_INFO *tmp_cs= cs[0];
3283
3291
if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3284
3292
!(tmp_cs->state & MY_CS_PRIMARY))
3286
3294
for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3288
const CHARSET_INFO *tmp_cl= cl[0];
3296
CHARSET_INFO *tmp_cl= cl[0];
3289
3297
if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3290
3298
!my_charset_same(tmp_cs,tmp_cl))
3327
Table *show_table= tables->table;
3335
TABLE *show_table= tables->table;
3328
3336
KEY *key_info=show_table->s->key_info;
3329
3337
if (show_table->file)
3330
3338
show_table->file->info(HA_STATUS_VARIABLE |
3331
3339
HA_STATUS_NO_LOCK |
3332
3340
HA_STATUS_TIME);
3333
for (uint32_t i=0 ; i < show_table->s->keys ; i++,key_info++)
3341
for (uint i=0 ; i < show_table->s->keys ; i++,key_info++)
3335
3343
KEY_PART_INFO *key_part= key_info->key_part;
3336
3344
const char *str;
3337
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
3345
for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
3339
3347
restore_record(table, s->default_values);
3340
3348
table->field[1]->store(db_name->str, db_name->length, cs);
3375
3383
key_part->field->charset()->mbmaxlen, true);
3376
3384
table->field[10]->set_notnull();
3378
uint32_t flags= key_part->field ? key_part->field->flags : 0;
3386
uint flags= key_part->field ? key_part->field->flags : 0;
3379
3387
const char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES");
3380
3388
table->field[12]->store(pos, strlen(pos), cs);
3381
3389
if (!show_table->s->keys_in_use.is_set(i))
3400
bool store_constraints(THD *thd, Table *table, LEX_STRING *db_name,
3408
bool store_constraints(THD *thd, TABLE *table, LEX_STRING *db_name,
3401
3409
LEX_STRING *table_name, const char *key_name,
3402
uint32_t key_len, const char *con_type, uint32_t con_len)
3410
uint key_len, const char *con_type, uint con_len)
3404
const CHARSET_INFO * const cs= system_charset_info;
3412
CHARSET_INFO *cs= system_charset_info;
3405
3413
restore_record(table, s->default_values);
3406
3414
table->field[1]->store(db_name->str, db_name->length, cs);
3407
3415
table->field[2]->store(key_name, key_len, cs);
3415
static int get_schema_constraints_record(THD *thd, TableList *tables,
3416
Table *table, bool res,
3423
static int get_schema_constraints_record(THD *thd, TABLE_LIST *tables,
3424
TABLE *table, bool res,
3417
3425
LEX_STRING *db_name,
3418
3426
LEX_STRING *table_name)
3422
3430
if (thd->is_error())
3423
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3431
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3424
3432
thd->main_da.sql_errno(), thd->main_da.message());
3425
3433
thd->clear_error();
3430
3438
List<FOREIGN_KEY_INFO> f_key_list;
3431
Table *show_table= tables->table;
3439
TABLE *show_table= tables->table;
3432
3440
KEY *key_info=show_table->key_info;
3433
uint32_t primary_key= show_table->s->primary_key;
3441
uint primary_key= show_table->s->primary_key;
3434
3442
show_table->file->info(HA_STATUS_VARIABLE |
3435
3443
HA_STATUS_NO_LOCK |
3436
3444
HA_STATUS_TIME);
3437
for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
3445
for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
3439
3447
if (i != primary_key && !(key_info->flags & HA_NOSAME))
3474
void store_key_column_usage(Table *table, LEX_STRING *db_name,
3482
void store_key_column_usage(TABLE *table, LEX_STRING *db_name,
3475
3483
LEX_STRING *table_name, const char *key_name,
3476
uint32_t key_len, const char *con_type, uint32_t con_len,
3484
uint key_len, const char *con_type, uint con_len,
3479
const CHARSET_INFO * const cs= system_charset_info;
3487
CHARSET_INFO *cs= system_charset_info;
3480
3488
table->field[1]->store(db_name->str, db_name->length, cs);
3481
3489
table->field[2]->store(key_name, key_len, cs);
3482
3490
table->field[4]->store(db_name->str, db_name->length, cs);
3505
3513
List<FOREIGN_KEY_INFO> f_key_list;
3506
Table *show_table= tables->table;
3514
TABLE *show_table= tables->table;
3507
3515
KEY *key_info=show_table->key_info;
3508
uint32_t primary_key= show_table->s->primary_key;
3516
uint primary_key= show_table->s->primary_key;
3509
3517
show_table->file->info(HA_STATUS_VARIABLE |
3510
3518
HA_STATUS_NO_LOCK |
3511
3519
HA_STATUS_TIME);
3512
for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
3520
for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
3514
3522
if (i != primary_key && !(key_info->flags & HA_NOSAME))
3517
3525
KEY_PART_INFO *key_part= key_info->key_part;
3518
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
3526
for (uint j=0 ; j < key_info->key_parts ; j++,key_part++)
3520
3528
if (key_part->field)
3578
int fill_open_tables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3586
int fill_open_tables(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3580
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NULL;
3581
Table *table= tables->table;
3582
const CHARSET_INFO * const cs= system_charset_info;
3583
OPEN_TableList *open_list;
3588
const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS;
3589
TABLE *table= tables->table;
3590
CHARSET_INFO *cs= system_charset_info;
3591
OPEN_TABLE_LIST *open_list;
3584
3592
if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3585
3593
&& thd->is_fatal_error)
3602
int fill_variables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3610
int fill_variables(THD *thd, TABLE_LIST *tables, COND *cond __attribute__((unused)))
3605
3613
LEX *lex= thd->lex;
3606
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3614
const char *wild= lex->wild ? lex->wild->ptr() : NullS;
3607
3615
enum enum_schema_tables schema_table_idx=
3608
3616
get_schema_table_idx(tables->schema_table);
3609
3617
enum enum_var_type option_type= OPT_SESSION;
3686
get_referential_constraints_record(THD *thd, TableList *tables,
3687
Table *table, bool res,
3694
get_referential_constraints_record(THD *thd, TABLE_LIST *tables,
3695
TABLE *table, bool res,
3688
3696
LEX_STRING *db_name, LEX_STRING *table_name)
3690
const CHARSET_INFO * const cs= system_charset_info;
3698
CHARSET_INFO *cs= system_charset_info;
3694
3702
if (thd->is_error())
3695
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3703
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
3696
3704
thd->main_da.sql_errno(), thd->main_da.message());
3697
3705
thd->clear_error();
3835
3843
@retval NULL Can't create table
3838
Table *create_schema_table(THD *thd, TableList *table_list)
3846
TABLE *create_schema_table(THD *thd, TABLE_LIST *table_list)
3840
3848
int field_count= 0;
3843
3851
List<Item> field_list;
3844
3852
ST_SCHEMA_TABLE *schema_table= table_list->schema_table;
3845
3853
ST_FIELD_INFO *fields_info= schema_table->fields_info;
3846
const CHARSET_INFO * const cs= system_charset_info;
3854
CHARSET_INFO *cs= system_charset_info;
3848
3856
for (; fields_info->field_name; fields_info++)
3850
3858
switch (fields_info->field_type) {
3851
3859
case DRIZZLE_TYPE_TINY:
3852
3860
case DRIZZLE_TYPE_LONG:
3861
case DRIZZLE_TYPE_SHORT:
3853
3862
case DRIZZLE_TYPE_LONGLONG:
3854
3863
if (!(item= new Item_return_int(fields_info->field_name,
3855
3864
fields_info->field_length,
3918
3927
tmp_table_param->schema_table= 1;
3919
3928
SELECT_LEX *select_lex= thd->lex->current_select;
3920
3929
if (!(table= create_tmp_table(thd, tmp_table_param,
3921
field_list, (order_st*) 0, 0, 0,
3930
field_list, (ORDER*) 0, 0, 0,
3922
3931
(select_lex->options | thd->options |
3923
3932
TMP_TABLE_ALL_COLUMNS),
3924
3933
HA_POS_ERROR, table_list->alias)))
3985
3994
ST_FIELD_INFO *field_info= &schema_table->fields_info[1];
3986
3995
String buffer(tmp,sizeof(tmp), system_charset_info);
3987
3996
Item_field *field= new Item_field(context,
3988
NULL, NULL, field_info->field_name);
3997
NullS, NullS, field_info->field_name);
3989
3998
if (!field || add_item_to_list(thd, field))
3991
4000
buffer.length(0);
4029
4038
field->set_name(buffer.ptr(), buffer.length(), system_charset_info);
4030
4039
field_info= &schema_table->fields_info[3];
4031
field= new Item_field(context, NULL, NULL, field_info->field_name);
4040
field= new Item_field(context, NullS, NullS, field_info->field_name);
4032
4041
if (add_item_to_list(thd, field))
4034
4043
field->set_name(field_info->old_name, strlen(field_info->old_name),
4582
4592
create_schema_table, fill_schema_coll_charset_app, 0, 0, -1, -1, 0, 0},
4583
4593
{"COLUMNS", columns_fields_info, create_schema_table,
4584
4594
get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2, 0,
4585
OPTIMIZE_I_S_TABLE},
4595
OPTIMIZE_I_S_TABLE|OPEN_VIEW_FULL},
4586
4596
{"GLOBAL_STATUS", variables_fields_info, create_schema_table,
4587
4597
fill_status, make_old_format, 0, -1, -1, 0, 0},
4588
4598
{"GLOBAL_VARIABLES", variables_fields_info, create_schema_table,