1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MDEV-16991 Rounding vs truncation for TIME, DATETIME, TIMESTAMP

This commit is contained in:
Alexander Barkov
2018-11-23 19:04:42 +04:00
parent 27f3329ff6
commit 4447a02cf1
59 changed files with 4774 additions and 398 deletions

View File

@ -1346,7 +1346,6 @@ public:
void copy_from_tmp(int offset);
uint fill_cache_field(struct st_cache_field *copy);
virtual bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate);
bool get_time(MYSQL_TIME *ltime) { return get_date(ltime, TIME_TIME_ONLY); }
virtual TYPELIB *get_typelib() const { return NULL; }
virtual CHARSET_INFO *charset(void) const { return &my_charset_bin; }
virtual CHARSET_INFO *charset_for_protocol(void) const
@ -2643,7 +2642,8 @@ public:
int save_in_field(Field *to)
{
MYSQL_TIME ltime;
if (get_date(&ltime, date_mode_t(0)))
// For temporal types no truncation needed. Rounding mode is not important.
if (get_date(&ltime, TIME_CONV_NONE | TIME_FRAC_NONE))
return to->reset();
return to->store_time_dec(&ltime, decimals());
}
@ -2721,7 +2721,6 @@ public:
class Field_timestamp :public Field_temporal {
protected:
date_mode_t sql_mode_for_timestamp(THD *thd) const;
int store_TIME_with_warning(THD *, const Datetime *,
const ErrConv *, int warn);
virtual void store_TIMEVAL(const timeval &tv)
@ -2771,10 +2770,15 @@ public:
{
return get_timestamp(ptr, sec_part);
}
// This is used by storage/perfschema
void store_TIME(my_time_t timestamp, ulong sec_part)
/*
This method is used by storage/perfschema and
Item_func_now_local::save_in_field().
*/
void store_TIME(my_time_t ts, ulong sec_part)
{
store_TIMESTAMP(Timestamp(timestamp, sec_part).trunc(decimals()));
int warn;
time_round_mode_t mode= Datetime::default_round_mode(get_thd());
store_TIMESTAMP(Timestamp(ts, sec_part).round(decimals(), mode, &warn));
}
bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate);
uchar *pack(uchar *to, const uchar *from,