summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <bar@mysql.com>2005-11-21 17:57:14 +0400
committerunknown <bar@mysql.com>2005-11-21 17:57:14 +0400
commitb50d01f4f5f6b19aa9a87cfbbb84bdddee62fa90 (patch)
tree3a55375958b1622a5abae8a3d262730bae90d37c /sql
parente8b14c4dbbe9be8a80e3a8eb68a36f441b1dde6d (diff)
parent4b5c33a75ca07fade8e9bd9893b05c28c89b3075 (diff)
downloadmariadb-git-b50d01f4f5f6b19aa9a87cfbbb84bdddee62fa90.tar.gz
Merge abarkov@bk-internal.mysql.com:/home/bk/mysql-5.0
into mysql.com:/usr/home/bar/mysql-5.0.b14255 sql/item_timefunc.cc: Auto merged
Diffstat (limited to 'sql')
-rw-r--r--sql/item_timefunc.cc44
1 files changed, 29 insertions, 15 deletions
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 2b0314bb287..54513d93636 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -2352,22 +2352,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;