Commit 4cefc97f authored by monty@mashka.mysql.fi's avatar monty@mashka.mysql.fi

Fixed CAST( xxx as CHAR)

parent 5dbea1b7
...@@ -85,12 +85,14 @@ class Item { ...@@ -85,12 +85,14 @@ class Item {
virtual bool get_date(TIME *ltime,bool fuzzydate); virtual bool get_date(TIME *ltime,bool fuzzydate);
virtual bool get_time(TIME *ltime); virtual bool get_time(TIME *ltime);
virtual bool is_null() { return 0; }; 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 bool check_loop(uint id);
virtual void top_level_item() {} 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); }
}; };
......
...@@ -1363,17 +1363,19 @@ String *Item_func_decode::val_str(String *str) ...@@ -1363,17 +1363,19 @@ String *Item_func_decode::val_str(String *str)
String *Item_func_database::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); str->length(0);
else 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; return str;
} }
String *Item_func_user::val_str(String *str) String *Item_func_user::val_str(String *str)
{ {
THD *thd=current_thd; 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 : ""; const char *host=thd->host ? thd->host : thd->ip ? thd->ip : "";
uint32 res_length=(strlen(thd->user)+strlen(host)+10) * cs->mbmaxlen; uint32 res_length=(strlen(thd->user)+strlen(host)+10) * cs->mbmaxlen;
...@@ -2128,7 +2130,8 @@ String *Item_func_charset::val_str(String *str) ...@@ -2128,7 +2130,8 @@ String *Item_func_charset::val_str(String *str)
if ((null_value=(args[0]->null_value || !res->charset()))) if ((null_value=(args[0]->null_value || !res->charset())))
return 0; 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; return str;
} }
......
...@@ -494,8 +494,9 @@ class Item_func_binary :public Item_str_func ...@@ -494,8 +494,9 @@ class Item_func_binary :public Item_str_func
{ {
String *tmp=args[0]->val_str(a); String *tmp=args[0]->val_str(a);
null_value=args[0]->null_value; null_value=args[0]->null_value;
tmp->set_charset(my_charset_bin);
return tmp; return tmp;
} }
void fix_length_and_dec() void fix_length_and_dec()
{ {
set_charset(my_charset_bin); set_charset(my_charset_bin);
......
...@@ -534,8 +534,17 @@ class Item_typecast :public Item_str_func ...@@ -534,8 +534,17 @@ class Item_typecast :public Item_str_func
Item_typecast(Item *a) :Item_str_func(a) {} Item_typecast(Item *a) :Item_str_func(a) {}
const char *func_name() const { return "char"; } const char *func_name() const { return "char"; }
String *val_str(String *a) 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); void print(String *str);
}; };
...@@ -544,7 +553,11 @@ class Item_char_typecast :public Item_typecast ...@@ -544,7 +553,11 @@ class Item_char_typecast :public Item_typecast
{ {
public: public:
Item_char_typecast(Item *a) :Item_typecast(a) {} 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;
}
}; };
......
...@@ -72,7 +72,7 @@ class String ...@@ -72,7 +72,7 @@ class String
{ sql_element_free(ptr_arg); } { sql_element_free(ptr_arg); }
~String() { free(); } ~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 CHARSET_INFO *charset() const { return str_charset; }
inline uint32 length() const { return str_length;} inline uint32 length() const { return str_length;}
inline uint32 alloced_length() const { return Alloced_length;} inline uint32 alloced_length() const { return Alloced_length;}
...@@ -177,7 +177,8 @@ class String ...@@ -177,7 +177,8 @@ class String
bool copy(); // Alloc string if not alloced bool copy(); // Alloc string if not alloced
bool copy(const String &s); // Allocate new string 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 *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 String &s);
bool append(const char *s,uint32 arg_length=0); bool append(const char *s,uint32 arg_length=0);
bool append(IO_CACHE* file, uint32 arg_length); bool append(IO_CACHE* file, uint32 arg_length);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment