Commit f64483cb authored by unknown's avatar unknown
Browse files

Bug #20924: CAST(expr as UNSIGNED) returns SIGNED value when used in various functions

- Honor unsigned_flag in the corresponding functions
- Use compare_int_signed_unsigned()/compare_int_unsigned_signed() instead of explicit comparison in GREATEST() and LEAST()


mysql-test/r/case.result:
  Added test case for bug #20924
mysql-test/r/func_if.result:
  Added test case for bug #20924
mysql-test/r/func_test.result:
  Added test case for bug #20924
mysql-test/r/user_var.result:
  Added test case for bug #20924
mysql-test/t/case.test:
  Added test case for bug #20924
mysql-test/t/func_if.test:
  Added test case for bug #20924
mysql-test/t/func_test.test:
  Added test case for bug #20924
mysql-test/t/user_var.test:
  Added test case for bug #20924
sql/item_cmpfunc.cc:
  Bug #20924: CAST(expr as UNSIGNED) returns SIGNED value when used in various functions
  
  - Moved some code out of Arg_comparator to external functions to be reused in Item_func_min_max
  - Fixed IFNULL(), IF(), CASE() and COALESCE()
sql/item_cmpfunc.h:
  Bug #20924: CAST(expr as UNSIGNED) returns SIGNED value when used in various functions
  
  - Moved some code out of Arg_comparator to external functions to be reused in Item_func_min_max
sql/item_func.cc:
  Bug #20924: CAST(expr as UNSIGNED) returns SIGNED value when used in various functions
  
  Fixed LEAST(), GREATEST() and "SET @a=..." parts
sql/item_func.h:
  Bug #20924: CAST(expr as UNSIGNED) returns SIGNED value when used in various functions
  
  Fixed "SET @a=..." part
sql/sql_class.h:
  Bug #20924: CAST(expr as UNSIGNED) returns SIGNED value when used in various functions
  
  Fixed "SET @a=..." part
parent 7a77b3d8
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -177,3 +177,9 @@ from t1 where b=3 group by b;
min(a)	min(case when 1=1 then a else NULL end)	min(case when 1!=1 then NULL else a end)
2	2	2
drop table t1;
SELECT CASE 1 WHEN 1 THEN 18446744073709551615 ELSE 1 END;
CASE 1 WHEN 1 THEN 18446744073709551615 ELSE 1 END
18446744073709551615
SELECT COALESCE(18446744073709551615);
COALESCE(18446744073709551615)
18446744073709551615
+6 −0
Original line number Diff line number Diff line
@@ -99,3 +99,9 @@ a NULLIF(a,'')
NULL	NULL
	NULL
DROP TABLE t1;
SELECT IF(1 != 0, 18446744073709551615, 1);
IF(1 != 0, 18446744073709551615, 1)
18446744073709551615
SELECT IFNULL(NULL, 18446744073709551615);
IFNULL(NULL, 18446744073709551615)
18446744073709551615
+6 −0
Original line number Diff line number Diff line
@@ -183,3 +183,9 @@ select 5.1 mod 3, 5.1 mod -3, -5.1 mod 3, -5.1 mod -3;
select 5 mod 3, 5 mod -3, -5 mod 3, -5 mod -3;
5 mod 3	5 mod -3	-5 mod 3	-5 mod -3
2	2	-2	-2
SELECT GREATEST(1, 18446744073709551615);
GREATEST(1, 18446744073709551615)
18446744073709551615
SELECT LEAST(1, 18446744073709551615);
LEAST(1, 18446744073709551615)
1
+4 −0
Original line number Diff line number Diff line
@@ -203,3 +203,7 @@ select @@global.version;
select @@session.VERSION;
@@session.VERSION
#
set @a=18446744073709551615;
select @a;
@a
18446744073709551615
+6 −0
Original line number Diff line number Diff line
@@ -130,4 +130,10 @@ select min(a), min(case when 1=1 then a else NULL end),
from t1 where b=3 group by b;
drop table t1;

#
# Bug #20924: UNSIGNED values in CASE and COALESCE are treated as SIGNED
#
SELECT CASE 1 WHEN 1 THEN 18446744073709551615 ELSE 1 END;
SELECT COALESCE(18446744073709551615);

# End of 4.1 tests
Loading