diff options
author | unknown <evgen@moonbone.local> | 2005-06-02 17:00:07 +0400 |
---|---|---|
committer | unknown <evgen@moonbone.local> | 2005-06-02 17:00:07 +0400 |
commit | c8e797b5b6d921803746d82b81c5e9e35d7c03a6 (patch) | |
tree | 949f9227c41dce4163f3d62c019efd88dbee6371 | |
parent | a6cf849e0def7f612a2ccb2e2ce281287db3f6e5 (diff) | |
download | mariadb-git-c8e797b5b6d921803746d82b81c5e9e35d7c03a6.tar.gz |
Fix bug #9669 Ordering on IF function with FROM_UNIXTIME function fails
Integer overflow results in wrong field sortlength.
sql/item_cmpfunc.cc:
Fix bug #9669 Ordering on IF function with FROM_UNIXTIME function fails.
mysql-test/t/func_if.test:
Test for bug #9669 Ordering on IF function with FROM_UNIXTIME function fails.
mysql-test/r/func_if.result:
Test for bug #9669 Ordering on IF function with FROM_UNIXTIME function fails.
-rw-r--r-- | mysql-test/r/func_if.result | 17 | ||||
-rw-r--r-- | mysql-test/t/func_if.test | 14 | ||||
-rw-r--r-- | sql/item_cmpfunc.cc | 9 |
3 files changed, 39 insertions, 1 deletions
diff --git a/mysql-test/r/func_if.result b/mysql-test/r/func_if.result index 4db31121756..3e72fb45a14 100644 --- a/mysql-test/r/func_if.result +++ b/mysql-test/r/func_if.result @@ -91,3 +91,20 @@ drop table t1; SELECT NULLIF(5,5) IS NULL, NULLIF(5,5) IS NOT NULL; NULLIF(5,5) IS NULL NULLIF(5,5) IS NOT NULL 1 0 +CREATE TABLE `t1` ( +`id` int(11) NOT NULL , +`date` int(10) default NULL, +`text` varchar(32) NOT NULL +); +INSERT INTO t1 VALUES (1,1110000000,'Day 1'),(2,1111000000,'Day 2'),(3,1112000000,'Day 3'); +SELECT id, IF(date IS NULL, '-', FROM_UNIXTIME(date, '%d-%m-%Y')) AS date_ord, text FROM t1 ORDER BY date_ord ASC; +id date_ord text +1 05-03-2005 Day 1 +2 16-03-2005 Day 2 +3 28-03-2005 Day 3 +SELECT id, IF(date IS NULL, '-', FROM_UNIXTIME(date, '%d-%m-%Y')) AS date_ord, text FROM t1 ORDER BY date_ord DESC; +id date_ord text +3 28-03-2005 Day 3 +2 16-03-2005 Day 2 +1 05-03-2005 Day 1 +DROP TABLE t1; diff --git a/mysql-test/t/func_if.test b/mysql-test/t/func_if.test index a2ea26390ca..37556984f68 100644 --- a/mysql-test/t/func_if.test +++ b/mysql-test/t/func_if.test @@ -61,3 +61,17 @@ drop table t1; # Bug #5595 NULLIF() IS NULL returns false if NULLIF() returns NULL # SELECT NULLIF(5,5) IS NULL, NULLIF(5,5) IS NOT NULL; + +# +# Bug #9669 Ordering on IF function with FROM_UNIXTIME function fails +# +CREATE TABLE `t1` ( + `id` int(11) NOT NULL , + `date` int(10) default NULL, + `text` varchar(32) NOT NULL +); +INSERT INTO t1 VALUES (1,1110000000,'Day 1'),(2,1111000000,'Day 2'),(3,1112000000,'Day 3'); +SELECT id, IF(date IS NULL, '-', FROM_UNIXTIME(date, '%d-%m-%Y')) AS date_ord, text FROM t1 ORDER BY date_ord ASC; +SELECT id, IF(date IS NULL, '-', FROM_UNIXTIME(date, '%d-%m-%Y')) AS date_ord, text FROM t1 ORDER BY date_ord DESC; +DROP TABLE t1; + diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index a7abb5f9be8..eb0dddd3e28 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1227,9 +1227,16 @@ Item_func_if::fix_length_and_dec() { maybe_null=args[1]->maybe_null || args[2]->maybe_null; decimals= max(args[1]->decimals, args[2]->decimals); - max_length= (max(args[1]->max_length - args[1]->decimals, + if (decimals == NOT_FIXED_DEC) + { + max_length= max(args[1]->max_length, args[2]->max_length); + } + else + { + max_length= (max(args[1]->max_length - args[1]->decimals, args[2]->max_length - args[2]->decimals) + decimals); + } enum Item_result arg1_type=args[1]->result_type(); enum Item_result arg2_type=args[2]->result_type(); bool null1=args[1]->const_item() && args[1]->null_value; |