Commit 55dd0776 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-17331 Reuse Temporal_hybrid in xxx_to_date_with_warn()

parent e5aebc14
...@@ -403,29 +403,36 @@ bool Temporal::str_to_datetime(MYSQL_TIME_STATUS *status, ...@@ -403,29 +403,36 @@ bool Temporal::str_to_datetime(MYSQL_TIME_STATUS *status,
See description of str_to_datetime() for more information. See description of str_to_datetime() for more information.
*/ */
bool static bool
str_to_datetime_with_warn(THD *thd, CHARSET_INFO *cs, str_to_datetime_with_warn(THD *thd, CHARSET_INFO *cs,
const char *str, size_t length, MYSQL_TIME *l_time, const char *str, size_t length, MYSQL_TIME *l_time,
date_mode_t flags) date_mode_t flags, MYSQL_TIME_STATUS *status)
{ {
MYSQL_TIME_STATUS status; Temporal_hybrid *t= new(l_time) Temporal_hybrid(status, str, length, cs, flags);
TemporalAsciiBuffer tmp(str, length, cs); if (!t->is_valid_temporal() || status->warnings)
bool ret_val= str_to_datetime(tmp.str, tmp.length, l_time,
ulonglong(flags & TIME_MODE_FOR_XXX_TO_DATE),
&status);
if (ret_val || status.warnings)
{ {
const ErrConvString err(str, length, &my_charset_bin); const ErrConvString err(str, length, &my_charset_bin);
make_truncated_value_warning(thd, make_truncated_value_warning(thd,
ret_val ? Sql_condition::WARN_LEVEL_WARN : !t->is_valid_temporal() ?
Sql_condition::time_warn_level(status.warnings), Sql_condition::WARN_LEVEL_WARN :
Sql_condition::time_warn_level(status->warnings),
&err, flags & TIME_TIME_ONLY ? &err, flags & TIME_TIME_ONLY ?
MYSQL_TIMESTAMP_TIME : l_time->time_type, NullS); MYSQL_TIMESTAMP_TIME : l_time->time_type, NullS);
} }
DBUG_EXECUTE_IF("str_to_datetime_warn", DBUG_EXECUTE_IF("str_to_datetime_warn",
push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, push_warning(thd, Sql_condition::WARN_LEVEL_NOTE,
ER_YES, str);); ER_YES, str););
return ret_val; 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)
{
MYSQL_TIME_STATUS status;
return str_to_datetime_with_warn(thd, cs, str, length, l_time, flags, &status);
} }
...@@ -433,8 +440,9 @@ bool double_to_datetime_with_warn(THD *thd, double value, MYSQL_TIME *ltime, ...@@ -433,8 +440,9 @@ bool double_to_datetime_with_warn(THD *thd, double value, MYSQL_TIME *ltime,
date_mode_t fuzzydate, const char *field_name) date_mode_t fuzzydate, const char *field_name)
{ {
const ErrConvDouble str(value); const ErrConvDouble str(value);
return Sec6(value).convert_to_mysql_time(thd, ltime, fuzzydate, Temporal_hybrid *t= new (ltime) Temporal_hybrid(thd, Sec6(value), fuzzydate,
&str, field_name); &str, field_name);
return !t->is_valid_temporal();
} }
...@@ -443,8 +451,9 @@ bool decimal_to_datetime_with_warn(THD *thd, const my_decimal *value, ...@@ -443,8 +451,9 @@ bool decimal_to_datetime_with_warn(THD *thd, const my_decimal *value,
date_mode_t fuzzydate, const char *field_name) date_mode_t fuzzydate, const char *field_name)
{ {
const ErrConvDecimal str(value); const ErrConvDecimal str(value);
return Sec6(value).convert_to_mysql_time(thd, ltime, fuzzydate, Temporal_hybrid *t= new (ltime) Temporal_hybrid(thd, Sec6(value), fuzzydate,
&str, field_name); &str, field_name);
return !t->is_valid_temporal();
} }
...@@ -453,8 +462,14 @@ bool int_to_datetime_with_warn(THD *thd, bool neg, ulonglong value, ...@@ -453,8 +462,14 @@ bool int_to_datetime_with_warn(THD *thd, bool neg, ulonglong value,
date_mode_t fuzzydate, const char *field_name) date_mode_t fuzzydate, const char *field_name)
{ {
const ErrConvInteger str(neg ? - (longlong) value : (longlong) value, !neg); const ErrConvInteger str(neg ? - (longlong) value : (longlong) value, !neg);
Sec6 sec(neg, value, 0); /*
return sec.convert_to_mysql_time(thd, ltime, fuzzydate, &str, field_name); 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(neg, value, 0),
fuzzydate, &str, field_name);
return !t->is_valid_temporal();
} }
......
...@@ -500,6 +500,12 @@ class Temporal_hybrid: public Temporal ...@@ -500,6 +500,12 @@ class Temporal_hybrid: public Temporal
if (str_to_datetime(st, str, length, cs, fuzzydate)) if (str_to_datetime(st, str, length, cs, fuzzydate))
time_type= MYSQL_TIMESTAMP_NONE; time_type= MYSQL_TIMESTAMP_NONE;
} }
Temporal_hybrid(THD *thd, const Sec6 &sec, date_mode_t fuzzydate,
const ErrConv *str, const char *field_name)
{
if (sec.convert_to_mysql_time(thd, this, fuzzydate, str, field_name))
time_type= MYSQL_TIMESTAMP_NONE;
}
longlong to_longlong() const longlong to_longlong() const
{ {
if (!is_valid_temporal()) if (!is_valid_temporal())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment