2 #pragma ident "%Z%%M% %I% %E% SMI"
6 # The author disclaims copyright to this source code. In place of
7 # a legal notice, here is a blessing:
9 # May you do good and not evil.
10 # May you find forgiveness for yourself and forgive others.
11 # May you share freely, never taking more than you give.
13 #***********************************************************************
14 # This file implements regression tests for SQLite library.
16 # This file implements tests for the PRAGMA command.
18 # $Id: pragma.test,v 1.9 2004/04/23 17:04:45 drh Exp $
20 set testdir [file dirname $argv0]
21 source $testdir/tester.tcl
23 # Delete the preexisting database to avoid the special setup
24 # that the "all.test" script does.
28 set DB [sqlite db test.db]
33 PRAGMA default_cache_size;
35 PRAGMA default_synchronous;
40 PRAGMA cache_size=1234;
42 PRAGMA default_cache_size;
44 PRAGMA default_synchronous;
52 PRAGMA default_cache_size;
54 PRAGMA default_synchronous;
59 PRAGMA synchronous=OFF;
61 PRAGMA default_cache_size;
63 PRAGMA default_synchronous;
68 PRAGMA cache_size=4321;
70 PRAGMA default_cache_size;
72 PRAGMA default_synchronous;
77 PRAGMA synchronous=ON;
79 PRAGMA default_cache_size;
81 PRAGMA default_synchronous;
89 PRAGMA default_cache_size;
91 PRAGMA default_synchronous;
96 PRAGMA default_synchronous=OFF;
98 PRAGMA default_cache_size;
100 PRAGMA default_synchronous;
105 PRAGMA default_cache_size=123;
107 PRAGMA default_cache_size;
109 PRAGMA default_synchronous;
112 do_test pragma-1.10 {
114 set ::DB [sqlite db test.db]
117 PRAGMA default_cache_size;
119 PRAGMA default_synchronous;
122 do_test pragma-1.11 {
124 PRAGMA synchronous=NORMAL;
126 PRAGMA default_cache_size;
128 PRAGMA default_synchronous;
131 do_test pragma-1.12 {
133 PRAGMA synchronous=FULL;
135 PRAGMA default_cache_size;
137 PRAGMA default_synchronous;
140 do_test pragma-1.13 {
142 set ::DB [sqlite db test.db]
145 PRAGMA default_cache_size;
147 PRAGMA default_synchronous;
150 do_test pragma-1.14 {
152 PRAGMA default_synchronous=FULL;
154 PRAGMA default_cache_size;
156 PRAGMA default_synchronous;
159 do_test pragma-1.15 {
161 set ::DB [sqlite db test.db]
164 PRAGMA default_cache_size;
166 PRAGMA default_synchronous;
172 PRAGMA show_datatypes=on;
173 PRAGMA empty_result_callbacks=off;
175 sqlite_datatypes $::DB {SELECT * FROM sqlite_master}
179 PRAGMA empty_result_callbacks=on;
181 sqlite_datatypes $::DB {SELECT * FROM sqlite_master}
182 } {text text text integer text}
184 # Make sure we can read the schema when empty_result_callbacks are
185 # turned on. Ticket #406
186 do_test pragma-2.2.1 {
189 CREATE TABLE tabx(a,b,c,d);
191 SELECT count(*) FROM sqlite_master;
207 sqlite_datatypes $::DB {SELECT * FROM t1}
208 } {INTEGER TEXT WHATEVER CLOB BLOB VARCHAR(123) nVaRcHaR(432)}
210 sqlite_datatypes $::DB {
211 SELECT 1, 'hello', NULL
213 } {NUMERIC TEXT TEXT}
215 sqlite_datatypes $::DB {
216 SELECT 1+2 AS X, 'hello' || 5 AS Y, NULL AS Z
218 } {NUMERIC TEXT TEXT}
221 CREATE VIEW v1 AS SELECT a+b, b||c, * FROM t1;
223 sqlite_datatypes $::DB {SELECT * FROM v1}
224 } {NUMERIC TEXT INTEGER TEXT WHATEVER CLOB BLOB VARCHAR(123) nVaRcHaR(432)}
226 sqlite_datatypes $::DB {
227 SELECT d,e FROM t1 UNION SELECT a,c FROM t1
231 sqlite_datatypes $::DB {
232 SELECT d,e FROM t1 EXCEPT SELECT c,e FROM t1
236 sqlite_datatypes $::DB {
237 SELECT d,e FROM t1 INTERSECT SELECT c,e FROM t1
240 do_test pragma-2.10 {
241 sqlite_datatypes $::DB {
242 SELECT d,e FROM t1 INTERSECT SELECT c,e FROM v1
246 # Construct a corrupted index and make sure the integrity_check
249 if {![sqlite -has-codec]} {
253 CREATE TABLE t2(a,b,c);
254 CREATE INDEX i2 ON t2(a);
255 INSERT INTO t2 VALUES(11,2,3);
256 INSERT INTO t2 VALUES(22,3,4);
258 SELECT rowid, * from t2;
260 } {1 11 2 3 2 22 3 4}
262 set rootpage [execsql {SELECT rootpage FROM sqlite_master WHERE name='i2'}]
263 set db [btree_open test.db]
264 btree_begin_transaction $db
265 set c [btree_cursor $db $rootpage 1]
270 execsql {PRAGMA integrity_check}
271 } {{rowid 1 missing from index i2} {wrong # of entries in index i2}}
274 # Test the temp_store and default_temp_store pragmas
278 PRAGMA temp_store='default';
284 PRAGMA temp_store='file';
290 PRAGMA temp_store='memory';
296 PRAGMA default_temp_store='default';
297 PRAGMA default_temp_store;
314 PRAGMA default_temp_store;
319 PRAGMA default_temp_store='file';
320 PRAGMA default_temp_store;
323 do_test pragma-4.10 {
328 do_test pragma-4.11 {
335 do_test pragma-4.12 {
337 PRAGMA default_temp_store;
340 do_test pragma-4.13 {
342 PRAGMA default_temp_store='memory';
343 PRAGMA default_temp_store;
346 do_test pragma-4.14 {
351 do_test pragma-4.15 {
358 do_test pragma-4.16 {
360 PRAGMA default_temp_store;
363 do_test pragma-4.17 {
365 PRAGMA temp_store='file';
369 do_test pragma-4.18 {
371 PRAGMA default_temp_store
374 do_test pragma-4.19 {
382 # Changing the TEMP_STORE deletes any existing temporary tables
384 do_test pragma-4.20 {
385 execsql {SELECT name FROM sqlite_temp_master}
387 do_test pragma-4.21 {
389 CREATE TEMP TABLE test1(a,b,c);
390 SELECT name FROM sqlite_temp_master;
393 do_test pragma-4.22 {
395 PRAGMA temp_store='file';
396 SELECT name FROM sqlite_temp_master;
399 do_test pragma-4.23 {
401 CREATE TEMP TABLE test1(a,b,c);
402 SELECT name FROM sqlite_temp_master;
405 do_test pragma-4.24 {
407 PRAGMA temp_store='memory';
408 SELECT name FROM sqlite_temp_master;
411 do_test pragma-4.25 {
414 PRAGMA temp_store='default';
417 } {1 {temporary storage cannot be changed from within a transaction}}