diff options
author | unknown <bar@mysql.com> | 2004-10-29 17:00:39 +0500 |
---|---|---|
committer | unknown <bar@mysql.com> | 2004-10-29 17:00:39 +0500 |
commit | 6e781e11a9f7606b8b41532c382df9cf00617d17 (patch) | |
tree | 9cc9765d8b1a393421a6e3df083461c690d1c028 | |
parent | fcb322279eba22dcc29093d0212ea5a21f78ed59 (diff) | |
download | mariadb-git-6e781e11a9f7606b8b41532c382df9cf00617d17.tar.gz |
A fix according to Monty's request:
"uint *errors" is now a non-optional parameter in String:copy()
and copy_and_convert().
-rw-r--r-- | sql/field.cc | 15 | ||||
-rw-r--r-- | sql/item.cc | 4 | ||||
-rw-r--r-- | sql/item_cmpfunc.cc | 3 | ||||
-rw-r--r-- | sql/item_create.cc | 5 | ||||
-rw-r--r-- | sql/item_func.cc | 3 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 9 | ||||
-rw-r--r-- | sql/item_timefunc.cc | 4 | ||||
-rw-r--r-- | sql/protocol.cc | 3 | ||||
-rw-r--r-- | sql/sql_class.cc | 6 | ||||
-rw-r--r-- | sql/sql_parse.cc | 17 | ||||
-rw-r--r-- | sql/sql_show.cc | 6 | ||||
-rw-r--r-- | sql/sql_string.cc | 25 | ||||
-rw-r--r-- | sql/sql_string.h | 4 | ||||
-rw-r--r-- | sql/thr_malloc.cc | 5 |
14 files changed, 72 insertions, 37 deletions
diff --git a/sql/field.cc b/sql/field.cc index 261494d2125..4b833874221 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -531,7 +531,8 @@ int Field_decimal::store(const char *from, uint len, CHARSET_INFO *cs) /* Convert character set if the old one is multi byte */ if (cs->mbmaxlen > 1) { - tmp.copy(from, len, cs, &my_charset_bin); + uint dummy_errors; + tmp.copy(from, len, cs, &my_charset_bin, &dummy_errors); from= tmp.ptr(); len= tmp.length(); } @@ -5502,7 +5503,8 @@ int Field_enum::store(const char *from,uint length,CHARSET_INFO *cs) /* Convert character set if nesessary */ if (String::needs_conversion(length, cs, field_charset, ¬_used)) { - tmpstr.copy(from, length, cs, field_charset); + uint dummy_errors; + tmpstr.copy(from, length, cs, field_charset, &dummy_errors); from= tmpstr.ptr(); length= tmpstr.length(); } @@ -5650,10 +5652,11 @@ void Field_enum::sql_type(String &res) const bool flag=0; for (const char **pos= typelib->type_names; *pos; pos++) { + uint dummy_errors; if (flag) res.append(','); /* convert to res.charset() == utf8, then quote */ - enum_item.copy(*pos, strlen(*pos), charset(), res.charset()); + enum_item.copy(*pos, strlen(*pos), charset(), res.charset(), &dummy_errors); append_unescaped(&res, enum_item.ptr(), enum_item.length()); flag= 1; } @@ -5684,7 +5687,8 @@ int Field_set::store(const char *from,uint length,CHARSET_INFO *cs) /* Convert character set if nesessary */ if (String::needs_conversion(length, cs, field_charset, ¬_used_offset)) { - tmpstr.copy(from, length, cs, field_charset); + uint dummy_errors; + tmpstr.copy(from, length, cs, field_charset, &dummy_errors); from= tmpstr.ptr(); length= tmpstr.length(); } @@ -5760,10 +5764,11 @@ void Field_set::sql_type(String &res) const bool flag=0; for (const char **pos= typelib->type_names; *pos; pos++) { + uint dummy_errors; if (flag) res.append(','); /* convert to res.charset() == utf8, then quote */ - set_item.copy(*pos, strlen(*pos), charset(), res.charset()); + set_item.copy(*pos, strlen(*pos), charset(), res.charset(), &dummy_errors); append_unescaped(&res, set_item.ptr(), set_item.length()); flag= 1; } diff --git a/sql/item.cc b/sql/item.cc index 18025d6d689..46215fd78ed 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -818,7 +818,9 @@ bool Item_param::set_str(const char *str, ulong length) Assign string with no conversion: data is converted only after it's been written to the binary log. */ - if (str_value.copy(str, length, &my_charset_bin, &my_charset_bin)) + uint dummy_errors; + if (str_value.copy(str, length, &my_charset_bin, &my_charset_bin, + &dummy_errors)) DBUG_RETURN(TRUE); state= STRING_VALUE; maybe_null= 0; diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index dc0377c791f..d9db07e2289 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1832,8 +1832,9 @@ void Item_func_in::fix_length_and_dec() { Item_string *conv; String tmp, cstr, *ostr= arg[0]->val_str(&tmp); + uint dummy_errors; cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), - cmp_collation.collation); + cmp_collation.collation, &dummy_errors); conv= new Item_string(cstr.ptr(),cstr.length(), cstr.charset(), arg[0]->collation.derivation); conv->str_value.copy(); diff --git a/sql/item_create.cc b/sql/item_create.cc index c98c7892c26..800489a6a72 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -377,7 +377,10 @@ Item *create_func_space(Item *a) { sp= new Item_string("",0,cs); if (sp) - sp->str_value.copy(" ",1,&my_charset_latin1,cs); + { + uint dummy_errors; + sp->str_value.copy(" ", 1, &my_charset_latin1, cs, &dummy_errors); + } } else { diff --git a/sql/item_func.cc b/sql/item_func.cc index 3cb125d2868..50843d3bf76 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -2906,8 +2906,9 @@ void Item_func_match::init_search(bool no_order) if (ft_tmp->charset() != cmp_collation.collation) { + uint dummy_errors; search_value.copy(ft_tmp->ptr(), ft_tmp->length(), ft_tmp->charset(), - cmp_collation.collation); + cmp_collation.collation, &dummy_errors); ft_tmp= &search_value; } diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 2d9f7e7bff8..5eda89ef21e 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2160,13 +2160,14 @@ String *Item_func_conv_charset::val_str(String *str) { DBUG_ASSERT(fixed == 1); String *arg= args[0]->val_str(str); + uint dummy_errors; if (!arg) { null_value=1; return 0; } null_value= str_value.copy(arg->ptr(),arg->length(),arg->charset(), - conv_charset); + conv_charset, &dummy_errors); return null_value ? 0 : &str_value; } @@ -2249,11 +2250,12 @@ String *Item_func_charset::val_str(String *str) { DBUG_ASSERT(fixed == 1); String *res = args[0]->val_str(str); + uint dummy_errors; if ((null_value=(args[0]->null_value || !res->charset()))) return 0; str->copy(res->charset()->csname,strlen(res->charset()->csname), - &my_charset_latin1, collation.collation); + &my_charset_latin1, collation.collation, &dummy_errors); return str; } @@ -2261,11 +2263,12 @@ String *Item_func_collation::val_str(String *str) { DBUG_ASSERT(fixed == 1); String *res = args[0]->val_str(str); + uint dummy_errors; if ((null_value=(args[0]->null_value || !res->charset()))) return 0; str->copy(res->charset()->name,strlen(res->charset()->name), - &my_charset_latin1, collation.collation); + &my_charset_latin1, collation.collation, &dummy_errors); return str; } diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 3c8dbb013a9..f621953a5bc 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2121,8 +2121,10 @@ String *Item_char_typecast::val_str(String *str) else { // Convert character set if differ + uint dummy_errors; if (!(res1= args[0]->val_str(&tmp_value)) || - str->copy(res1->ptr(), res1->length(),res1->charset(), cast_cs)) + str->copy(res1->ptr(), res1->length(), res1->charset(), + cast_cs, &dummy_errors)) { null_value= 1; return 0; diff --git a/sql/protocol.cc b/sql/protocol.cc index 887177c0a19..598d102ec29 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -713,7 +713,8 @@ bool Protocol::store_string_aux(const char *from, uint length, fromcs != &my_charset_bin && tocs != &my_charset_bin) { - return convert->copy(from, length, fromcs, tocs) || + uint dummy_errors; + return convert->copy(from, length, fromcs, tocs, &dummy_errors) || net_store_data(convert->ptr(), convert->length()); } return net_store_data(from, length); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index abe00027b07..7ad20967de0 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -508,13 +508,14 @@ bool THD::convert_string(LEX_STRING *to, CHARSET_INFO *to_cs, { DBUG_ENTER("convert_string"); size_s new_length= to_cs->mbmaxlen * from_length; + uint dummy_errors; if (!(to->str= alloc(new_length+1))) { to->length= 0; // Safety fix DBUG_RETURN(1); // EOM } to->length= copy_and_convert((char*) to->str, new_length, to_cs, - from, from_length, from_cs); + from, from_length, from_cs, &dummy_errors); to->str[to->length]=0; // Safety DBUG_RETURN(0); } @@ -537,7 +538,8 @@ bool THD::convert_string(LEX_STRING *to, CHARSET_INFO *to_cs, bool THD::convert_string(String *s, CHARSET_INFO *from_cs, CHARSET_INFO *to_cs) { - if (convert_buffer.copy(s->ptr(), s->length(), from_cs, to_cs)) + uint dummy_errors; + if (convert_buffer.copy(s->ptr(), s->length(), from_cs, to_cs, &dummy_errors)) return TRUE; /* If convert_buffer >> s copying is more efficient long term */ if (convert_buffer.alloced_length() >= convert_buffer.length() * 2 || diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index d1f460d918e..dce32720184 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -882,18 +882,20 @@ static int check_connection(THD *thd) /* Since 4.1 all database names are stored in utf8 */ if (db) { + uint dummy_errors; db_buff[copy_and_convert(db_buff, sizeof(db_buff)-1, system_charset_info, db, strlen(db), - thd->charset())]= 0; + thd->charset(), &dummy_errors)]= 0; db= db_buff; } if (user) { + uint dummy_errors; user_buff[copy_and_convert(user_buff, sizeof(user_buff)-1, system_charset_info, user, strlen(user), - thd->charset())]= '\0'; + thd->charset(), &dummy_errors)]= '\0'; user= user_buff; } @@ -1380,9 +1382,10 @@ bool dispatch_command(enum enum_server_command command, THD *thd, } #endif /* Convert database name to utf8 */ + uint dummy_errors; db_buff[copy_and_convert(db_buff, sizeof(db_buff)-1, system_charset_info, db, strlen(db), - thd->charset())]= 0; + thd->charset(), &dummy_errors)]= 0; db= db_buff; /* Save user and privileges */ @@ -2066,8 +2069,12 @@ mysql_execute_command(THD *thd) } if (need_conversion) - query_len= copy_and_convert(query_str, query_len, to_cs, pstr->ptr(), - pstr->length(), pstr->charset()); + { + uint dummy_errors; + query_len= copy_and_convert(query_str, query_len, to_cs, + pstr->ptr(), pstr->length(), + pstr->charset(), &dummy_errors); + } else memcpy(query_str, pstr->ptr(), pstr->length()); query_str[query_len]= 0; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 3bf11c0d6b8..2af4cb3fc23 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -752,8 +752,9 @@ mysqld_show_fields(THD *thd, TABLE_LIST *table_list,const char *wild, String def(tmp1,sizeof(tmp1), system_charset_info); type.set(tmp, sizeof(tmp), field->charset()); field->val_str(&type); + uint dummy_errors; def.copy(type.ptr(), type.length(), type.charset(), - system_charset_info); + system_charset_info, &dummy_errors); protocol->store(def.ptr(), def.length(), def.charset()); } else if (field->unireg_check == Field::NEXT_NUMBER || @@ -1338,9 +1339,10 @@ store_create_info(THD *thd, TABLE *table, String *packet) if (type.length()) { String def_val; + uint dummy_errors; /* convert to system_charset_info == utf8 */ def_val.copy(type.ptr(), type.length(), field->charset(), - system_charset_info); + system_charset_info, &dummy_errors); append_unescaped(packet, def_val.ptr(), def_val.length()); } else diff --git a/sql/sql_string.cc b/sql/sql_string.cc index 30559496fde..6b2bb07fb8c 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -121,12 +121,13 @@ bool String::set(ulonglong num, CHARSET_INFO *cs) bool String::set(double num,uint decimals, CHARSET_INFO *cs) { char buff[331]; + uint dummy_errors; str_charset=cs; if (decimals >= NOT_FIXED_DEC) { uint32 len= my_sprintf(buff,(buff, "%.14g",num));// Enough for a DATETIME - return copy(buff, len, &my_charset_latin1, cs); + return copy(buff, len, &my_charset_latin1, cs, &dummy_errors); } #ifdef HAVE_FCONVERT int decpt,sign; @@ -191,7 +192,8 @@ end: #else sprintf(buff,"%.*f",(int) decimals,num); #endif - return copy(buff,(uint32) strlen(buff), &my_charset_latin1, cs); + return copy(buff,(uint32) strlen(buff), &my_charset_latin1, cs, + &dummy_errors); #endif } @@ -336,14 +338,12 @@ bool String::copy(const char *str, uint32 arg_length, uint32 offset; if (!needs_conversion(arg_length, from_cs, to_cs, &offset)) { - if (errors) - *errors= 0; + *errors= 0; return copy(str, arg_length, to_cs); } if ((from_cs == &my_charset_bin) && offset) { - if (errors) - *errors= 0; + *errors= 0; return copy_aligned(str, arg_length, offset, to_cs); } uint32 new_length= to_cs->mbmaxlen*arg_length; @@ -382,7 +382,8 @@ bool String::set_ascii(const char *str, uint32 arg_length) set(str, arg_length, str_charset); return 0; } - return copy(str, arg_length, &my_charset_latin1, str_charset); + uint dummy_errors; + return copy(str, arg_length, &my_charset_latin1, str_charset, &dummy_errors); } @@ -436,10 +437,12 @@ bool String::append(const char *s,uint32 arg_length) if (str_charset->mbminlen > 1) { uint32 add_length=arg_length * str_charset->mbmaxlen; + uint dummy_errors; if (realloc(str_length+ add_length)) return TRUE; str_length+= copy_and_convert(Ptr+str_length, add_length, str_charset, - s, arg_length, &my_charset_latin1); + s, arg_length, &my_charset_latin1, + &dummy_errors); return FALSE; } @@ -476,10 +479,11 @@ bool String::append(const char *s,uint32 arg_length, CHARSET_INFO *cs) if (needs_conversion(arg_length, cs, str_charset, &dummy_offset)) { uint32 add_length= arg_length / cs->mbminlen * str_charset->mbmaxlen; + uint dummy_errors; if (realloc(str_length + add_length)) return TRUE; str_length+= copy_and_convert(Ptr+str_length, add_length, str_charset, - s, arg_length, cs); + s, arg_length, cs, &dummy_errors); } else { @@ -816,8 +820,7 @@ outp: else break; } - if (errors) - *errors= error_count; + *errors= error_count; return (uint32) (to - to_start); } diff --git a/sql/sql_string.h b/sql/sql_string.h index de8f4af58d9..a8fb9574c0b 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -29,7 +29,7 @@ int sortcmp(const String *a,const String *b, CHARSET_INFO *cs); String *copy_if_not_alloced(String *a,String *b,uint32 arg_length); uint32 copy_and_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs, const char *from, uint32 from_length, - CHARSET_INFO *from_cs, uint *errors= 0); + CHARSET_INFO *from_cs, uint *errors); class String { @@ -199,7 +199,7 @@ public: CHARSET_INFO *cs); bool set_or_copy_aligned(const char *s, uint32 arg_length, CHARSET_INFO *cs); bool copy(const char*s,uint32 arg_length, CHARSET_INFO *csfrom, - CHARSET_INFO *csto, uint *errors= 0); + CHARSET_INFO *csto, uint *errors); bool append(const String &s); bool append(const char *s); bool append(const char *s,uint32 arg_length); diff --git a/sql/thr_malloc.cc b/sql/thr_malloc.cc index fa678ec7de2..0df60858bcb 100644 --- a/sql/thr_malloc.cc +++ b/sql/thr_malloc.cc @@ -108,8 +108,11 @@ char *sql_strmake_with_convert(const char *str, uint32 arg_length, memcpy(pos, str, new_length); } else + { + uint dummy_errors; new_length= copy_and_convert((char*) pos, new_length, to_cs, str, - arg_length, from_cs); + arg_length, from_cs, &dummy_errors); + } pos[new_length]= 0; *result_length= new_length; return pos; |