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 #***********************************************************************
13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl
15 set testprefix bestindex6
22 register_tcl_module db
24 proc vtab_command {src method args} {
27 return [db one {SELECT sql FROM sqlite_master where name = $src}]
31 set clist [lindex $args 0]
37 catch { array unset C }
42 SELECT name FROM pragma_table_info($src) WHERE cid=$C(column)
46 lappend wlist "$col IS NULL"
47 lappend ret omit $iCons
50 lappend wlist "$col = %$iCons%"
51 lappend ret omit $iCons
57 #puts "xBestIndex: $ret"
58 lappend ret idxStr [join $wlist " AND "]
63 foreach {idxnum idxstr aa} $args {}
65 for {set iCons 0} {$iCons < [llength $aa]} {incr iCons} {
66 lappend map %$iCons% [lindex $aa $iCons]
69 "SELECT rowid, * FROM $src WHERE [string map $map $idxstr]"
71 # puts "xFilter: $ret"
81 CREATE TABLE t1(id int, value text);
82 CREATE TABLE t2(ctx int, id int, value text);
84 INSERT INTO t1 VALUES(1,'try');
85 INSERT INTO t2 VALUES(1,1,'good');
86 INSERT INTO t2 VALUES(2,2,'evil');
88 CREATE VIRTUAL TABLE vt1 USING tcl(vtab_command t1);
89 CREATE VIRTUAL TABLE vt2 USING tcl(vtab_command t2);
93 select * from t2 left join t1 on t1.id=t2.ctx where t1.value is null;
97 select * from vt2 left join vt1 on vt1.id=vt2.ctx where vt1.value is null;
100 unset -nocomplain xxx
101 do_execsql_test 1.3 {
102 select * from vt2 left join vt1 on vt1.id=vt2.ctx where vt1.value is $xxx;
105 do_execsql_test 1.4 {
106 select * from t2 left join vt1 on vt1.id=t2.ctx where vt1.value = 3