namespace changes and fixes for non-amalgamated builds
[sqlcipher.git] / test / bestindex7.test
blobf8d42b2b006c6334de6569f5118c2f7bbdf8fe49
1 # 2020-01-29
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
6 #    May you do good and not evil.
7 #    May you find forgiveness for yourself and forgive others.
8 #    May you share freely, never taking more than you give.
10 #***********************************************************************
11
13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl
15 set testprefix bestindex7
17 ifcapable !vtab {
18   finish_test
19   return
22 register_tcl_module db
24 proc vtab_command {src method args} {
25   switch -- $method {
26     xConnect {
27       return "CREATE TABLE xxx(a)"
28     }
30     xBestIndex {
31       set clist [lindex $args 0]
32       set iCons 0
33       set ret [list]
34       foreach cons $clist {
35         catch { array unset C }
36         array set C $cons
37         if {$C(usable)} {
38           lappend ret use $iCons
39         }
40         incr iCons
41       }
42       return $ret
43     }
45     xFilter {
46       return [list sql "SELECT rowid, x FROM $src"]
47     }
49   }
51   return {}
54 do_execsql_test 1.0 {
55   CREATE TABLE t1(x);
56   INSERT INTO t1 VALUES(0), (2);
57   CREATE VIRTUAL TABLE vt1 USING tcl(vtab_command t1);
60 do_execsql_test 1.1 { select * from vt1 } {0 2}
61 do_execsql_test 1.2 { select * from vt1 WHERE a=0 } {0}
62 do_execsql_test 1.3 { select * from vt1 WHERE a=1 } {}
63 do_execsql_test 1.4 { select * from vt1 WHERE a=1 OR a=0} {0}
65 do_execsql_test 1.5 {
66   UPDATE t1 SET x=NULL WHERE x=2;
69 do_execsql_test 1.6 { select * from vt1 } {0 {}}
70 do_execsql_test 1.7 { select * from vt1 WHERE a=0 } {0}
71 do_execsql_test 1.8 { select * from vt1 WHERE a=1 } {}
72 do_execsql_test 1.9 { select * from vt1 WHERE a=1 OR a=0} {0}
73 do_execsql_test 1.10 { select * from vt1 WHERE a IN (2) } {}
74 do_execsql_test 1.10 { select * from vt1 WHERE a IN (0,1,2,3) } {0}
75 do_execsql_test 1.11 { select * from vt1 WHERE a IN (0, NULL) } {0}
76 do_execsql_test 1.12 { select * from vt1 WHERE a IN (NULL) } {}
78 finish_test