1cd61c281Sdrh# 2002 March 6 2cd61c281Sdrh# 3cd61c281Sdrh# The author disclaims copyright to this source code. In place of 4cd61c281Sdrh# a legal notice, here is a blessing: 5cd61c281Sdrh# 6cd61c281Sdrh# May you do good and not evil. 7cd61c281Sdrh# May you find forgiveness for yourself and forgive others. 8cd61c281Sdrh# May you share freely, never taking more than you give. 9cd61c281Sdrh# 10cd61c281Sdrh#*********************************************************************** 11cd61c281Sdrh# This file implements regression tests for SQLite library. 12cd61c281Sdrh# 13cd61c281Sdrh# This file implements tests for the PRAGMA command. 14cd61c281Sdrh# 15*96fc5fe6Sdanielk1977# $Id: pragma.test,v 1.10 2004/05/13 11:34:17 danielk1977 Exp $ 16cd61c281Sdrh 17cd61c281Sdrhset testdir [file dirname $argv0] 18cd61c281Sdrhsource $testdir/tester.tcl 19cd61c281Sdrh 20cd61c281Sdrh# Delete the preexisting database to avoid the special setup 21cd61c281Sdrh# that the "all.test" script does. 22cd61c281Sdrh# 23cd61c281Sdrhdb close 24cd61c281Sdrhfile delete test.db 255a38705eSdrhset DB [sqlite db test.db] 26cd61c281Sdrh 27cd61c281Sdrhdo_test pragma-1.1 { 28cd61c281Sdrh execsql { 29cd61c281Sdrh PRAGMA cache_size; 30cd61c281Sdrh PRAGMA default_cache_size; 31cd61c281Sdrh PRAGMA synchronous; 32cd61c281Sdrh PRAGMA default_synchronous; 33cd61c281Sdrh } 34cd61c281Sdrh} {2000 2000 1 1} 35cd61c281Sdrhdo_test pragma-1.2 { 36cd61c281Sdrh execsql { 37cd61c281Sdrh PRAGMA cache_size=1234; 38cd61c281Sdrh PRAGMA cache_size; 39cd61c281Sdrh PRAGMA default_cache_size; 40cd61c281Sdrh PRAGMA synchronous; 41cd61c281Sdrh PRAGMA default_synchronous; 42cd61c281Sdrh } 43cd61c281Sdrh} {1234 2000 1 1} 44cd61c281Sdrhdo_test pragma-1.3 { 45cd61c281Sdrh db close 46cd61c281Sdrh sqlite db test.db 47cd61c281Sdrh execsql { 48cd61c281Sdrh PRAGMA cache_size; 49cd61c281Sdrh PRAGMA default_cache_size; 50cd61c281Sdrh PRAGMA synchronous; 51cd61c281Sdrh PRAGMA default_synchronous; 52cd61c281Sdrh } 53cd61c281Sdrh} {2000 2000 1 1} 54cd61c281Sdrhdo_test pragma-1.4 { 55cd61c281Sdrh execsql { 56cd61c281Sdrh PRAGMA synchronous=OFF; 57cd61c281Sdrh PRAGMA cache_size; 58cd61c281Sdrh PRAGMA default_cache_size; 59cd61c281Sdrh PRAGMA synchronous; 60cd61c281Sdrh PRAGMA default_synchronous; 61cd61c281Sdrh } 62cd61c281Sdrh} {2000 2000 0 1} 63cd61c281Sdrhdo_test pragma-1.5 { 64cd61c281Sdrh execsql { 65cd61c281Sdrh PRAGMA cache_size=4321; 66cd61c281Sdrh PRAGMA cache_size; 67cd61c281Sdrh PRAGMA default_cache_size; 68cd61c281Sdrh PRAGMA synchronous; 69cd61c281Sdrh PRAGMA default_synchronous; 70cd61c281Sdrh } 71cd61c281Sdrh} {4321 2000 0 1} 72cd61c281Sdrhdo_test pragma-1.6 { 73cd61c281Sdrh execsql { 74cd61c281Sdrh PRAGMA synchronous=ON; 75cd61c281Sdrh PRAGMA cache_size; 76cd61c281Sdrh PRAGMA default_cache_size; 77cd61c281Sdrh PRAGMA synchronous; 78cd61c281Sdrh PRAGMA default_synchronous; 79cd61c281Sdrh } 80cd61c281Sdrh} {4321 2000 1 1} 81cd61c281Sdrhdo_test pragma-1.7 { 82cd61c281Sdrh db close 83cd61c281Sdrh sqlite db test.db 84cd61c281Sdrh execsql { 85cd61c281Sdrh PRAGMA cache_size; 86cd61c281Sdrh PRAGMA default_cache_size; 87cd61c281Sdrh PRAGMA synchronous; 88cd61c281Sdrh PRAGMA default_synchronous; 89cd61c281Sdrh } 90cd61c281Sdrh} {2000 2000 1 1} 91cd61c281Sdrhdo_test pragma-1.8 { 92cd61c281Sdrh execsql { 93cd61c281Sdrh PRAGMA default_synchronous=OFF; 94cd61c281Sdrh PRAGMA cache_size; 95cd61c281Sdrh PRAGMA default_cache_size; 96cd61c281Sdrh PRAGMA synchronous; 97cd61c281Sdrh PRAGMA default_synchronous; 98cd61c281Sdrh } 99cd61c281Sdrh} {2000 2000 0 0} 100cd61c281Sdrhdo_test pragma-1.9 { 101cd61c281Sdrh execsql { 102cd61c281Sdrh PRAGMA default_cache_size=123; 103cd61c281Sdrh PRAGMA cache_size; 104cd61c281Sdrh PRAGMA default_cache_size; 105cd61c281Sdrh PRAGMA synchronous; 106cd61c281Sdrh PRAGMA default_synchronous; 107cd61c281Sdrh } 108cd61c281Sdrh} {123 123 0 0} 109cd61c281Sdrhdo_test pragma-1.10 { 110cd61c281Sdrh db close 1115a38705eSdrh set ::DB [sqlite db test.db] 112cd61c281Sdrh execsql { 113cd61c281Sdrh PRAGMA cache_size; 114cd61c281Sdrh PRAGMA default_cache_size; 115cd61c281Sdrh PRAGMA synchronous; 116cd61c281Sdrh PRAGMA default_synchronous; 117cd61c281Sdrh } 118cd61c281Sdrh} {123 123 0 0} 1195a38705eSdrhdo_test pragma-1.11 { 1205a38705eSdrh execsql { 1214303feedSdrh PRAGMA synchronous=NORMAL; 1224303feedSdrh PRAGMA cache_size; 1234303feedSdrh PRAGMA default_cache_size; 1244303feedSdrh PRAGMA synchronous; 1254303feedSdrh PRAGMA default_synchronous; 1264303feedSdrh } 1274303feedSdrh} {123 123 1 0} 1284303feedSdrhdo_test pragma-1.12 { 1294303feedSdrh execsql { 1304303feedSdrh PRAGMA synchronous=FULL; 1314303feedSdrh PRAGMA cache_size; 1324303feedSdrh PRAGMA default_cache_size; 1334303feedSdrh PRAGMA synchronous; 1344303feedSdrh PRAGMA default_synchronous; 1354303feedSdrh } 1364303feedSdrh} {123 123 2 0} 1374303feedSdrhdo_test pragma-1.13 { 1384303feedSdrh db close 1394303feedSdrh set ::DB [sqlite db test.db] 1404303feedSdrh execsql { 1414303feedSdrh PRAGMA cache_size; 1424303feedSdrh PRAGMA default_cache_size; 1434303feedSdrh PRAGMA synchronous; 1444303feedSdrh PRAGMA default_synchronous; 1454303feedSdrh } 1464303feedSdrh} {123 123 0 0} 1474303feedSdrhdo_test pragma-1.14 { 1484303feedSdrh execsql { 1494303feedSdrh PRAGMA default_synchronous=FULL; 1504303feedSdrh PRAGMA cache_size; 1514303feedSdrh PRAGMA default_cache_size; 1524303feedSdrh PRAGMA synchronous; 1534303feedSdrh PRAGMA default_synchronous; 1544303feedSdrh } 1554303feedSdrh} {123 123 2 2} 1564303feedSdrhdo_test pragma-1.15 { 1574303feedSdrh db close 1584303feedSdrh set ::DB [sqlite db test.db] 1594303feedSdrh execsql { 1604303feedSdrh PRAGMA cache_size; 1614303feedSdrh PRAGMA default_cache_size; 1624303feedSdrh PRAGMA synchronous; 1634303feedSdrh PRAGMA default_synchronous; 1644303feedSdrh } 1654303feedSdrh} {123 123 2 2} 1664303feedSdrh 1674303feedSdrhdo_test pragma-2.1 { 1684303feedSdrh execsql { 1695a38705eSdrh PRAGMA show_datatypes=on; 1705a38705eSdrh PRAGMA empty_result_callbacks=off; 1715a38705eSdrh } 1725a38705eSdrh sqlite_datatypes $::DB {SELECT * FROM sqlite_master} 1735a38705eSdrh} {} 1744303feedSdrhdo_test pragma-2.2 { 1755a38705eSdrh execsql { 1765a38705eSdrh PRAGMA empty_result_callbacks=on; 1775a38705eSdrh } 1785a38705eSdrh sqlite_datatypes $::DB {SELECT * FROM sqlite_master} 179fcb78a49Sdrh} {text text text integer text} 18098e3e600Sdrh 18198e3e600Sdrh# Make sure we can read the schema when empty_result_callbacks are 18298e3e600Sdrh# turned on. Ticket #406 18398e3e600Sdrhdo_test pragma-2.2.1 { 18498e3e600Sdrh execsql { 18598e3e600Sdrh BEGIN; 18698e3e600Sdrh CREATE TABLE tabx(a,b,c,d); 18798e3e600Sdrh ROLLBACK; 18898e3e600Sdrh SELECT count(*) FROM sqlite_master; 18998e3e600Sdrh } 19098e3e600Sdrh} {0} 19198e3e600Sdrh 1924303feedSdrhdo_test pragma-2.3 { 1935a38705eSdrh execsql { 1945a38705eSdrh CREATE TABLE t1( 1955a38705eSdrh a INTEGER, 1965a38705eSdrh b TEXT, 1975a38705eSdrh c WHATEVER, 1985a38705eSdrh d CLOB, 1995a38705eSdrh e BLOB, 2005a38705eSdrh f VARCHAR(123), 2015a38705eSdrh g nVaRcHaR(432) 2025a38705eSdrh ); 2035a38705eSdrh } 2045a38705eSdrh sqlite_datatypes $::DB {SELECT * FROM t1} 205fcb78a49Sdrh} {INTEGER TEXT WHATEVER CLOB BLOB VARCHAR(123) nVaRcHaR(432)} 2064303feedSdrhdo_test pragma-2.4 { 2075a38705eSdrh sqlite_datatypes $::DB { 2085a38705eSdrh SELECT 1, 'hello', NULL 2095a38705eSdrh } 2105a38705eSdrh} {NUMERIC TEXT TEXT} 2114303feedSdrhdo_test pragma-2.5 { 2125a38705eSdrh sqlite_datatypes $::DB { 2135a38705eSdrh SELECT 1+2 AS X, 'hello' || 5 AS Y, NULL AS Z 2145a38705eSdrh } 2155a38705eSdrh} {NUMERIC TEXT TEXT} 2164303feedSdrhdo_test pragma-2.6 { 217fcb78a49Sdrh execsql { 218fcb78a49Sdrh CREATE VIEW v1 AS SELECT a+b, b||c, * FROM t1; 219fcb78a49Sdrh } 220fcb78a49Sdrh sqlite_datatypes $::DB {SELECT * FROM v1} 221fcb78a49Sdrh} {NUMERIC TEXT INTEGER TEXT WHATEVER CLOB BLOB VARCHAR(123) nVaRcHaR(432)} 2224303feedSdrhdo_test pragma-2.7 { 223fcb78a49Sdrh sqlite_datatypes $::DB { 224fcb78a49Sdrh SELECT d,e FROM t1 UNION SELECT a,c FROM t1 225fcb78a49Sdrh } 226fcb78a49Sdrh} {INTEGER WHATEVER} 2274303feedSdrhdo_test pragma-2.8 { 228fcb78a49Sdrh sqlite_datatypes $::DB { 229fcb78a49Sdrh SELECT d,e FROM t1 EXCEPT SELECT c,e FROM t1 230fcb78a49Sdrh } 231fcb78a49Sdrh} {WHATEVER BLOB} 2324303feedSdrhdo_test pragma-2.9 { 233fcb78a49Sdrh sqlite_datatypes $::DB { 234fcb78a49Sdrh SELECT d,e FROM t1 INTERSECT SELECT c,e FROM t1 235fcb78a49Sdrh } 236fcb78a49Sdrh} {WHATEVER BLOB} 2374303feedSdrhdo_test pragma-2.10 { 238fcb78a49Sdrh sqlite_datatypes $::DB { 239fcb78a49Sdrh SELECT d,e FROM t1 INTERSECT SELECT c,e FROM v1 240fcb78a49Sdrh } 241fcb78a49Sdrh} {WHATEVER BLOB} 242fcb78a49Sdrh 243ed717fe3Sdrh# Construct a corrupted index and make sure the integrity_check 244ed717fe3Sdrh# pragma finds it. 245ed717fe3Sdrh# 2469eb9e26bSdrhif {![sqlite -has-codec]} { 247ed717fe3Sdrhdo_test pragma-3.1 { 248ed717fe3Sdrh execsql { 249ed717fe3Sdrh BEGIN; 250ed717fe3Sdrh CREATE TABLE t2(a,b,c); 251ed717fe3Sdrh CREATE INDEX i2 ON t2(a); 252ed717fe3Sdrh INSERT INTO t2 VALUES(11,2,3); 253ed717fe3Sdrh INSERT INTO t2 VALUES(22,3,4); 254ed717fe3Sdrh COMMIT; 255ed717fe3Sdrh SELECT rowid, * from t2; 256ed717fe3Sdrh } 257ed717fe3Sdrh} {1 11 2 3 2 22 3 4} 258ed717fe3Sdrhdo_test pragma-3.2 { 259ed717fe3Sdrh set rootpage [execsql {SELECT rootpage FROM sqlite_master WHERE name='i2'}] 260*96fc5fe6Sdanielk1977 set db [btree_open test.db 100 0] 261ed717fe3Sdrh btree_begin_transaction $db 262ed717fe3Sdrh set c [btree_cursor $db $rootpage 1] 263ed717fe3Sdrh btree_first $c 264ed717fe3Sdrh btree_delete $c 265ed717fe3Sdrh btree_commit $db 266ed717fe3Sdrh btree_close $db 267ed717fe3Sdrh execsql {PRAGMA integrity_check} 2684be295beSdrh} {{rowid 1 missing from index i2} {wrong # of entries in index i2}} 2699eb9e26bSdrh}; # endif has-codec 2705a38705eSdrh 2711bdd9b57Sdrh# Test the temp_store and default_temp_store pragmas 2721bdd9b57Sdrh# 2731bdd9b57Sdrhdo_test pragma-4.2 { 2741bdd9b57Sdrh execsql { 2751bdd9b57Sdrh PRAGMA temp_store='default'; 2761bdd9b57Sdrh PRAGMA temp_store; 2771bdd9b57Sdrh } 2781bdd9b57Sdrh} {0} 2791bdd9b57Sdrhdo_test pragma-4.3 { 2801bdd9b57Sdrh execsql { 2811bdd9b57Sdrh PRAGMA temp_store='file'; 2821bdd9b57Sdrh PRAGMA temp_store; 2831bdd9b57Sdrh } 2841bdd9b57Sdrh} {1} 2851bdd9b57Sdrhdo_test pragma-4.4 { 2861bdd9b57Sdrh execsql { 2871bdd9b57Sdrh PRAGMA temp_store='memory'; 2881bdd9b57Sdrh PRAGMA temp_store; 2891bdd9b57Sdrh } 2901bdd9b57Sdrh} {2} 2911bdd9b57Sdrhdo_test pragma-4.5 { 2921bdd9b57Sdrh execsql { 2931bdd9b57Sdrh PRAGMA default_temp_store='default'; 2941bdd9b57Sdrh PRAGMA default_temp_store; 2951bdd9b57Sdrh } 2961bdd9b57Sdrh} {0} 2971bdd9b57Sdrhdo_test pragma-4.6 { 2981bdd9b57Sdrh execsql { 2991bdd9b57Sdrh PRAGMA temp_store; 3001bdd9b57Sdrh } 3011bdd9b57Sdrh} {2} 3021bdd9b57Sdrhdo_test pragma-4.7 { 3031bdd9b57Sdrh db close 3041bdd9b57Sdrh sqlite db test.db 3051bdd9b57Sdrh execsql { 3061bdd9b57Sdrh PRAGMA temp_store; 3071bdd9b57Sdrh } 3081bdd9b57Sdrh} {0} 3091bdd9b57Sdrhdo_test pragma-4.8 { 3101bdd9b57Sdrh execsql { 3111bdd9b57Sdrh PRAGMA default_temp_store; 3121bdd9b57Sdrh } 3131bdd9b57Sdrh} {0} 3141bdd9b57Sdrhdo_test pragma-4.9 { 3151bdd9b57Sdrh execsql { 3161bdd9b57Sdrh PRAGMA default_temp_store='file'; 3171bdd9b57Sdrh PRAGMA default_temp_store; 3181bdd9b57Sdrh } 3191bdd9b57Sdrh} {1} 3201bdd9b57Sdrhdo_test pragma-4.10 { 3211bdd9b57Sdrh execsql { 3221bdd9b57Sdrh PRAGMA temp_store; 3231bdd9b57Sdrh } 3241bdd9b57Sdrh} {0} 3251bdd9b57Sdrhdo_test pragma-4.11 { 3261bdd9b57Sdrh db close 3271bdd9b57Sdrh sqlite db test.db 3281bdd9b57Sdrh execsql { 3291bdd9b57Sdrh PRAGMA temp_store; 3301bdd9b57Sdrh } 3311bdd9b57Sdrh} {1} 3321bdd9b57Sdrhdo_test pragma-4.12 { 3331bdd9b57Sdrh execsql { 3341bdd9b57Sdrh PRAGMA default_temp_store; 3351bdd9b57Sdrh } 3361bdd9b57Sdrh} {1} 3371bdd9b57Sdrhdo_test pragma-4.13 { 3381bdd9b57Sdrh execsql { 3391bdd9b57Sdrh PRAGMA default_temp_store='memory'; 3401bdd9b57Sdrh PRAGMA default_temp_store; 3411bdd9b57Sdrh } 3421bdd9b57Sdrh} {2} 3431bdd9b57Sdrhdo_test pragma-4.14 { 3441bdd9b57Sdrh execsql { 3451bdd9b57Sdrh PRAGMA temp_store; 3461bdd9b57Sdrh } 3471bdd9b57Sdrh} {1} 3481bdd9b57Sdrhdo_test pragma-4.15 { 3491bdd9b57Sdrh db close 3501bdd9b57Sdrh sqlite db test.db 3511bdd9b57Sdrh execsql { 3521bdd9b57Sdrh PRAGMA temp_store; 3531bdd9b57Sdrh } 3541bdd9b57Sdrh} {2} 3551bdd9b57Sdrhdo_test pragma-4.16 { 3561bdd9b57Sdrh execsql { 3571bdd9b57Sdrh PRAGMA default_temp_store; 3581bdd9b57Sdrh } 3591bdd9b57Sdrh} {2} 3601bdd9b57Sdrhdo_test pragma-4.17 { 3611bdd9b57Sdrh execsql { 3621bdd9b57Sdrh PRAGMA temp_store='file'; 3631bdd9b57Sdrh PRAGMA temp_store 3641bdd9b57Sdrh } 3651bdd9b57Sdrh} {1} 3661bdd9b57Sdrhdo_test pragma-4.18 { 3671bdd9b57Sdrh execsql { 3681bdd9b57Sdrh PRAGMA default_temp_store 3691bdd9b57Sdrh } 3701bdd9b57Sdrh} {2} 3711bdd9b57Sdrhdo_test pragma-4.19 { 3721bdd9b57Sdrh db close 3731bdd9b57Sdrh sqlite db test.db 3741bdd9b57Sdrh execsql { 3751bdd9b57Sdrh PRAGMA temp_store 3761bdd9b57Sdrh } 3771bdd9b57Sdrh} {2} 3781bdd9b57Sdrh 3791bdd9b57Sdrh# Changing the TEMP_STORE deletes any existing temporary tables 3801bdd9b57Sdrh# 3811bdd9b57Sdrhdo_test pragma-4.20 { 3821bdd9b57Sdrh execsql {SELECT name FROM sqlite_temp_master} 3831bdd9b57Sdrh} {} 3841bdd9b57Sdrhdo_test pragma-4.21 { 3851bdd9b57Sdrh execsql { 3861bdd9b57Sdrh CREATE TEMP TABLE test1(a,b,c); 3871bdd9b57Sdrh SELECT name FROM sqlite_temp_master; 3881bdd9b57Sdrh } 3891bdd9b57Sdrh} {test1} 3901bdd9b57Sdrhdo_test pragma-4.22 { 3911bdd9b57Sdrh execsql { 3921bdd9b57Sdrh PRAGMA temp_store='file'; 3931bdd9b57Sdrh SELECT name FROM sqlite_temp_master; 3941bdd9b57Sdrh } 3951bdd9b57Sdrh} {} 3961bdd9b57Sdrhdo_test pragma-4.23 { 3971bdd9b57Sdrh execsql { 3981bdd9b57Sdrh CREATE TEMP TABLE test1(a,b,c); 3991bdd9b57Sdrh SELECT name FROM sqlite_temp_master; 4001bdd9b57Sdrh } 4011bdd9b57Sdrh} {test1} 4021bdd9b57Sdrhdo_test pragma-4.24 { 4031bdd9b57Sdrh execsql { 4041bdd9b57Sdrh PRAGMA temp_store='memory'; 4051bdd9b57Sdrh SELECT name FROM sqlite_temp_master; 4061bdd9b57Sdrh } 4071bdd9b57Sdrh} {} 4081bdd9b57Sdrhdo_test pragma-4.25 { 4091bdd9b57Sdrh catchsql { 4101bdd9b57Sdrh BEGIN; 4111bdd9b57Sdrh PRAGMA temp_store='default'; 4121bdd9b57Sdrh COMMIT; 4131bdd9b57Sdrh } 4141bdd9b57Sdrh} {1 {temporary storage cannot be changed from within a transaction}} 4151bdd9b57Sdrhcatchsql {COMMIT} 4161bdd9b57Sdrh 417cd61c281Sdrhfinish_test 418