Details
- 
    Task 
- 
    Status: Closed (View Workflow)
- 
    Major 
- 
    Resolution: Fixed
- 
    None
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.
Attachments
Issue Links
- blocks
- 
                    MDEV-16991 Rounding vs truncation for TIME, DATETIME, TIMESTAMP -         
- Closed
 
-         
- relates to
- 
                    MDEV-17203 Move fractional second truncation from Item_xxx_typecast::get_date() to Time and Datetime constructors -         
- Closed
 
-