Index: src/where.c ================================================================== --- src/where.c +++ src/where.c @@ -2224,15 +2224,17 @@ }else{ pRhs = pRhs->x.pList->a[i].pExpr; } /* Check that the LHS of the comparison is a column reference to - ** the right column of the right source table. - */ + ** the right column of the right source table. And that the sort + ** order of the index column is the same as the sort order of the + ** leftmost index column. */ if( pLhs->op!=TK_COLUMN || pLhs->iTable!=iCur || pLhs->iColumn!=pIdx->aiColumn[i+nEq] + || pIdx->aSortOrder[i]!=pIdx->aSortOrder[0] ){ break; } aff = sqlite3CompareAffinity(pRhs, sqlite3ExprAffinity(pLhs)); Index: test/rowvalue3.test ================================================================== --- test/rowvalue3.test +++ test/rowvalue3.test @@ -15,19 +15,10 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl set ::testprefix rowvalue3 -# Drop all auxiliary indexes from the main database opened by handle [db]. -# -proc drop_all_indexes {} { - set L [db eval { - SELECT name FROM sqlite_master WHERE type='index' AND sql LIKE 'create%' - }] - foreach idx $L { db eval "DROP INDEX $idx" } -} - do_execsql_test 1.0 { CREATE TABLE t1(a, b, c); CREATE INDEX i1 ON t1(a, b); INSERT INTO t1 VALUES(1, 2, 3); INSERT INTO t1 VALUES(4, 5, 6); Index: test/rowvalue4.test ================================================================== --- test/rowvalue4.test +++ test/rowvalue4.test @@ -15,11 +15,18 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl set ::testprefix rowvalue4 -do_execsql_test 0 { +#------------------------------------------------------------------------- +# Test some error conditions: +# +# * row values used where they are not supported, +# * row values or sub-selects that contain/return the wrong number +# of elements. +# +do_execsql_test 1.0 { CREATE TABLE t1(a, b, c); CREATE INDEX t1bac ON t1(b, a, c); } foreach {tn e} { @@ -42,7 +49,62 @@ {sub-select returns 3 columns - expected 2} } { do_catchsql_test 2.$tn "$s" [list 1 $error] } +#------------------------------------------------------------------------- +do_execsql_test 2.0 { + CREATE TABLE t2(a, b, c, d); + INSERT INTO t2 VALUES(1, 1, 1, 1); + INSERT INTO t2 VALUES(1, 1, 2, 2); + INSERT INTO t2 VALUES(1, 1, 3, 3); + INSERT INTO t2 VALUES(1, 2, 1, 4); + INSERT INTO t2 VALUES(1, 2, 2, 5); + INSERT INTO t2 VALUES(1, 2, 3, 6); + INSERT INTO t2 VALUES(1, 3, 1, 7); + INSERT INTO t2 VALUES(1, 3, 2, 8); + INSERT INTO t2 VALUES(1, 3, 3, 9); + + INSERT INTO t2 VALUES(2, 1, 1, 10); + INSERT INTO t2 VALUES(2, 1, 2, 11); + INSERT INTO t2 VALUES(2, 1, 3, 12); + INSERT INTO t2 VALUES(2, 2, 1, 13); + INSERT INTO t2 VALUES(2, 2, 2, 14); + INSERT INTO t2 VALUES(2, 2, 3, 15); + INSERT INTO t2 VALUES(2, 3, 1, 16); + INSERT INTO t2 VALUES(2, 3, 2, 17); + INSERT INTO t2 VALUES(2, 3, 3, 18); + + INSERT INTO t2 VALUES(3, 1, 1, 19); + INSERT INTO t2 VALUES(3, 1, 2, 20); + INSERT INTO t2 VALUES(3, 1, 3, 21); + INSERT INTO t2 VALUES(3, 2, 1, 22); + INSERT INTO t2 VALUES(3, 2, 2, 23); + INSERT INTO t2 VALUES(3, 2, 3, 24); + INSERT INTO t2 VALUES(3, 3, 1, 25); + INSERT INTO t2 VALUES(3, 3, 2, 26); + INSERT INTO t2 VALUES(3, 3, 3, 27); +} + +foreach {nm idx} { + idx1 {} + idx2 { CREATE INDEX t2abc ON t2(a, b, c); } + idx3 { CREATE INDEX t2abc ON t2(a, b DESC, c); } + idx4 { CREATE INDEX t2abc ON t2(a DESC, b DESC, c DESC); } + idx5 { CREATE INDEX t2abc ON t2(a ASC, b ASC, c ASC); } + idx6 { CREATE INDEX t2abc ON t2(a DESC, b, c); } +} { + drop_all_indexes + execsql $idx + + foreach {tn where res} { + 1 "(a, b, c) < (2, 2, 2)" {1 2 3 4 5 6 7 8 9 10 11 12 13} + 2 "(a, b, c) <= (2, 2, 2)" {1 2 3 4 5 6 7 8 9 10 11 12 13 14} + 3 "(a, b, c) > (2, 2, 2)" {15 16 17 18 19 20 21 22 23 24 25 26 27} + 4 "(a, b, c) >= (2, 2, 2)" {14 15 16 17 18 19 20 21 22 23 24 25 26 27} + } { + set result [db eval "SELECT d FROM t2 WHERE $where"] + do_test 2.$nm.$tn { lsort -integer $result } $res + } +} finish_test Index: test/tester.tcl ================================================================== --- test/tester.tcl +++ test/tester.tcl @@ -23,10 +23,11 @@ # test_pwd # get_pwd # copy_file FROM TO # delete_file FILENAME # drop_all_tables ?DB? +# drop_all_indexes ?DB? # forcecopy FROM TO # forcedelete FILENAME # # Test the capability of the SQLite version built into the interpreter to # determine if a specific test can be run: @@ -1948,10 +1949,20 @@ } ifcapable trigger&&foreignkey { $db eval "PRAGMA foreign_keys = $pk" } } + +# Drop all auxiliary indexes from the main database opened by handle [db]. +# +proc drop_all_indexes {{db db}} { + set L [$db eval { + SELECT name FROM sqlite_master WHERE type='index' AND sql LIKE 'create%' + }] + foreach idx $L { $db eval "DROP INDEX $idx" } +} + #------------------------------------------------------------------------- # If a test script is executed with global variable $::G(perm:name) set to # "wal", then the tests are run in WAL mode. Otherwise, they should be run # in rollback mode. The following Tcl procs are used to make this less