Commit 1e63509d authored by unknown's avatar unknown

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*/


client/mysqldump.c:
  SHOW CREATE DATABASE IF NOT EXISTS
sql/mysql_priv.h:
  SHOW CREATE DATABASE IF NOT EXISTS
sql/sql_db.cc:
  SHOW CREATE DATABASE IF NOT EXISTS
sql/sql_parse.cc:
  SHOW CREATE DATABASE IF NOT EXISTS
sql/sql_yacc.yy:
  SHOW CREATE DATABASE IF NOT EXISTS
parent 11c6f6c4
...@@ -1252,7 +1252,7 @@ static int init_dumping(char *database) ...@@ -1252,7 +1252,7 @@ static int init_dumping(char *database)
MYSQL_ROW row; MYSQL_ROW row;
MYSQL_RES *dbinfo; 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))) if (mysql_query(sock, qbuf) || !(dbinfo = mysql_store_result(sock)))
{ {
......
...@@ -496,7 +496,7 @@ int mysqld_show_logs(THD *thd); ...@@ -496,7 +496,7 @@ int mysqld_show_logs(THD *thd);
void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild); 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_dump_create_info(THD *thd, TABLE *table, int fd = -1);
int mysqld_show_create(THD *thd, TABLE_LIST *table_list); 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); void mysqld_list_processes(THD *thd,const char *user,bool verbose);
int mysqld_show_status(THD *thd); int mysqld_show_status(THD *thd);
......
...@@ -597,7 +597,7 @@ bool mysql_change_db(THD *thd, const char *name) ...@@ -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; int length;
char path[FN_REFLEN], *to; char path[FN_REFLEN], *to;
...@@ -605,6 +605,8 @@ int mysqld_show_create_db(THD *thd, const char *dbname) ...@@ -605,6 +605,8 @@ int mysqld_show_create_db(THD *thd, const char *dbname)
bool found_libchar; bool found_libchar;
HA_CREATE_INFO create; HA_CREATE_INFO create;
CONVERT *convert=thd->variables.convert_set; CONVERT *convert=thd->variables.convert_set;
uint create_options = create_info ? create_info->options : 0;
DBUG_ENTER("mysql_show_create_db"); DBUG_ENTER("mysql_show_create_db");
if (check_db_name(dbname)) if (check_db_name(dbname))
...@@ -660,10 +662,15 @@ int mysqld_show_create_db(THD *thd, const char *dbname) ...@@ -660,10 +662,15 @@ int mysqld_show_create_db(THD *thd, const char *dbname)
String *packet = &thd->packet; String *packet = &thd->packet;
packet->length(0); packet->length(0);
net_store_data(packet, convert, dbname); 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) if (create.table_charset)
to= strxmov(to," DEFAULT CHARACTER SET ", create.table_charset->name, to= strxmov(to," /*!40100 DEFAULT CHARACTER SET ",
NullS); create.table_charset->name,"*/",NullS);
net_store_data(packet, convert, path, (uint) (to-path)); net_store_data(packet, convert, path, (uint) (to-path));
if (my_net_write(&thd->net,(char*) packet->ptr(), packet->length())) if (my_net_write(&thd->net,(char*) packet->ptr(), packet->length()))
......
...@@ -2462,7 +2462,7 @@ mysql_execute_command(THD *thd) ...@@ -2462,7 +2462,7 @@ mysql_execute_command(THD *thd)
send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION); send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION);
goto error; goto error;
} }
res=mysqld_show_create_db(thd,lex->name); res=mysqld_show_create_db(thd,lex->name,&lex->create_info);
break; break;
} }
case SQLCOM_CREATE_FUNCTION: case SQLCOM_CREATE_FUNCTION:
......
...@@ -2987,7 +2987,13 @@ opt_table_sym: ...@@ -2987,7 +2987,13 @@ opt_table_sym:
/* Show things */ /* 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: show_param:
DATABASES wild DATABASES wild
...@@ -3100,10 +3106,11 @@ show_param: ...@@ -3100,10 +3106,11 @@ show_param:
lex->grant_user=$3; lex->grant_user=$3;
lex->grant_user->password.str=NullS; lex->grant_user->password.str=NullS;
} }
| CREATE DATABASE ident | CREATE DATABASE opt_if_not_exists ident
{ {
Lex->sql_command=SQLCOM_SHOW_CREATE_DB; 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 | 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