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

Change Send_field::type from enum_field_types to Type_handler*

Details

    Description

      protocol.cc has various tests for MYSQL_TYPE_XXX, for example:

      bool Protocol_text::store(const char *from, size_t length,
                                CHARSET_INFO *fromcs, CHARSET_INFO *tocs)
      {
      #ifndef DBUG_OFF
        DBUG_ASSERT(field_types == 0 ||
      	      field_types[field_pos] == MYSQL_TYPE_DECIMAL ||
                    field_types[field_pos] == MYSQL_TYPE_BIT ||
                    field_types[field_pos] == MYSQL_TYPE_NEWDECIMAL ||
      	      (field_types[field_pos] >= MYSQL_TYPE_ENUM &&
      	       field_types[field_pos] <= MYSQL_TYPE_GEOMETRY));
        field_pos++;
      #endif
        return store_string_aux(from, length, fromcs, tocs);
      }
      

      This is not friendly to new/pluggable data types.

      To fix this problem, we'll do the following changes:

      • change Send_field::type from enum_field_type to const Type_handler *
      • add a new enum:

        enum protocol_send_type_t
        {
          PROTOCOL_SEND_STRING,
          PROTOCOL_SEND_FLOAT,
          PROTOCOL_SEND_DOUBLE,
          PROTOCOL_SEND_TINY,
          PROTOCOL_SEND_SHORT,
          PROTOCOL_SEND_LONG,
          PROTOCOL_SEND_LONGLONG,
          PROTOCOL_SEND_DATETIME,
          PROTOCOL_SEND_DATE,
          PROTOCOL_SEND_TIME
        };
        

      • add a new virtual method in Type_handler:

        virtual protocol_send_type_t protocol_send_type() const= 0;
        

      So the ::store() method implementations will simplify to something like:

      bool Protocol_text::store(const char *from, size_t length,
                                CHARSET_INFO *fromcs, CHARSET_INFO *tocs)
      {
      #ifndef DBUG_OFF
        DBUG_ASSERT(valid_handler(field_pos, PROTOCOL_SEND_STRING));
        field_pos++;
      #endif
        return store_string_aux(from, length, fromcs, tocs);
      }
      

      New data types will just need to implement a proper virtual implementation of Type_handler_xxx::protocol_send_type().

      Attachments

        Issue Links

          Activity

            bar Alexander Barkov created issue -
            bar Alexander Barkov made changes -
            Field Original Value New Value
            bar Alexander Barkov made changes -
            Description {{protocol.cc}} has various tests for {{MYSQL_TYPE_XXX}}, for example:

            {code:cpp}
            bool Protocol_text::store(const char *from, size_t length,
                                      CHARSET_INFO *fromcs, CHARSET_INFO *tocs)
            {
            #ifndef DBUG_OFF
              DBUG_ASSERT(field_types == 0 ||
            field_types[field_pos] == MYSQL_TYPE_DECIMAL ||
                          field_types[field_pos] == MYSQL_TYPE_BIT ||
                          field_types[field_pos] == MYSQL_TYPE_NEWDECIMAL ||
            (field_types[field_pos] >= MYSQL_TYPE_ENUM &&
            field_types[field_pos] <= MYSQL_TYPE_GEOMETRY));
              field_pos++;
            #endif
              return store_string_aux(from, length, fromcs, tocs);
            }
            {cpp}

            This is not friendly to new/pluggable data types.


            To fix this problem, we'll do the following changes:
            - change {{Send_field::type}} from {{enum_field_type}} to {{const Type_handler *}}
            - add a new enum:
            {code:cpp}
            enum protocol_send_type_t
            {
              PROTOCOL_SEND_STRING,
              PROTOCOL_SEND_FLOAT,
              PROTOCOL_SEND_DOUBLE,
              PROTOCOL_SEND_TINY,
              PROTOCOL_SEND_SHORT,
              PROTOCOL_SEND_LONG,
              PROTOCOL_SEND_LONGLONG,
              PROTOCOL_SEND_DATETIME,
              PROTOCOL_SEND_DATE,
              PROTOCOL_SEND_TIME
            };
            {code}
            - add a new virtual method in {{Type_handler}}:
            {code:cpp}
            virtual protocol_send_type_t protocol_send_type() const= 0;
            {code}


            So the {{::store()}} method implementations will simplify to something like:

            {code:cpp}
            bool Protocol_text::store(const char *from, size_t length,
                                      CHARSET_INFO *fromcs, CHARSET_INFO *tocs)
            {
            #ifndef DBUG_OFF
              DBUG_ASSERT(valid_handler(field_pos, PROTOCOL_SEND_STRING));
              field_pos++;
            #endif
              return store_string_aux(from, length, fromcs, tocs);
            }
            {code}

            New data types will just need to implement a proper virtual implementation of {{Type_handler_xxx::protocol_send_type()}}.
            {{protocol.cc}} has various tests for {{MYSQL_TYPE_XXX}}, for example:

            {code:cpp}
            bool Protocol_text::store(const char *from, size_t length,
                                      CHARSET_INFO *fromcs, CHARSET_INFO *tocs)
            {
            #ifndef DBUG_OFF
              DBUG_ASSERT(field_types == 0 ||
            field_types[field_pos] == MYSQL_TYPE_DECIMAL ||
                          field_types[field_pos] == MYSQL_TYPE_BIT ||
                          field_types[field_pos] == MYSQL_TYPE_NEWDECIMAL ||
            (field_types[field_pos] >= MYSQL_TYPE_ENUM &&
            field_types[field_pos] <= MYSQL_TYPE_GEOMETRY));
              field_pos++;
            #endif
              return store_string_aux(from, length, fromcs, tocs);
            }
            {code}

            This is not friendly to new/pluggable data types.


            To fix this problem, we'll do the following changes:
            - change {{Send_field::type}} from {{enum_field_type}} to {{const Type_handler *}}
            - add a new enum:
            {code:cpp}
            enum protocol_send_type_t
            {
              PROTOCOL_SEND_STRING,
              PROTOCOL_SEND_FLOAT,
              PROTOCOL_SEND_DOUBLE,
              PROTOCOL_SEND_TINY,
              PROTOCOL_SEND_SHORT,
              PROTOCOL_SEND_LONG,
              PROTOCOL_SEND_LONGLONG,
              PROTOCOL_SEND_DATETIME,
              PROTOCOL_SEND_DATE,
              PROTOCOL_SEND_TIME
            };
            {code}
            - add a new virtual method in {{Type_handler}}:
            {code:cpp}
            virtual protocol_send_type_t protocol_send_type() const= 0;
            {code}


            So the {{::store()}} method implementations will simplify to something like:

            {code:cpp}
            bool Protocol_text::store(const char *from, size_t length,
                                      CHARSET_INFO *fromcs, CHARSET_INFO *tocs)
            {
            #ifndef DBUG_OFF
              DBUG_ASSERT(valid_handler(field_pos, PROTOCOL_SEND_STRING));
              field_pos++;
            #endif
              return store_string_aux(from, length, fromcs, tocs);
            }
            {code}

            New data types will just need to implement a proper virtual implementation of {{Type_handler_xxx::protocol_send_type()}}.
            bar Alexander Barkov made changes -
            issue.field.resolutiondate 2019-04-02 13:53:00.0 2019-04-02 13:53:00.341
            bar Alexander Barkov made changes -
            Fix Version/s 10.4.4 [ 23310 ]
            Fix Version/s 10.4 [ 22408 ]
            Resolution Fixed [ 1 ]
            Status Open [ 1 ] Closed [ 6 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 94148 ] MariaDB v4 [ 133912 ]

            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.