112
118
return (*str != '\0');
122
bool drizzled_show_create(Session *session, TableList *table_list, bool is_if_not_exists)
125
String buffer(buff, sizeof(buff), system_charset_info);
127
/* Only one table for now, but VIEW can involve several tables */
128
if (session->openTables(table_list))
130
if (session->is_error())
134
Clear all messages with 'error' level status and
135
issue a warning with 'warning' level status in
136
case of invalid view and last error is ER_VIEW_INVALID
138
drizzle_reset_errors(session, true);
139
session->clear_error();
144
if (store_create_info(table_list, &buffer, is_if_not_exists))
147
List<Item> field_list;
149
field_list.push_back(new Item_empty_string("Table",NAME_CHAR_LEN));
150
// 1024 is for not to confuse old clients
151
field_list.push_back(new Item_empty_string("Create Table",
152
max(buffer.length(),(size_t)1024)));
155
if (session->client->sendFields(&field_list))
158
session->client->store(table_list->table->getAlias());
161
session->client->store(buffer.ptr(), buffer.length());
163
if (session->client->flush())
171
Get a CREATE statement for a given database.
173
The database is identified by its name, passed as @c dbname parameter.
174
The name should be encoded using the system character set (UTF8 currently).
176
Resulting statement is stored in the string pointed by @c buffer. The string
177
is emptied first and its character set is set to the system character set.
179
If is_if_not_exists is set, then
180
the resulting CREATE statement contains "IF NOT EXISTS" clause. Other flags
181
in @c create_options are ignored.
183
@param session The current thread instance.
184
@param dbname The name of the database.
185
@param buffer A String instance where the statement is stored.
186
@param create_info If not NULL, the options member influences the resulting
189
@returns true if errors are detected, false otherwise.
192
static bool store_db_create_info(SchemaIdentifier &schema_identifier, string &buffer, bool if_not_exists)
194
message::Schema schema;
196
bool found= plugin::StorageEngine::getSchemaDefinition(schema_identifier, schema);
200
buffer.append("CREATE DATABASE ");
203
buffer.append("IF NOT EXISTS ");
206
buffer.append(schema.name());
209
if (schema.has_collation())
211
buffer.append(" COLLATE = ");
212
buffer.append(schema.collation());
218
bool mysqld_show_create_db(Session &session, SchemaIdentifier &schema_identifier, bool if_not_exists)
220
message::Schema schema_message;
223
if (not plugin::StorageEngine::getSchemaDefinition(schema_identifier, schema_message))
226
This assumes that the only reason for which store_db_create_info()
227
can fail is incorrect database name (which is the case now).
229
my_error(ER_BAD_DB_ERROR, MYF(0), schema_identifier.getSQLPath().c_str());
233
if (not store_db_create_info(schema_identifier, buffer, if_not_exists))
236
This assumes that the only reason for which store_db_create_info()
237
can fail is incorrect database name (which is the case now).
239
my_error(ER_BAD_DB_ERROR, MYF(0), schema_identifier.getSQLPath().c_str());
243
List<Item> field_list;
244
field_list.push_back(new Item_empty_string("Database",NAME_CHAR_LEN));
245
field_list.push_back(new Item_empty_string("Create Database",1024));
247
if (session.client->sendFields(&field_list))
250
session.client->store(schema_message.name());
251
session.client->store(buffer);
253
if (session.client->flush())
116
262
Get the quote character for displaying an identifier.
142
bool buildScemas(Session *session)
144
session->getLex()->sql_command= SQLCOM_SELECT;
145
session->getLex()->statement= new statement::Show(session);
147
std::string column_name= "Database";
148
if (session->getLex()->wild)
150
column_name.append(" (");
151
column_name.append(session->getLex()->wild->ptr());
152
column_name.append(")");
155
if (session->getLex()->current_select->where)
157
if (prepare_new_schema_table(session, session->getLex(), "SCHEMAS"))
162
if (prepare_new_schema_table(session, session->getLex(), "SHOW_SCHEMAS"))
166
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "SCHEMA_NAME");
167
my_field->is_autogenerated_name= false;
168
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
170
if (session->add_item_to_list(my_field))
173
if (session->add_order_to_list(my_field, true))
179
bool buildTables(Session *session, const char *ident)
181
session->getLex()->sql_command= SQLCOM_SELECT;
183
drizzled::statement::Show *select= new statement::Show(session);
184
session->getLex()->statement= select;
186
std::string column_name= "Tables_in_";
188
util::string::const_shared_ptr schema(session->schema());
191
identifier::Schema identifier(ident);
192
column_name.append(ident);
193
session->getLex()->select_lex.db= const_cast<char *>(ident);
194
if (not plugin::StorageEngine::doesSchemaExist(identifier))
196
my_error(ER_BAD_DB_ERROR, identifier);
198
select->setShowPredicate(ident, "");
200
else if (schema and not schema->empty())
202
column_name.append(*schema);
203
select->setShowPredicate(*schema, "");
207
my_error(ER_NO_DB_ERROR, MYF(0));
212
if (session->getLex()->wild)
214
column_name.append(" (");
215
column_name.append(session->getLex()->wild->ptr());
216
column_name.append(")");
219
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");
223
my_field->is_autogenerated_name= false;
224
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
226
if (session->add_item_to_list(my_field))
229
if (session->add_order_to_list(my_field, true))
235
bool buildTemporaryTables(Session *session)
237
session->getLex()->sql_command= SQLCOM_SELECT;
239
session->getLex()->statement= new statement::Show(session);
242
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, "*")))
248
(session->getLex()->current_select->with_wild)++;
253
bool buildTableStatus(Session *session, const char *ident)
255
session->getLex()->sql_command= SQLCOM_SELECT;
256
drizzled::statement::Show *select= new statement::Show(session);
257
session->getLex()->statement= select;
259
std::string column_name= "Tables_in_";
261
util::string::const_shared_ptr schema(session->schema());
264
session->getLex()->select_lex.db= const_cast<char *>(ident);
266
identifier::Schema identifier(ident);
267
if (not plugin::StorageEngine::doesSchemaExist(identifier))
269
my_error(ER_BAD_DB_ERROR, identifier);
272
select->setShowPredicate(ident, "");
276
select->setShowPredicate(*schema, "");
280
my_error(ER_NO_DB_ERROR, MYF(0));
284
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->
292
(session->getLex()->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
bool buildColumns(Session *session, const char *schema_ident, Table_ident *table_ident)
309
session->getLex()->sql_command= SQLCOM_SELECT;
311
drizzled::statement::Show *select= new statement::Show(session);
312
session->getLex()->statement= select;
314
util::string::const_shared_ptr schema(session->schema());
317
select->setShowPredicate(schema_ident, table_ident->table.str);
319
else if (table_ident->db.str)
321
select->setShowPredicate(table_ident->db.str, table_ident->table.str);
325
select->setShowPredicate(*schema, table_ident->table.str);
329
my_error(ER_NO_DB_ERROR, MYF(0));
334
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), table_ident->table.str);
335
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
337
my_error(ER_TABLE_UNKNOWN, identifier);
341
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
(session->getLex()->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)
366
session->getLex()->statement= new statement::ShowWarnings(session);
369
void buildErrors(Session *session)
371
session->getLex()->statement= new statement::ShowErrors(session);
374
bool buildIndex(Session *session, const char *schema_ident, Table_ident *table_ident)
376
session->getLex()->sql_command= SQLCOM_SELECT;
377
drizzled::statement::Show *select= new statement::Show(session);
378
session->getLex()->statement= select;
380
util::string::const_shared_ptr schema(session->schema());
383
select->setShowPredicate(schema_ident, table_ident->table.str);
385
else if (table_ident->db.str)
387
select->setShowPredicate(table_ident->db.str, table_ident->table.str);
391
select->setShowPredicate(*schema, table_ident->table.str);
395
my_error(ER_NO_DB_ERROR, MYF(0));
400
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), table_ident->table.str);
401
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
403
my_error(ER_TABLE_UNKNOWN, identifier);
407
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, "*")))
413
(session->getLex()->current_select->with_wild)++;
418
bool buildStatus(Session *session, const drizzled::sql_var_t is_global)
420
session->getLex()->sql_command= SQLCOM_SELECT;
421
session->getLex()->statement= new statement::Show(session);
423
if (is_global == OPT_GLOBAL)
425
if (prepare_new_schema_table(session, session->getLex(), "GLOBAL_STATUS"))
430
if (prepare_new_schema_table(session, session->getLex(), "SESSION_STATUS"))
434
std::string key("Variable_name");
435
std::string value("Value");
437
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_NAME");
438
my_field->is_autogenerated_name= false;
439
my_field->set_name(key.c_str(), key.length(), system_charset_info);
441
if (session->add_item_to_list(my_field))
444
my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_VALUE");
445
my_field->is_autogenerated_name= false;
446
my_field->set_name(value.c_str(), value.length(), system_charset_info);
448
if (session->add_item_to_list(my_field))
454
bool buildCreateTable(Session *session, Table_ident *ident)
456
session->getLex()->sql_command= SQLCOM_SELECT;
457
statement::Show *select= new statement::Show(session);
458
session->getLex()->statement= select;
460
if (session->getLex()->statement == NULL)
463
if (prepare_new_schema_table(session, session->getLex(), "TABLE_SQL_DEFINITION"))
466
util::string::const_shared_ptr schema(session->schema());
469
select->setShowPredicate(ident->db.str, ident->table.str);
473
select->setShowPredicate(*schema, ident->table.str);
477
my_error(ER_NO_DB_ERROR, MYF(0));
481
std::string key("Table");
482
std::string value("Create Table");
484
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "TABLE_NAME");
485
my_field->is_autogenerated_name= false;
486
my_field->set_name(key.c_str(), key.length(), system_charset_info);
488
if (session->add_item_to_list(my_field))
491
my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
492
my_field->is_autogenerated_name= false;
493
my_field->set_name(value.c_str(), value.length(), system_charset_info);
495
if (session->add_item_to_list(my_field))
501
bool buildProcesslist(Session *session)
503
session->getLex()->sql_command= SQLCOM_SELECT;
504
session->getLex()->statement= new statement::Show(session);
506
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, "*")))
512
(session->getLex()->current_select->with_wild)++;
517
bool buildVariables(Session *session, const drizzled::sql_var_t is_global)
519
session->getLex()->sql_command= SQLCOM_SELECT;
520
session->getLex()->statement= new statement::Show(session);
522
if (is_global == OPT_GLOBAL)
524
if (prepare_new_schema_table(session, session->getLex(), "GLOBAL_VARIABLES"))
529
if (prepare_new_schema_table(session, session->getLex(), "SESSION_VARIABLES"))
533
std::string key("Variable_name");
534
std::string value("Value");
536
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_NAME");
537
my_field->is_autogenerated_name= false;
538
my_field->set_name(key.c_str(), key.length(), system_charset_info);
540
if (session->add_item_to_list(my_field))
543
my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "VARIABLE_VALUE");
544
my_field->is_autogenerated_name= false;
545
my_field->set_name(value.c_str(), value.length(), system_charset_info);
547
if (session->add_item_to_list(my_field))
553
bool buildCreateSchema(Session *session, LEX_STRING &ident)
555
session->getLex()->sql_command= SQLCOM_SELECT;
556
drizzled::statement::Show *select= new statement::Show(session);
557
session->getLex()->statement= select;
559
if (prepare_new_schema_table(session, session->getLex(), "SCHEMA_SQL_DEFINITION"))
562
util::string::const_shared_ptr schema(session->schema());
565
select->setShowPredicate(ident.str);
569
select->setShowPredicate(*schema);
573
my_error(ER_NO_DB_ERROR, MYF(0));
577
std::string key("Database");
578
std::string value("Create Database");
580
Item_field *my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "SCHEMA_NAME");
581
my_field->is_autogenerated_name= false;
582
my_field->set_name(key.c_str(), key.length(), system_charset_info);
584
if (session->add_item_to_list(my_field))
587
my_field= new Item_field(&session->getLex()->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
588
my_field->is_autogenerated_name= false;
589
my_field->set_name(value.c_str(), value.length(), system_charset_info);
591
if (session->add_item_to_list(my_field))
597
bool buildDescribe(Session *session, Table_ident *ident)
599
session->getLex()->lock_option= TL_READ;
600
init_select(session->getLex());
601
session->getLex()->current_select->parsing_place= SELECT_LIST;
602
session->getLex()->sql_command= SQLCOM_SELECT;
603
drizzled::statement::Show *select= new statement::Show(session);
604
session->getLex()->statement= select;
605
session->getLex()->select_lex.db= 0;
607
util::string::const_shared_ptr schema(session->schema());
610
select->setShowPredicate(ident->db.str, ident->table.str);
614
select->setShowPredicate(*schema, ident->table.str);
618
my_error(ER_NO_DB_ERROR, MYF(0));
623
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), ident->table.str);
624
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
626
my_error(ER_TABLE_UNKNOWN, identifier);
630
if (prepare_new_schema_table(session, session->getLex(), "SHOW_COLUMNS"))
635
if (session->add_item_to_list( new Item_field(&session->getLex()->current_select->
642
(session->getLex()->current_select->with_wild)++;
647
} /* namespace drizzled */
287
#define LIST_PROCESS_HOST_LEN 64
290
Build a CREATE TABLE statement for a table.
294
table_list A list containing one table to write statement
296
packet Pointer to a string where statement will be
300
Currently always return 0, but might return error code in the
307
int store_create_info(TableList *table_list, String *packet, bool is_if_not_exists)
309
Table *table= table_list->table;
311
table->restoreRecordAsDefault(); // Get empty record
315
enum drizzled::message::TransformSqlError transform_err;
317
(void)is_if_not_exists;
319
transform_err= message::transformTableDefinitionToSql(*(table->getShare()->getTableProto()),
324
packet->append(create_sql.c_str(), create_sql.length(), default_charset_info);
329
/****************************************************************************
330
Return info about all processes
331
returns for each thread: thread id, user, host, db, command, info
332
****************************************************************************/
347
thread_info(uint64_t thread_id_arg,
348
time_t start_time_arg,
349
uint32_t command_arg,
350
const string &user_arg,
351
const string &host_arg,
352
const string &db_arg,
353
const string &proc_info_arg,
354
const string &state_info_arg,
355
const string &query_arg)
356
: thread_id(thread_id_arg), start_time(start_time_arg), command(command_arg),
357
user(user_arg), host(host_arg), db(db_arg), proc_info(proc_info_arg),
358
state_info(state_info_arg), query(query_arg)
649
362
} /* namespace drizzled */