summaryrefslogtreecommitdiff
path: root/sql/item_timefunc.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/item_timefunc.cc')
-rw-r--r--sql/item_timefunc.cc46
1 files changed, 25 insertions, 21 deletions
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index c0e623f499c..788da1a5713 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -415,8 +415,8 @@ static bool extract_date_time(DATE_TIME_FORMAT *format,
l_time->minute > 59 || l_time->second > 59)
goto err;
- if ((fuzzy_date & TIME_NO_ZERO_DATE) &&
- (l_time->year == 0 || l_time->month == 0 || l_time->day == 0))
+ int was_cut;
+ if (check_date(l_time, fuzzy_date | TIME_INVALID_DATES, &was_cut))
goto err;
if (val != val_end)
@@ -780,7 +780,7 @@ longlong Item_func_to_seconds::val_int_endpoint(bool left_endp,
longlong seconds;
longlong days;
int dummy; /* unused */
- if (get_arg0_date(&ltime, TIME_FUZZY_DATE))
+ if (get_arg0_date(&ltime, TIME_FUZZY_DATES))
{
/* got NULL, leave the incl_endp intact */
return LONGLONG_MIN;
@@ -858,7 +858,7 @@ longlong Item_func_to_days::val_int_endpoint(bool left_endp, bool *incl_endp)
MYSQL_TIME ltime;
longlong res;
int dummy; /* unused */
- if (get_arg0_date(&ltime, TIME_FUZZY_DATE))
+ if (get_arg0_date(&ltime, 0))
{
/* got NULL, leave the incl_endp intact */
return LONGLONG_MIN;
@@ -866,7 +866,6 @@ longlong Item_func_to_days::val_int_endpoint(bool left_endp, bool *incl_endp)
res=(longlong) calc_daynr(ltime.year,ltime.month,ltime.day);
/* Set to NULL if invalid date, but keep the value */
null_value= check_date(&ltime,
- (ltime.year || ltime.month || ltime.day),
(TIME_NO_ZERO_IN_DATE | TIME_NO_ZERO_DATE),
&dummy);
if (null_value)
@@ -923,14 +922,14 @@ longlong Item_func_dayofmonth::val_int()
{
DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime;
- return get_arg0_date(&ltime, TIME_FUZZY_DATE) ? 0 : (longlong) ltime.day;
+ return get_arg0_date(&ltime, 0) ? 0 : (longlong) ltime.day;
}
longlong Item_func_month::val_int()
{
DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime;
- return get_arg0_date(&ltime, TIME_FUZZY_DATE) ? 0 : (longlong) ltime.month;
+ return get_arg0_date(&ltime, 0) ? 0 : (longlong) ltime.month;
}
@@ -954,7 +953,7 @@ String* Item_func_monthname::val_str(String* str)
uint err;
MYSQL_TIME ltime;
- if ((null_value= (get_arg0_date(&ltime, TIME_FUZZY_DATE) || !ltime.month)))
+ if ((null_value= (get_arg0_date(&ltime, 0) || !ltime.month)))
return (String *) 0;
month_name= locale->month_names->type_names[ltime.month - 1];
@@ -972,7 +971,7 @@ longlong Item_func_quarter::val_int()
{
DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime;
- if (get_arg0_date(&ltime, TIME_FUZZY_DATE))
+ if (get_arg0_date(&ltime, 0))
return 0;
return (longlong) ((ltime.month+2)/3);
}
@@ -1046,7 +1045,7 @@ longlong Item_func_week::val_int()
DBUG_ASSERT(fixed == 1);
uint year;
MYSQL_TIME ltime;
- if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
+ if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE))
return 0;
return (longlong) calc_week(&ltime,
week_mode((uint) args[1]->val_int()),
@@ -1059,7 +1058,7 @@ longlong Item_func_yearweek::val_int()
DBUG_ASSERT(fixed == 1);
uint year,week;
MYSQL_TIME ltime;
- if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
+ if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE))
return 0;
week= calc_week(&ltime,
(week_mode((uint) args[1]->val_int()) | WEEK_YEAR),
@@ -1073,7 +1072,7 @@ longlong Item_func_weekday::val_int()
DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime;
- if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
+ if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE))
return 0;
return (longlong) calc_weekday(calc_daynr(ltime.year, ltime.month,
@@ -1115,7 +1114,7 @@ longlong Item_func_year::val_int()
{
DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime;
- return get_arg0_date(&ltime, TIME_FUZZY_DATE) ? 0 : (longlong) ltime.year;
+ return get_arg0_date(&ltime, 0) ? 0 : (longlong) ltime.year;
}
@@ -1147,7 +1146,7 @@ longlong Item_func_year::val_int_endpoint(bool left_endp, bool *incl_endp)
{
DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime;
- if (get_arg0_date(&ltime, TIME_FUZZY_DATE))
+ if (get_arg0_date(&ltime, 0))
{
/* got NULL, leave the incl_endp intact */
return LONGLONG_MIN;
@@ -1190,7 +1189,7 @@ bool Item_func_unix_timestamp::get_timestamp_value(my_time_t *seconds,
}
MYSQL_TIME ltime;
- if (get_arg0_date(&ltime, 0))
+ if (get_arg0_date(&ltime, TIME_NO_ZERO_IN_DATE))
return 1;
uint error_code;
@@ -1468,7 +1467,7 @@ longlong Item_temporal_func::val_int()
{
DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime;
- if (get_date(&ltime, TIME_FUZZY_DATE | sql_mode))
+ if (get_date(&ltime, sql_mode))
return 0;
longlong v= TIME_to_ulonglong(&ltime);
return ltime.neg ? -v : v;
@@ -1479,7 +1478,7 @@ double Item_temporal_func::val_real()
{
DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime;
- if (get_date(&ltime, TIME_FUZZY_DATE | sql_mode))
+ if (get_date(&ltime, sql_mode))
return 0;
return TIME_to_double(&ltime);
}
@@ -1859,7 +1858,7 @@ String *Item_func_date_format::val_str(String *str)
int is_time_flag = is_time_format ? TIME_TIME_ONLY : 0;
DBUG_ASSERT(fixed == 1);
- if (get_arg0_date(&l_time, TIME_FUZZY_DATE | is_time_flag))
+ if (get_arg0_date(&l_time, is_time_flag))
return 0;
if (!(format = args[1]->val_str(str)) || !format->length())
@@ -2033,10 +2032,15 @@ bool Item_date_add_interval::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
{
INTERVAL interval;
- if (args[0]->get_date(ltime, TIME_NO_ZERO_DATE | TIME_FUZZY_DATE | TIME_NO_ZERO_IN_DATE) ||
+ if (args[0]->get_date(ltime, 0) ||
get_interval_value(args[1], int_type, &interval))
return (null_value=1);
+ if (ltime->time_type != MYSQL_TIMESTAMP_TIME &&
+ check_date_with_warn(ltime, TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE,
+ MYSQL_TIMESTAMP_ERROR))
+ return (null_value=1);
+
if (date_sub_interval)
interval.neg = !interval.neg;
@@ -2129,7 +2133,7 @@ longlong Item_extract::val_int()
long neg;
int is_time_flag = date_value ? 0 : TIME_TIME_ONLY;
- if (get_arg0_date(&ltime, TIME_FUZZY_DATE | is_time_flag))
+ if (get_arg0_date(&ltime, is_time_flag))
return 0;
neg= ltime.neg ? -1 : 1;
@@ -2553,7 +2557,7 @@ bool Item_func_add_time::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
if (is_date) // TIMESTAMP function
{
- if (get_arg0_date(&l_time1, TIME_FUZZY_DATE) ||
+ if (get_arg0_date(&l_time1, 0) ||
args[1]->get_time(&l_time2) ||
l_time1.time_type == MYSQL_TIMESTAMP_TIME ||
l_time2.time_type != MYSQL_TIMESTAMP_TIME)