3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file implements tests for the "intarray" object implemented
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
24 do_test intarray-1.0 {
26 CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
28 for {set i 1} {$i<=999} {incr i} {
29 set b [format {x%03d} $i]
30 db eval {INSERT INTO t1(a,b) VALUES($i,$b)}
33 CREATE TABLE t2(x INTEGER PRIMARY KEY, y);
34 INSERT INTO t2 SELECT * FROM t1;
35 SELECT b FROM t1 WHERE a IN (12,34,56,78) ORDER BY a
37 } {x012 x034 x056 x078}
39 do_test intarray-1.1 {
40 set ia1 [sqlite3_intarray_create db ia1]
41 set ia2 [sqlite3_intarray_create db ia2]
42 set ia3 [sqlite3_intarray_create db ia3]
43 set ia4 [sqlite3_intarray_create db ia4]
45 SELECT type, name FROM temp.sqlite_master
48 } {table ia1 table ia2 table ia3 table ia4}
50 # Verify the ability to DROP and recreate an intarray virtual table.
51 do_test intarray-1.1b {
52 db eval {DROP TABLE ia1}
53 set rc [catch {sqlite3_intarray_create db ia1} ia1]
57 do_test intarray-1.2 {
59 SELECT b FROM t1 WHERE a IN ia3 ORDER BY a
63 do_test intarray-1.3 {
64 sqlite3_intarray_bind $ia3 45 123 678
66 SELECT b FROM t1 WHERE a IN ia3 ORDER BY a
70 do_test intarray-1.4 {
72 SELECT count(b) FROM t1 WHERE a NOT IN ia3 ORDER BY a
76 #explain {SELECT b FROM t1 WHERE a NOT IN ia3}
78 do_test intarray-1.5 {
79 set cmd sqlite3_intarray_bind
81 for {set i 1} {$i<=999} {incr i} {
83 lappend cmd [expr {$i+1000}]
84 lappend cmd [expr {$i+2000}]
88 REPLACE INTO t1 SELECT * FROM t2;
89 DELETE FROM t1 WHERE a NOT IN ia1;
90 SELECT count(*) FROM t1;
94 do_test intarray-1.6 {
96 DELETE FROM t1 WHERE a IN ia1;
97 SELECT count(*) FROM t1;
101 do_test intarray-2.1 {
103 CREATE TEMP TABLE t3(p,q);
104 INSERT INTO t3 SELECT * FROM t2;
105 SELECT count(*) FROM t3 WHERE p IN ia1;
109 do_test intarray-2.2 {
110 set ia5 [sqlite3_intarray_create db ia5]
112 SELECT count(*) FROM t3 WHERE p IN ia1;