317
318
It prepares a Select_Lex and a TableList object to represent the
318
319
given command as a SELECT parse tree.
320
@param session thread handle
321
@param lex current lex
322
@param table_ident table alias if it's used
323
@param schema_table_idx the type of the INFORMATION_SCHEMA table to be
321
@param session thread handle
322
@param lex current lex
323
@param table_ident table alias if it's used
324
@param schema_table_name the name of the INFORMATION_SCHEMA table to be
327
328
Due to the way this function works with memory and LEX it cannot
338
339
int prepare_schema_table(Session *session, LEX *lex, Table_ident *table_ident,
339
enum enum_schema_tables schema_table_idx)
340
const string& schema_table_name)
341
342
Select_Lex *schema_select_lex= NULL;
343
switch (schema_table_idx) {
346
case SCH_TABLE_NAMES:
351
if (lex->select_lex.db == NULL &&
352
lex->copy_db_to(&lex->select_lex.db, &dummy))
356
schema_select_lex= new Select_Lex();
357
db.str= schema_select_lex->db= lex->select_lex.db;
358
schema_select_lex->table_list.first= NULL;
359
db.length= strlen(db.str);
361
if (check_db_name(&db))
363
my_error(ER_WRONG_DB_NAME, MYF(0), db.str);
345
if (schema_table_name.compare("TABLES") == 0 ||
346
schema_table_name.compare("TABLE_NAMES") == 0)
350
if (lex->select_lex.db == NULL &&
351
lex->copy_db_to(&lex->select_lex.db, &dummy))
355
schema_select_lex= new Select_Lex();
356
db.str= schema_select_lex->db= lex->select_lex.db;
357
schema_select_lex->table_list.first= NULL;
358
db.length= strlen(db.str);
360
if (check_db_name(&db))
362
my_error(ER_WRONG_DB_NAME, MYF(0), db.str);
366
else if (schema_table_name.compare("COLUMNS") == 0 ||
367
schema_table_name.compare("STATISTICS") == 0)
371
369
assert(table_ident);
372
370
TableList **query_tables_last= lex->query_tables_last;
374
372
/* 'parent_lex' is used in init_query() so it must be before it. */
375
373
schema_select_lex->parent_lex= lex;
376
374
schema_select_lex->init_query();
377
if (!schema_select_lex->add_table_to_list(session, table_ident, 0, 0, TL_READ))
375
if (! schema_select_lex->add_table_to_list(session, table_ident, 0, 0, TL_READ))
379
379
lex->query_tables_last= query_tables_last;
382
case SCH_OPEN_TABLES:
385
case SCH_TABLE_CONSTRAINTS:
386
case SCH_KEY_COLUMN_USAGE:
391
382
Select_Lex *select_lex= lex->current_select;
392
383
assert(select_lex);
393
if (make_schema_select(session, select_lex, schema_table_idx))
384
if (make_schema_select(session, select_lex, schema_table_name))
2517
2508
char command[80];
2518
2509
Lex_input_stream *lip= session->m_lip;
2519
2510
strncpy(command, lip->yylval->symbol.str,
2520
cmin(lip->yylval->symbol.length, sizeof(command)-1));
2521
command[cmin(lip->yylval->symbol.length, sizeof(command)-1)]=0;
2511
min(lip->yylval->symbol.length, (uint32_t)(sizeof(command)-1)));
2512
command[min(lip->yylval->symbol.length, (uint32_t)(sizeof(command)-1))]=0;
2522
2513
my_error(ER_CANT_USE_OPTION_HERE, MYF(0), command);