mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Merge abarkov@bk-internal.mysql.com:/home/bk/mysql-5.0
into mysql.com:/usr/home/bar/mysql-5.0.b14255
This commit is contained in:
@ -111,3 +111,6 @@ select count(distinct s1) from t1;
|
|||||||
count(distinct s1)
|
count(distinct s1)
|
||||||
3
|
3
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
select hex(cast(0x10 as binary(2)));
|
||||||
|
hex(cast(0x10 as binary(2)))
|
||||||
|
1000
|
||||||
|
@ -65,3 +65,6 @@ select hex(s1) from t1 where s1=0x0120;
|
|||||||
select hex(s1) from t1 where s1=0x0100;
|
select hex(s1) from t1 where s1=0x0100;
|
||||||
select count(distinct s1) from t1;
|
select count(distinct s1) from t1;
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
|
||||||
|
# check that cast appends trailing zeros
|
||||||
|
select hex(cast(0x10 as binary(2)));
|
||||||
|
@ -2352,22 +2352,36 @@ String *Item_char_typecast::val_str(String *str)
|
|||||||
and the result is longer than cast length, e.g.
|
and the result is longer than cast length, e.g.
|
||||||
CAST('string' AS CHAR(1))
|
CAST('string' AS CHAR(1))
|
||||||
*/
|
*/
|
||||||
if (cast_length >= 0 &&
|
if (cast_length >= 0)
|
||||||
(res->length() > (length= (uint32) res->charpos(cast_length))))
|
{
|
||||||
{ // Safe even if const arg
|
if (res->length() > (length= (uint32) res->charpos(cast_length)))
|
||||||
char char_type[40];
|
{ // Safe even if const arg
|
||||||
my_snprintf(char_type, sizeof(char_type), "CHAR(%lu)", length);
|
char char_type[40];
|
||||||
|
my_snprintf(char_type, sizeof(char_type), "CHAR(%lu)", length);
|
||||||
|
|
||||||
if (!res->alloced_length())
|
if (!res->alloced_length())
|
||||||
{ // Don't change const str
|
{ // Don't change const str
|
||||||
str_value= *res; // Not malloced string
|
str_value= *res; // Not malloced string
|
||||||
res= &str_value;
|
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;
|
null_value= 0;
|
||||||
return res;
|
return res;
|
||||||
|
Reference in New Issue
Block a user