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
19 # There is nothing to test if REINDEX is disable for this build.
21 ifcapable {!reindex} {
26 # Basic sanity checks.
31 INSERT INTO t1 VALUES(1,2);
32 INSERT INTO t1 VALUES(3,4);
33 CREATE INDEX i1 ON t1(a);
37 integrity_check reindex-1.2
43 integrity_check reindex-1.4
49 integrity_check reindex-1.6
64 } {1 {unable to identify the object to be reindexed}}
66 # Set up a table for testing that includes several different collating
67 # sequences including some that we can modify.
71 return [expr {-[string compare $a $b]}]
74 return [expr {-[string compare [string tolower $a] [string tolower $b]]}]
80 a TEXT PRIMARY KEY COLLATE c1,
81 b TEXT UNIQUE COLLATE c2,
82 c TEXT COLLATE nocase,
85 INSERT INTO t2 VALUES('abc','abc','abc','abc');
86 INSERT INTO t2 VALUES('ABCD','ABCD','ABCD','ABCD');
87 INSERT INTO t2 VALUES('bcd','bcd','bcd','bcd');
88 INSERT INTO t2 VALUES('BCDE','BCDE','BCDE','BCDE');
89 SELECT a FROM t2 ORDER BY a;
94 SELECT b FROM t2 ORDER BY b;
99 SELECT c FROM t2 ORDER BY c;
101 } {abc ABCD bcd BCDE}
102 do_test reindex-2.4 {
104 SELECT d FROM t2 ORDER BY d;
106 } {ABCD BCDE abc bcd}
108 # Change a collating sequence function. Verify that REINDEX rebuilds
111 do_test reindex-2.5 {
113 return [string compare $a $b]
116 SELECT a FROM t2 ORDER BY a;
118 } {bcd abc BCDE ABCD}
119 ifcapable {integrityck} {
120 do_test reindex-2.5.1 {
121 string equal ok [execsql {PRAGMA integrity_check}]
124 do_test reindex-2.6 {
127 SELECT a FROM t2 ORDER BY a;
129 } {bcd abc BCDE ABCD}
130 do_test reindex-2.7 {
133 SELECT a FROM t2 ORDER BY a;
135 } {bcd abc BCDE ABCD}
136 do_test reindex-2.8 {
139 SELECT a FROM t2 ORDER BY a;
141 } {ABCD BCDE abc bcd}
142 integrity_check reindex-2.8.1
144 # Try to REINDEX an index for which the collation sequence is not available.
146 do_test reindex-3.1 {
151 } {1 {no such collation sequence: c1}}
152 do_test reindex-3.2 {
153 proc need_collate {collation} {
156 db2 collation_needed need_collate
161 do_test reindex-3.3 {
165 } {1 {no such collation sequence: c2}}
167 do_test reindex-3.99 {