diff options
author | bar@mysql.com <> | 2005-10-25 15:36:39 +0500 |
---|---|---|
committer | bar@mysql.com <> | 2005-10-25 15:36:39 +0500 |
commit | c7db18719e06fc3330216032a05c2e66453d9169 (patch) | |
tree | c55b70882640f5c49ad3be26fe5917053c1033cd /sql/item_timefunc.cc | |
parent | d24027fa7963ca11f4379428ed3a1f033d8732f2 (diff) | |
download | mariadb-git-c7db18719e06fc3330216032a05c2e66453d9169.tar.gz |
Bug#14255 CAST(x AS BINARY(N)) does not pad
type_binary.result, type_binary.test:
Adding test case.
item_timefunc.cc:
Padding code was added.
Diffstat (limited to 'sql/item_timefunc.cc')
-rw-r--r-- | sql/item_timefunc.cc | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 7f94c19647e..e43b0cdf46e 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2327,22 +2327,36 @@ String *Item_char_typecast::val_str(String *str) and the result is longer than cast length, e.g. CAST('string' AS CHAR(1)) */ - if (cast_length >= 0 && - (res->length() > (length= (uint32) res->charpos(cast_length)))) - { // Safe even if const arg - char char_type[40]; - my_snprintf(char_type, sizeof(char_type), "CHAR(%lu)", length); - - if (!res->alloced_length()) - { // Don't change const str - str_value= *res; // Not malloced string - res= &str_value; + if (cast_length >= 0) + { + if (res->length() > (length= (uint32) res->charpos(cast_length))) + { // Safe even if const arg + char char_type[40]; + my_snprintf(char_type, sizeof(char_type), "CHAR(%lu)", length); + + if (!res->alloced_length()) + { // Don't change const str + str_value= *res; // Not malloced string + res= &str_value; + } + push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_TRUNCATED_WRONG_VALUE, + ER(ER_TRUNCATED_WRONG_VALUE), char_type, + res->c_ptr_safe()); + res->length((uint) length); + } + else if (cast_cs == &my_charset_bin && res->length() < (uint) cast_length) + { + if (res->alloced_length() < (uint) cast_length) + { + str->alloc(cast_length); + str->copy(*res); + res= str; + } + bzero((char*) res->ptr() + res->length(), + (uint) cast_length - res->length()); + res->length(cast_length); } - push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, - ER_TRUNCATED_WRONG_VALUE, - ER(ER_TRUNCATED_WRONG_VALUE), char_type, - res->c_ptr_safe()); - res->length((uint) length); } null_value= 0; return res; |