diff options
author | unknown <bar@mysql.com> | 2005-11-07 12:34:19 +0400 |
---|---|---|
committer | unknown <bar@mysql.com> | 2005-11-07 12:34:19 +0400 |
commit | 85cc43802bee44bcf02b459812ac8d77aa83a85f (patch) | |
tree | 8e98af338f584a95ea86d3f6720564cbd14a6f1c /sql/item_strfunc.cc | |
parent | a67e6fdf8ba67fcefd7d2009e3cef2a45c68df25 (diff) | |
download | mariadb-git-85cc43802bee44bcf02b459812ac8d77aa83a85f.tar.gz |
Bug#14146 CHAR(...USING ...) and CONVERT(CHAR(...) USING...) produce different results
ctype_utf8.result, ctype_utf8.test:
Adding test case.
item_strfunc.cc:
item_strfunc.h:
Moving the well formed checking code into a method,
to reuse in several Item_func_xxx. Reusing the new
method in Item_func_char and Item_func_charset_conv.
sql/item_strfunc.h:
Bug#14146 CHAR(...USING ...) and CONVERT(CHAR(...) USING...) produce different results
Moving the well formed checking code into a method,
to reuse in several Item_func_xxx.
sql/item_strfunc.cc:
Moving the well formed checking code into a method,
to reuse in several Item_func_xxx.
mysql-test/t/ctype_utf8.test:
Adding test case.
mysql-test/r/ctype_utf8.result:
Adding test case.
Diffstat (limited to 'sql/item_strfunc.cc')
-rw-r--r-- | sql/item_strfunc.cc | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 1e8fe2e695f..b4cdacd4bc0 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -48,6 +48,38 @@ static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, } +String *Item_str_func::check_well_formed_result(String *str) +{ + /* Check whether we got a well-formed string */ + CHARSET_INFO *cs= str->charset(); + int well_formed_error; + uint wlen= cs->cset->well_formed_len(cs, + str->ptr(), str->ptr() + str->length(), + str->length(), &well_formed_error); + if (wlen < str->length()) + { + THD *thd= current_thd; + char hexbuf[7]; + enum MYSQL_ERROR::enum_warning_level level; + uint diff= str->length() - wlen; + set_if_smaller(diff, 3); + octet2hex(hexbuf, str->ptr() + wlen, diff); + if (thd->variables.sql_mode & + (MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES)) + { + level= MYSQL_ERROR::WARN_LEVEL_ERROR; + null_value= 1; + str= 0; + } + else + level= MYSQL_ERROR::WARN_LEVEL_WARN; + push_warning_printf(thd, level, ER_INVALID_CHARACTER_STRING, + ER(ER_INVALID_CHARACTER_STRING), cs->csname, hexbuf); + } + return str; +} + + double Item_str_func::val_real() { DBUG_ASSERT(fixed == 1); @@ -1984,34 +2016,7 @@ String *Item_func_char::val_str(String *str) } str->set_charset(collation.collation); str->realloc(str->length()); // Add end 0 (for Purify) - - /* Check whether we got a well-formed string */ - CHARSET_INFO *cs= collation.collation; - int well_formed_error; - uint wlen= cs->cset->well_formed_len(cs, - str->ptr(), str->ptr() + str->length(), - str->length(), &well_formed_error); - if (wlen < str->length()) - { - THD *thd= current_thd; - char hexbuf[7]; - enum MYSQL_ERROR::enum_warning_level level; - uint diff= str->length() - wlen; - set_if_smaller(diff, 3); - octet2hex(hexbuf, str->ptr() + wlen, diff); - if (thd->variables.sql_mode & - (MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES)) - { - level= MYSQL_ERROR::WARN_LEVEL_ERROR; - null_value= 1; - str= 0; - } - else - level= MYSQL_ERROR::WARN_LEVEL_WARN; - push_warning_printf(thd, level, ER_INVALID_CHARACTER_STRING, - ER(ER_INVALID_CHARACTER_STRING), cs->csname, hexbuf); - } - return str; + return check_well_formed_result(str); } @@ -2320,7 +2325,7 @@ String *Item_func_conv_charset::val_str(String *str) } null_value= str_value.copy(arg->ptr(),arg->length(),arg->charset(), conv_charset, &dummy_errors); - return null_value ? 0 : &str_value; + return null_value ? 0 : check_well_formed_result(&str_value); } void Item_func_conv_charset::fix_length_and_dec() |