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.cc78
1 files changed, 32 insertions, 46 deletions
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index e9a6727162a..a4b5a18de35 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -415,10 +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_IN_DATE) &&
- (l_time->year == 0 || l_time->month == 0 || l_time->day == 0)) ||
- ((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)
@@ -711,8 +709,8 @@ static bool get_interval_info(const char *str,uint length,CHARSET_INFO *cs,
{
longlong value;
const char *start= str;
- for (value=0; str != end && my_isdigit(cs,*str) ; str++)
- value= value*LL(10) + (longlong) (*str - '0');
+ for (value=0; str != end && my_isdigit(cs, *str) ; str++)
+ value= value*10 + *str - '0';
msec_length= 6 - (str - start);
values[i]= value;
while (str != end && !my_isdigit(cs,*str))
@@ -782,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;
@@ -860,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;
@@ -868,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)
@@ -925,16 +922,14 @@ longlong Item_func_dayofmonth::val_int()
{
DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime;
- (void) get_arg0_date(&ltime, TIME_FUZZY_DATE);
- return (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;
- (void) get_arg0_date(&ltime, TIME_FUZZY_DATE);
- return (longlong) ltime.month;
+ return get_arg0_date(&ltime, 0) ? 0 : (longlong) ltime.month;
}
@@ -958,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];
@@ -976,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);
}
@@ -985,16 +980,14 @@ longlong Item_func_hour::val_int()
{
DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime;
- (void) get_arg0_time(&ltime);
- return ltime.hour;
+ return get_arg0_time(&ltime) ? 0 : ltime.hour;
}
longlong Item_func_minute::val_int()
{
DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime;
- (void) get_arg0_time(&ltime);
- return ltime.minute;
+ return get_arg0_time(&ltime) ? 0 : ltime.minute;
}
/**
@@ -1004,8 +997,7 @@ longlong Item_func_second::val_int()
{
DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime;
- (void) get_arg0_time(&ltime);
- return ltime.second;
+ return get_arg0_time(&ltime) ? 0 : ltime.second;
}
@@ -1122,8 +1114,7 @@ longlong Item_func_year::val_int()
{
DBUG_ASSERT(fixed == 1);
MYSQL_TIME ltime;
- (void) get_arg0_date(&ltime, TIME_FUZZY_DATE);
- return (longlong) ltime.year;
+ return get_arg0_date(&ltime, 0) ? 0 : (longlong) ltime.year;
}
@@ -1155,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;
@@ -1198,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;
@@ -1476,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;
@@ -1487,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);
}
@@ -1582,7 +1573,7 @@ static void set_sec_part(ulong sec_part, MYSQL_TIME *ltime, Item *item)
{
ltime->second_part= sec_part;
if (item->decimals < TIME_SECOND_PART_DIGITS)
- ltime->second_part= sec_part_truncate(ltime->second_part, item->decimals);
+ my_time_trunc(ltime, item->decimals);
}
}
@@ -1867,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())
@@ -2041,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;
@@ -2137,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;
@@ -2419,7 +2415,7 @@ bool Item_time_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
if (get_arg0_time(ltime))
return 1;
if (decimals < TIME_SECOND_PART_DIGITS)
- ltime->second_part= sec_part_truncate(ltime->second_part, decimals);
+ my_time_trunc(ltime, decimals);
/*
MYSQL_TIMESTAMP_TIME value can have non-zero day part,
which we should not lose.
@@ -2439,17 +2435,8 @@ bool Item_date_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0;
ltime->time_type= MYSQL_TIMESTAMP_DATE;
-
- int unused;
- if (check_date(ltime, ltime->year || ltime->month || ltime->day,
- fuzzy_date, &unused))
- {
- ErrConvTime str(ltime);
- make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN,
- &str, MYSQL_TIMESTAMP_DATE, 0);
- return (null_value= 1);
- }
- return (null_value= 0);
+ return (null_value= check_date_with_warn(ltime, fuzzy_date,
+ MYSQL_TIMESTAMP_DATE));
}
@@ -2460,8 +2447,7 @@ bool Item_datetime_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
return 1;
if (decimals < TIME_SECOND_PART_DIGITS)
- ltime->second_part= sec_part_truncate(ltime->second_part, decimals);
-
+ my_time_trunc(ltime, decimals);
/*
ltime is valid MYSQL_TYPE_TIME (according to fuzzy_date).
@@ -2573,7 +2559,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)