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