From 0282d03215e367e5fac4624fa9e9edcedf6938eb Mon Sep 17 00:00:00 2001 From: "gluh@gluh.mysql.r18.ru" <> Date: Mon, 6 Dec 2004 19:01:51 +0300 Subject: [PATCH] Syntax extention: 'ALTER DATABASE' without db name (after review) --- mysql-test/r/ctype_create.result | 9 +++++++++ mysql-test/t/ctype_create.test | 12 ++++++++++++ sql/sql_parse.cc | 18 ++++++++++++------ sql/sql_yacc.yy | 11 ++++++++--- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/mysql-test/r/ctype_create.result b/mysql-test/r/ctype_create.result index b35131f62a..63bae33c6e 100644 --- a/mysql-test/r/ctype_create.result +++ b/mysql-test/r/ctype_create.result @@ -63,3 +63,12 @@ ERROR HY000: Conflicting declarations: 'CHARACTER SET latin1' and 'CHARACTER SET create database d1 default character set latin1 collate latin2_bin; ERROR 42000: COLLATION 'latin2_bin' is not valid for CHARACTER SET 'latin1' DROP DATABASE mysqltest1; +CREATE DATABASE mysqltest2 DEFAULT CHARACTER SET latin7; +use mysqltest2; +ALTER DATABASE DEFAULT CHARACTER SET latin2; +show create database mysqltest2; +Database Create Database +mysqltest2 CREATE DATABASE `mysqltest2` /*!40100 DEFAULT CHARACTER SET latin2 */ +drop database mysqltest2; +ALTER DATABASE DEFAULT CHARACTER SET latin2; +ERROR 3D000: No database selected diff --git a/mysql-test/t/ctype_create.test b/mysql-test/t/ctype_create.test index 9a5cb02547..e97017ab41 100644 --- a/mysql-test/t/ctype_create.test +++ b/mysql-test/t/ctype_create.test @@ -86,3 +86,15 @@ create database d1 default character set latin1 collate latin2_bin; # # DROP DATABASE mysqltest1; + + +# +# Synatx: 'ALTER DATABASE' without db_name +# +CREATE DATABASE mysqltest2 DEFAULT CHARACTER SET latin7; +use mysqltest2; +ALTER DATABASE DEFAULT CHARACTER SET latin2; +show create database mysqltest2; +drop database mysqltest2; +--error 1046 +ALTER DATABASE DEFAULT CHARACTER SET latin2; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 3d1df80c37..1e18771ad1 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -3184,9 +3184,15 @@ purposes internal to the MySQL server", MYF(0)); } case SQLCOM_ALTER_DB: { - if (!strip_sp(lex->name) || check_db_name(lex->name)) + char *db= lex->name ? lex->name : thd->db; + if (!db) { - net_printf(thd, ER_WRONG_DB_NAME, lex->name); + send_error(thd, ER_NO_DB_ERROR); + goto error; + } + if (!strip_sp(db) || check_db_name(db)) + { + net_printf(thd, ER_WRONG_DB_NAME, db); break; } /* @@ -3198,21 +3204,21 @@ purposes internal to the MySQL server", MYF(0)); */ #ifdef HAVE_REPLICATION if (thd->slave_thread && - (!db_ok(lex->name, replicate_do_db, replicate_ignore_db) || - !db_ok_with_wild_table(lex->name))) + (!db_ok(db, replicate_do_db, replicate_ignore_db) || + !db_ok_with_wild_table(db))) { my_error(ER_SLAVE_IGNORED_TABLE, MYF(0)); break; } #endif - if (check_access(thd,ALTER_ACL,lex->name,0,1,0)) + if (check_access(thd, ALTER_ACL, db, 0, 1, 0)) break; if (thd->locked_tables || thd->active_transaction()) { send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION); goto error; } - res=mysql_alter_db(thd,lex->name,&lex->create_info); + res= mysql_alter_db(thd, db, &lex->create_info); break; } case SQLCOM_SHOW_CREATE_DB: diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 49e567ab54..e525fb2478 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -609,7 +609,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %type <simple_string> remember_name remember_end opt_ident opt_db text_or_password - opt_constraint constraint + opt_constraint constraint ident_or_empty %type <string> text_string opt_gconcat_separator @@ -1870,7 +1870,7 @@ alter: } alter_list {} - | ALTER DATABASE ident + | ALTER DATABASE ident_or_empty { Lex->create_info.default_table_charset= NULL; Lex->create_info.used_fields= 0; @@ -1879,10 +1879,15 @@ alter: { LEX *lex=Lex; lex->sql_command=SQLCOM_ALTER_DB; - lex->name=$3.str; + lex->name= $3; }; +ident_or_empty: + /* empty */ { $$= 0; } + | ident { $$= $1.str; }; + + alter_list: | DISCARD TABLESPACE { Lex->alter_info.tablespace_op= DISCARD_TABLESPACE; } | IMPORT TABLESPACE { Lex->alter_info.tablespace_op= IMPORT_TABLESPACE; } -- 2.30.9