summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2017-05-19 21:39:41 +0400
committerAlexander Barkov <bar@mariadb.org>2017-05-19 21:39:41 +0400
commitd2fec340d25c24c8862f461b1f3272c098e67d54 (patch)
tree990ec1a37e25d400480bae9c8c87f6b3bc91fba3
parentac4ce47b09f8869431dfc7a71a250f38ca84b406 (diff)
downloadmariadb-git-d2fec340d25c24c8862f461b1f3272c098e67d54.tar.gz
An after-fix for MDEV-12849 Out-of-range errors when casting hex-hybrid 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.
-rw-r--r--mysql-test/r/cast.result6
-rw-r--r--mysql-test/t/cast.test2
-rw-r--r--sql/item_func.h8
3 files changed, 14 insertions, 2 deletions
diff --git a/mysql-test/r/cast.result b/mysql-test/r/cast.result
index 0bcdc8e8097..69979854d8e 100644
--- a/mysql-test/r/cast.result
+++ b/mysql-test/r/cast.result
@@ -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
@@ -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');
@@ -1128,3 +1129,4 @@ c LENGTH(c)
------
DROP PROCEDURE p1;
+SET sql_mode=DEFAULT;
diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test
index 66bfbb61aa0..e56433b3d54 100644
--- a/mysql-test/t/cast.test
+++ b/mysql-test/t/cast.test
@@ -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
@@ -559,3 +560,4 @@ CALL p1('80FFFFFFFFFFFFFF');
CALL p1('8FFFFFFFFFFFFFFF');
DROP PROCEDURE p1;
+SET sql_mode=DEFAULT;
diff --git a/sql/item_func.h b/sql/item_func.h
index c644c1abf1b..baa80ede03f 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -834,6 +834,14 @@ public:
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();