Commit 92eed38c authored by Sergei Petrunia's avatar Sergei Petrunia

Provide a show_create_table_ex() function

It is like show_create_table() but allows the caller to specify the
database_name and table_name which are to be printed.
parent cbbe4971
......@@ -1976,6 +1976,14 @@ static void append_period(THD *thd, String *packet, const LEX_CSTRING &start,
packet->append(STRING_WITH_LEN(")"));
}
int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
Table_specification_st *create_info_arg,
enum_with_db_name with_db_name)
{
return show_create_table_ex(thd, table_list, NULL, NULL, packet,
create_info_arg, with_db_name);
}
/*
Build a CREATE TABLE statement for a table.
......@@ -1984,6 +1992,11 @@ static void append_period(THD *thd, String *packet, const LEX_CSTRING &start,
thd The thread
table_list A list containing one table to write statement
for.
force_db If not NULL, database name to use in the CREATE
TABLE statement.
force_name If not NULL, table name to use in the CREATE TABLE
statement. if NULL, the name from table_list will be
used.
packet Pointer to a string where statement will be
written.
create_info_arg Pointer to create information that can be used
......@@ -2000,7 +2013,9 @@ static void append_period(THD *thd, String *packet, const LEX_CSTRING &start,
0 OK
*/
int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
int show_create_table_ex(THD *thd, TABLE_LIST *table_list,
const char *force_db, const char *force_name,
String *packet,
Table_specification_st *create_info_arg,
enum_with_db_name with_db_name)
{
......@@ -2052,6 +2067,18 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
packet->append(STRING_WITH_LEN("TABLE "));
if (create_info_arg && create_info_arg->if_not_exists())
packet->append(STRING_WITH_LEN("IF NOT EXISTS "));
if (force_name)
{
if (force_db)
{
append_identifier(thd, packet, force_db, strlen(force_db));
packet->append(STRING_WITH_LEN("."));
}
append_identifier(thd, packet, force_name, strlen(force_name));
}
else
{
if (table_list->schema_table)
{
alias.str= table_list->schema_table->table_name;
......@@ -2087,6 +2114,8 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
}
append_identifier(thd, packet, &alias);
}
packet->append(STRING_WITH_LEN(" (\n"));
/*
We need this to get default values from the table
......
......@@ -83,6 +83,12 @@ int show_create_table(THD *thd, TABLE_LIST *table_list, String *packet,
Table_specification_st *create_info_arg,
enum_with_db_name with_db_name);
int show_create_table_ex(THD *thd, TABLE_LIST *table_list,
const char * forced_db, const char *forced_name,
String *packet,
Table_specification_st *create_info_arg,
enum_with_db_name with_db_name);
int copy_event_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table);
bool append_identifier(THD *thd, String *packet, const char *name, size_t length);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment