Commit 144c7f8b authored by Alexander Barkov's avatar Alexander Barkov

Adding Field_timestamp::sql_mode_for_timestamp() to reuse duplicate code

parent 5417002d
......@@ -5016,6 +5016,13 @@ copy_or_convert_to_datetime(THD *thd, const MYSQL_TIME *from, MYSQL_TIME *to)
}
sql_mode_t Field_timestamp::sql_mode_for_timestamp(THD *thd) const
{
// We don't want to store invalid or fuzzy datetime values in TIMESTAMP
return (thd->variables.sql_mode & MODE_NO_ZERO_DATE) | MODE_NO_ZERO_IN_DATE;
}
int Field_timestamp::store_time_dec(const MYSQL_TIME *ltime, uint dec)
{
int unused;
......@@ -5024,9 +5031,7 @@ int Field_timestamp::store_time_dec(const MYSQL_TIME *ltime, uint dec)
MYSQL_TIME l_time;
bool valid= !copy_or_convert_to_datetime(thd, ltime, &l_time) &&
!check_date(&l_time, pack_time(&l_time) != 0,
(thd->variables.sql_mode & MODE_NO_ZERO_DATE) |
MODE_NO_ZERO_IN_DATE, &unused);
sql_mode_for_timestamp(thd), &unused);
return store_TIME_with_warning(thd, &l_time, &str, false, valid);
}
......@@ -5039,11 +5044,8 @@ int Field_timestamp::store(const char *from,uint len,CHARSET_INFO *cs)
ErrConvString str(from, len, cs);
THD *thd= get_thd();
/* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */
have_smth_to_conv= !str_to_datetime(cs, from, len, &l_time,
(thd->variables.sql_mode &
MODE_NO_ZERO_DATE) |
MODE_NO_ZERO_IN_DATE, &status);
sql_mode_for_timestamp(thd), &status);
return store_TIME_with_warning(thd, &l_time, &str,
status.warnings, have_smth_to_conv);
}
......@@ -5056,9 +5058,8 @@ int Field_timestamp::store(double nr)
ErrConvDouble str(nr);
THD *thd= get_thd();
longlong tmp= double_to_datetime(nr, &l_time, (thd->variables.sql_mode &
MODE_NO_ZERO_DATE) |
MODE_NO_ZERO_IN_DATE, &error);
longlong tmp= double_to_datetime(nr, &l_time, sql_mode_for_timestamp(thd),
&error);
return store_TIME_with_warning(thd, &l_time, &str, error, tmp != -1);
}
......@@ -5070,10 +5071,8 @@ int Field_timestamp::store(longlong nr, bool unsigned_val)
ErrConvInteger str(nr, unsigned_val);
THD *thd= get_thd();
/* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */
longlong tmp= number_to_datetime(nr, 0, &l_time, (thd->variables.sql_mode &
MODE_NO_ZERO_DATE) |
MODE_NO_ZERO_IN_DATE, &error);
longlong tmp= number_to_datetime(nr, 0, &l_time, sql_mode_for_timestamp(thd),
&error);
return store_TIME_with_warning(thd, &l_time, &str, error, tmp != -1);
}
......@@ -5398,10 +5397,8 @@ int Field_timestamp::store_decimal(const my_decimal *d)
error= 2;
}
else
tmp= number_to_datetime(nr, sec_part, &ltime, TIME_NO_ZERO_IN_DATE |
(thd->variables.sql_mode &
MODE_NO_ZERO_DATE), &error);
tmp= number_to_datetime(nr, sec_part, &ltime, sql_mode_for_timestamp(thd),
&error);
return store_TIME_with_warning(thd, &ltime, &str, error, tmp != -1);
}
......
......@@ -2359,6 +2359,7 @@ class Field_temporal_with_date: public Field_temporal {
class Field_timestamp :public Field_temporal {
protected:
sql_mode_t sql_mode_for_timestamp(THD *thd) const;
int store_TIME_with_warning(THD *, MYSQL_TIME *, const ErrConv *,
int warnings, bool have_smth_to_conv);
public:
......
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