Skip to content

Commit

Permalink
fix grammar for "DEFAULT (SELECT 1)" not be a syntax error
Browse files Browse the repository at this point in the history
the error should be "subselect is not allowed here", same as for
DEFAULT ((SELECT 1))
  • Loading branch information
vuvova committed Jun 30, 2016
1 parent ed77ee1 commit 1b4f096
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 35 deletions.
6 changes: 3 additions & 3 deletions mysql-test/r/default.result
Expand Up @@ -443,9 +443,9 @@ drop table t1;
create or replace table t1 (a bigint default xxx());
ERROR HY000: Function or expression '`xxx`' is not allowed for 'DEFAULT' of column/constraint 'a'
create or replace table t1 (a bigint default (select (1)));
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'select (1)))' at line 1
ERROR HY000: Function or expression 'subselect' is not allowed for 'DEFAULT' of column/constraint 'a'
create or replace table t1 (a bigint default (1,2,3));
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '2,3))' at line 1
ERROR 21000: Operand should contain 1 column(s)
create or replace table t1 (a bigint default ((1,2,3)));
ERROR 21000: Operand should contain 1 column(s)
CREATE TABLE t1 (a INT, b INT, c INT DEFAULT a DIV b);
Expand All @@ -464,7 +464,7 @@ ERROR HY000: Function or expression 'subselect' is not allowed for 'DEFAULT' of
CREATE TABLE t1 (a INT DEFAULT ROW(1,1));
ERROR 21000: Operand should contain 1 column(s)
CREATE TABLE t1 (a INT DEFAULT (1,1));
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '1))' at line 1
ERROR 21000: Operand should contain 1 column(s)
CREATE TABLE t1 (a INT DEFAULT ((1,1)));
ERROR 21000: Operand should contain 1 column(s)
CREATE TABLE t1 (a INT DEFAULT ?);
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/vcol/r/vcol_blocked_sql_funcs.result
Expand Up @@ -238,7 +238,7 @@ create or replace table t1 (a varchar(1024), b varchar(1024) as (UpdateXML(a,'/a
#
create or replace table t1 (a int);
create or replace table t2 (a int, b int as (select count(*) from t1));
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'select count(*) from t1))' at line 1
ERROR HY000: Function or expression 'subselect' is not allowed for 'VIRTUAL' of column/constraint 'b'
drop table t1;
create or replace table t1 (a int, b int as ((select 1)));
ERROR HY000: Function or expression 'subselect' is not allowed for 'VIRTUAL' of column/constraint 'b'
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/vcol/t/vcol_blocked_sql_funcs_main.inc
Expand Up @@ -336,7 +336,7 @@ create or replace table t1 (a varchar(1024), b varchar(1024) as (UpdateXML(a,'/a
--echo #

create or replace table t1 (a int);
-- error ER_PARSE_ERROR
-- error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
create or replace table t2 (a int, b int as (select count(*) from t1));
drop table t1;

Expand Down
6 changes: 3 additions & 3 deletions mysql-test/t/default.test
Expand Up @@ -324,9 +324,9 @@ drop table t1;

--error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
create or replace table t1 (a bigint default xxx());
--error ER_PARSE_ERROR
--error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
create or replace table t1 (a bigint default (select (1)));
--error ER_PARSE_ERROR
--error ER_OPERAND_COLUMNS
create or replace table t1 (a bigint default (1,2,3));
--error ER_OPERAND_COLUMNS
create or replace table t1 (a bigint default ((1,2,3)));
Expand All @@ -351,7 +351,7 @@ CREATE TABLE t1 (a INT DEFAULT (1=ANY (SELECT 1)));
--error ER_OPERAND_COLUMNS
CREATE TABLE t1 (a INT DEFAULT ROW(1,1));

--error ER_PARSE_ERROR
--error ER_OPERAND_COLUMNS
CREATE TABLE t1 (a INT DEFAULT (1,1));

--error ER_OPERAND_COLUMNS
Expand Down
56 changes: 29 additions & 27 deletions sql/sql_yacc.yy
Expand Up @@ -1057,10 +1057,10 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%parse-param { THD *thd }
%lex-param { THD *thd }
/*
Currently there are 102 shift/reduce conflicts.
Currently there are 103 shift/reduce conflicts.
We should not introduce new conflicts any more.
*/
%expect 102
%expect 103

/*
Comments for TOKENS.
Expand Down Expand Up @@ -1854,7 +1854,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
literal text_literal insert_ident order_ident temporal_literal
simple_ident expr opt_expr opt_else sum_expr in_sum_expr
variable variable_aux bool_pri
predicate bit_expr
predicate bit_expr parenthesized_expr
table_wild simple_expr column_default_non_parenthesized_expr udf_expr
expr_or_default set_expr_or_default
geometry_function signed_literal
Expand Down Expand Up @@ -6336,9 +6336,8 @@ field_spec:

field_def:
opt_attribute
| opt_generated_always AS
'(' virtual_column_func ')'
{ Lex->last_field->vcol_info= $4; }
| opt_generated_always AS virtual_column_func
{ Lex->last_field->vcol_info= $3; }
vcol_opt_specifier vcol_opt_attribute
;

Expand Down Expand Up @@ -6393,7 +6392,7 @@ vcol_attribute:
;

parse_vcol_expr:
PARSE_VCOL_EXPR_SYM '(' virtual_column_func ')'
PARSE_VCOL_EXPR_SYM virtual_column_func
{
/*
"PARSE_VCOL_EXPR" can only be used by the SQL server
Expand All @@ -6405,15 +6404,32 @@ parse_vcol_expr:
my_message(ER_SYNTAX_ERROR, ER_THD(thd, ER_SYNTAX_ERROR), MYF(0));
MYSQL_YYABORT;
}
Lex->last_field->vcol_info= $3;
Lex->last_field->vcol_info= $2;
}
;

parenthesized_expr:
subselect
{
$$= new (thd->mem_root) Item_singlerow_subselect(thd, $1);
if ($$ == NULL)
MYSQL_YYABORT;
}
| expr
| expr ',' expr_list
{
$3->push_front($1, thd->mem_root);
$$= new (thd->mem_root) Item_row(thd, *$3);
if ($$ == NULL)
MYSQL_YYABORT;
}
;

virtual_column_func:
remember_cur_pos expr remember_end
'(' remember_cur_pos parenthesized_expr remember_end ')'
{
Virtual_column_info *v=
add_virtual_expression(thd, $1, (uint)($3 - $1), $2);
add_virtual_expression(thd, $2, (uint)($4 - $2), $3);
if (!v)
{
MYSQL_YYABORT;
Expand All @@ -6423,7 +6439,7 @@ virtual_column_func:
;

column_default_expr:
'(' virtual_column_func ')' { $$= $2; }
virtual_column_func
| remember_name column_default_non_parenthesized_expr opt_impossible_action remember_end
{
if (!($$= add_virtual_expression(thd, $1, (uint) ($4- $1), $2)))
Expand Down Expand Up @@ -7858,7 +7874,7 @@ alter_list_item:
lex->alter_info.keys_onoff= Alter_info::ENABLE;
lex->alter_info.flags|= Alter_info::ALTER_KEYS_ONOFF;
}
| ALTER opt_column field_ident SET DEFAULT virtual_column_func
| ALTER opt_column field_ident SET DEFAULT column_default_expr
{
LEX *lex=Lex;
Alter_column *ac= new (thd->mem_root) Alter_column($3.str,$6);
Expand Down Expand Up @@ -9668,21 +9684,7 @@ simple_expr:
if ($$ == NULL)
MYSQL_YYABORT;
}
| '(' subselect ')'
{
$$= new (thd->mem_root) Item_singlerow_subselect(thd, $2);
if ($$ == NULL)
MYSQL_YYABORT;
}
| '(' expr ')'
{ $$= $2; }
| '(' expr ',' expr_list ')'
{
$4->push_front($2, thd->mem_root);
$$= new (thd->mem_root) Item_row(thd, *$4);
if ($$ == NULL)
MYSQL_YYABORT;
}
| '(' parenthesized_expr ')' { $$= $2; }
| BINARY simple_expr %prec NEG
{
$$= create_func_cast(thd, $2, ITEM_CAST_CHAR, NULL, NULL,
Expand Down

0 comments on commit 1b4f096

Please sign in to comment.