blob: 580948038ef53067b919262f367adc6e7059701e [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#
danielk1977ddfb2f02006-02-17 12:25:14 +000015# $Id: pragma.test,v 1.40 2006/02/17 12:25:16 danielk1977 Exp $
drhcd61c282002-03-06 22:01:34 +000016
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
danielk197791cf71b2004-06-26 06:37:06 +000020# Test organization:
21#
22# pragma-1.*: Test cache_size, default_cache_size and synchronous on main db.
23# pragma-2.*: Test synchronous on attached db.
24# pragma-3.*: Test detection of table/index inconsistency by integrity_check.
25# pragma-4.*: Test cache_size and default_cache_size on attached db.
26# pragma-5.*: Test that pragma synchronous may not be used inside of a
27# transaction.
danielk1977cc6bd382005-01-10 02:48:49 +000028# pragma-6.*: Test schema-query pragmas.
29# pragma-7.*: Miscellaneous tests.
30# pragma-8.*: Test user_version and schema_version pragmas.
tpoindex9a09a3c2004-12-20 19:01:32 +000031# pragma-9.*: Test temp_store and temp_store_directory.
danielk1977cc6bd382005-01-10 02:48:49 +000032# pragma-10.*: Test the count_changes pragma in the presence of triggers.
danielk197748af65a2005-02-09 03:20:37 +000033# pragma-11.*: Test the collation_list pragma.
danielk197791cf71b2004-06-26 06:37:06 +000034#
35
drhcd61c282002-03-06 22:01:34 +000036# Delete the preexisting database to avoid the special setup
37# that the "all.test" script does.
38#
39db close
40file delete test.db
drhdddca282006-01-03 00:33:50 +000041sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
drhcd61c282002-03-06 22:01:34 +000042
danielk1977c7b4a442004-11-23 10:52:51 +000043ifcapable pager_pragmas {
drhcd61c282002-03-06 22:01:34 +000044do_test pragma-1.1 {
45 execsql {
46 PRAGMA cache_size;
47 PRAGMA default_cache_size;
48 PRAGMA synchronous;
drhcd61c282002-03-06 22:01:34 +000049 }
danielk197791cf71b2004-06-26 06:37:06 +000050} {2000 2000 2}
drhcd61c282002-03-06 22:01:34 +000051do_test pragma-1.2 {
52 execsql {
drheb43e5c2005-05-22 20:30:39 +000053 PRAGMA synchronous=OFF;
drhcd61c282002-03-06 22:01:34 +000054 PRAGMA cache_size=1234;
55 PRAGMA cache_size;
56 PRAGMA default_cache_size;
57 PRAGMA synchronous;
drhcd61c282002-03-06 22:01:34 +000058 }
drheb43e5c2005-05-22 20:30:39 +000059} {1234 2000 0}
drhcd61c282002-03-06 22:01:34 +000060do_test pragma-1.3 {
61 db close
drhef4ac8f2004-06-19 00:16:31 +000062 sqlite3 db test.db
drhcd61c282002-03-06 22:01:34 +000063 execsql {
64 PRAGMA cache_size;
65 PRAGMA default_cache_size;
66 PRAGMA synchronous;
drhcd61c282002-03-06 22:01:34 +000067 }
danielk197791cf71b2004-06-26 06:37:06 +000068} {2000 2000 2}
drhcd61c282002-03-06 22:01:34 +000069do_test pragma-1.4 {
70 execsql {
71 PRAGMA synchronous=OFF;
72 PRAGMA cache_size;
73 PRAGMA default_cache_size;
74 PRAGMA synchronous;
drhcd61c282002-03-06 22:01:34 +000075 }
danielk197791cf71b2004-06-26 06:37:06 +000076} {2000 2000 0}
drhcd61c282002-03-06 22:01:34 +000077do_test pragma-1.5 {
78 execsql {
79 PRAGMA cache_size=4321;
80 PRAGMA cache_size;
81 PRAGMA default_cache_size;
82 PRAGMA synchronous;
drhcd61c282002-03-06 22:01:34 +000083 }
danielk197791cf71b2004-06-26 06:37:06 +000084} {4321 2000 0}
drhcd61c282002-03-06 22:01:34 +000085do_test pragma-1.6 {
86 execsql {
87 PRAGMA synchronous=ON;
88 PRAGMA cache_size;
89 PRAGMA default_cache_size;
90 PRAGMA synchronous;
drhcd61c282002-03-06 22:01:34 +000091 }
danielk197791cf71b2004-06-26 06:37:06 +000092} {4321 2000 1}
drhcd61c282002-03-06 22:01:34 +000093do_test pragma-1.7 {
94 db close
drhef4ac8f2004-06-19 00:16:31 +000095 sqlite3 db test.db
drhcd61c282002-03-06 22:01:34 +000096 execsql {
97 PRAGMA cache_size;
98 PRAGMA default_cache_size;
99 PRAGMA synchronous;
drhcd61c282002-03-06 22:01:34 +0000100 }
danielk197791cf71b2004-06-26 06:37:06 +0000101} {2000 2000 2}
drhcd61c282002-03-06 22:01:34 +0000102do_test pragma-1.8 {
103 execsql {
drhcd61c282002-03-06 22:01:34 +0000104 PRAGMA default_cache_size=123;
105 PRAGMA cache_size;
106 PRAGMA default_cache_size;
107 PRAGMA synchronous;
drhcd61c282002-03-06 22:01:34 +0000108 }
danielk197791cf71b2004-06-26 06:37:06 +0000109} {123 123 2}
drh802d69a2005-02-13 23:34:24 +0000110do_test pragma-1.9.1 {
drhcd61c282002-03-06 22:01:34 +0000111 db close
drhdddca282006-01-03 00:33:50 +0000112 sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db]
drhcd61c282002-03-06 22:01:34 +0000113 execsql {
114 PRAGMA cache_size;
115 PRAGMA default_cache_size;
116 PRAGMA synchronous;
drhcd61c282002-03-06 22:01:34 +0000117 }
danielk197791cf71b2004-06-26 06:37:06 +0000118} {123 123 2}
drh802d69a2005-02-13 23:34:24 +0000119ifcapable vacuum {
120 do_test pragma-1.9.2 {
121 execsql {
122 VACUUM;
123 PRAGMA cache_size;
124 PRAGMA default_cache_size;
125 PRAGMA synchronous;
126 }
127 } {123 123 2}
128}
danielk197791cf71b2004-06-26 06:37:06 +0000129do_test pragma-1.10 {
drh5a387052003-01-11 14:19:51 +0000130 execsql {
drh4303fee2003-02-15 23:09:17 +0000131 PRAGMA synchronous=NORMAL;
132 PRAGMA cache_size;
133 PRAGMA default_cache_size;
134 PRAGMA synchronous;
drh4303fee2003-02-15 23:09:17 +0000135 }
danielk197791cf71b2004-06-26 06:37:06 +0000136} {123 123 1}
137do_test pragma-1.11 {
drh4303fee2003-02-15 23:09:17 +0000138 execsql {
139 PRAGMA synchronous=FULL;
140 PRAGMA cache_size;
141 PRAGMA default_cache_size;
142 PRAGMA synchronous;
drh4303fee2003-02-15 23:09:17 +0000143 }
danielk197791cf71b2004-06-26 06:37:06 +0000144} {123 123 2}
145do_test pragma-1.12 {
drh4303fee2003-02-15 23:09:17 +0000146 db close
drhdddca282006-01-03 00:33:50 +0000147 sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db]
drh4303fee2003-02-15 23:09:17 +0000148 execsql {
149 PRAGMA cache_size;
150 PRAGMA default_cache_size;
151 PRAGMA synchronous;
drh4303fee2003-02-15 23:09:17 +0000152 }
danielk197791cf71b2004-06-26 06:37:06 +0000153} {123 123 2}
154
drh5260f7e2004-06-26 19:35:29 +0000155# Make sure the pragma handler understands numeric values in addition
156# to keywords like "off" and "full".
157#
158do_test pragma-1.13 {
159 execsql {
160 PRAGMA synchronous=0;
161 PRAGMA synchronous;
162 }
163} {0}
164do_test pragma-1.14 {
165 execsql {
166 PRAGMA synchronous=2;
167 PRAGMA synchronous;
168 }
169} {2}
danielk1977c7b4a442004-11-23 10:52:51 +0000170} ;# ifcapable pager_pragmas
drh5260f7e2004-06-26 19:35:29 +0000171
172# Test turning "flag" pragmas on and off.
173#
174do_test pragma-1.15 {
175 execsql {
176 PRAGMA vdbe_listing=YES;
177 PRAGMA vdbe_listing;
178 }
179} {1}
180do_test pragma-1.16 {
181 execsql {
182 PRAGMA vdbe_listing=NO;
183 PRAGMA vdbe_listing;
184 }
185} {0}
186do_test pragma-1.17 {
187 execsql {
188 PRAGMA parser_trace=ON;
189 PRAGMA parser_trace=OFF;
190 }
191} {}
192do_test pragma-1.18 {
193 execsql {
194 PRAGMA bogus = -1234; -- Parsing of negative values
195 }
196} {}
197
danielk197791cf71b2004-06-26 06:37:06 +0000198# Test modifying the safety_level of an attached database.
199do_test pragma-2.1 {
200 file delete -force test2.db
201 file delete -force test2.db-journal
drh4303fee2003-02-15 23:09:17 +0000202 execsql {
danielk197791cf71b2004-06-26 06:37:06 +0000203 ATTACH 'test2.db' AS aux;
204 }
205} {}
danielk1977c7b4a442004-11-23 10:52:51 +0000206ifcapable pager_pragmas {
danielk197791cf71b2004-06-26 06:37:06 +0000207do_test pragma-2.2 {
drh4303fee2003-02-15 23:09:17 +0000208 execsql {
danielk197791cf71b2004-06-26 06:37:06 +0000209 pragma aux.synchronous;
210 }
211} {2}
212do_test pragma-2.3 {
213 execsql {
214 pragma aux.synchronous = OFF;
215 pragma aux.synchronous;
216 pragma synchronous;
217 }
218} {0 2}
219do_test pragma-2.4 {
220 execsql {
221 pragma aux.synchronous = ON;
222 pragma synchronous;
223 pragma aux.synchronous;
224 }
225} {2 1}
danielk1977c7b4a442004-11-23 10:52:51 +0000226} ;# ifcapable pager_pragmas
drh4303fee2003-02-15 23:09:17 +0000227
drhed717fe2003-06-15 23:42:24 +0000228# Construct a corrupted index and make sure the integrity_check
229# pragma finds it.
230#
drh25d65432004-07-22 15:02:25 +0000231# These tests won't work if the database is encrypted
232#
drhed717fe2003-06-15 23:42:24 +0000233do_test pragma-3.1 {
234 execsql {
235 BEGIN;
236 CREATE TABLE t2(a,b,c);
237 CREATE INDEX i2 ON t2(a);
238 INSERT INTO t2 VALUES(11,2,3);
239 INSERT INTO t2 VALUES(22,3,4);
240 COMMIT;
241 SELECT rowid, * from t2;
242 }
243} {1 11 2 3 2 22 3 4}
drh40e016e2004-11-04 14:47:11 +0000244if {![sqlite3 -has-codec] && $sqlite_options(integrityck)} {
drh25d65432004-07-22 15:02:25 +0000245 do_test pragma-3.2 {
246 set rootpage [execsql {SELECT rootpage FROM sqlite_master WHERE name='i2'}]
247 set db [btree_open test.db 100 0]
248 btree_begin_transaction $db
249 set c [btree_cursor $db $rootpage 1]
250 btree_first $c
251 btree_delete $c
252 btree_commit $db
253 btree_close $db
254 execsql {PRAGMA integrity_check}
255 } {{rowid 1 missing from index i2} {wrong # of entries in index i2}}
256}
danielk197791cf71b2004-06-26 06:37:06 +0000257do_test pragma-3.3 {
258 execsql {
259 DROP INDEX i2;
260 }
261} {}
262
263# Test modifying the cache_size of an attached database.
danielk1977c7b4a442004-11-23 10:52:51 +0000264ifcapable pager_pragmas {
danielk197791cf71b2004-06-26 06:37:06 +0000265do_test pragma-4.1 {
266 execsql {
267 pragma aux.cache_size;
268 pragma aux.default_cache_size;
269 }
270} {2000 2000}
drh1bdd9b52004-04-23 17:04:44 +0000271do_test pragma-4.2 {
272 execsql {
danielk197791cf71b2004-06-26 06:37:06 +0000273 pragma aux.cache_size = 50;
274 pragma aux.cache_size;
275 pragma aux.default_cache_size;
276 }
277} {50 2000}
drh1bdd9b52004-04-23 17:04:44 +0000278do_test pragma-4.3 {
279 execsql {
danielk197791cf71b2004-06-26 06:37:06 +0000280 pragma aux.default_cache_size = 456;
281 pragma aux.cache_size;
282 pragma aux.default_cache_size;
283 }
284} {456 456}
drh1bdd9b52004-04-23 17:04:44 +0000285do_test pragma-4.4 {
286 execsql {
danielk197791cf71b2004-06-26 06:37:06 +0000287 pragma cache_size;
288 pragma default_cache_size;
289 }
290} {123 123}
drh1bdd9b52004-04-23 17:04:44 +0000291do_test pragma-4.5 {
292 execsql {
danielk197791cf71b2004-06-26 06:37:06 +0000293 DETACH aux;
294 ATTACH 'test3.db' AS aux;
295 pragma aux.cache_size;
296 pragma aux.default_cache_size;
297 }
298} {2000 2000}
drh1bdd9b52004-04-23 17:04:44 +0000299do_test pragma-4.6 {
300 execsql {
danielk197791cf71b2004-06-26 06:37:06 +0000301 DETACH aux;
302 ATTACH 'test2.db' AS aux;
303 pragma aux.cache_size;
304 pragma aux.default_cache_size;
305 }
306} {456 456}
danielk1977c7b4a442004-11-23 10:52:51 +0000307} ;# ifcapable pager_pragmas
drh1bdd9b52004-04-23 17:04:44 +0000308
danielk197791cf71b2004-06-26 06:37:06 +0000309# Test that modifying the sync-level in the middle of a transaction is
310# disallowed.
danielk1977c7b4a442004-11-23 10:52:51 +0000311ifcapable pager_pragmas {
danielk197791cf71b2004-06-26 06:37:06 +0000312do_test pragma-5.0 {
drh1bdd9b52004-04-23 17:04:44 +0000313 execsql {
danielk197791cf71b2004-06-26 06:37:06 +0000314 pragma synchronous;
315 }
316} {2}
317do_test pragma-5.1 {
drh1bdd9b52004-04-23 17:04:44 +0000318 catchsql {
319 BEGIN;
danielk197791cf71b2004-06-26 06:37:06 +0000320 pragma synchronous = OFF;
321 }
322} {1 {Safety level may not be changed inside a transaction}}
323do_test pragma-5.2 {
324 execsql {
325 pragma synchronous;
326 }
327} {2}
drh5260f7e2004-06-26 19:35:29 +0000328catchsql {COMMIT;}
danielk1977c7b4a442004-11-23 10:52:51 +0000329} ;# ifcapable pager_pragmas
drh5260f7e2004-06-26 19:35:29 +0000330
331# Test schema-query pragmas
332#
danielk197727188fb2004-11-23 10:13:03 +0000333ifcapable schema_pragmas {
danielk197753c0f742005-03-29 03:10:59 +0000334ifcapable tempdb {
335 do_test pragma-6.1 {
336 set res {}
337 execsql {SELECT * FROM sqlite_temp_master}
338 foreach {idx name file} [execsql {pragma database_list}] {
339 lappend res $idx $name
340 }
341 set res
342 } {0 main 1 temp 2 aux}
343}
drh5260f7e2004-06-26 19:35:29 +0000344do_test pragma-6.2 {
345 execsql {
346 pragma table_info(t2)
347 }
drh9f6696a2006-02-09 16:52:23 +0000348} {0 a numeric 0 {} 0 1 b numeric 0 {} 0 2 c numeric 0 {} 0}
drh6bf89572004-11-03 16:27:01 +0000349ifcapable {foreignkey} {
350 do_test pragma-6.3 {
351 execsql {
352 CREATE TABLE t3(a int references t2(b), b UNIQUE);
353 pragma foreign_key_list(t3);
354 }
355 } {0 0 t2 a b}
356 do_test pragma-6.4 {
357 execsql {
358 pragma index_list(t3);
359 }
360 } {0 sqlite_autoindex_t3_1 1}
361}
362ifcapable {!foreignkey} {
363 execsql {CREATE TABLE t3(a,b UNIQUE)}
364}
drh5260f7e2004-06-26 19:35:29 +0000365do_test pragma-6.5 {
366 execsql {
367 CREATE INDEX t3i1 ON t3(a,b);
368 pragma index_info(t3i1);
369 }
370} {0 0 a 1 1 b}
danielk197727188fb2004-11-23 10:13:03 +0000371} ;# ifcapable schema_pragmas
drh5260f7e2004-06-26 19:35:29 +0000372# Miscellaneous tests
373#
danielk197727188fb2004-11-23 10:13:03 +0000374ifcapable schema_pragmas {
drh5260f7e2004-06-26 19:35:29 +0000375do_test pragma-7.1 {
376 # Make sure a pragma knows to read the schema if it needs to
377 db close
378 sqlite3 db test.db
379 execsql {
380 pragma index_list(t3);
381 }
382} {0 t3i1 0 1 sqlite_autoindex_t3_1 1}
danielk197727188fb2004-11-23 10:13:03 +0000383} ;# ifcapable schema_pragmas
drh6c626082004-11-14 21:56:29 +0000384ifcapable {utf16} {
385 do_test pragma-7.2 {
386 db close
387 sqlite3 db test.db
388 catchsql {
389 pragma encoding=bogus;
390 }
391 } {1 {unsupported encoding: bogus}}
392}
danielk197753c0f742005-03-29 03:10:59 +0000393ifcapable tempdb {
394 do_test pragma-7.3 {
395 db close
396 sqlite3 db test.db
397 execsql {
398 pragma lock_status;
399 }
400 } {main unlocked temp closed}
401} else {
402 do_test pragma-7.3 {
403 db close
404 sqlite3 db test.db
405 execsql {
406 pragma lock_status;
407 }
408 } {main unlocked}
409}
drh5260f7e2004-06-26 19:35:29 +0000410
411
danielk1977dae24952004-11-11 05:10:43 +0000412#----------------------------------------------------------------------
danielk1977b92b70b2004-11-12 16:11:59 +0000413# Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA
414# user_version" statements.
danielk1977dae24952004-11-11 05:10:43 +0000415#
danielk1977b92b70b2004-11-12 16:11:59 +0000416# pragma-8.1: PRAGMA schema_version
417# pragma-8.2: PRAGMA user_version
danielk1977dae24952004-11-11 05:10:43 +0000418#
419
danielk197711cf9fb2004-11-23 11:16:42 +0000420ifcapable schema_version {
421
danielk1977b92b70b2004-11-12 16:11:59 +0000422# First check that we can set the schema version and then retrieve the
danielk1977dae24952004-11-11 05:10:43 +0000423# same value.
424do_test pragma-8.1.1 {
425 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000426 PRAGMA schema_version = 105;
danielk1977dae24952004-11-11 05:10:43 +0000427 }
428} {}
429do_test pragma-8.1.2 {
430 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000431 PRAGMA schema_version;
danielk1977dae24952004-11-11 05:10:43 +0000432 }
433} 105
434do_test pragma-8.1.3 {
435 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000436 PRAGMA schema_version = 106;
danielk1977dae24952004-11-11 05:10:43 +0000437 }
438} {}
439do_test pragma-8.1.4 {
440 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000441 PRAGMA schema_version;
danielk1977dae24952004-11-11 05:10:43 +0000442 }
443} 106
444
danielk1977b92b70b2004-11-12 16:11:59 +0000445# Check that creating a table modifies the schema-version (this is really
446# to verify that the value being read is in fact the schema version).
danielk1977dae24952004-11-11 05:10:43 +0000447do_test pragma-8.1.5 {
448 execsql {
449 CREATE TABLE t4(a, b, c);
450 INSERT INTO t4 VALUES(1, 2, 3);
451 SELECT * FROM t4;
452 }
453} {1 2 3}
454do_test pragma-8.1.6 {
455 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000456 PRAGMA schema_version;
danielk1977dae24952004-11-11 05:10:43 +0000457 }
458} 107
459
460# Now open a second connection to the database. Ensure that changing the
danielk1977b92b70b2004-11-12 16:11:59 +0000461# schema-version using the first connection forces the second connection
danielk1977dae24952004-11-11 05:10:43 +0000462# to reload the schema. This has to be done using the C-API test functions,
463# because the TCL API accounts for SCHEMA_ERROR and retries the query.
464do_test pragma-8.1.7 {
drhdddca282006-01-03 00:33:50 +0000465 sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]
danielk1977dae24952004-11-11 05:10:43 +0000466 execsql {
467 SELECT * FROM t4;
468 } db2
469} {1 2 3}
470do_test pragma-8.1.8 {
471 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000472 PRAGMA schema_version = 108;
danielk1977dae24952004-11-11 05:10:43 +0000473 }
474} {}
475do_test pragma-8.1.9 {
476 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY]
477 sqlite3_step $::STMT
478} SQLITE_ERROR
479do_test pragma-8.1.10 {
480 sqlite3_finalize $::STMT
481} SQLITE_SCHEMA
482
danielk1977b92b70b2004-11-12 16:11:59 +0000483# Make sure the schema-version can be manipulated in an attached database.
danielk1977dae24952004-11-11 05:10:43 +0000484file delete -force test2.db
485file delete -force test2.db-journal
486do_test pragma-8.1.11 {
487 execsql {
488 ATTACH 'test2.db' AS aux;
489 CREATE TABLE aux.t1(a, b, c);
danielk1977b92b70b2004-11-12 16:11:59 +0000490 PRAGMA aux.schema_version = 205;
danielk1977dae24952004-11-11 05:10:43 +0000491 }
492} {}
493do_test pragma-8.1.12 {
494 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000495 PRAGMA aux.schema_version;
danielk1977dae24952004-11-11 05:10:43 +0000496 }
497} 205
498do_test pragma-8.1.13 {
499 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000500 PRAGMA schema_version;
danielk1977dae24952004-11-11 05:10:43 +0000501 }
502} 108
503
danielk1977b92b70b2004-11-12 16:11:59 +0000504# And check that modifying the schema-version in an attached database
danielk1977dae24952004-11-11 05:10:43 +0000505# forces the second connection to reload the schema.
506do_test pragma-8.1.14 {
drhdddca282006-01-03 00:33:50 +0000507 sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2]
danielk1977dae24952004-11-11 05:10:43 +0000508 execsql {
509 ATTACH 'test2.db' AS aux;
510 SELECT * FROM aux.t1;
511 } db2
512} {}
513do_test pragma-8.1.15 {
514 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000515 PRAGMA aux.schema_version = 206;
danielk1977dae24952004-11-11 05:10:43 +0000516 }
517} {}
518do_test pragma-8.1.16 {
519 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY]
520 sqlite3_step $::STMT
521} SQLITE_ERROR
522do_test pragma-8.1.17 {
523 sqlite3_finalize $::STMT
524} SQLITE_SCHEMA
525do_test pragma-8.1.18 {
526 db2 close
527} {}
528
danielk1977b92b70b2004-11-12 16:11:59 +0000529# Now test that the user-version can be read and written (and that we aren't
530# accidentally manipulating the schema-version instead).
danielk1977dae24952004-11-11 05:10:43 +0000531do_test pragma-8.2.1 {
532 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000533 PRAGMA user_version;
danielk1977dae24952004-11-11 05:10:43 +0000534 }
535} {0}
536do_test pragma-8.2.2 {
537 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000538 PRAGMA user_version = 2;
danielk1977dae24952004-11-11 05:10:43 +0000539 }
540} {}
drh802d69a2005-02-13 23:34:24 +0000541do_test pragma-8.2.3.1 {
danielk1977dae24952004-11-11 05:10:43 +0000542 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000543 PRAGMA user_version;
danielk1977dae24952004-11-11 05:10:43 +0000544 }
545} {2}
drh802d69a2005-02-13 23:34:24 +0000546do_test pragma-8.2.3.2 {
547 db close
548 sqlite3 db test.db
549 execsql {
550 PRAGMA user_version;
551 }
552} {2}
553do_test pragma-8.2.4.1 {
danielk1977dae24952004-11-11 05:10:43 +0000554 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000555 PRAGMA schema_version;
danielk1977dae24952004-11-11 05:10:43 +0000556 }
557} {108}
drh802d69a2005-02-13 23:34:24 +0000558ifcapable vacuum {
559 do_test pragma-8.2.4.2 {
560 execsql {
561 VACUUM;
562 PRAGMA user_version;
563 }
564 } {2}
565 do_test pragma-8.2.4.3 {
566 execsql {
567 PRAGMA schema_version;
568 }
569 } {109}
570}
571db eval {ATTACH 'test2.db' AS aux}
danielk1977dae24952004-11-11 05:10:43 +0000572
danielk1977b92b70b2004-11-12 16:11:59 +0000573# Check that the user-version in the auxilary database can be manipulated (
danielk1977dae24952004-11-11 05:10:43 +0000574# and that we aren't accidentally manipulating the same in the main db).
575do_test pragma-8.2.5 {
576 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000577 PRAGMA aux.user_version;
danielk1977dae24952004-11-11 05:10:43 +0000578 }
579} {0}
580do_test pragma-8.2.6 {
581 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000582 PRAGMA aux.user_version = 3;
danielk1977dae24952004-11-11 05:10:43 +0000583 }
584} {}
585do_test pragma-8.2.7 {
586 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000587 PRAGMA aux.user_version;
danielk1977dae24952004-11-11 05:10:43 +0000588 }
589} {3}
590do_test pragma-8.2.8 {
591 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000592 PRAGMA main.user_version;
danielk1977dae24952004-11-11 05:10:43 +0000593 }
594} {2}
595
danielk1977b92b70b2004-11-12 16:11:59 +0000596# Now check that a ROLLBACK resets the user-version if it has been modified
danielk1977dae24952004-11-11 05:10:43 +0000597# within a transaction.
598do_test pragma-8.2.9 {
599 execsql {
600 BEGIN;
danielk1977b92b70b2004-11-12 16:11:59 +0000601 PRAGMA aux.user_version = 10;
602 PRAGMA user_version = 11;
danielk1977dae24952004-11-11 05:10:43 +0000603 }
604} {}
605do_test pragma-8.2.10 {
606 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000607 PRAGMA aux.user_version;
danielk1977dae24952004-11-11 05:10:43 +0000608 }
609} {10}
610do_test pragma-8.2.11 {
611 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000612 PRAGMA main.user_version;
danielk1977dae24952004-11-11 05:10:43 +0000613 }
614} {11}
615do_test pragma-8.2.12 {
616 execsql {
617 ROLLBACK;
danielk1977b92b70b2004-11-12 16:11:59 +0000618 PRAGMA aux.user_version;
danielk1977dae24952004-11-11 05:10:43 +0000619 }
620} {3}
621do_test pragma-8.2.13 {
622 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000623 PRAGMA main.user_version;
danielk1977dae24952004-11-11 05:10:43 +0000624 }
625} {2}
626
danielk1977b92b70b2004-11-12 16:11:59 +0000627# Try a negative value for the user-version
danielk1977dae24952004-11-11 05:10:43 +0000628do_test pragma-8.2.14 {
629 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000630 PRAGMA user_version = -450;
danielk1977dae24952004-11-11 05:10:43 +0000631 }
632} {}
633do_test pragma-8.2.15 {
634 execsql {
danielk1977b92b70b2004-11-12 16:11:59 +0000635 PRAGMA user_version;
danielk1977dae24952004-11-11 05:10:43 +0000636 }
637} {-450}
danielk1977d9c847d2005-01-07 10:42:48 +0000638} ; # ifcapable schema_version
639
tpoindex9a09a3c2004-12-20 19:01:32 +0000640
641# Test temp_store and temp_store_directory pragmas
642#
drh268283b2005-01-08 15:44:25 +0000643ifcapable pager_pragmas {
tpoindex9a09a3c2004-12-20 19:01:32 +0000644do_test pragma-9.1 {
645 db close
646 sqlite3 db test.db
647 execsql {
648 PRAGMA temp_store;
649 }
650} {0}
651do_test pragma-9.2 {
652 execsql {
653 PRAGMA temp_store=file;
654 PRAGMA temp_store;
655 }
656} {1}
657do_test pragma-9.3 {
658 execsql {
659 PRAGMA temp_store=memory;
660 PRAGMA temp_store;
661 }
662} {2}
663do_test pragma-9.4 {
664 execsql {
665 PRAGMA temp_store_directory;
666 }
667} {}
668do_test pragma-9.5 {
drh268283b2005-01-08 15:44:25 +0000669 set pwd [string map {' ''} [pwd]]
670 execsql "
671 PRAGMA temp_store_directory='$pwd';
tpoindex9a09a3c2004-12-20 19:01:32 +0000672 "
673} {}
674do_test pragma-9.6 {
675 execsql {
676 PRAGMA temp_store_directory;
677 }
678} [pwd]
679do_test pragma-9.7 {
drh268283b2005-01-08 15:44:25 +0000680 catchsql {
681 PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR';
682 }
683} {1 {not a writable directory}}
tpoindex9a09a3c2004-12-20 19:01:32 +0000684do_test pragma-9.8 {
685 execsql {
686 PRAGMA temp_store_directory='';
687 }
688} {}
danielk197753c0f742005-03-29 03:10:59 +0000689ifcapable tempdb {
690 do_test pragma-9.9 {
691 execsql {
692 PRAGMA temp_store_directory;
693 PRAGMA temp_store=FILE;
694 CREATE TEMP TABLE temp_store_directory_test(a integer);
695 INSERT INTO temp_store_directory_test values (2);
696 SELECT * FROM temp_store_directory_test;
697 }
698 } {2}
699}
tpoindex9a09a3c2004-12-20 19:01:32 +0000700do_test pragma-9.10 {
drh268283b2005-01-08 15:44:25 +0000701 catchsql "
702 PRAGMA temp_store_directory='$pwd';
703 SELECT * FROM temp_store_directory_test;
704 "
705} {1 {no such table: temp_store_directory_test}}
706} ;# ifcapable pager_pragmas
tpoindex9a09a3c2004-12-20 19:01:32 +0000707
danielk1977cc6bd382005-01-10 02:48:49 +0000708ifcapable trigger {
709
710do_test pragma-10.0 {
711 catchsql {
712 DROP TABLE main.t1;
713 }
714 execsql {
715 PRAGMA count_changes = 1;
716
717 CREATE TABLE t1(a PRIMARY KEY);
718 CREATE TABLE t1_mirror(a);
719 CREATE TABLE t1_mirror2(a);
720 CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN
721 INSERT INTO t1_mirror VALUES(new.a);
722 END;
723 CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN
724 INSERT INTO t1_mirror2 VALUES(new.a);
725 END;
726 CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN
727 UPDATE t1_mirror SET a = new.a WHERE a = old.a;
728 END;
729 CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN
730 UPDATE t1_mirror2 SET a = new.a WHERE a = old.a;
731 END;
732 CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN
733 DELETE FROM t1_mirror WHERE a = old.a;
734 END;
735 CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN
736 DELETE FROM t1_mirror2 WHERE a = old.a;
737 END;
738 }
739} {}
740
741do_test pragma-10.1 {
742 execsql {
743 INSERT INTO t1 VALUES(randstr(10,10));
744 }
745} {1}
746do_test pragma-10.2 {
747 execsql {
748 UPDATE t1 SET a = randstr(10,10);
749 }
750} {1}
751do_test pragma-10.3 {
752 execsql {
753 DELETE FROM t1;
754 }
755} {1}
756
757} ;# ifcapable trigger
758
danielk197748af65a2005-02-09 03:20:37 +0000759ifcapable schema_pragmas {
760 do_test pragma-11.1 {
761 execsql2 {
762 pragma collation_list;
763 }
764 } {seq 0 name NOCASE seq 1 name BINARY}
765 do_test pragma-11.2 {
766 db collate New_Collation blah...
767 execsql {
768 pragma collation_list;
769 }
770 } {0 New_Collation 1 NOCASE 2 BINARY}
771}
772
danielk1977ddfb2f02006-02-17 12:25:14 +0000773ifcapable schema_pragmas&&tempdb {
774 do_test pragma-12.1 {
775 sqlite3 db2 test.db
776 execsql {
777 PRAGMA temp.table_info('abc');
778 } db2
779 } {}
780 db2 close
781
782 do_test pragma-12.2 {
783 sqlite3 db2 test.db
784 execsql {
785 PRAGMA temp.default_cache_size = 200;
786 PRAGMA temp.default_cache_size;
787 } db2
788 } {200}
789 db2 close
790
791 do_test pragma-12.3 {
792 sqlite3 db2 test.db
793 execsql {
794 PRAGMA temp.cache_size = 400;
795 PRAGMA temp.cache_size;
796 } db2
797 } {400}
798 db2 close
799}
800
danielk19775558a8a2005-01-17 07:53:44 +0000801# Reset the sqlite3_temp_directory variable for the next run of tests:
802sqlite3 dbX :memory:
803dbX eval {PRAGMA temp_store_directory = ""}
804dbX close
805
drhcd61c282002-03-06 22:01:34 +0000806finish_test