153
bool buildScemas(Session *session)
155
session->getLex()->sql_command= SQLCOM_SELECT;
156
session->getLex()->statement= new statement::Show(session);
158
std::string column_name= "Database";
159
if (session->getLex()->wild)
161
column_name.append(" (");
162
column_name.append(session->getLex()->wild->ptr());
163
column_name.append(")");
166
if (session->getLex()->current_select->where)
168
if (prepare_new_schema_table(session, session->getLex(), "SCHEMAS"))
173
if (prepare_new_schema_table(session, session->getLex(), "SHOW_SCHEMAS"))
177
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
178
my_field->is_autogenerated_name= false;
179
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
181
if (session->add_item_to_list(my_field))
184
if (session->add_order_to_list(my_field, true))
190
bool buildTables(Session *session, const char *ident)
192
session->getLex()->sql_command= SQLCOM_SELECT;
194
drizzled::statement::Show *select= new statement::Show(session);
195
session->getLex()->statement= select;
197
std::string column_name= "Tables_in_";
199
util::string::const_shared_ptr schema(session->schema());
202
identifier::Schema identifier(ident);
203
column_name.append(ident);
204
session->getLex()->select_lex.db= const_cast<char *>(ident);
205
if (not plugin::StorageEngine::doesSchemaExist(identifier))
207
my_error(ER_BAD_DB_ERROR, MYF(0), ident);
209
select->setShowPredicate(ident, "");
211
else if (schema and not schema->empty())
213
column_name.append(*schema);
214
select->setShowPredicate(*schema, "");
218
my_error(ER_NO_DB_ERROR, MYF(0));
223
if (session->getLex()->wild)
225
column_name.append(" (");
226
column_name.append(session->getLex()->wild->ptr());
227
column_name.append(")");
230
if (prepare_new_schema_table(session, session->getLex(), "SHOW_TABLES"))
233
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
234
my_field->is_autogenerated_name= false;
235
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
237
if (session->add_item_to_list(my_field))
240
if (session->add_order_to_list(my_field, true))
246
bool buildTemporaryTables(Session *session)
248
session->getLex()->sql_command= SQLCOM_SELECT;
250
session->getLex()->statement= new statement::Show(session);
253
if (prepare_new_schema_table(session, session->getLex(), "SHOW_TEMPORARY_TABLES"))
256
if (session->add_item_to_list( new Item_field(&session->lex->current_select->context, NULL, NULL, "*")))
259
(session->lex->current_select->with_wild)++;
264
bool buildTableStatus(Session *session, const char *ident)
266
session->getLex()->sql_command= SQLCOM_SELECT;
267
drizzled::statement::Show *select= new statement::Show(session);
268
session->getLex()->statement= select;
270
std::string column_name= "Tables_in_";
272
util::string::const_shared_ptr schema(session->schema());
275
session->getLex()->select_lex.db= const_cast<char *>(ident);
277
identifier::Schema identifier(ident);
278
if (not plugin::StorageEngine::doesSchemaExist(identifier))
280
my_error(ER_BAD_DB_ERROR, MYF(0), ident);
283
select->setShowPredicate(ident, "");
287
select->setShowPredicate(*schema, "");
291
my_error(ER_NO_DB_ERROR, MYF(0));
295
if (prepare_new_schema_table(session, session->getLex(), "SHOW_TABLE_STATUS"))
298
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
303
(session->lex->current_select->with_wild)++;
308
bool buildColumns(Session *session, const char *schema_ident, Table_ident *table_ident)
310
session->getLex()->sql_command= SQLCOM_SELECT;
312
drizzled::statement::Show *select= new statement::Show(session);
313
session->getLex()->statement= select;
315
util::string::const_shared_ptr schema(session->schema());
318
select->setShowPredicate(schema_ident, table_ident->table.str);
320
else if (table_ident->db.str)
322
select->setShowPredicate(table_ident->db.str, table_ident->table.str);
326
select->setShowPredicate(*schema, table_ident->table.str);
330
my_error(ER_NO_DB_ERROR, MYF(0));
335
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), table_ident->table.str);
336
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
338
my_error(ER_NO_SUCH_TABLE, MYF(0),
339
select->getShowSchema().c_str(),
340
table_ident->table.str);
344
if (prepare_new_schema_table(session, session->getLex(), "SHOW_COLUMNS"))
347
if (session->add_item_to_list( new Item_field(&session->lex->current_select->context, NULL, NULL, "*")))
350
(session->lex->current_select->with_wild)++;
355
bool buildWarnings(Session *session)
357
session->getLex()->sql_command = SQLCOM_SHOW_WARNS;
358
session->getLex()->statement= new statement::ShowWarnings(session);
363
bool buildErrors(Session *session)
365
session->getLex()->sql_command = SQLCOM_SHOW_ERRORS;
366
session->getLex()->statement= new statement::ShowErrors(session);
371
bool buildIndex(Session *session, const char *schema_ident, Table_ident *table_ident)
373
session->getLex()->sql_command= SQLCOM_SELECT;
374
drizzled::statement::Show *select= new statement::Show(session);
375
session->getLex()->statement= select;
377
util::string::const_shared_ptr schema(session->schema());
380
select->setShowPredicate(schema_ident, table_ident->table.str);
382
else if (table_ident->db.str)
384
select->setShowPredicate(table_ident->db.str, table_ident->table.str);
388
select->setShowPredicate(*schema, table_ident->table.str);
392
my_error(ER_NO_DB_ERROR, MYF(0));
397
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), table_ident->table.str);
398
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
400
my_error(ER_NO_SUCH_TABLE, MYF(0),
401
select->getShowSchema().c_str(),
402
table_ident->table.str);
406
if (prepare_new_schema_table(session, session->getLex(), "SHOW_INDEXES"))
409
if (session->add_item_to_list( new Item_field(&session->lex->current_select->context, NULL, NULL, "*")))
412
(session->lex->current_select->with_wild)++;
417
bool buildStatus(Session *session, const drizzled::sql_var_t is_global)
419
session->getLex()->sql_command= SQLCOM_SELECT;
420
session->getLex()->statement= new statement::Show(session);
422
if (is_global == OPT_GLOBAL)
424
if (prepare_new_schema_table(session, session->getLex(), "GLOBAL_STATUS"))
429
if (prepare_new_schema_table(session, session->getLex(), "SESSION_STATUS"))
433
std::string key("Variable_name");
434
std::string value("Value");
436
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
437
my_field->is_autogenerated_name= false;
438
my_field->set_name(key.c_str(), key.length(), system_charset_info);
440
if (session->add_item_to_list(my_field))
443
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
444
my_field->is_autogenerated_name= false;
445
my_field->set_name(value.c_str(), value.length(), system_charset_info);
447
if (session->add_item_to_list(my_field))
453
bool buildCreateTable(Session *session, Table_ident *ident)
455
session->getLex()->sql_command= SQLCOM_SELECT;
456
statement::Show *select= new statement::Show(session);
457
session->getLex()->statement= select;
459
if (session->getLex()->statement == NULL)
462
if (prepare_new_schema_table(session, session->getLex(), "TABLE_SQL_DEFINITION"))
465
util::string::const_shared_ptr schema(session->schema());
468
select->setShowPredicate(ident->db.str, ident->table.str);
472
select->setShowPredicate(*schema, ident->table.str);
476
my_error(ER_NO_DB_ERROR, MYF(0));
480
std::string key("Table");
481
std::string value("Create Table");
483
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
484
my_field->is_autogenerated_name= false;
485
my_field->set_name(key.c_str(), key.length(), system_charset_info);
487
if (session->add_item_to_list(my_field))
490
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
491
my_field->is_autogenerated_name= false;
492
my_field->set_name(value.c_str(), value.length(), system_charset_info);
494
if (session->add_item_to_list(my_field))
500
bool buildProcesslist(Session *session)
502
session->getLex()->sql_command= SQLCOM_SELECT;
503
session->getLex()->statement= new statement::Show(session);
505
if (prepare_new_schema_table(session, session->getLex(), "PROCESSLIST"))
508
if (session->add_item_to_list( new Item_field(&session->lex->current_select->context, NULL, NULL, "*")))
511
(session->lex->current_select->with_wild)++;
516
bool buildVariables(Session *session, const drizzled::sql_var_t is_global)
518
session->getLex()->sql_command= SQLCOM_SELECT;
519
session->getLex()->statement= new statement::Show(session);
521
if (is_global == OPT_GLOBAL)
523
if (prepare_new_schema_table(session, session->getLex(), "GLOBAL_VARIABLES"))
528
if (prepare_new_schema_table(session, session->getLex(), "SESSION_VARIABLES"))
532
std::string key("Variable_name");
533
std::string value("Value");
535
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
536
my_field->is_autogenerated_name= false;
537
my_field->set_name(key.c_str(), key.length(), system_charset_info);
539
if (session->add_item_to_list(my_field))
542
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
543
my_field->is_autogenerated_name= false;
544
my_field->set_name(value.c_str(), value.length(), system_charset_info);
546
if (session->add_item_to_list(my_field))
552
bool buildCreateSchema(Session *session, LEX_STRING &ident)
554
session->getLex()->sql_command= SQLCOM_SELECT;
555
drizzled::statement::Show *select= new statement::Show(session);
556
session->getLex()->statement= select;
558
if (prepare_new_schema_table(session, session->getLex(), "SCHEMA_SQL_DEFINITION"))
561
util::string::const_shared_ptr schema(session->schema());
564
select->setShowPredicate(ident.str);
568
select->setShowPredicate(*schema);
572
my_error(ER_NO_DB_ERROR, MYF(0));
576
std::string key("Database");
577
std::string value("Create Database");
579
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
580
my_field->is_autogenerated_name= false;
581
my_field->set_name(key.c_str(), key.length(), system_charset_info);
583
if (session->add_item_to_list(my_field))
586
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
587
my_field->is_autogenerated_name= false;
588
my_field->set_name(value.c_str(), value.length(), system_charset_info);
590
if (session->add_item_to_list(my_field))
596
bool buildDescribe(Session *session, Table_ident *ident)
598
session->getLex()->lock_option= TL_READ;
599
init_select(session->getLex());
600
session->getLex()->current_select->parsing_place= SELECT_LIST;
601
session->getLex()->sql_command= SQLCOM_SELECT;
602
drizzled::statement::Show *select= new statement::Show(session);
603
session->getLex()->statement= select;
604
session->getLex()->select_lex.db= 0;
606
util::string::const_shared_ptr schema(session->schema());
609
select->setShowPredicate(ident->db.str, ident->table.str);
613
select->setShowPredicate(*schema, ident->table.str);
617
my_error(ER_NO_DB_ERROR, MYF(0));
622
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), ident->table.str);
623
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
625
my_error(ER_NO_SUCH_TABLE, MYF(0),
626
select->getShowSchema().c_str(),
631
if (prepare_new_schema_table(session, session->getLex(), "SHOW_COLUMNS"))
636
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
643
(session->lex->current_select->with_wild)++;
648
} /* namespace drizzled */
146
650
} /* namespace drizzled */