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

Change the parameter of Field_xxx::store_TIME_with_dec() to const Datetime* and const Time*

    XMLWordPrintable

    Details

      Description

      These methods:

      • Field_timestamp::store_TIME_with_warning()
      • Field_temporal_with_date::store_TIME_with_warning()
      • Field_time::store_TIME_with_warning()

      currently get the value to store as a pointer to MYSQL_TIME structure.

      In order to implement MDEV-8894 easier, we'll change them as follows:

      int Field_timestamp::store_TIME_with_warning(const Datetime *ltime,
                                                   const ErrConv *str,
                                                   int was_cut);
       
      int Field_temporal_with_date::store_TIME_with_warning(const Datetime *dt,
                                                            const ErrConv *str,
                                                            int was_cut)
       
      int Field_time::store_TIME_with_warning(const Time *t,
                                              const ErrConv *str, int warn);
      

      In order to do this, new constructors for Time and Datetime will be added:

      Time(int *warn, const char *str, uint len, CHARSET_INFO *cs,
           const Options opt);
      Time(int *warn, const Sec6 &nr, const Options opt);
      Time(int *warn, double nr);
      Time(int *warn, longlong nr, bool unsigned_val);
      Time(int *warn, const my_decimal *d);
      Datetime(int *warn, const char *str, uint len, CHARSET_INFO *cs,
               sql_mode_t flags);
      Datetime(int *warn, double nr, sql_mode_t flags);
      Datetime(int *warn, const my_decimal *d, sql_mode_t flags);
      Datetime(int *warn, longlong sec, ulong usec, sql_mode_t flags);
      

      and new methods will be added:

      Datetime Datetime::trunc(uint dec) const;
      Time Time::trunc(uint dec) const;
      

      Also, the truncation/rounding logic for DATETIME will migrate from store_TIME() to Field_temporal_with_date::store_TIME_with_warning(), for symmetry with Field_time::store_TIME_with_warning().
      This will allow to add the "const" qualifier to the parameter to store_TIME() of all Field_temporal_with_date descendants. Currently it is not "const" for Field_temporal_with_date (but is "const" for Field_timestamp and Field_time).

      After this change store_TIME_with_warning() will have equal code structure:

      int Field_xxx::store_TIME_with_warning(const Xxx *t,
                                             const ErrConv *str, int warn)
      {
        ASSERT_COLUMN_MARKED_FOR_WRITE;
        // Handle totally bad values
        ...
        // Adjust and store the value (truncation and rounding happens here)
        ...
        // calculate return value and send warnings if needed
        ...
      }
      

      The part to "calculate return value" will be reused between by Field_time and Field_temporal_with_date using this method:

        int store_TIME_return_code_with_warnings(int warn, const ErrConv *str,
                                                 timestamp_type ts_type)
        {
          if (!MYSQL_TIME_WARN_HAVE_WARNINGS(warn) &&
              MYSQL_TIME_WARN_HAVE_NOTES(warn))
          {
            set_warnings(Sql_condition::WARN_LEVEL_NOTE, str,
                         warn | MYSQL_TIME_WARN_TRUNCATED, ts_type);
            return 3;
          }
          set_warnings(Sql_condition::WARN_LEVEL_WARN, str, warn, ts_type);
          return warn ? 2 : 0;
        }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bar Alexander Barkov
              Reporter:
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: