]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix for tickets #32 and #33: Generate the names of the result set early, before
authordrh <drh@noemail.net>
Wed, 8 May 2002 11:54:14 +0000 (11:54 +0000)
committerdrh <drh@noemail.net>
Wed, 8 May 2002 11:54:14 +0000 (11:54 +0000)
doing the flattening optimization or evaluating subqueries.  Otherwise, the
result set column names are generated incorrectly or after they are needed. (CVS 553)

FossilOrigin-Name: 08f27cb36805d38648274b6fe91dec43a5910057

manifest
manifest.uuid
src/select.c
test/view.test

index 07120727c26820ebb7e605f9ee97c44e5fa106a3..46318c96989c37193cb950796e36b0777c6f0d9c 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Added\sdocumentation\sabout\sthe\snew\sCASE\sexpression.\s(CVS\s552)
-D 2002-05-06T11:47:33
+C Fix\sfor\stickets\s#32\sand\s#33:\sGenerate\sthe\snames\sof\sthe\sresult\sset\searly,\sbefore\ndoing\sthe\sflattening\soptimization\sor\sevaluating\ssubqueries.\s\sOtherwise,\sthe\nresult\sset\scolumn\snames\sare\sgenerated\sincorrectly\sor\safter\sthey\sare\sneeded.\s(CVS\s553)
+D 2002-05-08T11:54:15
 F Makefile.in 50f1b3351df109b5774771350d8c1b8d3640130d
 F Makefile.template 89e373b2dad0321df00400fa968dc14b61a03296
 F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0
@@ -37,7 +37,7 @@ F src/pager.h 6fddfddd3b73aa8abc081b973886320e3c614f0e
 F src/parse.y 0ce56f1c751657f01e18a4b4ac1aa4d29525ac20
 F src/printf.c 300a90554345751f26e1fc0c0333b90a66110a1d
 F src/random.c 19e8e00fe0df32a742f115773f57651be327cabe
-F src/select.c 5e9fe2cdbb398be036c43bfa71b0686fcbbe5f96
+F src/select.c 1b623a7d826ec7c245bc542b665d61724da2a62d
 F src/shell.c 5acbe59e137d60d8efd975c683dbea74ab626530
 F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e
 F src/sqlite.h.in ffcacf73b5ed1a4939205d29a704a185758fa6a6
@@ -100,7 +100,7 @@ F test/trans.test ae0b9a82d5d34122c3a3108781eb8d078091ccee
 F test/unique.test 07776624b82221a80c8b4138ce0dd8b0853bb3ea
 F test/update.test 3cf1ca0565f678063c2dfa9a7948d2d66ae1a778
 F test/vacuum.test 059871b312eb910bbe49dafde1d01490cc2c6bbe
-F test/view.test 4a8a9cf59b54409228c7b9b918ed8bf9bade1220
+F test/view.test 1536b58161e9cef544085d3928b53f17c9ed8424
 F test/where.test 1d85a7eba93e7acc0a971c6d9daead0e49cb023a
 F tool/lemon.c 77d026f58d7715543786d457cf9432f9103e3f62
 F tool/lempar.c ee508b94607f74d591d60eda5c8014db4e144de5
@@ -130,7 +130,7 @@ F www/speed.tcl da8afcc1d3ccc5696cfb388a68982bc3d9f7f00f
 F www/sqlite.tcl 8b5884354cb615049aed83039f8dfe1552a44279
 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P 5772d31934ced7e35842d7c7689ff4878b7e80f5
-R b085b09618ae8814b296116bb7ca3dee
+P cc541b10302774b9004babbfb3a11b1f65d4b863
+R 054a35fac576992802ba562437446471
 U drh
-Z cddb6e7b9d73903f2cd270dc5481d839
+Z 04c420bf6c4394719a156e66dc666487
index c1903872e073f3d2b8ebf7dbed3548facb21ce14..5f41bfe897f17618c36f96f2c876cfc223b5a61a 100644 (file)
@@ -1 +1 @@
-cc541b10302774b9004babbfb3a11b1f65d4b863
\ No newline at end of file
+08f27cb36805d38648274b6fe91dec43a5910057
\ No newline at end of file
index 530a7a3dda997f5e1559369f3ad2a1ff18839d04..7038809ce9bd76ee50db917fb73c7855dd7f8380 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains C code routines that are called by the parser
 ** to handle SELECT statements in SQLite.
 **
-** $Id: select.c,v 1.80 2002/04/30 19:20:29 drh Exp $
+** $Id: select.c,v 1.81 2002/05/08 11:54:15 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -931,9 +931,10 @@ substExprList(ExprList *pList, int iTable, ExprList *pEList, int iSub){
 ** the subquery before this routine runs.
 */
 int flattenSubquery(Select *p, int iFrom, int isAgg, int subqueryIsAgg){
-  Select *pSub;
-  IdList *pSrc, *pSubSrc;
-  ExprList *pList;
+  Select *pSub;       /* The inner query or "subquery" */
+  IdList *pSrc;       /* The FROM clause of the outer query */
+  IdList *pSubSrc;    /* The FROM clause of the subquery */
+  ExprList *pList;    /* The result set of the outer query */
   int i;
   int iParent, iSub;
   Expr *pWhere;
@@ -954,7 +955,7 @@ int flattenSubquery(Select *p, int iFrom, int isAgg, int subqueryIsAgg){
   if( pSub->isDistinct && isAgg ) return 0;
   if( p->isDistinct && subqueryIsAgg ) return 0;
 
-  /* If we reach this point, it means flatting is permitted for the
+  /* If we reach this point, it means flattening is permitted for the
   ** i-th entry of the FROM clause in the outer query.
   */
   iParent = p->base + iFrom;
@@ -1332,6 +1333,22 @@ int sqliteSelect(
   v = sqliteGetVdbe(pParse);
   if( v==0 ) goto select_end;
 
+  /* Identify column names if we will be using in the callback.  This
+  ** step is skipped if the output is going to a table or a memory cell.
+  */
+  if( eDest==SRT_Callback ){
+    generateColumnNames(pParse, p->base, pTabList, pEList);
+  }
+
+  /* Set the limiter
+  */
+  if( p->nLimit<=0 ){
+    p->nOffset = 0;
+  }else{
+    if( p->nOffset<0 ) p->nOffset = 0;
+    sqliteVdbeAddOp(v, OP_Limit, p->nLimit, p->nOffset);
+  }
+
   /* Generate code for all sub-queries in the FROM clause
   */
   for(i=0; i<pTabList->nId; i++){
@@ -1392,23 +1409,6 @@ int sqliteSelect(
     }
   }
 
-  /* Set the limiter
-  */
-  if( p->nLimit<=0 ){
-    p->nOffset = 0;
-  }else{
-    if( p->nOffset<0 ) p->nOffset = 0;
-    sqliteVdbeAddOp(v, OP_Limit, p->nLimit, p->nOffset);
-  }
-    
-
-  /* Identify column names if we will be using in the callback.  This
-  ** step is skipped if the output is going to a table or a memory cell.
-  */
-  if( eDest==SRT_Callback ){
-    generateColumnNames(pParse, p->base, pTabList, pEList);
-  }
-
   /* Reset the aggregator
   */
   if( isAgg ){
index 859d9e95b10758f43215469c851c500968ca193c..f915384a859fea994434d51a15f1e74d75b592f9 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing VIEW statements.
 #
-# $Id: view.test,v 1.3 2002/03/03 23:06:02 drh Exp $
+# $Id: view.test,v 1.4 2002/05/08 11:54:16 drh Exp $
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
 
@@ -121,6 +121,31 @@ do_test view-2.6 {
   }
 } {11}
 
+# Test that column name of views are generated correctly.
+#
+do_test view-3.1 {
+  execsql2 {
+    SELECT * FROM v1 LIMIT 1
+  }
+} {a 2 b 3}
+do_test view-3.2 {
+  execsql2 {
+    SELECT * FROM v2 LIMIT 1
+  }
+} {x 7 a 8 b 9 c 10}
+do_test view-3.3 {
+  execsql2 {
+    DROP VIEW v1;
+    CREATE VIEW v1 AS SELECT a AS 'xyz', b+c AS 'pqr', c-b FROM t1;
+    SELECT * FROM v1 LIMIT 1
+  }
+} {xyz 2 pqr 7 c-b 1}
+do_test  view-3.4 {
+  execsql2 {
+    CREATE VIEW v3 AS SELECT a FROM t1 UNION SELECT b FROM t1 ORDER BY b;
+    SELECT * FROM v3 LIMIT 4;
+  }
+} {b 2 b 3 b 5 b 6}
 
 
 finish_test