Browse Source

MDEV-4804 Date comparing false result

pull/843/head
Alexander Barkov 12 years ago
parent
commit
c40de1df36
  1. 38
      mysql-test/r/type_date.result
  2. 22
      mysql-test/t/type_date.test
  3. 6
      sql/item_cmpfunc.cc

38
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
#

22
mysql-test/t/type_date.test

@ -287,6 +287,28 @@ drop table t1;
--echo #
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 #

6
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);
}

Loading…
Cancel
Save