# 2017-07-15 # # 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 the "swarmvtab" extension # set testdir [file dirname $argv0] source $testdir/tester.tcl set testprefix swarmvtab ifcapable !vtab { finish_test return } load_static_extension db unionvtab set nFile $sqlite_open_file_count do_execsql_test 1.0 { CREATE TABLE t0(a INTEGER PRIMARY KEY, b TEXT); WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<400) INSERT INTO t0 SELECT i, hex(randomblob(50)) FROM s; CREATE TABLE dir(f, t, imin, imax); } do_test 1.1 { for {set i 0} {$i < 40} {incr i} { set iMin [expr $i*10 + 1] set iMax [expr $iMin+9] forcedelete "test.db$i" execsql [subst { ATTACH 'test.db$i' AS aux; CREATE TABLE aux.t$i (a INTEGER PRIMARY KEY, b TEXT); INSERT INTO aux.t$i SELECT * FROM t0 WHERE a BETWEEN $iMin AND $iMax; DETACH aux; INSERT INTO dir VALUES('test.db$i', 't$i', $iMin, $iMax); }] } execsql { CREATE VIRTUAL TABLE temp.s1 USING swarmvtab('SELECT * FROM dir'); } } {} do_execsql_test 1.2 { DROP TABLE s1; } {} do_execsql_test 1.3 { CREATE VIRTUAL TABLE temp.s1 USING swarmvtab('SELECT * FROM dir'); SELECT count(*) FROM s1 WHERE rowid<50; } {49} proc do_compare_test {tn where} { set sql [subst { SELECT ( SELECT group_concat(a || ',' || b, ',') FROM t0 WHERE $where ) IS ( SELECT group_concat(a || ',' || b, ',') FROM s1 WHERE $where ) }] uplevel [list do_execsql_test $tn $sql 1] } do_compare_test 1.4 "rowid = 55" do_compare_test 1.5 "rowid BETWEEN 20 AND 100" do_compare_test 1.6 "rowid > 350" do_compare_test 1.7 "rowid >= 350" do_compare_test 1.8 "rowid >= 200" do_compare_test 1.9 "1" do_compare_test 1.10 "rowid = 700" do_compare_test 1.11 "rowid = -1" do_compare_test 1.12 "rowid = 0" do_test 1.x { set sqlite_open_file_count } [expr $nFile+9] do_test 1.y { db close } {} finish_test