Skip to content

Commit 0282d03

Browse files
author
gluh@gluh.mysql.r18.ru
committed
Syntax extention: 'ALTER DATABASE' without db name (after review)
1 parent 6ad5876 commit 0282d03

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

mysql-test/r/ctype_create.result

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,12 @@ ERROR HY000: Conflicting declarations: 'CHARACTER SET latin1' and 'CHARACTER SET
6363
create database d1 default character set latin1 collate latin2_bin;
6464
ERROR 42000: COLLATION 'latin2_bin' is not valid for CHARACTER SET 'latin1'
6565
DROP DATABASE mysqltest1;
66+
CREATE DATABASE mysqltest2 DEFAULT CHARACTER SET latin7;
67+
use mysqltest2;
68+
ALTER DATABASE DEFAULT CHARACTER SET latin2;
69+
show create database mysqltest2;
70+
Database Create Database
71+
mysqltest2 CREATE DATABASE `mysqltest2` /*!40100 DEFAULT CHARACTER SET latin2 */
72+
drop database mysqltest2;
73+
ALTER DATABASE DEFAULT CHARACTER SET latin2;
74+
ERROR 3D000: No database selected

mysql-test/t/ctype_create.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,15 @@ create database d1 default character set latin1 collate latin2_bin;
8686
#
8787
#
8888
DROP DATABASE mysqltest1;
89+
90+
91+
#
92+
# Synatx: 'ALTER DATABASE' without db_name
93+
#
94+
CREATE DATABASE mysqltest2 DEFAULT CHARACTER SET latin7;
95+
use mysqltest2;
96+
ALTER DATABASE DEFAULT CHARACTER SET latin2;
97+
show create database mysqltest2;
98+
drop database mysqltest2;
99+
--error 1046
100+
ALTER DATABASE DEFAULT CHARACTER SET latin2;

sql/sql_parse.cc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3184,9 +3184,15 @@ purposes internal to the MySQL server", MYF(0));
31843184
}
31853185
case SQLCOM_ALTER_DB:
31863186
{
3187-
if (!strip_sp(lex->name) || check_db_name(lex->name))
3187+
char *db= lex->name ? lex->name : thd->db;
3188+
if (!db)
31883189
{
3189-
net_printf(thd, ER_WRONG_DB_NAME, lex->name);
3190+
send_error(thd, ER_NO_DB_ERROR);
3191+
goto error;
3192+
}
3193+
if (!strip_sp(db) || check_db_name(db))
3194+
{
3195+
net_printf(thd, ER_WRONG_DB_NAME, db);
31903196
break;
31913197
}
31923198
/*
@@ -3198,21 +3204,21 @@ purposes internal to the MySQL server", MYF(0));
31983204
*/
31993205
#ifdef HAVE_REPLICATION
32003206
if (thd->slave_thread &&
3201-
(!db_ok(lex->name, replicate_do_db, replicate_ignore_db) ||
3202-
!db_ok_with_wild_table(lex->name)))
3207+
(!db_ok(db, replicate_do_db, replicate_ignore_db) ||
3208+
!db_ok_with_wild_table(db)))
32033209
{
32043210
my_error(ER_SLAVE_IGNORED_TABLE, MYF(0));
32053211
break;
32063212
}
32073213
#endif
3208-
if (check_access(thd,ALTER_ACL,lex->name,0,1,0))
3214+
if (check_access(thd, ALTER_ACL, db, 0, 1, 0))
32093215
break;
32103216
if (thd->locked_tables || thd->active_transaction())
32113217
{
32123218
send_error(thd,ER_LOCK_OR_ACTIVE_TRANSACTION);
32133219
goto error;
32143220
}
3215-
res=mysql_alter_db(thd,lex->name,&lex->create_info);
3221+
res= mysql_alter_db(thd, db, &lex->create_info);
32163222
break;
32173223
}
32183224
case SQLCOM_SHOW_CREATE_DB:

sql/sql_yacc.yy

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
609609

610610
%type <simple_string>
611611
remember_name remember_end opt_ident opt_db text_or_password
612-
opt_constraint constraint
612+
opt_constraint constraint ident_or_empty
613613

614614
%type <string>
615615
text_string opt_gconcat_separator
@@ -1870,7 +1870,7 @@ alter:
18701870
}
18711871
alter_list
18721872
{}
1873-
| ALTER DATABASE ident
1873+
| ALTER DATABASE ident_or_empty
18741874
{
18751875
Lex->create_info.default_table_charset= NULL;
18761876
Lex->create_info.used_fields= 0;
@@ -1879,10 +1879,15 @@ alter:
18791879
{
18801880
LEX *lex=Lex;
18811881
lex->sql_command=SQLCOM_ALTER_DB;
1882-
lex->name=$3.str;
1882+
lex->name= $3;
18831883
};
18841884

18851885

1886+
ident_or_empty:
1887+
/* empty */ { $$= 0; }
1888+
| ident { $$= $1.str; };
1889+
1890+
18861891
alter_list:
18871892
| DISCARD TABLESPACE { Lex->alter_info.tablespace_op= DISCARD_TABLESPACE; }
18881893
| IMPORT TABLESPACE { Lex->alter_info.tablespace_op= IMPORT_TABLESPACE; }

0 commit comments

Comments
 (0)