Enhance the command-line completion extension to return the names of
[sqlite.git] / test / rowvalue5.test
blob58b39f2793dd7ce2a3b8b323c80fda6bc5495969
1 # 2016 July 29
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 #***********************************************************************
11 # This file implements regression tests for SQLite library.  The
12 # focus of this file is syntax errors involving row-values and
13 # virtual tables.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 set ::testprefix rowvalue5
20 ifcapable !vtab {
21   finish_test
22   return
25 proc vtab_command {method args} {
26   switch -- $method {
27     xConnect {
28       return "CREATE TABLE t1(a, b, c, d, expr)"
29     }
31     xBestIndex {
32       set COL(0) a
33       set COL(1) b
34       set COL(2) c
35       set COL(3) d
36       set COL(4) expr
38       set OP(eq) =
39       set OP(ne) !=
40       set OP(gt) >
41       set OP(le) <=
42       set OP(lt) <
43       set OP(ge) >=
44       set OP(match) MATCH
45       set OP(like) LIKE
46       set OP(glob) GLOB
47       set OP(regexp) REGEXP
49       set clist [lindex $args 0]
50       set ret [list]
51       set elist [list]
52       set i 0
53       foreach c $clist {
54         array set C $c
55         if {$C(usable)} {
56           lappend ret omit $i
57           lappend elist "$COL($C(column)) $OP($C(op)) %$i%"
58         }
59         incr i
60       }
62       lappend ret idxstr [join $elist " AND "]
63       #puts "xBestIndex: $ret"
64       return $ret
65     }
67     xFilter {
68       foreach {idxnum idxstr arglist} $args {}
69       set i 0
70       set ee $idxstr
71       foreach a $arglist {
72         if {[string is double $a]==0} {
73           set a "'[string map {' ''} $a]'"
74         }
75         set ee [string map [list "%$i%" $a] $ee]
76         incr i
77       }
78       set ee [string map [list "'" "''"] $ee]
80       set ret [list sql "SELECT 1, 'a', 'b', 'c', 'd', '$ee'"]
81       #puts "xFilter: $ret"
82       return $ret
83     }
84   }
86   return {}
89 register_tcl_module db
90 do_execsql_test 1.0 {
91   CREATE VIRTUAL TABLE x1 USING tcl(vtab_command);
92 } {}
95 foreach {tn where res} {
96   1 "1"                              {{}}
97   2 "a=1"                            {{a = 1}}
98   3 "a=1 AND 4 = b"                  {{a = 1 AND b = 4}}
99   4 "c>'hello'"                      {{c > 'hello'}}
100   5 "c<='hel''lo'"                   {{c <= 'hel''lo'}}
101   6 "(a, b) = (SELECT 9, 10)"        {{a = 9 AND b = 10}}
102   7 "(+a, b) = (SELECT 'a', 'b')"    {{b = 'b'}}
103   8 "(a, +b) = (SELECT 'a', 'b')"    {{a = 'a'}}
104   11 "(+a, b) IN (SELECT 'a', 'b')"  {{b = 'b'}}
105   12 "(a, +b) IN (SELECT 'a', 'b')"  {{a = 'a'}}
107   13 "(a, b) < ('d', 'e')"           {{a <= 'd'}}
108   14 "(a, b) < ('a', 'c')"           {{a <= 'a'}}
109   15 "(a, b) <= ('a', 'b')"          {{a <= 'a'}}
110   16 "(a, b) < ('a', 'b')"           {}
111 } {
112   do_execsql_test 1.$tn "SELECT expr FROM x1 WHERE $where" $res
115 finish_test