2016-08-09 08:48:40 +03:00
|
|
|
# 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
|
|
|
|
|
2016-09-10 17:43:07 +03:00
|
|
|
ifcapable !vtab {
|
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-08-09 08:48:40 +03:00
|
|
|
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
|
|
|
|
|
2022-02-02 22:15:53 +03:00
|
|
|
set hdl [lindex $args 0]
|
|
|
|
set clist [$hdl constraints]
|
|
|
|
|
2016-08-09 08:48:40 +03:00
|
|
|
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'}}
|
2016-09-06 22:08:21 +03:00
|
|
|
11 "(+a, b) IN (SELECT 'a', 'b')" {{b = 'b'}}
|
|
|
|
12 "(a, +b) IN (SELECT 'a', 'b')" {{a = 'a'}}
|
2016-08-09 08:48:40 +03:00
|
|
|
|
2016-09-06 22:08:21 +03:00
|
|
|
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')" {}
|
2016-08-09 08:48:40 +03:00
|
|
|
} {
|
|
|
|
do_execsql_test 1.$tn "SELECT expr FROM x1 WHERE $where" $res
|
|
|
|
}
|
|
|
|
|
|
|
|
finish_test
|