1017
static int make_table_list(Session *session, Select_Lex *sel,
1018
LEX_STRING *db_name, LEX_STRING *table_name)
1020
Table_ident *table_ident;
1021
table_ident= new Table_ident(*db_name, *table_name);
1023
if (! sel->add_table_to_list(session, table_ident, 0, 0, TL_READ))
1030
@brief Get lookup value from the part of 'WHERE' condition
1032
@details This function gets lookup value from
1033
the part of 'WHERE' condition if it's possible and
1034
fill appropriate lookup_field_vals struct field
1037
@param[in] session thread Cursor
1038
@param[in] item_func part of WHERE condition
1039
@param[in] table I_S table
1040
@param[in, out] lookup_field_vals Struct which holds lookup values
1044
1 error, there can be no matching records for the condition
1047
static bool get_lookup_value(Session *session, Item_func *item_func,
1049
LOOKUP_FIELD_VALUES *lookup_field_vals,
1050
plugin::InfoSchemaTable *schema_table)
1052
const char *field_name1= schema_table->getFirstColumnIndex() >= 0 ?
1053
schema_table->getColumnName(schema_table->getFirstColumnIndex()).c_str() : "";
1054
const char *field_name2= schema_table->getSecondColumnIndex() >= 0 ?
1055
schema_table->getColumnName(schema_table->getSecondColumnIndex()).c_str() : "";
1057
if (item_func->functype() == Item_func::EQ_FUNC ||
1058
item_func->functype() == Item_func::EQUAL_FUNC)
1060
int idx_field, idx_val;
1061
char tmp[MAX_FIELD_WIDTH];
1062
String *tmp_str, str_buff(tmp, sizeof(tmp), system_charset_info);
1063
Item_field *item_field;
1064
const CHARSET_INFO * const cs= system_charset_info;
1066
if (item_func->arguments()[0]->type() == Item::FIELD_ITEM &&
1067
item_func->arguments()[1]->const_item())
1072
else if (item_func->arguments()[1]->type() == Item::FIELD_ITEM &&
1073
item_func->arguments()[0]->const_item())
1081
item_field= (Item_field*) item_func->arguments()[idx_field];
1082
if (table->table != item_field->field->table)
1084
tmp_str= item_func->arguments()[idx_val]->val_str(&str_buff);
1086
/* impossible value */
1090
/* Lookup value is database name */
1091
if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
1092
(unsigned char *) item_field->field_name,
1093
strlen(item_field->field_name), 0))
1095
session->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1096
tmp_str->length(), false);
1098
/* Lookup value is table name */
1099
else if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name2,
1100
strlen(field_name2),
1101
(unsigned char *) item_field->field_name,
1102
strlen(item_field->field_name), 0))
1104
session->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1105
tmp_str->length(), false);
1113
@brief Calculates lookup values from 'WHERE' condition
1115
@details This function calculates lookup value(database name, table name)
1116
from 'WHERE' condition if it's possible and
1117
fill lookup_field_vals struct fields with these values.
1119
@param[in] session thread Cursor
1120
@param[in] cond WHERE condition
1121
@param[in] table I_S table
1122
@param[in, out] lookup_field_vals Struct which holds lookup values
1126
1 error, there can be no matching records for the condition
1129
bool calc_lookup_values_from_cond(Session *session, COND *cond, TableList *table,
1130
LOOKUP_FIELD_VALUES *lookup_field_vals,
1131
plugin::InfoSchemaTable *schema_table)
1136
if (cond->type() == Item::COND_ITEM)
1138
if (((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC)
1140
List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
1142
while ((item= li++))
1144
if (item->type() == Item::FUNC_ITEM)
1146
if (get_lookup_value(session, (Item_func*)item, table, lookup_field_vals, schema_table))
1151
if (calc_lookup_values_from_cond(session, item, table, lookup_field_vals, schema_table))
1158
else if (cond->type() == Item::FUNC_ITEM &&
1159
get_lookup_value(session, (Item_func*) cond, table, lookup_field_vals, schema_table))
1165
static bool uses_only_table_name_fields(Item *item, Table *table, plugin::InfoSchemaTable *schema_table)
1167
if (item->type() == Item::FUNC_ITEM)
1169
Item_func *item_func= (Item_func*)item;
1170
for (uint32_t i=0; i<item_func->argument_count(); i++)
1172
if (! uses_only_table_name_fields(item_func->arguments()[i], table, schema_table))
1176
else if (item->type() == Item::FIELD_ITEM)
1178
Item_field *item_field= (Item_field*)item;
1179
const CHARSET_INFO * const cs= system_charset_info;
1180
const char *field_name1= schema_table->getFirstColumnIndex() >= 0 ?
1181
schema_table->getColumnName(schema_table->getFirstColumnIndex()).c_str() : "";
1182
const char *field_name2= schema_table->getSecondColumnIndex() >= 0 ?
1183
schema_table->getColumnName(schema_table->getSecondColumnIndex()).c_str() : "";
1184
if (table != item_field->field->table ||
1185
(cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
1186
(unsigned char *) item_field->field_name,
1187
strlen(item_field->field_name), 0) &&
1188
cs->coll->strnncollsp(cs, (unsigned char *) field_name2, strlen(field_name2),
1189
(unsigned char *) item_field->field_name,
1190
strlen(item_field->field_name), 0)))
1193
else if (item->type() == Item::REF_ITEM)
1194
return uses_only_table_name_fields(item->real_item(), table, schema_table);
1196
if (item->type() == Item::SUBSELECT_ITEM && !item->const_item())
1203
static COND * make_cond_for_info_schema(COND *cond, Table *table, plugin::InfoSchemaTable *schema_table)
1207
if (cond->type() == Item::COND_ITEM)
1209
if (((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC)
1211
/* Create new top level AND item */
1212
Item_cond_and *new_cond=new Item_cond_and;
1215
List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
1219
Item *fix= make_cond_for_info_schema(item, table, schema_table);
1221
new_cond->argument_list()->push_back(fix);
1223
switch (new_cond->argument_list()->elements) {
1227
return new_cond->argument_list()->head();
1229
new_cond->quick_fix_field();
1235
Item_cond_or *new_cond=new Item_cond_or;
1238
List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
1242
Item *fix=make_cond_for_info_schema(item, table, schema_table);
1245
new_cond->argument_list()->push_back(fix);
1247
new_cond->quick_fix_field();
1248
new_cond->top_level_item();
1253
if (! uses_only_table_name_fields(cond, table, schema_table))
1260
@brief Calculate lookup values(database name, table name)
1262
@details This function calculates lookup values(database name, table name)
1263
from 'WHERE' condition or wild values (for 'SHOW' commands only)
1264
from LEX struct and fill lookup_field_vals struct field
1267
@param[in] session thread Cursor
1268
@param[in] cond WHERE condition
1269
@param[in] tables I_S table
1270
@param[in, out] lookup_field_values Struct which holds lookup values
1274
1 error, there can be no matching records for the condition
1277
bool get_lookup_field_values(Session *session, COND *cond, TableList *tables,
1278
LOOKUP_FIELD_VALUES *lookup_field_values,
1279
plugin::InfoSchemaTable *schema_table)
1281
LEX *lex= session->lex;
1282
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1283
memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1284
switch (lex->sql_command) {
1285
case SQLCOM_SHOW_DATABASES:
1288
lookup_field_values->db_value.str= (char*) wild;
1289
lookup_field_values->db_value.length= strlen(wild);
1290
lookup_field_values->wild_db_value= 1;
1293
case SQLCOM_SHOW_TABLES:
1294
case SQLCOM_SHOW_TABLE_STATUS:
1295
lookup_field_values->db_value.str= lex->select_lex.db;
1296
lookup_field_values->db_value.length=strlen(lex->select_lex.db);
1299
lookup_field_values->table_value.str= (char*)wild;
1300
lookup_field_values->table_value.length= strlen(wild);
1301
lookup_field_values->wild_table_value= 1;
1306
The "default" is for queries over I_S.
1307
All previous cases handle SHOW commands.
1309
return calc_lookup_values_from_cond(session, cond, tables, lookup_field_values, schema_table);
1315
* Function used for sorting with std::sort within make_db_list.
1317
* @returns true if a < b, false otherwise
1320
static bool lex_string_sort(const LEX_STRING *a, const LEX_STRING *b)
1322
return (strcmp(a->str, b->str) < 0);
1328
* Create db names list. Information schema name always is first in list
1330
* @param[in] session Thread Cursor
1331
* @param[out] files List of db names
1332
* @param[in] wild Wild string
1333
* @param[in] idx_field_vals idx_field_vals->db_name contains db name or
1335
* @param[out] with_i_schema Returns 1 if we added 'IS' name to list
1336
* otherwise returns 0
1341
int make_db_list(Session *session, vector<LEX_STRING*> &files,
1342
LOOKUP_FIELD_VALUES *lookup_field_vals,
1343
bool *with_i_schema)
1345
LEX_STRING *i_s_name_copy= 0;
1346
i_s_name_copy= session->make_lex_string(i_s_name_copy,
1347
INFORMATION_SCHEMA_NAME.c_str(),
1348
INFORMATION_SCHEMA_NAME.length(), true);
1350
if (lookup_field_vals->wild_db_value)
1353
This part of code is only for SHOW DATABASES command.
1354
idx_field_vals->db_value can be 0 when we don't use
1355
LIKE clause (see also get_index_field_values() function)
1357
if (!lookup_field_vals->db_value.str ||
1358
!wild_case_compare(system_charset_info,
1359
INFORMATION_SCHEMA_NAME.c_str(),
1360
lookup_field_vals->db_value.str))
1363
files.push_back(i_s_name_copy);
1366
if (find_schemas(session, files, drizzle_data_home,
1367
lookup_field_vals->db_value.str) == true)
1372
sort(files.begin()+1, files.end(), lex_string_sort);
1378
If we have db lookup vaule we just add it to list and
1379
exit from the function
1381
if (lookup_field_vals->db_value.str)
1383
if (!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.c_str(),
1384
lookup_field_vals->db_value.str))
1387
files.push_back(i_s_name_copy);
1391
files.push_back(&lookup_field_vals->db_value);
1396
Create list of existing databases. It is used in case
1397
of select from information schema table
1399
files.push_back(i_s_name_copy);
1403
if (find_schemas(session, files, drizzle_data_home, NULL) == true)
1408
sort(files.begin()+1, files.end(), lex_string_sort);
1414
@brief Create table names list
1416
@details The function creates the list of table names in
1419
@param[in] session thread Cursor
1420
@param[in] table_names List of table names in database
1421
@param[in] lex pointer to LEX struct
1422
@param[in] lookup_field_vals pointer to LOOKUP_FIELD_VALUE struct
1423
@param[in] with_i_schema true means that we add I_S tables to list
1424
@param[in] db_name database name
1426
@return Operation status
1428
@retval 1 fatal error
1429
@retval 2 Not fatal error; Safe to ignore this cursor list
1433
make_table_name_list(Session *session, vector<LEX_STRING*> &table_names,
1434
LOOKUP_FIELD_VALUES *lookup_field_vals,
1435
bool with_i_schema, LEX_STRING *db_name)
1437
char path[FN_REFLEN];
1438
set<string> set_of_names;
1440
build_table_filename(path, sizeof(path), db_name->str, "", false);
1442
if (!lookup_field_vals->wild_table_value &&
1443
lookup_field_vals->table_value.str)
1447
if (plugin::InfoSchemaTable::getTable(lookup_field_vals->table_value.str))
1449
table_names.push_back(&lookup_field_vals->table_value);
1454
table_names.push_back(&lookup_field_vals->table_value);
1459
string db(db_name->str);
1460
plugin::StorageEngine::getTableNames(db, set_of_names);
1463
New I_S engine will make this go away, so ignore lack of foreach() usage.
1465
Notice how bad this design is... sure we created a set... but then we
1466
are just pushing to another set. --
1467
Also... callback design won't work, so we need to rewrite this to
1468
feed (which means new I_S). For the moment we will not optimize this.
1471
for (set<string>::iterator it= set_of_names.begin(); it != set_of_names.end(); it++)
1473
LEX_STRING *file_name= NULL;
1475
file_name= session->make_lex_string(file_name, (*it).c_str(),
1476
(*it).length(), true);
1477
const char* wild= lookup_field_vals->table_value.str;
1478
if (wild && internal::wild_compare((*it).c_str(), wild, 0))
1481
table_names.push_back(file_name);
1489
@brief Fill I_S table for SHOW COLUMNS|INDEX commands
1491
@param[in] session thread Cursor
1492
@param[in] tables TableList for I_S table
1493
@param[in] schema_table pointer to I_S structure
1494
@param[in] open_tables_state_backup pointer to Open_tables_state object
1495
which is used to save|restore original
1496
status of variables related to
1499
@return Operation status
1505
fill_schema_show_cols_or_idxs(Session *session, TableList *tables,
1506
plugin::InfoSchemaTable *schema_table,
1507
Open_tables_state *open_tables_state_backup)
1509
LEX *lex= session->lex;
1511
LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
1512
enum_sql_command save_sql_command= lex->sql_command;
1513
TableList *show_table_list= (TableList*) tables->schema_select_lex->
1515
Table *table= tables->table;
1518
lex->all_selects_list= tables->schema_select_lex;
1520
Restore session->temporary_tables to be able to process
1521
temporary tables(only for 'show index' & 'show columns').
1522
This should be changed when processing of temporary tables for
1523
I_S tables will be done.
1525
session->temporary_tables= open_tables_state_backup->temporary_tables;
1527
Let us set fake sql_command so views won't try to merge
1528
themselves into main statement. If we don't do this,
1529
SELECT * from information_schema.xxxx will cause problems.
1530
SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
1532
lex->sql_command= SQLCOM_SHOW_FIELDS;
1533
res= session->openTables(show_table_list, DRIZZLE_LOCK_IGNORE_FLUSH);
1534
lex->sql_command= save_sql_command;
1536
get_all_tables() returns 1 on failure and 0 on success thus
1537
return only these and not the result code of ::process_table()
1539
We should use show_table_list->alias instead of
1540
show_table_list->table_name because table_name
1541
could be changed during opening of I_S tables. It's safe
1542
to use alias because alias contains original table name
1543
in this case(this part of code is used only for
1544
'show columns' & 'show statistics' commands).
1546
table_name= session->make_lex_string(&tmp_lex_string1, show_table_list->alias,
1547
strlen(show_table_list->alias), false);
1548
db_name= session->make_lex_string(&tmp_lex_string, show_table_list->db,
1549
show_table_list->db_length, false);
1552
table->setWriteSet();
1553
error= test(schema_table->processTable(session, show_table_list,
1554
table, res, db_name,
1556
session->temporary_tables= 0;
1557
session->close_tables_for_reopen(&show_table_list);
1564
@brief Fill I_S table for SHOW Table NAMES commands
1566
@param[in] session thread Cursor
1567
@param[in] table Table struct for I_S table
1568
@param[in] db_name database name
1569
@param[in] table_name table name
1570
@param[in] with_i_schema I_S table if true
1572
@return Operation status
1577
static int fill_schema_table_names(Session *session, Table *table,
1578
LEX_STRING *db_name, LEX_STRING *table_name,
1580
plugin::InfoSchemaTable *schema_table)
1584
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"),
1585
system_charset_info);
1589
char path[FN_REFLEN];
1590
(void) build_table_filename(path, sizeof(path), db_name->str,
1591
table_name->str, false);
1593
table->field[3]->store(STRING_WITH_LEN("BASE Table"),
1594
system_charset_info);
1596
if (session->is_error() && session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
1598
session->clear_error();
1602
schema_table->addRow(table->record[0], table->s->reclength);
1606
int plugin::InfoSchemaMethods::fillTable(Session *session,
1608
plugin::InfoSchemaTable *schema_table)
1610
LEX *lex= session->lex;
1611
Select_Lex *old_all_select_lex= lex->all_selects_list;
1612
enum_sql_command save_sql_command= lex->sql_command;
1613
Select_Lex *lsel= table->pos_in_table_list->schema_select_lex;
1615
LOOKUP_FIELD_VALUES lookup_field_vals;
1617
vector<LEX_STRING*> db_names, table_names;
1618
/* the WHERE clause */
1619
COND *cond= table->reginfo.join_tab->select_cond;
1620
COND *partial_cond= 0;
1621
uint32_t derived_tables= lex->derived_tables;
1623
Open_tables_state open_tables_state_backup;
1624
Query_tables_list query_tables_list_backup;
1625
bool old_value= session->no_warnings_for_error;
1628
We should not introduce deadlocks even if we already have some
1629
tables open and locked, since we won't lock tables which we will
1630
open and will ignore possible name-locks for these tables.
1632
session->reset_n_backup_open_tables_state(&open_tables_state_backup);
1635
this branch processes SHOW FIELDS, SHOW INDEXES commands.
1636
see sql_parse.cc, prepare_schema_table() function where
1637
this values are initialized
1639
if (lsel && lsel->table_list.first)
1641
error= fill_schema_show_cols_or_idxs(session, table->pos_in_table_list, schema_table,
1642
&open_tables_state_backup);
1646
if (get_lookup_field_values(session,
1648
table->pos_in_table_list,
1656
if (!lookup_field_vals.wild_db_value && !lookup_field_vals.wild_table_value)
1659
if lookup value is empty string then
1660
it's impossible table name or db name
1662
if ((lookup_field_vals.db_value.str && !lookup_field_vals.db_value.str[0]) ||
1663
(lookup_field_vals.table_value.str && !lookup_field_vals.table_value.str[0]))
1670
if (lookup_field_vals.db_value.length &&
1671
!lookup_field_vals.wild_db_value)
1672
table->pos_in_table_list->has_db_lookup_value= true;
1674
if (lookup_field_vals.table_value.length &&
1675
!lookup_field_vals.wild_table_value)
1676
table->pos_in_table_list->has_table_lookup_value= true;
1678
if (table->pos_in_table_list->has_db_lookup_value &&
1679
table->pos_in_table_list->has_table_lookup_value)
1682
partial_cond= make_cond_for_info_schema(cond, table, schema_table);
1686
/* EXPLAIN SELECT */
1691
table->setWriteSet();
1692
if (make_db_list(session, db_names, &lookup_field_vals, &with_i_schema))
1695
for (vector<LEX_STRING*>::iterator db_name= db_names.begin(); db_name != db_names.end(); ++db_name )
1697
session->no_warnings_for_error= 1;
1698
table_names.clear();
1699
int res= make_table_name_list(session, table_names,
1701
with_i_schema, *db_name);
1703
if (res == 2) /* Not fatal error, continue */
1710
for (vector<LEX_STRING*>::iterator table_name= table_names.begin(); table_name != table_names.end(); ++table_name)
1712
table->restoreRecordAsDefault();
1713
table->field[schema_table->getFirstColumnIndex()]->
1714
store((*db_name)->str, (*db_name)->length, system_charset_info);
1715
table->field[schema_table->getSecondColumnIndex()]->
1716
store((*table_name)->str, (*table_name)->length, system_charset_info);
1718
if (!partial_cond || partial_cond->val_int())
1720
/* SHOW Table NAMES command */
1721
if (schema_table->getTableName().compare("TABLE_NAMES") == 0)
1723
if (fill_schema_table_names(session,
1733
LEX_STRING tmp_lex_string, orig_db_name;
1735
Set the parent lex of 'sel' because it is needed by
1736
sel.init_query() which is called inside make_table_list.
1738
session->no_warnings_for_error= 1;
1739
sel.parent_lex= lex;
1740
/* db_name can be changed in make_table_list() func */
1741
if (! session->make_lex_string(&orig_db_name,
1749
if (make_table_list(session, &sel, *db_name, *table_name))
1752
TableList *show_table_list= (TableList*) sel.table_list.first;
1753
lex->all_selects_list= &sel;
1754
lex->derived_tables= 0;
1755
lex->sql_command= SQLCOM_SHOW_FIELDS;
1756
show_table_list->i_s_requested_object=
1757
schema_table->getRequestedObject();
1758
res= session->openTables(show_table_list, DRIZZLE_LOCK_IGNORE_FLUSH);
1759
lex->sql_command= save_sql_command;
1761
XXX-> show_table_list has a flag i_is_requested,
1762
and when it's set, openTables()
1763
can return an error without setting an error message
1764
in Session, which is a hack. This is why we have to
1765
check for res, then for session->is_error() only then
1766
for session->main_da.sql_errno().
1768
if (res && session->is_error() &&
1769
session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
1772
Hide error for not existing table.
1773
This error can occur for example when we use
1774
where condition with db name and table name and this
1775
table does not exist.
1778
session->clear_error();
1783
We should use show_table_list->alias instead of
1784
show_table_list->table_name because table_name
1785
could be changed during opening of I_S tables. It's safe
1786
to use alias because alias contains original table name
1789
session->make_lex_string(&tmp_lex_string, show_table_list->alias,
1790
strlen(show_table_list->alias), false);
1791
res= schema_table->processTable(session, show_table_list, table,
1794
session->close_tables_for_reopen(&show_table_list);
1796
assert(!lex->query_tables_own_last);
1803
If we have information schema its always the first table and only
1804
the first table. Reset for other tables.
1812
session->restore_backup_open_tables_state(&open_tables_state_backup);
1813
lex->derived_tables= derived_tables;
1814
lex->all_selects_list= old_all_select_lex;
1815
lex->sql_command= save_sql_command;
1816
session->no_warnings_for_error= old_value;
1822
@brief Store field characteristics into appropriate I_S table columns
1824
@param[in] table I_S table
1825
@param[in] field processed field
1826
@param[in] cs I_S table charset
1827
@param[in] offset offset from beginning of table
1828
to DATE_TYPE column in I_S table
1833
static void store_column_type(Table *table, Field *field,
1834
const CHARSET_INFO * const cs,
1838
int decimals, field_length;
1839
const char *tmp_buff;
1840
char column_type_buff[MAX_FIELD_WIDTH];
1841
String column_type(column_type_buff, sizeof(column_type_buff), cs);
1843
field->sql_type(column_type);
1844
/* DTD_IDENTIFIER column */
1845
table->field[offset + 7]->store(column_type.ptr(), column_type.length(), cs);
1846
table->field[offset + 7]->set_notnull();
1847
tmp_buff= strchr(column_type.ptr(), '(');
1848
/* DATA_TYPE column */
1849
table->field[offset]->store(column_type.ptr(),
1850
(tmp_buff ? tmp_buff - column_type.ptr() :
1851
column_type.length()), cs);
1852
is_blob= (field->type() == DRIZZLE_TYPE_BLOB);
1853
if (field->has_charset() || is_blob ||
1854
field->real_type() == DRIZZLE_TYPE_VARCHAR) // For varbinary type
1856
uint32_t octet_max_length= field->max_display_length();
1857
if (is_blob && octet_max_length != (uint32_t) 4294967295U)
1858
octet_max_length /= field->charset()->mbmaxlen;
1859
int64_t char_max_len= is_blob ?
1860
(int64_t) octet_max_length / field->charset()->mbminlen :
1861
(int64_t) octet_max_length / field->charset()->mbmaxlen;
1862
/* CHARACTER_MAXIMUM_LENGTH column*/
1863
table->field[offset + 1]->store(char_max_len, true);
1864
table->field[offset + 1]->set_notnull();
1865
/* CHARACTER_OCTET_LENGTH column */
1866
table->field[offset + 2]->store((int64_t) octet_max_length, true);
1867
table->field[offset + 2]->set_notnull();
1871
Calculate field_length and decimals.
1872
They are set to -1 if they should not be set (we should return NULL)
1875
decimals= field->decimals();
1876
switch (field->type()) {
1877
case DRIZZLE_TYPE_DECIMAL:
1878
field_length= ((Field_decimal*) field)->precision;
1880
case DRIZZLE_TYPE_LONG:
1881
case DRIZZLE_TYPE_LONGLONG:
1882
field_length= field->max_display_length() - 1;
1884
case DRIZZLE_TYPE_DOUBLE:
1885
field_length= field->field_length;
1886
if (decimals == NOT_FIXED_DEC)
1887
decimals= -1; // return NULL
1890
field_length= decimals= -1;
1894
/* NUMERIC_PRECISION column */
1895
if (field_length >= 0)
1897
table->field[offset + 3]->store((int64_t) field_length, true);
1898
table->field[offset + 3]->set_notnull();
1900
/* NUMERIC_SCALE column */
1903
table->field[offset + 4]->store((int64_t) decimals, true);
1904
table->field[offset + 4]->set_notnull();
1906
if (field->has_charset())
1908
/* CHARACTER_SET_NAME column*/
1909
tmp_buff= field->charset()->csname;
1910
table->field[offset + 5]->store(tmp_buff, strlen(tmp_buff), cs);
1911
table->field[offset + 5]->set_notnull();
1912
/* COLLATION_NAME column */
1913
tmp_buff= field->charset()->name;
1914
table->field[offset + 6]->store(tmp_buff, strlen(tmp_buff), cs);
1915
table->field[offset + 6]->set_notnull();
1920
int plugin::InfoSchemaMethods::processTable(
1921
plugin::InfoSchemaTable *store_table,
1924
Table *table, bool res,
1925
LEX_STRING *db_name,
1926
LEX_STRING *table_name)
1928
LEX *lex= session->lex;
1929
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1930
const CHARSET_INFO * const cs= system_charset_info;
1932
TableShare *show_table_share;
1933
Field **ptr, *field, *timestamp_field;
1938
if (lex->sql_command != SQLCOM_SHOW_FIELDS)
1941
I.e. we are in SELECT FROM INFORMATION_SCHEMA.COLUMS
1942
rather than in SHOW COLUMNS
1944
if (session->is_error())
1945
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1946
session->main_da.sql_errno(), session->main_da.message());
1947
session->clear_error();
1953
show_table= tables->table;
1954
show_table_share= show_table->s;
1957
ptr= show_table_share->field;
1958
timestamp_field= show_table_share->timestamp_field;
1960
/* For the moment we just set everything to read */
1961
if (!show_table->read_set)
1963
show_table->def_read_set.setAll();
1964
show_table->read_set= &show_table->def_read_set;
1966
show_table->use_all_columns(); // Required for default
1968
for (; (field= *ptr) ; ptr++)
1971
char tmp[MAX_FIELD_WIDTH];
1972
String type(tmp,sizeof(tmp), system_charset_info);
1975
/* to satisfy 'field->val_str' ASSERTs */
1976
field->table= show_table;
1977
show_table->in_use= session;
1979
if (wild && wild[0] &&
1980
wild_case_compare(system_charset_info, field->field_name,wild))
1984
/* Get default row, with all NULL fields set to NULL */
1985
table->restoreRecordAsDefault();
1987
table->field[1]->store(db_name->str, db_name->length, cs);
1988
table->field[2]->store(table_name->str, table_name->length, cs);
1989
table->field[3]->store(field->field_name, strlen(field->field_name),
1991
table->field[4]->store((int64_t) count, true);
1993
if (get_field_default_value(timestamp_field, field, &type, 0))
1995
table->field[5]->store(type.ptr(), type.length(), cs);
1996
table->field[5]->set_notnull();
1998
pos=(unsigned char*) ((field->flags & NOT_NULL_FLAG) ? "NO" : "YES");
1999
table->field[6]->store((const char*) pos,
2000
strlen((const char*) pos), cs);
2001
store_column_type(table, field, cs, 7);
2003
pos=(unsigned char*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
2004
(field->flags & UNIQUE_KEY_FLAG) ? "UNI" :
2005
(field->flags & MULTIPLE_KEY_FLAG) ? "MUL":"");
2006
table->field[15]->store((const char*) pos,
2007
strlen((const char*) pos), cs);
2010
if (field->unireg_check == Field::NEXT_NUMBER)
2011
table->field[16]->store(STRING_WITH_LEN("auto_increment"), cs);
2012
if (timestamp_field == field &&
2013
field->unireg_check != Field::TIMESTAMP_DN_FIELD)
2014
table->field[16]->store(STRING_WITH_LEN("on update CURRENT_TIMESTAMP"),
2016
table->field[18]->store(field->comment.str, field->comment.length, cs);
2018
enum column_format_type column_format= (enum column_format_type)
2019
((field->flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
2020
pos=(unsigned char*)"Default";
2021
table->field[19]->store((const char*) pos,
2022
strlen((const char*) pos), cs);
2023
pos=(unsigned char*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
2024
column_format == COLUMN_FORMAT_TYPE_FIXED ? "Fixed" :
2026
table->field[20]->store((const char*) pos,
2027
strlen((const char*) pos), cs);
2029
store_table->addRow(table->record[0], table->s->reclength);
2036
For old SHOW compatibility. It is used when
2037
old SHOW doesn't have generated column names
2038
Make list of fields for SHOW
2041
plugin::InfoSchemaMethods::oldFormat()
2042
session thread Cursor
2043
schema_table pointer to 'schema_tables' element
2050
int plugin::InfoSchemaMethods::oldFormat(Session *session, plugin::InfoSchemaTable *schema_table)
2053
Name_resolution_context *context= &session->lex->select_lex.context;
2054
const plugin::InfoSchemaTable::Columns columns= schema_table->getColumns();
2055
plugin::InfoSchemaTable::Columns::const_iterator iter= columns.begin();
2057
while (iter != columns.end())
2059
const plugin::ColumnInfo *column= *iter;
2060
if (column->getOldName().length() != 0)
2062
Item_field *field= new Item_field(context,
2064
column->getName().c_str());
2067
field->set_name(column->getOldName().c_str(),
2068
column->getOldName().length(),
2069
system_charset_info);
2070
if (session->add_item_to_list(field))
2081
Generate select from information_schema table
2084
make_schema_select()
2085
session thread Cursor
2086
sel pointer to Select_Lex
2087
schema_table_name name of 'schema_tables' element
2093
bool make_schema_select(Session *session, Select_Lex *sel,
2094
const string& schema_table_name)
2096
plugin::InfoSchemaTable *schema_table= plugin::InfoSchemaTable::getTable(schema_table_name.c_str());
2097
LEX_STRING db, table;
2099
We have to make non const db_name & table_name
2100
because of lower_case_table_names
2102
session->make_lex_string(&db, INFORMATION_SCHEMA_NAME.c_str(),
2103
INFORMATION_SCHEMA_NAME.length(), 0);
2104
session->make_lex_string(&table, schema_table->getTableName().c_str(),
2105
schema_table->getTableName().length(), 0);
2106
if (schema_table->oldFormat(session, schema_table) || /* Handle old syntax */
2107
! sel->add_table_to_list(session, new Table_ident(db, table), 0, 0, TL_READ))
2114
875
} /* namespace drizzled */