880
} /* namespace drizzled */
1007
static int make_table_list(Session *session, Select_Lex *sel,
1008
LEX_STRING *db_name, LEX_STRING *table_name)
1010
Table_ident *table_ident;
1011
table_ident= new Table_ident(*db_name, *table_name);
1013
if (! sel->add_table_to_list(session, table_ident, 0, 0, TL_READ))
1020
@brief Get lookup value from the part of 'WHERE' condition
1022
@details This function gets lookup value from
1023
the part of 'WHERE' condition if it's possible and
1024
fill appropriate lookup_field_vals struct field
1027
@param[in] session thread Cursor
1028
@param[in] item_func part of WHERE condition
1029
@param[in] table I_S table
1030
@param[in, out] lookup_field_vals Struct which holds lookup values
1034
1 error, there can be no matching records for the condition
1037
static bool get_lookup_value(Session *session, Item_func *item_func,
1039
LOOKUP_FIELD_VALUES *lookup_field_vals,
1040
plugin::InfoSchemaTable *schema_table)
1042
const char *field_name1= schema_table->getFirstColumnIndex() >= 0 ?
1043
schema_table->getColumnName(schema_table->getFirstColumnIndex()).c_str() : "";
1044
const char *field_name2= schema_table->getSecondColumnIndex() >= 0 ?
1045
schema_table->getColumnName(schema_table->getSecondColumnIndex()).c_str() : "";
1047
if (item_func->functype() == Item_func::EQ_FUNC ||
1048
item_func->functype() == Item_func::EQUAL_FUNC)
1050
int idx_field, idx_val;
1051
char tmp[MAX_FIELD_WIDTH];
1052
String *tmp_str, str_buff(tmp, sizeof(tmp), system_charset_info);
1053
Item_field *item_field;
1054
const CHARSET_INFO * const cs= system_charset_info;
1056
if (item_func->arguments()[0]->type() == Item::FIELD_ITEM &&
1057
item_func->arguments()[1]->const_item())
1062
else if (item_func->arguments()[1]->type() == Item::FIELD_ITEM &&
1063
item_func->arguments()[0]->const_item())
1071
item_field= (Item_field*) item_func->arguments()[idx_field];
1072
if (table->table != item_field->field->table)
1074
tmp_str= item_func->arguments()[idx_val]->val_str(&str_buff);
1076
/* impossible value */
1080
/* Lookup value is database name */
1081
if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
1082
(unsigned char *) item_field->field_name,
1083
strlen(item_field->field_name), 0))
1085
session->make_lex_string(&lookup_field_vals->db_value, tmp_str->ptr(),
1086
tmp_str->length(), false);
1088
/* Lookup value is table name */
1089
else if (!cs->coll->strnncollsp(cs, (unsigned char *) field_name2,
1090
strlen(field_name2),
1091
(unsigned char *) item_field->field_name,
1092
strlen(item_field->field_name), 0))
1094
session->make_lex_string(&lookup_field_vals->table_value, tmp_str->ptr(),
1095
tmp_str->length(), false);
1103
@brief Calculates lookup values from 'WHERE' condition
1105
@details This function calculates lookup value(database name, table name)
1106
from 'WHERE' condition if it's possible and
1107
fill lookup_field_vals struct fields with these values.
1109
@param[in] session thread Cursor
1110
@param[in] cond WHERE condition
1111
@param[in] table I_S table
1112
@param[in, out] lookup_field_vals Struct which holds lookup values
1116
1 error, there can be no matching records for the condition
1119
bool calc_lookup_values_from_cond(Session *session, COND *cond, TableList *table,
1120
LOOKUP_FIELD_VALUES *lookup_field_vals,
1121
plugin::InfoSchemaTable *schema_table)
1126
if (cond->type() == Item::COND_ITEM)
1128
if (((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC)
1130
List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
1132
while ((item= li++))
1134
if (item->type() == Item::FUNC_ITEM)
1136
if (get_lookup_value(session, (Item_func*)item, table, lookup_field_vals, schema_table))
1141
if (calc_lookup_values_from_cond(session, item, table, lookup_field_vals, schema_table))
1148
else if (cond->type() == Item::FUNC_ITEM &&
1149
get_lookup_value(session, (Item_func*) cond, table, lookup_field_vals, schema_table))
1155
static bool uses_only_table_name_fields(Item *item, Table *table, plugin::InfoSchemaTable *schema_table)
1157
if (item->type() == Item::FUNC_ITEM)
1159
Item_func *item_func= (Item_func*)item;
1160
for (uint32_t i=0; i<item_func->argument_count(); i++)
1162
if (! uses_only_table_name_fields(item_func->arguments()[i], table, schema_table))
1166
else if (item->type() == Item::FIELD_ITEM)
1168
Item_field *item_field= (Item_field*)item;
1169
const CHARSET_INFO * const cs= system_charset_info;
1170
const char *field_name1= schema_table->getFirstColumnIndex() >= 0 ?
1171
schema_table->getColumnName(schema_table->getFirstColumnIndex()).c_str() : "";
1172
const char *field_name2= schema_table->getSecondColumnIndex() >= 0 ?
1173
schema_table->getColumnName(schema_table->getSecondColumnIndex()).c_str() : "";
1174
if (table != item_field->field->table ||
1175
(cs->coll->strnncollsp(cs, (unsigned char *) field_name1, strlen(field_name1),
1176
(unsigned char *) item_field->field_name,
1177
strlen(item_field->field_name), 0) &&
1178
cs->coll->strnncollsp(cs, (unsigned char *) field_name2, strlen(field_name2),
1179
(unsigned char *) item_field->field_name,
1180
strlen(item_field->field_name), 0)))
1183
else if (item->type() == Item::REF_ITEM)
1184
return uses_only_table_name_fields(item->real_item(), table, schema_table);
1186
if (item->type() == Item::SUBSELECT_ITEM && !item->const_item())
1193
static COND * make_cond_for_info_schema(COND *cond, Table *table, plugin::InfoSchemaTable *schema_table)
1197
if (cond->type() == Item::COND_ITEM)
1199
if (((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC)
1201
/* Create new top level AND item */
1202
Item_cond_and *new_cond=new Item_cond_and;
1205
List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
1209
Item *fix= make_cond_for_info_schema(item, table, schema_table);
1211
new_cond->argument_list()->push_back(fix);
1213
switch (new_cond->argument_list()->elements) {
1217
return new_cond->argument_list()->head();
1219
new_cond->quick_fix_field();
1225
Item_cond_or *new_cond=new Item_cond_or;
1228
List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
1232
Item *fix=make_cond_for_info_schema(item, table, schema_table);
1235
new_cond->argument_list()->push_back(fix);
1237
new_cond->quick_fix_field();
1238
new_cond->top_level_item();
1243
if (! uses_only_table_name_fields(cond, table, schema_table))
1250
@brief Calculate lookup values(database name, table name)
1252
@details This function calculates lookup values(database name, table name)
1253
from 'WHERE' condition or wild values (for 'SHOW' commands only)
1254
from LEX struct and fill lookup_field_vals struct field
1257
@param[in] session thread Cursor
1258
@param[in] cond WHERE condition
1259
@param[in] tables I_S table
1260
@param[in, out] lookup_field_values Struct which holds lookup values
1264
1 error, there can be no matching records for the condition
1267
bool get_lookup_field_values(Session *session, COND *cond, TableList *tables,
1268
LOOKUP_FIELD_VALUES *lookup_field_values,
1269
plugin::InfoSchemaTable *schema_table)
1271
LEX *lex= session->lex;
1272
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1273
memset(lookup_field_values, 0, sizeof(LOOKUP_FIELD_VALUES));
1274
switch (lex->sql_command) {
1275
case SQLCOM_SHOW_DATABASES:
1278
lookup_field_values->db_value.str= (char*) wild;
1279
lookup_field_values->db_value.length= strlen(wild);
1280
lookup_field_values->wild_db_value= 1;
1283
case SQLCOM_SHOW_TABLES:
1284
case SQLCOM_SHOW_TABLE_STATUS:
1285
lookup_field_values->db_value.str= lex->select_lex.db;
1286
lookup_field_values->db_value.length=strlen(lex->select_lex.db);
1289
lookup_field_values->table_value.str= (char*)wild;
1290
lookup_field_values->table_value.length= strlen(wild);
1291
lookup_field_values->wild_table_value= 1;
1296
The "default" is for queries over I_S.
1297
All previous cases handle SHOW commands.
1299
return calc_lookup_values_from_cond(session, cond, tables, lookup_field_values, schema_table);
1305
* Function used for sorting with std::sort within make_db_list.
1307
* @returns true if a < b, false otherwise
1310
static bool lex_string_sort(const LEX_STRING *a, const LEX_STRING *b)
1312
return (strcmp(a->str, b->str) < 0);
1318
* Create db names list. Information schema name always is first in list
1320
* @param[in] session Thread Cursor
1321
* @param[out] files List of db names
1322
* @param[in] wild Wild string
1323
* @param[in] idx_field_vals idx_field_vals->db_name contains db name or
1325
* @param[out] with_i_schema Returns 1 if we added 'IS' name to list
1326
* otherwise returns 0
1331
int make_db_list(Session *session, vector<LEX_STRING*> &files,
1332
LOOKUP_FIELD_VALUES *lookup_field_vals,
1333
bool *with_i_schema)
1335
LEX_STRING *i_s_name_copy= 0;
1336
i_s_name_copy= session->make_lex_string(i_s_name_copy,
1337
INFORMATION_SCHEMA_NAME.c_str(),
1338
INFORMATION_SCHEMA_NAME.length(), true);
1340
if (lookup_field_vals->wild_db_value)
1343
This part of code is only for SHOW DATABASES command.
1344
idx_field_vals->db_value can be 0 when we don't use
1345
LIKE clause (see also get_index_field_values() function)
1347
if (!lookup_field_vals->db_value.str ||
1348
!wild_case_compare(system_charset_info,
1349
INFORMATION_SCHEMA_NAME.c_str(),
1350
lookup_field_vals->db_value.str))
1353
files.push_back(i_s_name_copy);
1356
if (find_schemas(session, files, drizzle_data_home,
1357
lookup_field_vals->db_value.str) == true)
1362
sort(files.begin()+1, files.end(), lex_string_sort);
1368
If we have db lookup vaule we just add it to list and
1369
exit from the function
1371
if (lookup_field_vals->db_value.str)
1373
if (!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.c_str(),
1374
lookup_field_vals->db_value.str))
1377
files.push_back(i_s_name_copy);
1381
files.push_back(&lookup_field_vals->db_value);
1386
Create list of existing databases. It is used in case
1387
of select from information schema table
1389
files.push_back(i_s_name_copy);
1393
if (find_schemas(session, files, drizzle_data_home, NULL) == true)
1398
sort(files.begin()+1, files.end(), lex_string_sort);
1404
@brief Create table names list
1406
@details The function creates the list of table names in
1409
@param[in] session thread Cursor
1410
@param[in] table_names List of table names in database
1411
@param[in] lex pointer to LEX struct
1412
@param[in] lookup_field_vals pointer to LOOKUP_FIELD_VALUE struct
1413
@param[in] with_i_schema true means that we add I_S tables to list
1414
@param[in] db_name database name
1416
@return Operation status
1418
@retval 1 fatal error
1419
@retval 2 Not fatal error; Safe to ignore this cursor list
1423
make_table_name_list(Session *session, vector<LEX_STRING*> &table_names,
1424
LOOKUP_FIELD_VALUES *lookup_field_vals,
1425
bool with_i_schema, LEX_STRING *db_name)
1427
char path[FN_REFLEN];
1428
set<string> set_of_names;
1430
build_table_filename(path, sizeof(path), db_name->str, "", false);
1432
if (!lookup_field_vals->wild_table_value &&
1433
lookup_field_vals->table_value.str)
1437
if (plugin::InfoSchemaTable::getTable(lookup_field_vals->table_value.str))
1439
table_names.push_back(&lookup_field_vals->table_value);
1444
table_names.push_back(&lookup_field_vals->table_value);
1449
string db(db_name->str);
1450
plugin::StorageEngine::getTableNames(db, set_of_names);
1453
New I_S engine will make this go away, so ignore lack of foreach() usage.
1455
Notice how bad this design is... sure we created a set... but then we
1456
are just pushing to another set. --
1457
Also... callback design won't work, so we need to rewrite this to
1458
feed (which means new I_S). For the moment we will not optimize this.
1461
for (set<string>::iterator it= set_of_names.begin(); it != set_of_names.end(); it++)
1463
LEX_STRING *file_name= NULL;
1465
file_name= session->make_lex_string(file_name, (*it).c_str(),
1466
(*it).length(), true);
1467
const char* wild= lookup_field_vals->table_value.str;
1468
if (wild && wild_compare((*it).c_str(), wild, 0))
1471
table_names.push_back(file_name);
1479
@brief Fill I_S table for SHOW COLUMNS|INDEX commands
1481
@param[in] session thread Cursor
1482
@param[in] tables TableList for I_S table
1483
@param[in] schema_table pointer to I_S structure
1484
@param[in] open_tables_state_backup pointer to Open_tables_state object
1485
which is used to save|restore original
1486
status of variables related to
1489
@return Operation status
1495
fill_schema_show_cols_or_idxs(Session *session, TableList *tables,
1496
plugin::InfoSchemaTable *schema_table,
1497
Open_tables_state *open_tables_state_backup)
1499
LEX *lex= session->lex;
1501
LEX_STRING tmp_lex_string, tmp_lex_string1, *db_name, *table_name;
1502
enum_sql_command save_sql_command= lex->sql_command;
1503
TableList *show_table_list= (TableList*) tables->schema_select_lex->
1505
Table *table= tables->table;
1508
lex->all_selects_list= tables->schema_select_lex;
1510
Restore session->temporary_tables to be able to process
1511
temporary tables(only for 'show index' & 'show columns').
1512
This should be changed when processing of temporary tables for
1513
I_S tables will be done.
1515
session->temporary_tables= open_tables_state_backup->temporary_tables;
1517
Let us set fake sql_command so views won't try to merge
1518
themselves into main statement. If we don't do this,
1519
SELECT * from information_schema.xxxx will cause problems.
1520
SQLCOM_SHOW_FIELDS is used because it satisfies 'only_view_structure()'
1522
lex->sql_command= SQLCOM_SHOW_FIELDS;
1523
res= session->openTables(show_table_list, DRIZZLE_LOCK_IGNORE_FLUSH);
1524
lex->sql_command= save_sql_command;
1526
get_all_tables() returns 1 on failure and 0 on success thus
1527
return only these and not the result code of ::process_table()
1529
We should use show_table_list->alias instead of
1530
show_table_list->table_name because table_name
1531
could be changed during opening of I_S tables. It's safe
1532
to use alias because alias contains original table name
1533
in this case(this part of code is used only for
1534
'show columns' & 'show statistics' commands).
1536
table_name= session->make_lex_string(&tmp_lex_string1, show_table_list->alias,
1537
strlen(show_table_list->alias), false);
1538
db_name= session->make_lex_string(&tmp_lex_string, show_table_list->db,
1539
show_table_list->db_length, false);
1542
table->setWriteSet();
1543
error= test(schema_table->processTable(session, show_table_list,
1544
table, res, db_name,
1546
session->temporary_tables= 0;
1547
session->close_tables_for_reopen(&show_table_list);
1554
@brief Fill I_S table for SHOW Table NAMES commands
1556
@param[in] session thread Cursor
1557
@param[in] table Table struct for I_S table
1558
@param[in] db_name database name
1559
@param[in] table_name table name
1560
@param[in] with_i_schema I_S table if true
1562
@return Operation status
1567
static int fill_schema_table_names(Session *session, Table *table,
1568
LEX_STRING *db_name, LEX_STRING *table_name,
1570
plugin::InfoSchemaTable *schema_table)
1574
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"),
1575
system_charset_info);
1579
char path[FN_REFLEN];
1580
(void) build_table_filename(path, sizeof(path), db_name->str,
1581
table_name->str, false);
1583
table->field[3]->store(STRING_WITH_LEN("BASE Table"),
1584
system_charset_info);
1586
if (session->is_error() && session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
1588
session->clear_error();
1592
schema_table->addRow(table->record[0], table->s->reclength);
1598
@brief Fill I_S tables whose data are retrieved
1599
from frm files and storage engine
1601
@details The information schema tables are internally represented as
1602
temporary tables that are filled at query execution time.
1603
Those I_S tables whose data are retrieved
1604
from frm files and storage engine are filled by the function
1605
plugin::InfoSchemaMethods::fillTable().
1607
@param[in] session thread Cursor
1608
@param[in] tables I_S table
1610
@return Operation status
1614
int plugin::InfoSchemaMethods::fillTable(Session *session,
1616
plugin::InfoSchemaTable *schema_table)
1618
LEX *lex= session->lex;
1619
Select_Lex *old_all_select_lex= lex->all_selects_list;
1620
enum_sql_command save_sql_command= lex->sql_command;
1621
Select_Lex *lsel= table->pos_in_table_list->schema_select_lex;
1623
LOOKUP_FIELD_VALUES lookup_field_vals;
1625
vector<LEX_STRING*> db_names, table_names;
1626
/* the WHERE clause */
1627
COND *cond= table->reginfo.join_tab->select_cond;
1628
COND *partial_cond= 0;
1629
uint32_t derived_tables= lex->derived_tables;
1631
Open_tables_state open_tables_state_backup;
1632
Query_tables_list query_tables_list_backup;
1633
bool old_value= session->no_warnings_for_error;
1636
We should not introduce deadlocks even if we already have some
1637
tables open and locked, since we won't lock tables which we will
1638
open and will ignore possible name-locks for these tables.
1640
session->reset_n_backup_open_tables_state(&open_tables_state_backup);
1643
this branch processes SHOW FIELDS, SHOW INDEXES commands.
1644
see sql_parse.cc, prepare_schema_table() function where
1645
this values are initialized
1647
if (lsel && lsel->table_list.first)
1649
error= fill_schema_show_cols_or_idxs(session, table->pos_in_table_list, schema_table,
1650
&open_tables_state_backup);
1654
if (get_lookup_field_values(session,
1656
table->pos_in_table_list,
1664
if (!lookup_field_vals.wild_db_value && !lookup_field_vals.wild_table_value)
1667
if lookup value is empty string then
1668
it's impossible table name or db name
1670
if ((lookup_field_vals.db_value.str && !lookup_field_vals.db_value.str[0]) ||
1671
(lookup_field_vals.table_value.str && !lookup_field_vals.table_value.str[0]))
1678
if (lookup_field_vals.db_value.length &&
1679
!lookup_field_vals.wild_db_value)
1680
table->pos_in_table_list->has_db_lookup_value= true;
1682
if (lookup_field_vals.table_value.length &&
1683
!lookup_field_vals.wild_table_value)
1684
table->pos_in_table_list->has_table_lookup_value= true;
1686
if (table->pos_in_table_list->has_db_lookup_value &&
1687
table->pos_in_table_list->has_table_lookup_value)
1690
partial_cond= make_cond_for_info_schema(cond, table, schema_table);
1694
/* EXPLAIN SELECT */
1699
table->setWriteSet();
1700
if (make_db_list(session, db_names, &lookup_field_vals, &with_i_schema))
1703
for (vector<LEX_STRING*>::iterator db_name= db_names.begin(); db_name != db_names.end(); ++db_name )
1705
session->no_warnings_for_error= 1;
1706
table_names.clear();
1707
int res= make_table_name_list(session, table_names,
1709
with_i_schema, *db_name);
1711
if (res == 2) /* Not fatal error, continue */
1718
for (vector<LEX_STRING*>::iterator table_name= table_names.begin(); table_name != table_names.end(); ++table_name)
1720
table->restoreRecordAsDefault();
1721
table->field[schema_table->getFirstColumnIndex()]->
1722
store((*db_name)->str, (*db_name)->length, system_charset_info);
1723
table->field[schema_table->getSecondColumnIndex()]->
1724
store((*table_name)->str, (*table_name)->length, system_charset_info);
1726
if (!partial_cond || partial_cond->val_int())
1728
/* SHOW Table NAMES command */
1729
if (schema_table->getTableName().compare("TABLE_NAMES") == 0)
1731
if (fill_schema_table_names(session,
1741
LEX_STRING tmp_lex_string, orig_db_name;
1743
Set the parent lex of 'sel' because it is needed by
1744
sel.init_query() which is called inside make_table_list.
1746
session->no_warnings_for_error= 1;
1747
sel.parent_lex= lex;
1748
/* db_name can be changed in make_table_list() func */
1749
if (! session->make_lex_string(&orig_db_name,
1757
if (make_table_list(session, &sel, *db_name, *table_name))
1760
TableList *show_table_list= (TableList*) sel.table_list.first;
1761
lex->all_selects_list= &sel;
1762
lex->derived_tables= 0;
1763
lex->sql_command= SQLCOM_SHOW_FIELDS;
1764
show_table_list->i_s_requested_object=
1765
schema_table->getRequestedObject();
1766
res= session->openTables(show_table_list, DRIZZLE_LOCK_IGNORE_FLUSH);
1767
lex->sql_command= save_sql_command;
1769
XXX-> show_table_list has a flag i_is_requested,
1770
and when it's set, openTables()
1771
can return an error without setting an error message
1772
in Session, which is a hack. This is why we have to
1773
check for res, then for session->is_error() only then
1774
for session->main_da.sql_errno().
1776
if (res && session->is_error() &&
1777
session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
1780
Hide error for not existing table.
1781
This error can occur for example when we use
1782
where condition with db name and table name and this
1783
table does not exist.
1786
session->clear_error();
1791
We should use show_table_list->alias instead of
1792
show_table_list->table_name because table_name
1793
could be changed during opening of I_S tables. It's safe
1794
to use alias because alias contains original table name
1797
session->make_lex_string(&tmp_lex_string, show_table_list->alias,
1798
strlen(show_table_list->alias), false);
1799
res= schema_table->processTable(session, show_table_list, table,
1802
session->close_tables_for_reopen(&show_table_list);
1804
assert(!lex->query_tables_own_last);
1811
If we have information schema its always the first table and only
1812
the first table. Reset for other tables.
1820
session->restore_backup_open_tables_state(&open_tables_state_backup);
1821
lex->derived_tables= derived_tables;
1822
lex->all_selects_list= old_all_select_lex;
1823
lex->sql_command= save_sql_command;
1824
session->no_warnings_for_error= old_value;
1830
@brief Store field characteristics into appropriate I_S table columns
1832
@param[in] table I_S table
1833
@param[in] field processed field
1834
@param[in] cs I_S table charset
1835
@param[in] offset offset from beginning of table
1836
to DATE_TYPE column in I_S table
1841
static void store_column_type(Table *table, Field *field,
1842
const CHARSET_INFO * const cs,
1846
int decimals, field_length;
1847
const char *tmp_buff;
1848
char column_type_buff[MAX_FIELD_WIDTH];
1849
String column_type(column_type_buff, sizeof(column_type_buff), cs);
1851
field->sql_type(column_type);
1852
/* DTD_IDENTIFIER column */
1853
table->field[offset + 7]->store(column_type.ptr(), column_type.length(), cs);
1854
table->field[offset + 7]->set_notnull();
1855
tmp_buff= strchr(column_type.ptr(), '(');
1856
/* DATA_TYPE column */
1857
table->field[offset]->store(column_type.ptr(),
1858
(tmp_buff ? tmp_buff - column_type.ptr() :
1859
column_type.length()), cs);
1860
is_blob= (field->type() == DRIZZLE_TYPE_BLOB);
1861
if (field->has_charset() || is_blob ||
1862
field->real_type() == DRIZZLE_TYPE_VARCHAR) // For varbinary type
1864
uint32_t octet_max_length= field->max_display_length();
1865
if (is_blob && octet_max_length != (uint32_t) 4294967295U)
1866
octet_max_length /= field->charset()->mbmaxlen;
1867
int64_t char_max_len= is_blob ?
1868
(int64_t) octet_max_length / field->charset()->mbminlen :
1869
(int64_t) octet_max_length / field->charset()->mbmaxlen;
1870
/* CHARACTER_MAXIMUM_LENGTH column*/
1871
table->field[offset + 1]->store(char_max_len, true);
1872
table->field[offset + 1]->set_notnull();
1873
/* CHARACTER_OCTET_LENGTH column */
1874
table->field[offset + 2]->store((int64_t) octet_max_length, true);
1875
table->field[offset + 2]->set_notnull();
1879
Calculate field_length and decimals.
1880
They are set to -1 if they should not be set (we should return NULL)
1883
decimals= field->decimals();
1884
switch (field->type()) {
1885
case DRIZZLE_TYPE_DECIMAL:
1886
field_length= ((Field_decimal*) field)->precision;
1888
case DRIZZLE_TYPE_LONG:
1889
case DRIZZLE_TYPE_LONGLONG:
1890
field_length= field->max_display_length() - 1;
1892
case DRIZZLE_TYPE_DOUBLE:
1893
field_length= field->field_length;
1894
if (decimals == NOT_FIXED_DEC)
1895
decimals= -1; // return NULL
1898
field_length= decimals= -1;
1902
/* NUMERIC_PRECISION column */
1903
if (field_length >= 0)
1905
table->field[offset + 3]->store((int64_t) field_length, true);
1906
table->field[offset + 3]->set_notnull();
1908
/* NUMERIC_SCALE column */
1911
table->field[offset + 4]->store((int64_t) decimals, true);
1912
table->field[offset + 4]->set_notnull();
1914
if (field->has_charset())
1916
/* CHARACTER_SET_NAME column*/
1917
tmp_buff= field->charset()->csname;
1918
table->field[offset + 5]->store(tmp_buff, strlen(tmp_buff), cs);
1919
table->field[offset + 5]->set_notnull();
1920
/* COLLATION_NAME column */
1921
tmp_buff= field->charset()->name;
1922
table->field[offset + 6]->store(tmp_buff, strlen(tmp_buff), cs);
1923
table->field[offset + 6]->set_notnull();
1928
int plugin::InfoSchemaMethods::processTable(
1929
plugin::InfoSchemaTable *store_table,
1932
Table *table, bool res,
1933
LEX_STRING *db_name,
1934
LEX_STRING *table_name)
1936
LEX *lex= session->lex;
1937
const char *wild= lex->wild ? lex->wild->ptr() : NULL;
1938
const CHARSET_INFO * const cs= system_charset_info;
1940
TableShare *show_table_share;
1941
Field **ptr, *field, *timestamp_field;
1946
if (lex->sql_command != SQLCOM_SHOW_FIELDS)
1949
I.e. we are in SELECT FROM INFORMATION_SCHEMA.COLUMS
1950
rather than in SHOW COLUMNS
1952
if (session->is_error())
1953
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1954
session->main_da.sql_errno(), session->main_da.message());
1955
session->clear_error();
1961
show_table= tables->table;
1962
show_table_share= show_table->s;
1965
ptr= show_table_share->field;
1966
timestamp_field= show_table_share->timestamp_field;
1968
/* For the moment we just set everything to read */
1969
if (!show_table->read_set)
1971
show_table->def_read_set.setAll();
1972
show_table->read_set= &show_table->def_read_set;
1974
show_table->use_all_columns(); // Required for default
1976
for (; (field= *ptr) ; ptr++)
1979
char tmp[MAX_FIELD_WIDTH];
1980
String type(tmp,sizeof(tmp), system_charset_info);
1983
/* to satisfy 'field->val_str' ASSERTs */
1984
field->table= show_table;
1985
show_table->in_use= session;
1987
if (wild && wild[0] &&
1988
wild_case_compare(system_charset_info, field->field_name,wild))
1992
/* Get default row, with all NULL fields set to NULL */
1993
table->restoreRecordAsDefault();
1995
table->field[1]->store(db_name->str, db_name->length, cs);
1996
table->field[2]->store(table_name->str, table_name->length, cs);
1997
table->field[3]->store(field->field_name, strlen(field->field_name),
1999
table->field[4]->store((int64_t) count, true);
2001
if (get_field_default_value(timestamp_field, field, &type, 0))
2003
table->field[5]->store(type.ptr(), type.length(), cs);
2004
table->field[5]->set_notnull();
2006
pos=(unsigned char*) ((field->flags & NOT_NULL_FLAG) ? "NO" : "YES");
2007
table->field[6]->store((const char*) pos,
2008
strlen((const char*) pos), cs);
2009
store_column_type(table, field, cs, 7);
2011
pos=(unsigned char*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
2012
(field->flags & UNIQUE_KEY_FLAG) ? "UNI" :
2013
(field->flags & MULTIPLE_KEY_FLAG) ? "MUL":"");
2014
table->field[15]->store((const char*) pos,
2015
strlen((const char*) pos), cs);
2018
if (field->unireg_check == Field::NEXT_NUMBER)
2019
table->field[16]->store(STRING_WITH_LEN("auto_increment"), cs);
2020
if (timestamp_field == field &&
2021
field->unireg_check != Field::TIMESTAMP_DN_FIELD)
2022
table->field[16]->store(STRING_WITH_LEN("on update CURRENT_TIMESTAMP"),
2024
table->field[18]->store(field->comment.str, field->comment.length, cs);
2026
enum column_format_type column_format= (enum column_format_type)
2027
((field->flags >> COLUMN_FORMAT_FLAGS) & COLUMN_FORMAT_MASK);
2028
pos=(unsigned char*)"Default";
2029
table->field[19]->store((const char*) pos,
2030
strlen((const char*) pos), cs);
2031
pos=(unsigned char*)(column_format == COLUMN_FORMAT_TYPE_DEFAULT ? "Default" :
2032
column_format == COLUMN_FORMAT_TYPE_FIXED ? "Fixed" :
2034
table->field[20]->store((const char*) pos,
2035
strlen((const char*) pos), cs);
2037
store_table->addRow(table->record[0], table->s->reclength);
2044
For old SHOW compatibility. It is used when
2045
old SHOW doesn't have generated column names
2046
Make list of fields for SHOW
2049
plugin::InfoSchemaMethods::oldFormat()
2050
session thread Cursor
2051
schema_table pointer to 'schema_tables' element
2058
int plugin::InfoSchemaMethods::oldFormat(Session *session, plugin::InfoSchemaTable *schema_table)
2061
Name_resolution_context *context= &session->lex->select_lex.context;
2062
const plugin::InfoSchemaTable::Columns columns= schema_table->getColumns();
2063
plugin::InfoSchemaTable::Columns::const_iterator iter= columns.begin();
2065
while (iter != columns.end())
2067
const plugin::ColumnInfo *column= *iter;
2068
if (column->getOldName().length() != 0)
2070
Item_field *field= new Item_field(context,
2072
column->getName().c_str());
2075
field->set_name(column->getOldName().c_str(),
2076
column->getOldName().length(),
2077
system_charset_info);
2078
if (session->add_item_to_list(field))
2089
Generate select from information_schema table
2092
make_schema_select()
2093
session thread Cursor
2094
sel pointer to Select_Lex
2095
schema_table_name name of 'schema_tables' element
2101
bool make_schema_select(Session *session, Select_Lex *sel,
2102
const string& schema_table_name)
2104
plugin::InfoSchemaTable *schema_table= plugin::InfoSchemaTable::getTable(schema_table_name.c_str());
2105
LEX_STRING db, table;
2107
We have to make non const db_name & table_name
2108
because of lower_case_table_names
2110
session->make_lex_string(&db, INFORMATION_SCHEMA_NAME.c_str(),
2111
INFORMATION_SCHEMA_NAME.length(), 0);
2112
session->make_lex_string(&table, schema_table->getTableName().c_str(),
2113
schema_table->getTableName().length(), 0);
2114
if (schema_table->oldFormat(session, schema_table) || /* Handle old syntax */
2115
! sel->add_table_to_list(session, new Table_ident(db, table), 0, 0, TL_READ))