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