1
0
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:
unknown
2003-12-02 19:06:24 +04:00
parent 40d2de8eaa
commit 6990f6cf7e
3 changed files with 37 additions and 9 deletions

View File

@ -14,3 +14,16 @@ drop table t1;
create table t1 (a int null); create table t1 (a int null);
insert into t1 values (1),(NULL); insert into t1 values (1),(NULL);
drop table t1; 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;

View File

@ -21,3 +21,9 @@ drop table t1;
create table t1 (a int null); create table t1 (a int null);
insert into t1 values (1),(NULL); insert into t1 values (1),(NULL);
drop table t1; 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;

View File

@ -598,7 +598,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%type <simple_string> %type <simple_string>
remember_name remember_end opt_ident opt_db text_or_password remember_name remember_end opt_ident opt_db text_or_password
opt_escape opt_escape opt_constraint
%type <string> %type <string>
text_string opt_gconcat_separator 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 expr_list udf_expr_list when_list ident_list ident_list_arg
%type <key_type> %type <key_type>
key_type opt_unique_or_fulltext key_type opt_unique_or_fulltext constraint_key_type
%type <key_alg> %type <key_alg>
key_alg opt_btree_or_rtree 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->key_list.push_back(new Key($1,$2, $3, lex->col_list));
lex->col_list.empty(); /* Alloced by sql_alloc */ 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 | opt_constraint FOREIGN KEY_SYM opt_ident '(' key_list ')' references
{ {
LEX *lex=Lex; LEX *lex=Lex;
@ -1212,8 +1219,8 @@ check_constraint:
; ;
opt_constraint: opt_constraint:
/* empty */ /* empty */ { $$=(char*) 0; }
| CONSTRAINT opt_ident; | CONSTRAINT opt_ident { $$=$2; };
field_spec: field_spec:
field_ident field_ident
@ -1575,14 +1582,16 @@ delete_option:
| SET DEFAULT { $$= (int) foreign_key::FK_OPTION_DEFAULT; }; | SET DEFAULT { $$= (int) foreign_key::FK_OPTION_DEFAULT; };
key_type: 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::FULLTEXT; }
| FULLTEXT_SYM key_or_index { $$= Key::FULLTEXT; } | FULLTEXT_SYM key_or_index { $$= Key::FULLTEXT; }
| SPATIAL_SYM { $$= Key::SPATIAL; } | SPATIAL_SYM { $$= Key::SPATIAL; }
| SPATIAL_SYM key_or_index { $$= Key::SPATIAL; } | SPATIAL_SYM key_or_index { $$= Key::SPATIAL; };
| opt_constraint UNIQUE_SYM { $$= Key::UNIQUE; }
| opt_constraint UNIQUE_SYM key_or_index { $$= Key::UNIQUE; }; constraint_key_type:
PRIMARY_SYM KEY_SYM { $$= Key::PRIMARY; }
| UNIQUE_SYM { $$= Key::UNIQUE; }
| UNIQUE_SYM key_or_index { $$= Key::UNIQUE; };
key_or_index: key_or_index:
KEY_SYM {} KEY_SYM {}