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.
12 # This file implements tests for the REINDEX command.
14 # $Id: reindex.test,v 1.4 2008/07/12 14:52:20 drh Exp $
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 set testprefix reindex
20 # There is nothing to test if REINDEX is disable for this build.
22 ifcapable {!reindex} {
27 # Basic sanity checks.
32 INSERT INTO t1 VALUES(1,2);
33 INSERT INTO t1 VALUES(3,4);
34 CREATE INDEX i1 ON t1(a);
38 integrity_check reindex-1.2
44 integrity_check reindex-1.4
50 integrity_check reindex-1.6
65 } {1 {unable to identify the object to be reindexed}}
67 # Set up a table for testing that includes several different collating
68 # sequences including some that we can modify.
72 return [expr {-[string compare $a $b]}]
75 return [expr {-[string compare [string tolower $a] [string tolower $b]]}]
81 a TEXT PRIMARY KEY COLLATE c1,
82 b TEXT UNIQUE COLLATE c2,
83 c TEXT COLLATE nocase,
86 INSERT INTO t2 VALUES('abc','abc','abc','abc');
87 INSERT INTO t2 VALUES('ABCD','ABCD','ABCD','ABCD');
88 INSERT INTO t2 VALUES('bcd','bcd','bcd','bcd');
89 INSERT INTO t2 VALUES('BCDE','BCDE','BCDE','BCDE');
90 SELECT a FROM t2 ORDER BY a;
95 SELECT b FROM t2 ORDER BY b;
100 SELECT c FROM t2 ORDER BY c;
102 } {abc ABCD bcd BCDE}
103 do_test reindex-2.4 {
105 SELECT d FROM t2 ORDER BY d;
107 } {ABCD BCDE abc bcd}
109 # Change a collating sequence function. Verify that REINDEX rebuilds
112 do_test reindex-2.5 {
114 return [string compare $a $b]
117 SELECT a FROM t2 ORDER BY a;
119 } {bcd abc BCDE ABCD}
120 ifcapable {integrityck} {
121 do_test reindex-2.5.1 {
122 string equal ok [execsql {PRAGMA integrity_check}]
125 do_test reindex-2.6 {
128 SELECT a FROM t2 ORDER BY a;
130 } {bcd abc BCDE ABCD}
131 do_test reindex-2.7 {
134 SELECT a FROM t2 ORDER BY a;
136 } {bcd abc BCDE ABCD}
137 do_test reindex-2.8 {
140 SELECT a FROM t2 ORDER BY a;
142 } {ABCD BCDE abc bcd}
143 integrity_check reindex-2.8.1
145 # Try to REINDEX an index for which the collation sequence is not available.
147 do_test reindex-3.1 {
152 } {1 {no such collation sequence: c1}}
153 do_test reindex-3.2 {
154 proc need_collate {collation} {
157 db2 collation_needed need_collate
162 do_test reindex-3.3 {
166 } {1 {no such collation sequence: c2}}
168 do_test reindex-3.99 {
172 #-------------------------------------------------------------------------
173 foreach {tn wo} {1 "" 2 "WITHOUT ROWID"} {
175 eval [string map [list %without_rowid% $wo] {
176 do_execsql_test 4.$tn.0 {
178 c0 INTEGER PRIMARY KEY DESC,
179 c1 UNIQUE DEFAULT NULL
181 INSERT INTO t0(c0) VALUES (1), (2), (3), (4), (5);
182 SELECT c0 FROM t0 WHERE c1 IS NULL ORDER BY 1;
185 do_execsql_test 4.$tn.1 {
189 do_execsql_test 4.$tn.2 {
190 SELECT c0 FROM t0 WHERE c1 IS NULL ORDER BY 1;
193 do_execsql_test 4.$tn.3 {
194 SELECT c0 FROM t0 WHERE c1 IS NULL AND c0 IN (1,2,3,4,5);
197 do_execsql_test 4.$tn.4 {
198 PRAGMA integrity_check;