Skip to content

Commit

Permalink
An after-fix for MDEV-12849 Out-of-range errors when casting hex-hybr…
Browse files Browse the repository at this point in the history
…id to SIGNED and UNSIGNED

1. Adding the forgotten "SET sql_mode=STRICT_ALL_TABLES" into the test.
2. STRICT_ALL_TABLES revealed that CAST(0xFFFFFFFF AS SIGNED),
   e.g. with a hex number with 8 hex digits, did not work well.
   Fixing Item_func_unsigned::create_tmp_field() and
   Item_func_unsigned::create_field_for_create_select() to handle
   this corner case.
  • Loading branch information
Alexander Barkov committed May 19, 2017
1 parent ac4ce47 commit d2fec34
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mysql-test/r/cast.result
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ DROP TABLE t1;
#
# MDEV-12849 Out-of-range errors when casting hex-hybrid to SIGNED and UNSIGNED
#
SET sql_mode=STRICT_ALL_TABLES;
CREATE PROCEDURE p1(hh TEXT)
BEGIN
EXECUTE IMMEDIATE
Expand Down Expand Up @@ -957,9 +958,9 @@ c int(10) unsigned NO NULL
c LENGTH(c)
4294967295 10
Field Type Null Key Default Extra
c int(10) NO NULL
c bigint(10) NO NULL
c LENGTH(c)
2147483647 10
4294967295 10
------

CALL p1('FFFFFFFFFF');
Expand Down Expand Up @@ -1128,3 +1129,4 @@ c LENGTH(c)
------

DROP PROCEDURE p1;
SET sql_mode=DEFAULT;
2 changes: 2 additions & 0 deletions mysql-test/t/cast.test
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ DROP TABLE t1;
--echo # MDEV-12849 Out-of-range errors when casting hex-hybrid to SIGNED and UNSIGNED
--echo #

SET sql_mode=STRICT_ALL_TABLES;
DELIMITER $$;
CREATE PROCEDURE p1(hh TEXT)
BEGIN
Expand Down Expand Up @@ -559,3 +560,4 @@ CALL p1('80FFFFFFFFFFFFFF');
CALL p1('8FFFFFFFFFFFFFFF');

DROP PROCEDURE p1;
SET sql_mode=DEFAULT;
8 changes: 8 additions & 0 deletions sql/item_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,14 @@ class Item_func_signed :public Item_int_func
unsigned_flag= 0;
}
const char *func_name() const { return "cast_as_signed"; }
Field *create_tmp_field(bool group, TABLE *table)
{
return Item::create_tmp_field(false, table,
MY_INT32_NUM_DECIMAL_DIGITS - 2 +
unsigned_flag);
}
Field *create_field_for_create_select(TABLE *table)
{ return Item_func_signed::create_tmp_field(false, table); }
longlong val_int()
{
longlong value= args[0]->val_int_signed_typecast();
Expand Down

0 comments on commit d2fec34

Please sign in to comment.