From dba07c73960eba1dc1e961a22a07eb6e1998e532 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Fri, 22 Jan 2010 19:00:19 -0700 Subject: [PATCH] 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. --- mysql-test/r/constraints.result | 18 +++++++++++++- mysql-test/t/constraints.test | 44 ++++++++++++++++++++++++++++++++- sql/sql_yacc.yy | 10 +++----- 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/mysql-test/r/constraints.result b/mysql-test/r/constraints.result index 116efe429d5..46a718e4c42 100644 --- a/mysql-test/r/constraints.result +++ b/mysql-test/r/constraints.result @@ -3,7 +3,7 @@ create table t1 (a int check (a>0)); insert into t1 values (1); insert into t1 values (0); drop table t1; -create table t1 (a int ,b int, check a>b); +create table t1 (a int, b int, check (a>b)); insert into t1 values (1,0); insert into t1 values (0,1); drop table t1; @@ -27,3 +27,19 @@ t1 CREATE TABLE `t1` ( UNIQUE KEY `key_2` (`a`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; +drop table if exists t_illegal; +create table t_illegal (a int, b int, check a>b); +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 +create table t_illegal (a int, b int, constraint abc check a>b); +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 +create table t_illegal (a int, b int, constraint abc); +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 +drop table if exists t_11714; +create table t_11714(a int, b int); +alter table t_11714 add constraint cons1; +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 +drop table t_11714; +CREATE TABLE t_illegal (col_1 INT CHECK something (whatever)); +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 +CREATE TABLE t_illegal (col_1 INT CHECK something); +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 diff --git a/mysql-test/t/constraints.test b/mysql-test/t/constraints.test index ed268ab5846..70a95e5f16e 100644 --- a/mysql-test/t/constraints.test +++ b/mysql-test/t/constraints.test @@ -10,7 +10,7 @@ create table t1 (a int check (a>0)); insert into t1 values (1); insert into t1 values (0); drop table t1; -create table t1 (a int ,b int, check a>b); +create table t1 (a int, b int, check (a>b)); insert into t1 values (1,0); insert into t1 values (0,1); drop table t1; @@ -29,3 +29,45 @@ show create table t1; drop table t1; # End of 4.1 tests + +# +# Bug#35578 (Parser allows useless/illegal CREATE TABLE syntax) +# + +--disable_warnings +drop table if exists t_illegal; +--enable_warnings + +--error ER_PARSE_ERROR +create table t_illegal (a int, b int, check a>b); + +--error ER_PARSE_ERROR +create table t_illegal (a int, b int, constraint abc check a>b); + +--error ER_PARSE_ERROR +create table t_illegal (a int, b int, constraint abc); + +# +# Bug#11714 (Non-sensical ALTER TABLE ADD CONSTRAINT allowed) +# + +--disable_warnings +drop table if exists t_11714; +--enable_warnings + +create table t_11714(a int, b int); + +--error ER_PARSE_ERROR +alter table t_11714 add constraint cons1; + +drop table t_11714; + +# +# Bug#38696 (CREATE TABLE ... CHECK ... allows illegal syntax) + +--error ER_PARSE_ERROR +CREATE TABLE t_illegal (col_1 INT CHECK something (whatever)); + +--error ER_PARSE_ERROR +CREATE TABLE t_illegal (col_1 INT CHECK something); + diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index ab128a9b701..aebf80e340f 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -765,10 +765,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %pure_parser /* We have threads */ /* - Currently there are 172 shift/reduce conflicts. + Currently there are 169 shift/reduce conflicts. We should not introduce new conflicts any more. */ -%expect 172 +%expect 169 /* Comments for TOKENS. @@ -5282,10 +5282,6 @@ key_def: /* Only used for ALTER TABLE. Ignored otherwise. */ lex->alter_info.flags|= ALTER_FOREIGN_KEY; } - | constraint opt_check_constraint - { - Lex->col_list.empty(); /* Alloced by sql_alloc */ - } | opt_constraint check_constraint { Lex->col_list.empty(); /* Alloced by sql_alloc */ @@ -5298,7 +5294,7 @@ opt_check_constraint: ; check_constraint: - CHECK_SYM expr + CHECK_SYM '(' expr ')' ; opt_constraint: