diff options
-rw-r--r-- | mysql-test/r/derived.result | 8 | ||||
-rw-r--r-- | mysql-test/t/derived.test | 13 | ||||
-rw-r--r-- | sql/sql_derived.cc | 2 |
3 files changed, 22 insertions, 1 deletions
diff --git a/mysql-test/r/derived.result b/mysql-test/r/derived.result index f9e52174469..944253bd527 100644 --- a/mysql-test/r/derived.result +++ b/mysql-test/r/derived.result @@ -196,3 +196,11 @@ drop table t1,t2; SELECT a.x FROM (SELECT 1 AS x) AS a HAVING a.x = 1; x 1 +create table a1 select 1 as a; +select 2 as a from (select * from a1) b; +ERROR 3D000: No Database Selected +use test; +select 2 as a from (select * from a1) b; +a +2 +drop table a1; diff --git a/mysql-test/t/derived.test b/mysql-test/t/derived.test index c3edbabcd53..3c735878e46 100644 --- a/mysql-test/t/derived.test +++ b/mysql-test/t/derived.test @@ -94,3 +94,16 @@ drop table t1,t2; # derived table reference # SELECT a.x FROM (SELECT 1 AS x) AS a HAVING a.x = 1; + +# +# Test for select if database is not selected. +# +# Connect without a database +create table a1 select 1 as a; +connect (con1,localhost,mysqltest_1,,*NO-ONE*,$MASTER_MYPORT,master.sock); +connection con1; +--error 1046 +select 2 as a from (select * from a1) b; +use test; +select 2 as a from (select * from a1) b; +drop table a1; diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 771d68e8462..5d05fea4fe3 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -96,7 +96,7 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, else res= check_access(thd, SELECT_ACL, any_db); if (res) - DBUG_RETURN(-1); + DBUG_RETURN(1); if (!(res=open_and_lock_tables(thd,tables))) { |