From 1d3d64d69b9bf96a18768df031dc2cad29e84b15 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 8 Sep 2003 17:30:53 +0500 Subject: [PATCH] Fix for the bug #1209: SELECT DATABASE(). --- mysql-test/r/create.result | 13 +++++++++++++ mysql-test/t/create.test | 16 ++++++++++++++++ sql/item_strfunc.cc | 4 ++-- sql/sql_db.cc | 2 ++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index 80ff8aef15b..06ddd5e2280 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -361,3 +361,16 @@ a b c d e f g h dd 1 -7 7 2000-01-01 b 2000-01-01 00:00:00 05:04:03 yet another binary data 02:00:00 2 -2 2 1825-12-14 a 2003-01-01 03:02:01 04:03:02 binary data 02:00:00 drop table t1, t2; +drop database if exists test_$1; +create database test_$1; +use test_$1; +select database(); +database() +test_$1 +drop database test_$1; +select database(); +database() +NULL +select database(); +database() +NULL diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index 2e21768dc0b..0b86b67fdbf 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -260,3 +260,19 @@ select * from t2; drop table t1, t2; +# +# Bug #1209 +# + +--disable_warnings +drop database if exists test_$1; +--enable_warnings +create database test_$1; +use test_$1; +select database(); +drop database test_$1; +select database(); + +# Connect without a database +connect (user4,localhost,mysqltest_1,,*NO-ONE*); +select database(); diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index f8cc602129f..c4ad7f1e1e2 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1454,8 +1454,8 @@ String *Item_func_database::val_str(String *str) THD *thd= current_thd; if (!thd->db) { - str->length(0); - str->set_charset(system_charset_info); + null_value= 1; + return 0; } else str->copy((const char*) thd->db,(uint) strlen(thd->db),system_charset_info); diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 34e81402dd0..343eb6e42f2 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -391,6 +391,8 @@ int mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent) exit: start_waiting_global_read_lock(thd); + if (thd->db && !strcmp(thd->db, db)) + thd->db= 0; exit2: VOID(pthread_mutex_unlock(&LOCK_mysql_create_db));