Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-17182

Move fractional second truncation outside of Field_xxx::store_TIME_with_warn()

    XMLWordPrintable

Details

    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

          Activity

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.