Commit 86b63337 authored by bar@bar.mysql.r18.ru's avatar bar@bar.mysql.r18.ru

Some charset code clean-ups

parent 5d45eae0
...@@ -198,7 +198,8 @@ class Field { ...@@ -198,7 +198,8 @@ class Field {
uint fill_cache_field(struct st_cache_field *copy); uint fill_cache_field(struct st_cache_field *copy);
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 CHARSET_INFO *charset(void) { return my_charset_bin; } virtual CHARSET_INFO *charset(void) const { return my_charset_bin; }
virtual void set_charset(CHARSET_INFO *charset) { }
friend bool reopen_table(THD *,struct st_table *,bool); friend bool reopen_table(THD *,struct st_table *,bool);
friend int cre_myisam(my_string name, register TABLE *form, uint options, friend int cre_myisam(my_string name, register TABLE *form, uint options,
ulonglong auto_increment_value); ulonglong auto_increment_value);
...@@ -260,9 +261,9 @@ class Field_str :public Field { ...@@ -260,9 +261,9 @@ class Field_str :public Field {
uint decimals() const { return NOT_FIXED_DEC; } uint decimals() const { return NOT_FIXED_DEC; }
void make_field(Send_field *); void make_field(Send_field *);
uint size_of() const { return sizeof(*this); } uint size_of() const { return sizeof(*this); }
CHARSET_INFO *charset(void) { return field_charset; } CHARSET_INFO *charset(void) const { return field_charset; }
inline void set_charset(CHARSET_INFO *charset) { field_charset=charset; } void set_charset(CHARSET_INFO *charset) { field_charset=charset; }
bool binary() const { return field_charset->state & MY_CS_BINSORT ? 1 : 0; } bool binary() const { return field_charset->state & MY_CS_BINSORT ? 1 : 0; }
inline int cmp_image(char *buff,uint length) inline int cmp_image(char *buff,uint length)
{ {
......
...@@ -525,8 +525,7 @@ void field_conv(Field *to,Field *from) ...@@ -525,8 +525,7 @@ void field_conv(Field *to,Field *from)
if (!blob->value.is_alloced() && if (!blob->value.is_alloced() &&
from->real_type() != FIELD_TYPE_STRING) from->real_type() != FIELD_TYPE_STRING)
blob->value.copy(); blob->value.copy();
blob->store(blob->value.ptr(),blob->value.length(), blob->store(blob->value.ptr(),blob->value.length(),to->charset());
to->binary()?default_charset_info:((Field_str*)to)->charset());
return; return;
} }
if ((from->result_type() == STRING_RESULT && if ((from->result_type() == STRING_RESULT &&
...@@ -538,8 +537,7 @@ void field_conv(Field *to,Field *from) ...@@ -538,8 +537,7 @@ void field_conv(Field *to,Field *from)
char buff[MAX_FIELD_WIDTH]; char buff[MAX_FIELD_WIDTH];
String result(buff,sizeof(buff),default_charset_info); String result(buff,sizeof(buff),default_charset_info);
from->val_str(&result,&result); from->val_str(&result,&result);
to->store(result.c_ptr_quick(),result.length(), to->store(result.c_ptr_quick(),result.length(),to->charset());
to->binary()?default_charset_info:((Field_str*)to)->charset());
// QQ: what to do if "from" and "to" are of dirrent charsets? // QQ: what to do if "from" and "to" are of dirrent charsets?
} }
else if (from->result_type() == REAL_RESULT) else if (from->result_type() == REAL_RESULT)
......
...@@ -75,7 +75,7 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length, ...@@ -75,7 +75,7 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
uchar **sort_keys; uchar **sort_keys;
IO_CACHE tempfile, buffpek_pointers, *selected_records_file, *outfile; IO_CACHE tempfile, buffpek_pointers, *selected_records_file, *outfile;
SORTPARAM param; SORTPARAM param;
CHARSET_INFO *charset=table->table_charset; CHARSET_INFO *charset=my_charset_bin;
DBUG_ENTER("filesort"); DBUG_ENTER("filesort");
DBUG_EXECUTE("info",TEST_filesort(sortorder,s_length);); DBUG_EXECUTE("info",TEST_filesort(sortorder,s_length););
#ifdef SKIP_DBUG_IN_FILESORT #ifdef SKIP_DBUG_IN_FILESORT
...@@ -85,8 +85,7 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length, ...@@ -85,8 +85,7 @@ ha_rows filesort(THD *thd, TABLE *table, SORT_FIELD *sortorder, uint s_length,
// BAR TODO: this is not absolutely correct, but OK for now // BAR TODO: this is not absolutely correct, but OK for now
for(i=0;i<table->fields;i++) for(i=0;i<table->fields;i++)
if (!table->field[i]->binary()) if (!table->field[i]->binary())
charset=((Field_str*)(table->field[i]))->charset(); charset=table->field[i]->charset();
charset=charset?charset:default_charset_info;
// /BAR TODO // /BAR TODO
outfile= table->io_cache; outfile= table->io_cache;
...@@ -930,7 +929,7 @@ sortlength(SORT_FIELD *sortorder, uint s_length) ...@@ -930,7 +929,7 @@ sortlength(SORT_FIELD *sortorder, uint s_length)
#ifdef USE_STRCOLL #ifdef USE_STRCOLL
if (!sortorder->field->binary()) if (!sortorder->field->binary())
{ {
CHARSET_INFO *cs=((Field_str*)(sortorder->field))->charset(); CHARSET_INFO *cs=sortorder->field->charset();
if (use_strnxfrm(cs)) if (use_strnxfrm(cs))
sortorder->length= sortorder->length*cs->strxfrm_multiply; sortorder->length= sortorder->length*cs->strxfrm_multiply;
} }
......
...@@ -291,7 +291,7 @@ int ha_heap::create(const char *name, TABLE *table, ...@@ -291,7 +291,7 @@ int ha_heap::create(const char *name, TABLE *table,
seg->start= (uint) key_part->offset; seg->start= (uint) key_part->offset;
seg->length= (uint) key_part->length; seg->length= (uint) key_part->length;
seg->flag = 0; seg->flag = 0;
seg->charset= field->binary() ? NULL : ((Field_str*)field)->charset(); seg->charset= field->charset();
if (field->null_ptr) if (field->null_ptr)
{ {
seg->null_bit= field->null_bit; seg->null_bit= field->null_bit;
......
...@@ -1078,8 +1078,7 @@ int ha_myisam::create(const char *name, register TABLE *table, ...@@ -1078,8 +1078,7 @@ int ha_myisam::create(const char *name, register TABLE *table,
keydef[i].seg[j].start= pos->key_part[j].offset; keydef[i].seg[j].start= pos->key_part[j].offset;
keydef[i].seg[j].length= pos->key_part[j].length; keydef[i].seg[j].length= pos->key_part[j].length;
keydef[i].seg[j].bit_start=keydef[i].seg[j].bit_end=0; keydef[i].seg[j].bit_start=keydef[i].seg[j].bit_end=0;
keydef[i].seg[j].language = field->binary() ? MY_CHARSET_CURRENT : keydef[i].seg[j].language = field->charset()->number;
((Field_str*)field)->charset()->number;
if (field->null_ptr) if (field->null_ptr)
{ {
......
...@@ -313,15 +313,15 @@ void Item_param::set_double(double value) ...@@ -313,15 +313,15 @@ void Item_param::set_double(double value)
} }
void Item_param::set_value(const char *str, uint length) void Item_param::set_value(const char *str, uint length, CHARSET_INFO *cs)
{ {
str_value.set(str,length,default_charset_info); str_value.set(str,length,cs);
item_result_type = STRING_RESULT; item_result_type = STRING_RESULT;
item_type = STRING_ITEM; item_type = STRING_ITEM;
} }
void Item_param::set_longdata(const char *str, ulong length) void Item_param::set_longdata(const char *str, ulong length, CHARSET_INFO *cs)
{ {
/* TODO: Fix this for binary handling by making use of /* TODO: Fix this for binary handling by making use of
buffer_type.. buffer_type..
...@@ -346,10 +346,8 @@ int Item_param::save_in_field(Field *field) ...@@ -346,10 +346,8 @@ int Item_param::save_in_field(Field *field)
double nr=val(); double nr=val();
return (field->store(nr)) ? -1 : 0; return (field->store(nr)) ? -1 : 0;
} }
String *result; String *result=val_str(&str_value);
CHARSET_INFO *cs=default_charset_info; //fix this return (field->store(result->ptr(),result->length(),field->charset())) ? -1 : 0;
result=val_str(&str_value);
return (field->store(result->ptr(),result->length(),cs)) ? -1 : 0;
} }
...@@ -658,7 +656,7 @@ int Item::save_in_field(Field *field) ...@@ -658,7 +656,7 @@ int Item::save_in_field(Field *field)
field->result_type() == STRING_RESULT) field->result_type() == STRING_RESULT)
{ {
String *result; String *result;
CHARSET_INFO *cs=field->binary()?my_charset_bin:((Field_str*)field)->charset(); CHARSET_INFO *cs=field->charset();
char buff[MAX_FIELD_WIDTH]; // Alloc buffer for small columns char buff[MAX_FIELD_WIDTH]; // Alloc buffer for small columns
str_value.set_quick(buff,sizeof(buff),cs); str_value.set_quick(buff,sizeof(buff),cs);
result=val_str(&str_value); result=val_str(&str_value);
...@@ -690,7 +688,7 @@ int Item::save_in_field(Field *field) ...@@ -690,7 +688,7 @@ int Item::save_in_field(Field *field)
int Item_string::save_in_field(Field *field) int Item_string::save_in_field(Field *field)
{ {
String *result; String *result;
CHARSET_INFO *cs=field->binary()?my_charset_bin:((Field_str*)field)->charset(); CHARSET_INFO *cs=field->charset();
result=val_str(&str_value); result=val_str(&str_value);
if (null_value) if (null_value)
return set_field_to_null(field); return set_field_to_null(field);
...@@ -763,7 +761,7 @@ longlong Item_varbinary::val_int() ...@@ -763,7 +761,7 @@ longlong Item_varbinary::val_int()
int Item_varbinary::save_in_field(Field *field) int Item_varbinary::save_in_field(Field *field)
{ {
int error; int error;
CHARSET_INFO *cs=field->binary()?default_charset_info:((Field_str*)field)->charset(); CHARSET_INFO *cs=field->charset();
field->set_notnull(); field->set_notnull();
if (field->result_type() == STRING_RESULT) if (field->result_type() == STRING_RESULT)
{ {
......
...@@ -196,10 +196,10 @@ class Item_param :public Item ...@@ -196,10 +196,10 @@ class Item_param :public Item
void set_null(); void set_null();
void set_int(longlong i); void set_int(longlong i);
void set_double(double i); void set_double(double i);
void set_value(const char *str, uint length); void set_value(const char *str, uint length, CHARSET_INFO *cs);
void set_long_str(const char *str, ulong length); void set_long_str(const char *str, ulong length, CHARSET_INFO *cs);
void set_long_binary(const char *str, ulong length); void set_long_binary(const char *str, ulong length, CHARSET_INFO *cs);
void set_longdata(const char *str, ulong length); void set_longdata(const char *str, ulong length, CHARSET_INFO *cs);
void set_long_end(); void set_long_end();
void reset() {} void reset() {}
enum Item_result result_type () const enum Item_result result_type () const
......
...@@ -1637,7 +1637,7 @@ String *Item_func_char::val_str(String *str) ...@@ -1637,7 +1637,7 @@ String *Item_func_char::val_str(String *str)
int32 num=(int32) args[i]->val_int(); int32 num=(int32) args[i]->val_int();
if (!args[i]->null_value) if (!args[i]->null_value)
#ifdef USE_MB #ifdef USE_MB
if (use_mb(default_charset_info)) if (use_mb(charset()))
{ {
if (num&0xFF000000L) { if (num&0xFF000000L) {
str->append((char)(num>>24)); str->append((char)(num>>24));
......
...@@ -31,28 +31,28 @@ ...@@ -31,28 +31,28 @@
static String month_names[] = static String month_names[] =
{ {
String("January", default_charset_info), String("January", my_charset_latin1),
String("February", default_charset_info), String("February", my_charset_latin1),
String("March", default_charset_info), String("March", my_charset_latin1),
String("April", default_charset_info), String("April", my_charset_latin1),
String("May", default_charset_info), String("May", my_charset_latin1),
String("June", default_charset_info), String("June", my_charset_latin1),
String("July", default_charset_info), String("July", my_charset_latin1),
String("August", default_charset_info), String("August", my_charset_latin1),
String("September", default_charset_info), String("September", my_charset_latin1),
String("October", default_charset_info), String("October", my_charset_latin1),
String("November", default_charset_info), String("November", my_charset_latin1),
String("December", default_charset_info) String("December", my_charset_latin1)
}; };
static String day_names[] = static String day_names[] =
{ {
String("Monday", default_charset_info), String("Monday", my_charset_latin1),
String("Tuesday", default_charset_info), String("Tuesday", my_charset_latin1),
String("Wednesday", default_charset_info), String("Wednesday", my_charset_latin1),
String("Thursday", default_charset_info), String("Thursday", my_charset_latin1),
String("Friday", default_charset_info), String("Friday", my_charset_latin1),
String("Saturday", default_charset_info), String("Saturday", my_charset_latin1),
String("Sunday", default_charset_info) String("Sunday", my_charset_latin1)
}; };
/* /*
......
...@@ -976,7 +976,7 @@ get_mm_leaf(PARAM *param, Field *field, KEY_PART *key_part, ...@@ -976,7 +976,7 @@ get_mm_leaf(PARAM *param, Field *field, KEY_PART *key_part,
&min_length,&max_length); &min_length,&max_length);
else else
{ {
CHARSET_INFO *charset=((Field_str*)(field))->charset(); CHARSET_INFO *charset=field->charset();
#ifdef USE_STRCOLL #ifdef USE_STRCOLL
if (use_strnxfrm(charset)) if (use_strnxfrm(charset))
like_error= my_like_range(charset, like_error= my_like_range(charset,
......
...@@ -271,7 +271,7 @@ static uchar* setup_param_field(Item_param *item_param, ...@@ -271,7 +271,7 @@ static uchar* setup_param_field(Item_param *item_param,
default: default:
{ {
ulong len=get_param_length(&pos); ulong len=get_param_length(&pos);
item_param->set_value((const char*)pos,len); item_param->set_value((const char*)pos,len,current_thd->thd_charset);
pos+=len; pos+=len;
} }
} }
...@@ -829,7 +829,7 @@ void mysql_stmt_get_longdata(THD *thd, char *pos, ulong packet_length) ...@@ -829,7 +829,7 @@ void mysql_stmt_get_longdata(THD *thd, char *pos, ulong packet_length)
sprintf(stmt->last_error, ER(ER_WRONG_ARGUMENTS), "get_longdata"); sprintf(stmt->last_error, ER(ER_WRONG_ARGUMENTS), "get_longdata");
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
stmt->param[param_number].set_longdata(pos, packet_length-9); stmt->param[param_number].set_longdata(pos, packet_length-9, current_thd->thd_charset);
stmt->long_data_used= 1; stmt->long_data_used= 1;
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -4231,9 +4231,7 @@ static bool create_myisam_tmp_table(TABLE *table,TMP_TABLE_PARAM *param, ...@@ -4231,9 +4231,7 @@ static bool create_myisam_tmp_table(TABLE *table,TMP_TABLE_PARAM *param,
{ {
Field *field=keyinfo->key_part[i].field; Field *field=keyinfo->key_part[i].field;
seg->flag= 0; seg->flag= 0;
seg->language= field->binary() ? MY_CHARSET_CURRENT : seg->language= field->charset()->number;
((Field_str*)field)->charset()->number;
seg->length= keyinfo->key_part[i].length; seg->length= keyinfo->key_part[i].length;
seg->start= keyinfo->key_part[i].offset; seg->start= keyinfo->key_part[i].offset;
if (field->flags & BLOB_FLAG) if (field->flags & BLOB_FLAG)
......
...@@ -392,8 +392,7 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, ...@@ -392,8 +392,7 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag,
outparam->fieldnames.type_names[i], outparam->fieldnames.type_names[i],
outparam); outparam);
reg_field->comment=comment; reg_field->comment=comment;
if (!reg_field->binary()) reg_field->set_charset(charset);
((Field_str*) reg_field)->set_charset(charset);
if (!(reg_field->flags & NOT_NULL_FLAG)) if (!(reg_field->flags & NOT_NULL_FLAG))
{ {
if ((null_bit<<=1) == 256) if ((null_bit<<=1) == 256)
......
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