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

Implement sql_type() for Field_real and Field_int

    XMLWordPrintable

Details

    Description

      This change was suggested by Serg during the review of MDEV-20016.

      Let's implement sql_type() in abstract classes as much as possible. It will reduce the amout of the code:

      • in the built-in Field_xxx classes
      • in the future plugin Field_xxx classes

      Note, this task is limited to Field_real and Field_int only. Other classes will be changed the same way later.

      Let's remove sql_type() implementations from:

      • Field_tiny
      • Field_short
      • Field_medium
      • Field_long
      • Field_longlong
      • Field_float
      • Field_double
        The inherited implementations will work for these classes. The exact data type name will be taken from the Type_handler.

      The implementation for the abstract classes will look like:

      void Field_int::sql_type(String &res) const
      {
        CHARSET_INFO *cs=res.charset();
        Name name= type_handler()->type_handler_signed()->name();
        res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
                                "%.*s(%d)", (int) name.length(), name.ptr(),
                                (int) field_length));
        add_zerofill_and_unsigned(res);
      }
      

      void Field_real::sql_type(String &res) const
      {
        const Name name= type_handler()->name();
        if (dec >= FLOATING_POINT_DECIMALS)
        {
          res.set_ascii(name.ptr(), name.length());
        }
        else
        {
          CHARSET_INFO *cs= res.charset();
          res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
                                  "%.*s(%d,%d)", (int) name.length(), name.ptr(),
                                  (int) field_length,dec));
        }
        add_zerofill_and_unsigned(res);
      }
      

      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.