AryaWu/sqlite
0
1# 2017-07-152#3# The author disclaims copyright to this source code. In place of4# 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. The12# focus of this file is the "swarmvtab" extension13#14 15set testdir [file dirname $argv0]16source $testdir/tester.tcl17set testprefix swarmvtab218do_not_use_codec19 20ifcapable !vtab {21 finish_test22 return23}24 25 26db close27foreach name [glob -nocomplain test*.db] {28 forcedelete $name29}30sqlite3 db test.db31load_static_extension db unionvtab32proc create_database {filename} {33 sqlite3 dbx $filename34 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<$end42 )43 INSERT INTO t2(a,b) SELECT x, printf('**%05d**',x) FROM c;44 }45 dbx close46}47db func create_database create_database48do_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} {}56do_execsql_test 110 {57 SELECT b FROM v1 WHERE a=3875;58} {**03875**}59do_test 120 {60 lsort [glob -nocomplain test?*.db]61} {test001.db test003.db}62do_execsql_test 130 {63 SELECT b FROM v1 WHERE a BETWEEN 3999 AND 4000 ORDER BY a;64} {**03999** **04000**}65do_test 140 {66 lsort [glob -nocomplain test?*.db]67} {test001.db test003.db test004.db}68do_execsql_test 150 {69 SELECT b FROM v1 WHERE a>=99998;70} {**99998** **99999**}71do_test 160 {72 lsort -dictionary [glob -nocomplain test?*.db]73} {test001.db test003.db test004.db test099.db}74 75finish_test76 