diff options
Diffstat (limited to 'sql/sql_time.cc')
-rw-r--r-- | sql/sql_time.cc | 83 |
1 files changed, 21 insertions, 62 deletions
diff --git a/sql/sql_time.cc b/sql/sql_time.cc index 630d150be77..9562394f11e 100644 --- a/sql/sql_time.cc +++ b/sql/sql_time.cc @@ -377,9 +377,11 @@ bool Temporal::str_to_time(MYSQL_TIME_STATUS *status, date_mode_t fuzzydate) { TemporalAsciiBuffer tmp(str, length, cs); - return ::str_to_time(tmp.str, tmp.length, this, + bool rc= ::str_to_time(tmp.str, tmp.length, this, ulonglong(fuzzydate & TIME_MODE_FOR_XXX_TO_DATE), status); + DBUG_ASSERT(status->warnings || !rc); + return rc; } @@ -389,9 +391,11 @@ bool Temporal::str_to_datetime(MYSQL_TIME_STATUS *status, date_mode_t flags) { TemporalAsciiBuffer tmp(str, length, cs); - return ::str_to_datetime(tmp.str, tmp.length, this, + bool rc= ::str_to_datetime(tmp.str, tmp.length, this, ulonglong(flags & TIME_MODE_FOR_XXX_TO_DATE), status); + DBUG_ASSERT(status->warnings || !rc); + return rc; } @@ -401,7 +405,9 @@ bool Interval_DDhhmmssff::str_to_DDhhmmssff(MYSQL_TIME_STATUS *status, CHARSET_INFO *cs, ulong max_hour) { TemporalAsciiBuffer tmp(str, length, cs); - return ::str_to_DDhhmmssff(tmp.str, tmp.length, this, UINT_MAX32, status); + bool rc= ::str_to_DDhhmmssff(tmp.str, tmp.length, this, UINT_MAX32, status); + DBUG_ASSERT(status->warnings || !rc); + return rc; } @@ -413,45 +419,22 @@ bool Interval_DDhhmmssff::str_to_DDhhmmssff(MYSQL_TIME_STATUS *status, See description of str_to_datetime() for more information. */ -static bool -str_to_datetime_with_warn(THD *thd, CHARSET_INFO *cs, - const char *str, size_t length, MYSQL_TIME *l_time, - date_mode_t flags, MYSQL_TIME_STATUS *status) -{ - Temporal_hybrid *t= new(l_time) Temporal_hybrid(status, str, length, cs, flags); - if (!t->is_valid_temporal() || status->warnings) - { - const ErrConvString err(str, length, &my_charset_bin); - make_truncated_value_warning(thd, - !t->is_valid_temporal() ? - Sql_condition::WARN_LEVEL_WARN : - Sql_condition::time_warn_level(status->warnings), - &err, flags & TIME_TIME_ONLY ? - MYSQL_TIMESTAMP_TIME : l_time->time_type, NullS); - } - DBUG_EXECUTE_IF("str_to_datetime_warn", - push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, - ER_YES, str);); - return !t->is_valid_temporal(); -} - - bool str_to_datetime_with_warn(THD *thd, CHARSET_INFO *cs, - const char *str, size_t length, MYSQL_TIME *l_time, - date_mode_t flags) + const char *str, size_t length, MYSQL_TIME *to, + date_mode_t mode) { - MYSQL_TIME_STATUS status; - return str_to_datetime_with_warn(thd, cs, str, length, l_time, flags, &status); + Temporal::Warn_push warn(thd, NullS, to, mode); + Temporal_hybrid *t= new(to) Temporal_hybrid(thd, &warn, str, length, cs, mode); + return !t->is_valid_temporal(); } bool double_to_datetime_with_warn(THD *thd, double value, MYSQL_TIME *ltime, date_mode_t fuzzydate, const char *field_name) { - const ErrConvDouble str(value); - Temporal_hybrid *t= new (ltime) Temporal_hybrid(thd, Sec6(value), fuzzydate, - &str, field_name); + Temporal::Warn_push warn(thd, field_name, ltime, fuzzydate); + Temporal_hybrid *t= new (ltime) Temporal_hybrid(thd, &warn, value, fuzzydate); return !t->is_valid_temporal(); } @@ -460,9 +443,8 @@ bool decimal_to_datetime_with_warn(THD *thd, const my_decimal *value, MYSQL_TIME *ltime, date_mode_t fuzzydate, const char *field_name) { - const ErrConvDecimal str(value); - Temporal_hybrid *t= new (ltime) Temporal_hybrid(thd, Sec6(value), fuzzydate, - &str, field_name); + Temporal::Warn_push warn(thd, field_name, ltime, fuzzydate); + Temporal_hybrid *t= new (ltime) Temporal_hybrid(thd, &warn, value, fuzzydate); return !t->is_valid_temporal(); } @@ -471,14 +453,12 @@ bool int_to_datetime_with_warn(THD *thd, const Longlong_hybrid &nr, MYSQL_TIME *ltime, date_mode_t fuzzydate, const char *field_name) { - const ErrConvInteger str(nr); /* Note: conversion from an integer to TIME can overflow to '838:59:59.999999', so the conversion result can have fractional digits. */ - Temporal_hybrid *t= new (ltime) - Temporal_hybrid(thd, Sec6(nr), - fuzzydate, &str, field_name); + Temporal::Warn_push warn(thd, field_name, ltime, fuzzydate); + Temporal_hybrid *t= new (ltime) Temporal_hybrid(thd, &warn, nr, fuzzydate); return !t->is_valid_temporal(); } @@ -909,20 +889,7 @@ void make_truncated_value_warning(THD *thd, timestamp_type time_type, const char *field_name) { - const char *type_str; - - switch (time_type) { - case MYSQL_TIMESTAMP_DATE: - type_str= "date"; - break; - case MYSQL_TIMESTAMP_TIME: - type_str= "time"; - break; - case MYSQL_TIMESTAMP_DATETIME: // FALLTHROUGH - default: - type_str= "datetime"; - break; - } + const char *type_str= Temporal::type_name_by_timestamp_type(time_type); return thd->push_warning_wrong_or_truncated_value(level, time_type <= MYSQL_TIMESTAMP_ERROR, type_str, sval->ptr(), field_name); @@ -1400,11 +1367,3 @@ void unpack_time(longlong packed, MYSQL_TIME *my_time, break; } } - - -bool my_decimal::to_datetime_with_warn(THD *thd, MYSQL_TIME *to, - date_mode_t fuzzydate, - const char *field_name) -{ - return decimal_to_datetime_with_warn(thd, this, to, fuzzydate, field_name); -} |