List:Commits« Previous MessageNext Message »
From:mhansson Date:December 10 2007 9:05am
Subject:bk commit into 5.1 tree (mhansson:1.2587) BUG#32858
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of martin. When martin does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2007-12-10 09:05:38+01:00, mhansson@stripped +3 -0
  Bug#32858: Erro: "Incorrect usage of UNION and INTO" does not take subselects 
  into account
  
  It is forbidden to use the SELECT INTO construction inside UNION statements
  unless on the last SELECT of the union. The parser records whether it 
  has seen INTO or not when parsing a UNION statement. But if the INTO was
  legally used in an outer query, an error is thrown if UNION is seen in a
  subquery. Fixed in 5.1 by only allowing INTO in top level SELECT's, and
  only doing the check for misplaced INTO when parsing top level UNION.

  mysql-test/r/union.result@stripped, 2007-12-10 09:05:35+01:00, mhansson@stripped +15
-0
    Bug#32858: Test result

  mysql-test/t/union.test@stripped, 2007-12-10 09:05:35+01:00, mhansson@stripped +25
-0
    Bug#32858: Test case

  sql/sql_yacc.yy@stripped, 2007-12-10 09:05:35+01:00, mhansson@stripped +7 -2
    Bug#32858: The fix

diff -Nrup a/mysql-test/r/union.result b/mysql-test/r/union.result
--- a/mysql-test/r/union.result	2007-05-29 14:57:47 +02:00
+++ b/mysql-test/r/union.result	2007-12-10 09:05:35 +01:00
@@ -1446,3 +1446,18 @@ select @var;
 (select 2) union (select 1 into @var);
 ERROR 42000: Result consisted of more than one row
 End of 5.0 tests
+CREATE TABLE t1 (
+a INT
+);
+INSERT INTO t1 VALUES (1);
+SELECT a INTO @v FROM (
+SELECT a FROM t1
+UNION
+SELECT a FROM t1
+) alias;
+SELECT a FROM (SELECT a INTO @v FROM t1) alias;
+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 'INTO @v FROM t1) alias' at
line 1
+SELECT a FROM t1 UNION SELECT a INTO @v FROM t1;
+SELECT a INTO @v FROM t1 UNION SELECT a FROM t1;
+ERROR HY000: Incorrect usage of UNION and INTO
+DROP TABLE t1;
diff -Nrup a/mysql-test/t/union.test b/mysql-test/t/union.test
--- a/mysql-test/t/union.test	2007-03-22 08:21:15 +01:00
+++ b/mysql-test/t/union.test	2007-12-10 09:05:35 +01:00
@@ -923,3 +923,28 @@ select @var;
 --error 1172
 (select 2) union (select 1 into @var);
 --echo End of 5.0 tests
+
+#
+# Bug#32858: Erro: "Incorrect usage of UNION and INTO" does not take subselects 
+# into account
+#
+CREATE TABLE t1 (
+  a INT
+);
+INSERT INTO t1 VALUES (1);
+
+SELECT a INTO @v FROM (
+  SELECT a FROM t1
+  UNION
+  SELECT a FROM t1
+) alias;
+
+# INTO is not allowed in subqueries in version 5.1 and above.
+--error ER_PARSE_ERROR
+SELECT a FROM (SELECT a INTO @v FROM t1) alias;
+
+SELECT a FROM t1 UNION SELECT a INTO @v FROM t1;
+--error ER_WRONG_USAGE
+SELECT a INTO @v FROM t1 UNION SELECT a FROM t1;
+
+DROP TABLE t1;
diff -Nrup a/sql/sql_yacc.yy b/sql/sql_yacc.yy
--- a/sql/sql_yacc.yy	2007-10-16 11:10:03 +02:00
+++ b/sql/sql_yacc.yy	2007-12-10 09:05:35 +01:00
@@ -8434,6 +8434,8 @@ procedure_item:
 select_var_list_init:
           {
             LEX *lex=Lex;
+            if (lex->nest_level > 0 )
+              my_parse_error(ER(ER_SYNTAX_ERROR));
             if (!lex->describe && (!(lex->result= new select_dumpvar())))
               MYSQL_YYABORT;
           }
@@ -11733,9 +11735,12 @@ union_list:
           UNION_SYM union_option
           {
             LEX *lex=Lex;
-            if (lex->result)
+            if (lex->result && lex->nest_level == 0)
             {
-              /* Only the last SELECT can have  INTO...... */
+              /* 
+                 Only the last SELECT can have INTO, but nested selects can't
+                 contain INTO anyway.
+              */
               my_error(ER_WRONG_USAGE, MYF(0), "UNION", "INTO");
               MYSQL_YYABORT;
             }
Thread
bk commit into 5.1 tree (mhansson:1.2587) BUG#32858mhansson10 Dec