102
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(),(uint32_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())
106
262
Get the quote character for displaying an identifier.
132
bool buildScemas(Session *session)
134
session->getLex()->sql_command= SQLCOM_SELECT;
135
session->getLex()->statement= new statement::Show(session);
137
std::string column_name= "Database";
138
if (session->getLex()->wild)
140
column_name.append(" (");
141
column_name.append(session->getLex()->wild->ptr());
142
column_name.append(")");
145
if (session->getLex()->current_select->where)
147
if (prepare_new_schema_table(session, session->getLex(), "SCHEMAS"))
152
if (prepare_new_schema_table(session, session->getLex(), "SHOW_SCHEMAS"))
156
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
157
my_field->is_autogenerated_name= false;
158
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
160
if (session->add_item_to_list(my_field))
163
if (session->add_order_to_list(my_field, true))
169
bool buildTables(Session *session, const char *ident)
171
session->getLex()->sql_command= SQLCOM_SELECT;
173
drizzled::statement::Show *select= new statement::Show(session);
174
session->getLex()->statement= select;
176
std::string column_name= "Tables_in_";
178
util::string::const_shared_ptr schema(session->schema());
181
identifier::Schema identifier(ident);
182
column_name.append(ident);
183
session->getLex()->select_lex.db= const_cast<char *>(ident);
184
if (not plugin::StorageEngine::doesSchemaExist(identifier))
186
my_error(ER_BAD_DB_ERROR, MYF(0), ident);
188
select->setShowPredicate(ident, "");
190
else if (schema and not schema->empty())
192
column_name.append(*schema);
193
select->setShowPredicate(*schema, "");
197
my_error(ER_NO_DB_ERROR, MYF(0));
202
if (session->getLex()->wild)
204
column_name.append(" (");
205
column_name.append(session->getLex()->wild->ptr());
206
column_name.append(")");
209
if (prepare_new_schema_table(session, session->getLex(), "SHOW_TABLES"))
212
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
213
my_field->is_autogenerated_name= false;
214
my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
216
if (session->add_item_to_list(my_field))
219
if (session->add_order_to_list(my_field, true))
225
bool buildTemporaryTables(Session *session)
227
session->getLex()->sql_command= SQLCOM_SELECT;
229
session->getLex()->statement= new statement::Show(session);
232
if (prepare_new_schema_table(session, session->getLex(), "SHOW_TEMPORARY_TABLES"))
235
if (session->add_item_to_list( new Item_field(&session->lex->current_select->context, NULL, NULL, "*")))
238
(session->lex->current_select->with_wild)++;
243
bool buildTableStatus(Session *session, const char *ident)
245
session->getLex()->sql_command= SQLCOM_SELECT;
246
drizzled::statement::Show *select= new statement::Show(session);
247
session->getLex()->statement= select;
249
std::string column_name= "Tables_in_";
251
util::string::const_shared_ptr schema(session->schema());
254
session->getLex()->select_lex.db= const_cast<char *>(ident);
256
identifier::Schema identifier(ident);
257
if (not plugin::StorageEngine::doesSchemaExist(identifier))
259
my_error(ER_BAD_DB_ERROR, MYF(0), ident);
262
select->setShowPredicate(ident, "");
266
select->setShowPredicate(*schema, "");
270
my_error(ER_NO_DB_ERROR, MYF(0));
274
if (prepare_new_schema_table(session, session->getLex(), "SHOW_TABLE_STATUS"))
277
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
282
(session->lex->current_select->with_wild)++;
287
bool buildEngineStatus(Session *session, LEX_STRING)
289
session->getLex()->sql_command= SQLCOM_SELECT;
290
drizzled::statement::Show *select= new statement::Show(session);
291
session->getLex()->statement= select;
293
my_error(ER_USE_DATA_DICTIONARY);
297
bool buildColumns(Session *session, const char *schema_ident, Table_ident *table_ident)
299
session->getLex()->sql_command= SQLCOM_SELECT;
301
drizzled::statement::Show *select= new statement::Show(session);
302
session->getLex()->statement= select;
304
util::string::const_shared_ptr schema(session->schema());
307
select->setShowPredicate(schema_ident, table_ident->table.str);
309
else if (table_ident->db.str)
311
select->setShowPredicate(table_ident->db.str, table_ident->table.str);
315
select->setShowPredicate(*schema, table_ident->table.str);
319
my_error(ER_NO_DB_ERROR, MYF(0));
324
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), table_ident->table.str);
325
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
327
my_error(ER_TABLE_UNKNOWN, identifier);
331
if (prepare_new_schema_table(session, session->getLex(), "SHOW_COLUMNS"))
334
if (session->add_item_to_list( new Item_field(&session->lex->current_select->context, NULL, NULL, "*")))
337
(session->lex->current_select->with_wild)++;
342
void buildSelectWarning(Session *session)
344
(void) create_select_for_variable(session, "warning_count");
345
session->getLex()->statement= new statement::Show(session);
348
void buildSelectError(Session *session)
350
(void) create_select_for_variable(session, "error_count");
351
session->getLex()->statement= new statement::Show(session);
354
void buildWarnings(Session *session)
356
session->getLex()->statement= new statement::ShowWarnings(session);
359
void buildErrors(Session *session)
361
session->getLex()->statement= new statement::ShowErrors(session);
364
bool buildIndex(Session *session, const char *schema_ident, Table_ident *table_ident)
366
session->getLex()->sql_command= SQLCOM_SELECT;
367
drizzled::statement::Show *select= new statement::Show(session);
368
session->getLex()->statement= select;
370
util::string::const_shared_ptr schema(session->schema());
373
select->setShowPredicate(schema_ident, table_ident->table.str);
375
else if (table_ident->db.str)
377
select->setShowPredicate(table_ident->db.str, table_ident->table.str);
381
select->setShowPredicate(*schema, table_ident->table.str);
385
my_error(ER_NO_DB_ERROR, MYF(0));
390
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), table_ident->table.str);
391
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
393
my_error(ER_TABLE_UNKNOWN, identifier);
397
if (prepare_new_schema_table(session, session->getLex(), "SHOW_INDEXES"))
400
if (session->add_item_to_list( new Item_field(&session->lex->current_select->context, NULL, NULL, "*")))
403
(session->lex->current_select->with_wild)++;
408
bool buildStatus(Session *session, const drizzled::sql_var_t is_global)
410
session->getLex()->sql_command= SQLCOM_SELECT;
411
session->getLex()->statement= new statement::Show(session);
413
if (is_global == OPT_GLOBAL)
415
if (prepare_new_schema_table(session, session->getLex(), "GLOBAL_STATUS"))
420
if (prepare_new_schema_table(session, session->getLex(), "SESSION_STATUS"))
424
std::string key("Variable_name");
425
std::string value("Value");
427
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
428
my_field->is_autogenerated_name= false;
429
my_field->set_name(key.c_str(), key.length(), system_charset_info);
431
if (session->add_item_to_list(my_field))
434
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
435
my_field->is_autogenerated_name= false;
436
my_field->set_name(value.c_str(), value.length(), system_charset_info);
438
if (session->add_item_to_list(my_field))
444
bool buildCreateTable(Session *session, Table_ident *ident)
446
session->getLex()->sql_command= SQLCOM_SELECT;
447
statement::Show *select= new statement::Show(session);
448
session->getLex()->statement= select;
450
if (session->getLex()->statement == NULL)
453
if (prepare_new_schema_table(session, session->getLex(), "TABLE_SQL_DEFINITION"))
456
util::string::const_shared_ptr schema(session->schema());
459
select->setShowPredicate(ident->db.str, ident->table.str);
463
select->setShowPredicate(*schema, ident->table.str);
467
my_error(ER_NO_DB_ERROR, MYF(0));
471
std::string key("Table");
472
std::string value("Create Table");
474
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
475
my_field->is_autogenerated_name= false;
476
my_field->set_name(key.c_str(), key.length(), system_charset_info);
478
if (session->add_item_to_list(my_field))
481
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_SQL_DEFINITION");
482
my_field->is_autogenerated_name= false;
483
my_field->set_name(value.c_str(), value.length(), system_charset_info);
485
if (session->add_item_to_list(my_field))
491
bool buildProcesslist(Session *session)
493
session->getLex()->sql_command= SQLCOM_SELECT;
494
session->getLex()->statement= new statement::Show(session);
496
if (prepare_new_schema_table(session, session->getLex(), "PROCESSLIST"))
499
if (session->add_item_to_list( new Item_field(&session->lex->current_select->context, NULL, NULL, "*")))
502
(session->lex->current_select->with_wild)++;
507
bool buildVariables(Session *session, const drizzled::sql_var_t is_global)
509
session->getLex()->sql_command= SQLCOM_SELECT;
510
session->getLex()->statement= new statement::Show(session);
512
if (is_global == OPT_GLOBAL)
514
if (prepare_new_schema_table(session, session->getLex(), "GLOBAL_VARIABLES"))
519
if (prepare_new_schema_table(session, session->getLex(), "SESSION_VARIABLES"))
523
std::string key("Variable_name");
524
std::string value("Value");
526
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_NAME");
527
my_field->is_autogenerated_name= false;
528
my_field->set_name(key.c_str(), key.length(), system_charset_info);
530
if (session->add_item_to_list(my_field))
533
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "VARIABLE_VALUE");
534
my_field->is_autogenerated_name= false;
535
my_field->set_name(value.c_str(), value.length(), system_charset_info);
537
if (session->add_item_to_list(my_field))
543
bool buildCreateSchema(Session *session, LEX_STRING &ident)
545
session->getLex()->sql_command= SQLCOM_SELECT;
546
drizzled::statement::Show *select= new statement::Show(session);
547
session->getLex()->statement= select;
549
if (prepare_new_schema_table(session, session->getLex(), "SCHEMA_SQL_DEFINITION"))
552
util::string::const_shared_ptr schema(session->schema());
555
select->setShowPredicate(ident.str);
559
select->setShowPredicate(*schema);
563
my_error(ER_NO_DB_ERROR, MYF(0));
567
std::string key("Database");
568
std::string value("Create Database");
570
Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_NAME");
571
my_field->is_autogenerated_name= false;
572
my_field->set_name(key.c_str(), key.length(), system_charset_info);
574
if (session->add_item_to_list(my_field))
577
my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "SCHEMA_SQL_DEFINITION");
578
my_field->is_autogenerated_name= false;
579
my_field->set_name(value.c_str(), value.length(), system_charset_info);
581
if (session->add_item_to_list(my_field))
587
bool buildDescribe(Session *session, Table_ident *ident)
589
session->getLex()->lock_option= TL_READ;
590
init_select(session->getLex());
591
session->getLex()->current_select->parsing_place= SELECT_LIST;
592
session->getLex()->sql_command= SQLCOM_SELECT;
593
drizzled::statement::Show *select= new statement::Show(session);
594
session->getLex()->statement= select;
595
session->getLex()->select_lex.db= 0;
597
util::string::const_shared_ptr schema(session->schema());
600
select->setShowPredicate(ident->db.str, ident->table.str);
604
select->setShowPredicate(*schema, ident->table.str);
608
my_error(ER_NO_DB_ERROR, MYF(0));
613
drizzled::identifier::Table identifier(select->getShowSchema().c_str(), ident->table.str);
614
if (not plugin::StorageEngine::doesTableExist(*session, identifier))
616
my_error(ER_TABLE_UNKNOWN, identifier);
620
if (prepare_new_schema_table(session, session->getLex(), "SHOW_COLUMNS"))
625
if (session->add_item_to_list( new Item_field(&session->lex->current_select->
632
(session->lex->current_select->with_wild)++;
637
} /* 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)
639
362
} /* namespace drizzled */