[MDEV-17182] Move fractional second truncation outside of Field_xxx::store_TIME_with_warn() Created: 2018-09-12  Updated: 2018-09-16  Resolved: 2018-09-12

Status: Closed
Project: MariaDB Server
Component/s: Data types, Temporal Types
Fix Version/s: 10.4.0

Type: Task Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-16991 Rounding vs truncation for TIME, DATE... Closed
Relates
relates to MDEV-17203 Move fractional second truncation fro... Closed

 Description   

This task is self-sufficient change MDEV-16991.

To make the main MDEV-16991 patch simpler, we'll move fractional second truncation from these methods:

int Field_timestamp::store_TIME_with_warning()
int Field_temporal_with_date::store_TIME_with_warning()
int Field_time::store_TIME_with_warning()

to the caller level. store_TIME_with_warning() will get an already properly truncated value.

We'll also add truncating constructors for Time and Datetime.

For example, for Datetime, the new constructors will looks approximately like this:

  Datetime(MYSQL_TIME_STATUS *status,
           const char *str, size_t len, CHARSET_INFO *cs,
           sql_mode_t fuzzydate, uint dec)
   :Temporal_with_date(Datetime(status, str, len, cs, fuzzydate))
  {
    trunc(dec);
  }
  Datetime(int *warn, double nr, sql_mode_t fuzzydate, uint dec)
   :Temporal_with_date(Datetime(warn, nr, fuzzydate))
  {
    trunc(dec);
  }
  Datetime(int *warn, const my_decimal *d, sql_mode_t fuzzydate, uint dec)
   :Temporal_with_date(Datetime(warn, d, fuzzydate))
  {
    trunc(dec);
  }
  Datetime(THD *thd, int *warn, const MYSQL_TIME *from,
           sql_mode_t fuzzydate, uint dec)
   :Temporal_with_date(Datetime(thd, warn, from, fuzzydate))
  {
    trunc(dec);
  }

The callers will be changed to truncate the value before passing it to store_TIME_with_warn(). For example, in case of string-to-TIME conversion, the change will look like this:

 int Field_time::store(const char *from,size_t len,CHARSET_INFO *cs)
 {
   ErrConvString str(from, len, cs);
   MYSQL_TIME_STATUS st;
-  Time tm(&st, from, len, cs, sql_mode_for_dates(get_thd()));
+  Time tm(&st, from, len, cs, sql_mode_for_dates(get_thd()), decimals());
   return store_TIME_with_warning(&tm, &str, st.warnings);
 }

Later, in the main patch for MDEV-16991, all truncating Time and Datetime constructors will be fixed to choose between truncation and rounding, according to the current session options.


Generated at Thu Feb 08 08:34:32 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.