Commit 8229d282 authored by bar@bar.mysql.r18.ru's avatar bar@bar.mysql.r18.ru

Extensions to support this:

SHOW CREATE DATABASE [IF NOT EXISTS] dbname

Version dependant parts are displayed in appropriative comments:
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `ucs` /*!40100 DEFAULT CHARACTER SET ucs2*/
parent 52914626
......@@ -1252,7 +1252,7 @@ static int init_dumping(char *database)
MYSQL_ROW row;
MYSQL_RES *dbinfo;
sprintf(qbuf,"SHOW CREATE DATABASE %s",database);
sprintf(qbuf,"SHOW CREATE DATABASE IF NOT EXISTS %s",database);
if (mysql_query(sock, qbuf) || !(dbinfo = mysql_store_result(sock)))
{
......
......@@ -496,7 +496,7 @@ int mysqld_show_logs(THD *thd);
void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild);
int mysqld_dump_create_info(THD *thd, TABLE *table, int fd = -1);
int mysqld_show_create(THD *thd, TABLE_LIST *table_list);
int mysqld_show_create_db(THD *thd, const char *dbname);
int mysqld_show_create_db(THD *thd, const char *dbname, HA_CREATE_INFO *create);
void mysqld_list_processes(THD *thd,const char *user,bool verbose);
int mysqld_show_status(THD *thd);
......
......@@ -597,7 +597,7 @@ bool mysql_change_db(THD *thd, const char *name)
}
int mysqld_show_create_db(THD *thd, const char *dbname)
int mysqld_show_create_db(THD *thd, const char *dbname, HA_CREATE_INFO *create_info)
{
int length;
char path[FN_REFLEN], *to;
......@@ -605,6 +605,8 @@ int mysqld_show_create_db(THD *thd, const char *dbname)
bool found_libchar;
HA_CREATE_INFO create;
CONVERT *convert=thd->variables.convert_set;
uint create_options = create_info ? create_info->options : 0;
DBUG_ENTER("mysql_show_create_db");
if (check_db_name(dbname))
......@@ -660,10 +662,15 @@ int mysqld_show_create_db(THD *thd, const char *dbname)
String *packet = &thd->packet;
packet->length(0);
net_store_data(packet, convert, dbname);
to= strxmov(path, "CREATE DATABASE `", dbname, "`", NullS);
to= strxmov(path, "CREATE DATABASE ", NullS);
if (create_options & HA_LEX_CREATE_IF_NOT_EXISTS)
to= strxmov(to,"/*!32312 IF NOT EXISTS*/ ", NullS);
to=strxmov(to,"`",dbname,"`", NullS);
if (create.table_charset)
to= strxmov(to," DEFAULT CHARACTER SET ", create.table_charset->name,
NullS);
to= strxmov(to," /*!40100 DEFAULT CHARACTER SET ",
create.table_charset->name,"*/",NullS);
net_store_data(packet, convert, path, (uint) (to-path));
if (my_net_write(&thd->net,(char*) packet->ptr(), packet->length()))
......
......@@ -2462,7 +2462,7 @@ mysql_execute_command(THD *thd)
send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION);
goto error;
}
res=mysqld_show_create_db(thd,lex->name);
res=mysqld_show_create_db(thd,lex->name,&lex->create_info);
break;
}
case SQLCOM_CREATE_FUNCTION:
......
......@@ -2987,7 +2987,13 @@ opt_table_sym:
/* Show things */
show: SHOW { Lex->wild=0;} show_param;
show: SHOW
{
LEX *lex=Lex;
lex->wild=0;
bzero((char*) &lex->create_info,sizeof(lex->create_info));
}
show_param;
show_param:
DATABASES wild
......@@ -3100,10 +3106,11 @@ show_param:
lex->grant_user=$3;
lex->grant_user->password.str=NullS;
}
| CREATE DATABASE ident
| CREATE DATABASE opt_if_not_exists ident
{
Lex->sql_command=SQLCOM_SHOW_CREATE_DB;
Lex->name=$3.str;
Lex->create_info.options=$3;
Lex->name=$4.str;
}
| CREATE TABLE_SYM table_ident
{
......
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