summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/sp-error.result8
-rw-r--r--mysql-test/r/view.result6
-rw-r--r--mysql-test/suite/funcs_1/r/innodb_views.result2
-rw-r--r--mysql-test/suite/funcs_1/r/memory_views.result2
-rw-r--r--mysql-test/suite/funcs_1/views/views_master.inc2
-rw-r--r--mysql-test/t/sp-error.test8
-rw-r--r--mysql-test/t/view.test6
-rw-r--r--sql/share/errmsg-utf8.txt2
-rw-r--r--sql/sql_lex.cc2
-rw-r--r--sql/sql_lex.h2
-rw-r--r--sql/sql_yacc.yy89
11 files changed, 85 insertions, 44 deletions
diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result
index c56597e6e44..447afe3d330 100644
--- a/mysql-test/r/sp-error.result
+++ b/mysql-test/r/sp-error.result
@@ -1227,14 +1227,14 @@ DROP PROCEDURE IF EXISTS bug14702;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (i INT);
CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO @a;
-ERROR HY000: View's SELECT contains a 'INTO' clause
+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 'INTO @a' at line 1
CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO DUMPFILE "file";
-ERROR HY000: View's SELECT contains a 'INTO' clause
+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 'INTO DUMPFILE "file"' at line 1
CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO OUTFILE "file";
-ERROR HY000: View's SELECT contains a 'INTO' clause
+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 'INTO OUTFILE "file"' at line 1
CREATE PROCEDURE bug20953()
CREATE VIEW v AS SELECT i FROM t1 PROCEDURE ANALYSE();
-ERROR HY000: View's SELECT contains a 'PROCEDURE' clause
+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 'PROCEDURE ANALYSE()' at line 2
CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 FROM (SELECT 1) AS d1;
ERROR HY000: View's SELECT contains a subquery in the FROM clause
CREATE PROCEDURE bug20953(i INT) CREATE VIEW v AS SELECT i;
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index 3fccd6e54c2..ca1a1dfa48a 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -923,12 +923,12 @@ select * from v4;
ERROR 21000: Subquery returns more than 1 row
drop view v4, v3, v2, v1;
create view v1 as select 5 into @w;
-ERROR HY000: View's SELECT contains a 'INTO' clause
+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 'into @w' at line 1
create view v1 as select 5 into outfile 'ttt';
-ERROR HY000: View's SELECT contains a 'INTO' clause
+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 'into outfile 'ttt'' at line 1
create table t1 (a int);
create view v1 as select a from t1 procedure analyse();
-ERROR HY000: View's SELECT contains a 'PROCEDURE' clause
+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 'procedure analyse()' at line 1
create view v1 as select 1 from (select 1) as d1;
ERROR HY000: View's SELECT contains a subquery in the FROM clause
drop table t1;
diff --git a/mysql-test/suite/funcs_1/r/innodb_views.result b/mysql-test/suite/funcs_1/r/innodb_views.result
index 59eec5b0220..45de9534df2 100644
--- a/mysql-test/suite/funcs_1/r/innodb_views.result
+++ b/mysql-test/suite/funcs_1/r/innodb_views.result
@@ -3497,7 +3497,7 @@ DROP VIEW IF EXISTS v2 ;
CREATE TABLE t1 (f1 BIGINT) ;
SET @x=0;
CREATE or REPLACE VIEW v1 AS Select 1 INTO @x;
-ERROR HY000: View's SELECT contains a 'INTO' clause
+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 'INTO @x' at line 1
Select @x;
@x
0
diff --git a/mysql-test/suite/funcs_1/r/memory_views.result b/mysql-test/suite/funcs_1/r/memory_views.result
index 995787aba84..ab4e2a9933c 100644
--- a/mysql-test/suite/funcs_1/r/memory_views.result
+++ b/mysql-test/suite/funcs_1/r/memory_views.result
@@ -3498,7 +3498,7 @@ DROP VIEW IF EXISTS v2 ;
CREATE TABLE t1 (f1 BIGINT) ;
SET @x=0;
CREATE or REPLACE VIEW v1 AS Select 1 INTO @x;
-ERROR HY000: View's SELECT contains a 'INTO' clause
+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 'INTO @x' at line 1
Select @x;
@x
0
diff --git a/mysql-test/suite/funcs_1/views/views_master.inc b/mysql-test/suite/funcs_1/views/views_master.inc
index bb9bbdb06d0..f55788de6c6 100644
--- a/mysql-test/suite/funcs_1/views/views_master.inc
+++ b/mysql-test/suite/funcs_1/views/views_master.inc
@@ -266,7 +266,7 @@ CREATE TABLE t1 (f1 BIGINT) ;
# SELECT INTO is illegal
SET @x=0;
---error ER_VIEW_SELECT_CLAUSE
+--error ER_PARSE_ERROR
CREATE or REPLACE VIEW v1 AS Select 1 INTO @x;
Select @x;
diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test
index d403b19eff7..b1d4f67f357 100644
--- a/mysql-test/t/sp-error.test
+++ b/mysql-test/t/sp-error.test
@@ -1785,13 +1785,13 @@ CREATE TABLE t1 (i INT);
# We do not have to drop this procedure and view because they won't be
# created.
---error ER_VIEW_SELECT_CLAUSE
+--error ER_PARSE_ERROR
CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO @a;
---error ER_VIEW_SELECT_CLAUSE
+--error ER_PARSE_ERROR
CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO DUMPFILE "file";
---error ER_VIEW_SELECT_CLAUSE
+--error ER_PARSE_ERROR
CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO OUTFILE "file";
---error ER_VIEW_SELECT_CLAUSE
+--error ER_PARSE_ERROR
CREATE PROCEDURE bug20953()
CREATE VIEW v AS SELECT i FROM t1 PROCEDURE ANALYSE();
--error ER_VIEW_SELECT_DERIVED
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index d11b7f0bc37..9fdabca82de 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -840,12 +840,12 @@ drop view v4, v3, v2, v1;
#
# VIEW over SELECT with prohibited clauses
#
--- error ER_VIEW_SELECT_CLAUSE
+-- error ER_PARSE_ERROR
create view v1 as select 5 into @w;
--- error ER_VIEW_SELECT_CLAUSE
+-- error ER_PARSE_ERROR
create view v1 as select 5 into outfile 'ttt';
create table t1 (a int);
--- error ER_VIEW_SELECT_CLAUSE
+-- error ER_PARSE_ERROR
create view v1 as select a from t1 procedure analyse();
-- error ER_VIEW_SELECT_DERIVED
create view v1 as select 1 from (select 1) as d1;
diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index 376c1eb9d0d..7dfc6223763 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -5218,6 +5218,8 @@ ER_VIEW_SELECT_DERIVED
ger "SELECT der View enthält eine Subquery in der FROM-Klausel"
rus "View SELECT содержит подзапрос в конструкции FROM"
ukr "View SELECT має підзапит у конструкції FROM"
+
+# Not used any more, syntax error is returned instead
ER_VIEW_SELECT_CLAUSE
eng "View's SELECT contains a '%s' clause"
ger "SELECT der View enthält eine '%s'-Klausel"
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index de345b4dd1c..8d5f54f2766 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -232,8 +232,6 @@ void
st_parsing_options::reset()
{
allows_variable= TRUE;
- allows_select_into= TRUE;
- allows_select_procedure= TRUE;
allows_derived= TRUE;
}
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 10247bd33a2..028ede480d4 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -1817,8 +1817,6 @@ private:
struct st_parsing_options
{
bool allows_variable;
- bool allows_select_into;
- bool allows_select_procedure;
bool allows_derived;
st_parsing_options() { reset(); }
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 50b943c7ea0..ac43129372c 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -8545,6 +8545,23 @@ select_paren:
| '(' select_paren ')'
;
+select_paren_view:
+ {
+ /*
+ In order to correctly parse UNION's global ORDER BY we need to
+ set braces before parsing the clause.
+ */
+ Lex->current_select->set_braces(true);
+ }
+ SELECT_SYM select_options_and_item_list select_part3_view
+ opt_select_lock_type
+ {
+ if (setup_select_in_parentheses(Lex))
+ MYSQL_YYABORT;
+ }
+ | '(' select_paren_view ')'
+ ;
+
/* The equivalent of select_paren for nested queries. */
select_paren_derived:
{
@@ -8580,11 +8597,37 @@ select_init3:
;
+select_init3_view:
+ opt_table_expression opt_select_lock_type
+ {
+ Lex->current_select->set_braces(false);
+ }
+ | opt_table_expression opt_select_lock_type
+ {
+ Lex->current_select->set_braces(false);
+ }
+ union_list_view
+ | order_or_limit opt_select_lock_type
+ {
+ Lex->current_select->set_braces(false);
+ }
+ | table_expression order_or_limit opt_select_lock_type
+ {
+ Lex->current_select->set_braces(false);
+ }
+ ;
+
select_part3:
opt_table_expression
| select_part3_union_not_ready
;
+select_part3_view:
+ opt_table_expression
+ | order_or_limit
+ | table_expression order_or_limit
+ ;
+
/*
The SELECT parts after select_item_list that cannot be followed by UNION.
*/
@@ -11969,12 +12012,6 @@ procedure_clause:
{
LEX *lex=Lex;
- if (! lex->parsing_options.allows_select_procedure)
- {
- my_error(ER_VIEW_SELECT_CLAUSE, MYF(0), "PROCEDURE");
- MYSQL_YYABORT;
- }
-
if (&lex->select_lex != lex->current_select)
{
// SELECT * FROM t1 UNION SELECT * FROM t2 PROCEDURE ANALYSE();
@@ -12086,15 +12123,7 @@ select_outvar:
;
into:
- INTO
- {
- if (! Lex->parsing_options.allows_select_into)
- {
- my_error(ER_VIEW_SELECT_CLAUSE, MYF(0), "INTO");
- MYSQL_YYABORT;
- }
- }
- into_destination
+ INTO into_destination
;
into_destination:
@@ -16342,6 +16371,18 @@ union_list:
}
;
+union_list_view:
+ UNION_SYM union_option
+ {
+ if (add_select_to_union_list(Lex, (bool)$2, TRUE))
+ MYSQL_YYABORT;
+ }
+ query_expression_body_view
+ {
+ Lex->pop_context();
+ }
+ ;
+
union_opt:
opt_union_order_or_limit
| union_list { $$= 1; }
@@ -16654,12 +16695,10 @@ view_select:
{
LEX *lex= Lex;
lex->parsing_options.allows_variable= FALSE;
- lex->parsing_options.allows_select_into= FALSE;
- lex->parsing_options.allows_select_procedure= FALSE;
lex->parsing_options.allows_derived= FALSE;
lex->create_view_select.str= (char *) YYLIP->get_cpp_ptr();
}
- opt_with_clause view_select_aux view_check_option
+ opt_with_clause query_expression_body_view view_check_option
{
LEX *lex= Lex;
uint len= YYLIP->get_cpp_ptr() - lex->create_view_select.str;
@@ -16668,16 +16707,20 @@ view_select:
lex->create_view_select.str= (char *) create_view_select;
trim_whitespace(thd->charset(), &lex->create_view_select);
lex->parsing_options.allows_variable= TRUE;
- lex->parsing_options.allows_select_into= TRUE;
- lex->parsing_options.allows_select_procedure= TRUE;
lex->parsing_options.allows_derived= TRUE;
lex->current_select->set_with_clause($2);
}
;
-view_select_aux:
- SELECT_SYM select_options_and_item_list select_init3
- | '(' select_paren ')' union_opt
+/*
+ SQL Standard <query expression body> for VIEWs.
+ Does not include INTO and PROCEDURE clauses.
+*/
+query_expression_body_view:
+ SELECT_SYM select_options_and_item_list select_init3_view
+ | '(' select_paren_view ')'
+ | '(' select_paren_view ')' union_order_or_limit
+ | '(' select_paren_view ')' union_list_view
;
view_check_option: