mirror of
https://github.com/tursodatabase/libsql.git
synced 2024-11-23 12:06:16 +00:00
136 lines
3.4 KiB
Plaintext
136 lines
3.4 KiB
Plaintext
# 2018 October 14
|
|
#
|
|
# 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.
|
|
#
|
|
#***********************************************************************
|
|
#
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
source $testdir/tester.tcl
|
|
set ::testprefix rowvaluevtab
|
|
|
|
ifcapable !vtab {
|
|
finish_test
|
|
return
|
|
}
|
|
|
|
register_echo_module db
|
|
|
|
#############
|
|
# Test echo
|
|
#############
|
|
|
|
do_execsql_test 1.0 {
|
|
CREATE TABLE t1(a, b, c);
|
|
CREATE INDEX t1b ON t1(b);
|
|
INSERT INTO t1 VALUES('one', 1, 1);
|
|
INSERT INTO t1 VALUES('two', 1, 2);
|
|
INSERT INTO t1 VALUES('three', 1, 3);
|
|
INSERT INTO t1 VALUES('four', 2, 1);
|
|
INSERT INTO t1 VALUES('five', 2, 2);
|
|
INSERT INTO t1 VALUES('six', 2, 3);
|
|
INSERT INTO t1 VALUES('seven', 3, 1);
|
|
INSERT INTO t1 VALUES('eight', 3, 2);
|
|
INSERT INTO t1 VALUES('nine', 3, 3);
|
|
|
|
WITH s(i) AS (
|
|
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<10000
|
|
) INSERT INTO t1 SELECT NULL, NULL, NULL FROM s;
|
|
CREATE VIRTUAL TABLE e1 USING echo(t1);
|
|
}
|
|
|
|
proc do_vfilter4_test {tn sql expected} {
|
|
set res [list]
|
|
db eval "explain $sql" {
|
|
if {$opcode=="VFilter"} {
|
|
lappend res $p4
|
|
}
|
|
}
|
|
uplevel [list do_test $tn [list set {} $res] [list {*}$expected]]
|
|
}
|
|
|
|
do_execsql_test 1.1 {
|
|
SELECT a FROM e1 WHERE (b, c) = (2, 2)
|
|
} {five}
|
|
do_vfilter4_test 1.1f {
|
|
SELECT a FROM e1 WHERE (b, c) = (?, ?)
|
|
} {{SELECT rowid, a, b, c FROM 't1' WHERE b = ?}}
|
|
|
|
do_execsql_test 1.2 {
|
|
SELECT a FROM e1 WHERE (b, c) > (2, 2)
|
|
} {six seven eight nine}
|
|
do_vfilter4_test 1.2f {
|
|
SELECT a FROM e1 WHERE (b, c) > (2, 2)
|
|
} {
|
|
{SELECT rowid, a, b, c FROM 't1' WHERE b >= ?}
|
|
}
|
|
|
|
do_execsql_test 1.3 {
|
|
SELECT a FROM e1 WHERE (b, c) >= (2, 2)
|
|
} {five six seven eight nine}
|
|
do_vfilter4_test 1.3f {
|
|
SELECT a FROM e1 WHERE (b, c) >= (2, 2)
|
|
} {
|
|
{SELECT rowid, a, b, c FROM 't1' WHERE b >= ?}
|
|
}
|
|
|
|
do_execsql_test 1.3 {
|
|
SELECT a FROM e1 WHERE (b, c) BETWEEN (1, 2) AND (2, 3)
|
|
} {two three four five six}
|
|
do_vfilter4_test 1.3f {
|
|
SELECT a FROM e1 WHERE (b, c) BETWEEN (1, 2) AND (2, 3)
|
|
} {
|
|
{SELECT rowid, a, b, c FROM 't1' WHERE b >= ? AND b <= ?}
|
|
}
|
|
|
|
do_execsql_test 1.4 {
|
|
SELECT a FROM e1 WHERE (b, c) IN ( VALUES(2, 2) )
|
|
} {five}
|
|
do_vfilter4_test 1.4f {
|
|
SELECT a FROM e1 WHERE (b, c) IN ( VALUES(2, 2) )
|
|
} {{SELECT rowid, a, b, c FROM 't1' WHERE b = ?}}
|
|
|
|
#######################################################################
|
|
# Test echo_v2. We simply want to ensure that OP_VPreparedSql executes
|
|
#######################################################################
|
|
|
|
do_execsql_test 2.0 {
|
|
CREATE TABLE t2(a, b, c);
|
|
CREATE INDEX t2b ON t2(b);
|
|
INSERT INTO t2 VALUES('one', 1, 1);
|
|
INSERT INTO t2 VALUES('two', 1, 2);
|
|
INSERT INTO t2 VALUES('three', 1, 3);
|
|
|
|
WITH s(i) AS (
|
|
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<10000
|
|
) INSERT INTO t2 SELECT NULL, NULL, NULL FROM s;
|
|
CREATE VIRTUAL TABLE e2 USING echo_v2(t2);
|
|
}
|
|
|
|
proc do_vpreparedsql1_test {tn sql expected} {
|
|
set rc -1
|
|
db eval "explain $sql" {
|
|
if {$opcode=="VPreparedSql"} {
|
|
set rc 0
|
|
}
|
|
}
|
|
if {$rc != $expected} {
|
|
error "Unexpected result $rc, was hoping for $expected"
|
|
}
|
|
}
|
|
|
|
do_execsql_test 2.1 {
|
|
SELECT a FROM e2 WHERE (b, c) IN ( VALUES(1, 3) )
|
|
} {three}
|
|
do_vpreparedsql1_test 2.1f {
|
|
SELECT a FROM e2 WHERE (b, c) IN ( VALUES(2, 2) )
|
|
} {0}
|
|
|
|
finish_test
|