From 1af778c05bf236177262ae5231a65d56bd92ee5c Mon Sep 17 00:00:00 2001 From: "bar@bar.mysql.r18.ru" <> Date: Tue, 1 Oct 2002 17:23:28 +0500 Subject: [PATCH] User variables didn't store charset, so this didn't work as expected and returned default charset instead: SET @x = _koi8_ru'test'; SELECT CHARSET(@x); --- sql/item_func.cc | 14 +++++++++----- sql/item_func.h | 2 +- sql/sql_class.h | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/sql/item_func.cc b/sql/item_func.cc index 8728187718c..ded5e045af4 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1801,7 +1801,8 @@ Item_func_set_user_var::fix_length_and_dec() } void Item_func_set_user_var::update_hash(void *ptr, uint length, - Item_result type) + Item_result type, + CHARSET_INFO *cs) { if ((null_value=args[0]->null_value)) { @@ -1810,6 +1811,7 @@ void Item_func_set_user_var::update_hash(void *ptr, uint length, my_free(entry->value,MYF(0)); entry->value=0; entry->length=0; + entry->var_charset=cs; } else { @@ -1840,6 +1842,7 @@ void Item_func_set_user_var::update_hash(void *ptr, uint length, memcpy(entry->value,ptr,length); entry->length= length; entry->type=type; + entry->var_charset=cs; } return; @@ -1874,7 +1877,7 @@ double Item_func_set_user_var::val() { double value=args[0]->val(); - update_hash((void*) &value,sizeof(value), REAL_RESULT); + update_hash((void*) &value,sizeof(value), REAL_RESULT, default_charset_info); return value; } @@ -1882,7 +1885,7 @@ longlong Item_func_set_user_var::val_int() { longlong value=args[0]->val_int(); - update_hash((void*) &value,sizeof(longlong),INT_RESULT); + update_hash((void*) &value,sizeof(longlong),INT_RESULT, default_charset_info); return value; } @@ -1891,9 +1894,9 @@ Item_func_set_user_var::val_str(String *str) { String *res=args[0]->val_str(str); if (!res) // Null value - update_hash((void*) 0,0,STRING_RESULT); + update_hash((void*) 0,0,STRING_RESULT, default_charset_info); else - update_hash(res->c_ptr(),res->length()+1,STRING_RESULT); + update_hash(res->c_ptr(),res->length()+1,STRING_RESULT,res->charset()); return res; } @@ -1939,6 +1942,7 @@ Item_func_get_user_var::val_str(String *str) null_value=1; return NULL; } + str->set_charset(entry->var_charset); break; } return str; diff --git a/sql/item_func.h b/sql/item_func.h index 2e61ed87c3c..d8f6963479d 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -875,7 +875,7 @@ public: double val(); longlong val_int(); String *val_str(String *str); - void update_hash(void *ptr, uint length, enum Item_result type); + void update_hash(void *ptr, uint length, enum Item_result type, CHARSET_INFO *cs); bool update(); enum Item_result result_type () const { return cached_result_type; } bool fix_fields(THD *thd, struct st_table_list *tables, Item **ref); diff --git a/sql/sql_class.h b/sql/sql_class.h index a6b7e45ab03..84dde229b2f 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -830,6 +830,7 @@ class user_var_entry char *value; ulong length, update_query_id; Item_result type; + CHARSET_INFO *var_charset; }; /* Class for unique (removing of duplicates) */