interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / bestindex7.test

82 lines · 2033 bytes Raw Blame History
1# 2020-01-29
2#
3# The author disclaims copyright to this source code. In place of
4# 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.tcl
15set testprefix bestindex7
16
17ifcapable !vtab {
18 finish_test
19 return
20}
21
22register_tcl_module db
23
24proc vtab_command {src method args} {
25 switch -- $method {
26 xConnect {
27 return "CREATE TABLE xxx(a)"
28 }
29
30 xBestIndex {
31 set hdl [lindex $args 0]
32 set clist [$hdl constraints]
33 set orderby [$hdl orderby]
34 set mask [$hdl mask]
35
36 set iCons 0
37 set ret [list]
38 foreach cons $clist {
39 catch { array unset C }
40 array set C $cons
41 if {$C(usable)} {
42 lappend ret use $iCons
43 }
44 incr iCons
45 }
46 return $ret
47 }
48
49 xFilter {
50 return [list sql "SELECT rowid, x FROM $src"]
51 }
52
53 }
54
55 return {}
56}
57
58do_execsql_test 1.0 {
59 CREATE TABLE t1(x);
60 INSERT INTO t1 VALUES(0), (2);
61 CREATE VIRTUAL TABLE vt1 USING tcl(vtab_command t1);
62}
63
64do_execsql_test 1.1 { select * from vt1 } {0 2}
65do_execsql_test 1.2 { select * from vt1 WHERE a=0 } {0}
66do_execsql_test 1.3 { select * from vt1 WHERE a=1 } {}
67do_execsql_test 1.4 { select * from vt1 WHERE a=1 OR a=0} {0}
68
69do_execsql_test 1.5 {
70 UPDATE t1 SET x=NULL WHERE x=2;
71}
72
73do_execsql_test 1.6 { select * from vt1 } {0 {}}
74do_execsql_test 1.7 { select * from vt1 WHERE a=0 } {0}
75do_execsql_test 1.8 { select * from vt1 WHERE a=1 } {}
76do_execsql_test 1.9 { select * from vt1 WHERE a=1 OR a=0} {0}
77do_execsql_test 1.10 { select * from vt1 WHERE a IN (2) } {}
78do_execsql_test 1.10 { select * from vt1 WHERE a IN (0,1,2,3) } {0}
79do_execsql_test 1.11 { select * from vt1 WHERE a IN (0, NULL) } {0}
80do_execsql_test 1.12 { select * from vt1 WHERE a IN (NULL) } {}
81
82finish_test