summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2013-08-22 15:20:27 +0400
committerAlexander Barkov <bar@mariadb.org>2013-08-22 15:20:27 +0400
commitc40de1df363da0bc04118b4957c94fd52afe20b0 (patch)
treeca2b24f99c4134155d53a17de81402265dfec314
parentf8af4423b4bd9bb2978668b21506677f5dcac873 (diff)
downloadmariadb-git-c40de1df363da0bc04118b4957c94fd52afe20b0.tar.gz
MDEV-4804 Date comparing false result
-rw-r--r--mysql-test/r/type_date.result38
-rw-r--r--mysql-test/t/type_date.test22
-rw-r--r--sql/item_cmpfunc.cc6
3 files changed, 63 insertions, 3 deletions
diff --git a/mysql-test/r/type_date.result b/mysql-test/r/type_date.result
index da38f8d9ef8..e452b3255ae 100644
--- a/mysql-test/r/type_date.result
+++ b/mysql-test/r/type_date.result
@@ -307,5 +307,43 @@ NULL
Warnings:
Warning 1292 Incorrect datetime value: '2022-00-00 00:00:00'
#
+# MDEV-4804 Date comparing false result
+#
+SET @h0="20111107";
+SET @h1="0";
+SET @@timestamp=UNIX_TIMESTAMP('2013-08-19 20:30:00');
+SELECT
+COALESCE(DATE(@h0),DATE("1901-01-01")) AS h0d,
+COALESCE(DATE(@h1),DATE(NOW())) AS h1d,
+COALESCE(DATE(@h0),DATE("1901-01-01"))>COALESCE(DATE(@h1),DATE(NOW())) AS compare_h0_gt_h1;
+h0d h1d compare_h0_gt_h1
+2011-11-07 2013-08-19 0
+Warnings:
+Warning 1292 Incorrect datetime value: '0'
+Warning 1292 Incorrect datetime value: '0'
+SELECT
+DATE('20011107'),
+DATE('0'),
+COALESCE(DATE('0'),CURRENT_DATE) AS d1,
+DATE('20011107')>COALESCE(DATE('0'),CURRENT_DATE) AS cmp;
+DATE('20011107') DATE('0') d1 cmp
+2001-11-07 NULL 2013-08-19 0
+Warnings:
+Warning 1292 Incorrect datetime value: '0'
+Warning 1292 Incorrect datetime value: '0'
+Warning 1292 Incorrect datetime value: '0'
+SELECT
+DATE('20011107'),
+DATE('0'),
+IFNULL(DATE('0'),CURRENT_DATE) AS d1,
+DATE('20011107')>IFNULL(DATE('0'),CURRENT_DATE) AS cmp;
+DATE('20011107') DATE('0') d1 cmp
+2001-11-07 NULL 2013-08-19 0
+Warnings:
+Warning 1292 Incorrect datetime value: '0'
+Warning 1292 Incorrect datetime value: '0'
+Warning 1292 Incorrect datetime value: '0'
+SET @@timestamp=DEFAULT;
+#
# End of 5.3 tests
#
diff --git a/mysql-test/t/type_date.test b/mysql-test/t/type_date.test
index 57b545f004b..8a47d324406 100644
--- a/mysql-test/t/type_date.test
+++ b/mysql-test/t/type_date.test
@@ -288,5 +288,27 @@ drop table t1;
SELECT CONVERT_TZ(GREATEST(DATE('2021-00-00'),DATE('2022-00-00')),'+00:00','+7:5');
--echo #
+--echo # MDEV-4804 Date comparing false result
+--echo #
+SET @h0="20111107";
+SET @h1="0";
+SET @@timestamp=UNIX_TIMESTAMP('2013-08-19 20:30:00');
+SELECT
+ COALESCE(DATE(@h0),DATE("1901-01-01")) AS h0d,
+ COALESCE(DATE(@h1),DATE(NOW())) AS h1d,
+ COALESCE(DATE(@h0),DATE("1901-01-01"))>COALESCE(DATE(@h1),DATE(NOW())) AS compare_h0_gt_h1;
+SELECT
+ DATE('20011107'),
+ DATE('0'),
+ COALESCE(DATE('0'),CURRENT_DATE) AS d1,
+ DATE('20011107')>COALESCE(DATE('0'),CURRENT_DATE) AS cmp;
+SELECT
+ DATE('20011107'),
+ DATE('0'),
+ IFNULL(DATE('0'),CURRENT_DATE) AS d1,
+ DATE('20011107')>IFNULL(DATE('0'),CURRENT_DATE) AS cmp;
+SET @@timestamp=DEFAULT;
+
+--echo #
--echo # End of 5.3 tests
--echo #
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index fd688181c92..e133e2811bd 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -3155,12 +3155,12 @@ bool Item_func_coalesce::get_date(MYSQL_TIME *ltime,uint fuzzydate)
null_value= 0;
for (uint i= 0; i < arg_count; i++)
{
- bool res= args[i]->get_date(ltime, fuzzydate);
+ bool res= args[i]->get_date(ltime, fuzzydate & ~TIME_FUZZY_DATES);
if (!args[i]->null_value)
return res;
}
- null_value=1;
- return 1;
+ bzero((char*) ltime,sizeof(*ltime));
+ return null_value|= !(fuzzydate & TIME_FUZZY_DATES);
}