From b8359693cd7176822b905537ca6944285c524fc6 Mon Sep 17 00:00:00 2001 From: Alexander Peresypkin <7003484@gmail.com> Date: Sun, 4 Aug 2019 18:19:57 +0200 Subject: [PATCH] Fix cast unsigned. Version 5.7 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 c2ac11abbb4..691e2049954 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1661,7 +1661,7 @@ longlong Item_func_unsigned::val_int() { 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;