summaryrefslogtreecommitdiffstats
path: root/test/rowvalue5.test
blob: b91dfa49ac7995cc46188ad6da2f6d55c22f076c (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
# 2016 July 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.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is syntax errors involving row-values and
# virtual tables.
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
set ::testprefix rowvalue5

ifcapable !vtab {
  finish_test
  return
}

proc vtab_command {method args} {
  switch -- $method {
    xConnect {
      return "CREATE TABLE t1(a, b, c, d, expr)"
    }

    xBestIndex {
      set COL(0) a
      set COL(1) b
      set COL(2) c
      set COL(3) d
      set COL(4) expr

      set OP(eq) =
      set OP(ne) !=
      set OP(gt) >
      set OP(le) <=
      set OP(lt) <
      set OP(ge) >=
      set OP(match) MATCH
      set OP(like) LIKE
      set OP(glob) GLOB
      set OP(regexp) REGEXP

      set hdl [lindex $args 0]
      set clist [$hdl constraints]

      set ret [list]
      set elist [list]
      set i 0
      foreach c $clist {
        array set C $c
        if {$C(usable)} {
          lappend ret omit $i
          lappend elist "$COL($C(column)) $OP($C(op)) %$i%"
        }
        incr i
      }

      lappend ret idxstr [join $elist " AND "]
      #puts "xBestIndex: $ret"
      return $ret
    }

    xFilter {
      foreach {idxnum idxstr arglist} $args {}
      set i 0
      set ee $idxstr
      foreach a $arglist {
        if {[string is double $a]==0} {
          set a "'[string map {' ''} $a]'"
        }
        set ee [string map [list "%$i%" $a] $ee]
        incr i
      }
      set ee [string map [list "'" "''"] $ee]

      set ret [list sql "SELECT 1, 'a', 'b', 'c', 'd', '$ee'"]
      #puts "xFilter: $ret"
      return $ret
    }
  }

  return {}
}

register_tcl_module db
do_execsql_test 1.0 {
  CREATE VIRTUAL TABLE x1 USING tcl(vtab_command);
} {}


foreach {tn where res} {
  1 "1"                              {{}}
  2 "a=1"                            {{a = 1}}
  3 "a=1 AND 4 = b"                  {{a = 1 AND b = 4}}
  4 "c>'hello'"                      {{c > 'hello'}}
  5 "c<='hel''lo'"                   {{c <= 'hel''lo'}}
  6 "(a, b) = (SELECT 9, 10)"        {{a = 9 AND b = 10}}
  7 "(+a, b) = (SELECT 'a', 'b')"    {{b = 'b'}}
  8 "(a, +b) = (SELECT 'a', 'b')"    {{a = 'a'}}
  11 "(+a, b) IN (SELECT 'a', 'b')"  {{b = 'b'}}
  12 "(a, +b) IN (SELECT 'a', 'b')"  {{a = 'a'}}

  13 "(a, b) < ('d', 'e')"           {{a <= 'd'}}
  14 "(a, b) < ('a', 'c')"           {{a <= 'a'}}
  15 "(a, b) <= ('a', 'b')"          {{a <= 'a'}}
  16 "(a, b) < ('a', 'b')"           {}
} {
  do_execsql_test 1.$tn "SELECT expr FROM x1 WHERE $where" $res
}

finish_test