Index: src/select.c ================================================================== --- src/select.c +++ src/select.c @@ -10,11 +10,11 @@ ** ************************************************************************* ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** -** $Id: select.c,v 1.235 2005/01/29 08:32:45 danielk1977 Exp $ +** $Id: select.c,v 1.236 2005/01/30 11:11:44 danielk1977 Exp $ */ #include "sqliteInt.h" /* @@ -854,10 +854,13 @@ ExprList *pEList; Column *aCol, *pCol; if( prepSelectStmt(pParse, pSelect) ){ return 0; + } + if( sqlite3SelectResolve(pParse, pSelect, 0) ){ + return 0; } pTab = sqliteMalloc( sizeof(Table) ); if( pTab==0 ){ return 0; } @@ -987,11 +990,10 @@ assert( pFrom->pSelect!=0 ); if( pFrom->zAlias==0 ){ pFrom->zAlias = sqlite3MPrintf("sqlite_subquery_%p_", (void*)pFrom->pSelect); } - sqlite3SelectResolve(pParse, pFrom->pSelect, 0); pFrom->pTab = pTab = sqlite3ResultSetOfSelect(pParse, pFrom->zAlias, pFrom->pSelect); if( pTab==0 ){ return 1; } Index: test/subquery.test ================================================================== --- test/subquery.test +++ test/subquery.test @@ -9,11 +9,11 @@ # #************************************************************************* # This file implements regression tests for SQLite library. The # focus of this script is testing correlated subqueries # -# $Id: subquery.test,v 1.3 2005/01/29 08:32:47 danielk1977 Exp $ +# $Id: subquery.test,v 1.4 2005/01/30 11:11:44 danielk1977 Exp $ # set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -77,15 +77,27 @@ SELECT a, x FROM t2, t1 WHERE t1.a = (SELECT x); } } {1 1 3 3 5 5 7 7} # Try an aggregate in both the subquery and the parent query. -do_test subquery-1.6 { +do_test subquery-1.8 { execsql { SELECT count(*) FROM t1 WHERE a > (SELECT count(*) FROM t2); } } {2} + +# Test a correlated subquery disables the "only open the index" optimization. +do_test subquery-1.9.1 { + execsql { + SELECT (y*2)>b FROM t1, t2 WHERE a=x; + } +} {0 1 1 1} +do_test subquery-1.9.2 { + execsql { + SELECT a FROM t1 WHERE (SELECT (y*2)>b FROM t2 WHERE a=x); + } +} {3 5 7} #------------------------------------------------------------------ # The following test cases - subquery-2.* - are not logically # organized. They're here largely because they were failing during Index: test/view.test ================================================================== --- test/view.test +++ test/view.test @@ -9,11 +9,11 @@ # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing VIEW statements. # -# $Id: view.test,v 1.23 2005/01/29 08:32:47 danielk1977 Exp $ +# $Id: view.test,v 1.24 2005/01/30 11:11:44 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Omit this entire file if the library is not configured with views enabled. ifcapable !view { @@ -416,7 +416,28 @@ do_test view-10.2 { execsql { SELECT * FROM v_t3_b; } } {2} + +do_test view-11.1 { + execsql { + CREATE TABLE t4(a COLLATE NOCASE); + INSERT INTO t4 VALUES('This'); + INSERT INTO t4 VALUES('this'); + INSERT INTO t4 VALUES('THIS'); + SELECT * FROM t4 WHERE a = 'THIS'; + } +} {This this THIS} +do_test view-11.2 { + execsql { + SELECT * FROM (SELECT * FROM t4) WHERE a = 'THIS'; + } +} {This this THIS} +do_test view-11.3 { + execsql { + CREATE VIEW v11 AS SELECT * FROM t4; + SELECT * FROM v11 WHERE a = 'THIS'; + } +} {This this THIS} finish_test