blob: 1976986471947e2497bb7265a48cfc76f2d05908 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# 2020-01-29
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix bestindexA
ifcapable !vtab {
finish_test
return
}
proc vtab_command {method args} {
switch -- $method {
xConnect {
return "CREATE TABLE x(a, b, c)"
}
xBestIndex {
set hdl [lindex $args 0]
set clist [$hdl constraints]
foreach c $clist {
array set C $c
lappend ::vtab_constraints [list $C(op) $C(column)]
}
return [list]
}
xFilter {
return ""
}
xFindFunction {
foreach {nArg name} $args {}
if {$nArg==2 && $name=="even"} {
return 152
}
return 0
}
}
return {}
}
register_tcl_module db
do_execsql_test 1.0 {
CREATE VIRTUAL TABLE t1 USING tcl(vtab_command);
}
proc do_xbestindex_test {tn sql res} {
set script [subst {
execsql "$sql"
set ::vtab_constraints
}]
uplevel [list do_test $tn $script [list {*}$res]]
set ::vtab_constraints [list]
}
do_xbestindex_test 1.1 {
SELECT * FROM t1 WHERE a=?
} {
{eq 0}
}
do_xbestindex_test 1.2 {
SELECT * FROM t1 WHERE a=? LIMIT 10
} {
{eq 0}
{limit 0}
}
do_xbestindex_test 1.3 {
SELECT * FROM t1 WHERE a=? AND (b+1)=? LIMIT 10
} {
{eq 0}
}
proc error_function {args} { error "not a function!" }
db function even error_function
do_xbestindex_test 1.4 {
SELECT * FROM t1 WHERE even(a, ?)
} {
{152 0}
}
do_xbestindex_test 1.5 {
SELECT * FROM t1 WHERE b=10 AND even(a, ?)
} {
{eq 1}
{152 0}
}
do_xbestindex_test 1.6 {
SELECT * FROM t1 WHERE b=10 LIMIT 10
} {
{eq 1}
{limit 0}
}
do_xbestindex_test 1.7 {
SELECT * FROM t1 WHERE even(b,?) LIMIT 10
} {
{152 1}
{limit 0}
}
do_xbestindex_test 1.8 {
SELECT * FROM t1 WHERE b!=? LIMIT 10
} {
{ne 1}
{limit 0}
}
do_xbestindex_test 1.9 {
SELECT * FROM t1 WHERE ?=a LIMIT 10
} {
{eq 0}
{limit 0}
}
finish_test
|