22
22
/* Function with list databases, tables or fields */
24
#include <drizzled/sql_select.h>
25
#include <drizzled/show.h>
26
#include <drizzled/gettext.h>
27
#include <drizzled/util/convert.h>
28
#include <drizzled/error.h>
29
#include <drizzled/tztime.h>
25
30
#include <drizzled/data_home.h>
26
#include <drizzled/error.h>
27
#include <drizzled/internal/my_sys.h>
28
#include <drizzled/plugin/storage_engine.h>
29
#include <drizzled/session.h>
30
#include <drizzled/show.h>
31
#include <drizzled/sql_select.h>
31
#include <drizzled/item/blob.h>
32
#include <drizzled/item/cmpfunc.h>
33
#include <drizzled/item/return_int.h>
34
#include <drizzled/item/empty_string.h>
35
#include <drizzled/item/return_date_time.h>
36
#include <drizzled/sql_base.h>
37
#include <drizzled/db.h>
38
#include <drizzled/field/epoch.h>
39
#include <drizzled/field/decimal.h>
40
#include <drizzled/lock.h>
41
#include <drizzled/item/return_date_time.h>
42
#include <drizzled/item/empty_string.h>
43
#include "drizzled/session/cache.h"
44
#include <drizzled/message/schema.pb.h>
45
#include <drizzled/plugin/client.h>
46
#include <drizzled/cached_directory.h>
47
#include "drizzled/sql_table.h"
48
#include "drizzled/global_charset_info.h"
49
#include "drizzled/pthread_globals.h"
50
#include "drizzled/internal/m_string.h"
51
#include "drizzled/internal/my_sys.h"
52
#include "drizzled/message/statement_transform.h"
33
#include <drizzled/statement/show.h>
34
#include <drizzled/statement/show_errors.h>
35
#include <drizzled/statement/show_warnings.h>
54
#include "drizzled/statement/show.h"
55
#include "drizzled/statement/show_errors.h"
56
#include "drizzled/statement/show_warnings.h"
38
59
#include <sys/stat.h>
54
75
return str ? str : "<nil>";
57
int wild_case_compare(const charset_info_st * const cs, const char *str, const char *wildstr)
78
int wild_case_compare(const CHARSET_INFO * const cs, const char *str, const char *wildstr)
91
108
if ((cmp= *wildstr) == internal::wild_prefix && wildstr[1])
94
110
cmp= my_toupper(cs, cmp);
96
111
while (*str && my_toupper(cs, *str) != cmp)
103
116
if (wild_case_compare(cs, str, wildstr) == 0)
106
118
} while (*str++);
166
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "SCHEMA_NAME");
177
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
167
178
my_field->is_autogenerated_name= false;
168
179
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
193
204
session->getLex()->select_lex.db= const_cast<char *>(ident);
194
205
if (not plugin::StorageEngine::doesSchemaExist(identifier))
196
my_error(ER_BAD_DB_ERROR, identifier);
207
my_error(ER_BAD_DB_ERROR, MYF(0), ident);
198
209
select->setShowPredicate(ident, "");
219
230
if (prepare_new_schema_table(session, session->getLex(), "SHOW_TABLES"))
222
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "TABLE_NAME");
233
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
223
234
my_field->is_autogenerated_name= false;
224
235
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
242
253
if (prepare_new_schema_table(session, session->getLex(), "SHOW_TEMPORARY_TABLES"))
245
if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->context, NULL, NULL, "*")))
256
if (session->add_item_to_list( new Item_field(&session->lex->current_select->context, NULL, NULL, "*")))
248
(session->getLex()->current_select->with_wild)++;
259
(session->lex->current_select->with_wild)++;
266
277
identifier::Schema identifier(ident);
267
278
if (not plugin::StorageEngine::doesSchemaExist(identifier))
269
my_error(ER_BAD_DB_ERROR, identifier);
280
my_error(ER_BAD_DB_ERROR, MYF(0), ident);
272
283
select->setShowPredicate(ident, "");
284
295
if (prepare_new_schema_table(session, session->getLex(), "SHOW_TABLE_STATUS"))
287
if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->
298
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
289
300
NULL, NULL, "*")))
292
(session->getLex()->current_select->with_wild)++;
303
(session->lex->current_select->with_wild)++;
297
bool buildEngineStatus(Session *session, LEX_STRING)
299
session->getLex()->sql_command= SQLCOM_SELECT;
300
drizzled::statement::Show *select= new statement::Show(session);
301
session->getLex()->statement= select;
303
my_error(ER_USE_DATA_DICTIONARY);
307
308
bool buildColumns(Session *session, const char *schema_ident, Table_ident *table_ident)
309
310
session->getLex()->sql_command= SQLCOM_SELECT;
334
335
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), table_ident->table.str);
335
336
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
337
my_error(ER_TABLE_UNKNOWN, identifier);
338
my_error(ER_NO_SUCH_TABLE, MYF(0),
339
select->getShowSchema().c_str(),
340
table_ident->table.str);
341
344
if (prepare_new_schema_table(session, session->getLex(), "SHOW_COLUMNS"))
344
if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->context, NULL, NULL, "*")))
347
if (session->add_item_to_list( new Item_field(&session->lex->current_select->context, NULL, NULL, "*")))
347
(session->getLex()->current_select->with_wild)++;
350
(session->lex->current_select->with_wild)++;
352
void buildSelectWarning(Session *session)
354
(void) create_select_for_variable(session, "warning_count");
355
session->getLex()->statement= new statement::Show(session);
358
void buildSelectError(Session *session)
360
(void) create_select_for_variable(session, "error_count");
361
session->getLex()->statement= new statement::Show(session);
364
void buildWarnings(Session *session)
355
bool buildWarnings(Session *session)
357
session->getLex()->sql_command = SQLCOM_SHOW_WARNS;
366
358
session->getLex()->statement= new statement::ShowWarnings(session);
369
void buildErrors(Session *session)
363
bool buildErrors(Session *session)
365
session->getLex()->sql_command = SQLCOM_SHOW_ERRORS;
371
366
session->getLex()->statement= new statement::ShowErrors(session);
374
371
bool buildIndex(Session *session, const char *schema_ident, Table_ident *table_ident)
400
397
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), table_ident->table.str);
401
398
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
403
my_error(ER_TABLE_UNKNOWN, identifier);
400
my_error(ER_NO_SUCH_TABLE, MYF(0),
401
select->getShowSchema().c_str(),
402
table_ident->table.str);
407
406
if (prepare_new_schema_table(session, session->getLex(), "SHOW_INDEXES"))
410
if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->context, NULL, NULL, "*")))
409
if (session->add_item_to_list( new Item_field(&session->lex->current_select->context, NULL, NULL, "*")))
413
(session->getLex()->current_select->with_wild)++;
412
(session->lex->current_select->with_wild)++;
434
433
std::string key("Variable_name");
435
434
std::string value("Value");
437
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_NAME");
436
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
438
437
my_field->is_autogenerated_name= false;
439
438
my_field->set_name(key.c_str(), key.length(), system_charset_info);
441
440
if (session->add_item_to_list(my_field))
444
my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_VALUE");
443
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
445
444
my_field->is_autogenerated_name= false;
446
445
my_field->set_name(value.c_str(), value.length(), system_charset_info);
481
480
std::string key("Table");
482
481
std::string value("Create Table");
484
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "TABLE_NAME");
483
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
485
484
my_field->is_autogenerated_name= false;
486
485
my_field->set_name(key.c_str(), key.length(), system_charset_info);
488
487
if (session->add_item_to_list(my_field))
491
my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
490
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
492
491
my_field->is_autogenerated_name= false;
493
492
my_field->set_name(value.c_str(), value.length(), system_charset_info);
506
505
if (prepare_new_schema_table(session, session->getLex(), "PROCESSLIST"))
509
if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->context, NULL, NULL, "*")))
508
if (session->add_item_to_list( new Item_field(&session->lex->current_select->context, NULL, NULL, "*")))
512
(session->getLex()->current_select->with_wild)++;
511
(session->lex->current_select->with_wild)++;
533
532
std::string key("Variable_name");
534
533
std::string value("Value");
536
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_NAME");
535
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
537
536
my_field->is_autogenerated_name= false;
538
537
my_field->set_name(key.c_str(), key.length(), system_charset_info);
540
539
if (session->add_item_to_list(my_field))
543
my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_VALUE");
542
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
544
543
my_field->is_autogenerated_name= false;
545
544
my_field->set_name(value.c_str(), value.length(), system_charset_info);
577
576
std::string key("Database");
578
577
std::string value("Create Database");
580
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "SCHEMA_NAME");
579
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
581
580
my_field->is_autogenerated_name= false;
582
581
my_field->set_name(key.c_str(), key.length(), system_charset_info);
584
583
if (session->add_item_to_list(my_field))
587
my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
586
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
588
587
my_field->is_autogenerated_name= false;
589
588
my_field->set_name(value.c_str(), value.length(), system_charset_info);
623
622
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), ident->table.str);
624
623
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
626
my_error(ER_TABLE_UNKNOWN, identifier);
625
my_error(ER_NO_SUCH_TABLE, MYF(0),
626
select->getShowSchema().c_str(),