Commit 8c8bee0a authored by Alexander Barkov's avatar Alexander Barkov

MDEV-10307 CAST(11068046444225730969 AS SIGNED) does not return a warning

parent 447b8ba1
......@@ -724,3 +724,9 @@ $$
DELIMITER ;$$
SET sql_mode=DEFAULT;
--echo #
--echo # MDEV-10307 CAST(11068046444225730969 AS SIGNED) does not return a warning
--echo #
SELECT CAST(11068046444225730969 AS SIGNED);
......@@ -2217,6 +2217,8 @@ t1 CREATE TABLE `t1` (
`b` bigint(20) DEFAULT (cast(`a` as signed))
) ENGINE=MyISAM DEFAULT CHARSET=latin1
INSERT INTO t1 (a) VALUES (0xFFFFFFFFFFFFFFFF);
Warnings:
Note 1105 Cast to signed converted positive out-of-range integer to it's negative complement
SELECT * FROM t1;
a b
18446744073709551615 -1
......
......@@ -333,6 +333,15 @@ longlong Item::val_int_unsigned_typecast_from_int()
}
longlong Item::val_int_signed_typecast_from_int()
{
longlong value= val_int();
if (!null_value && unsigned_flag && value < 0)
push_note_converted_to_negative_complement(current_thd);
return value;
}
String *Item::val_string_from_date(String *str)
{
MYSQL_TIME ltime;
......
......@@ -1057,6 +1057,13 @@ class Item: public Value_source,
longlong val_int_unsigned_typecast_from_decimal();
longlong val_int_unsigned_typecast_from_int();
longlong val_int_unsigned_typecast_from_str();
/**
Get a value for CAST(x AS UNSIGNED).
Huge positive unsigned values are converted to negative complements.
*/
longlong val_int_signed_typecast_from_int();
/*
This is just a shortcut to avoid the cast. You should still use
unsigned_flag to check the sign of the item.
......
......@@ -3380,7 +3380,7 @@ longlong Type_handler_real_result::
longlong Type_handler_int_result::
Item_val_int_signed_typecast(Item *item) const
{
return item->val_int();
return item->val_int_signed_typecast_from_int();
}
longlong Type_handler_decimal_result::
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment