From b2a6e97aac6e967b8d1ade8ba1aae4074935b914 Mon Sep 17 00:00:00 2001 From: Alexander Peresypkin <7003484@gmail.com> Date: Sun, 4 Aug 2019 17:14:06 +0200 Subject: [PATCH] Fix cast unsigned. Version 8.0 https://bugs.mysql.com/bug.php?id=95954 --- mysql-test/r/cast_unsigned.result | 19 +++++++++++++++++++ mysql-test/t/cast_unsigned.test | 14 ++++++++++++++ sql/item_func.cc | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 mysql-test/r/cast_unsigned.result create mode 100644 mysql-test/t/cast_unsigned.test diff --git a/mysql-test/r/cast_unsigned.result b/mysql-test/r/cast_unsigned.result new file mode 100644 index 00000000000..53d56ae0864 --- /dev/null +++ b/mysql-test/r/cast_unsigned.result @@ -0,0 +1,19 @@ +DROP TABLE IF EXISTS t0; +CREATE TABLE t0(c0 BIGINT UNSIGNED); +INSERT INTO t0(c0) VALUES(NULL); +SELECT * FROM t0 WHERE CAST(COALESCE(t0.c0, -1) AS UNSIGNED); +c0 +NULL +SELECT * FROM t0 WHERE CAST(IFNULL(t0.c0, -1) AS UNSIGNED); +c0 +NULL +SELECT CAST(COALESCE(t0.c0, -1) AS UNSIGNED) IS TRUE FROM t0; +CAST(COALESCE(t0.c0, -1) AS UNSIGNED) IS TRUE +1 +SELECT CAST(COALESCE(t0.c0, -1) AS UNSIGNED) FROM t0; +CAST(COALESCE(t0.c0, -1) AS UNSIGNED) +18446744073709551615 +DROP TABLE t0; +SELECT CAST(-1.1 AS UNSIGNED); +CAST(-1.1 AS UNSIGNED) +18446744073709551615 diff --git a/mysql-test/t/cast_unsigned.test b/mysql-test/t/cast_unsigned.test new file mode 100644 index 00000000000..3a909bb54ae --- /dev/null +++ b/mysql-test/t/cast_unsigned.test @@ -0,0 +1,14 @@ +--disable_warnings +DROP TABLE IF EXISTS t0; +--enable_warnings + +CREATE TABLE t0(c0 BIGINT UNSIGNED); +INSERT INTO t0(c0) VALUES(NULL); +SELECT * FROM t0 WHERE CAST(COALESCE(t0.c0, -1) AS UNSIGNED); +SELECT * FROM t0 WHERE CAST(IFNULL(t0.c0, -1) AS UNSIGNED); +SELECT CAST(COALESCE(t0.c0, -1) AS UNSIGNED) IS TRUE FROM t0; +SELECT CAST(COALESCE(t0.c0, -1) AS UNSIGNED) FROM t0; + +DROP TABLE t0; + +SELECT CAST(-1.1 AS UNSIGNED); diff --git a/sql/item_func.cc b/sql/item_func.cc index 08daf8681ab..352b584530c 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1577,7 +1577,7 @@ longlong Item_typecast_unsigned::val_int() { if (args[0]->cast_to_int_type() == DECIMAL_RESULT) { my_decimal tmp, *dec = args[0]->val_decimal(&tmp); if (!(null_value = args[0]->null_value)) - my_decimal2int(E_DEC_FATAL_ERROR, dec, 1, &value); + my_decimal2int(E_DEC_FATAL_ERROR, dec, args[0]->unsigned_flag, &value); else value = 0; return value;