AryaWu/sqlite
0
1# 2020-01-292#3# The author disclaims copyright to this source code. In place of4# a legal notice, here is a blessing:5#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.9#10#***********************************************************************11# 12 13set testdir [file dirname $argv0]14source $testdir/tester.tcl15set testprefix bestindexA16 17ifcapable !vtab {18 finish_test19 return20}21 22 23proc vtab_command {method args} {24 switch -- $method {25 xConnect {26 return "CREATE TABLE x(a, b, c)"27 }28 29 xBestIndex {30 set hdl [lindex $args 0]31 set clist [$hdl constraints]32 foreach c $clist {33 array set C $c34 lappend ::vtab_constraints [list $C(op) $C(column)]35 }36 return [list]37 }38 39 xFilter {40 return ""41 }42 43 xFindFunction {44 foreach {nArg name} $args {}45 if {$nArg==2 && $name=="even"} { 46 return 152 47 }48 return 049 }50 51 }52 53 return {}54}55 56register_tcl_module db57do_execsql_test 1.0 {58 CREATE VIRTUAL TABLE t1 USING tcl(vtab_command);59}60 61proc do_xbestindex_test {tn sql res} {62 set script [subst {63 execsql "$sql"64 set ::vtab_constraints65 }]66 67 uplevel [list do_test $tn $script [list {*}$res]]68 set ::vtab_constraints [list]69}70 71do_xbestindex_test 1.1 {72 SELECT * FROM t1 WHERE a=?73} {74 {eq 0}75}76 77do_xbestindex_test 1.2 {78 SELECT * FROM t1 WHERE a=? LIMIT 1079} {80 {eq 0}81 {limit 0}82}83 84do_xbestindex_test 1.3 {85 SELECT * FROM t1 WHERE a=? AND (b+1)=? LIMIT 1086} {87 {eq 0}88}89 90proc error_function {args} { error "not a function!" }91db function even error_function92 93do_xbestindex_test 1.4 {94 SELECT * FROM t1 WHERE even(a, ?)95} {96 {152 0}97}98 99do_xbestindex_test 1.5 {100 SELECT * FROM t1 WHERE b=10 AND even(a, ?)101} {102 {eq 1}103 {152 0}104}105 106do_xbestindex_test 1.6 {107 SELECT * FROM t1 WHERE b=10 LIMIT 10108} {109 {eq 1}110 {limit 0}111}112 113do_xbestindex_test 1.7 {114 SELECT * FROM t1 WHERE even(b,?) LIMIT 10115} {116 {152 1}117 {limit 0}118}119 120do_xbestindex_test 1.8 {121 SELECT * FROM t1 WHERE b!=? LIMIT 10122} {123 {ne 1}124 {limit 0}125}126 127do_xbestindex_test 1.9 {128 SELECT * FROM t1 WHERE ?=a LIMIT 10129} {130 {eq 0}131 {limit 0}132}133 134 135finish_test136 