mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Fix for #1189 (Mess with names about CONSTRAINT)
Second edition: error message was deleted as Segey suggested Now name of the constraint will be used as the name of the key if the last not specified mysql-test/r/constraints.result: appropriate test result mysql-test/t/constraints.test: test case for 1189 sql/sql_yacc.yy: language definitions changed so that we can obtaint constraint's name and send it as the name of the key if it's not specified
This commit is contained in:
@ -14,3 +14,16 @@ drop table t1;
|
||||
create table t1 (a int null);
|
||||
insert into t1 values (1),(NULL);
|
||||
drop table t1;
|
||||
create table t1 (a int null);
|
||||
alter table t1 add constraint constraint_1 unique (a);
|
||||
alter table t1 add constraint unique key_1(a);
|
||||
alter table t1 add constraint constraint_2 unique key_2(a);
|
||||
show create table t1;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`a` int(11) default NULL,
|
||||
UNIQUE KEY `constraint_1` (`a`),
|
||||
UNIQUE KEY `key_1` (`a`),
|
||||
UNIQUE KEY `key_2` (`a`)
|
||||
) TYPE=MyISAM DEFAULT CHARSET=latin1
|
||||
drop table t1;
|
||||
|
@ -21,3 +21,9 @@ drop table t1;
|
||||
create table t1 (a int null);
|
||||
insert into t1 values (1),(NULL);
|
||||
drop table t1;
|
||||
create table t1 (a int null);
|
||||
alter table t1 add constraint constraint_1 unique (a);
|
||||
alter table t1 add constraint unique key_1(a);
|
||||
alter table t1 add constraint constraint_2 unique key_2(a);
|
||||
show create table t1;
|
||||
drop table t1;
|
||||
|
@ -598,7 +598,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
|
||||
|
||||
%type <simple_string>
|
||||
remember_name remember_end opt_ident opt_db text_or_password
|
||||
opt_escape
|
||||
opt_escape opt_constraint
|
||||
|
||||
%type <string>
|
||||
text_string opt_gconcat_separator
|
||||
@ -631,7 +631,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
|
||||
expr_list udf_expr_list when_list ident_list ident_list_arg
|
||||
|
||||
%type <key_type>
|
||||
key_type opt_unique_or_fulltext
|
||||
key_type opt_unique_or_fulltext constraint_key_type
|
||||
|
||||
%type <key_alg>
|
||||
key_alg opt_btree_or_rtree
|
||||
@ -1189,6 +1189,13 @@ key_def:
|
||||
lex->key_list.push_back(new Key($1,$2, $3, lex->col_list));
|
||||
lex->col_list.empty(); /* Alloced by sql_alloc */
|
||||
}
|
||||
| opt_constraint constraint_key_type opt_ident key_alg '(' key_list ')'
|
||||
{
|
||||
LEX *lex=Lex;
|
||||
const char *key_name= $3 ? $3:$1;
|
||||
lex->key_list.push_back(new Key($2, key_name, $4, lex->col_list));
|
||||
lex->col_list.empty(); /* Alloced by sql_alloc */
|
||||
}
|
||||
| opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
|
||||
{
|
||||
LEX *lex=Lex;
|
||||
@ -1212,8 +1219,8 @@ check_constraint:
|
||||
;
|
||||
|
||||
opt_constraint:
|
||||
/* empty */
|
||||
| CONSTRAINT opt_ident;
|
||||
/* empty */ { $$=(char*) 0; }
|
||||
| CONSTRAINT opt_ident { $$=$2; };
|
||||
|
||||
field_spec:
|
||||
field_ident
|
||||
@ -1575,14 +1582,16 @@ delete_option:
|
||||
| SET DEFAULT { $$= (int) foreign_key::FK_OPTION_DEFAULT; };
|
||||
|
||||
key_type:
|
||||
opt_constraint PRIMARY_SYM KEY_SYM { $$= Key::PRIMARY; }
|
||||
| key_or_index { $$= Key::MULTIPLE; }
|
||||
key_or_index { $$= Key::MULTIPLE; }
|
||||
| FULLTEXT_SYM { $$= Key::FULLTEXT; }
|
||||
| FULLTEXT_SYM key_or_index { $$= Key::FULLTEXT; }
|
||||
| SPATIAL_SYM { $$= Key::SPATIAL; }
|
||||
| SPATIAL_SYM key_or_index { $$= Key::SPATIAL; }
|
||||
| opt_constraint UNIQUE_SYM { $$= Key::UNIQUE; }
|
||||
| opt_constraint UNIQUE_SYM key_or_index { $$= Key::UNIQUE; };
|
||||
| SPATIAL_SYM key_or_index { $$= Key::SPATIAL; };
|
||||
|
||||
constraint_key_type:
|
||||
PRIMARY_SYM KEY_SYM { $$= Key::PRIMARY; }
|
||||
| UNIQUE_SYM { $$= Key::UNIQUE; }
|
||||
| UNIQUE_SYM key_or_index { $$= Key::UNIQUE; };
|
||||
|
||||
key_or_index:
|
||||
KEY_SYM {}
|
||||
|
Reference in New Issue
Block a user