| 1 |
# 2017-07-15 |
| 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 the "swarmvtab" extension |
| 13 |
# |
| 14 |
|
| 15 |
set testdir [file dirname $argv0] |
| 16 |
source $testdir/tester.tcl |
| 17 |
set testprefix swarmvtab2 |
| 18 |
do_not_use_codec |
| 19 |
|
| 20 |
ifcapable !vtab { |
| 21 |
finish_test |
| 22 |
return |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
db close |
| 27 |
foreach name [glob -nocomplain test*.db] { |
| 28 |
forcedelete $name |
| 29 |
} |
| 30 |
sqlite3 db test.db |
| 31 |
load_static_extension db unionvtab |
| 32 |
proc create_database {filename} { |
| 33 |
sqlite3 dbx $filename |
| 34 |
set num [regsub -all {[^0-9]+} $filename {}] |
| 35 |
set num [string trimleft $num 0] |
| 36 |
set start [expr {$num*1000}] |
| 37 |
set end [expr {$start+999}] |
| 38 |
dbx eval { |
| 39 |
CREATE TABLE t2(a INTEGER PRIMARY KEY,b); |
| 40 |
WITH RECURSIVE c(x) AS ( |
| 41 |
VALUES($start) UNION ALL SELECT x+1 FROM c WHERE x<$end |
| 42 |
) |
| 43 |
INSERT INTO t2(a,b) SELECT x, printf('**%05d**',x) FROM c; |
| 44 |
} |
| 45 |
dbx close |
| 46 |
} |
| 47 |
db func create_database create_database |
| 48 |
do_execsql_test 100 { |
| 49 |
CREATE TABLE t1(filename, tablename, istart, iend); |
| 50 |
WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<99) |
| 51 |
INSERT INTO t1 SELECT printf('test%03d.db',x),'t2',x*1000,x*1000+999 FROM c; |
| 52 |
CREATE VIRTUAL TABLE temp.v1 USING swarmvtab( |
| 53 |
'SELECT * FROM t1', 'create_database' |
| 54 |
); |
| 55 |
} {} |
| 56 |
do_execsql_test 110 { |
| 57 |
SELECT b FROM v1 WHERE a=3875; |
| 58 |
} {**03875**} |
| 59 |
do_test 120 { |
| 60 |
lsort [glob -nocomplain test?*.db] |
| 61 |
} {test001.db test003.db} |
| 62 |
do_execsql_test 130 { |
| 63 |
SELECT b FROM v1 WHERE a BETWEEN 3999 AND 4000 ORDER BY a; |
| 64 |
} {**03999** **04000**} |
| 65 |
do_test 140 { |
| 66 |
lsort [glob -nocomplain test?*.db] |
| 67 |
} {test001.db test003.db test004.db} |
| 68 |
do_execsql_test 150 { |
| 69 |
SELECT b FROM v1 WHERE a>=99998; |
| 70 |
} {**99998** **99999**} |
| 71 |
do_test 160 { |
| 72 |
lsort -dictionary [glob -nocomplain test?*.db] |
| 73 |
} {test001.db test003.db test004.db test099.db} |
| 74 |
|
| 75 |
finish_test |