/ Check-in [85b355cf]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Make sure a multi-row VALUES clause works correctly in a compound SELECT.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 85b355cfb40e8dbeb171980204ffad897184063f
User & Date: drh 2014-02-19 01:31:02
Context
2014-02-19
14:20
Add the SQLITE_NOTNULL P5 code for comparison operations - really a composite of SQLITE_NULLEQ and SQLITE_JUMPIFNULL. This flag indicates that NULL operands are not possible and raises and assert() if NULL operands are seen. Also omit an unnecessary scan of the sqlite_sequence table when writing into an AUTOINCREMENT table. check-in: d2c047f3 user: drh tags: trunk
01:31
Make sure a multi-row VALUES clause works correctly in a compound SELECT. check-in: 85b355cf user: drh tags: trunk
00:53
Tweaks in support of VDBE branch test coverage. check-in: b9782564 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/parse.y.

   433    433     }
   434    434     A = p;
   435    435   }
   436    436   
   437    437   selectnowith(A) ::= oneselect(X).                      {A = X;}
   438    438   %ifndef SQLITE_OMIT_COMPOUND_SELECT
   439    439   selectnowith(A) ::= selectnowith(X) multiselect_op(Y) oneselect(Z).  {
   440         -  if( Z ){
   441         -    Z->op = (u8)Y;
   442         -    Z->pPrior = X;
          440  +  Select *pRhs = Z;
          441  +  if( pRhs && pRhs->pPrior ){
          442  +    SrcList *pFrom;
          443  +    Token x;
          444  +    x.n = 0;
          445  +    pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
          446  +    pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0);
          447  +  }
          448  +  if( pRhs ){
          449  +    pRhs->op = (u8)Y;
          450  +    pRhs->pPrior = X;
   443    451       if( Y!=TK_ALL ) pParse->hasCompound = 1;
   444    452     }else{
   445    453       sqlite3SelectDelete(pParse->db, X);
   446    454     }
   447         -  A = Z;
          455  +  A = pRhs;
   448    456   }
   449    457   %type multiselect_op {int}
   450    458   multiselect_op(A) ::= UNION(OP).             {A = @OP;}
   451    459   multiselect_op(A) ::= UNION ALL.             {A = TK_ALL;}
   452    460   multiselect_op(A) ::= EXCEPT|INTERSECT(OP).  {A = @OP;}
   453    461   %endif SQLITE_OMIT_COMPOUND_SELECT
   454    462   oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)

Changes to test/select4.test.

   819    819       INSERT INTO t13 VALUES(2,2);
   820    820       INSERT INTO t13 VALUES(3,2);
   821    821       INSERT INTO t13 VALUES(4,2);
   822    822       CREATE INDEX t13ab ON t13(a,b);
   823    823       SELECT DISTINCT b from t13 WHERE a IN (1,2,3);
   824    824     }
   825    825   } {1 2}
          826  +
          827  +# 2014-02-18: Make sure compound SELECTs work with VALUES clauses
          828  +#
          829  +do_execsql_test select4-14.1 {
          830  +  CREATE TABLE t14(a,b,c);
          831  +  INSERT INTO t14 VALUES(1,2,3),(4,5,6);
          832  +  SELECT * FROM t14 INTERSECT VALUES(3,2,1),(2,3,1),(1,2,3),(2,1,3);
          833  +} {1 2 3}
          834  +do_execsql_test select4-14.2 {
          835  +  SELECT * FROM t14 INTERSECT VALUES(1,2,3);
          836  +} {1 2 3}
          837  +do_execsql_test select4-14.3 {
          838  +  SELECT * FROM t14
          839  +   UNION VALUES(3,2,1),(2,3,1),(1,2,3),(7,8,9),(4,5,6)
          840  +   UNION SELECT * FROM t14 ORDER BY 1, 2, 3
          841  +} {1 2 3 2 3 1 3 2 1 4 5 6 7 8 9}
          842  +do_execsql_test select4-14.4 {
          843  +  SELECT * FROM t14
          844  +   UNION VALUES(3,2,1)
          845  +   UNION SELECT * FROM t14 ORDER BY 1, 2, 3
          846  +} {1 2 3 3 2 1 4 5 6}
          847  +do_execsql_test select4-14.5 {
          848  +  SELECT * FROM t14 EXCEPT VALUES(3,2,1),(2,3,1),(1,2,3),(2,1,3);
          849  +} {4 5 6}
          850  +do_execsql_test select4-14.6 {
          851  +  SELECT * FROM t14 EXCEPT VALUES(1,2,3)
          852  +} {4 5 6}
          853  +do_execsql_test select4-14.7 {
          854  +  SELECT * FROM t14 EXCEPT VALUES(1,2,3) EXCEPT VALUES(4,5,6)
          855  +} {}
          856  +do_execsql_test select4-14.8 {
          857  +  SELECT * FROM t14 EXCEPT VALUES('a','b','c') EXCEPT VALUES(4,5,6)
          858  +} {1 2 3}
          859  +do_execsql_test select4-14.9 {
          860  +  SELECT * FROM t14 UNION ALL VALUES(3,2,1),(2,3,1),(1,2,3),(2,1,3);
          861  +} {1 2 3 4 5 6 3 2 1 2 3 1 1 2 3 2 1 3}
   826    862   
   827    863   finish_test