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 #***********************************************************************
12 # The focus of this file is testing the incremental integrity check
16 source [file join [file dirname [info script]] intck_common.tcl]
20 1 "CREATE TABLE t1(a PRIMARY KEY, b)"
21 2 "CREATE TABLE t2(a PRIMARY KEY, b) WITHOUT ROWID "
22 3 "CREATE TABLE t3(a PRIMARY KEY, b) WITHOUT rowID;"
23 4 "CREATE TABLE t4(a PRIMARY KEY, ROWID)"
24 5 {CREATE TABLE t5(a PRIMARY KEY, ROWID) WITHOUT ROWID
33 set space " \n\v\t\r\f"
36 SELECT name, (rtrim(sql, $space) LIKE '%rowid')
37 FROM sqlite_schema WHERE type='table'
48 CREATE TABLE x1(a COLLATE nocase, b INTEGER, c BLOB);
49 INSERT INTO x1 VALUES('lEtTeRs', 1234, 1234);
51 do_execsql_test 1.3.1 {
52 WITH wrapper(c1, c2, c3) AS (
53 SELECT a, b, c FROM x1
55 SELECT * FROM wrapper WHERE c1='letters';
57 do_execsql_test 1.3.2 {
58 WITH wrapper(c1, c2, c3) AS (
59 SELECT a, b, c FROM x1
61 SELECT * FROM wrapper WHERE c2='1234';
63 do_execsql_test 1.3.2 {
64 WITH wrapper(c1, c2, c3) AS (
65 SELECT a, b, c FROM x1
67 SELECT * FROM wrapper WHERE c3='1234';
71 CREATE TABLE z1(a, b);
72 CREATE INDEX z1ab ON z1(a+b COLLATE nocase);
74 do_execsql_test 1.4.1 {
75 SELECT * FROM z1 INDEXED BY z1ab
78 do_catchsql_test 1.5.1 {
79 CREATE INDEX z1b ON z1(b ASC NULLS LAST);
80 } {1 {unsupported use of NULLS LAST}}
81 do_catchsql_test 1.5.2 {
82 CREATE INDEX z1b ON z1(b DESC NULLS LAST);
83 } {1 {unsupported use of NULLS LAST}}
84 do_catchsql_test 1.5.3 {
85 CREATE INDEX z1b ON z1(b ASC NULLS FIRST);
86 } {1 {unsupported use of NULLS FIRST}}
87 do_catchsql_test 1.5.4 {
88 CREATE INDEX z1b ON z1(b DESC NULLS FIRST);
89 } {1 {unsupported use of NULLS FIRST}}
93 do_execsql_test 1.6.1 {
94 CREATE TABLE t1(i INTEGER PRIMARY KEY, b, c);
95 CREATE INDEX i1 ON t1(b);
97 INSERT INTO sqlite_stat1 VALUES('t1', 'i1', '10000 10000');
98 ANALYZE sqlite_schema;
101 SELECT 1 FROM t1 INDEXED BY i1 WHERE (b, i) IS (?, ?);
106 #-------------------------------------------------------------------------
110 set ic [sqlite3_intck db main]
114 do_execsql_test 2.1 {
115 CREATE TABLE t1(a, b);
116 INSERT INTO t1 VALUES(1, 2);
117 INSERT INTO t1 VALUES(3, 4);
119 CREATE INDEX i1 ON t1(a COLLATE nocase);
120 CREATE INDEX i2 ON t1(b, a);
121 CREATE INDEX i3 ON t1(b + a COLLATE nocase) WHERE a!=1;
127 # Delete a row from each of the i1 and i2 indexes using the imposter
131 db eval {SELECT name, rootpage FROM sqlite_schema} {
132 set R($name) $rootpage
134 sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 1 $R(i1)
135 db eval { CREATE TABLE imp1(a PRIMARY KEY, rowid) WITHOUT ROWID; }
136 sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 1 $R(i2)
137 db eval { CREATE TABLE imp2(b, a, rowid, PRIMARY KEY(b, a)) WITHOUT ROWID; }
138 sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 0
141 DELETE FROM imp1 WHERE rowid=1;
142 DELETE FROM imp2 WHERE rowid=2;
150 {entry (1,1) missing from index i1}
151 {entry (4,3,2) missing from index i2}
154 #-------------------------------------------------------------------------
156 do_execsql_test 3.0 {
157 CREATE TABLE x1(a, b, c, PRIMARY KEY(c, b)) WITHOUT ROWID;
158 CREATE INDEX x1a ON x1(a COLLATE nocase);
160 INSERT INTO x1 VALUES(1, 2, 'three');
161 INSERT INTO x1 VALUES(4, 5, 'six');
162 INSERT INTO x1 VALUES(7, 8, 'nine');
165 do_intck_test 3.1 { }
168 db eval {SELECT name, rootpage FROM sqlite_schema} {
169 set R($name) $rootpage
171 sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 1 $R(x1a)
172 db eval { CREATE TABLE imp1(c, b, a, PRIMARY KEY(c, b)) WITHOUT ROWID }
173 sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 0
176 DELETE FROM imp1 WHERE a=5;
186 {entry (4,'six',5) missing from index x1a}
189 #-------------------------------------------------------------------------
191 do_execsql_test 4.0 {
192 CREATE TABLE www(x, y, z);
193 CREATE INDEX w1 ON www( (x+1), z );
194 INSERT INTO www VALUES(1, 1, 1), (2, 2, 2);
197 do_intck_test 4.1 { }
199 #-------------------------------------------------------------------------
201 do_execsql_test 5.0 {
202 CREATE TABLE t1(a, b);
203 CREATE INDEX i1 ON t1(a COLLATE NOCASE);
204 INSERT INTO t1 VALUES(1, 1);
205 INSERT INTO t1 VALUES(2, 2);
209 set ic [sqlite3_intck db nosuchdb]
215 set ic [sqlite3_intck db {}]
216 while {[$ic step]=="SQLITE_OK"} {}
222 do_test 5.3 { test_do_intck db "main" } {}
226 set ic [sqlite3_intck db main]
227 db eval [$ic test_sql t1] {
228 if {$error_message!=""} { lappend ret $error_message }
236 set ic [sqlite3_intck db main]
237 db eval [$ic test_sql {}] {
238 if {$error_message!=""} { lappend ret $error_message }
248 set ic [sqlite3_intck db main]
250 db eval [$ic test_sql {}] {
251 if {$error_message!=""} { lappend ret $error_message }
257 #-------------------------------------------------------------------------
260 do_execsql_test 6.0 {
261 CREATE TABLE t1(x, y, PRIMARY KEY(x)) WITHOUT ROWID;
262 CREATE INDEX i1 ON t1(y, x);
263 INSERT INTO t1 VALUES(X'0000', X'1111');
268 do_execsql_test 6.2.1 {
269 PRAGMA writable_schema = 1;
270 UPDATE sqlite_schema SET sql = 'CREATE INDEX i1' WHERE name='i1';
272 do_intck_test 6.2.2 {}
274 do_execsql_test 6.3.1 {
275 UPDATE sqlite_schema SET sql = 'CREATE INDEX i1(y' WHERE name='i1';
277 do_intck_test 6.3.2 {}
279 do_execsql_test 6.4.1 {
281 SET sql = 'CREATE INDEX i1(y) hello world'
284 do_intck_test 6.4.2 {}
286 do_execsql_test 6.5.1 {
288 SET sql = 'CREATE INDEX i1(y, x) WHERE 1 '
291 do_intck_test 6.5.2 {}
293 do_execsql_test 6.6.1 {
295 SET sql = 'CREATE INDEX i1( , ) WHERE 1 '
300 set ic [sqlite3_intck db main]
305 } {SQLITE_ERROR {near "AS": syntax error}}
308 do_execsql_test 6.6.1 {
310 SET sql = 'CREATE INDEX i1([y'
313 do_intck_test 6.6.2 {}
315 #-------------------------------------------------------------------------
317 do_execsql_test 7.0 {
318 CREATE TABLE x1("1", "22", "3333", four);
319 CREATE INDEX i1 ON x1( "1" , "22", NULL);
320 INSERT INTO x1 VALUES(1, 22, 3333, NULL);
321 INSERT INTO x1 VALUES(1, 22, 3333, NULL);
323 do_execsql_test 7.1 " CREATE INDEX i2 ON x1( \"1\"\r\n\t ) "
324 do_execsql_test 7.2 { CREATE INDEX i3 ON x1( "22" || 'abc''def' || `1` ) }
325 do_execsql_test 7.3 { CREATE INDEX i4 ON x1( [22] + [1] ) }
326 do_execsql_test 7.4 { CREATE INDEX i5 ON x1( four||'hello' ) }