Skip to content

Commit dba07c7

Browse files
author
Marc Alff
committed
Bug#11714 Non-sensical ALTER TABLE ADD CONSTRAINT allowed
Bug#35578 Parser allows useless/illegal CREATE TABLE syntax Bug#38696 CREATE TABLE ... CHECK ... allows illegal syntax Backport from 6.0 to mysql-next-mr.
1 parent 7146864 commit dba07c7

File tree

3 files changed

+63
-9
lines changed

3 files changed

+63
-9
lines changed

mysql-test/r/constraints.result

+17-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ create table t1 (a int check (a>0));
33
insert into t1 values (1);
44
insert into t1 values (0);
55
drop table t1;
6-
create table t1 (a int ,b int, check a>b);
6+
create table t1 (a int, b int, check (a>b));
77
insert into t1 values (1,0);
88
insert into t1 values (0,1);
99
drop table t1;
@@ -27,3 +27,19 @@ t1 CREATE TABLE `t1` (
2727
UNIQUE KEY `key_2` (`a`)
2828
) ENGINE=MyISAM DEFAULT CHARSET=latin1
2929
drop table t1;
30+
drop table if exists t_illegal;
31+
create table t_illegal (a int, b int, check a>b);
32+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a>b)' at line 1
33+
create table t_illegal (a int, b int, constraint abc check a>b);
34+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a>b)' at line 1
35+
create table t_illegal (a int, b int, constraint abc);
36+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
37+
drop table if exists t_11714;
38+
create table t_11714(a int, b int);
39+
alter table t_11714 add constraint cons1;
40+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
41+
drop table t_11714;
42+
CREATE TABLE t_illegal (col_1 INT CHECK something (whatever));
43+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'something (whatever))' at line 1
44+
CREATE TABLE t_illegal (col_1 INT CHECK something);
45+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'something)' at line 1

mysql-test/t/constraints.test

+43-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ create table t1 (a int check (a>0));
1010
insert into t1 values (1);
1111
insert into t1 values (0);
1212
drop table t1;
13-
create table t1 (a int ,b int, check a>b);
13+
create table t1 (a int, b int, check (a>b));
1414
insert into t1 values (1,0);
1515
insert into t1 values (0,1);
1616
drop table t1;
@@ -29,3 +29,45 @@ show create table t1;
2929
drop table t1;
3030

3131
# End of 4.1 tests
32+
33+
#
34+
# Bug#35578 (Parser allows useless/illegal CREATE TABLE syntax)
35+
#
36+
37+
--disable_warnings
38+
drop table if exists t_illegal;
39+
--enable_warnings
40+
41+
--error ER_PARSE_ERROR
42+
create table t_illegal (a int, b int, check a>b);
43+
44+
--error ER_PARSE_ERROR
45+
create table t_illegal (a int, b int, constraint abc check a>b);
46+
47+
--error ER_PARSE_ERROR
48+
create table t_illegal (a int, b int, constraint abc);
49+
50+
#
51+
# Bug#11714 (Non-sensical ALTER TABLE ADD CONSTRAINT allowed)
52+
#
53+
54+
--disable_warnings
55+
drop table if exists t_11714;
56+
--enable_warnings
57+
58+
create table t_11714(a int, b int);
59+
60+
--error ER_PARSE_ERROR
61+
alter table t_11714 add constraint cons1;
62+
63+
drop table t_11714;
64+
65+
#
66+
# Bug#38696 (CREATE TABLE ... CHECK ... allows illegal syntax)
67+
68+
--error ER_PARSE_ERROR
69+
CREATE TABLE t_illegal (col_1 INT CHECK something (whatever));
70+
71+
--error ER_PARSE_ERROR
72+
CREATE TABLE t_illegal (col_1 INT CHECK something);
73+

sql/sql_yacc.yy

+3-7
Original file line numberDiff line numberDiff line change
@@ -765,10 +765,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
765765

766766
%pure_parser /* We have threads */
767767
/*
768-
Currently there are 172 shift/reduce conflicts.
768+
Currently there are 169 shift/reduce conflicts.
769769
We should not introduce new conflicts any more.
770770
*/
771-
%expect 172
771+
%expect 169
772772

773773
/*
774774
Comments for TOKENS.
@@ -5282,10 +5282,6 @@ key_def:
52825282
/* Only used for ALTER TABLE. Ignored otherwise. */
52835283
lex->alter_info.flags|= ALTER_FOREIGN_KEY;
52845284
}
5285-
| constraint opt_check_constraint
5286-
{
5287-
Lex->col_list.empty(); /* Alloced by sql_alloc */
5288-
}
52895285
| opt_constraint check_constraint
52905286
{
52915287
Lex->col_list.empty(); /* Alloced by sql_alloc */
@@ -5298,7 +5294,7 @@ opt_check_constraint:
52985294
;
52995295

53005296
check_constraint:
5301-
CHECK_SYM expr
5297+
CHECK_SYM '(' expr ')'
53025298
;
53035299

53045300
opt_constraint:

0 commit comments

Comments
 (0)