Commit 1f776e9f authored by Alexander Barkov's avatar Alexander Barkov

BUG#13458237 - INCONSISTENT HANDLING OF INVALIDE DATES WITH ZERO DAY. SIMILAR TO '2009-10-00'

- Reverting the patch for Bug # 12584302
  The patch will be reverted in 5.1 and 5.5.
  The patch will not be reverted in 5.6, the change will
  be properly documented in 5.6.
- Backporting DBUG_ASSERT not to crash on '0000-01-00'
  (already fixed in mysql-trunk (5.6))
parent 429fdb3b
...@@ -1430,6 +1430,188 @@ NULL ...@@ -1430,6 +1430,188 @@ NULL
# Bug#12584302 AFTER FIX FOR #12403504: ASSERTION FAILED: DELSUM+(INT) Y/4-TEMP > 0, # Bug#12584302 AFTER FIX FOR #12403504: ASSERTION FAILED: DELSUM+(INT) Y/4-TEMP > 0,
# #
DO WEEK((DATE_ADD((CAST(0 AS DATE)), INTERVAL 1 YEAR_MONTH)), 5); DO WEEK((DATE_ADD((CAST(0 AS DATE)), INTERVAL 1 YEAR_MONTH)), 5);
#
# BUG#13458237 INCONSISTENT HANDLING OF INVALIDE DATES WITH ZERO DAY
# SIMILAR TO '2009-10-00'
#
SELECT
DATE('20091000'),
STR_TO_DATE('200910','%Y%m'),
LAST_DAY('2009-10-00'),
LAST_DAY(DATE('2009-10-00')),
LAST_DAY(DATE'2009-10-00'),
LAST_DAY(STR_TO_DATE('200910','%Y%m')),
WEEK('2009-10-00'),
WEEK(DATE('2009-10-00')),
WEEK(DATE'2009-10-00'),
WEEK(STR_TO_DATE('200910','%Y%m')),
WEEKOFYEAR('2009-10-00'),
WEEKOFYEAR(DATE('2009-10-00')),
WEEKOFYEAR(DATE'2009-10-00'),
WEEKOFYEAR(STR_TO_DATE('200910','%Y%m')),
DAYOFYEAR('2009-10-00'),
DAYOFYEAR(DATE('2009-10-00')),
DAYOFYEAR(DATE'2009-10-00'),
DAYOFYEAR(STR_TO_DATE('200910','%Y%m')),
WEEKDAY('2009-10-00'),
WEEKDAY(DATE('2009-10-00')),
WEEKDAY(DATE'2009-10-00'),
WEEKDAY(STR_TO_DATE('200910','%Y%m')),
TO_DAYs('2009-10-00'),
TO_DAYs(DATE('2009-10-00')),
TO_DAYs(DATE'2009-10-00'),
TO_DAYs(STR_TO_DATE('200910','%Y%m'));
DATE('20091000') 2009-10-00
STR_TO_DATE('200910','%Y%m') 2009-10-00
LAST_DAY('2009-10-00') NULL
LAST_DAY(DATE('2009-10-00')) 2009-10-31
LAST_DAY(DATE'2009-10-00') NULL
LAST_DAY(STR_TO_DATE('200910','%Y%m')) 2009-10-31
WEEK('2009-10-00') NULL
WEEK(DATE('2009-10-00')) 39
WEEK(DATE'2009-10-00') NULL
WEEK(STR_TO_DATE('200910','%Y%m')) NULL
WEEKOFYEAR('2009-10-00') NULL
WEEKOFYEAR(DATE('2009-10-00')) 40
WEEKOFYEAR(DATE'2009-10-00') NULL
WEEKOFYEAR(STR_TO_DATE('200910','%Y%m')) NULL
DAYOFYEAR('2009-10-00') NULL
DAYOFYEAR(DATE('2009-10-00')) 273
DAYOFYEAR(DATE'2009-10-00') NULL
DAYOFYEAR(STR_TO_DATE('200910','%Y%m')) NULL
WEEKDAY('2009-10-00') NULL
WEEKDAY(DATE('2009-10-00')) 2
WEEKDAY(DATE'2009-10-00') NULL
WEEKDAY(STR_TO_DATE('200910','%Y%m')) NULL
TO_DAYs('2009-10-00') NULL
TO_DAYs(DATE('2009-10-00')) 734045
TO_DAYs(DATE'2009-10-00') NULL
TO_DAYs(STR_TO_DATE('200910','%Y%m')) NULL
Warnings:
Level Warning
Code 1292
Message Incorrect datetime value: '2009-10-00'
Level Warning
Code 1292
Message Incorrect datetime value: '2009-10-00'
Level Warning
Code 1292
Message Incorrect datetime value: '2009-10-00'
Level Warning
Code 1292
Message Incorrect datetime value: '2009-10-00'
Level Warning
Code 1292
Message Incorrect datetime value: '2009-10-00'
Level Warning
Code 1292
Message Incorrect datetime value: '2009-10-00'
Level Warning
Code 1292
Message Incorrect datetime value: '2009-10-00'
Level Warning
Code 1292
Message Incorrect datetime value: '2009-10-00'
Level Warning
Code 1292
Message Incorrect datetime value: '2009-10-00'
Level Warning
Code 1292
Message Incorrect datetime value: '2009-10-00'
Level Warning
Code 1292
Message Incorrect datetime value: '2009-10-00'
Level Warning
Code 1292
Message Incorrect datetime value: '2009-10-00'
SELECT
DATE('00000100'),
STR_TO_DATE('000001','%Y%m'),
LAST_DAY('0000-01-00'),
LAST_DAY(DATE('0000-01-00')),
LAST_DAY(DATE'0000-01-00'),
LAST_DAY(STR_TO_DATE('000001','%Y%m')),
WEEK('0000-01-00'),
WEEK(DATE('0000-01-00')),
WEEK(DATE'0000-01-00'),
WEEK(STR_TO_DATE('000001','%Y%m')),
WEEKOFYEAR('0000-01-00'),
WEEKOFYEAR(DATE('0000-01-00')),
WEEKOFYEAR(DATE'0000-01-00'),
WEEKOFYEAR(STR_TO_DATE('000001','%Y%m')),
DAYOFYEAR('0000-01-00'),
DAYOFYEAR(DATE('0000-01-00')),
DAYOFYEAR(DATE'0000-01-00'),
DAYOFYEAR(STR_TO_DATE('000001','%Y%m')),
WEEKDAY('0000-01-00'),
WEEKDAY(DATE('0000-01-00')),
WEEKDAY(DATE'0000-01-00'),
WEEKDAY(STR_TO_DATE('000001','%Y%m')),
TO_DAYs('0000-01-00'),
TO_DAYs(DATE('0000-01-00')),
TO_DAYs(DATE'0000-01-00'),
TO_DAYs(STR_TO_DATE('000001','%Y%m'));
DATE('00000100') 0000-01-00
STR_TO_DATE('000001','%Y%m') 0000-01-00
LAST_DAY('0000-01-00') NULL
LAST_DAY(DATE('0000-01-00')) 0000-01-31
LAST_DAY(DATE'0000-01-00') NULL
LAST_DAY(STR_TO_DATE('000001','%Y%m')) 0000-01-31
WEEK('0000-01-00') NULL
WEEK(DATE('0000-01-00')) 52
WEEK(DATE'0000-01-00') NULL
WEEK(STR_TO_DATE('000001','%Y%m')) NULL
WEEKOFYEAR('0000-01-00') NULL
WEEKOFYEAR(DATE('0000-01-00')) 52
WEEKOFYEAR(DATE'0000-01-00') NULL
WEEKOFYEAR(STR_TO_DATE('000001','%Y%m')) NULL
DAYOFYEAR('0000-01-00') NULL
DAYOFYEAR(DATE('0000-01-00')) 0
DAYOFYEAR(DATE'0000-01-00') NULL
DAYOFYEAR(STR_TO_DATE('000001','%Y%m')) NULL
WEEKDAY('0000-01-00') NULL
WEEKDAY(DATE('0000-01-00')) 5
WEEKDAY(DATE'0000-01-00') NULL
WEEKDAY(STR_TO_DATE('000001','%Y%m')) NULL
TO_DAYs('0000-01-00') NULL
TO_DAYs(DATE('0000-01-00')) 0
TO_DAYs(DATE'0000-01-00') NULL
TO_DAYs(STR_TO_DATE('000001','%Y%m')) NULL
Warnings: Warnings:
Warning 1292 Incorrect datetime value: '0' Level Warning
Code 1292
Message Incorrect datetime value: '0000-01-00'
Level Warning
Code 1292
Message Incorrect datetime value: '0000-01-00'
Level Warning
Code 1292
Message Incorrect datetime value: '0000-01-00'
Level Warning
Code 1292
Message Incorrect datetime value: '0000-01-00'
Level Warning
Code 1292
Message Incorrect datetime value: '0000-01-00'
Level Warning
Code 1292
Message Incorrect datetime value: '0000-01-00'
Level Warning
Code 1292
Message Incorrect datetime value: '0000-01-00'
Level Warning
Code 1292
Message Incorrect datetime value: '0000-01-00'
Level Warning
Code 1292
Message Incorrect datetime value: '0000-01-00'
Level Warning
Code 1292
Message Incorrect datetime value: '0000-01-00'
Level Warning
Code 1292
Message Incorrect datetime value: '0000-01-00'
Level Warning
Code 1292
Message Incorrect datetime value: '0000-01-00'
End of 5.1 tests End of 5.1 tests
...@@ -934,4 +934,65 @@ SELECT WEEK(DATE_ADD(FROM_DAYS(1),INTERVAL 1 MONTH), 1); ...@@ -934,4 +934,65 @@ SELECT WEEK(DATE_ADD(FROM_DAYS(1),INTERVAL 1 MONTH), 1);
DO WEEK((DATE_ADD((CAST(0 AS DATE)), INTERVAL 1 YEAR_MONTH)), 5); DO WEEK((DATE_ADD((CAST(0 AS DATE)), INTERVAL 1 YEAR_MONTH)), 5);
--echo #
--echo # BUG#13458237 INCONSISTENT HANDLING OF INVALIDE DATES WITH ZERO DAY
--echo # SIMILAR TO '2009-10-00'
--echo #
query_vertical SELECT
DATE('20091000'),
STR_TO_DATE('200910','%Y%m'),
LAST_DAY('2009-10-00'),
LAST_DAY(DATE('2009-10-00')),
LAST_DAY(DATE'2009-10-00'),
LAST_DAY(STR_TO_DATE('200910','%Y%m')),
WEEK('2009-10-00'),
WEEK(DATE('2009-10-00')),
WEEK(DATE'2009-10-00'),
WEEK(STR_TO_DATE('200910','%Y%m')),
WEEKOFYEAR('2009-10-00'),
WEEKOFYEAR(DATE('2009-10-00')),
WEEKOFYEAR(DATE'2009-10-00'),
WEEKOFYEAR(STR_TO_DATE('200910','%Y%m')),
DAYOFYEAR('2009-10-00'),
DAYOFYEAR(DATE('2009-10-00')),
DAYOFYEAR(DATE'2009-10-00'),
DAYOFYEAR(STR_TO_DATE('200910','%Y%m')),
WEEKDAY('2009-10-00'),
WEEKDAY(DATE('2009-10-00')),
WEEKDAY(DATE'2009-10-00'),
WEEKDAY(STR_TO_DATE('200910','%Y%m')),
TO_DAYs('2009-10-00'),
TO_DAYs(DATE('2009-10-00')),
TO_DAYs(DATE'2009-10-00'),
TO_DAYs(STR_TO_DATE('200910','%Y%m'));
query_vertical SELECT
DATE('00000100'),
STR_TO_DATE('000001','%Y%m'),
LAST_DAY('0000-01-00'),
LAST_DAY(DATE('0000-01-00')),
LAST_DAY(DATE'0000-01-00'),
LAST_DAY(STR_TO_DATE('000001','%Y%m')),
WEEK('0000-01-00'),
WEEK(DATE('0000-01-00')),
WEEK(DATE'0000-01-00'),
WEEK(STR_TO_DATE('000001','%Y%m')),
WEEKOFYEAR('0000-01-00'),
WEEKOFYEAR(DATE('0000-01-00')),
WEEKOFYEAR(DATE'0000-01-00'),
WEEKOFYEAR(STR_TO_DATE('000001','%Y%m')),
DAYOFYEAR('0000-01-00'),
DAYOFYEAR(DATE('0000-01-00')),
DAYOFYEAR(DATE'0000-01-00'),
DAYOFYEAR(STR_TO_DATE('000001','%Y%m')),
WEEKDAY('0000-01-00'),
WEEKDAY(DATE('0000-01-00')),
WEEKDAY(DATE'0000-01-00'),
WEEKDAY(STR_TO_DATE('000001','%Y%m')),
TO_DAYs('0000-01-00'),
TO_DAYs(DATE('0000-01-00')),
TO_DAYs(DATE'0000-01-00'),
TO_DAYs(STR_TO_DATE('000001','%Y%m'));
--echo End of 5.1 tests --echo End of 5.1 tests
...@@ -785,7 +785,7 @@ long calc_daynr(uint year,uint month,uint day) ...@@ -785,7 +785,7 @@ long calc_daynr(uint year,uint month,uint day)
temp=(int) ((y/100+1)*3)/4; temp=(int) ((y/100+1)*3)/4;
DBUG_PRINT("exit",("year: %d month: %d day: %d -> daynr: %ld", DBUG_PRINT("exit",("year: %d month: %d day: %d -> daynr: %ld",
y+(month <= 2),month,day,delsum+y/4-temp)); y+(month <= 2),month,day,delsum+y/4-temp));
DBUG_ASSERT(delsum+(int) y/4-temp > 0); DBUG_ASSERT(delsum+(int) y/4-temp >= 0);
DBUG_RETURN(delsum+(int) y/4-temp); DBUG_RETURN(delsum+(int) y/4-temp);
} /* calc_daynr */ } /* calc_daynr */
......
...@@ -2646,7 +2646,7 @@ String *Item_time_typecast::val_str(String *str) ...@@ -2646,7 +2646,7 @@ String *Item_time_typecast::val_str(String *str)
bool Item_date_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date) bool Item_date_typecast::get_date(MYSQL_TIME *ltime, uint fuzzy_date)
{ {
bool res= get_arg0_date(ltime, fuzzy_date); bool res= get_arg0_date(ltime, TIME_FUZZY_DATE);
ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0; ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0;
ltime->time_type= MYSQL_TIMESTAMP_DATE; ltime->time_type= MYSQL_TIMESTAMP_DATE;
return res; return res;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment