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 sqlite_temp_master
48 } {table ia1 table ia2 table ia3 table ia4}
50 do_test intarray-1.2 {
52 SELECT b FROM t1 WHERE a IN ia3 ORDER BY a
56 do_test intarray-1.3 {
57 sqlite3_intarray_bind $ia3 45 123 678
59 SELECT b FROM t1 WHERE a IN ia3 ORDER BY a
63 do_test intarray-1.4 {
65 SELECT count(b) FROM t1 WHERE a NOT IN ia3 ORDER BY a
69 #explain {SELECT b FROM t1 WHERE a NOT IN ia3}
71 do_test intarray-1.5 {
72 set cmd sqlite3_intarray_bind
74 for {set i 1} {$i<=999} {incr i} {
76 lappend cmd [expr {$i+1000}]
77 lappend cmd [expr {$i+2000}]
81 REPLACE INTO t1 SELECT * FROM t2;
82 DELETE FROM t1 WHERE a NOT IN ia1;
83 SELECT count(*) FROM t1;
87 do_test intarray-1.6 {
89 DELETE FROM t1 WHERE a IN ia1;
90 SELECT count(*) FROM t1;
94 do_test intarray-2.1 {
96 CREATE TEMP TABLE t3(p,q);
97 INSERT INTO t3 SELECT * FROM t2;
98 SELECT count(*) FROM t3 WHERE p IN ia1;
102 do_test intarray-2.2 {
103 set ia5 [sqlite3_intarray_create db ia5]
105 SELECT count(*) FROM t3 WHERE p IN ia1;