From 3ff1acb8dbee3096aa67f4fee1fe56b0c52cd04a Mon Sep 17 00:00:00 2001 From: "bar@mysql.com" <> Date: Tue, 30 Aug 2005 17:11:59 +0500 Subject: [PATCH] Bug#12363 character_set_results is nullable, but value_ptr returns string "NULL" set_var.cc: Create Item_null instead of Item_string for NULL values variables.result, variables.test: adding test case --- mysql-test/r/variables.result | 5 +++++ mysql-test/t/variables.test | 8 ++++++++ sql/set_var.cc | 14 ++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/variables.result b/mysql-test/r/variables.result index 14260cd04f9..b01a8c1f8bf 100644 --- a/mysql-test/r/variables.result +++ b/mysql-test/r/variables.result @@ -491,3 +491,8 @@ SHOW VARIABLES LIKE 'table_cache'; Variable_name Value table_cache 1 SET GLOBAL table_cache=DEFAULT; +set character_set_results=NULL; +select ifnull(@@character_set_results,"really null"); +ifnull(@@character_set_results,"really null") +really null +set names latin1; diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test index 7743b70d0cd..40cade15c9f 100644 --- a/mysql-test/t/variables.test +++ b/mysql-test/t/variables.test @@ -380,4 +380,12 @@ SET GLOBAL table_cache=-1; SHOW VARIABLES LIKE 'table_cache'; SET GLOBAL table_cache=DEFAULT; +# +# Bugs12363: character_set_results is nullable, +# but value_ptr returns string "NULL" +# +set character_set_results=NULL; +select ifnull(@@character_set_results,"really null"); +set names latin1; + # End of 4.1 tests diff --git a/sql/set_var.cc b/sql/set_var.cc index 99985c3647c..50f5c6b840e 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -1598,11 +1598,17 @@ Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base) return new Item_int((int32) *(my_bool*) value_ptr(thd, var_type, base),1); case SHOW_CHAR: { - Item_string *tmp; + Item *tmp; pthread_mutex_lock(&LOCK_global_system_variables); char *str= (char*) value_ptr(thd, var_type, base); - tmp= new Item_string(str, strlen(str), - system_charset_info, DERIVATION_SYSCONST); + if (str) + tmp= new Item_string(str, strlen(str), + system_charset_info, DERIVATION_SYSCONST); + else + { + tmp= new Item_null(); + tmp->collation.set(system_charset_info, DERIVATION_SYSCONST); + } pthread_mutex_unlock(&LOCK_global_system_variables); return tmp; } @@ -1892,7 +1898,7 @@ byte *sys_var_character_set::value_ptr(THD *thd, enum_var_type type, LEX_STRING *base) { CHARSET_INFO *cs= ci_ptr(thd,type)[0]; - return cs ? (byte*) cs->csname : (byte*) "NULL"; + return cs ? (byte*) cs->csname : (byte*) NULL; }