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

Move MYSQL_TIME initialization from Field_xxx::store_time_dec() to new constructors Time() and Datetime()

    XMLWordPrintable

Details

    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.

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              1 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.