From b258f911032a04394b8e0f8f092da799d804a205 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 2 Jul 2016 12:22:58 +0200 Subject: [PATCH] fix ALTER TABLE .. DROP CONSTRAINT IF NOT EXISTS --- mysql-test/r/check_constraint.result | 3 +++ mysql-test/t/check_constraint.test | 1 + sql/sql_table.cc | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/check_constraint.result b/mysql-test/r/check_constraint.result index 1ffe0ba3ba6..babb42d93b8 100644 --- a/mysql-test/r/check_constraint.result +++ b/mysql-test/r/check_constraint.result @@ -84,6 +84,9 @@ t2 CREATE TABLE `t2` ( ) ENGINE=MyISAM DEFAULT CHARSET=latin1 alter table t2 drop constraint c; ERROR 42000: Can't DROP CONSTRAINT `c`; check that it exists +alter table t2 drop constraint if exists c; +Warnings: +Note 1091 Can't DROP CONSTRAINT `c`; check that it exists alter table t2 drop constraint min; show create table t2; Table Create Table diff --git a/mysql-test/t/check_constraint.test b/mysql-test/t/check_constraint.test index 7bd6a654e9b..8dd6fcc4f27 100644 --- a/mysql-test/t/check_constraint.test +++ b/mysql-test/t/check_constraint.test @@ -48,6 +48,7 @@ create table t2 like t1; show create table t2; --error ER_CANT_DROP_FIELD_OR_KEY alter table t2 drop constraint c; +alter table t2 drop constraint if exists c; alter table t2 drop constraint min; show create table t2; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index de843172c75..e745fe8efcb 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -5880,7 +5880,7 @@ drop_create_field: } else if (drop->type == Alter_drop::CHECK_CONSTRAINT) { - for (uint i=0; i < table->s->table_check_constraints; i++) + for (uint i=table->s->field_check_constraints; i < table->s->table_check_constraints; i++) { if (my_strcasecmp(system_charset_info, drop->name, table->check_constraints[i]->name.str) == 0)