diff options
-rw-r--r-- | sql/item.h | 10 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 11 | ||||
-rw-r--r-- | sql/item_strfunc.h | 3 | ||||
-rw-r--r-- | sql/item_timefunc.h | 19 | ||||
-rw-r--r-- | sql/sql_string.h | 5 |
5 files changed, 34 insertions, 14 deletions
diff --git a/sql/item.h b/sql/item.h index 5eeaa22a2a2..34ca221cadc 100644 --- a/sql/item.h +++ b/sql/item.h @@ -85,12 +85,14 @@ public: virtual bool get_date(TIME *ltime,bool fuzzydate); virtual bool get_time(TIME *ltime); virtual bool is_null() { return 0; }; - virtual CHARSET_INFO *thd_charset() const; - virtual CHARSET_INFO *charset() const { return str_value.charset(); }; - virtual bool binary() const { return str_value.charset()->state & MY_CS_BINSORT ? 1 : 0 ; } - virtual void set_charset(CHARSET_INFO *cs) { str_value.set_charset(cs); } virtual bool check_loop(uint id); virtual void top_level_item() {} + + virtual bool binary() const + { return str_value.charset()->state & MY_CS_BINSORT ? 1 : 0 ; } + CHARSET_INFO *thd_charset() const; + CHARSET_INFO *charset() const { return str_value.charset(); }; + void set_charset(CHARSET_INFO *cs) { str_value.set_charset(cs); } }; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 1a561c9eb34..34c89a49e8a 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1363,17 +1363,19 @@ String *Item_func_decode::val_str(String *str) String *Item_func_database::val_str(String *str) { - if (!current_thd->db) + THD *thd= current_thd; + if (!thd->db) str->length(0); else - str->copy((const char*) current_thd->db,(uint) strlen(current_thd->db), system_charset_info, thd_charset()); + str->copy((const char*) thd->db,(uint) strlen(thd->db), + system_charset_info, thd->thd_charset); return str; } String *Item_func_user::val_str(String *str) { THD *thd=current_thd; - CHARSET_INFO *cs=thd_charset(); + CHARSET_INFO *cs=thd->thd_charset; const char *host=thd->host ? thd->host : thd->ip ? thd->ip : ""; uint32 res_length=(strlen(thd->user)+strlen(host)+10) * cs->mbmaxlen; @@ -2128,7 +2130,8 @@ String *Item_func_charset::val_str(String *str) if ((null_value=(args[0]->null_value || !res->charset()))) return 0; - str->copy(res->charset()->name,strlen(res->charset()->name),my_charset_latin1,thd_charset()); + str->copy(res->charset()->name,strlen(res->charset()->name), + my_charset_latin1, thd_charset()); return str; } diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 2b308630b48..9fd9143586e 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -494,8 +494,9 @@ public: { String *tmp=args[0]->val_str(a); null_value=args[0]->null_value; + tmp->set_charset(my_charset_bin); return tmp; - } + } void fix_length_and_dec() { set_charset(my_charset_bin); diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 7765769c1d3..f9b987324f0 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -534,8 +534,17 @@ public: Item_typecast(Item *a) :Item_str_func(a) {} const char *func_name() const { return "char"; } String *val_str(String *a) - { a=args[0]->val_str(a); null_value=args[0]->null_value; return a; } - void fix_length_and_dec() { max_length=args[0]->max_length; } + { + String *tmp=args[0]->val_str(a); + null_value=args[0]->null_value; + tmp->set_charset(charset()); + return tmp; + } + void fix_length_and_dec() + { + set_charset(thd_charset()); + max_length=args[0]->max_length; + } void print(String *str); }; @@ -544,7 +553,11 @@ class Item_char_typecast :public Item_typecast { public: Item_char_typecast(Item *a) :Item_typecast(a) {} - void fix_length_and_dec() { binary=0; max_length=args[0]->max_length; } + void fix_length_and_dec() + { + set_charset(thd_charset()); + max_length=args[0]->max_length; + } }; diff --git a/sql/sql_string.h b/sql/sql_string.h index 42f9e446981..dde67b11d50 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -72,7 +72,7 @@ public: { sql_element_free(ptr_arg); } ~String() { free(); } - inline void set_charset(CHARSET_INFO *charset) { str_charset=charset; } + inline void set_charset(CHARSET_INFO *charset) { str_charset= charset; } inline CHARSET_INFO *charset() const { return str_charset; } inline uint32 length() const { return str_length;} inline uint32 alloced_length() const { return Alloced_length;} @@ -177,7 +177,8 @@ public: bool copy(); // Alloc string if not alloced bool copy(const String &s); // Allocate new string bool copy(const char *s,uint32 arg_length, CHARSET_INFO *cs); // Allocate new string - bool copy(const char*s,uint32 arg_length, CHARSET_INFO *csfrom, CHARSET_INFO *csto); + bool copy(const char*s,uint32 arg_length, CHARSET_INFO *csfrom, + CHARSET_INFO *csto); bool append(const String &s); bool append(const char *s,uint32 arg_length=0); bool append(IO_CACHE* file, uint32 arg_length); |