Commit 9a9e7ce0 authored by bar@bar.mysql.r18.ru's avatar bar@bar.mysql.r18.ru

Item->thd_charset() - returns a default charset which should be used

to compose strings appeared without charset context, for example,
in convertion from numer into string type.
parent 8229d282
......@@ -4316,14 +4316,14 @@ int Field_blob::store(const char *from,uint len,CHARSET_INFO *cs)
int Field_blob::store(double nr)
{
value.set(nr,2,my_thd_charset);
value.set(nr,2,current_thd->thd_charset);
return Field_blob::store(value.ptr(),(uint) value.length(), value.charset());
}
int Field_blob::store(longlong nr)
{
value.set(nr,my_thd_charset);
value.set(nr,current_thd->thd_charset);
return Field_blob::store(value.ptr(), (uint) value.length(), value.charset());
}
......
......@@ -117,6 +117,11 @@ bool Item::get_time(TIME *ltime)
return 0;
}
CHARSET_INFO * Item::thd_charset() const
{
return current_thd->thd_charset;
}
Item_field::Item_field(Field *f) :Item_ident(NullS,f->table_name,f->field_name)
{
set_field(f);
......@@ -234,7 +239,7 @@ table_map Item_field::used_tables() const
String *Item_int::val_str(String *str)
{
str->set(value, my_thd_charset);
str->set(value, thd_charset());
return str;
}
......@@ -242,7 +247,7 @@ void Item_int::print(String *str)
{
if (!name)
{
str_value.set(value, my_thd_charset);
str_value.set(value, thd_charset());
name=str_value.c_ptr();
}
str->append(name);
......@@ -250,7 +255,7 @@ void Item_int::print(String *str)
String *Item_uint::val_str(String *str)
{
str->set((ulonglong) value, my_thd_charset);
str->set((ulonglong) value, thd_charset());
return str;
}
......@@ -258,7 +263,7 @@ void Item_uint::print(String *str)
{
if (!name)
{
str_value.set((ulonglong) value, my_thd_charset);
str_value.set((ulonglong) value, thd_charset());
name=str_value.c_ptr();
}
str->append(name);
......@@ -267,7 +272,7 @@ void Item_uint::print(String *str)
String *Item_real::val_str(String *str)
{
str->set(value,decimals,my_thd_charset);
str->set(value,decimals,thd_charset());
return str;
}
......@@ -384,10 +389,10 @@ String *Item_param::val_str(String* str)
{
switch (item_result_type) {
case INT_RESULT:
str->set(int_value, my_thd_charset);
str->set(int_value, thd_charset());
return str;
case REAL_RESULT:
str->set(real_value, 2, my_thd_charset);
str->set(real_value, 2, thd_charset());
return str;
default:
return (String*) &str_value;
......
......@@ -84,6 +84,7 @@ class Item {
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); }
......
......@@ -243,7 +243,7 @@ String *Item_real_func::val_str(String *str)
if (null_value)
return 0; /* purecov: inspected */
else
str->set(nr,decimals,my_thd_charset);
str->set(nr,decimals,thd_charset());
return str;
}
......@@ -256,9 +256,9 @@ String *Item_num_func::val_str(String *str)
if (null_value)
return 0; /* purecov: inspected */
else if (!unsigned_flag)
str->set(nr,my_thd_charset);
str->set(nr,thd_charset());
else
str->set((ulonglong) nr,my_thd_charset);
str->set((ulonglong) nr,thd_charset());
}
else
{
......@@ -266,7 +266,7 @@ String *Item_num_func::val_str(String *str)
if (null_value)
return 0; /* purecov: inspected */
else
str->set(nr,decimals,my_thd_charset);
str->set(nr,decimals,thd_charset());
}
return str;
}
......@@ -286,9 +286,9 @@ String *Item_int_func::val_str(String *str)
if (null_value)
return 0;
else if (!unsigned_flag)
str->set(nr,my_thd_charset);
str->set(nr,thd_charset());
else
str->set((ulonglong) nr,my_thd_charset);
str->set((ulonglong) nr,thd_charset());
return str;
}
......@@ -315,9 +315,9 @@ String *Item_num_op::val_str(String *str)
if (null_value)
return 0; /* purecov: inspected */
else if (!unsigned_flag)
str->set(nr,my_thd_charset);
str->set(nr,thd_charset());
else
str->set((ulonglong) nr,my_thd_charset);
str->set((ulonglong) nr,thd_charset());
}
else
{
......@@ -325,7 +325,7 @@ String *Item_num_op::val_str(String *str)
if (null_value)
return 0; /* purecov: inspected */
else
str->set(nr,decimals,my_thd_charset);
str->set(nr,decimals,thd_charset());
}
return str;
}
......@@ -813,9 +813,9 @@ String *Item_func_min_max::val_str(String *str)
if (null_value)
return 0;
else if (!unsigned_flag)
str->set(nr,my_thd_charset);
str->set(nr,thd_charset());
else
str->set((ulonglong) nr,my_thd_charset);
str->set((ulonglong) nr,thd_charset());
return str;
}
case REAL_RESULT:
......@@ -824,7 +824,7 @@ String *Item_func_min_max::val_str(String *str)
if (null_value)
return 0; /* purecov: inspected */
else
str->set(nr,decimals,my_thd_charset);
str->set(nr,decimals,thd_charset());
return str;
}
case STRING_RESULT:
......@@ -1447,7 +1447,7 @@ String *Item_func_udf_float::val_str(String *str)
if (null_value)
return 0; /* purecov: inspected */
else
str->set(nr,decimals,my_thd_charset);
str->set(nr,decimals,thd_charset());
return str;
}
......@@ -1468,9 +1468,9 @@ String *Item_func_udf_int::val_str(String *str)
if (null_value)
return 0;
else if (!unsigned_flag)
str->set(nr,my_thd_charset);
str->set(nr,thd_charset());
else
str->set((ulonglong) nr,my_thd_charset);
str->set((ulonglong) nr,thd_charset());
return str;
}
......@@ -2034,10 +2034,10 @@ Item_func_get_user_var::val_str(String *str)
return NULL;
switch (entry->type) {
case REAL_RESULT:
str->set(*(double*) entry->value,decimals,my_thd_charset);
str->set(*(double*) entry->value,decimals,thd_charset());
break;
case INT_RESULT:
str->set(*(longlong*) entry->value,my_thd_charset);
str->set(*(longlong*) entry->value,thd_charset());
break;
case STRING_RESULT:
if (str->copy(entry->value, entry->length-1))
......
......@@ -1469,7 +1469,7 @@ String *Item_func_format::val_str(String *str)
if ((null_value=args[0]->null_value))
return 0; /* purecov: inspected */
dec= decimals ? decimals+1 : 0;
str->set(nr,decimals,my_thd_charset);
str->set(nr,decimals,thd_charset());
str_length=str->length();
if (nr < 0)
str_length--; // Don't count sign
......
......@@ -200,7 +200,7 @@ String *Item_exists_subselect::val_str(String *str)
assign_null();
return 0;
}
str->set(value,my_thd_charset);
str->set(value,thd_charset());
return str;
}
......
......@@ -93,7 +93,7 @@ Item_sum_num::val_str(String *str)
double nr=val();
if (null_value)
return 0;
str->set(nr,decimals,my_thd_charset);
str->set(nr,decimals,thd_charset());
return str;
}
......@@ -359,13 +359,13 @@ Item_sum_hybrid::val_str(String *str)
case STRING_RESULT:
return &value;
case REAL_RESULT:
str->set(sum,decimals,my_thd_charset);
str->set(sum,decimals,thd_charset());
break;
case INT_RESULT:
if (unsigned_flag)
str->set((ulonglong) sum_int,my_thd_charset);
str->set((ulonglong) sum_int,thd_charset());
else
str->set((longlong) sum_int,my_thd_charset);
str->set((longlong) sum_int,thd_charset());
break;
}
return str; // Keep compiler happy
......@@ -810,7 +810,7 @@ String *Item_avg_field::val_str(String *str)
double nr=Item_avg_field::val();
if (null_value)
return 0;
str->set(nr,decimals,my_thd_charset);
str->set(nr,decimals,thd_charset());
return str;
}
......@@ -847,7 +847,7 @@ String *Item_std_field::val_str(String *str)
double nr=val();
if (null_value)
return 0;
str->set(nr,decimals,my_thd_charset);
str->set(nr,decimals,thd_charset());
return str;
}
......@@ -1177,7 +1177,7 @@ String *Item_sum_udf_float::val_str(String *str)
if (null_value)
return 0; /* purecov: inspected */
else
str->set(nr,decimals,my_thd_charset);
str->set(nr,decimals,thd_charset());
return str;
}
......@@ -1196,7 +1196,7 @@ String *Item_sum_udf_int::val_str(String *str)
if (null_value)
return 0;
else
str->set(nr,my_thd_charset);
str->set(nr,thd_charset());
return str;
}
......
......@@ -69,7 +69,7 @@ class Item_func_month :public Item_func
double val() { return (double) Item_func_month::val_int(); }
String *val_str(String *str)
{
str->set(val_int(), my_thd_charset);
str->set(val_int(), thd_charset());
return null_value ? 0 : str;
}
const char *func_name() const { return "month"; }
......@@ -177,7 +177,7 @@ class Item_func_weekday :public Item_func
longlong val_int();
double val() { return (double) val_int(); }
String *val_str(String *str) {
str->set(val_int(), my_thd_charset);
str->set(val_int(), thd_charset());
return null_value ? 0 : str;
}
const char *func_name() const { return "weekday"; }
......@@ -243,7 +243,7 @@ class Item_date :public Item_func
}
Field *tmp_table_field(TABLE *t_arg)
{
return (!t_arg) ? result_field : new Field_date(maybe_null, name, t_arg, my_thd_charset);
return (!t_arg) ? result_field : new Field_date(maybe_null, name, t_arg, thd_charset());
}
};
......@@ -261,7 +261,7 @@ class Item_date_func :public Item_str_func
Field *tmp_table_field(TABLE *t_arg)
{
return (!t_arg) ? result_field : new Field_datetime(maybe_null, name,
t_arg, my_thd_charset);
t_arg, thd_charset());
}
};
......@@ -288,7 +288,7 @@ class Item_func_curtime :public Item_func
Field *tmp_table_field(TABLE *t_arg)
{
return (!t_arg) ? result_field :
new Field_time(maybe_null, name, t_arg, my_thd_charset);
new Field_time(maybe_null, name, t_arg, thd_charset());
}
};
......@@ -381,7 +381,7 @@ class Item_func_sec_to_time :public Item_str_func
Field *tmp_table_field(TABLE *t_arg)
{
return (!t_arg) ? result_field :
new Field_time(maybe_null, name, t_arg, my_thd_charset);
new Field_time(maybe_null, name, t_arg, thd_charset());
}
};
......@@ -446,7 +446,7 @@ class Item_date_typecast :public Item_typecast
Field *tmp_table_field(TABLE *t_arg)
{
return (!t_arg) ? result_field :
new Field_date(maybe_null, name, t_arg, my_thd_charset);
new Field_date(maybe_null, name, t_arg, thd_charset());
}
};
......@@ -462,7 +462,7 @@ class Item_time_typecast :public Item_typecast
Field *tmp_table_field(TABLE *t_arg)
{
return (!t_arg) ? result_field :
new Field_time(maybe_null, name, t_arg, my_thd_charset);
new Field_time(maybe_null, name, t_arg, thd_charset());
}
};
......@@ -478,6 +478,6 @@ class Item_datetime_typecast :public Item_typecast
Field *tmp_table_field(TABLE *t_arg)
{
return (!t_arg) ? result_field : new Field_datetime(maybe_null, name,
t_arg, my_thd_charset);
t_arg, thd_charset());
}
};
......@@ -896,14 +896,14 @@ int collect_real(double *element, element_count count __attribute__((unused)),
TREE_INFO *info)
{
char buff[MAX_FIELD_WIDTH];
String s(buff, sizeof(buff),default_charset_info);
String s(buff, sizeof(buff),current_thd->thd_charset);
if (info->found)
info->str->append(',');
else
info->found = 1;
info->str->append('\'');
s.set(*element, info->item->decimals, my_thd_charset);
s.set(*element, info->item->decimals, current_thd->thd_charset);
info->str->append(s);
info->str->append('\'');
return 0;
......
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