diff options
author | Alexander Barkov <bar@mariadb.com> | 2018-09-27 16:38:14 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2018-09-27 16:38:14 +0400 |
commit | 492998c0d80aa7d5c4804ac7792a38333e3b83dd (patch) | |
tree | 376d323584d3d846bf62d5c50293181af9db9397 /sql | |
parent | 786940d7e03630d28d82bca4388c937c0d48594a (diff) | |
download | mariadb-git-492998c0d80aa7d5c4804ac7792a38333e3b83dd.tar.gz |
MDEV-15406 NO_ZERO_IN_DATE erroneously affects how CAST(AS DATE) warns about fractional digit truncation
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sql_type.cc | 60 | ||||
-rw-r--r-- | sql/sql_type.h | 4 |
2 files changed, 17 insertions, 47 deletions
diff --git a/sql/sql_type.cc b/sql/sql_type.cc index e3c854a227f..31a066271db 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -215,60 +215,34 @@ void Sec6::make_truncated_warning(THD *thd, const char *type_str) const } -bool Sec6::to_time_with_warn(MYSQL_TIME *to, const ErrConv *str, - const char *field_name) const -{ - int was_cut; - bool res= to_time(to, &was_cut); - if (res || MYSQL_TIME_WARN_HAVE_WARNINGS(was_cut)) - current_thd-> - push_warning_wrong_or_truncated_value(Sql_condition::WARN_LEVEL_WARN, - res, "time", str->ptr(), - field_name); - return res; -} - - -bool Sec6::to_datetime_with_warn(MYSQL_TIME *to, ulonglong fuzzydate, - const ErrConv *str, - const char *field_name) const -{ - bool res, have_warnings= false; - int was_cut; - res= to_datetime(to, fuzzydate, &was_cut); - have_warnings= was_cut && (fuzzydate & TIME_NO_ZERO_IN_DATE); - if (res || have_warnings) - current_thd-> - push_warning_wrong_or_truncated_value(Sql_condition::WARN_LEVEL_WARN, - res, "datetime", str->ptr(), - field_name); - return res; -} - - bool Sec6::convert_to_mysql_time(MYSQL_TIME *ltime, ulonglong fuzzydate, const ErrConv *str, const char *field_name) const { + int warn; bool is_time= fuzzydate & TIME_TIME_ONLY; + const char *typestr= is_time ? "time" : "datetime"; + bool rc= is_time ? to_time(ltime, &warn) : + to_datetime(ltime, fuzzydate, &warn); if (truncated()) { - /* - The value was already truncated at the constructor call time, - and a truncation warning was issued. Here we convert silently - to avoid double warnings. - */ + // The value was already truncated at the constructor call time current_thd-> push_warning_wrong_or_truncated_value(Sql_condition::WARN_LEVEL_WARN, - !is_time, - is_time ? "time" : "datetime", + !is_time, typestr, str->ptr(), field_name); - int warn; - return is_time ? to_time(ltime, &warn) : - to_datetime(ltime, fuzzydate, &warn); } - return is_time ? to_time_with_warn(ltime, str, field_name) : - to_datetime_with_warn(ltime, fuzzydate, str, field_name); + else if (rc || MYSQL_TIME_WARN_HAVE_WARNINGS(warn)) + current_thd-> + push_warning_wrong_or_truncated_value(Sql_condition::WARN_LEVEL_WARN, + rc, typestr, str->ptr(), + field_name); + else if (MYSQL_TIME_WARN_HAVE_NOTES(warn)) + current_thd-> + push_warning_wrong_or_truncated_value(Sql_condition::WARN_LEVEL_NOTE, + rc, typestr, str->ptr(), + field_name); + return rc; } diff --git a/sql/sql_type.h b/sql/sql_type.h index 21704bf9ef0..f48d0c3af51 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -273,8 +273,6 @@ public: { return number_to_time(m_neg, m_sec, m_usec, to, warn); } - bool to_time_with_warn(MYSQL_TIME *to, const ErrConv *str, - const char *field_name) const; /* Convert a number in format YYYYMMDDhhmmss.ff to TIMESTAMP'YYYY-MM-DD hh:mm:ss.ff' @@ -288,8 +286,6 @@ public: } return number_to_datetime(m_sec, m_usec, to, flags, warn) == -1; } - bool to_datetime_with_warn(MYSQL_TIME *to, ulonglong fuzzydate, - const ErrConv *str, const char *field_name) const; // Convert elapsed seconds to TIME bool sec_to_time(MYSQL_TIME *ltime, uint dec) const { |