diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index ce404c7dce2..9100022cb7f 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -4102,3 +4102,10 @@ UNLOCK TABLES; # Connection default DROP PROCEDURE p1; DROP TABLE t1; +# +# Bug#12626844: WRONG ERROR MESSAGE WHILE CREATING A VIEW ON A +# NON EXISTING DATABASE +# +DROP DATABASE IF EXISTS nodb; +CREATE VIEW nodb.a AS SELECT 1; +ERROR 42000: Unknown database 'nodb' diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 39985bec339..603b3e5cdb9 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -4136,6 +4136,17 @@ disconnect con2; disconnect con3; +--echo # +--echo # Bug#12626844: WRONG ERROR MESSAGE WHILE CREATING A VIEW ON A +--echo # NON EXISTING DATABASE +--echo # + +--disable_warnings +DROP DATABASE IF EXISTS nodb; +--enable_warnings +--error ER_BAD_DB_ERROR +CREATE VIEW nodb.a AS SELECT 1; + # Check that all connections opened by test cases in this file are really # gone so execution of other tests won't be affected by their presence. --source include/wait_until_count_sessions.inc diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 1d26d2b113c..24cb0dd3e8d 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -444,6 +444,13 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views, view= lex->unlink_first_table(&link_to_local); + if (check_db_dir_existence(view->db)) + { + my_error(ER_BAD_DB_ERROR, MYF(0), view->db); + res= TRUE; + goto err; + } + if (mode == VIEW_ALTER && fill_defined_view_parts(thd, view)) { res= TRUE;