diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2019-12-12 14:41:51 +0200 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2019-12-12 14:41:51 +0200 |
commit | 0a20e5ab77f8a6532b41ea2518626397059ccf42 (patch) | |
tree | 1ef90ec718bc16d80ca65eb89537f697e1482f09 /sql/sql_table.cc | |
parent | e0f9540bcc6ab1618b6fd475f02e019401c4c295 (diff) | |
parent | beec9c0e19284a0e50d3629f4cb2486007b0333b (diff) | |
download | mariadb-git-0a20e5ab77f8a6532b41ea2518626397059ccf42.tar.gz |
Merge 10.2 into 10.3
Diffstat (limited to 'sql/sql_table.cc')
-rw-r--r-- | sql/sql_table.cc | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 170c02c0f7f..8642bd47da5 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -4238,10 +4238,10 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, continue; { - /* Check that there's no repeating constraint names. */ + /* Check that there's no repeating table CHECK constraint names. */ List_iterator_fast<Virtual_column_info> dup_it(alter_info->check_constraint_list); - Virtual_column_info *dup_check; + const Virtual_column_info *dup_check; while ((dup_check= dup_it++) && dup_check != check) { if (!lex_string_cmp(system_charset_info, @@ -4253,6 +4253,27 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, } } + /* Check that there's no repeating key constraint names. */ + List_iterator_fast<Key> key_it(alter_info->key_list); + while (const Key *key= key_it++) + { + /* + Not all keys considered to be the CONSTRAINT + Noly Primary Key UNIQUE and Foreign keys. + */ + if (key->type != Key::PRIMARY && key->type != Key::UNIQUE && + key->type != Key::FOREIGN_KEY) + continue; + + if (check->name.length == key->name.length && + my_strcasecmp(system_charset_info, + check->name.str, key->name.str) == 0) + { + my_error(ER_DUP_CONSTRAINT_NAME, MYF(0), "CHECK", check->name.str); + DBUG_RETURN(TRUE); + } + } + if (check_string_char_length(&check->name, 0, NAME_CHAR_LEN, system_charset_info, 1)) { @@ -8497,6 +8518,35 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, } } } + + if (!alter_info->check_constraint_list.is_empty()) + { + /* Check the table FOREIGN KEYs for name duplications. */ + List <FOREIGN_KEY_INFO> fk_child_key_list; + FOREIGN_KEY_INFO *f_key; + table->file->get_foreign_key_list(thd, &fk_child_key_list); + List_iterator<FOREIGN_KEY_INFO> fk_key_it(fk_child_key_list); + while ((f_key= fk_key_it++)) + { + List_iterator_fast<Virtual_column_info> + c_it(alter_info->check_constraint_list); + Virtual_column_info *check; + while ((check= c_it++)) + { + if (!check->name.length || check->automatic_name) + continue; + + if (check->name.length == f_key->foreign_id->length && + my_strcasecmp(system_charset_info, f_key->foreign_id->str, + check->name.str) == 0) + { + my_error(ER_DUP_CONSTRAINT_NAME, MYF(0), "CHECK", check->name.str); + goto err; + } + } + } + } + /* Add new constraints */ new_constraint_list.append(&alter_info->check_constraint_list); |