blob: 3eb624328e2dc7417ca3af1b99670bd0223a082e [file] [log] [blame]
drhcd61c282002-03-06 22:01:34 +00001# 2002 March 6
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
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.
9#
10#***********************************************************************
11# This file implements regression tests for SQLite library.
12#
13# This file implements tests for the PRAGMA command.
14#
danielk1977838cce42009-01-12 14:01:45 +000015# $Id: pragma.test,v 1.73 2009/01/12 14:01:45 danielk1977 Exp $
drhcd61c282002-03-06 22:01:34 +000016
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
dan5885e762012-07-16 10:06:12 +000019set testprefix pragma
drhcd61c282002-03-06 22:01:34 +000020
dan68928b62010-06-22 13:46:43 +000021# Do not use a codec for tests in this file, as the database file is
22# manipulated directly using tcl scripts (using the [hexio_write] command).
23#
24do_not_use_codec
25
danielk197791cf71b2004-06-26 06:37:06 +000026# Test organization:
27#
28# pragma-1.*: Test cache_size, default_cache_size and synchronous on main db.
29# pragma-2.*: Test synchronous on attached db.
30# pragma-3.*: Test detection of table/index inconsistency by integrity_check.
31# pragma-4.*: Test cache_size and default_cache_size on attached db.
32# pragma-5.*: Test that pragma synchronous may not be used inside of a
33# transaction.
danielk1977cc6bd382005-01-10 02:48:49 +000034# pragma-6.*: Test schema-query pragmas.
35# pragma-7.*: Miscellaneous tests.
36# pragma-8.*: Test user_version and schema_version pragmas.
tpoindex9a09a3c2004-12-20 19:01:32 +000037# pragma-9.*: Test temp_store and temp_store_directory.
danielk1977cc6bd382005-01-10 02:48:49 +000038# pragma-10.*: Test the count_changes pragma in the presence of triggers.
danielk197748af65a2005-02-09 03:20:37 +000039# pragma-11.*: Test the collation_list pragma.
danielk197759a93792008-05-15 17:48:20 +000040# pragma-14.*: Test the page_count pragma.
danielk19778cf6c552008-06-23 16:53:46 +000041# pragma-15.*: Test that the value set using the cache_size pragma is not
42# reset when the schema is reloaded.
aswiftaebf4132008-11-21 00:10:35 +000043# pragma-16.*: Test proxy locking
mistachkina112d142012-03-14 00:44:01 +000044# pragma-20.*: Test data_store_directory.
dan5885e762012-07-16 10:06:12 +000045# pragma-22.*: Test that "PRAGMA [db].integrity_check" respects the "db"
46# directive - if it is present.
danielk197791cf71b2004-06-26 06:37:06 +000047#
48
drh05a82982006-03-19 13:00:25 +000049ifcapable !pragma {
50 finish_test
51 return
52}
53
drhcd61c282002-03-06 22:01:34 +000054# Delete the preexisting database to avoid the special setup
55# that the "all.test" script does.
56#
57db close
mistachkinfda06be2011-08-02 00:57:34 +000058delete_file test.db test.db-journal
59delete_file test3.db test3.db-journal
drhdddca282006-01-03 00:33:50 +000060sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
drhcd61c282002-03-06 22:01:34 +000061
drh1e9daa62007-04-06 21:42:22 +000062
danielk1977c7b4a442004-11-23 10:52:51 +000063ifcapable pager_pragmas {
drh1e9daa62007-04-06 21:42:22 +000064set DFLT_CACHE_SZ [db one {PRAGMA default_cache_size}]
65set TEMP_CACHE_SZ [db one {PRAGMA temp.default_cache_size}]
drhcd61c282002-03-06 22:01:34 +000066do_test pragma-1.1 {
67 execsql {
68 PRAGMA cache_size;
69 PRAGMA default_cache_size;
70 PRAGMA synchronous;
drhcd61c282002-03-06 22:01:34 +000071 }
drh1e9daa62007-04-06 21:42:22 +000072} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
drhcd61c282002-03-06 22:01:34 +000073do_test pragma-1.2 {
74 execsql {
drheb43e5c2005-05-22 20:30:39 +000075 PRAGMA synchronous=OFF;
drhcd61c282002-03-06 22:01:34 +000076 PRAGMA cache_size=1234;
77 PRAGMA cache_size;
78 PRAGMA default_cache_size;
79 PRAGMA synchronous;
drhcd61c282002-03-06 22:01:34 +000080 }
drh1e9daa62007-04-06 21:42:22 +000081} [list 1234 $DFLT_CACHE_SZ 0]
drhcd61c282002-03-06 22:01:34 +000082do_test pragma-1.3 {
83 db close
drhef4ac8f2004-06-19 00:16:31 +000084 sqlite3 db test.db
drhcd61c282002-03-06 22:01:34 +000085 execsql {
86 PRAGMA cache_size;
87 PRAGMA default_cache_size;
88 PRAGMA synchronous;
drhcd61c282002-03-06 22:01:34 +000089 }
drh1e9daa62007-04-06 21:42:22 +000090} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
drhcd61c282002-03-06 22:01:34 +000091do_test pragma-1.4 {
92 execsql {
93 PRAGMA synchronous=OFF;
94 PRAGMA cache_size;
95 PRAGMA default_cache_size;
96 PRAGMA synchronous;
drhcd61c282002-03-06 22:01:34 +000097 }
drh1e9daa62007-04-06 21:42:22 +000098} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 0]
drhcd61c282002-03-06 22:01:34 +000099do_test pragma-1.5 {
100 execsql {
drhd2cb50b2009-01-09 21:41:17 +0000101 PRAGMA cache_size=-4321;
drhcd61c282002-03-06 22:01:34 +0000102 PRAGMA cache_size;
103 PRAGMA default_cache_size;
104 PRAGMA synchronous;
drhcd61c282002-03-06 22:01:34 +0000105 }
drh3b42abb2011-11-09 14:23:04 +0000106} [list -4321 $DFLT_CACHE_SZ 0]
drhcd61c282002-03-06 22:01:34 +0000107do_test pragma-1.6 {
108 execsql {
109 PRAGMA synchronous=ON;
110 PRAGMA cache_size;
111 PRAGMA default_cache_size;
112 PRAGMA synchronous;
drhcd61c282002-03-06 22:01:34 +0000113 }
drh3b42abb2011-11-09 14:23:04 +0000114} [list -4321 $DFLT_CACHE_SZ 1]
drhcd61c282002-03-06 22:01:34 +0000115do_test pragma-1.7 {
116 db close
drhef4ac8f2004-06-19 00:16:31 +0000117 sqlite3 db test.db
drhcd61c282002-03-06 22:01:34 +0000118 execsql {
119 PRAGMA cache_size;
120 PRAGMA default_cache_size;
121 PRAGMA synchronous;
drhcd61c282002-03-06 22:01:34 +0000122 }
drh1e9daa62007-04-06 21:42:22 +0000123} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
drhcd61c282002-03-06 22:01:34 +0000124do_test pragma-1.8 {
125 execsql {
drhd2cb50b2009-01-09 21:41:17 +0000126 PRAGMA default_cache_size=-123;
drhcd61c282002-03-06 22:01:34 +0000127 PRAGMA cache_size;
128 PRAGMA default_cache_size;
129 PRAGMA synchronous;
drhcd61c282002-03-06 22:01:34 +0000130 }
danielk197791cf71b2004-06-26 06:37:06 +0000131} {123 123 2}
drh802d69a2005-02-13 23:34:24 +0000132do_test pragma-1.9.1 {
drhcd61c282002-03-06 22:01:34 +0000133 db close
drhdddca282006-01-03 00:33:50 +0000134 sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db]
drhcd61c282002-03-06 22:01:34 +0000135 execsql {
136 PRAGMA cache_size;
137 PRAGMA default_cache_size;
138 PRAGMA synchronous;
drhcd61c282002-03-06 22:01:34 +0000139 }
danielk197791cf71b2004-06-26 06:37:06 +0000140} {123 123 2}
drh802d69a2005-02-13 23:34:24 +0000141ifcapable vacuum {
142 do_test pragma-1.9.2 {
143 execsql {
144 VACUUM;
145 PRAGMA cache_size;
146 PRAGMA default_cache_size;
147 PRAGMA synchronous;
148 }
149 } {123 123 2}
150}
danielk197791cf71b2004-06-26 06:37:06 +0000151do_test pragma-1.10 {
drh5a387052003-01-11 14:19:51 +0000152 execsql {
drh4303fee2003-02-15 23:09:17 +0000153 PRAGMA synchronous=NORMAL;
154 PRAGMA cache_size;
155 PRAGMA default_cache_size;
156 PRAGMA synchronous;
drh4303fee2003-02-15 23:09:17 +0000157 }
danielk197791cf71b2004-06-26 06:37:06 +0000158} {123 123 1}
159do_test pragma-1.11 {
drh4303fee2003-02-15 23:09:17 +0000160 execsql {
161 PRAGMA synchronous=FULL;
162 PRAGMA cache_size;
163 PRAGMA default_cache_size;
164 PRAGMA synchronous;
drh4303fee2003-02-15 23:09:17 +0000165 }
danielk197791cf71b2004-06-26 06:37:06 +0000166} {123 123 2}
167do_test pragma-1.12 {
drh4303fee2003-02-15 23:09:17 +0000168 db close
drhdddca282006-01-03 00:33:50 +0000169 sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db]
drh4303fee2003-02-15 23:09:17 +0000170 execsql {
171 PRAGMA cache_size;
172 PRAGMA default_cache_size;
173 PRAGMA synchronous;
drh4303fee2003-02-15 23:09:17 +0000174 }
danielk197791cf71b2004-06-26 06:37:06 +0000175} {123 123 2}
176
drh5260f7e2004-06-26 19:35:29 +0000177# Make sure the pragma handler understands numeric values in addition
178# to keywords like "off" and "full".
179#
180do_test pragma-1.13 {
181 execsql {
182 PRAGMA synchronous=0;
183 PRAGMA synchronous;
184 }
185} {0}
186do_test pragma-1.14 {
187 execsql {
188 PRAGMA synchronous=2;
189 PRAGMA synchronous;
190 }
191} {2}
danielk1977c7b4a442004-11-23 10:52:51 +0000192} ;# ifcapable pager_pragmas
drh5260f7e2004-06-26 19:35:29 +0000193
194# Test turning "flag" pragmas on and off.
195#
danielk19776338c762007-05-17 16:38:30 +0000196ifcapable debug {
197 # Pragma "vdbe_listing" is only available if compiled with SQLITE_DEBUG
198 #
199 do_test pragma-1.15 {
200 execsql {
201 PRAGMA vdbe_listing=YES;
202 PRAGMA vdbe_listing;
203 }
204 } {1}
205 do_test pragma-1.16 {
206 execsql {
207 PRAGMA vdbe_listing=NO;
208 PRAGMA vdbe_listing;
209 }
210 } {0}
211}
212
drh5260f7e2004-06-26 19:35:29 +0000213do_test pragma-1.17 {
214 execsql {
215 PRAGMA parser_trace=ON;
216 PRAGMA parser_trace=OFF;
217 }
218} {}
219do_test pragma-1.18 {
220 execsql {
221 PRAGMA bogus = -1234; -- Parsing of negative values
222 }
223} {}
224
danielk197791cf71b2004-06-26 06:37:06 +0000225# Test modifying the safety_level of an attached database.
danielk19775a8f9372007-10-09 08:29:32 +0000226ifcapable pager_pragmas&&attach {
227 do_test pragma-2.1 {
mistachkinfda06be2011-08-02 00:57:34 +0000228 forcedelete test2.db
229 forcedelete test2.db-journal
danielk19775a8f9372007-10-09 08:29:32 +0000230 execsql {
231 ATTACH 'test2.db' AS aux;
232 }
233 } {}
234 do_test pragma-2.2 {
235 execsql {
236 pragma aux.synchronous;
237 }
238 } {2}
239 do_test pragma-2.3 {
240 execsql {
241 pragma aux.synchronous = OFF;
242 pragma aux.synchronous;
243 pragma synchronous;
244 }
245 } {0 2}
246 do_test pragma-2.4 {
247 execsql {
248 pragma aux.synchronous = ON;
249 pragma synchronous;
250 pragma aux.synchronous;
251 }
252 } {2 1}
danielk1977c7b4a442004-11-23 10:52:51 +0000253} ;# ifcapable pager_pragmas
drh4303fee2003-02-15 23:09:17 +0000254
drhed717fe2003-06-15 23:42:24 +0000255# Construct a corrupted index and make sure the integrity_check
256# pragma finds it.
257#
drh25d65432004-07-22 15:02:25 +0000258# These tests won't work if the database is encrypted
259#
drhed717fe2003-06-15 23:42:24 +0000260do_test pragma-3.1 {
drh1e9daa62007-04-06 21:42:22 +0000261 db close
mistachkinfda06be2011-08-02 00:57:34 +0000262 forcedelete test.db test.db-journal
drh1e9daa62007-04-06 21:42:22 +0000263 sqlite3 db test.db
drhed717fe2003-06-15 23:42:24 +0000264 execsql {
drh1e9daa62007-04-06 21:42:22 +0000265 PRAGMA auto_vacuum=OFF;
drhed717fe2003-06-15 23:42:24 +0000266 BEGIN;
267 CREATE TABLE t2(a,b,c);
268 CREATE INDEX i2 ON t2(a);
269 INSERT INTO t2 VALUES(11,2,3);
270 INSERT INTO t2 VALUES(22,3,4);
271 COMMIT;
272 SELECT rowid, * from t2;
273 }
274} {1 11 2 3 2 22 3 4}
danielk19775a8f9372007-10-09 08:29:32 +0000275ifcapable attach {
276 if {![sqlite3 -has-codec] && $sqlite_options(integrityck)} {
277 do_test pragma-3.2 {
drhbb8a2792008-03-19 00:21:30 +0000278 db eval {SELECT rootpage FROM sqlite_master WHERE name='i2'} break
279 set pgsz [db eval {PRAGMA page_size}]
280 # overwrite the header on the rootpage of the index in order to
281 # make the index appear to be empty.
282 #
283 set offset [expr {$pgsz*($rootpage-1)}]
284 hexio_write test.db $offset 0a00000000040000000000
285 db close
286 sqlite3 db test.db
danielk19775a8f9372007-10-09 08:29:32 +0000287 execsql {PRAGMA integrity_check}
drhbb8a2792008-03-19 00:21:30 +0000288 } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
danielk19775a8f9372007-10-09 08:29:32 +0000289 do_test pragma-3.3 {
290 execsql {PRAGMA integrity_check=1}
291 } {{rowid 1 missing from index i2}}
292 do_test pragma-3.4 {
293 execsql {
294 ATTACH DATABASE 'test.db' AS t2;
295 PRAGMA integrity_check
296 }
drhbb8a2792008-03-19 00:21:30 +0000297 } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
danielk19775a8f9372007-10-09 08:29:32 +0000298 do_test pragma-3.5 {
299 execsql {
drhbb8a2792008-03-19 00:21:30 +0000300 PRAGMA integrity_check=4
danielk19775a8f9372007-10-09 08:29:32 +0000301 }
drhbb8a2792008-03-19 00:21:30 +0000302 } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2}}
danielk19775a8f9372007-10-09 08:29:32 +0000303 do_test pragma-3.6 {
304 execsql {
305 PRAGMA integrity_check=xyz
306 }
drhbb8a2792008-03-19 00:21:30 +0000307 } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
danielk19775a8f9372007-10-09 08:29:32 +0000308 do_test pragma-3.7 {
309 execsql {
310 PRAGMA integrity_check=0
311 }
drhbb8a2792008-03-19 00:21:30 +0000312 } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
danielk19775a8f9372007-10-09 08:29:32 +0000313
314 # Add additional corruption by appending unused pages to the end of
315 # the database file testerr.db
316 #
317 do_test pragma-3.8 {
318 execsql {DETACH t2}
mistachkinfda06be2011-08-02 00:57:34 +0000319 forcedelete testerr.db testerr.db-journal
danielk19775a8f9372007-10-09 08:29:32 +0000320 set out [open testerr.db w]
321 fconfigure $out -translation binary
322 set in [open test.db r]
323 fconfigure $in -translation binary
324 puts -nonewline $out [read $in]
325 seek $in 0
326 puts -nonewline $out [read $in]
327 close $in
328 close $out
drhdd3cd972010-03-27 17:12:36 +0000329 hexio_write testerr.db 28 00000000
danielk19775a8f9372007-10-09 08:29:32 +0000330 execsql {REINDEX t2}
331 execsql {PRAGMA integrity_check}
332 } {ok}
danielk197741c58b72007-12-29 13:39:19 +0000333 do_test pragma-3.8.1 {
334 execsql {PRAGMA quick_check}
335 } {ok}
drh5d16a9a2011-10-13 14:41:22 +0000336 do_test pragma-3.8.2 {
337 execsql {PRAGMA QUICK_CHECK}
338 } {ok}
danielk19775a8f9372007-10-09 08:29:32 +0000339 do_test pragma-3.9 {
340 execsql {
341 ATTACH 'testerr.db' AS t2;
342 PRAGMA integrity_check
343 }
344 } {{*** in database t2 ***
drh1dcdbc02007-01-27 02:24:54 +0000345Page 4 is never used
346Page 5 is never used
drhbb8a2792008-03-19 00:21:30 +0000347Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
danielk19775a8f9372007-10-09 08:29:32 +0000348 do_test pragma-3.10 {
349 execsql {
350 PRAGMA integrity_check=1
351 }
352 } {{*** in database t2 ***
drh1dcdbc02007-01-27 02:24:54 +0000353Page 4 is never used}}
danielk19775a8f9372007-10-09 08:29:32 +0000354 do_test pragma-3.11 {
355 execsql {
356 PRAGMA integrity_check=5
357 }
358 } {{*** in database t2 ***
drh1dcdbc02007-01-27 02:24:54 +0000359Page 4 is never used
360Page 5 is never used
drhbb8a2792008-03-19 00:21:30 +0000361Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2}}
danielk19775a8f9372007-10-09 08:29:32 +0000362 do_test pragma-3.12 {
363 execsql {
364 PRAGMA integrity_check=4
365 }
366 } {{*** in database t2 ***
drh1dcdbc02007-01-27 02:24:54 +0000367Page 4 is never used
368Page 5 is never used
369Page 6 is never used} {rowid 1 missing from index i2}}
danielk19775a8f9372007-10-09 08:29:32 +0000370 do_test pragma-3.13 {
371 execsql {
372 PRAGMA integrity_check=3
373 }
374 } {{*** in database t2 ***
drh1dcdbc02007-01-27 02:24:54 +0000375Page 4 is never used
376Page 5 is never used
377Page 6 is never used}}
danielk19775a8f9372007-10-09 08:29:32 +0000378 do_test pragma-3.14 {
379 execsql {
380 PRAGMA integrity_check(2)
381 }
382 } {{*** in database t2 ***
drh1dcdbc02007-01-27 02:24:54 +0000383Page 4 is never used
384Page 5 is never used}}
danielk19775a8f9372007-10-09 08:29:32 +0000385 do_test pragma-3.15 {
386 execsql {
387 ATTACH 'testerr.db' AS t3;
388 PRAGMA integrity_check
389 }
390 } {{*** in database t2 ***
drh1dcdbc02007-01-27 02:24:54 +0000391Page 4 is never used
392Page 5 is never used
drhbb8a2792008-03-19 00:21:30 +0000393Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
drh1dcdbc02007-01-27 02:24:54 +0000394Page 4 is never used
395Page 5 is never used
drhbb8a2792008-03-19 00:21:30 +0000396Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
danielk19775a8f9372007-10-09 08:29:32 +0000397 do_test pragma-3.16 {
398 execsql {
drhbb8a2792008-03-19 00:21:30 +0000399 PRAGMA integrity_check(10)
danielk19775a8f9372007-10-09 08:29:32 +0000400 }
401 } {{*** in database t2 ***
drh1dcdbc02007-01-27 02:24:54 +0000402Page 4 is never used
403Page 5 is never used
drhbb8a2792008-03-19 00:21:30 +0000404Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
drh1dcdbc02007-01-27 02:24:54 +0000405Page 4 is never used
406Page 5 is never used
407Page 6 is never used} {rowid 1 missing from index i2}}
danielk19775a8f9372007-10-09 08:29:32 +0000408 do_test pragma-3.17 {
409 execsql {
drhbb8a2792008-03-19 00:21:30 +0000410 PRAGMA integrity_check=8
danielk19775a8f9372007-10-09 08:29:32 +0000411 }
412 } {{*** in database t2 ***
drh1dcdbc02007-01-27 02:24:54 +0000413Page 4 is never used
414Page 5 is never used
drhbb8a2792008-03-19 00:21:30 +0000415Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
drh1dcdbc02007-01-27 02:24:54 +0000416Page 4 is never used
417Page 5 is never used}}
danielk19775a8f9372007-10-09 08:29:32 +0000418 do_test pragma-3.18 {
419 execsql {
420 PRAGMA integrity_check=4
421 }
422 } {{*** in database t2 ***
drh1dcdbc02007-01-27 02:24:54 +0000423Page 4 is never used
424Page 5 is never used
425Page 6 is never used} {rowid 1 missing from index i2}}
danielk19775a8f9372007-10-09 08:29:32 +0000426 }
drhd2cb50b2009-01-09 21:41:17 +0000427 do_test pragma-3.19 {
428 catch {db close}
mistachkinfda06be2011-08-02 00:57:34 +0000429 forcedelete test.db test.db-journal
drhd2cb50b2009-01-09 21:41:17 +0000430 sqlite3 db test.db
431 db eval {PRAGMA integrity_check}
432 } {ok}
drh25d65432004-07-22 15:02:25 +0000433}
drhd2cb50b2009-01-09 21:41:17 +0000434#exit
danielk197791cf71b2004-06-26 06:37:06 +0000435
436# Test modifying the cache_size of an attached database.
danielk19775a8f9372007-10-09 08:29:32 +0000437ifcapable pager_pragmas&&attach {
danielk197791cf71b2004-06-26 06:37:06 +0000438do_test pragma-4.1 {
439 execsql {
drh1e9daa62007-04-06 21:42:22 +0000440 ATTACH 'test2.db' AS aux;
danielk197791cf71b2004-06-26 06:37:06 +0000441 pragma aux.cache_size;
442 pragma aux.default_cache_size;
443 }
drh1e9daa62007-04-06 21:42:22 +0000444} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
drh1bdd9b52004-04-23 17:04:44 +0000445do_test pragma-4.2 {
446 execsql {
danielk197791cf71b2004-06-26 06:37:06 +0000447 pragma aux.cache_size = 50;
448 pragma aux.cache_size;
449 pragma aux.default_cache_size;
450 }
drh1e9daa62007-04-06 21:42:22 +0000451} [list 50 $DFLT_CACHE_SZ]
drh1bdd9b52004-04-23 17:04:44 +0000452do_test pragma-4.3 {
453 execsql {
danielk197791cf71b2004-06-26 06:37:06 +0000454 pragma aux.default_cache_size = 456;
455 pragma aux.cache_size;
456 pragma aux.default_cache_size;
457 }
458} {456 456}
drh1bdd9b52004-04-23 17:04:44 +0000459do_test pragma-4.4 {
460 execsql {
danielk197791cf71b2004-06-26 06:37:06 +0000461 pragma cache_size;
462 pragma default_cache_size;
463 }
drh1e9daa62007-04-06 21:42:22 +0000464} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
drh1bdd9b52004-04-23 17:04:44 +0000465do_test pragma-4.5 {
466 execsql {
danielk197791cf71b2004-06-26 06:37:06 +0000467 DETACH aux;
468 ATTACH 'test3.db' AS aux;
469 pragma aux.cache_size;
470 pragma aux.default_cache_size;
471 }
drh1e9daa62007-04-06 21:42:22 +0000472} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
drh1bdd9b52004-04-23 17:04:44 +0000473do_test pragma-4.6 {
474 execsql {
danielk197791cf71b2004-06-26 06:37:06 +0000475 DETACH aux;
476 ATTACH 'test2.db' AS aux;
477 pragma aux.cache_size;
478 pragma aux.default_cache_size;
479 }
480} {456 456}
danielk1977c7b4a442004-11-23 10:52:51 +0000481} ;# ifcapable pager_pragmas
drh1bdd9b52004-04-23 17:04:44 +0000482
danielk197791cf71b2004-06-26 06:37:06 +0000483# Test that modifying the sync-level in the middle of a transaction is
484# disallowed.
danielk1977c7b4a442004-11-23 10:52:51 +0000485ifcapable pager_pragmas {
danielk197791cf71b2004-06-26 06:37:06 +0000486do_test pragma-5.0 {
drh1bdd9b52004-04-23 17:04:44 +0000487 execsql {
danielk197791cf71b2004-06-26 06:37:06 +0000488 pragma synchronous;
489 }
490} {2}
491do_test pragma-5.1 {
drh1bdd9b52004-04-23 17:04:44 +0000492 catchsql {
493 BEGIN;
danielk197791cf71b2004-06-26 06:37:06 +0000494 pragma synchronous = OFF;
495 }
496} {1 {Safety level may not be changed inside a transaction}}
497do_test pragma-5.2 {
498 execsql {
499 pragma synchronous;
500 }
501} {2}
drh5260f7e2004-06-26 19:35:29 +0000502catchsql {COMMIT;}
danielk1977c7b4a442004-11-23 10:52:51 +0000503} ;# ifcapable pager_pragmas
drh5260f7e2004-06-26 19:35:29 +0000504
505# Test schema-query pragmas
506#
danielk197727188fb2004-11-23 10:13:03 +0000507ifcapable schema_pragmas {
danielk19775a8f9372007-10-09 08:29:32 +0000508ifcapable tempdb&&attach {
danielk197753c0f742005-03-29 03:10:59 +0000509 do_test pragma-6.1 {
510 set res {}
511 execsql {SELECT * FROM sqlite_temp_master}
512 foreach {idx name file} [execsql {pragma database_list}] {
513 lappend res $idx $name
514 }
515 set res
516 } {0 main 1 temp 2 aux}
517}
drh5260f7e2004-06-26 19:35:29 +0000518do_test pragma-6.2 {
519 execsql {
drhd2cb50b2009-01-09 21:41:17 +0000520 CREATE TABLE t2(a,b,c);
drh5260f7e2004-06-26 19:35:29 +0000521 pragma table_info(t2)
522 }
drhbfa8b102006-03-03 21:20:16 +0000523} {0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0}
drhd2cb50b2009-01-09 21:41:17 +0000524do_test pragma-6.2.1 {
525 execsql {
526 pragma table_info;
527 }
528} {}
drh736c7d42006-11-30 13:06:37 +0000529db nullvalue <<NULL>>
drh417ec632006-08-14 14:23:41 +0000530do_test pragma-6.2.2 {
531 execsql {
drh736c7d42006-11-30 13:06:37 +0000532 CREATE TABLE t5(
533 a TEXT DEFAULT CURRENT_TIMESTAMP,
534 b DEFAULT (5+3),
535 c TEXT,
536 d INTEGER DEFAULT NULL,
drh384b7fe2013-01-01 13:55:31 +0000537 e TEXT DEFAULT '',
538 UNIQUE(b,c,d),
539 PRIMARY KEY(e,b,c)
drh736c7d42006-11-30 13:06:37 +0000540 );
drh417ec632006-08-14 14:23:41 +0000541 PRAGMA table_info(t5);
542 }
drh384b7fe2013-01-01 13:55:31 +0000543} {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 2 2 c TEXT 0 <<NULL>> 3 3 d INTEGER 0 NULL 0 4 e TEXT 0 '' 1}
drh736c7d42006-11-30 13:06:37 +0000544db nullvalue {}
drh384b7fe2013-01-01 13:55:31 +0000545do_test pragma-6.2.3 {
546 execsql {
547 CREATE TABLE t2_3(a,b INTEGER PRIMARY KEY,c);
548 pragma table_info(t2_3)
549 }
550} {0 a {} 0 {} 0 1 b INTEGER 0 {} 1 2 c {} 0 {} 0}
drh6bf89572004-11-03 16:27:01 +0000551ifcapable {foreignkey} {
drhd2cb50b2009-01-09 21:41:17 +0000552 do_test pragma-6.3.1 {
drh6bf89572004-11-03 16:27:01 +0000553 execsql {
554 CREATE TABLE t3(a int references t2(b), b UNIQUE);
555 pragma foreign_key_list(t3);
556 }
dan1da40a32009-09-19 17:00:31 +0000557 } {0 0 t2 a b {NO ACTION} {NO ACTION} NONE}
drhd2cb50b2009-01-09 21:41:17 +0000558 do_test pragma-6.3.2 {
559 execsql {
560 pragma foreign_key_list;
561 }
562 } {}
563 do_test pragma-6.3.3 {
564 execsql {
565 pragma foreign_key_list(t3_bogus);
566 }
567 } {}
568 do_test pragma-6.3.4 {
569 execsql {
570 pragma foreign_key_list(t5);
571 }
572 } {}
drh6bf89572004-11-03 16:27:01 +0000573 do_test pragma-6.4 {
574 execsql {
575 pragma index_list(t3);
576 }
577 } {0 sqlite_autoindex_t3_1 1}
578}
579ifcapable {!foreignkey} {
580 execsql {CREATE TABLE t3(a,b UNIQUE)}
581}
drhd2cb50b2009-01-09 21:41:17 +0000582do_test pragma-6.5.1 {
drh5260f7e2004-06-26 19:35:29 +0000583 execsql {
584 CREATE INDEX t3i1 ON t3(a,b);
585 pragma index_info(t3i1);
586 }
587} {0 0 a 1 1 b}
drhd2cb50b2009-01-09 21:41:17 +0000588do_test pragma-6.5.2 {
589 execsql {
590 pragma index_info(t3i1_bogus);
591 }
592} {}
danielk1977260d8a62008-08-20 16:34:24 +0000593
594ifcapable tempdb {
595 # Test for ticket #3320. When a temp table of the same name exists, make
596 # sure the schema of the main table can still be queried using
597 # "pragma table_info":
598 do_test pragma-6.6.1 {
599 execsql {
600 CREATE TABLE trial(col_main);
601 CREATE TEMP TABLE trial(col_temp);
602 }
603 } {}
604 do_test pragma-6.6.2 {
605 execsql {
606 PRAGMA table_info(trial);
607 }
608 } {0 col_temp {} 0 {} 0}
609 do_test pragma-6.6.3 {
610 execsql {
611 PRAGMA temp.table_info(trial);
612 }
613 } {0 col_temp {} 0 {} 0}
614 do_test pragma-6.6.4 {
615 execsql {
616 PRAGMA main.table_info(trial);
617 }
618 } {0 col_main {} 0 {} 0}
619}
danielk1977f96a3772008-10-23 05:45:07 +0000620
danielk1977f96a3772008-10-23 05:45:07 +0000621do_test pragma-6.7 {
622 execsql {
623 CREATE TABLE test_table(
624 one INT NOT NULL DEFAULT -1,
625 two text,
626 three VARCHAR(45, 65) DEFAULT 'abcde',
627 four REAL DEFAULT X'abcdef',
628 five DEFAULT CURRENT_TIME
629 );
630 PRAGMA table_info(test_table);
631 }
632} [concat \
633 {0 one INT 1 -1 0} \
634 {1 two text 0 {} 0} \
635 {2 three {VARCHAR(45, 65)} 0 'abcde' 0} \
636 {3 four REAL 0 X'abcdef' 0} \
637 {4 five {} 0 CURRENT_TIME 0} \
638]
danielk197727188fb2004-11-23 10:13:03 +0000639} ;# ifcapable schema_pragmas
drh5260f7e2004-06-26 19:35:29 +0000640# Miscellaneous tests
641#
danielk197727188fb2004-11-23 10:13:03 +0000642ifcapable schema_pragmas {
drhd2cb50b2009-01-09 21:41:17 +0000643do_test pragma-7.1.1 {
drh5260f7e2004-06-26 19:35:29 +0000644 # Make sure a pragma knows to read the schema if it needs to
645 db close
646 sqlite3 db test.db
647 execsql {
648 pragma index_list(t3);
649 }
650} {0 t3i1 0 1 sqlite_autoindex_t3_1 1}
drhd2cb50b2009-01-09 21:41:17 +0000651do_test pragma-7.1.2 {
652 execsql {
653 pragma index_list(t3_bogus);
654 }
655} {}
danielk197727188fb2004-11-23 10:13:03 +0000656} ;# ifcapable schema_pragmas
drh6c626082004-11-14 21:56:29 +0000657ifcapable {utf16} {
dancb354602010-07-08 09:44:42 +0000658 if {[permutation] == ""} {
659 do_test pragma-7.2 {
660 db close
661 sqlite3 db test.db
662 catchsql {
663 pragma encoding=bogus;
664 }
665 } {1 {unsupported encoding: bogus}}
666 }
drh6c626082004-11-14 21:56:29 +0000667}
danielk197753c0f742005-03-29 03:10:59 +0000668ifcapable tempdb {
669 do_test pragma-7.3 {
670 db close
671 sqlite3 db test.db
672 execsql {
673 pragma lock_status;
674 }
675 } {main unlocked temp closed}
676} else {
677 do_test pragma-7.3 {
678 db close
679 sqlite3 db test.db
680 execsql {
681 pragma lock_status;
682 }
683 } {main unlocked}
684}
drh5260f7e2004-06-26 19:35:29 +0000685
686
danielk1977dae24952004-11-11 05:10:43 +0000687#----------------------------------------------------------------------
danielk1977b92b70b2004-11-12 16:11:59 +0000688# Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA
689# user_version" statements.
danielk1977dae24952004-11-11 05:10:43 +0000690#
danielk1977b92b70b2004-11-12 16:11:59 +0000691# pragma-8.1: PRAGMA schema_version
692# pragma-8.2: PRAGMA user_version
danielk1977dae24952004-11-11 05:10:43 +0000693#
694
danielk197711cf9fb2004-11-23 11:16:42 +0000695ifcapable schema_version {
696
danielk1977b92b70b2004-11-12 16:11:59 +0000697# First check that we can set the schema version and then retrieve the
danielk1977dae24952004-11-11 05:10:43 +0000698# same value.
699do_test pragma-8.1.1 {
700 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000701 PRAGMA schema_version = 105;
danielk1977dae24952004-11-11 05:10:43 +0000702 }
703} {}
704do_test pragma-8.1.2 {
drh25403652007-01-04 22:13:41 +0000705 execsql2 {
danielk1977b92b70b2004-11-12 16:11:59 +0000706 PRAGMA schema_version;
danielk1977dae24952004-11-11 05:10:43 +0000707 }
drh25403652007-01-04 22:13:41 +0000708} {schema_version 105}
danielk1977dae24952004-11-11 05:10:43 +0000709do_test pragma-8.1.3 {
710 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000711 PRAGMA schema_version = 106;
danielk1977dae24952004-11-11 05:10:43 +0000712 }
713} {}
714do_test pragma-8.1.4 {
715 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000716 PRAGMA schema_version;
danielk1977dae24952004-11-11 05:10:43 +0000717 }
718} 106
719
danielk1977b92b70b2004-11-12 16:11:59 +0000720# Check that creating a table modifies the schema-version (this is really
721# to verify that the value being read is in fact the schema version).
danielk1977dae24952004-11-11 05:10:43 +0000722do_test pragma-8.1.5 {
723 execsql {
724 CREATE TABLE t4(a, b, c);
725 INSERT INTO t4 VALUES(1, 2, 3);
726 SELECT * FROM t4;
727 }
728} {1 2 3}
729do_test pragma-8.1.6 {
730 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000731 PRAGMA schema_version;
danielk1977dae24952004-11-11 05:10:43 +0000732 }
733} 107
734
735# Now open a second connection to the database. Ensure that changing the
danielk1977b92b70b2004-11-12 16:11:59 +0000736# schema-version using the first connection forces the second connection
danielk1977dae24952004-11-11 05:10:43 +0000737# to reload the schema. This has to be done using the C-API test functions,
738# because the TCL API accounts for SCHEMA_ERROR and retries the query.
739do_test pragma-8.1.7 {
drhdddca282006-01-03 00:33:50 +0000740 sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]
danielk1977dae24952004-11-11 05:10:43 +0000741 execsql {
742 SELECT * FROM t4;
743 } db2
744} {1 2 3}
745do_test pragma-8.1.8 {
746 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000747 PRAGMA schema_version = 108;
danielk1977dae24952004-11-11 05:10:43 +0000748 }
749} {}
750do_test pragma-8.1.9 {
751 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY]
752 sqlite3_step $::STMT
753} SQLITE_ERROR
754do_test pragma-8.1.10 {
755 sqlite3_finalize $::STMT
756} SQLITE_SCHEMA
757
danielk1977b92b70b2004-11-12 16:11:59 +0000758# Make sure the schema-version can be manipulated in an attached database.
mistachkinfda06be2011-08-02 00:57:34 +0000759forcedelete test2.db
760forcedelete test2.db-journal
danielk19775a8f9372007-10-09 08:29:32 +0000761ifcapable attach {
762 do_test pragma-8.1.11 {
763 execsql {
764 ATTACH 'test2.db' AS aux;
765 CREATE TABLE aux.t1(a, b, c);
766 PRAGMA aux.schema_version = 205;
767 }
768 } {}
769 do_test pragma-8.1.12 {
770 execsql {
771 PRAGMA aux.schema_version;
772 }
773 } 205
774}
danielk1977dae24952004-11-11 05:10:43 +0000775do_test pragma-8.1.13 {
776 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000777 PRAGMA schema_version;
danielk1977dae24952004-11-11 05:10:43 +0000778 }
779} 108
780
danielk1977b92b70b2004-11-12 16:11:59 +0000781# And check that modifying the schema-version in an attached database
danielk1977dae24952004-11-11 05:10:43 +0000782# forces the second connection to reload the schema.
danielk19775a8f9372007-10-09 08:29:32 +0000783ifcapable attach {
784 do_test pragma-8.1.14 {
785 sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]
786 execsql {
787 ATTACH 'test2.db' AS aux;
788 SELECT * FROM aux.t1;
789 } db2
790 } {}
791 do_test pragma-8.1.15 {
792 execsql {
793 PRAGMA aux.schema_version = 206;
794 }
795 } {}
796 do_test pragma-8.1.16 {
797 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY]
798 sqlite3_step $::STMT
799 } SQLITE_ERROR
800 do_test pragma-8.1.17 {
801 sqlite3_finalize $::STMT
802 } SQLITE_SCHEMA
803 do_test pragma-8.1.18 {
804 db2 close
805 } {}
806}
danielk1977dae24952004-11-11 05:10:43 +0000807
danielk1977b92b70b2004-11-12 16:11:59 +0000808# Now test that the user-version can be read and written (and that we aren't
809# accidentally manipulating the schema-version instead).
danielk1977dae24952004-11-11 05:10:43 +0000810do_test pragma-8.2.1 {
drh25403652007-01-04 22:13:41 +0000811 execsql2 {
danielk1977b92b70b2004-11-12 16:11:59 +0000812 PRAGMA user_version;
danielk1977dae24952004-11-11 05:10:43 +0000813 }
drh25403652007-01-04 22:13:41 +0000814} {user_version 0}
danielk1977dae24952004-11-11 05:10:43 +0000815do_test pragma-8.2.2 {
816 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000817 PRAGMA user_version = 2;
danielk1977dae24952004-11-11 05:10:43 +0000818 }
819} {}
drh802d69a2005-02-13 23:34:24 +0000820do_test pragma-8.2.3.1 {
drh25403652007-01-04 22:13:41 +0000821 execsql2 {
danielk1977b92b70b2004-11-12 16:11:59 +0000822 PRAGMA user_version;
danielk1977dae24952004-11-11 05:10:43 +0000823 }
drh25403652007-01-04 22:13:41 +0000824} {user_version 2}
drh802d69a2005-02-13 23:34:24 +0000825do_test pragma-8.2.3.2 {
826 db close
827 sqlite3 db test.db
828 execsql {
829 PRAGMA user_version;
830 }
831} {2}
832do_test pragma-8.2.4.1 {
danielk1977dae24952004-11-11 05:10:43 +0000833 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000834 PRAGMA schema_version;
danielk1977dae24952004-11-11 05:10:43 +0000835 }
836} {108}
drh802d69a2005-02-13 23:34:24 +0000837ifcapable vacuum {
838 do_test pragma-8.2.4.2 {
839 execsql {
840 VACUUM;
841 PRAGMA user_version;
842 }
843 } {2}
844 do_test pragma-8.2.4.3 {
845 execsql {
846 PRAGMA schema_version;
847 }
848 } {109}
849}
danielk1977dae24952004-11-11 05:10:43 +0000850
danielk19775a8f9372007-10-09 08:29:32 +0000851ifcapable attach {
852 db eval {ATTACH 'test2.db' AS aux}
853
854 # Check that the user-version in the auxilary database can be manipulated (
855 # and that we aren't accidentally manipulating the same in the main db).
856 do_test pragma-8.2.5 {
857 execsql {
858 PRAGMA aux.user_version;
859 }
860 } {0}
861 do_test pragma-8.2.6 {
862 execsql {
863 PRAGMA aux.user_version = 3;
864 }
865 } {}
866 do_test pragma-8.2.7 {
867 execsql {
868 PRAGMA aux.user_version;
869 }
870 } {3}
871 do_test pragma-8.2.8 {
872 execsql {
873 PRAGMA main.user_version;
874 }
875 } {2}
876
877 # Now check that a ROLLBACK resets the user-version if it has been modified
878 # within a transaction.
879 do_test pragma-8.2.9 {
880 execsql {
881 BEGIN;
882 PRAGMA aux.user_version = 10;
883 PRAGMA user_version = 11;
884 }
885 } {}
886 do_test pragma-8.2.10 {
887 execsql {
888 PRAGMA aux.user_version;
889 }
890 } {10}
891 do_test pragma-8.2.11 {
892 execsql {
893 PRAGMA main.user_version;
894 }
895 } {11}
896 do_test pragma-8.2.12 {
897 execsql {
898 ROLLBACK;
899 PRAGMA aux.user_version;
900 }
901 } {3}
902 do_test pragma-8.2.13 {
903 execsql {
904 PRAGMA main.user_version;
905 }
906 } {2}
907}
danielk1977dae24952004-11-11 05:10:43 +0000908
danielk1977b92b70b2004-11-12 16:11:59 +0000909# Try a negative value for the user-version
danielk1977dae24952004-11-11 05:10:43 +0000910do_test pragma-8.2.14 {
911 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000912 PRAGMA user_version = -450;
danielk1977dae24952004-11-11 05:10:43 +0000913 }
914} {}
915do_test pragma-8.2.15 {
916 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000917 PRAGMA user_version;
danielk1977dae24952004-11-11 05:10:43 +0000918 }
919} {-450}
danielk1977d9c847d2005-01-07 10:42:48 +0000920} ; # ifcapable schema_version
921
drhd19744f2008-03-18 13:46:53 +0000922# Check to see if TEMP_STORE is memory or disk. Return strings
923# "memory" or "disk" as appropriate.
924#
925proc check_temp_store {} {
926 db eval {CREATE TEMP TABLE IF NOT EXISTS a(b)}
927 db eval {PRAGMA database_list} {
928 if {$name=="temp"} {
danielk197717b90b52008-06-06 11:11:25 +0000929 set bt [btree_from_db db 1]
930 if {[btree_ismemdb $bt]} {
drhd19744f2008-03-18 13:46:53 +0000931 return "memory"
drhd19744f2008-03-18 13:46:53 +0000932 }
danielk197717b90b52008-06-06 11:11:25 +0000933 return "disk"
drhd19744f2008-03-18 13:46:53 +0000934 }
935 }
936 return "unknown"
937}
938
tpoindex9a09a3c2004-12-20 19:01:32 +0000939
940# Test temp_store and temp_store_directory pragmas
941#
drh268283b2005-01-08 15:44:25 +0000942ifcapable pager_pragmas {
tpoindex9a09a3c2004-12-20 19:01:32 +0000943do_test pragma-9.1 {
944 db close
945 sqlite3 db test.db
946 execsql {
947 PRAGMA temp_store;
948 }
949} {0}
drhd19744f2008-03-18 13:46:53 +0000950if {$TEMP_STORE<=1} {
951 do_test pragma-9.1.1 {
952 check_temp_store
953 } {disk}
954} else {
955 do_test pragma-9.1.1 {
956 check_temp_store
957 } {memory}
958}
959
tpoindex9a09a3c2004-12-20 19:01:32 +0000960do_test pragma-9.2 {
drhd19744f2008-03-18 13:46:53 +0000961 db close
962 sqlite3 db test.db
tpoindex9a09a3c2004-12-20 19:01:32 +0000963 execsql {
964 PRAGMA temp_store=file;
965 PRAGMA temp_store;
966 }
967} {1}
drhd19744f2008-03-18 13:46:53 +0000968if {$TEMP_STORE==3} {
969 # When TEMP_STORE is 3, always use memory regardless of pragma settings.
970 do_test pragma-9.2.1 {
971 check_temp_store
972 } {memory}
973} else {
974 do_test pragma-9.2.1 {
975 check_temp_store
976 } {disk}
977}
978
tpoindex9a09a3c2004-12-20 19:01:32 +0000979do_test pragma-9.3 {
drhd19744f2008-03-18 13:46:53 +0000980 db close
981 sqlite3 db test.db
tpoindex9a09a3c2004-12-20 19:01:32 +0000982 execsql {
983 PRAGMA temp_store=memory;
984 PRAGMA temp_store;
985 }
986} {2}
drhd19744f2008-03-18 13:46:53 +0000987if {$TEMP_STORE==0} {
988 # When TEMP_STORE is 0, always use the disk regardless of pragma settings.
989 do_test pragma-9.3.1 {
990 check_temp_store
991 } {disk}
992} else {
993 do_test pragma-9.3.1 {
994 check_temp_store
995 } {memory}
996}
997
tpoindex9a09a3c2004-12-20 19:01:32 +0000998do_test pragma-9.4 {
999 execsql {
1000 PRAGMA temp_store_directory;
1001 }
1002} {}
drh78f82d12008-09-02 00:52:52 +00001003ifcapable wsd {
1004 do_test pragma-9.5 {
mistachkinf8a78462012-03-08 20:00:36 +00001005 set pwd [string map {' ''} [file nativename [get_pwd]]]
drh78f82d12008-09-02 00:52:52 +00001006 execsql "
1007 PRAGMA temp_store_directory='$pwd';
1008 "
1009 } {}
1010 do_test pragma-9.6 {
1011 execsql {
1012 PRAGMA temp_store_directory;
1013 }
mistachkinf8a78462012-03-08 20:00:36 +00001014 } [list [file nativename [get_pwd]]]
drh78f82d12008-09-02 00:52:52 +00001015 do_test pragma-9.7 {
1016 catchsql {
1017 PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR';
1018 }
1019 } {1 {not a writable directory}}
1020 do_test pragma-9.8 {
1021 execsql {
1022 PRAGMA temp_store_directory='';
1023 }
1024 } {}
1025 if {![info exists TEMP_STORE] || $TEMP_STORE<=1} {
1026 ifcapable tempdb {
1027 do_test pragma-9.9 {
1028 execsql {
1029 PRAGMA temp_store_directory;
1030 PRAGMA temp_store=FILE;
1031 CREATE TEMP TABLE temp_store_directory_test(a integer);
1032 INSERT INTO temp_store_directory_test values (2);
1033 SELECT * FROM temp_store_directory_test;
1034 }
1035 } {2}
1036 do_test pragma-9.10 {
1037 catchsql "
1038 PRAGMA temp_store_directory='$pwd';
1039 SELECT * FROM temp_store_directory_test;
1040 "
1041 } {1 {no such table: temp_store_directory_test}}
1042 }
tpoindex9a09a3c2004-12-20 19:01:32 +00001043 }
drh78f82d12008-09-02 00:52:52 +00001044}
danielk197795b289b2007-03-30 17:11:12 +00001045do_test pragma-9.11 {
1046 execsql {
1047 PRAGMA temp_store = 0;
1048 PRAGMA temp_store;
1049 }
1050} {0}
1051do_test pragma-9.12 {
1052 execsql {
1053 PRAGMA temp_store = 1;
1054 PRAGMA temp_store;
1055 }
1056} {1}
1057do_test pragma-9.13 {
1058 execsql {
1059 PRAGMA temp_store = 2;
1060 PRAGMA temp_store;
1061 }
1062} {2}
1063do_test pragma-9.14 {
1064 execsql {
1065 PRAGMA temp_store = 3;
1066 PRAGMA temp_store;
1067 }
1068} {0}
danielk197795b289b2007-03-30 17:11:12 +00001069do_test pragma-9.15 {
1070 catchsql {
1071 BEGIN EXCLUSIVE;
1072 CREATE TEMP TABLE temp_table(t);
1073 INSERT INTO temp_table VALUES('valuable data');
1074 PRAGMA temp_store = 1;
1075 }
1076} {1 {temporary storage cannot be changed from within a transaction}}
1077do_test pragma-9.16 {
1078 execsql {
1079 SELECT * FROM temp_table;
1080 COMMIT;
1081 }
1082} {{valuable data}}
danielk1977983e2302008-07-08 07:35:51 +00001083
1084do_test pragma-9.17 {
1085 execsql {
1086 INSERT INTO temp_table VALUES('valuable data II');
1087 SELECT * FROM temp_table;
1088 }
1089} {{valuable data} {valuable data II}}
1090
1091do_test pragma-9.18 {
1092 set rc [catch {
1093 db eval {SELECT t FROM temp_table} {
1094 execsql {pragma temp_store = 1}
1095 }
1096 } msg]
1097 list $rc $msg
1098} {1 {temporary storage cannot be changed from within a transaction}}
1099
drh268283b2005-01-08 15:44:25 +00001100} ;# ifcapable pager_pragmas
tpoindex9a09a3c2004-12-20 19:01:32 +00001101
danielk1977cc6bd382005-01-10 02:48:49 +00001102ifcapable trigger {
1103
1104do_test pragma-10.0 {
1105 catchsql {
1106 DROP TABLE main.t1;
1107 }
1108 execsql {
1109 PRAGMA count_changes = 1;
1110
1111 CREATE TABLE t1(a PRIMARY KEY);
1112 CREATE TABLE t1_mirror(a);
1113 CREATE TABLE t1_mirror2(a);
1114 CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN
1115 INSERT INTO t1_mirror VALUES(new.a);
1116 END;
1117 CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN
1118 INSERT INTO t1_mirror2 VALUES(new.a);
1119 END;
1120 CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN
1121 UPDATE t1_mirror SET a = new.a WHERE a = old.a;
1122 END;
1123 CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN
1124 UPDATE t1_mirror2 SET a = new.a WHERE a = old.a;
1125 END;
1126 CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN
1127 DELETE FROM t1_mirror WHERE a = old.a;
1128 END;
1129 CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN
1130 DELETE FROM t1_mirror2 WHERE a = old.a;
1131 END;
1132 }
1133} {}
1134
1135do_test pragma-10.1 {
1136 execsql {
1137 INSERT INTO t1 VALUES(randstr(10,10));
1138 }
1139} {1}
1140do_test pragma-10.2 {
1141 execsql {
1142 UPDATE t1 SET a = randstr(10,10);
1143 }
1144} {1}
1145do_test pragma-10.3 {
1146 execsql {
1147 DELETE FROM t1;
1148 }
1149} {1}
1150
1151} ;# ifcapable trigger
1152
danielk197748af65a2005-02-09 03:20:37 +00001153ifcapable schema_pragmas {
1154 do_test pragma-11.1 {
1155 execsql2 {
1156 pragma collation_list;
1157 }
drh9b5adfa2008-01-20 23:19:56 +00001158 } {seq 0 name NOCASE seq 1 name RTRIM seq 2 name BINARY}
danielk197748af65a2005-02-09 03:20:37 +00001159 do_test pragma-11.2 {
1160 db collate New_Collation blah...
1161 execsql {
1162 pragma collation_list;
1163 }
drh9b5adfa2008-01-20 23:19:56 +00001164 } {0 New_Collation 1 NOCASE 2 RTRIM 3 BINARY}
danielk197748af65a2005-02-09 03:20:37 +00001165}
1166
danielk1977ddfb2f02006-02-17 12:25:14 +00001167ifcapable schema_pragmas&&tempdb {
1168 do_test pragma-12.1 {
1169 sqlite3 db2 test.db
1170 execsql {
1171 PRAGMA temp.table_info('abc');
1172 } db2
1173 } {}
1174 db2 close
1175
1176 do_test pragma-12.2 {
1177 sqlite3 db2 test.db
1178 execsql {
1179 PRAGMA temp.default_cache_size = 200;
1180 PRAGMA temp.default_cache_size;
1181 } db2
1182 } {200}
1183 db2 close
1184
1185 do_test pragma-12.3 {
1186 sqlite3 db2 test.db
1187 execsql {
1188 PRAGMA temp.cache_size = 400;
1189 PRAGMA temp.cache_size;
1190 } db2
1191 } {400}
1192 db2 close
1193}
1194
danielk19774b2688a2006-06-20 11:01:07 +00001195ifcapable bloblit {
1196
drh05a82982006-03-19 13:00:25 +00001197do_test pragma-13.1 {
1198 execsql {
1199 DROP TABLE IF EXISTS t4;
1200 PRAGMA vdbe_trace=on;
1201 PRAGMA vdbe_listing=on;
1202 PRAGMA sql_trace=on;
1203 CREATE TABLE t4(a INTEGER PRIMARY KEY,b);
1204 INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789');
1205 INSERT INTO t4(b) VALUES(randstr(30,30));
1206 INSERT INTO t4(b) VALUES(1.23456);
1207 INSERT INTO t4(b) VALUES(NULL);
1208 INSERT INTO t4(b) VALUES(0);
1209 INSERT INTO t4(b) SELECT b||b||b||b FROM t4;
1210 SELECT * FROM t4;
1211 }
1212 execsql {
1213 PRAGMA vdbe_trace=off;
1214 PRAGMA vdbe_listing=off;
1215 PRAGMA sql_trace=off;
1216 }
1217} {}
1218
danielk19774b2688a2006-06-20 11:01:07 +00001219} ;# ifcapable bloblit
1220
danielk197759a93792008-05-15 17:48:20 +00001221ifcapable pager_pragmas {
1222 db close
mistachkinfda06be2011-08-02 00:57:34 +00001223 forcedelete test.db
danielk197759a93792008-05-15 17:48:20 +00001224 sqlite3 db test.db
1225
1226 do_test pragma-14.1 {
1227 execsql { pragma auto_vacuum = 0 }
1228 execsql { pragma page_count }
1229 } {0}
1230
1231 do_test pragma-14.2 {
1232 execsql {
1233 CREATE TABLE abc(a, b, c);
1234 PRAGMA page_count;
1235 }
1236 } {2}
drh5d16a9a2011-10-13 14:41:22 +00001237 do_test pragma-14.2uc {
1238 execsql {pragma PAGE_COUNT}
1239 } {2}
danielk197759a93792008-05-15 17:48:20 +00001240
1241 do_test pragma-14.3 {
1242 execsql {
1243 BEGIN;
1244 CREATE TABLE def(a, b, c);
1245 PRAGMA page_count;
1246 }
1247 } {3}
drh5d16a9a2011-10-13 14:41:22 +00001248 do_test pragma-14.3uc {
1249 execsql {pragma PAGE_COUNT}
1250 } {3}
danielk197759a93792008-05-15 17:48:20 +00001251
1252 do_test pragma-14.4 {
1253 set page_size [db one {pragma page_size}]
1254 expr [file size test.db] / $page_size
1255 } {2}
1256
1257 do_test pragma-14.5 {
1258 execsql {
1259 ROLLBACK;
1260 PRAGMA page_count;
1261 }
1262 } {2}
1263
1264 do_test pragma-14.6 {
mistachkinfda06be2011-08-02 00:57:34 +00001265 forcedelete test2.db
danielk197759a93792008-05-15 17:48:20 +00001266 sqlite3 db2 test2.db
1267 execsql {
1268 PRAGMA auto_vacuum = 0;
1269 CREATE TABLE t1(a, b, c);
1270 CREATE TABLE t2(a, b, c);
1271 CREATE TABLE t3(a, b, c);
1272 CREATE TABLE t4(a, b, c);
1273 } db2
1274 db2 close
1275 execsql {
1276 ATTACH 'test2.db' AS aux;
1277 PRAGMA aux.page_count;
1278 }
1279 } {5}
drh5d16a9a2011-10-13 14:41:22 +00001280 do_test pragma-14.6uc {
1281 execsql {pragma AUX.PAGE_COUNT}
1282 } {5}
danielk197759a93792008-05-15 17:48:20 +00001283}
1284
danielk19778cf6c552008-06-23 16:53:46 +00001285# Test that the value set using the cache_size pragma is not reset when the
1286# schema is reloaded.
1287#
1288ifcapable pager_pragmas {
1289 db close
1290 sqlite3 db test.db
1291 do_test pragma-15.1 {
1292 execsql {
1293 PRAGMA cache_size=59;
1294 PRAGMA cache_size;
1295 }
1296 } {59}
1297 do_test pragma-15.2 {
1298 sqlite3 db2 test.db
1299 execsql {
1300 CREATE TABLE newtable(a, b, c);
1301 } db2
1302 db2 close
1303 } {}
1304 do_test pragma-15.3 {
1305 # Evaluating this statement will cause the schema to be reloaded (because
1306 # the schema was changed by another connection in pragma-15.2). At one
1307 # point there was a bug that reset the cache_size to its default value
1308 # when this happened.
1309 execsql { SELECT * FROM sqlite_master }
1310 execsql { PRAGMA cache_size }
1311 } {59}
1312}
1313
danielk19775558a8a2005-01-17 07:53:44 +00001314# Reset the sqlite3_temp_directory variable for the next run of tests:
1315sqlite3 dbX :memory:
1316dbX eval {PRAGMA temp_store_directory = ""}
1317dbX close
1318
danielk1977838cce42009-01-12 14:01:45 +00001319ifcapable lock_proxy_pragmas&&prefer_proxy_locking {
aswiftaebf4132008-11-21 00:10:35 +00001320 set sqlite_hostid_num 1
1321
1322 set using_proxy 0
1323 foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {
1324 set using_proxy $value
1325 }
1326
1327 # Test the lock_proxy_file pragmas.
1328 #
1329 db close
1330 set env(SQLITE_FORCE_PROXY_LOCKING) "0"
1331
1332 sqlite3 db test.db
1333 do_test pragma-16.1 {
1334 execsql {
1335 PRAGMA lock_proxy_file="mylittleproxy";
1336 select * from sqlite_master;
1337 }
1338 execsql {
1339 PRAGMA lock_proxy_file;
1340 }
1341 } {mylittleproxy}
1342
1343 do_test pragma-16.2 {
1344 sqlite3 db2 test.db
1345 execsql {
1346 PRAGMA lock_proxy_file="mylittleproxy";
1347 } db2
1348 } {}
1349
1350 db2 close
1351 do_test pragma-16.2.1 {
1352 sqlite3 db2 test.db
1353 execsql {
1354 PRAGMA lock_proxy_file=":auto:";
1355 select * from sqlite_master;
1356 } db2
1357 execsql {
1358 PRAGMA lock_proxy_file;
1359 } db2
1360 } {mylittleproxy}
1361
1362 db2 close
1363 do_test pragma-16.3 {
1364 sqlite3 db2 test.db
1365 execsql {
1366 PRAGMA lock_proxy_file="myotherproxy";
1367 } db2
1368 catchsql {
1369 select * from sqlite_master;
1370 } db2
1371 } {1 {database is locked}}
1372
1373 do_test pragma-16.4 {
1374 db2 close
1375 db close
1376 sqlite3 db2 test.db
1377 execsql {
1378 PRAGMA lock_proxy_file="myoriginalproxy";
1379 PRAGMA lock_proxy_file="myotherproxy";
1380 PRAGMA lock_proxy_file;
1381 } db2
1382 } {myotherproxy}
1383
1384 db2 close
1385 set env(SQLITE_FORCE_PROXY_LOCKING) "1"
1386 do_test pragma-16.5 {
1387 sqlite3 db2 test.db
1388 execsql {
1389 PRAGMA lock_proxy_file=":auto:";
1390 PRAGMA lock_proxy_file;
1391 } db2
1392 } {myotherproxy}
1393
1394 do_test pragma-16.6 {
1395 db2 close
1396 sqlite3 db2 test2.db
1397 set lockpath [execsql {
1398 PRAGMA lock_proxy_file=":auto:";
1399 PRAGMA lock_proxy_file;
1400 } db2]
1401 string match "*test2.db:auto:" $lockpath
1402 } {1}
1403
1404 set sqlite_hostid_num 2
1405 do_test pragma-16.7 {
dan14d14602010-10-06 16:42:52 +00001406 list [catch {
1407 sqlite3 db test2.db
1408 execsql {
1409 PRAGMA lock_proxy_file=":auto:";
1410 select * from sqlite_master;
1411 }
1412 } msg] $msg
aswiftaebf4132008-11-21 00:10:35 +00001413 } {1 {database is locked}}
1414 db close
1415
1416 do_test pragma-16.8 {
dan14d14602010-10-06 16:42:52 +00001417 list [catch {
1418 sqlite3 db test2.db
1419 execsql { select * from sqlite_master }
1420 } msg] $msg
aswiftaebf4132008-11-21 00:10:35 +00001421 } {1 {database is locked}}
1422
1423 db2 close
1424 do_test pragma-16.8.1 {
1425 execsql {
1426 PRAGMA lock_proxy_file="yetanotherproxy";
1427 PRAGMA lock_proxy_file;
1428 }
1429 } {yetanotherproxy}
1430 do_test pragma-16.8.2 {
1431 execsql {
1432 create table mine(x);
1433 }
1434 } {}
1435
1436 db close
1437 do_test pragma-16.9 {
1438 sqlite3 db proxytest.db
1439 set lockpath2 [execsql {
1440 PRAGMA lock_proxy_file=":auto:";
1441 PRAGMA lock_proxy_file;
1442 } db]
1443 string match "*proxytest.db:auto:" $lockpath2
1444 } {1}
1445
1446 set env(SQLITE_FORCE_PROXY_LOCKING) $using_proxy
1447 set sqlite_hostid_num 0
1448}
drhd2cb50b2009-01-09 21:41:17 +00001449
1450# Parsing of auto_vacuum settings.
1451#
1452foreach {autovac_setting val} {
1453 0 0
1454 1 1
1455 2 2
1456 3 0
1457 -1 0
1458 none 0
1459 NONE 0
1460 NoNe 0
1461 full 1
1462 FULL 1
1463 incremental 2
1464 INCREMENTAL 2
1465 -1234 0
1466 1234 0
1467} {
1468 do_test pragma-17.1.$autovac_setting {
1469 catch {db close}
1470 sqlite3 db :memory:
1471 execsql "
1472 PRAGMA auto_vacuum=$::autovac_setting;
1473 PRAGMA auto_vacuum;
1474 "
1475 } $val
1476}
1477
1478# Parsing of temp_store settings.
1479#
1480foreach {temp_setting val} {
1481 0 0
1482 1 1
1483 2 2
1484 3 0
1485 -1 0
1486 file 1
1487 FILE 1
1488 fIlE 1
1489 memory 2
1490 MEMORY 2
1491 MeMoRy 2
1492} {
1493 do_test pragma-18.1.$temp_setting {
1494 catch {db close}
1495 sqlite3 db :memory:
1496 execsql "
1497 PRAGMA temp_store=$::temp_setting;
1498 PRAGMA temp_store=$::temp_setting;
1499 PRAGMA temp_store;
1500 "
1501 } $val
1502}
1503
drh92c700d2012-02-22 19:56:17 +00001504# The SQLITE_FCNTL_PRAGMA logic, with error handling.
1505#
1506db close
1507testvfs tvfs
1508sqlite3 db test.db -vfs tvfs
1509do_test pragma-19.1 {
1510 catchsql {PRAGMA error}
1511} {1 {SQL logic error or missing database}}
1512do_test pragma-19.2 {
1513 catchsql {PRAGMA error='This is the error message'}
1514} {1 {This is the error message}}
1515do_test pragma-19.3 {
1516 catchsql {PRAGMA error='7 This is the error message'}
1517} {1 {This is the error message}}
1518do_test pragma-19.4 {
1519 catchsql {PRAGMA error=7}
1520} {1 {out of memory}}
drhc8517f62012-02-22 20:08:49 +00001521do_test pragma-19.5 {
mistachkin5b044542012-03-02 22:41:06 +00001522 file tail [lindex [execsql {PRAGMA filename}] 0]
drhc8517f62012-02-22 20:08:49 +00001523} {test.db}
drh92c700d2012-02-22 19:56:17 +00001524
drhcc716452012-06-06 23:23:23 +00001525if {$tcl_platform(platform)=="windows"} {
mistachkina112d142012-03-14 00:44:01 +00001526# Test data_store_directory pragma
1527#
1528db close
1529sqlite3 db test.db
1530file mkdir data_dir
1531do_test pragma-20.1 {
1532 catchsql {PRAGMA data_store_directory}
1533} {0 {}}
1534do_test pragma-20.2 {
1535 set pwd [string map {' ''} [file nativename [get_pwd]]]
1536 catchsql "PRAGMA data_store_directory='$pwd';"
1537} {0 {}}
1538do_test pragma-20.3 {
1539 catchsql {PRAGMA data_store_directory}
1540} [list 0 [list [file nativename [get_pwd]]]]
1541do_test pragma-20.4 {
1542 set pwd [string map {' ''} [file nativename \
1543 [file join [get_pwd] data_dir]]]
1544 catchsql "PRAGMA data_store_directory='$pwd';"
1545} {0 {}}
1546do_test pragma-20.5 {
1547 sqlite3 db2 test2.db
1548 catchsql "PRAGMA database_list;" db2
1549} [list 0 [list 0 main [file nativename \
1550 [file join [get_pwd] data_dir test2.db]]]]
1551catch {db2 close}
1552do_test pragma-20.6 {
1553 sqlite3 db2 [file join [get_pwd] test2.db]
1554 catchsql "PRAGMA database_list;" db2
1555} [list 0 [list 0 main [file nativename \
1556 [file join [get_pwd] test2.db]]]]
1557catch {db2 close}
1558do_test pragma-20.7 {
1559 catchsql "PRAGMA data_store_directory='';"
1560} {0 {}}
1561do_test pragma-20.8 {
1562 catchsql {PRAGMA data_store_directory}
1563} {0 {}}
drh92c700d2012-02-22 19:56:17 +00001564
mistachkina112d142012-03-14 00:44:01 +00001565forcedelete data_dir
drhcc716452012-06-06 23:23:23 +00001566} ;# endif windows
drhcd61c282002-03-06 22:01:34 +00001567
dan5885e762012-07-16 10:06:12 +00001568do_test 21.1 {
1569 # Create a corrupt database in testerr.db. And a non-corrupt at test.db.
1570 #
1571 db close
1572 forcedelete test.db
1573 sqlite3 db test.db
1574 execsql {
1575 PRAGMA page_size = 1024;
1576 PRAGMA auto_vacuum = 0;
1577 CREATE TABLE t1(a PRIMARY KEY, b);
1578 INSERT INTO t1 VALUES(1, 1);
1579 }
1580 for {set i 0} {$i < 10} {incr i} {
1581 execsql { INSERT INTO t1 SELECT a + (1 << $i), b + (1 << $i) FROM t1 }
1582 }
1583 db close
1584 forcecopy test.db testerr.db
1585 hexio_write testerr.db 15000 [string repeat 55 100]
1586} {100}
1587
1588set mainerr {*** in database main ***
1589Multiple uses for byte 672 of page 15}
1590set auxerr {*** in database aux ***
1591Multiple uses for byte 672 of page 15}
1592
1593do_test 22.2 {
1594 catch { db close }
1595 sqlite3 db testerr.db
1596 execsql { PRAGMA integrity_check }
1597} [list $mainerr]
1598
1599do_test 22.3.1 {
1600 catch { db close }
1601 sqlite3 db test.db
1602 execsql {
1603 ATTACH 'testerr.db' AS 'aux';
1604 PRAGMA integrity_check;
1605 }
1606} [list $auxerr]
1607do_test 22.3.2 {
1608 execsql { PRAGMA main.integrity_check; }
1609} {ok}
1610do_test 22.3.3 {
1611 execsql { PRAGMA aux.integrity_check; }
1612} [list $auxerr]
1613
1614do_test 22.4.1 {
1615 catch { db close }
1616 sqlite3 db testerr.db
1617 execsql {
1618 ATTACH 'test.db' AS 'aux';
1619 PRAGMA integrity_check;
1620 }
1621} [list $mainerr]
1622do_test 22.4.2 {
1623 execsql { PRAGMA main.integrity_check; }
1624} [list $mainerr]
1625do_test 22.4.3 {
1626 execsql { PRAGMA aux.integrity_check; }
1627} {ok}
1628
drhc95e01d2013-02-14 16:16:05 +00001629db close
1630forcedelete test.db test.db-wal test.db-journal
1631sqlite3 db test.db
1632sqlite3 db2 test.db
1633do_test 23.1 {
1634 db eval {
1635 CREATE TABLE t1(a INTEGER PRIMARY KEY,b,c,d);
1636 CREATE INDEX i1 ON t1(b,c);
1637 CREATE INDEX i2 ON t1(c,d);
1638 CREATE TABLE t2(x INTEGER REFERENCES t1);
1639 }
1640 db2 eval {SELECT name FROM sqlite_master}
1641} {t1 i1 i2 t2}
1642do_test 23.2 {
1643 db eval {
1644 DROP INDEX i2;
1645 CREATE INDEX i2 ON t1(c,d,b);
1646 }
1647 db2 eval {PRAGMA index_info(i2)}
1648} {0 2 c 1 3 d 2 1 b}
1649do_test 23.3 {
1650 db eval {
1651 CREATE INDEX i3 ON t1(d,b,c);
1652 }
1653 db2 eval {PRAGMA index_list(t1)}
1654} {0 i3 0 1 i2 0 2 i1 0}
1655do_test 23.4 {
1656 db eval {
1657 ALTER TABLE t1 ADD COLUMN e;
1658 }
1659 db2 eval {
1660 PRAGMA table_info(t1);
1661 }
1662} {/4 e {} 0 {} 0/}
1663do_test 23.5 {
1664 db eval {
1665 DROP TABLE t2;
1666 CREATE TABLE t2(x, y INTEGER REFERENCES t1);
1667 }
1668 db2 eval {
1669 PRAGMA foreign_key_list(t2);
1670 }
1671} {0 0 t1 y {} {NO ACTION} {NO ACTION} NONE}
1672
drhcd61c282002-03-06 22:01:34 +00001673finish_test