diff options
-rw-r--r-- | mysql-test/r/func_time.result | 184 | ||||
-rw-r--r-- | mysql-test/t/func_time.test | 61 | ||||
-rw-r--r-- | sql-common/my_time.c | 2 | ||||
-rw-r--r-- | sql/item_timefunc.cc | 2 |
4 files changed, 246 insertions, 3 deletions
diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index 68c1e667440..ceb9dd4f7ea 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -1430,6 +1430,188 @@ NULL # 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); +# +# 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: -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 diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test index 2dcac0d5796..3ea79a7fc94 100644 --- a/mysql-test/t/func_time.test +++ b/mysql-test/t/func_time.test @@ -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); +--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 diff --git a/sql-common/my_time.c b/sql-common/my_time.c index 0c90f14ae79..13ba691a090 100644 --- a/sql-common/my_time.c +++ b/sql-common/my_time.c @@ -785,7 +785,7 @@ long calc_daynr(uint year,uint month,uint day) temp=(int) ((y/100+1)*3)/4; DBUG_PRINT("exit",("year: %d month: %d day: %d -> daynr: %ld", 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); } /* calc_daynr */ diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 31474f1d6ca..83b0b7cdebc 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -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 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->time_type= MYSQL_TIMESTAMP_DATE; return res; |