diff options
author | Sergei Golubchik <serg@mariadb.org> | 2017-10-14 15:03:43 +0200 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2017-10-17 07:37:39 +0200 |
commit | 421716391b8bafe9af853b1ee3f83d521b69db6e (patch) | |
tree | e4157f125ca1a7f7619cda3f8195d7e19365eca7 /sql | |
parent | 93144b9e92d3d4fee3247895c1e06e8e7cfedcaa (diff) | |
download | mariadb-git-421716391b8bafe9af853b1ee3f83d521b69db6e.tar.gz |
MDEV-13912 Can't refer the same column twice in one ALTER TABLE
backport ce6c0e584e3
MDEV-8960: Can't refer the same column twice in one ALTER TABLE
Problem was that if column was created in alter table when
it was refered again it was not tried to find from list
of current columns.
mysql_prepare_alter_table:
There is two cases
(1) If alter table adds a new column and then later alter
changes the field definition, there was no check from
list of new columns, instead an incorrect error was given.
(2) If alter table adds a new column and then later alter
changes the default, there was no check from list of
new columns, instead an incorrect error was given.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sql_table.cc | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc index e6490876352..19093d9b2ca 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -5739,9 +5739,25 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, { if (def->change && ! def->field) { - my_error(ER_BAD_FIELD_ERROR, MYF(0), def->change, - table->s->table_name.str); - goto err; + /* + Check if there is modify for newly added field. + */ + Create_field *find; + find_it.rewind(); + while((find=find_it++)) + { + if (!my_strcasecmp(system_charset_info,find->field_name, def->field_name)) + break; + } + + if (find && !find->field) + find_it.remove(); + else + { + my_error(ER_BAD_FIELD_ERROR, MYF(0), def->change, + table->s->table_name.str); + goto err; + } } /* Check that the DATE/DATETIME not null field we are going to add is @@ -5793,6 +5809,29 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, */ alter_info->change_level= ALTER_TABLE_DATA_CHANGED; } + /* + Check if there is alter for newly added field. + */ + alter_it.rewind(); + Alter_column *alter; + while ((alter=alter_it++)) + { + if (!my_strcasecmp(system_charset_info,def->field_name, alter->name)) + break; + } + if (alter) + { + if (def->sql_type == MYSQL_TYPE_BLOB) + { + my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0), def->change); + goto err; + } + if ((def->def=alter->def)) // Use new default + def->flags&= ~NO_DEFAULT_VALUE_FLAG; + else + def->flags|= NO_DEFAULT_VALUE_FLAG; + alter_it.remove(); + } } if (alter_info->alter_list.elements) { |