diff options
author | unknown <jimw@mysql.com> | 2005-08-02 15:28:09 -0700 |
---|---|---|
committer | unknown <jimw@mysql.com> | 2005-08-02 15:28:09 -0700 |
commit | 455ee425d146f876085c8fe8db0be2f4124640f8 (patch) | |
tree | 0aa7f4ebd49ff0e98d9e3384d984bfe5b01824f3 /sql/item_timefunc.cc | |
parent | 6eb7a80aff5363f3f0d714d5c7c1d46561a42ba1 (diff) | |
download | mariadb-git-455ee425d146f876085c8fe8db0be2f4124640f8.tar.gz |
Generate a warning/error when DATE_SUB/ADD() functions calculate a date
that is outside the acceptable date range. (Bug #10627)
mysql-test/r/func_date_add.result:
Add new results
mysql-test/t/func_date_add.test:
Add new regression test
sql/item_timefunc.cc:
Add warning for error conditions in Item_date_add_interval::get_date()
sql/share/errmsg.txt:
Add new error message
Diffstat (limited to 'sql/item_timefunc.cc')
-rw-r--r-- | sql/item_timefunc.cc | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index a6fbbee6f23..dfbfca3b078 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -1938,7 +1938,7 @@ bool Item_date_add_interval::get_date(TIME *ltime, uint fuzzy_date) daynr= calc_daynr(ltime->year,ltime->month,1) + days; /* Day number from year 0 to 9999-12-31 */ if ((ulonglong) daynr >= MAX_DAY_NUMBER) - goto null_date; + goto invalid_date; get_date_from_daynr((long) daynr, <ime->year, <ime->month, <ime->day); break; @@ -1949,13 +1949,13 @@ bool Item_date_add_interval::get_date(TIME *ltime, uint fuzzy_date) sign * (long) interval.day); /* Daynumber from year 0 to 9999-12-31 */ if ((ulong) period >= MAX_DAY_NUMBER) - goto null_date; + goto invalid_date; get_date_from_daynr((long) period,<ime->year,<ime->month,<ime->day); break; case INTERVAL_YEAR: ltime->year+= sign * (long) interval.year; if ((ulong) ltime->year >= 10000L) - goto null_date; + goto invalid_date; if (ltime->month == 2 && ltime->day == 29 && calc_days_in_year(ltime->year) != 366) ltime->day=28; // Was leap-year @@ -1966,7 +1966,7 @@ bool Item_date_add_interval::get_date(TIME *ltime, uint fuzzy_date) period= (ltime->year*12 + sign * (long) interval.year*12 + ltime->month-1 + sign * (long) interval.month); if ((ulong) period >= 120000L) - goto null_date; + goto invalid_date; ltime->year= (uint) (period / 12); ltime->month= (uint) (period % 12L)+1; /* Adjust day if the new month doesn't have enough days */ @@ -1982,6 +1982,11 @@ bool Item_date_add_interval::get_date(TIME *ltime, uint fuzzy_date) } return 0; // Ok +invalid_date: + push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_DATETIME_FUNCTION_OVERFLOW, + ER(ER_DATETIME_FUNCTION_OVERFLOW), + "datetime"); null_date: return (null_value=1); } |