diff options
author | Alexander Barkov <bar@mariadb.com> | 2018-09-16 12:40:57 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2018-09-16 12:41:48 +0400 |
commit | d93399746df8a730109c7363eaf0502923a39e02 (patch) | |
tree | 793d2a8d197ec2679ffe49a642b31666103c7203 /sql | |
parent | 171fbbb968ed52dc7e2bbd33a6f8f72bbc6f5e88 (diff) | |
download | mariadb-git-d93399746df8a730109c7363eaf0502923a39e02.tar.gz |
MDEV-17203 Move fractional second truncation from Item_xxx_typecast::get_date() to Time and Datetime constructors
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item_timefunc.cc | 37 | ||||
-rw-r--r-- | sql/sql_time.cc | 30 | ||||
-rw-r--r-- | sql/sql_time.h | 2 | ||||
-rw-r--r-- | sql/sql_type.h | 16 |
4 files changed, 26 insertions, 59 deletions
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 84db154566a..1cc0d0bb2e1 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2474,43 +2474,26 @@ void Item_char_typecast::fix_length_and_dec_internal(CHARSET_INFO *from_cs) bool Item_time_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) { - Time tm(args[0], Time::Options_for_cast()); - if ((null_value= !tm.is_valid_time())) - return true; - tm.copy_to_mysql_time(ltime); - if (decimals < TIME_SECOND_PART_DIGITS) - my_time_trunc(ltime, decimals); - return (fuzzy_date & TIME_TIME_ONLY) ? 0 : - (null_value= check_date_with_warn(ltime, fuzzy_date, - MYSQL_TIMESTAMP_ERROR)); + Time *tm= new(ltime) Time(args[0], Time::Options_for_cast(), + MY_MIN(decimals, TIME_SECOND_PART_DIGITS)); + return (null_value= !tm->is_valid_time()); } bool Item_date_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) { - fuzzy_date |= sql_mode_for_dates(current_thd); - if (get_arg0_date(ltime, fuzzy_date & ~TIME_TIME_ONLY)) - return 1; - - if (make_date_with_warn(ltime, fuzzy_date, MYSQL_TIMESTAMP_DATE)) - return (null_value= 1); - - return 0; + fuzzy_date= (fuzzy_date | sql_mode_for_dates(current_thd)) & ~TIME_TIME_ONLY; + Date *d= new(ltime) Date(current_thd, args[0], fuzzy_date); + return (null_value= !d->is_valid_date()); } bool Item_datetime_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date) { - fuzzy_date |= sql_mode_for_dates(current_thd); - if (get_arg0_date(ltime, fuzzy_date & ~TIME_TIME_ONLY)) - return 1; - - if (decimals < TIME_SECOND_PART_DIGITS) - my_time_trunc(ltime, decimals); - - DBUG_ASSERT(ltime->time_type != MYSQL_TIMESTAMP_TIME); - ltime->time_type= MYSQL_TIMESTAMP_DATETIME; - return 0; + fuzzy_date= (fuzzy_date | sql_mode_for_dates(current_thd)) & ~TIME_TIME_ONLY; + Datetime *dt= new(ltime) Datetime(current_thd, args[0], fuzzy_date, + MY_MIN(decimals, TIME_SECOND_PART_DIGITS)); + return (null_value= !dt->is_valid_datetime()); } diff --git a/sql/sql_time.cc b/sql/sql_time.cc index 7b1cb504f08..ee56022a868 100644 --- a/sql/sql_time.cc +++ b/sql/sql_time.cc @@ -1185,36 +1185,6 @@ bool time_to_datetime(MYSQL_TIME *ltime) } -/** - Return a valid DATE or DATETIME value from an arbitrary MYSQL_TIME. - If ltime is TIME, it's first converted to DATETIME. - If ts_type is DATE, hhmmss is set to zero. - The date part of the result is checked against fuzzy_date. - - @param ltime The value to convert. - @param fuzzy_date Flags to check date. - @param ts_type The type to convert to. - @return false on success, true of error (negative time).*/ -bool -make_date_with_warn(MYSQL_TIME *ltime, ulonglong fuzzy_date, - timestamp_type ts_type) -{ - DBUG_ASSERT(ts_type == MYSQL_TIMESTAMP_DATE || - ts_type == MYSQL_TIMESTAMP_DATETIME); - if (ltime->time_type == MYSQL_TIMESTAMP_TIME && time_to_datetime(ltime)) - { - /* e.g. negative time */ - ErrConvTime str(ltime); - make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN, - &str, ts_type, 0); - return true; - } - if ((ltime->time_type= ts_type) == MYSQL_TIMESTAMP_DATE) - ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0; - return check_date_with_warn(ltime, fuzzy_date, ts_type); -} - - /* Convert a TIME value to DAY-TIME interval, e.g. for extraction: EXTRACT(DAY FROM x), EXTRACT(HOUR FROM x), etc. diff --git a/sql/sql_time.h b/sql/sql_time.h index 862289ffdf1..47c057cd9b5 100644 --- a/sql/sql_time.h +++ b/sql/sql_time.h @@ -168,8 +168,6 @@ check_date(const MYSQL_TIME *ltime, ulonglong flags, int *was_cut) } bool check_date_with_warn(const MYSQL_TIME *ltime, ulonglong fuzzy_date, timestamp_type ts_type); -bool make_date_with_warn(MYSQL_TIME *ltime, - ulonglong fuzzy_date, timestamp_type ts_type); bool adjust_time_range_with_warn(MYSQL_TIME *ltime, uint dec); longlong pack_time(const MYSQL_TIME *my_time); diff --git a/sql/sql_type.h b/sql/sql_type.h index 4eaf578fac1..c497e041ea0 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -471,6 +471,12 @@ protected: bool str_to_datetime(MYSQL_TIME_STATUS *st, const char *str, size_t length, CHARSET_INFO *cs, sql_mode_t fuzzydate); public: + static void *operator new(size_t size, MYSQL_TIME *ltime) throw() + { + DBUG_ASSERT(size == sizeof(MYSQL_TIME)); + return ltime; + } + long fraction_remainder(uint dec) const { return my_time_fraction_remainder(second_part, dec); @@ -772,6 +778,11 @@ public: :Temporal(Time(warn, Sec6(d), Options())) { } + Time(Item *item, const Options opt, uint dec) + :Temporal(Time(item, opt)) + { + trunc(dec); + } Time(int *warn, const MYSQL_TIME *from, long curdays, uint dec) :Temporal(Time(warn, from, curdays)) { @@ -1125,6 +1136,11 @@ public: DBUG_ASSERT(is_valid_value_slow()); } + Datetime(THD *thd, Item *item, sql_mode_t flags, uint dec) + :Temporal_with_date(Datetime(thd, item, flags)) + { + trunc(dec); + } Datetime(MYSQL_TIME_STATUS *status, const char *str, size_t len, CHARSET_INFO *cs, sql_mode_t fuzzydate, uint dec) |