diff options
Diffstat (limited to 'sql/item_timefunc.cc')
-rw-r--r-- | sql/item_timefunc.cc | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 1c2c1cfe512..24cf4da0a95 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2338,8 +2338,6 @@ void Item_extract::print(String *str, enum_query_type query_type) void Item_extract::fix_length_and_dec() { - value.alloc(32); // alloc buffer - maybe_null=1; // If wrong date switch (int_type) { case INTERVAL_YEAR: max_length=4; date_value=1; break; @@ -2382,6 +2380,8 @@ longlong Item_extract::val_int() } else { + char buf[40]; + String value(buf, sizeof(buf), &my_charset_bin);; String *res= args[0]->val_str(&value); if (!res || str_to_time_with_warn(res->charset(), res->ptr(), res->length(), @@ -3368,6 +3368,8 @@ void Item_func_str_to_date::fix_length_and_dec() cached_field_type= MYSQL_TYPE_DATETIME; max_length= MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN; cached_timestamp_type= MYSQL_TIMESTAMP_NONE; + sql_mode= (current_thd->variables.sql_mode & + (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE)); if ((const_item= args[1]->const_item())) { char format_buff[64]; @@ -3433,6 +3435,14 @@ bool Item_func_str_to_date::get_date(MYSQL_TIME *ltime, uint fuzzy_date) return 0; null_date: + if (fuzzy_date & TIME_NO_ZERO_DATE) + { + char buff[128]; + strmake(buff, val->ptr(), min(val->length(), sizeof(buff)-1)); + push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE), + "datetime", buff, "str_to_date"); + } return (null_value=1); } @@ -3442,7 +3452,7 @@ String *Item_func_str_to_date::val_str(String *str) DBUG_ASSERT(fixed == 1); MYSQL_TIME ltime; - if (Item_func_str_to_date::get_date(<ime, TIME_FUZZY_DATE)) + if (Item_func_str_to_date::get_date(<ime, TIME_FUZZY_DATE | sql_mode)) return 0; if (!make_datetime((const_item ? cached_format_type : @@ -3453,6 +3463,29 @@ String *Item_func_str_to_date::val_str(String *str) } +longlong Item_func_str_to_date::val_int() +{ + DBUG_ASSERT(fixed == 1); + MYSQL_TIME ltime; + + if (Item_func_str_to_date::get_date(<ime, TIME_FUZZY_DATE | sql_mode)) + return 0; + + if (const_item) + { + switch (cached_field_type) { + case MYSQL_TYPE_DATE: + return TIME_to_ulonglong_date(<ime); + case MYSQL_TYPE_TIME: + return TIME_to_ulonglong_time(<ime); + default: + return TIME_to_ulonglong_datetime(<ime); + } + } + return TIME_to_ulonglong_datetime(<ime); +} + + bool Item_func_last_day::get_date(MYSQL_TIME *ltime, uint fuzzy_date) { if (get_arg0_date(ltime, fuzzy_date & ~TIME_FUZZY_DATE) || |