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*9a09a3caStpoindex# $Id: pragma.test,v 1.28 2004/12/20 19:01:33 tpoindex Exp $ 16cd61c281Sdrh 17cd61c281Sdrhset testdir [file dirname $argv0] 18cd61c281Sdrhsource $testdir/tester.tcl 19cd61c281Sdrh 2091cf71b0Sdanielk1977# Test organization: 2191cf71b0Sdanielk1977# 2291cf71b0Sdanielk1977# pragma-1.*: Test cache_size, default_cache_size and synchronous on main db. 2391cf71b0Sdanielk1977# pragma-2.*: Test synchronous on attached db. 2491cf71b0Sdanielk1977# pragma-3.*: Test detection of table/index inconsistency by integrity_check. 2591cf71b0Sdanielk1977# pragma-4.*: Test cache_size and default_cache_size on attached db. 2691cf71b0Sdanielk1977# pragma-5.*: Test that pragma synchronous may not be used inside of a 2791cf71b0Sdanielk1977# transaction. 28*9a09a3caStpoindex# pragma-9.*: Test temp_store and temp_store_directory. 2991cf71b0Sdanielk1977# 3091cf71b0Sdanielk1977 31cd61c281Sdrh# Delete the preexisting database to avoid the special setup 32cd61c281Sdrh# that the "all.test" script does. 33cd61c281Sdrh# 34cd61c281Sdrhdb close 35cd61c281Sdrhfile delete test.db 36ef4ac8f9Sdrhset DB [sqlite3 db test.db] 37cd61c281Sdrh 38c7b4a44cSdanielk1977ifcapable pager_pragmas { 39cd61c281Sdrhdo_test pragma-1.1 { 40cd61c281Sdrh execsql { 41cd61c281Sdrh PRAGMA cache_size; 42cd61c281Sdrh PRAGMA default_cache_size; 43cd61c281Sdrh PRAGMA synchronous; 44cd61c281Sdrh } 4591cf71b0Sdanielk1977} {2000 2000 2} 46cd61c281Sdrhdo_test pragma-1.2 { 47cd61c281Sdrh execsql { 48cd61c281Sdrh PRAGMA cache_size=1234; 49cd61c281Sdrh PRAGMA cache_size; 50cd61c281Sdrh PRAGMA default_cache_size; 51cd61c281Sdrh PRAGMA synchronous; 52cd61c281Sdrh } 5391cf71b0Sdanielk1977} {1234 2000 2} 54cd61c281Sdrhdo_test pragma-1.3 { 55cd61c281Sdrh db close 56ef4ac8f9Sdrh sqlite3 db test.db 57cd61c281Sdrh execsql { 58cd61c281Sdrh PRAGMA cache_size; 59cd61c281Sdrh PRAGMA default_cache_size; 60cd61c281Sdrh PRAGMA synchronous; 61cd61c281Sdrh } 6291cf71b0Sdanielk1977} {2000 2000 2} 63cd61c281Sdrhdo_test pragma-1.4 { 64cd61c281Sdrh execsql { 65cd61c281Sdrh PRAGMA synchronous=OFF; 66cd61c281Sdrh PRAGMA cache_size; 67cd61c281Sdrh PRAGMA default_cache_size; 68cd61c281Sdrh PRAGMA synchronous; 69cd61c281Sdrh } 7091cf71b0Sdanielk1977} {2000 2000 0} 71cd61c281Sdrhdo_test pragma-1.5 { 72cd61c281Sdrh execsql { 73cd61c281Sdrh PRAGMA cache_size=4321; 74cd61c281Sdrh PRAGMA cache_size; 75cd61c281Sdrh PRAGMA default_cache_size; 76cd61c281Sdrh PRAGMA synchronous; 77cd61c281Sdrh } 7891cf71b0Sdanielk1977} {4321 2000 0} 79cd61c281Sdrhdo_test pragma-1.6 { 80cd61c281Sdrh execsql { 81cd61c281Sdrh PRAGMA synchronous=ON; 82cd61c281Sdrh PRAGMA cache_size; 83cd61c281Sdrh PRAGMA default_cache_size; 84cd61c281Sdrh PRAGMA synchronous; 85cd61c281Sdrh } 8691cf71b0Sdanielk1977} {4321 2000 1} 87cd61c281Sdrhdo_test pragma-1.7 { 88cd61c281Sdrh db close 89ef4ac8f9Sdrh sqlite3 db test.db 90cd61c281Sdrh execsql { 91cd61c281Sdrh PRAGMA cache_size; 92cd61c281Sdrh PRAGMA default_cache_size; 93cd61c281Sdrh PRAGMA synchronous; 94cd61c281Sdrh } 9591cf71b0Sdanielk1977} {2000 2000 2} 96cd61c281Sdrhdo_test pragma-1.8 { 97cd61c281Sdrh execsql { 98cd61c281Sdrh PRAGMA default_cache_size=123; 99cd61c281Sdrh PRAGMA cache_size; 100cd61c281Sdrh PRAGMA default_cache_size; 101cd61c281Sdrh PRAGMA synchronous; 102cd61c281Sdrh } 10391cf71b0Sdanielk1977} {123 123 2} 10491cf71b0Sdanielk1977do_test pragma-1.9 { 105cd61c281Sdrh db close 106ef4ac8f9Sdrh set ::DB [sqlite3 db test.db] 107cd61c281Sdrh execsql { 108cd61c281Sdrh PRAGMA cache_size; 109cd61c281Sdrh PRAGMA default_cache_size; 110cd61c281Sdrh PRAGMA synchronous; 111cd61c281Sdrh } 11291cf71b0Sdanielk1977} {123 123 2} 11391cf71b0Sdanielk1977do_test pragma-1.10 { 1145a38705eSdrh execsql { 1154303feedSdrh PRAGMA synchronous=NORMAL; 1164303feedSdrh PRAGMA cache_size; 1174303feedSdrh PRAGMA default_cache_size; 1184303feedSdrh PRAGMA synchronous; 1194303feedSdrh } 12091cf71b0Sdanielk1977} {123 123 1} 12191cf71b0Sdanielk1977do_test pragma-1.11 { 1224303feedSdrh execsql { 1234303feedSdrh PRAGMA synchronous=FULL; 1244303feedSdrh PRAGMA cache_size; 1254303feedSdrh PRAGMA default_cache_size; 1264303feedSdrh PRAGMA synchronous; 1274303feedSdrh } 12891cf71b0Sdanielk1977} {123 123 2} 12991cf71b0Sdanielk1977do_test pragma-1.12 { 1304303feedSdrh db close 131ef4ac8f9Sdrh set ::DB [sqlite3 db test.db] 1324303feedSdrh execsql { 1334303feedSdrh PRAGMA cache_size; 1344303feedSdrh PRAGMA default_cache_size; 1354303feedSdrh PRAGMA synchronous; 1364303feedSdrh } 13791cf71b0Sdanielk1977} {123 123 2} 13891cf71b0Sdanielk1977 1395260f7e9Sdrh# Make sure the pragma handler understands numeric values in addition 1405260f7e9Sdrh# to keywords like "off" and "full". 1415260f7e9Sdrh# 1425260f7e9Sdrhdo_test pragma-1.13 { 1435260f7e9Sdrh execsql { 1445260f7e9Sdrh PRAGMA synchronous=0; 1455260f7e9Sdrh PRAGMA synchronous; 1465260f7e9Sdrh } 1475260f7e9Sdrh} {0} 1485260f7e9Sdrhdo_test pragma-1.14 { 1495260f7e9Sdrh execsql { 1505260f7e9Sdrh PRAGMA synchronous=2; 1515260f7e9Sdrh PRAGMA synchronous; 1525260f7e9Sdrh } 1535260f7e9Sdrh} {2} 154c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 1555260f7e9Sdrh 1565260f7e9Sdrh# Test turning "flag" pragmas on and off. 1575260f7e9Sdrh# 1585260f7e9Sdrhdo_test pragma-1.15 { 1595260f7e9Sdrh execsql { 1605260f7e9Sdrh PRAGMA vdbe_listing=YES; 1615260f7e9Sdrh PRAGMA vdbe_listing; 1625260f7e9Sdrh } 1635260f7e9Sdrh} {1} 1645260f7e9Sdrhdo_test pragma-1.16 { 1655260f7e9Sdrh execsql { 1665260f7e9Sdrh PRAGMA vdbe_listing=NO; 1675260f7e9Sdrh PRAGMA vdbe_listing; 1685260f7e9Sdrh } 1695260f7e9Sdrh} {0} 1705260f7e9Sdrhdo_test pragma-1.17 { 1715260f7e9Sdrh execsql { 1725260f7e9Sdrh PRAGMA parser_trace=ON; 1735260f7e9Sdrh PRAGMA parser_trace=OFF; 1745260f7e9Sdrh } 1755260f7e9Sdrh} {} 1765260f7e9Sdrhdo_test pragma-1.18 { 1775260f7e9Sdrh execsql { 1785260f7e9Sdrh PRAGMA bogus = -1234; -- Parsing of negative values 1795260f7e9Sdrh } 1805260f7e9Sdrh} {} 1815260f7e9Sdrh 18291cf71b0Sdanielk1977# Test modifying the safety_level of an attached database. 18391cf71b0Sdanielk1977do_test pragma-2.1 { 18491cf71b0Sdanielk1977 file delete -force test2.db 18591cf71b0Sdanielk1977 file delete -force test2.db-journal 1864303feedSdrh execsql { 18791cf71b0Sdanielk1977 ATTACH 'test2.db' AS aux; 1884303feedSdrh } 18991cf71b0Sdanielk1977} {} 190c7b4a44cSdanielk1977ifcapable pager_pragmas { 19191cf71b0Sdanielk1977do_test pragma-2.2 { 1924303feedSdrh execsql { 19391cf71b0Sdanielk1977 pragma aux.synchronous; 1944303feedSdrh } 19591cf71b0Sdanielk1977} {2} 19691cf71b0Sdanielk1977do_test pragma-2.3 { 19791cf71b0Sdanielk1977 execsql { 19891cf71b0Sdanielk1977 pragma aux.synchronous = OFF; 19991cf71b0Sdanielk1977 pragma aux.synchronous; 20091cf71b0Sdanielk1977 pragma synchronous; 20191cf71b0Sdanielk1977 } 20291cf71b0Sdanielk1977} {0 2} 20391cf71b0Sdanielk1977do_test pragma-2.4 { 20491cf71b0Sdanielk1977 execsql { 20591cf71b0Sdanielk1977 pragma aux.synchronous = ON; 20691cf71b0Sdanielk1977 pragma synchronous; 20791cf71b0Sdanielk1977 pragma aux.synchronous; 20891cf71b0Sdanielk1977 } 20991cf71b0Sdanielk1977} {2 1} 210c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 2114303feedSdrh 212ed717fe3Sdrh# Construct a corrupted index and make sure the integrity_check 213ed717fe3Sdrh# pragma finds it. 214ed717fe3Sdrh# 21525d6543dSdrh# These tests won't work if the database is encrypted 21625d6543dSdrh# 217ed717fe3Sdrhdo_test pragma-3.1 { 218ed717fe3Sdrh execsql { 219ed717fe3Sdrh BEGIN; 220ed717fe3Sdrh CREATE TABLE t2(a,b,c); 221ed717fe3Sdrh CREATE INDEX i2 ON t2(a); 222ed717fe3Sdrh INSERT INTO t2 VALUES(11,2,3); 223ed717fe3Sdrh INSERT INTO t2 VALUES(22,3,4); 224ed717fe3Sdrh COMMIT; 225ed717fe3Sdrh SELECT rowid, * from t2; 226ed717fe3Sdrh } 227ed717fe3Sdrh} {1 11 2 3 2 22 3 4} 22840e016e4Sdrhif {![sqlite3 -has-codec] && $sqlite_options(integrityck)} { 229ed717fe3Sdrh do_test pragma-3.2 { 230ed717fe3Sdrh set rootpage [execsql {SELECT rootpage FROM sqlite_master WHERE name='i2'}] 23196fc5fe6Sdanielk1977 set db [btree_open test.db 100 0] 232ed717fe3Sdrh btree_begin_transaction $db 233ed717fe3Sdrh set c [btree_cursor $db $rootpage 1] 234ed717fe3Sdrh btree_first $c 235ed717fe3Sdrh btree_delete $c 236ed717fe3Sdrh btree_commit $db 237ed717fe3Sdrh btree_close $db 238ed717fe3Sdrh execsql {PRAGMA integrity_check} 2394be295beSdrh } {{rowid 1 missing from index i2} {wrong # of entries in index i2}} 24025d6543dSdrh} 24191cf71b0Sdanielk1977do_test pragma-3.3 { 24291cf71b0Sdanielk1977 execsql { 24391cf71b0Sdanielk1977 DROP INDEX i2; 24491cf71b0Sdanielk1977 } 24591cf71b0Sdanielk1977} {} 24691cf71b0Sdanielk1977 24791cf71b0Sdanielk1977# Test modifying the cache_size of an attached database. 248c7b4a44cSdanielk1977ifcapable pager_pragmas { 24991cf71b0Sdanielk1977do_test pragma-4.1 { 25091cf71b0Sdanielk1977 execsql { 25191cf71b0Sdanielk1977 pragma aux.cache_size; 25291cf71b0Sdanielk1977 pragma aux.default_cache_size; 25391cf71b0Sdanielk1977 } 25491cf71b0Sdanielk1977} {2000 2000} 2551bdd9b57Sdrhdo_test pragma-4.2 { 2561bdd9b57Sdrh execsql { 25791cf71b0Sdanielk1977 pragma aux.cache_size = 50; 25891cf71b0Sdanielk1977 pragma aux.cache_size; 25991cf71b0Sdanielk1977 pragma aux.default_cache_size; 2601bdd9b57Sdrh } 26191cf71b0Sdanielk1977} {50 2000} 2621bdd9b57Sdrhdo_test pragma-4.3 { 2631bdd9b57Sdrh execsql { 26491cf71b0Sdanielk1977 pragma aux.default_cache_size = 456; 26591cf71b0Sdanielk1977 pragma aux.cache_size; 26691cf71b0Sdanielk1977 pragma aux.default_cache_size; 2671bdd9b57Sdrh } 26891cf71b0Sdanielk1977} {456 456} 2691bdd9b57Sdrhdo_test pragma-4.4 { 2701bdd9b57Sdrh execsql { 27191cf71b0Sdanielk1977 pragma cache_size; 27291cf71b0Sdanielk1977 pragma default_cache_size; 2731bdd9b57Sdrh } 27491cf71b0Sdanielk1977} {123 123} 2751bdd9b57Sdrhdo_test pragma-4.5 { 2761bdd9b57Sdrh execsql { 27791cf71b0Sdanielk1977 DETACH aux; 27891cf71b0Sdanielk1977 ATTACH 'test3.db' AS aux; 27991cf71b0Sdanielk1977 pragma aux.cache_size; 28091cf71b0Sdanielk1977 pragma aux.default_cache_size; 2811bdd9b57Sdrh } 28291cf71b0Sdanielk1977} {2000 2000} 2831bdd9b57Sdrhdo_test pragma-4.6 { 2841bdd9b57Sdrh execsql { 28591cf71b0Sdanielk1977 DETACH aux; 28691cf71b0Sdanielk1977 ATTACH 'test2.db' AS aux; 28791cf71b0Sdanielk1977 pragma aux.cache_size; 28891cf71b0Sdanielk1977 pragma aux.default_cache_size; 2891bdd9b57Sdrh } 29091cf71b0Sdanielk1977} {456 456} 291c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 2921bdd9b57Sdrh 29391cf71b0Sdanielk1977# Test that modifying the sync-level in the middle of a transaction is 29491cf71b0Sdanielk1977# disallowed. 295c7b4a44cSdanielk1977ifcapable pager_pragmas { 29691cf71b0Sdanielk1977do_test pragma-5.0 { 2971bdd9b57Sdrh execsql { 29891cf71b0Sdanielk1977 pragma synchronous; 2991bdd9b57Sdrh } 30091cf71b0Sdanielk1977} {2} 30191cf71b0Sdanielk1977do_test pragma-5.1 { 3021bdd9b57Sdrh catchsql { 3031bdd9b57Sdrh BEGIN; 30491cf71b0Sdanielk1977 pragma synchronous = OFF; 3051bdd9b57Sdrh } 30691cf71b0Sdanielk1977} {1 {Safety level may not be changed inside a transaction}} 30791cf71b0Sdanielk1977do_test pragma-5.2 { 30891cf71b0Sdanielk1977 execsql { 30991cf71b0Sdanielk1977 pragma synchronous; 31091cf71b0Sdanielk1977 } 31191cf71b0Sdanielk1977} {2} 3125260f7e9Sdrhcatchsql {COMMIT;} 313c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 3145260f7e9Sdrh 3155260f7e9Sdrh# Test schema-query pragmas 3165260f7e9Sdrh# 31727188fb5Sdanielk1977ifcapable schema_pragmas { 3185260f7e9Sdrhdo_test pragma-6.1 { 319956bc92cSdrh set res {} 32040e016e4Sdrh execsql {SELECT * FROM sqlite_temp_master} 3215260f7e9Sdrh foreach {idx name file} [execsql {pragma database_list}] { 3225260f7e9Sdrh lappend res $idx $name 3235260f7e9Sdrh } 3245260f7e9Sdrh set res 325a71aa001Sdrh} {0 main 1 temp 2 aux} 3265260f7e9Sdrhdo_test pragma-6.2 { 3275260f7e9Sdrh execsql { 3285260f7e9Sdrh pragma table_info(t2) 3295260f7e9Sdrh } 3305260f7e9Sdrh} {0 a numeric 0 {} 0 1 b numeric 0 {} 0 2 c numeric 0 {} 0} 3316bf89570Sdrhifcapable {foreignkey} { 3325260f7e9Sdrh do_test pragma-6.3 { 3335260f7e9Sdrh execsql { 3345260f7e9Sdrh CREATE TABLE t3(a int references t2(b), b UNIQUE); 3355260f7e9Sdrh pragma foreign_key_list(t3); 3365260f7e9Sdrh } 3375260f7e9Sdrh } {0 0 t2 a b} 3385260f7e9Sdrh do_test pragma-6.4 { 3395260f7e9Sdrh execsql { 3405260f7e9Sdrh pragma index_list(t3); 3415260f7e9Sdrh } 3425260f7e9Sdrh } {0 sqlite_autoindex_t3_1 1} 3436bf89570Sdrh} 3446bf89570Sdrhifcapable {!foreignkey} { 3456bf89570Sdrh execsql {CREATE TABLE t3(a,b UNIQUE)} 3466bf89570Sdrh} 3475260f7e9Sdrhdo_test pragma-6.5 { 3485260f7e9Sdrh execsql { 3495260f7e9Sdrh CREATE INDEX t3i1 ON t3(a,b); 3505260f7e9Sdrh pragma index_info(t3i1); 3515260f7e9Sdrh } 3525260f7e9Sdrh} {0 0 a 1 1 b} 35327188fb5Sdanielk1977} ;# ifcapable schema_pragmas 3545260f7e9Sdrh# Miscellaneous tests 3555260f7e9Sdrh# 35627188fb5Sdanielk1977ifcapable schema_pragmas { 3575260f7e9Sdrhdo_test pragma-7.1 { 3585260f7e9Sdrh # Make sure a pragma knows to read the schema if it needs to 3595260f7e9Sdrh db close 3605260f7e9Sdrh sqlite3 db test.db 3615260f7e9Sdrh execsql { 3625260f7e9Sdrh pragma index_list(t3); 3635260f7e9Sdrh } 3645260f7e9Sdrh} {0 t3i1 0 1 sqlite_autoindex_t3_1 1} 36527188fb5Sdanielk1977} ;# ifcapable schema_pragmas 3666c62608fSdrhifcapable {utf16} { 3675260f7e9Sdrh do_test pragma-7.2 { 3685260f7e9Sdrh db close 3695260f7e9Sdrh sqlite3 db test.db 3705260f7e9Sdrh catchsql { 3715260f7e9Sdrh pragma encoding=bogus; 3725260f7e9Sdrh } 3735260f7e9Sdrh } {1 {unsupported encoding: bogus}} 3746c62608fSdrh} 3755260f7e9Sdrhdo_test pragma-7.3 { 3765260f7e9Sdrh db close 3775260f7e9Sdrh sqlite3 db test.db 3785260f7e9Sdrh execsql { 3795260f7e9Sdrh pragma lock_status; 3805260f7e9Sdrh } 3815260f7e9Sdrh} {main unlocked temp closed} 3825260f7e9Sdrh 3835260f7e9Sdrh 384dae2495bSdanielk1977#---------------------------------------------------------------------- 385b92b70bbSdanielk1977# Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA 386b92b70bbSdanielk1977# user_version" statements. 387dae2495bSdanielk1977# 388b92b70bbSdanielk1977# pragma-8.1: PRAGMA schema_version 389b92b70bbSdanielk1977# pragma-8.2: PRAGMA user_version 390dae2495bSdanielk1977# 391dae2495bSdanielk1977 39211cf9fbcSdanielk1977ifcapable schema_version { 39311cf9fbcSdanielk1977 394b92b70bbSdanielk1977# First check that we can set the schema version and then retrieve the 395dae2495bSdanielk1977# same value. 396dae2495bSdanielk1977do_test pragma-8.1.1 { 397dae2495bSdanielk1977 execsql { 398b92b70bbSdanielk1977 PRAGMA schema_version = 105; 399dae2495bSdanielk1977 } 400dae2495bSdanielk1977} {} 401dae2495bSdanielk1977do_test pragma-8.1.2 { 402dae2495bSdanielk1977 execsql { 403b92b70bbSdanielk1977 PRAGMA schema_version; 404dae2495bSdanielk1977 } 405dae2495bSdanielk1977} 105 406dae2495bSdanielk1977do_test pragma-8.1.3 { 407dae2495bSdanielk1977 execsql { 408b92b70bbSdanielk1977 PRAGMA schema_version = 106; 409dae2495bSdanielk1977 } 410dae2495bSdanielk1977} {} 411dae2495bSdanielk1977do_test pragma-8.1.4 { 412dae2495bSdanielk1977 execsql { 413b92b70bbSdanielk1977 PRAGMA schema_version; 414dae2495bSdanielk1977 } 415dae2495bSdanielk1977} 106 416dae2495bSdanielk1977 417b92b70bbSdanielk1977# Check that creating a table modifies the schema-version (this is really 418b92b70bbSdanielk1977# to verify that the value being read is in fact the schema version). 419dae2495bSdanielk1977do_test pragma-8.1.5 { 420dae2495bSdanielk1977 execsql { 421dae2495bSdanielk1977 CREATE TABLE t4(a, b, c); 422dae2495bSdanielk1977 INSERT INTO t4 VALUES(1, 2, 3); 423dae2495bSdanielk1977 SELECT * FROM t4; 424dae2495bSdanielk1977 } 425dae2495bSdanielk1977} {1 2 3} 426dae2495bSdanielk1977do_test pragma-8.1.6 { 427dae2495bSdanielk1977 execsql { 428b92b70bbSdanielk1977 PRAGMA schema_version; 429dae2495bSdanielk1977 } 430dae2495bSdanielk1977} 107 431dae2495bSdanielk1977 432dae2495bSdanielk1977# Now open a second connection to the database. Ensure that changing the 433b92b70bbSdanielk1977# schema-version using the first connection forces the second connection 434dae2495bSdanielk1977# to reload the schema. This has to be done using the C-API test functions, 435dae2495bSdanielk1977# because the TCL API accounts for SCHEMA_ERROR and retries the query. 436dae2495bSdanielk1977do_test pragma-8.1.7 { 437dae2495bSdanielk1977 set ::DB2 [sqlite3 db2 test.db] 438dae2495bSdanielk1977 execsql { 439dae2495bSdanielk1977 SELECT * FROM t4; 440dae2495bSdanielk1977 } db2 441dae2495bSdanielk1977} {1 2 3} 442dae2495bSdanielk1977do_test pragma-8.1.8 { 443dae2495bSdanielk1977 execsql { 444b92b70bbSdanielk1977 PRAGMA schema_version = 108; 445dae2495bSdanielk1977 } 446dae2495bSdanielk1977} {} 447dae2495bSdanielk1977do_test pragma-8.1.9 { 448dae2495bSdanielk1977 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY] 449dae2495bSdanielk1977 sqlite3_step $::STMT 450dae2495bSdanielk1977} SQLITE_ERROR 451dae2495bSdanielk1977do_test pragma-8.1.10 { 452dae2495bSdanielk1977 sqlite3_finalize $::STMT 453dae2495bSdanielk1977} SQLITE_SCHEMA 454dae2495bSdanielk1977 455b92b70bbSdanielk1977# Make sure the schema-version can be manipulated in an attached database. 456dae2495bSdanielk1977file delete -force test2.db 457dae2495bSdanielk1977file delete -force test2.db-journal 458dae2495bSdanielk1977do_test pragma-8.1.11 { 459dae2495bSdanielk1977 execsql { 460dae2495bSdanielk1977 ATTACH 'test2.db' AS aux; 461dae2495bSdanielk1977 CREATE TABLE aux.t1(a, b, c); 462b92b70bbSdanielk1977 PRAGMA aux.schema_version = 205; 463dae2495bSdanielk1977 } 464dae2495bSdanielk1977} {} 465dae2495bSdanielk1977do_test pragma-8.1.12 { 466dae2495bSdanielk1977 execsql { 467b92b70bbSdanielk1977 PRAGMA aux.schema_version; 468dae2495bSdanielk1977 } 469dae2495bSdanielk1977} 205 470dae2495bSdanielk1977do_test pragma-8.1.13 { 471dae2495bSdanielk1977 execsql { 472b92b70bbSdanielk1977 PRAGMA schema_version; 473dae2495bSdanielk1977 } 474dae2495bSdanielk1977} 108 475dae2495bSdanielk1977 476b92b70bbSdanielk1977# And check that modifying the schema-version in an attached database 477dae2495bSdanielk1977# forces the second connection to reload the schema. 478dae2495bSdanielk1977do_test pragma-8.1.14 { 479dae2495bSdanielk1977 set ::DB2 [sqlite3 db2 test.db] 480dae2495bSdanielk1977 execsql { 481dae2495bSdanielk1977 ATTACH 'test2.db' AS aux; 482dae2495bSdanielk1977 SELECT * FROM aux.t1; 483dae2495bSdanielk1977 } db2 484dae2495bSdanielk1977} {} 485dae2495bSdanielk1977do_test pragma-8.1.15 { 486dae2495bSdanielk1977 execsql { 487b92b70bbSdanielk1977 PRAGMA aux.schema_version = 206; 488dae2495bSdanielk1977 } 489dae2495bSdanielk1977} {} 490dae2495bSdanielk1977do_test pragma-8.1.16 { 491dae2495bSdanielk1977 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY] 492dae2495bSdanielk1977 sqlite3_step $::STMT 493dae2495bSdanielk1977} SQLITE_ERROR 494dae2495bSdanielk1977do_test pragma-8.1.17 { 495dae2495bSdanielk1977 sqlite3_finalize $::STMT 496dae2495bSdanielk1977} SQLITE_SCHEMA 497dae2495bSdanielk1977do_test pragma-8.1.18 { 498dae2495bSdanielk1977 db2 close 499dae2495bSdanielk1977} {} 500dae2495bSdanielk1977 501b92b70bbSdanielk1977# Now test that the user-version can be read and written (and that we aren't 502b92b70bbSdanielk1977# accidentally manipulating the schema-version instead). 503dae2495bSdanielk1977do_test pragma-8.2.1 { 504dae2495bSdanielk1977 execsql { 505b92b70bbSdanielk1977 PRAGMA user_version; 506dae2495bSdanielk1977 } 507dae2495bSdanielk1977} {0} 508dae2495bSdanielk1977do_test pragma-8.2.2 { 509dae2495bSdanielk1977 execsql { 510b92b70bbSdanielk1977 PRAGMA user_version = 2; 511dae2495bSdanielk1977 } 512dae2495bSdanielk1977} {} 513dae2495bSdanielk1977do_test pragma-8.2.3 { 514dae2495bSdanielk1977 execsql { 515b92b70bbSdanielk1977 PRAGMA user_version; 516dae2495bSdanielk1977 } 517dae2495bSdanielk1977} {2} 518dae2495bSdanielk1977do_test pragma-8.2.4 { 519dae2495bSdanielk1977 execsql { 520b92b70bbSdanielk1977 PRAGMA schema_version; 521dae2495bSdanielk1977 } 522dae2495bSdanielk1977} {108} 523dae2495bSdanielk1977 524b92b70bbSdanielk1977# Check that the user-version in the auxilary database can be manipulated ( 525dae2495bSdanielk1977# and that we aren't accidentally manipulating the same in the main db). 526dae2495bSdanielk1977do_test pragma-8.2.5 { 527dae2495bSdanielk1977 execsql { 528b92b70bbSdanielk1977 PRAGMA aux.user_version; 529dae2495bSdanielk1977 } 530dae2495bSdanielk1977} {0} 531dae2495bSdanielk1977do_test pragma-8.2.6 { 532dae2495bSdanielk1977 execsql { 533b92b70bbSdanielk1977 PRAGMA aux.user_version = 3; 534dae2495bSdanielk1977 } 535dae2495bSdanielk1977} {} 536dae2495bSdanielk1977do_test pragma-8.2.7 { 537dae2495bSdanielk1977 execsql { 538b92b70bbSdanielk1977 PRAGMA aux.user_version; 539dae2495bSdanielk1977 } 540dae2495bSdanielk1977} {3} 541dae2495bSdanielk1977do_test pragma-8.2.8 { 542dae2495bSdanielk1977 execsql { 543b92b70bbSdanielk1977 PRAGMA main.user_version; 544dae2495bSdanielk1977 } 545dae2495bSdanielk1977} {2} 546dae2495bSdanielk1977 547b92b70bbSdanielk1977# Now check that a ROLLBACK resets the user-version if it has been modified 548dae2495bSdanielk1977# within a transaction. 549dae2495bSdanielk1977do_test pragma-8.2.9 { 550dae2495bSdanielk1977 execsql { 551dae2495bSdanielk1977 BEGIN; 552b92b70bbSdanielk1977 PRAGMA aux.user_version = 10; 553b92b70bbSdanielk1977 PRAGMA user_version = 11; 554dae2495bSdanielk1977 } 555dae2495bSdanielk1977} {} 556dae2495bSdanielk1977do_test pragma-8.2.10 { 557dae2495bSdanielk1977 execsql { 558b92b70bbSdanielk1977 PRAGMA aux.user_version; 559dae2495bSdanielk1977 } 560dae2495bSdanielk1977} {10} 561dae2495bSdanielk1977do_test pragma-8.2.11 { 562dae2495bSdanielk1977 execsql { 563b92b70bbSdanielk1977 PRAGMA main.user_version; 564dae2495bSdanielk1977 } 565dae2495bSdanielk1977} {11} 566dae2495bSdanielk1977do_test pragma-8.2.12 { 567dae2495bSdanielk1977 execsql { 568dae2495bSdanielk1977 ROLLBACK; 569b92b70bbSdanielk1977 PRAGMA aux.user_version; 570dae2495bSdanielk1977 } 571dae2495bSdanielk1977} {3} 572dae2495bSdanielk1977do_test pragma-8.2.13 { 573dae2495bSdanielk1977 execsql { 574b92b70bbSdanielk1977 PRAGMA main.user_version; 575dae2495bSdanielk1977 } 576dae2495bSdanielk1977} {2} 577dae2495bSdanielk1977 578b92b70bbSdanielk1977# Try a negative value for the user-version 579dae2495bSdanielk1977do_test pragma-8.2.14 { 580dae2495bSdanielk1977 execsql { 581b92b70bbSdanielk1977 PRAGMA user_version = -450; 582dae2495bSdanielk1977 } 583dae2495bSdanielk1977} {} 584dae2495bSdanielk1977do_test pragma-8.2.15 { 585dae2495bSdanielk1977 execsql { 586b92b70bbSdanielk1977 PRAGMA user_version; 587dae2495bSdanielk1977 } 588dae2495bSdanielk1977} {-450} 5891bdd9b57Sdrh 590*9a09a3caStpoindex 591*9a09a3caStpoindex# Test temp_store and temp_store_directory pragmas 592*9a09a3caStpoindex# 593*9a09a3caStpoindex 594*9a09a3caStpoindexdo_test pragma-9.1 { 595*9a09a3caStpoindex db close 596*9a09a3caStpoindex sqlite3 db test.db 597*9a09a3caStpoindex execsql { 598*9a09a3caStpoindex PRAGMA temp_store; 599*9a09a3caStpoindex } 600*9a09a3caStpoindex} {0} 601*9a09a3caStpoindexdo_test pragma-9.2 { 602*9a09a3caStpoindex execsql { 603*9a09a3caStpoindex PRAGMA temp_store=file; 604*9a09a3caStpoindex PRAGMA temp_store; 605*9a09a3caStpoindex } 606*9a09a3caStpoindex} {1} 607*9a09a3caStpoindexdo_test pragma-9.3 { 608*9a09a3caStpoindex execsql { 609*9a09a3caStpoindex PRAGMA temp_store=memory; 610*9a09a3caStpoindex PRAGMA temp_store; 611*9a09a3caStpoindex } 612*9a09a3caStpoindex} {2} 613*9a09a3caStpoindexdo_test pragma-9.4 { 614*9a09a3caStpoindex execsql { 615*9a09a3caStpoindex PRAGMA temp_store_directory; 616*9a09a3caStpoindex } 617*9a09a3caStpoindex} {} 618*9a09a3caStpoindexdo_test pragma-9.5 { 619*9a09a3caStpoindex execsql " \ 620*9a09a3caStpoindex PRAGMA temp_store_directory='[pwd]'; \ 621*9a09a3caStpoindex " 622*9a09a3caStpoindex} {} 623*9a09a3caStpoindexdo_test pragma-9.6 { 624*9a09a3caStpoindex execsql { 625*9a09a3caStpoindex PRAGMA temp_store_directory; 626*9a09a3caStpoindex } 627*9a09a3caStpoindex} [pwd] 628*9a09a3caStpoindexdo_test pragma-9.7 { 629*9a09a3caStpoindex set result "" 630*9a09a3caStpoindex catch { 631*9a09a3caStpoindex execsql { 632*9a09a3caStpoindex PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR'; 633*9a09a3caStpoindex } 634*9a09a3caStpoindex } result 635*9a09a3caStpoindex set result 636*9a09a3caStpoindex} {not a directory, or not writable} 637*9a09a3caStpoindexdo_test pragma-9.8 { 638*9a09a3caStpoindex execsql { 639*9a09a3caStpoindex PRAGMA temp_store_directory=''; 640*9a09a3caStpoindex } 641*9a09a3caStpoindex} {} 642*9a09a3caStpoindexdo_test pragma-9.9 { 643*9a09a3caStpoindex execsql { 644*9a09a3caStpoindex PRAGMA temp_store_directory; 645*9a09a3caStpoindex PRAGMA temp_store=FILE; 646*9a09a3caStpoindex CREATE TEMP TABLE temp_store_directory_test(a integer); 647*9a09a3caStpoindex INSERT INTO temp_store_directory_test values (2); 648*9a09a3caStpoindex SELECT * FROM temp_store_directory_test; 649*9a09a3caStpoindex } 650*9a09a3caStpoindex} {2} 651*9a09a3caStpoindexdo_test pragma-9.10 { 652*9a09a3caStpoindex set result "" 653*9a09a3caStpoindex catch { 654*9a09a3caStpoindex execsql " \ 655*9a09a3caStpoindex PRAGMA temp_store_directory='[pwd]'; \ 656*9a09a3caStpoindex SELECT * FROM temp_store_directory_test; 657*9a09a3caStpoindex " 658*9a09a3caStpoindex } result 659*9a09a3caStpoindex set result 660*9a09a3caStpoindex} {no such table: temp_store_directory_test} 661*9a09a3caStpoindex 662*9a09a3caStpoindex 663*9a09a3caStpoindex 66411cf9fbcSdanielk1977} ; # ifcapable schema_version 66511cf9fbcSdanielk1977 666cd61c281Sdrhfinish_test 667