61
return(0); /* '*' as last char: OK */
112
return (0); /* '*' as last char: OK */
62
113
flag=(*wildstr != wild_many && *wildstr != wild_one);
68
if ((cmp= *wildstr) == wild_prefix && wildstr[1])
70
cmp=my_toupper(cs, cmp);
71
while (*str && my_toupper(cs, *str) != cmp)
119
if ((cmp= *wildstr) == wild_prefix && wildstr[1])
121
cmp= my_toupper(cs, cmp);
122
while (*str && my_toupper(cs, *str) != cmp)
127
if (wild_case_compare(cs, str, wildstr) == 0)
76
if (wild_case_compare(cs, str,wildstr) == 0)
82
133
return (*str != '\0');
85
/***************************************************************************
86
** List all table types supported
87
***************************************************************************/
89
static bool show_plugins(THD *thd, plugin_ref plugin,
92
Table *table= (Table*) arg;
93
struct st_mysql_plugin *plug= plugin_decl(plugin);
94
struct st_plugin_dl *plugin_dl= plugin_dlib(plugin);
95
const CHARSET_INFO * const cs= system_charset_info;
97
restore_record(table, s->default_values);
99
table->field[0]->store(plugin_name(plugin)->str,
100
plugin_name(plugin)->length, cs);
104
table->field[1]->store(plug->version, strlen(plug->version), cs);
105
table->field[1]->set_notnull();
108
table->field[1]->set_null();
110
switch (plugin_state(plugin)) {
111
/* case PLUGIN_IS_FREED: does not happen */
112
case PLUGIN_IS_DELETED:
113
table->field[2]->store(STRING_WITH_LEN("DELETED"), cs);
115
case PLUGIN_IS_UNINITIALIZED:
116
table->field[2]->store(STRING_WITH_LEN("INACTIVE"), cs);
118
case PLUGIN_IS_READY:
119
table->field[2]->store(STRING_WITH_LEN("ACTIVE"), cs);
125
table->field[3]->store(plugin_type_names[plug->type].str,
126
plugin_type_names[plug->type].length,
131
table->field[4]->store(plugin_dl->dl.str, plugin_dl->dl.length, cs);
132
table->field[4]->set_notnull();
136
table->field[4]->set_null();
141
table->field[5]->store(plug->author, strlen(plug->author), cs);
142
table->field[5]->set_notnull();
145
table->field[5]->set_null();
149
table->field[6]->store(plug->descr, strlen(plug->descr), cs);
150
table->field[6]->set_notnull();
153
table->field[6]->set_null();
155
switch (plug->license) {
156
case PLUGIN_LICENSE_GPL:
157
table->field[7]->store(PLUGIN_LICENSE_GPL_STRING,
158
strlen(PLUGIN_LICENSE_GPL_STRING), cs);
160
case PLUGIN_LICENSE_BSD:
161
table->field[7]->store(PLUGIN_LICENSE_BSD_STRING,
162
strlen(PLUGIN_LICENSE_BSD_STRING), cs);
165
table->field[7]->store(PLUGIN_LICENSE_PROPRIETARY_STRING,
166
strlen(PLUGIN_LICENSE_PROPRIETARY_STRING), cs);
169
table->field[7]->set_notnull();
171
return schema_table_store_record(thd, table);
175
int fill_plugins(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
177
Table *table= tables->table;
179
if (plugin_foreach_with_mask(thd, show_plugins, DRIZZLE_ANY_PLUGIN,
180
~PLUGIN_IS_FREED, table))
188
find_files() - find files in a given directory.
193
files put found files in this list
194
db database name to set in TableList structure
195
path path to database
196
wild filter for found files
197
dir read databases in path if true, read .frm files in
201
FIND_FILES_OK success
202
FIND_FILES_OOM out of memory error
203
FIND_FILES_DIR no such directory, or directory can't be read
208
find_files(THD *thd, List<LEX_STRING> *files, const char *db,
209
const char *path, const char *wild, bool dir)
215
LEX_STRING *file_name= 0;
216
uint32_t file_name_len;
217
TableList table_list;
219
if (wild && !wild[0])
222
memset(&table_list, 0, sizeof(table_list));
224
if (!(dirp = my_dir(path,MYF(dir ? MY_WANT_STAT : 0))))
226
if (my_errno == ENOENT)
227
my_error(ER_BAD_DB_ERROR, MYF(ME_BELL+ME_WAITTANG), db);
229
my_error(ER_CANT_READ_DIR, MYF(ME_BELL+ME_WAITTANG), path, my_errno);
230
return(FIND_FILES_DIR);
233
for (i=0 ; i < (uint) dirp->number_off_files ; i++)
139
* Find subdirectories (schemas) in a given directory (datadir).
141
* @param[in] session Thread handler
142
* @param[out] files Put found entries in this list
143
* @param[in] path Path to database
144
* @param[in] wild Filter for found entries
146
* @retval false Success
149
static bool find_schemas(Session *session, vector<LEX_STRING*> &files,
150
const char *path, const char *wild)
152
if (wild && (wild[0] == '\0'))
155
CachedDirectory directory(path);
157
if (directory.fail())
159
my_errno= directory.getError();
160
my_error(ER_CANT_READ_DIR, MYF(0), path, my_errno);
164
CachedDirectory::Entries entries= directory.getEntries();
165
CachedDirectory::Entries::iterator entry_iter= entries.begin();
167
while (entry_iter != entries.end())
169
uint32_t file_name_len;
235
170
char uname[NAME_LEN + 1]; /* Unencoded name */
236
file=dirp->dir_entry+i;
238
{ /* Return databases */
239
if ((file->name[0] == '.' &&
240
((file->name[1] == '.' && file->name[2] == '\0') ||
241
file->name[1] == '\0')))
242
continue; /* . or .. */
245
char buff[FN_REFLEN];
246
if (my_use_symdir && !strcmp(ext=fn_ext(file->name), ".sym"))
248
/* Only show the sym file if it points to a directory */
250
*ext=0; /* Remove extension */
251
unpack_dirname(buff, file->name);
252
end= strchr(buff, '\0');
253
if (end != buff && end[-1] == FN_LIBCHAR)
254
end[-1]= 0; // Remove end FN_LIBCHAR
255
if (stat(buff, file->mystat))
259
if (!S_ISDIR(file->mystat->st_mode))
262
file_name_len= filename_to_tablename(file->name, uname, sizeof(uname));
263
if (wild && wild_compare(uname, wild, 0))
266
thd->make_lex_string(file_name, uname, file_name_len, true)))
269
return(FIND_FILES_OOM);
274
// Return only .frm files which aren't temp files.
275
if (my_strcasecmp(system_charset_info, ext=fn_rext(file->name),reg_ext) ||
276
is_prefix(file->name, tmp_file_prefix))
279
file_name_len= filename_to_tablename(file->name, uname, sizeof(uname));
282
if (lower_case_table_names)
284
if (wild_case_compare(files_charset_info, uname, wild))
287
else if (wild_compare(uname, wild, 0))
292
thd->make_lex_string(file_name, uname, file_name_len, true)) ||
293
files->push_back(file_name))
296
return(FIND_FILES_OOM);
171
struct stat entry_stat;
172
CachedDirectory::Entry *entry= *entry_iter;
174
if ((entry->filename == ".") || (entry->filename == ".."))
180
if (stat(entry->filename.c_str(), &entry_stat))
183
my_error(ER_CANT_GET_STAT, MYF(0), entry->filename.c_str(), my_errno);
187
if (! S_ISDIR(entry_stat.st_mode))
193
file_name_len= filename_to_tablename(entry->filename.c_str(), uname,
195
if (wild && wild_compare(uname, wild, 0))
201
LEX_STRING *file_name= 0;
202
file_name= session->make_lex_string(file_name, uname, file_name_len, true);
203
if (file_name == NULL)
206
files.push_back(file_name);
301
return(FIND_FILES_OK);
306
mysqld_show_create(THD *thd, TableList *table_list)
214
bool drizzled_show_create(Session *session, TableList *table_list)
308
Protocol *protocol= thd->protocol;
216
plugin::Protocol *protocol= session->protocol;
310
218
String buffer(buff, sizeof(buff), system_charset_info);
312
220
/* Only one table for now, but VIEW can involve several tables */
313
if (open_normal_and_derived_tables(thd, table_list, 0))
221
if (session->openTables(table_list))
315
if (thd->is_error() && thd->main_da.sql_errno() != ER_VIEW_INVALID)
223
if (session->is_error())
319
227
Clear all messages with 'error' level status and
320
issue a warning with 'warning' level status in
228
issue a warning with 'warning' level status in
321
229
case of invalid view and last error is ER_VIEW_INVALID
323
drizzle_reset_errors(thd, true);
231
drizzle_reset_errors(session, true);
232
session->clear_error();
327
235
buffer.length(0);
329
if (store_create_info(thd, table_list, &buffer, NULL))
237
if (store_create_info(table_list, &buffer, NULL))
332
240
List<Item> field_list;
334
242
field_list.push_back(new Item_empty_string("Table",NAME_CHAR_LEN));
335
243
// 1024 is for not to confuse old clients
336
244
field_list.push_back(new Item_empty_string("Create Table",
337
cmax(buffer.length(),(uint32_t)1024)));
245
max(buffer.length(),(uint32_t)1024)));
340
if (protocol->send_fields(&field_list,
341
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
343
protocol->prepare_for_resend();
248
if (protocol->sendFields(&field_list))
250
protocol->prepareForResend();
345
252
if (table_list->schema_table)
346
protocol->store(table_list->schema_table->table_name,
347
system_charset_info);
253
protocol->store(table_list->schema_table->getTableName().c_str());
349
protocol->store(table_list->table->alias, system_charset_info);
255
protocol->store(table_list->table->alias);
352
protocol->store(buffer.ptr(), buffer.length(), buffer.charset());
258
protocol->store(buffer.ptr(), buffer.length());
354
260
if (protocol->write())
361
bool mysqld_show_create_db(THD *thd, char *dbname,
362
HA_CREATE_INFO *create_info)
268
Get a CREATE statement for a given database.
270
The database is identified by its name, passed as @c dbname parameter.
271
The name should be encoded using the system character set (UTF8 currently).
273
Resulting statement is stored in the string pointed by @c buffer. The string
274
is emptied first and its character set is set to the system character set.
276
If HA_LEX_CREATE_IF_NOT_EXISTS flag is set in @c create_info->options, then
277
the resulting CREATE statement contains "IF NOT EXISTS" clause. Other flags
278
in @c create_options are ignored.
280
@param session The current thread instance.
281
@param dbname The name of the database.
282
@param buffer A String instance where the statement is stored.
283
@param create_info If not NULL, the options member influences the resulting
286
@returns true if errors are detected, false otherwise.
289
static bool store_db_create_info(const char *dbname, String *buffer, bool if_not_exists)
291
drizzled::message::Schema schema;
293
if (!my_strcasecmp(system_charset_info, dbname,
294
INFORMATION_SCHEMA_NAME.c_str()))
296
dbname= INFORMATION_SCHEMA_NAME.c_str();
300
int r= get_database_metadata(dbname, &schema);
307
buffer->set_charset(system_charset_info);
308
buffer->append(STRING_WITH_LEN("CREATE DATABASE "));
311
buffer->append(STRING_WITH_LEN("IF NOT EXISTS "));
313
buffer->append_identifier(dbname, strlen(dbname));
315
if (schema.has_collation() && strcmp(schema.collation().c_str(),
316
default_charset_info->name))
318
buffer->append(" COLLATE = ");
319
buffer->append(schema.collation().c_str());
325
bool mysqld_show_create_db(Session *session, char *dbname, bool if_not_exists)
365
328
String buffer(buff, sizeof(buff), system_charset_info);
366
Protocol *protocol=thd->protocol;
329
plugin::Protocol *protocol= session->protocol;
368
if (store_db_create_info(thd, dbname, &buffer, create_info))
331
if (store_db_create_info(dbname, &buffer, if_not_exists))
371
334
This assumes that the only reason for which store_db_create_info()
372
335
can fail is incorrect database name (which is the case now).
374
337
my_error(ER_BAD_DB_ERROR, MYF(0), dbname);
378
341
List<Item> field_list;
379
342
field_list.push_back(new Item_empty_string("Database",NAME_CHAR_LEN));
380
343
field_list.push_back(new Item_empty_string("Create Database",1024));
382
if (protocol->send_fields(&field_list,
383
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
345
if (protocol->sendFields(&field_list))
386
protocol->prepare_for_resend();
387
protocol->store(dbname, strlen(dbname), system_charset_info);
388
protocol->store(buffer.ptr(), buffer.length(), buffer.charset());
348
protocol->prepareForResend();
349
protocol->store(dbname, strlen(dbname));
350
protocol->store(buffer.ptr(), buffer.length());
390
352
if (protocol->write())
398
/****************************************************************************
399
Return only fields for API mysql_list_fields
400
Use "show table wildcard" in mysql instead of this
401
****************************************************************************/
404
mysqld_list_fields(THD *thd, TableList *table_list, const char *wild)
408
if (open_normal_and_derived_tables(thd, table_list, 0))
410
table= table_list->table;
412
List<Item> field_list;
415
for (ptr=table->field ; (field= *ptr); ptr++)
417
if (!wild || !wild[0] ||
418
!wild_case_compare(system_charset_info, field->field_name,wild))
420
field_list.push_back(new Item_field(field));
423
restore_record(table, s->default_values); // Get empty record
424
table->use_all_columns();
425
if (thd->protocol->send_fields(&field_list, Protocol::SEND_DEFAULTS))
433
Go through all character combinations and ensure that sql_lex.cc can
434
parse it as an identifier.
439
name_length length of name
442
# Pointer to conflicting character
443
0 No conflicting character
446
static const char *require_quotes(const char *name, uint32_t name_length)
449
bool pure_digit= true;
450
const char *end= name + name_length;
452
for (; name < end ; name++)
454
unsigned char chr= (unsigned char) *name;
455
length= my_mbcharlen(system_charset_info, chr);
456
if (length == 1 && !system_charset_info->ident_map[chr])
458
if (length == 1 && (chr < '0' || chr > '9'))
468
Quote the given identifier if needed and append it to the target string.
469
If the given identifier is empty, it will be quoted.
475
name the identifier to be appended
476
name_length length of the appending identifier
480
append_identifier(THD *thd, String *packet, const char *name, uint32_t length)
482
const char *name_end;
484
int q= get_quote_char_for_identifier(thd, name, length);
488
packet->append(name, length, packet->charset());
493
The identifier must be quoted as it includes a quote character or
497
packet->reserve(length*2 + 2);
498
quote_char= (char) q;
499
packet->append("e_char, 1, system_charset_info);
501
for (name_end= name+length ; name < name_end ; name+= length)
503
unsigned char chr= (unsigned char) *name;
504
length= my_mbcharlen(system_charset_info, chr);
506
my_mbcharlen can return 0 on a wrong multibyte
507
sequence. It is possible when upgrading from 4.0,
508
and identifier contains some accented characters.
509
The manual says it does not work. So we'll just
510
change length to 1 not to hang in the endless loop.
514
if (length == 1 && chr == (unsigned char) quote_char)
515
packet->append("e_char, 1, system_charset_info);
516
packet->append(name, length, system_charset_info);
518
packet->append("e_char, 1, system_charset_info);
523
359
Get the quote character for displaying an identifier.
526
362
get_quote_char_for_identifier()
529
length length of name
532
365
Force quoting in the following cases:
2562
if (make_db_list(thd, &db_names, &lookup_field_vals, &with_i_schema))
1955
table->setWriteSet();
1956
if (make_db_list(session, db_names, &lookup_field_vals, &with_i_schema))
2564
it.rewind(); /* To get access to new elements in basis list */
2565
while ((db_name= it++))
1959
for (vector<LEX_STRING*>::iterator db_name= db_names.begin(); db_name != db_names.end(); ++db_name )
1961
session->no_warnings_for_error= 1;
1962
table_names.clear();
1963
int res= make_table_name_list(session, table_names, lex,
1965
with_i_schema, *db_name);
1967
if (res == 2) /* Not fatal error, continue */
1974
for (vector<LEX_STRING*>::iterator table_name= table_names.begin(); table_name != table_names.end(); ++table_name)
2568
thd->no_warnings_for_error= 1;
2569
List<LEX_STRING> table_names;
2570
int res= make_table_name_list(thd, &table_names, lex,
2572
with_i_schema, db_name);
2573
if (res == 2) /* Not fatal error, continue */
1976
table->restoreRecordAsDefault();
1977
table->field[schema_table->getFirstColumnIndex()]->
1978
store((*db_name)->str, (*db_name)->length, system_charset_info);
1979
table->field[schema_table->getSecondColumnIndex()]->
1980
store((*table_name)->str, (*table_name)->length, system_charset_info);
2578
List_iterator_fast<LEX_STRING> it_files(table_names);
2579
while ((table_name= it_files++))
1982
if (!partial_cond || partial_cond->val_int())
2581
restore_record(table, s->default_values);
2582
table->field[schema_table->idx_field1]->
2583
store(db_name->str, db_name->length, system_charset_info);
2584
table->field[schema_table->idx_field2]->
2585
store(table_name->str, table_name->length, system_charset_info);
1985
If table is I_S.tables and open_table_method is 0 (eg SKIP_OPEN)
1986
we can skip table opening and we don't have lookup value for
1987
table name or lookup value is wild string(table name list is
1988
already created by make_table_name_list() function).
1990
if (! table_open_method &&
1991
schema_table->getTableName().compare("TABLES") == 0 &&
1992
(! lookup_field_vals.table_value.length ||
1993
lookup_field_vals.wild_table_value))
1995
if (schema_table_store_record(session, table))
1996
goto err; /* Out of space in temporary table */
2587
if (!partial_cond || partial_cond->val_int())
2000
/* SHOW Table NAMES command */
2001
if (schema_table->getTableName().compare("TABLE_NAMES") == 0)
2590
If table is I_S.tables and open_table_method is 0 (eg SKIP_OPEN)
2591
we can skip table opening and we don't have lookup value for
2592
table name or lookup value is wild string(table name list is
2593
already created by make_table_name_list() function).
2595
if (!table_open_method && schema_table_idx == SCH_TABLES &&
2596
(!lookup_field_vals.table_value.length ||
2597
lookup_field_vals.wild_table_value))
2599
if (schema_table_store_record(thd, table))
2600
goto err; /* Out of space in temporary table */
2003
if (fill_schema_table_names(session, tables->table, *db_name,
2004
*table_name, with_i_schema))
2604
/* SHOW Table NAMES command */
2605
if (schema_table_idx == SCH_TABLE_NAMES)
2009
if (!(table_open_method & ~OPEN_FRM_ONLY) &&
2607
if (fill_schema_table_names(thd, tables->table, db_name,
2608
table_name, with_i_schema))
2012
if (!fill_schema_table_from_frm(session, tables, schema_table, *db_name,
2017
LEX_STRING tmp_lex_string, orig_db_name;
2019
Set the parent lex of 'sel' because it is needed by
2020
sel.init_query() which is called inside make_table_list.
2022
session->no_warnings_for_error= 1;
2023
sel.parent_lex= lex;
2024
/* db_name can be changed in make_table_list() func */
2025
if (!session->make_lex_string(&orig_db_name, (*db_name)->str,
2026
(*db_name)->length, false))
2029
if (make_table_list(session, &sel, *db_name, *table_name))
2032
TableList *show_table_list= (TableList*) sel.table_list.first;
2033
lex->all_selects_list= &sel;
2034
lex->derived_tables= 0;
2035
lex->sql_command= SQLCOM_SHOW_FIELDS;
2036
show_table_list->i_s_requested_object=
2037
schema_table->getRequestedObject();
2038
res= session->openTables(show_table_list, DRIZZLE_LOCK_IGNORE_FLUSH);
2039
lex->sql_command= save_sql_command;
2041
XXX-> show_table_list has a flag i_is_requested,
2042
and when it's set, openTables()
2043
can return an error without setting an error message
2044
in Session, which is a hack. This is why we have to
2045
check for res, then for session->is_error() only then
2046
for session->main_da.sql_errno().
2048
if (res && session->is_error() &&
2049
session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2052
Hide error for not existing table.
2053
This error can occur for example when we use
2054
where condition with db name and table name and this
2055
table does not exist.
2058
session->clear_error();
2613
if (!(table_open_method & ~OPEN_FRM_ONLY) &&
2616
if (!fill_schema_table_from_frm(thd, tables, schema_table, db_name,
2617
table_name, schema_table_idx))
2622
LEX_STRING tmp_lex_string, orig_db_name;
2624
Set the parent lex of 'sel' because it is needed by
2625
sel.init_query() which is called inside make_table_list.
2627
thd->no_warnings_for_error= 1;
2628
sel.parent_lex= lex;
2629
/* db_name can be changed in make_table_list() func */
2630
if (!thd->make_lex_string(&orig_db_name, db_name->str,
2631
db_name->length, false))
2633
if (make_table_list(thd, &sel, db_name, table_name))
2635
TableList *show_table_list= (TableList*) sel.table_list.first;
2636
lex->all_selects_list= &sel;
2637
lex->derived_tables= 0;
2638
lex->sql_command= SQLCOM_SHOW_FIELDS;
2639
show_table_list->i_s_requested_object=
2640
schema_table->i_s_requested_object;
2641
res= open_normal_and_derived_tables(thd, show_table_list,
2642
DRIZZLE_LOCK_IGNORE_FLUSH);
2643
lex->sql_command= save_sql_command;
2645
XXX: show_table_list has a flag i_is_requested,
2646
and when it's set, open_normal_and_derived_tables()
2647
can return an error without setting an error message
2648
in THD, which is a hack. This is why we have to
2649
check for res, then for thd->is_error() only then
2650
for thd->main_da.sql_errno().
2652
if (res && thd->is_error() &&
2653
thd->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2656
Hide error for not existing table.
2657
This error can occur for example when we use
2658
where condition with db name and table name and this
2659
table does not exist.
2667
We should use show_table_list->alias instead of
2668
show_table_list->table_name because table_name
2669
could be changed during opening of I_S tables. It's safe
2670
to use alias because alias contains original table name
2673
thd->make_lex_string(&tmp_lex_string, show_table_list->alias,
2674
strlen(show_table_list->alias), false);
2675
res= schema_table->process_table(thd, show_table_list, table,
2678
close_tables_for_reopen(thd, &show_table_list);
2680
assert(!lex->query_tables_own_last);
2063
We should use show_table_list->alias instead of
2064
show_table_list->table_name because table_name
2065
could be changed during opening of I_S tables. It's safe
2066
to use alias because alias contains original table name
2069
session->make_lex_string(&tmp_lex_string, show_table_list->alias,
2070
strlen(show_table_list->alias), false);
2071
res= schema_table->processTable(session, show_table_list, table,
2074
session->close_tables_for_reopen(&show_table_list);
2076
assert(!lex->query_tables_own_last);
2687
If we have information schema its always the first table and only
2688
the first table. Reset for other tables.
2083
If we have information schema its always the first table and only
2084
the first table. Reset for other tables.
2696
thd->restore_backup_open_tables_state(&open_tables_state_backup);
2697
lex->restore_backup_query_tables_list(&query_tables_list_backup);
2092
session->restore_backup_open_tables_state(&open_tables_state_backup);
2698
2093
lex->derived_tables= derived_tables;
2699
2094
lex->all_selects_list= old_all_select_lex;
2700
2095
lex->sql_command= save_sql_command;
2701
thd->no_warnings_for_error= old_value;
2096
session->no_warnings_for_error= old_value;
2706
bool store_schema_shemata(THD* thd, Table *table, LEX_STRING *db_name,
2707
const CHARSET_INFO * const cs)
2709
restore_record(table, s->default_values);
2710
table->field[1]->store(db_name->str, db_name->length, system_charset_info);
2711
table->field[2]->store(cs->csname, strlen(cs->csname), system_charset_info);
2712
table->field[3]->store(cs->name, strlen(cs->name), system_charset_info);
2713
return schema_table_store_record(thd, table);
2717
int fill_schema_schemata(THD *thd, TableList *tables, COND *cond)
2720
TODO: fill_schema_shemata() is called when new client is connected.
2721
Returning error status in this case leads to client hangup.
2724
LOOKUP_FIELD_VALUES lookup_field_vals;
2725
List<LEX_STRING> db_names;
2726
LEX_STRING *db_name;
2728
HA_CREATE_INFO create;
2729
Table *table= tables->table;
2731
if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
2733
if (make_db_list(thd, &db_names, &lookup_field_vals,
2738
If we have lookup db value we should check that the database exists
2740
if(lookup_field_vals.db_value.str && !lookup_field_vals.wild_db_value &&
2743
char path[FN_REFLEN+16];
2745
struct stat stat_info;
2746
if (!lookup_field_vals.db_value.str[0])
2748
path_len= build_table_filename(path, sizeof(path),
2749
lookup_field_vals.db_value.str, "", "", 0);
2750
path[path_len-1]= 0;
2751
if (stat(path,&stat_info))
2755
List_iterator_fast<LEX_STRING> it(db_names);
2756
while ((db_name=it++))
2758
if (with_i_schema) // information schema name is always first in list
2760
if (store_schema_shemata(thd, table, db_name,
2761
system_charset_info))
2767
load_db_opt_by_name(thd, db_name->str, &create);
2768
if (store_schema_shemata(thd, table, db_name,
2769
create.default_table_charset))
2777
static int get_schema_tables_record(THD *thd, TableList *tables,
2778
Table *table, bool res,
2779
LEX_STRING *db_name,
2780
LEX_STRING *table_name)
2782
const char *tmp_buff;
2784
const CHARSET_INFO * const cs= system_charset_info;
2786
restore_record(table, s->default_values);
2787
table->field[1]->store(db_name->str, db_name->length, cs);
2788
table->field[2]->store(table_name->str, table_name->length, cs);
2792
there was errors during opening tables
2794
const char *error= thd->is_error() ? thd->main_da.message() : "";
2795
if (tables->schema_table)
2796
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2798
table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2799
table->field[20]->store(error, strlen(error), cs);
2804
char option_buff[400],*ptr;
2805
Table *show_table= tables->table;
2806
TABLE_SHARE *share= show_table->s;
2807
handler *file= show_table->file;
2808
handlerton *tmp_db_type= share->db_type();
2809
if (share->tmp_table == SYSTEM_TMP_TABLE)
2810
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
2811
else if (share->tmp_table)
2812
table->field[3]->store(STRING_WITH_LEN("LOCAL TEMPORARY"), cs);
2814
table->field[3]->store(STRING_WITH_LEN("BASE Table"), cs);
2816
for (int i= 4; i < 20; i++)
2818
if (i == 7 || (i > 12 && i < 17) || i == 18)
2820
table->field[i]->set_notnull();
2822
tmp_buff= (char *) ha_resolve_storage_engine_name(tmp_db_type);
2823
table->field[4]->store(tmp_buff, strlen(tmp_buff), cs);
2824
table->field[5]->store((int64_t) share->frm_version, true);
2827
if (share->min_rows)
2829
ptr=my_stpcpy(ptr," min_rows=");
2830
ptr=int64_t10_to_str(share->min_rows,ptr,10);
2832
if (share->max_rows)
2834
ptr=my_stpcpy(ptr," max_rows=");
2835
ptr=int64_t10_to_str(share->max_rows,ptr,10);
2837
if (share->avg_row_length)
2839
ptr=my_stpcpy(ptr," avg_row_length=");
2840
ptr=int64_t10_to_str(share->avg_row_length,ptr,10);
2842
if (share->db_create_options & HA_OPTION_PACK_KEYS)
2843
ptr=my_stpcpy(ptr," pack_keys=1");
2844
if (share->db_create_options & HA_OPTION_NO_PACK_KEYS)
2845
ptr=my_stpcpy(ptr," pack_keys=0");
2846
/* We use CHECKSUM, instead of TABLE_CHECKSUM, for backward compability */
2847
if (share->db_create_options & HA_OPTION_CHECKSUM)
2848
ptr=my_stpcpy(ptr," checksum=1");
2849
if (share->page_checksum != HA_CHOICE_UNDEF)
2850
ptr= strxmov(ptr, " page_checksum=",
2851
ha_choice_values[(uint) share->page_checksum], NULL);
2852
if (share->db_create_options & HA_OPTION_DELAY_KEY_WRITE)
2853
ptr=my_stpcpy(ptr," delay_key_write=1");
2854
if (share->row_type != ROW_TYPE_DEFAULT)
2855
ptr=strxmov(ptr, " row_format=",
2856
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
if (share->transactional != HA_CHOICE_UNDEF)
2866
ptr= strxmov(ptr, " TRANSACTIONAL=",
2867
(share->transactional == HA_CHOICE_YES ? "1" : "0"),
2870
if (share->transactional != HA_CHOICE_UNDEF)
2871
ptr= strxmov(ptr, " transactional=",
2872
ha_choice_values[(uint) share->transactional], NULL);
2873
table->field[19]->store(option_buff+1,
2874
(ptr == option_buff ? 0 :
2875
(uint) (ptr-option_buff)-1), cs);
2877
tmp_buff= (share->table_charset ?
2878
share->table_charset->name : "default");
2879
table->field[17]->store(tmp_buff, strlen(tmp_buff), cs);
2881
if (share->comment.str)
2882
table->field[20]->store(share->comment.str, share->comment.length, cs);
2886
file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_AUTO |
2888
enum row_type row_type = file->get_row_type();
2890
case ROW_TYPE_NOT_USED:
2891
case ROW_TYPE_DEFAULT:
2892
tmp_buff= ((share->db_options_in_use &
2893
HA_OPTION_COMPRESS_RECORD) ? "Compressed" :
2894
(share->db_options_in_use & HA_OPTION_PACK_RECORD) ?
2895
"Dynamic" : "Fixed");
2897
case ROW_TYPE_FIXED:
2900
case ROW_TYPE_DYNAMIC:
2901
tmp_buff= "Dynamic";
2903
case ROW_TYPE_COMPRESSED:
2904
tmp_buff= "Compressed";
2906
case ROW_TYPE_REDUNDANT:
2907
tmp_buff= "Redundant";
2909
case ROW_TYPE_COMPACT:
2910
tmp_buff= "Compact";
2916
table->field[6]->store(tmp_buff, strlen(tmp_buff), cs);
2917
if (!tables->schema_table)
2919
table->field[7]->store((int64_t) file->stats.records, true);
2920
table->field[7]->set_notnull();
2922
table->field[8]->store((int64_t) file->stats.mean_rec_length, true);
2923
table->field[9]->store((int64_t) file->stats.data_file_length, true);
2924
if (file->stats.max_data_file_length)
2926
table->field[10]->store((int64_t) file->stats.max_data_file_length,
2929
table->field[11]->store((int64_t) file->stats.index_file_length, true);
2930
table->field[12]->store((int64_t) file->stats.delete_length, true);
2931
if (show_table->found_next_number_field)
2933
table->field[13]->store((int64_t) file->stats.auto_increment_value,
2935
table->field[13]->set_notnull();
2937
if (file->stats.create_time)
2939
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2940
(my_time_t) file->stats.create_time);
2941
table->field[14]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2942
table->field[14]->set_notnull();
2944
if (file->stats.update_time)
2946
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2947
(my_time_t) file->stats.update_time);
2948
table->field[15]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2949
table->field[15]->set_notnull();
2951
if (file->stats.check_time)
2953
thd->variables.time_zone->gmt_sec_to_TIME(&time,
2954
(my_time_t) file->stats.check_time);
2955
table->field[16]->store_time(&time, DRIZZLE_TIMESTAMP_DATETIME);
2956
table->field[16]->set_notnull();
2958
if (file->ha_table_flags() & (ulong) HA_HAS_CHECKSUM)
2960
table->field[18]->store((int64_t) file->checksum(), true);
2961
table->field[18]->set_notnull();
2965
return(schema_table_store_record(thd, table));
2970
2102
@brief Store field characteristics into appropriate I_S table columns
3190
2311
table->field[20]->store((const char*) pos,
3191
2312
strlen((const char*) pos), cs);
3193
if (schema_table_store_record(thd, table))
3201
int fill_schema_charsets(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
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;
3208
for (cs= all_charsets ; cs < all_charsets+255 ; cs++)
3210
const CHARSET_INFO * const tmp_cs= cs[0];
3211
if (tmp_cs && (tmp_cs->state & MY_CS_PRIMARY) &&
3212
(tmp_cs->state & MY_CS_AVAILABLE) &&
3213
!(tmp_cs->state & MY_CS_HIDDEN) &&
3214
!(wild && wild[0] &&
3215
wild_case_compare(scs, tmp_cs->csname,wild)))
3217
const char *comment;
3218
restore_record(table, s->default_values);
3219
table->field[0]->store(tmp_cs->csname, strlen(tmp_cs->csname), scs);
3220
table->field[1]->store(tmp_cs->name, strlen(tmp_cs->name), scs);
3221
comment= tmp_cs->comment ? tmp_cs->comment : "";
3222
table->field[2]->store(comment, strlen(comment), scs);
3223
table->field[3]->store((int64_t) tmp_cs->mbmaxlen, true);
3224
if (schema_table_store_record(thd, table))
3232
int fill_schema_collation(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
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;
3238
for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3241
const CHARSET_INFO *tmp_cs= cs[0];
3242
if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3243
(tmp_cs->state & MY_CS_HIDDEN) ||
3244
!(tmp_cs->state & MY_CS_PRIMARY))
3246
for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3248
const CHARSET_INFO *tmp_cl= cl[0];
3249
if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3250
!my_charset_same(tmp_cs, tmp_cl))
3252
if (!(wild && wild[0] &&
3253
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);
3258
table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3259
table->field[2]->store((int64_t) tmp_cl->number, true);
3260
tmp_buff= (tmp_cl->state & MY_CS_PRIMARY) ? "Yes" : "";
3261
table->field[3]->store(tmp_buff, strlen(tmp_buff), scs);
3262
tmp_buff= (tmp_cl->state & MY_CS_COMPILED)? "Yes" : "";
3263
table->field[4]->store(tmp_buff, strlen(tmp_buff), scs);
3264
table->field[5]->store((int64_t) tmp_cl->strxfrm_multiply, true);
3265
if (schema_table_store_record(thd, table))
3274
int fill_schema_coll_charset_app(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3277
Table *table= tables->table;
3278
const CHARSET_INFO * const scs= system_charset_info;
3279
for (cs= all_charsets ; cs < all_charsets+255 ; cs++ )
3282
const CHARSET_INFO *tmp_cs= cs[0];
3283
if (!tmp_cs || !(tmp_cs->state & MY_CS_AVAILABLE) ||
3284
!(tmp_cs->state & MY_CS_PRIMARY))
3286
for (cl= all_charsets; cl < all_charsets+255 ;cl ++)
3288
const CHARSET_INFO *tmp_cl= cl[0];
3289
if (!tmp_cl || !(tmp_cl->state & MY_CS_AVAILABLE) ||
3290
!my_charset_same(tmp_cs,tmp_cl))
3292
restore_record(table, s->default_values);
3293
table->field[0]->store(tmp_cl->name, strlen(tmp_cl->name), scs);
3294
table->field[1]->store(tmp_cl->csname , strlen(tmp_cl->csname), scs);
3295
if (schema_table_store_record(thd, table))
3303
static int get_schema_stat_record(THD *thd, TableList *tables,
3304
Table *table, bool res,
3305
LEX_STRING *db_name,
3306
LEX_STRING *table_name)
3308
const CHARSET_INFO * const cs= system_charset_info;
3311
if (thd->lex->sql_command != SQLCOM_SHOW_KEYS)
3314
I.e. we are in SELECT FROM INFORMATION_SCHEMA.STATISTICS
3315
rather than in SHOW KEYS
3317
if (thd->is_error())
3318
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3319
thd->main_da.sql_errno(), thd->main_da.message());
3327
Table *show_table= tables->table;
3328
KEY *key_info=show_table->s->key_info;
3329
if (show_table->file)
3330
show_table->file->info(HA_STATUS_VARIABLE |
3333
for (uint32_t i=0 ; i < show_table->s->keys ; i++,key_info++)
3335
KEY_PART_INFO *key_part= key_info->key_part;
3337
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
3339
restore_record(table, s->default_values);
3340
table->field[1]->store(db_name->str, db_name->length, cs);
3341
table->field[2]->store(table_name->str, table_name->length, cs);
3342
table->field[3]->store((int64_t) ((key_info->flags &
3343
HA_NOSAME) ? 0 : 1), true);
3344
table->field[4]->store(db_name->str, db_name->length, cs);
3345
table->field[5]->store(key_info->name, strlen(key_info->name), cs);
3346
table->field[6]->store((int64_t) (j+1), true);
3347
str=(key_part->field ? key_part->field->field_name :
3349
table->field[7]->store(str, strlen(str), cs);
3350
if (show_table->file)
3352
if (show_table->file->index_flags(i, j, 0) & HA_READ_ORDER)
3354
table->field[8]->store(((key_part->key_part_flag &
3357
table->field[8]->set_notnull();
3359
KEY *key=show_table->key_info+i;
3360
if (key->rec_per_key[j])
3362
ha_rows records=(show_table->file->stats.records /
3363
key->rec_per_key[j]);
3364
table->field[9]->store((int64_t) records, true);
3365
table->field[9]->set_notnull();
3367
str= show_table->file->index_type(i);
3368
table->field[13]->store(str, strlen(str), cs);
3370
if ((key_part->field &&
3372
show_table->s->field[key_part->fieldnr-1]->key_length()))
3374
table->field[10]->store((int64_t) key_part->length /
3375
key_part->field->charset()->mbmaxlen, true);
3376
table->field[10]->set_notnull();
3378
uint32_t flags= key_part->field ? key_part->field->flags : 0;
3379
const char *pos=(char*) ((flags & NOT_NULL_FLAG) ? "" : "YES");
3380
table->field[12]->store(pos, strlen(pos), cs);
3381
if (!show_table->s->keys_in_use.is_set(i))
3382
table->field[14]->store(STRING_WITH_LEN("disabled"), cs);
3384
table->field[14]->store("", 0, cs);
3385
table->field[14]->set_notnull();
3386
assert(test(key_info->flags & HA_USES_COMMENT) ==
3387
(key_info->comment.length > 0));
3388
if (key_info->flags & HA_USES_COMMENT)
3389
table->field[15]->store(key_info->comment.str,
3390
key_info->comment.length, cs);
3391
if (schema_table_store_record(thd, table))
3400
bool store_constraints(THD *thd, Table *table, LEX_STRING *db_name,
3401
LEX_STRING *table_name, const char *key_name,
3402
uint32_t key_len, const char *con_type, uint32_t con_len)
3404
const CHARSET_INFO * const cs= system_charset_info;
3405
restore_record(table, s->default_values);
3406
table->field[1]->store(db_name->str, db_name->length, cs);
3407
table->field[2]->store(key_name, key_len, cs);
3408
table->field[3]->store(db_name->str, db_name->length, cs);
3409
table->field[4]->store(table_name->str, table_name->length, cs);
3410
table->field[5]->store(con_type, con_len, cs);
3411
return schema_table_store_record(thd, table);
3415
static int get_schema_constraints_record(THD *thd, TableList *tables,
3416
Table *table, bool res,
3417
LEX_STRING *db_name,
3418
LEX_STRING *table_name)
3422
if (thd->is_error())
3423
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3424
thd->main_da.sql_errno(), thd->main_da.message());
3430
List<FOREIGN_KEY_INFO> f_key_list;
3431
Table *show_table= tables->table;
3432
KEY *key_info=show_table->key_info;
3433
uint32_t primary_key= show_table->s->primary_key;
3434
show_table->file->info(HA_STATUS_VARIABLE |
3437
for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
3439
if (i != primary_key && !(key_info->flags & HA_NOSAME))
3442
if (i == primary_key && !strcmp(key_info->name, primary_key_name))
3444
if (store_constraints(thd, table, db_name, table_name, key_info->name,
3445
strlen(key_info->name),
3446
STRING_WITH_LEN("PRIMARY KEY")))
3449
else if (key_info->flags & HA_NOSAME)
3451
if (store_constraints(thd, table, db_name, table_name, key_info->name,
3452
strlen(key_info->name),
3453
STRING_WITH_LEN("UNIQUE")))
3458
show_table->file->get_foreign_key_list(thd, &f_key_list);
3459
FOREIGN_KEY_INFO *f_key_info;
3460
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3461
while ((f_key_info=it++))
3463
if (store_constraints(thd, table, db_name, table_name,
3464
f_key_info->forein_id->str,
3465
strlen(f_key_info->forein_id->str),
3474
void store_key_column_usage(Table *table, LEX_STRING *db_name,
3475
LEX_STRING *table_name, const char *key_name,
3476
uint32_t key_len, const char *con_type, uint32_t con_len,
3479
const CHARSET_INFO * const cs= system_charset_info;
3480
table->field[1]->store(db_name->str, db_name->length, cs);
3481
table->field[2]->store(key_name, key_len, cs);
3482
table->field[4]->store(db_name->str, db_name->length, cs);
3483
table->field[5]->store(table_name->str, table_name->length, cs);
3484
table->field[6]->store(con_type, con_len, cs);
3485
table->field[7]->store((int64_t) idx, true);
3489
static int get_schema_key_column_usage_record(THD *thd,
3491
Table *table, bool res,
3492
LEX_STRING *db_name,
3493
LEX_STRING *table_name)
3497
if (thd->is_error())
3498
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3499
thd->main_da.sql_errno(), thd->main_da.message());
3505
List<FOREIGN_KEY_INFO> f_key_list;
3506
Table *show_table= tables->table;
3507
KEY *key_info=show_table->key_info;
3508
uint32_t primary_key= show_table->s->primary_key;
3509
show_table->file->info(HA_STATUS_VARIABLE |
3512
for (uint32_t i=0 ; i < show_table->s->keys ; i++, key_info++)
3514
if (i != primary_key && !(key_info->flags & HA_NOSAME))
3517
KEY_PART_INFO *key_part= key_info->key_part;
3518
for (uint32_t j=0 ; j < key_info->key_parts ; j++,key_part++)
3520
if (key_part->field)
3523
restore_record(table, s->default_values);
3524
store_key_column_usage(table, db_name, table_name,
3526
strlen(key_info->name),
3527
key_part->field->field_name,
3528
strlen(key_part->field->field_name),
3530
if (schema_table_store_record(thd, table))
3536
show_table->file->get_foreign_key_list(thd, &f_key_list);
3537
FOREIGN_KEY_INFO *f_key_info;
3538
List_iterator_fast<FOREIGN_KEY_INFO> fkey_it(f_key_list);
3539
while ((f_key_info= fkey_it++))
3543
List_iterator_fast<LEX_STRING> it(f_key_info->foreign_fields),
3544
it1(f_key_info->referenced_fields);
3546
while ((f_info= it++))
3550
restore_record(table, s->default_values);
3551
store_key_column_usage(table, db_name, table_name,
3552
f_key_info->forein_id->str,
3553
f_key_info->forein_id->length,
3554
f_info->str, f_info->length,
3556
table->field[8]->store((int64_t) f_idx, true);
3557
table->field[8]->set_notnull();
3558
table->field[9]->store(f_key_info->referenced_db->str,
3559
f_key_info->referenced_db->length,
3560
system_charset_info);
3561
table->field[9]->set_notnull();
3562
table->field[10]->store(f_key_info->referenced_table->str,
3563
f_key_info->referenced_table->length,
3564
system_charset_info);
3565
table->field[10]->set_notnull();
3566
table->field[11]->store(r_info->str, r_info->length,
3567
system_charset_info);
3568
table->field[11]->set_notnull();
3569
if (schema_table_store_record(thd, table))
3578
int fill_open_tables(THD *thd, TableList *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;
3584
if (!(open_list=list_open_tables(thd,thd->lex->select_lex.db, wild))
3585
&& thd->is_fatal_error)
3588
for (; open_list ; open_list=open_list->next)
3590
restore_record(table, s->default_values);
3591
table->field[0]->store(open_list->db, strlen(open_list->db), cs);
3592
table->field[1]->store(open_list->table, strlen(open_list->table), cs);
3593
table->field[2]->store((int64_t) open_list->in_use, true);
3594
table->field[3]->store((int64_t) open_list->locked, true);
3595
if (schema_table_store_record(thd, table))
3602
int fill_variables(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3606
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3607
enum enum_schema_tables schema_table_idx=
3608
get_schema_table_idx(tables->schema_table);
3609
enum enum_var_type option_type= OPT_SESSION;
3610
bool upper_case_names= (schema_table_idx != SCH_VARIABLES);
3611
bool sorted_vars= (schema_table_idx == SCH_VARIABLES);
3613
if (lex->option_type == OPT_GLOBAL ||
3614
schema_table_idx == SCH_GLOBAL_VARIABLES)
3615
option_type= OPT_GLOBAL;
3617
rw_rdlock(&LOCK_system_variables_hash);
3618
res= show_status_array(thd, wild, enumerate_sys_vars(thd, sorted_vars),
3619
option_type, NULL, "", tables->table, upper_case_names);
3620
rw_unlock(&LOCK_system_variables_hash);
3625
int fill_status(THD *thd, TableList *tables, COND *cond __attribute__((unused)))
3628
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
3630
STATUS_VAR *tmp1, tmp;
3631
enum enum_schema_tables schema_table_idx=
3632
get_schema_table_idx(tables->schema_table);
3633
enum enum_var_type option_type;
3634
bool upper_case_names= (schema_table_idx != SCH_STATUS);
3636
if (schema_table_idx == SCH_STATUS)
3638
option_type= lex->option_type;
3639
if (option_type == OPT_GLOBAL)
3642
tmp1= thd->initial_status_var;
3644
else if (schema_table_idx == SCH_GLOBAL_STATUS)
3646
option_type= OPT_GLOBAL;
3651
option_type= OPT_SESSION;
3652
tmp1= &thd->status_var;
3655
pthread_mutex_lock(&LOCK_status);
3656
if (option_type == OPT_GLOBAL)
3657
calc_sum_of_all_status(&tmp);
3658
res= show_status_array(thd, wild,
3659
(SHOW_VAR *)all_status_vars.buffer,
3660
option_type, tmp1, "", tables->table,
3662
pthread_mutex_unlock(&LOCK_status);
3668
Fill and store records into I_S.referential_constraints table
3671
get_referential_constraints_record()
3673
tables table list struct(processed table)
3675
res 1 means the error during opening of the processed table
3676
0 means processed table is opened without error
3678
file_name table name
3686
get_referential_constraints_record(THD *thd, TableList *tables,
3687
Table *table, bool res,
3688
LEX_STRING *db_name, LEX_STRING *table_name)
3690
const CHARSET_INFO * const cs= system_charset_info;
3694
if (thd->is_error())
3695
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
3696
thd->main_da.sql_errno(), thd->main_da.message());
3702
List<FOREIGN_KEY_INFO> f_key_list;
3703
Table *show_table= tables->table;
3704
show_table->file->info(HA_STATUS_VARIABLE |
3708
show_table->file->get_foreign_key_list(thd, &f_key_list);
3709
FOREIGN_KEY_INFO *f_key_info;
3710
List_iterator_fast<FOREIGN_KEY_INFO> it(f_key_list);
3711
while ((f_key_info= it++))
3713
restore_record(table, s->default_values);
3714
table->field[1]->store(db_name->str, db_name->length, cs);
3715
table->field[9]->store(table_name->str, table_name->length, cs);
3716
table->field[2]->store(f_key_info->forein_id->str,
3717
f_key_info->forein_id->length, cs);
3718
table->field[4]->store(f_key_info->referenced_db->str,
3719
f_key_info->referenced_db->length, cs);
3720
table->field[10]->store(f_key_info->referenced_table->str,
3721
f_key_info->referenced_table->length, cs);
3722
if (f_key_info->referenced_key_name)
3724
table->field[5]->store(f_key_info->referenced_key_name->str,
3725
f_key_info->referenced_key_name->length, cs);
3726
table->field[5]->set_notnull();
3729
table->field[5]->set_null();
3730
table->field[6]->store(STRING_WITH_LEN("NONE"), cs);
3731
table->field[7]->store(f_key_info->update_method->str,
3732
f_key_info->update_method->length, cs);
3733
table->field[8]->store(f_key_info->delete_method->str,
3734
f_key_info->delete_method->length, cs);
3735
if (schema_table_store_record(thd, table))
3743
struct schema_table_ref
2314
if (schema_table_store_record(session, table))
2321
class FindSchemaTableByName : public unary_function<InfoSchemaTable *, bool>
3745
2323
const char *table_name;
3746
ST_SCHEMA_TABLE *schema_table;
2325
FindSchemaTableByName(const char *table_name_arg)
2326
: table_name(table_name_arg) {}
2327
result_type operator() (argument_type schema_table)
2329
return ! my_strcasecmp(system_charset_info,
2330
schema_table->getTableName().c_str(),
4290
2663
table_list->schema_table_state= executed_place;
4293
thd->no_warnings_for_error= 0;
2666
session->no_warnings_for_error= 0;
4294
2667
return(result);
4297
ST_FIELD_INFO schema_fields_info[]=
4299
{"CATALOG_NAME", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4300
{"SCHEMA_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Database",
4302
{"DEFAULT_CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4304
{"DEFAULT_COLLATION_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4305
{"SQL_PATH", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4306
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4310
ST_FIELD_INFO tables_fields_info[]=
4312
{"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4313
{"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4314
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name",
4316
{"TABLE_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4317
{"ENGINE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, "Engine", OPEN_FRM_ONLY},
4318
{"VERSION", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4319
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Version", OPEN_FRM_ONLY},
4320
{"ROW_FORMAT", 10, DRIZZLE_TYPE_VARCHAR, 0, 1, "Row_format", OPEN_FULL_TABLE},
4321
{"TABLE_ROWS", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4322
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Rows", OPEN_FULL_TABLE},
4323
{"AVG_ROW_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4324
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Avg_row_length", OPEN_FULL_TABLE},
4325
{"DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4326
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Data_length", OPEN_FULL_TABLE},
4327
{"MAX_DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4328
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Max_data_length", OPEN_FULL_TABLE},
4329
{"INDEX_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4330
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Index_length", OPEN_FULL_TABLE},
4331
{"DATA_FREE", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4332
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Data_free", OPEN_FULL_TABLE},
4333
{"AUTO_INCREMENT", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG, 0,
4334
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Auto_increment", OPEN_FULL_TABLE},
4335
{"CREATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Create_time", OPEN_FULL_TABLE},
4336
{"UPDATE_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Update_time", OPEN_FULL_TABLE},
4337
{"CHECK_TIME", 0, DRIZZLE_TYPE_DATETIME, 0, 1, "Check_time", OPEN_FULL_TABLE},
4338
{"TABLE_COLLATION", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, "Collation", OPEN_FRM_ONLY},
4339
{"CHECKSUM", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4340
(MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Checksum", OPEN_FULL_TABLE},
4341
{"CREATE_OPTIONS", 255, DRIZZLE_TYPE_VARCHAR, 0, 1, "Create_options",
4343
{"TABLE_COMMENT", TABLE_COMMENT_MAXLEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Comment", OPEN_FRM_ONLY},
4344
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4348
ST_FIELD_INFO columns_fields_info[]=
4350
{"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FRM_ONLY},
4351
{"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4352
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4353
{"COLUMN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Field",
4355
{"ORDINAL_POSITION", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0,
4356
MY_I_S_UNSIGNED, 0, OPEN_FRM_ONLY},
4357
{"COLUMN_DEFAULT", MAX_FIELD_VARCHARLENGTH, DRIZZLE_TYPE_VARCHAR, 0,
4358
1, "Default", OPEN_FRM_ONLY},
4359
{"IS_NULLABLE", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Null", OPEN_FRM_ONLY},
4360
{"DATA_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4361
{"CHARACTER_MAXIMUM_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG,
4362
0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
4363
{"CHARACTER_OCTET_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG,
4364
0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
4365
{"NUMERIC_PRECISION", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG,
4366
0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
4367
{"NUMERIC_SCALE", MY_INT64_NUM_DECIMAL_DIGITS , DRIZZLE_TYPE_LONGLONG,
4368
0, (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), 0, OPEN_FRM_ONLY},
4369
{"CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FRM_ONLY},
4370
{"COLLATION_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, "Collation", OPEN_FRM_ONLY},
4371
{"COLUMN_TYPE", 65535, DRIZZLE_TYPE_VARCHAR, 0, 0, "Type", OPEN_FRM_ONLY},
4372
{"COLUMN_KEY", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Key", OPEN_FRM_ONLY},
4373
{"EXTRA", 27, DRIZZLE_TYPE_VARCHAR, 0, 0, "Extra", OPEN_FRM_ONLY},
4374
{"PRIVILEGES", 80, DRIZZLE_TYPE_VARCHAR, 0, 0, "Privileges", OPEN_FRM_ONLY},
4375
{"COLUMN_COMMENT", COLUMN_COMMENT_MAXLEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Comment", OPEN_FRM_ONLY},
4376
{"STORAGE", 8, DRIZZLE_TYPE_VARCHAR, 0, 0, "Storage", OPEN_FRM_ONLY},
4377
{"FORMAT", 8, DRIZZLE_TYPE_VARCHAR, 0, 0, "Format", OPEN_FRM_ONLY},
4378
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4382
ST_FIELD_INFO charsets_fields_info[]=
4384
{"CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Charset",
4386
{"DEFAULT_COLLATE_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Default collation",
4388
{"DESCRIPTION", 60, DRIZZLE_TYPE_VARCHAR, 0, 0, "Description",
4390
{"MAXLEN", 3, DRIZZLE_TYPE_LONGLONG, 0, 0, "Maxlen", SKIP_OPEN_TABLE},
4391
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4395
ST_FIELD_INFO collation_fields_info[]=
4397
{"COLLATION_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Collation", SKIP_OPEN_TABLE},
4398
{"CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Charset",
4400
{"ID", MY_INT32_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0, 0, "Id",
4402
{"IS_DEFAULT", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Default", SKIP_OPEN_TABLE},
4403
{"IS_COMPILED", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Compiled", SKIP_OPEN_TABLE},
4404
{"SORTLEN", 3, DRIZZLE_TYPE_LONGLONG, 0, 0, "Sortlen", SKIP_OPEN_TABLE},
4405
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4410
ST_FIELD_INFO coll_charset_app_fields_info[]=
4412
{"COLLATION_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4413
{"CHARACTER_SET_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4414
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4418
ST_FIELD_INFO stat_fields_info[]=
4420
{"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FRM_ONLY},
4421
{"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4422
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Table", OPEN_FRM_ONLY},
4423
{"NON_UNIQUE", 1, DRIZZLE_TYPE_LONGLONG, 0, 0, "Non_unique", OPEN_FRM_ONLY},
4424
{"INDEX_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FRM_ONLY},
4425
{"INDEX_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Key_name",
4427
{"SEQ_IN_INDEX", 2, DRIZZLE_TYPE_LONGLONG, 0, 0, "Seq_in_index", OPEN_FRM_ONLY},
4428
{"COLUMN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Column_name",
4430
{"COLLATION", 1, DRIZZLE_TYPE_VARCHAR, 0, 1, "Collation", OPEN_FRM_ONLY},
4431
{"CARDINALITY", MY_INT64_NUM_DECIMAL_DIGITS, DRIZZLE_TYPE_LONGLONG, 0, 1,
4432
"Cardinality", OPEN_FULL_TABLE},
4433
{"SUB_PART", 3, DRIZZLE_TYPE_LONGLONG, 0, 1, "Sub_part", OPEN_FRM_ONLY},
4434
{"PACKED", 10, DRIZZLE_TYPE_VARCHAR, 0, 1, "Packed", OPEN_FRM_ONLY},
4435
{"NULLABLE", 3, DRIZZLE_TYPE_VARCHAR, 0, 0, "Null", OPEN_FRM_ONLY},
4436
{"INDEX_TYPE", 16, DRIZZLE_TYPE_VARCHAR, 0, 0, "Index_type", OPEN_FULL_TABLE},
4437
{"COMMENT", 16, DRIZZLE_TYPE_VARCHAR, 0, 1, "Comment", OPEN_FRM_ONLY},
4438
{"INDEX_COMMENT", INDEX_COMMENT_MAXLEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Index_Comment", OPEN_FRM_ONLY},
4439
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4443
ST_FIELD_INFO table_constraints_fields_info[]=
4445
{"CONSTRAINT_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FULL_TABLE},
4446
{"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4448
{"CONSTRAINT_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4450
{"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4451
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4452
{"CONSTRAINT_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4454
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4458
ST_FIELD_INFO key_column_usage_fields_info[]=
4460
{"CONSTRAINT_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FULL_TABLE},
4461
{"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4463
{"CONSTRAINT_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4465
{"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FULL_TABLE},
4466
{"TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4467
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4468
{"COLUMN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4469
{"ORDINAL_POSITION", 10 ,DRIZZLE_TYPE_LONGLONG, 0, 0, 0, OPEN_FULL_TABLE},
4470
{"POSITION_IN_UNIQUE_CONSTRAINT", 10 ,DRIZZLE_TYPE_LONGLONG, 0, 1, 0,
4472
{"REFERENCED_TABLE_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0,
4474
{"REFERENCED_TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0,
4476
{"REFERENCED_COLUMN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0,
4478
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4482
ST_FIELD_INFO table_names_fields_info[]=
4484
{"TABLE_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4485
{"TABLE_SCHEMA",NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4486
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Tables_in_",
4488
{"TABLE_TYPE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Table_type",
4490
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4494
ST_FIELD_INFO open_tables_fields_info[]=
4496
{"Database", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Database",
4498
{"Table",NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Table", SKIP_OPEN_TABLE},
4499
{"In_use", 1, DRIZZLE_TYPE_LONGLONG, 0, 0, "In_use", SKIP_OPEN_TABLE},
4500
{"Name_locked", 4, DRIZZLE_TYPE_LONGLONG, 0, 0, "Name_locked", SKIP_OPEN_TABLE},
4501
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4505
ST_FIELD_INFO variables_fields_info[]=
4507
{"VARIABLE_NAME", 64, DRIZZLE_TYPE_VARCHAR, 0, 0, "Variable_name",
4509
{"VARIABLE_VALUE", 16300, DRIZZLE_TYPE_VARCHAR, 0, 1, "Value", SKIP_OPEN_TABLE},
4510
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4514
ST_FIELD_INFO processlist_fields_info[]=
4516
{"ID", 4, DRIZZLE_TYPE_LONGLONG, 0, 0, "Id", SKIP_OPEN_TABLE},
4517
{"USER", 16, DRIZZLE_TYPE_VARCHAR, 0, 0, "User", SKIP_OPEN_TABLE},
4518
{"HOST", LIST_PROCESS_HOST_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Host",
4520
{"DB", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, "Db", SKIP_OPEN_TABLE},
4521
{"COMMAND", 16, DRIZZLE_TYPE_VARCHAR, 0, 0, "Command", SKIP_OPEN_TABLE},
4522
{"TIME", 7, DRIZZLE_TYPE_LONGLONG, 0, 0, "Time", SKIP_OPEN_TABLE},
4523
{"STATE", 64, DRIZZLE_TYPE_VARCHAR, 0, 1, "State", SKIP_OPEN_TABLE},
4524
{"INFO", PROCESS_LIST_INFO_WIDTH, DRIZZLE_TYPE_VARCHAR, 0, 1, "Info",
4526
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4530
ST_FIELD_INFO plugin_fields_info[]=
4532
{"PLUGIN_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, "Name",
4534
{"PLUGIN_VERSION", 20, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE},
4535
{"PLUGIN_STATUS", 10, DRIZZLE_TYPE_VARCHAR, 0, 0, "Status", SKIP_OPEN_TABLE},
4536
{"PLUGIN_TYPE", 80, DRIZZLE_TYPE_VARCHAR, 0, 0, "Type", SKIP_OPEN_TABLE},
4537
{"PLUGIN_LIBRARY", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, "Library",
4539
{"PLUGIN_AUTHOR", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4540
{"PLUGIN_DESCRIPTION", 65535, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, SKIP_OPEN_TABLE},
4541
{"PLUGIN_LICENSE", 80, DRIZZLE_TYPE_VARCHAR, 0, 1, "License", SKIP_OPEN_TABLE},
4542
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4545
ST_FIELD_INFO referential_constraints_fields_info[]=
4547
{"CONSTRAINT_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0, OPEN_FULL_TABLE},
4548
{"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4550
{"CONSTRAINT_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4552
{"UNIQUE_CONSTRAINT_CATALOG", FN_REFLEN, DRIZZLE_TYPE_VARCHAR, 0, 1, 0,
4554
{"UNIQUE_CONSTRAINT_SCHEMA", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4556
{"UNIQUE_CONSTRAINT_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0,
4557
MY_I_S_MAYBE_NULL, 0, OPEN_FULL_TABLE},
4558
{"MATCH_OPTION", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4559
{"UPDATE_RULE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4560
{"DELETE_RULE", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4561
{"TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, OPEN_FULL_TABLE},
4562
{"REFERENCED_TABLE_NAME", NAME_CHAR_LEN, DRIZZLE_TYPE_VARCHAR, 0, 0, 0,
4564
{0, 0, DRIZZLE_TYPE_VARCHAR, 0, 0, 0, SKIP_OPEN_TABLE}
4569
Description of ST_FIELD_INFO in table.h
4571
Make sure that the order of schema_tables and enum_schema_tables are the same.
4575
ST_SCHEMA_TABLE schema_tables[]=
4577
{"CHARACTER_SETS", charsets_fields_info, create_schema_table,
4578
fill_schema_charsets, make_character_sets_old_format, 0, -1, -1, 0, 0},
4579
{"COLLATIONS", collation_fields_info, create_schema_table,
4580
fill_schema_collation, make_old_format, 0, -1, -1, 0, 0},
4581
{"COLLATION_CHARACTER_SET_APPLICABILITY", coll_charset_app_fields_info,
4582
create_schema_table, fill_schema_coll_charset_app, 0, 0, -1, -1, 0, 0},
4583
{"COLUMNS", columns_fields_info, create_schema_table,
4584
get_all_tables, make_columns_old_format, get_schema_column_record, 1, 2, 0,
4585
OPTIMIZE_I_S_TABLE},
4586
{"GLOBAL_STATUS", variables_fields_info, create_schema_table,
4587
fill_status, make_old_format, 0, -1, -1, 0, 0},
4588
{"GLOBAL_VARIABLES", variables_fields_info, create_schema_table,
4589
fill_variables, make_old_format, 0, -1, -1, 0, 0},
4590
{"KEY_COLUMN_USAGE", key_column_usage_fields_info, create_schema_table,
4591
get_all_tables, 0, get_schema_key_column_usage_record, 4, 5, 0,
4593
{"OPEN_TABLES", open_tables_fields_info, create_schema_table,
4594
fill_open_tables, make_old_format, 0, -1, -1, 1, 0},
4595
{"PLUGINS", plugin_fields_info, create_schema_table,
4596
fill_plugins, make_old_format, 0, -1, -1, 0, 0},
4597
{"PROCESSLIST", processlist_fields_info, create_schema_table,
4598
fill_schema_processlist, make_old_format, 0, -1, -1, 0, 0},
4599
{"REFERENTIAL_CONSTRAINTS", referential_constraints_fields_info,
4600
create_schema_table, get_all_tables, 0, get_referential_constraints_record,
4601
1, 9, 0, OPEN_TABLE_ONLY},
4602
{"SCHEMATA", schema_fields_info, create_schema_table,
4603
fill_schema_schemata, make_schemata_old_format, 0, 1, -1, 0, 0},
4604
{"SESSION_STATUS", variables_fields_info, create_schema_table,
4605
fill_status, make_old_format, 0, -1, -1, 0, 0},
4606
{"SESSION_VARIABLES", variables_fields_info, create_schema_table,
4607
fill_variables, make_old_format, 0, -1, -1, 0, 0},
4608
{"STATISTICS", stat_fields_info, create_schema_table,
4609
get_all_tables, make_old_format, get_schema_stat_record, 1, 2, 0,
4610
OPEN_TABLE_ONLY|OPTIMIZE_I_S_TABLE},
4611
{"STATUS", variables_fields_info, create_schema_table, fill_status,
4612
make_old_format, 0, -1, -1, 1, 0},
4613
{"TABLES", tables_fields_info, create_schema_table,
4614
get_all_tables, make_old_format, get_schema_tables_record, 1, 2, 0,
4615
OPTIMIZE_I_S_TABLE},
4616
{"TABLE_CONSTRAINTS", table_constraints_fields_info, create_schema_table,
4617
get_all_tables, 0, get_schema_constraints_record, 3, 4, 0, OPEN_TABLE_ONLY},
4618
{"TABLE_NAMES", table_names_fields_info, create_schema_table,
4619
get_all_tables, make_table_names_old_format, 0, 1, 2, 1, 0},
4620
{"VARIABLES", variables_fields_info, create_schema_table, fill_variables,
4621
make_old_format, 0, -1, -1, 1, 0},
4622
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
4626
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
4627
template class List_iterator_fast<char>;
4628
template class List<char>;
4631
int initialize_schema_table(st_plugin_int *plugin)
4633
ST_SCHEMA_TABLE *schema_table;
4635
if (!(schema_table= (ST_SCHEMA_TABLE *)my_malloc(sizeof(ST_SCHEMA_TABLE),
4636
MYF(MY_WME | MY_ZEROFILL))))
4638
/* Historical Requirement */
4639
plugin->data= schema_table; // shortcut for the future
4640
if (plugin->plugin->init)
4642
schema_table->create_table= create_schema_table;
4643
schema_table->old_format= make_old_format;
4644
schema_table->idx_field1= -1,
4645
schema_table->idx_field2= -1;
4647
/* Make the name available to the init() function. */
4648
schema_table->table_name= plugin->name.str;
4650
if (plugin->plugin->init(schema_table))
4652
sql_print_error(_("Plugin '%s' init function returned error."),
4657
/* Make sure the plugin name is not set inside the init() function. */
4658
schema_table->table_name= plugin->name.str;
4667
int finalize_schema_table(st_plugin_int *plugin)
4669
ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data;
4671
if (schema_table && plugin->plugin->deinit)