The first assert() added in [0ebc65481f4a3e79] is not necessarily true in a
[sqlite.git] / test / bestindexA.test
blob1976986471947e2497bb7265a48cfc76f2d05908
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 bestindexA
17 ifcapable !vtab {
18   finish_test
19   return
23 proc vtab_command {method args} {
24   switch -- $method {
25     xConnect {
26       return "CREATE TABLE x(a, b, c)"
27     }
29     xBestIndex {
30       set hdl [lindex $args 0]
31       set clist [$hdl constraints]
32       foreach c $clist {
33         array set C $c
34         lappend ::vtab_constraints [list $C(op) $C(column)]
35       }
36       return [list]
37     }
39     xFilter {
40       return ""
41     }
43     xFindFunction {
44       foreach {nArg name} $args {}
45       if {$nArg==2 && $name=="even"} { 
46         return 152 
47       }
48       return 0
49     }
51   }
53   return {}
56 register_tcl_module db
57 do_execsql_test 1.0 {
58   CREATE VIRTUAL TABLE t1 USING tcl(vtab_command);
61 proc do_xbestindex_test {tn sql res} {
62   set script [subst {
63     execsql "$sql"
64     set ::vtab_constraints
65   }]
67   uplevel [list do_test $tn $script [list {*}$res]]
68   set ::vtab_constraints [list]
71 do_xbestindex_test 1.1 {
72   SELECT * FROM t1 WHERE a=?
73 } {
74   {eq 0}
77 do_xbestindex_test 1.2 {
78   SELECT * FROM t1 WHERE a=? LIMIT 10
79 } {
80   {eq 0}
81   {limit 0}
84 do_xbestindex_test 1.3 {
85   SELECT * FROM t1 WHERE a=? AND (b+1)=? LIMIT 10
86 } {
87   {eq 0}
90 proc error_function {args} { error "not a function!" }
91 db function even error_function
93 do_xbestindex_test 1.4 {
94   SELECT * FROM t1 WHERE even(a, ?)
95 } {
96   {152 0}
99 do_xbestindex_test 1.5 {
100   SELECT * FROM t1 WHERE b=10 AND even(a, ?)
101 } {
102   {eq 1}
103   {152 0}
106 do_xbestindex_test 1.6 {
107   SELECT * FROM t1 WHERE b=10 LIMIT 10
108 } {
109   {eq 1}
110   {limit 0}
113 do_xbestindex_test 1.7 {
114   SELECT * FROM t1 WHERE even(b,?) LIMIT 10
115 } {
116   {152 1}
117   {limit 0}
120 do_xbestindex_test 1.8 {
121   SELECT * FROM t1 WHERE b!=? LIMIT 10
122 } {
123   {ne 1}
124   {limit 0}
127 do_xbestindex_test 1.9 {
128   SELECT * FROM t1 WHERE ?=a LIMIT 10
129 } {
130   {eq 0}
131   {limit 0}
135 finish_test