285
bool mysqld_show_create_db(Session *session, char *dbname,
286
HA_CREATE_INFO *create_info)
287
Get a CREATE statement for a given database.
289
The database is identified by its name, passed as @c dbname parameter.
290
The name should be encoded using the system character set (UTF8 currently).
292
Resulting statement is stored in the string pointed by @c buffer. The string
293
is emptied first and its character set is set to the system character set.
295
If HA_LEX_CREATE_IF_NOT_EXISTS flag is set in @c create_info->options, then
296
the resulting CREATE statement contains "IF NOT EXISTS" clause. Other flags
297
in @c create_options are ignored.
299
@param session The current thread instance.
300
@param dbname The name of the database.
301
@param buffer A String instance where the statement is stored.
302
@param create_info If not NULL, the options member influences the resulting
305
@returns true if errors are detected, false otherwise.
308
static bool store_db_create_info(const char *dbname, String *buffer, bool if_not_exists)
310
drizzled::message::Schema schema;
312
if (!my_strcasecmp(system_charset_info, dbname,
313
INFORMATION_SCHEMA_NAME.c_str()))
315
dbname= INFORMATION_SCHEMA_NAME.c_str();
319
int r= get_database_metadata(dbname, &schema);
326
buffer->set_charset(system_charset_info);
327
buffer->append(STRING_WITH_LEN("CREATE DATABASE "));
330
buffer->append(STRING_WITH_LEN("IF NOT EXISTS "));
332
buffer->append_identifier(dbname, strlen(dbname));
334
if (schema.has_collation() && strcmp(schema.collation().c_str(),
335
default_charset_info->name))
337
buffer->append(" COLLATE = ");
338
buffer->append(schema.collation().c_str());
344
bool mysqld_show_create_db(Session *session, char *dbname, bool if_not_exists)
289
347
String buffer(buff, sizeof(buff), system_charset_info);
290
348
Protocol *protocol=session->protocol;
292
if (store_db_create_info(dbname, &buffer, create_info))
350
if (store_db_create_info(dbname, &buffer, if_not_exists))
295
353
This assumes that the only reason for which store_db_create_info()
772
Get a CREATE statement for a given database.
774
The database is identified by its name, passed as @c dbname parameter.
775
The name should be encoded using the system character set (UTF8 currently).
777
Resulting statement is stored in the string pointed by @c buffer. The string
778
is emptied first and its character set is set to the system character set.
780
If HA_LEX_CREATE_IF_NOT_EXISTS flag is set in @c create_info->options, then
781
the resulting CREATE statement contains "IF NOT EXISTS" clause. Other flags
782
in @c create_options are ignored.
784
@param session The current thread instance.
785
@param dbname The name of the database.
786
@param buffer A String instance where the statement is stored.
787
@param create_info If not NULL, the options member influences the resulting
790
@returns true if errors are detected, false otherwise.
793
bool store_db_create_info(const char *dbname, String *buffer, HA_CREATE_INFO *create_info)
795
HA_CREATE_INFO create;
796
uint32_t create_options = create_info ? create_info->options : 0;
798
if (!my_strcasecmp(system_charset_info, dbname,
799
INFORMATION_SCHEMA_NAME.c_str()))
801
dbname= INFORMATION_SCHEMA_NAME.c_str();
802
create.default_table_charset= system_charset_info;
806
if (check_db_dir_existence(dbname))
809
load_db_opt_by_name(dbname, &create);
814
buffer->set_charset(system_charset_info);
815
buffer->append(STRING_WITH_LEN("CREATE DATABASE "));
817
if (create_options & HA_LEX_CREATE_IF_NOT_EXISTS)
818
buffer->append(STRING_WITH_LEN("IF NOT EXISTS "));
820
buffer->append_identifier(dbname, strlen(dbname));
825
829
static void store_key_options(String *packet, Table *table, KEY *key_info)
827
831
char *end, buff[32];