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

Split ALTER related data type specific code in sql_table.cc to Type_handler

    XMLWordPrintable

Details

    Description

      Some code in sql_table.cc is not friendly to pluggable data types:

      In mysql_prepare_alter_table():

          if ((def->real_field_type() == MYSQL_TYPE_DATE ||
               def->real_field_type() == MYSQL_TYPE_NEWDATE ||
               def->real_field_type() == MYSQL_TYPE_DATETIME ||
               def->real_field_type() == MYSQL_TYPE_DATETIME2) &&
               !alter_ctx->datetime_field &&
               !(~def->flags & (NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG)) &&
               thd->variables.sql_mode & MODE_NO_ZERO_DATE)
          {
              alter_ctx->datetime_field= def;
              alter_ctx->error_if_not_empty= TRUE;
          }
      
      

      In mysql_alter_table():

          switch (alter_ctx.datetime_field->real_field_type())
          {
            case MYSQL_TYPE_DATE:
            case MYSQL_TYPE_NEWDATE:
              f_val= "0000-00-00";
              t_type= MYSQL_TIMESTAMP_DATE;
              break;
            case MYSQL_TYPE_DATETIME:
            case MYSQL_TYPE_DATETIME2:
              f_val= "0000-00-00 00:00:00";
              t_type= MYSQL_TIMESTAMP_DATETIME;
              break;
            default:
              /* Shouldn't get here. */
              DBUG_ASSERT(0);
          }
      

      Let's split this code into two new virtual methods in Type_handler:

      virtual const Name default_value() const;
      virtual bool validate_implicit_default_value(THD *thd,
                                                   const Column_definition &def)
                                                   const;
      

      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.