Index: src/where.c ================================================================== --- src/where.c +++ src/where.c @@ -3156,22 +3156,27 @@ int nEq = pPlan->nEq; char *zRet = 0; int i; for(i=0; iaCol[pIndex->aiColumn[i]].zName; zRet = sqlite3MAppendf(db, zRet, - "%s%s%s=?", (zRet?zRet:""), (zRet?" AND ":""), zCol); + "%s%s%s=?", (zRet?zRet:""), (zRet?" AND ":""), + pTab->aCol[pIndex->aiColumn[i]].zName + ); } if( pPlan->wsFlags&WHERE_BTM_LIMIT ){ zRet = sqlite3MAppendf(db, zRet, - "%s%s%s>?", (zRet?zRet:""), (zRet?" AND ":""), pTab->aCol[nEq].zName); + "%s%s%s>?", (zRet?zRet:""), (zRet?" AND ":""), + pTab->aCol[pIndex->aiColumn[i]].zName + ); } if( pPlan->wsFlags&WHERE_TOP_LIMIT ){ zRet = sqlite3MAppendf(db, zRet, - "%s%s%saCol[nEq].zName); + "%s%s%saCol[pIndex->aiColumn[i]].zName + ); } if( zRet ){ zRet = sqlite3MAppendf(db, zRet, " (%s)", zRet); } Index: test/autoindex1.test ================================================================== --- test/autoindex1.test +++ test/autoindex1.test @@ -239,13 +239,13 @@ ) y ON x.sheep_no = y.sheep_no WHERE y.sheep_no IS NULL ORDER BY x.registering_flock; } { 1 0 0 {SCAN TABLE sheep AS s (~1000000 rows)} - 1 1 1 {SCAN TABLE flock_owner AS prev BY INDEX sqlite_autoindex_flock_owner_1 (flock_no=? AND flock_no? AND flock_no? AND owner_change_date10" - {0 0 0 {SCAN TABLE t2 BY INDEX sqlite_autoindex_t2_1 (b=? AND b>?) (~3 rows)}} + {0 0 0 {SCAN TABLE t2 BY INDEX sqlite_autoindex_t2_1 (b=? AND c>?) (~3 rows)}} } # EVIDENCE-OF: R-45493-35653 A CHECK constraint may be attached to a # column definition or specified as a table constraint. In practice it # makes no difference. Index: test/fts3fault.test ================================================================== --- test/fts3fault.test +++ test/fts3fault.test @@ -12,10 +12,13 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl set ::testprefix fts3fault + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { finish_test ; return } # Test error handling in the sqlite3Fts3Init() function. This is the # function that registers the FTS3 module and various support functions # with SQLite. # Index: test/where7.test ================================================================== --- test/where7.test +++ test/where7.test @@ -23341,10 +23341,10 @@ OR t301.c8 = 1407424651264000) ORDER BY t302.c5 LIMIT 200; } { 0 0 1 {SCAN TABLE t301 BY COVERING INDEX t301_c4 (c4=?) (~10 rows)} 0 0 1 {SCAN TABLE t301 BY INTEGER PRIMARY KEY (rowid=?) (~1 rows)} - 0 1 0 {SCAN TABLE t302 BY INDEX t302_c8_c3 (c8=? AND c8>?) (~2 rows)} + 0 1 0 {SCAN TABLE t302 BY INDEX t302_c8_c3 (c8=? AND c3>?) (~2 rows)} 0 0 0 {USE TEMP B-TREE FOR ORDER BY} } finish_test Index: test/where9.test ================================================================== --- test/where9.test +++ test/where9.test @@ -470,11 +470,11 @@ # an OR. # do_execsql_test where9-5.3 { EXPLAIN QUERY PLAN SELECT a FROM t1 WHERE b>1000 AND (c>=31031 OR d IS NULL) } { - 0 0 0 {SCAN TABLE t1 BY INDEX t1b (a>?) (~165000 rows)} + 0 0 0 {SCAN TABLE t1 BY INDEX t1b (b>?) (~165000 rows)} } } ############################################################################ # Make sure OR-clauses work correctly on UPDATE and DELETE statements.