[MDEV-16928] Move MYSQL_TIME initialization from Field_xxx::store_time_dec() to new constructors Time() and Datetime() Created: 2018-08-09  Updated: 2018-08-15  Resolved: 2018-08-09

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-8894 Inserting fractional seconds into My... Closed

 Description   

The following methods:

  • Field_timestamp::store_time_dec()
  • Field_temporal_with_date::store_time_dec()
  • Field_time::store_time_dec()
    have pieces of code responsible for MYSQL_TIME initialization and verification.

We'll move this code to new constructors for Time() and Datetime().

For example, for Field_time the relevant code looks like this:

int Field_temporal_with_date::store_time_dec(const MYSQL_TIME *ltime, uint dec)
{
  int error= 0, have_smth_to_conv= 1;
  ErrConvTime str(ltime);
  MYSQL_TIME l_time;
 
  if (copy_or_convert_to_datetime(get_thd(), ltime, &l_time))
  {
    /*
      Set have_smth_to_conv and error in a way to have
      store_TIME_with_warning do bzero().
    */
    have_smth_to_conv= false;
    error= MYSQL_TIME_WARN_OUT_OF_RANGE;
  }
  else
  {
    /*
      We don't perform range checking here since values stored in TIME
      structure always fit into DATETIME range.
    */
    have_smth_to_conv= !check_date(&l_time, pack_time(&l_time) != 0,
                                   sql_mode_for_dates(get_thd()), &error);
  }
  return store_TIME_with_warning(&l_time, &str, error, have_smth_to_conv);
}

After this change, the code will look about like this:

int Field_temporal_with_date::store_time_dec(const MYSQL_TIME *ltime, uint dec)
{
  int error;
  ErrConvTime str(ltime);
  THD *thd= get_thd();
  Datetime dt(thd, &error, ltime, sql_mode_for_dates(thd));
  ltime= dt.is_valid_datetime() ? dt.get_mysql_time() : NULL;
  return store_TIME_with_warning(const_cast<MYSQL_TIME*>(ltime), &str, error);
}

Notice, in the new reduction (instead of MYSQL_TIME initialization), there will be a Datetime() instantiation.
The new code in Field_xxx will look much simpler.

Note, the "bool have_smth_to_conv" will be removed. It's not needed. We'll pass NULL to store_TIME_with_warning() instead of a MYSQL_TIME pointer in all cases when false was passed as a actual parameter for have_smth_to_conv.

This change is needed for MDEV-8894.

The idea is to have these methods:

  • Datetime Datetime::round(uint scale)
  • Time Time::round(uint scale)

Therefore, the relevant code should be ready to work in terms of Time and Datetime rather than MYSQL_TIME.


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