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 hdl [lindex $args 0]
32 set clist [$hdl constraints]
33 set orderby [$hdl orderby]
41 catch { array unset C }
46 SELECT name FROM pragma_table_info($src) WHERE cid=$C(column)
50 lappend wlist "$col IS NULL"
51 lappend ret omit $iCons
54 lappend wlist "$col = %$iCons%"
55 lappend ret omit $iCons
61 #puts "xBestIndex: $ret"
62 lappend ret idxStr [join $wlist " AND "]
67 foreach {idxnum idxstr aa} $args {}
69 for {set iCons 0} {$iCons < [llength $aa]} {incr iCons} {
70 lappend map %$iCons% [lindex $aa $iCons]
73 "SELECT rowid, * FROM $src WHERE [string map $map $idxstr]"
75 # puts "xFilter: $ret"
85 CREATE TABLE t1(id int, value text);
86 CREATE TABLE t2(ctx int, id int, value text);
88 INSERT INTO t1 VALUES(1,'try');
89 INSERT INTO t2 VALUES(1,1,'good');
90 INSERT INTO t2 VALUES(2,2,'evil');
92 CREATE VIRTUAL TABLE vt1 USING tcl(vtab_command t1);
93 CREATE VIRTUAL TABLE vt2 USING tcl(vtab_command t2);
97 select * from t2 left join t1 on t1.id=t2.ctx where t1.value is null;
100 do_execsql_test 1.2 {
101 select * from vt2 left join vt1 on vt1.id=vt2.ctx where vt1.value is null;
104 unset -nocomplain xxx
105 do_execsql_test 1.3 {
106 select * from vt2 left join vt1 on vt1.id=vt2.ctx where vt1.value is $xxx;
109 do_execsql_test 1.4 {
110 select * from t2 left join vt1 on vt1.id=t2.ctx where vt1.value = 3