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*aebf413dSaswift# $Id: pragma.test,v 1.70 2008/11/21 00:10:35 aswift 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. 28cc6bd383Sdanielk1977# pragma-6.*: Test schema-query pragmas. 29cc6bd383Sdanielk1977# pragma-7.*: Miscellaneous tests. 30cc6bd383Sdanielk1977# pragma-8.*: Test user_version and schema_version pragmas. 319a09a3caStpoindex# pragma-9.*: Test temp_store and temp_store_directory. 32cc6bd383Sdanielk1977# pragma-10.*: Test the count_changes pragma in the presence of triggers. 3348af65aeSdanielk1977# pragma-11.*: Test the collation_list pragma. 3459a93791Sdanielk1977# pragma-14.*: Test the page_count pragma. 358cf6c554Sdanielk1977# pragma-15.*: Test that the value set using the cache_size pragma is not 368cf6c554Sdanielk1977# reset when the schema is reloaded. 37*aebf413dSaswift# pragma-16.*: Test proxy locking 3891cf71b0Sdanielk1977# 3991cf71b0Sdanielk1977 4005a82983Sdrhifcapable !pragma { 4105a82983Sdrh finish_test 4205a82983Sdrh return 4305a82983Sdrh} 4405a82983Sdrh 45cd61c281Sdrh# Delete the preexisting database to avoid the special setup 46cd61c281Sdrh# that the "all.test" script does. 47cd61c281Sdrh# 48cd61c281Sdrhdb close 4925403650Sdrhfile delete test.db test.db-journal 5025403650Sdrhfile delete test3.db test3.db-journal 51dddca286Sdrhsqlite3 db test.db; set DB [sqlite3_connection_pointer db] 52cd61c281Sdrh 531e9daa6aSdrh 54c7b4a44cSdanielk1977ifcapable pager_pragmas { 551e9daa6aSdrhset DFLT_CACHE_SZ [db one {PRAGMA default_cache_size}] 561e9daa6aSdrhset TEMP_CACHE_SZ [db one {PRAGMA temp.default_cache_size}] 57cd61c281Sdrhdo_test pragma-1.1 { 58cd61c281Sdrh execsql { 59cd61c281Sdrh PRAGMA cache_size; 60cd61c281Sdrh PRAGMA default_cache_size; 61cd61c281Sdrh PRAGMA synchronous; 62cd61c281Sdrh } 631e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] 64cd61c281Sdrhdo_test pragma-1.2 { 65cd61c281Sdrh execsql { 66eb43e5c7Sdrh PRAGMA synchronous=OFF; 67cd61c281Sdrh PRAGMA cache_size=1234; 68cd61c281Sdrh PRAGMA cache_size; 69cd61c281Sdrh PRAGMA default_cache_size; 70cd61c281Sdrh PRAGMA synchronous; 71cd61c281Sdrh } 721e9daa6aSdrh} [list 1234 $DFLT_CACHE_SZ 0] 73cd61c281Sdrhdo_test pragma-1.3 { 74cd61c281Sdrh db close 75ef4ac8f9Sdrh sqlite3 db test.db 76cd61c281Sdrh execsql { 77cd61c281Sdrh PRAGMA cache_size; 78cd61c281Sdrh PRAGMA default_cache_size; 79cd61c281Sdrh PRAGMA synchronous; 80cd61c281Sdrh } 811e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] 82cd61c281Sdrhdo_test pragma-1.4 { 83cd61c281Sdrh execsql { 84cd61c281Sdrh PRAGMA synchronous=OFF; 85cd61c281Sdrh PRAGMA cache_size; 86cd61c281Sdrh PRAGMA default_cache_size; 87cd61c281Sdrh PRAGMA synchronous; 88cd61c281Sdrh } 891e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 0] 90cd61c281Sdrhdo_test pragma-1.5 { 91cd61c281Sdrh execsql { 92cd61c281Sdrh PRAGMA cache_size=4321; 93cd61c281Sdrh PRAGMA cache_size; 94cd61c281Sdrh PRAGMA default_cache_size; 95cd61c281Sdrh PRAGMA synchronous; 96cd61c281Sdrh } 971e9daa6aSdrh} [list 4321 $DFLT_CACHE_SZ 0] 98cd61c281Sdrhdo_test pragma-1.6 { 99cd61c281Sdrh execsql { 100cd61c281Sdrh PRAGMA synchronous=ON; 101cd61c281Sdrh PRAGMA cache_size; 102cd61c281Sdrh PRAGMA default_cache_size; 103cd61c281Sdrh PRAGMA synchronous; 104cd61c281Sdrh } 1051e9daa6aSdrh} [list 4321 $DFLT_CACHE_SZ 1] 106cd61c281Sdrhdo_test pragma-1.7 { 107cd61c281Sdrh db close 108ef4ac8f9Sdrh sqlite3 db test.db 109cd61c281Sdrh execsql { 110cd61c281Sdrh PRAGMA cache_size; 111cd61c281Sdrh PRAGMA default_cache_size; 112cd61c281Sdrh PRAGMA synchronous; 113cd61c281Sdrh } 1141e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] 115cd61c281Sdrhdo_test pragma-1.8 { 116cd61c281Sdrh execsql { 117cd61c281Sdrh PRAGMA default_cache_size=123; 118cd61c281Sdrh PRAGMA cache_size; 119cd61c281Sdrh PRAGMA default_cache_size; 120cd61c281Sdrh PRAGMA synchronous; 121cd61c281Sdrh } 12291cf71b0Sdanielk1977} {123 123 2} 123802d69a7Sdrhdo_test pragma-1.9.1 { 124cd61c281Sdrh db close 125dddca286Sdrh sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db] 126cd61c281Sdrh execsql { 127cd61c281Sdrh PRAGMA cache_size; 128cd61c281Sdrh PRAGMA default_cache_size; 129cd61c281Sdrh PRAGMA synchronous; 130cd61c281Sdrh } 13191cf71b0Sdanielk1977} {123 123 2} 132802d69a7Sdrhifcapable vacuum { 133802d69a7Sdrh do_test pragma-1.9.2 { 134802d69a7Sdrh execsql { 135802d69a7Sdrh VACUUM; 136802d69a7Sdrh PRAGMA cache_size; 137802d69a7Sdrh PRAGMA default_cache_size; 138802d69a7Sdrh PRAGMA synchronous; 139802d69a7Sdrh } 140802d69a7Sdrh } {123 123 2} 141802d69a7Sdrh} 14291cf71b0Sdanielk1977do_test pragma-1.10 { 1435a38705eSdrh execsql { 1444303feedSdrh PRAGMA synchronous=NORMAL; 1454303feedSdrh PRAGMA cache_size; 1464303feedSdrh PRAGMA default_cache_size; 1474303feedSdrh PRAGMA synchronous; 1484303feedSdrh } 14991cf71b0Sdanielk1977} {123 123 1} 15091cf71b0Sdanielk1977do_test pragma-1.11 { 1514303feedSdrh execsql { 1524303feedSdrh PRAGMA synchronous=FULL; 1534303feedSdrh PRAGMA cache_size; 1544303feedSdrh PRAGMA default_cache_size; 1554303feedSdrh PRAGMA synchronous; 1564303feedSdrh } 15791cf71b0Sdanielk1977} {123 123 2} 15891cf71b0Sdanielk1977do_test pragma-1.12 { 1594303feedSdrh db close 160dddca286Sdrh sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db] 1614303feedSdrh execsql { 1624303feedSdrh PRAGMA cache_size; 1634303feedSdrh PRAGMA default_cache_size; 1644303feedSdrh PRAGMA synchronous; 1654303feedSdrh } 16691cf71b0Sdanielk1977} {123 123 2} 16791cf71b0Sdanielk1977 1685260f7e9Sdrh# Make sure the pragma handler understands numeric values in addition 1695260f7e9Sdrh# to keywords like "off" and "full". 1705260f7e9Sdrh# 1715260f7e9Sdrhdo_test pragma-1.13 { 1725260f7e9Sdrh execsql { 1735260f7e9Sdrh PRAGMA synchronous=0; 1745260f7e9Sdrh PRAGMA synchronous; 1755260f7e9Sdrh } 1765260f7e9Sdrh} {0} 1775260f7e9Sdrhdo_test pragma-1.14 { 1785260f7e9Sdrh execsql { 1795260f7e9Sdrh PRAGMA synchronous=2; 1805260f7e9Sdrh PRAGMA synchronous; 1815260f7e9Sdrh } 1825260f7e9Sdrh} {2} 183c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 1845260f7e9Sdrh 1855260f7e9Sdrh# Test turning "flag" pragmas on and off. 1865260f7e9Sdrh# 1876338c762Sdanielk1977ifcapable debug { 1886338c762Sdanielk1977 # Pragma "vdbe_listing" is only available if compiled with SQLITE_DEBUG 1896338c762Sdanielk1977 # 1905260f7e9Sdrh do_test pragma-1.15 { 1915260f7e9Sdrh execsql { 1925260f7e9Sdrh PRAGMA vdbe_listing=YES; 1935260f7e9Sdrh PRAGMA vdbe_listing; 1945260f7e9Sdrh } 1955260f7e9Sdrh } {1} 1965260f7e9Sdrh do_test pragma-1.16 { 1975260f7e9Sdrh execsql { 1985260f7e9Sdrh PRAGMA vdbe_listing=NO; 1995260f7e9Sdrh PRAGMA vdbe_listing; 2005260f7e9Sdrh } 2015260f7e9Sdrh } {0} 2026338c762Sdanielk1977} 2036338c762Sdanielk1977 2045260f7e9Sdrhdo_test pragma-1.17 { 2055260f7e9Sdrh execsql { 2065260f7e9Sdrh PRAGMA parser_trace=ON; 2075260f7e9Sdrh PRAGMA parser_trace=OFF; 2085260f7e9Sdrh } 2095260f7e9Sdrh} {} 2105260f7e9Sdrhdo_test pragma-1.18 { 2115260f7e9Sdrh execsql { 2125260f7e9Sdrh PRAGMA bogus = -1234; -- Parsing of negative values 2135260f7e9Sdrh } 2145260f7e9Sdrh} {} 2155260f7e9Sdrh 21691cf71b0Sdanielk1977# Test modifying the safety_level of an attached database. 2175a8f9374Sdanielk1977ifcapable pager_pragmas&&attach { 21891cf71b0Sdanielk1977 do_test pragma-2.1 { 21991cf71b0Sdanielk1977 file delete -force test2.db 22091cf71b0Sdanielk1977 file delete -force test2.db-journal 2214303feedSdrh execsql { 22291cf71b0Sdanielk1977 ATTACH 'test2.db' AS aux; 2234303feedSdrh } 22491cf71b0Sdanielk1977 } {} 22591cf71b0Sdanielk1977 do_test pragma-2.2 { 2264303feedSdrh execsql { 22791cf71b0Sdanielk1977 pragma aux.synchronous; 2284303feedSdrh } 22991cf71b0Sdanielk1977 } {2} 23091cf71b0Sdanielk1977 do_test pragma-2.3 { 23191cf71b0Sdanielk1977 execsql { 23291cf71b0Sdanielk1977 pragma aux.synchronous = OFF; 23391cf71b0Sdanielk1977 pragma aux.synchronous; 23491cf71b0Sdanielk1977 pragma synchronous; 23591cf71b0Sdanielk1977 } 23691cf71b0Sdanielk1977 } {0 2} 23791cf71b0Sdanielk1977 do_test pragma-2.4 { 23891cf71b0Sdanielk1977 execsql { 23991cf71b0Sdanielk1977 pragma aux.synchronous = ON; 24091cf71b0Sdanielk1977 pragma synchronous; 24191cf71b0Sdanielk1977 pragma aux.synchronous; 24291cf71b0Sdanielk1977 } 24391cf71b0Sdanielk1977 } {2 1} 244c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 2454303feedSdrh 246ed717fe3Sdrh# Construct a corrupted index and make sure the integrity_check 247ed717fe3Sdrh# pragma finds it. 248ed717fe3Sdrh# 24925d6543dSdrh# These tests won't work if the database is encrypted 25025d6543dSdrh# 251ed717fe3Sdrhdo_test pragma-3.1 { 2521e9daa6aSdrh db close 2531e9daa6aSdrh file delete -force test.db test.db-journal 2541e9daa6aSdrh sqlite3 db test.db 255ed717fe3Sdrh execsql { 2561e9daa6aSdrh PRAGMA auto_vacuum=OFF; 257ed717fe3Sdrh BEGIN; 258ed717fe3Sdrh CREATE TABLE t2(a,b,c); 259ed717fe3Sdrh CREATE INDEX i2 ON t2(a); 260ed717fe3Sdrh INSERT INTO t2 VALUES(11,2,3); 261ed717fe3Sdrh INSERT INTO t2 VALUES(22,3,4); 262ed717fe3Sdrh COMMIT; 263ed717fe3Sdrh SELECT rowid, * from t2; 264ed717fe3Sdrh } 265ed717fe3Sdrh} {1 11 2 3 2 22 3 4} 2665a8f9374Sdanielk1977ifcapable attach { 26740e016e4Sdrh if {![sqlite3 -has-codec] && $sqlite_options(integrityck)} { 268ed717fe3Sdrh do_test pragma-3.2 { 269bb8a279eSdrh db eval {SELECT rootpage FROM sqlite_master WHERE name='i2'} break 270bb8a279eSdrh set pgsz [db eval {PRAGMA page_size}] 271bb8a279eSdrh # overwrite the header on the rootpage of the index in order to 272bb8a279eSdrh # make the index appear to be empty. 273bb8a279eSdrh # 274bb8a279eSdrh set offset [expr {$pgsz*($rootpage-1)}] 275bb8a279eSdrh hexio_write test.db $offset 0a00000000040000000000 276bb8a279eSdrh db close 277bb8a279eSdrh sqlite3 db test.db 278ed717fe3Sdrh execsql {PRAGMA integrity_check} 279bb8a279eSdrh } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}} 28091cf71b0Sdanielk1977 do_test pragma-3.3 { 2811dcdbc06Sdrh execsql {PRAGMA integrity_check=1} 2821dcdbc06Sdrh } {{rowid 1 missing from index i2}} 2831dcdbc06Sdrh do_test pragma-3.4 { 28491cf71b0Sdanielk1977 execsql { 2851dcdbc06Sdrh ATTACH DATABASE 'test.db' AS t2; 2861dcdbc06Sdrh PRAGMA integrity_check 28791cf71b0Sdanielk1977 } 288bb8a279eSdrh } {{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}} 2891dcdbc06Sdrh do_test pragma-3.5 { 2901dcdbc06Sdrh execsql { 291bb8a279eSdrh PRAGMA integrity_check=4 2921dcdbc06Sdrh } 293bb8a279eSdrh } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2}} 2941dcdbc06Sdrh do_test pragma-3.6 { 2951dcdbc06Sdrh execsql { 2961dcdbc06Sdrh PRAGMA integrity_check=xyz 2971dcdbc06Sdrh } 298bb8a279eSdrh } {{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}} 2991dcdbc06Sdrh do_test pragma-3.7 { 3001dcdbc06Sdrh execsql { 3011dcdbc06Sdrh PRAGMA integrity_check=0 3021dcdbc06Sdrh } 303bb8a279eSdrh } {{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}} 3041dcdbc06Sdrh 3051dcdbc06Sdrh # Add additional corruption by appending unused pages to the end of 3061dcdbc06Sdrh # the database file testerr.db 3071dcdbc06Sdrh # 3081dcdbc06Sdrh do_test pragma-3.8 { 3091dcdbc06Sdrh execsql {DETACH t2} 3101dcdbc06Sdrh file delete -force testerr.db testerr.db-journal 311e3d559adSdrh set out [open testerr.db w] 312e3d559adSdrh fconfigure $out -translation binary 313e3d559adSdrh set in [open test.db r] 314e3d559adSdrh fconfigure $in -translation binary 3151dcdbc06Sdrh puts -nonewline $out [read $in] 3161dcdbc06Sdrh seek $in 0 3171dcdbc06Sdrh puts -nonewline $out [read $in] 3181dcdbc06Sdrh close $in 3191dcdbc06Sdrh close $out 3201dcdbc06Sdrh execsql {REINDEX t2} 3211dcdbc06Sdrh execsql {PRAGMA integrity_check} 3221dcdbc06Sdrh } {ok} 32341c58b78Sdanielk1977 do_test pragma-3.8.1 { 32441c58b78Sdanielk1977 execsql {PRAGMA quick_check} 32541c58b78Sdanielk1977 } {ok} 3261dcdbc06Sdrh do_test pragma-3.9 { 3271dcdbc06Sdrh execsql { 3281dcdbc06Sdrh ATTACH 'testerr.db' AS t2; 3291dcdbc06Sdrh PRAGMA integrity_check 3301dcdbc06Sdrh } 3311dcdbc06Sdrh } {{*** in database t2 *** 3321dcdbc06SdrhPage 4 is never used 3331dcdbc06SdrhPage 5 is never used 334bb8a279eSdrhPage 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}} 3351dcdbc06Sdrh do_test pragma-3.10 { 3361dcdbc06Sdrh execsql { 3371dcdbc06Sdrh PRAGMA integrity_check=1 3381dcdbc06Sdrh } 3391dcdbc06Sdrh } {{*** in database t2 *** 3401dcdbc06SdrhPage 4 is never used}} 3411dcdbc06Sdrh do_test pragma-3.11 { 3421dcdbc06Sdrh execsql { 3431dcdbc06Sdrh PRAGMA integrity_check=5 3441dcdbc06Sdrh } 3451dcdbc06Sdrh } {{*** in database t2 *** 3461dcdbc06SdrhPage 4 is never used 3471dcdbc06SdrhPage 5 is never used 348bb8a279eSdrhPage 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2}} 3491dcdbc06Sdrh do_test pragma-3.12 { 3501dcdbc06Sdrh execsql { 3511dcdbc06Sdrh PRAGMA integrity_check=4 3521dcdbc06Sdrh } 3531dcdbc06Sdrh } {{*** in database t2 *** 3541dcdbc06SdrhPage 4 is never used 3551dcdbc06SdrhPage 5 is never used 3561dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}} 3571dcdbc06Sdrh do_test pragma-3.13 { 3581dcdbc06Sdrh execsql { 3591dcdbc06Sdrh PRAGMA integrity_check=3 3601dcdbc06Sdrh } 3611dcdbc06Sdrh } {{*** in database t2 *** 3621dcdbc06SdrhPage 4 is never used 3631dcdbc06SdrhPage 5 is never used 3641dcdbc06SdrhPage 6 is never used}} 3651dcdbc06Sdrh do_test pragma-3.14 { 3661dcdbc06Sdrh execsql { 3671dcdbc06Sdrh PRAGMA integrity_check(2) 3681dcdbc06Sdrh } 3691dcdbc06Sdrh } {{*** in database t2 *** 3701dcdbc06SdrhPage 4 is never used 3711dcdbc06SdrhPage 5 is never used}} 3721dcdbc06Sdrh do_test pragma-3.15 { 3731dcdbc06Sdrh execsql { 3741dcdbc06Sdrh ATTACH 'testerr.db' AS t3; 3751dcdbc06Sdrh PRAGMA integrity_check 3761dcdbc06Sdrh } 3771dcdbc06Sdrh } {{*** in database t2 *** 3781dcdbc06SdrhPage 4 is never used 3791dcdbc06SdrhPage 5 is never used 380bb8a279eSdrhPage 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 *** 3811dcdbc06SdrhPage 4 is never used 3821dcdbc06SdrhPage 5 is never used 383bb8a279eSdrhPage 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}} 3841dcdbc06Sdrh do_test pragma-3.16 { 3851dcdbc06Sdrh execsql { 386bb8a279eSdrh PRAGMA integrity_check(10) 3871dcdbc06Sdrh } 3881dcdbc06Sdrh } {{*** in database t2 *** 3891dcdbc06SdrhPage 4 is never used 3901dcdbc06SdrhPage 5 is never used 391bb8a279eSdrhPage 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 *** 3921dcdbc06SdrhPage 4 is never used 3931dcdbc06SdrhPage 5 is never used 3941dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}} 3951dcdbc06Sdrh do_test pragma-3.17 { 3961dcdbc06Sdrh execsql { 397bb8a279eSdrh PRAGMA integrity_check=8 3981dcdbc06Sdrh } 3991dcdbc06Sdrh } {{*** in database t2 *** 4001dcdbc06SdrhPage 4 is never used 4011dcdbc06SdrhPage 5 is never used 402bb8a279eSdrhPage 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 *** 4031dcdbc06SdrhPage 4 is never used 4041dcdbc06SdrhPage 5 is never used}} 4051dcdbc06Sdrh do_test pragma-3.18 { 4061dcdbc06Sdrh execsql { 4071dcdbc06Sdrh PRAGMA integrity_check=4 4081dcdbc06Sdrh } 4091dcdbc06Sdrh } {{*** in database t2 *** 4101dcdbc06SdrhPage 4 is never used 4111dcdbc06SdrhPage 5 is never used 4121dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}} 4131dcdbc06Sdrh } 4141dcdbc06Sdrh do_test pragma-3.99 { 4151dcdbc06Sdrh catchsql {DETACH t3} 4161dcdbc06Sdrh catchsql {DETACH t2} 41790ddb123Sdrh file delete -force testerr.db testerr.db-journal 41805a6f4acSdrh catchsql {DROP INDEX i2} 4191dcdbc06Sdrh } {0 {}} 4205a8f9374Sdanielk1977} 42191cf71b0Sdanielk1977 42291cf71b0Sdanielk1977# Test modifying the cache_size of an attached database. 4235a8f9374Sdanielk1977ifcapable pager_pragmas&&attach { 42491cf71b0Sdanielk1977do_test pragma-4.1 { 42591cf71b0Sdanielk1977 execsql { 4261e9daa6aSdrh ATTACH 'test2.db' AS aux; 42791cf71b0Sdanielk1977 pragma aux.cache_size; 42891cf71b0Sdanielk1977 pragma aux.default_cache_size; 42991cf71b0Sdanielk1977 } 4301e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] 4311bdd9b57Sdrhdo_test pragma-4.2 { 4321bdd9b57Sdrh execsql { 43391cf71b0Sdanielk1977 pragma aux.cache_size = 50; 43491cf71b0Sdanielk1977 pragma aux.cache_size; 43591cf71b0Sdanielk1977 pragma aux.default_cache_size; 4361bdd9b57Sdrh } 4371e9daa6aSdrh} [list 50 $DFLT_CACHE_SZ] 4381bdd9b57Sdrhdo_test pragma-4.3 { 4391bdd9b57Sdrh execsql { 44091cf71b0Sdanielk1977 pragma aux.default_cache_size = 456; 44191cf71b0Sdanielk1977 pragma aux.cache_size; 44291cf71b0Sdanielk1977 pragma aux.default_cache_size; 4431bdd9b57Sdrh } 44491cf71b0Sdanielk1977} {456 456} 4451bdd9b57Sdrhdo_test pragma-4.4 { 4461bdd9b57Sdrh execsql { 44791cf71b0Sdanielk1977 pragma cache_size; 44891cf71b0Sdanielk1977 pragma default_cache_size; 4491bdd9b57Sdrh } 4501e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] 4511bdd9b57Sdrhdo_test pragma-4.5 { 4521bdd9b57Sdrh execsql { 45391cf71b0Sdanielk1977 DETACH aux; 45491cf71b0Sdanielk1977 ATTACH 'test3.db' AS aux; 45591cf71b0Sdanielk1977 pragma aux.cache_size; 45691cf71b0Sdanielk1977 pragma aux.default_cache_size; 4571bdd9b57Sdrh } 4581e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] 4591bdd9b57Sdrhdo_test pragma-4.6 { 4601bdd9b57Sdrh execsql { 46191cf71b0Sdanielk1977 DETACH aux; 46291cf71b0Sdanielk1977 ATTACH 'test2.db' AS aux; 46391cf71b0Sdanielk1977 pragma aux.cache_size; 46491cf71b0Sdanielk1977 pragma aux.default_cache_size; 4651bdd9b57Sdrh } 46691cf71b0Sdanielk1977} {456 456} 467c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 4681bdd9b57Sdrh 46991cf71b0Sdanielk1977# Test that modifying the sync-level in the middle of a transaction is 47091cf71b0Sdanielk1977# disallowed. 471c7b4a44cSdanielk1977ifcapable pager_pragmas { 47291cf71b0Sdanielk1977do_test pragma-5.0 { 4731bdd9b57Sdrh execsql { 47491cf71b0Sdanielk1977 pragma synchronous; 4751bdd9b57Sdrh } 47691cf71b0Sdanielk1977} {2} 47791cf71b0Sdanielk1977do_test pragma-5.1 { 4781bdd9b57Sdrh catchsql { 4791bdd9b57Sdrh BEGIN; 48091cf71b0Sdanielk1977 pragma synchronous = OFF; 4811bdd9b57Sdrh } 48291cf71b0Sdanielk1977} {1 {Safety level may not be changed inside a transaction}} 48391cf71b0Sdanielk1977do_test pragma-5.2 { 48491cf71b0Sdanielk1977 execsql { 48591cf71b0Sdanielk1977 pragma synchronous; 48691cf71b0Sdanielk1977 } 48791cf71b0Sdanielk1977} {2} 4885260f7e9Sdrhcatchsql {COMMIT;} 489c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 4905260f7e9Sdrh 4915260f7e9Sdrh# Test schema-query pragmas 4925260f7e9Sdrh# 49327188fb5Sdanielk1977ifcapable schema_pragmas { 4945a8f9374Sdanielk1977ifcapable tempdb&&attach { 4955260f7e9Sdrh do_test pragma-6.1 { 496956bc92cSdrh set res {} 49740e016e4Sdrh execsql {SELECT * FROM sqlite_temp_master} 4985260f7e9Sdrh foreach {idx name file} [execsql {pragma database_list}] { 4995260f7e9Sdrh lappend res $idx $name 5005260f7e9Sdrh } 5015260f7e9Sdrh set res 502a71aa001Sdrh } {0 main 1 temp 2 aux} 50353c0f748Sdanielk1977} 5045260f7e9Sdrhdo_test pragma-6.2 { 5055260f7e9Sdrh execsql { 5065260f7e9Sdrh pragma table_info(t2) 5075260f7e9Sdrh } 508bfa8b102Sdrh} {0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0} 509736c7d4bSdrhdb nullvalue <<NULL>> 510417ec638Sdrhdo_test pragma-6.2.2 { 511417ec638Sdrh execsql { 512736c7d4bSdrh CREATE TABLE t5( 513736c7d4bSdrh a TEXT DEFAULT CURRENT_TIMESTAMP, 514736c7d4bSdrh b DEFAULT (5+3), 515736c7d4bSdrh c TEXT, 516736c7d4bSdrh d INTEGER DEFAULT NULL, 517736c7d4bSdrh e TEXT DEFAULT '' 518736c7d4bSdrh ); 519417ec638Sdrh PRAGMA table_info(t5); 520417ec638Sdrh } 521736c7d4bSdrh} {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 0 2 c TEXT 0 <<NULL>> 0 3 d INTEGER 0 NULL 0 4 e TEXT 0 '' 0} 522736c7d4bSdrhdb nullvalue {} 5236bf89570Sdrhifcapable {foreignkey} { 5245260f7e9Sdrh do_test pragma-6.3 { 5255260f7e9Sdrh execsql { 5265260f7e9Sdrh CREATE TABLE t3(a int references t2(b), b UNIQUE); 5275260f7e9Sdrh pragma foreign_key_list(t3); 5285260f7e9Sdrh } 52950af3e1dSdanielk1977 } {0 0 t2 a b RESTRICT RESTRICT NONE} 5305260f7e9Sdrh do_test pragma-6.4 { 5315260f7e9Sdrh execsql { 5325260f7e9Sdrh pragma index_list(t3); 5335260f7e9Sdrh } 5345260f7e9Sdrh } {0 sqlite_autoindex_t3_1 1} 5356bf89570Sdrh} 5366bf89570Sdrhifcapable {!foreignkey} { 5376bf89570Sdrh execsql {CREATE TABLE t3(a,b UNIQUE)} 5386bf89570Sdrh} 5395260f7e9Sdrhdo_test pragma-6.5 { 5405260f7e9Sdrh execsql { 5415260f7e9Sdrh CREATE INDEX t3i1 ON t3(a,b); 5425260f7e9Sdrh pragma index_info(t3i1); 5435260f7e9Sdrh } 5445260f7e9Sdrh} {0 0 a 1 1 b} 545260d8a6aSdanielk1977 546260d8a6aSdanielk1977ifcapable tempdb { 547260d8a6aSdanielk1977 # Test for ticket #3320. When a temp table of the same name exists, make 548260d8a6aSdanielk1977 # sure the schema of the main table can still be queried using 549260d8a6aSdanielk1977 # "pragma table_info": 550260d8a6aSdanielk1977 do_test pragma-6.6.1 { 551260d8a6aSdanielk1977 execsql { 552260d8a6aSdanielk1977 CREATE TABLE trial(col_main); 553260d8a6aSdanielk1977 CREATE TEMP TABLE trial(col_temp); 554260d8a6aSdanielk1977 } 555260d8a6aSdanielk1977 } {} 556260d8a6aSdanielk1977 do_test pragma-6.6.2 { 557260d8a6aSdanielk1977 execsql { 558260d8a6aSdanielk1977 PRAGMA table_info(trial); 559260d8a6aSdanielk1977 } 560260d8a6aSdanielk1977 } {0 col_temp {} 0 {} 0} 561260d8a6aSdanielk1977 do_test pragma-6.6.3 { 562260d8a6aSdanielk1977 execsql { 563260d8a6aSdanielk1977 PRAGMA temp.table_info(trial); 564260d8a6aSdanielk1977 } 565260d8a6aSdanielk1977 } {0 col_temp {} 0 {} 0} 566260d8a6aSdanielk1977 do_test pragma-6.6.4 { 567260d8a6aSdanielk1977 execsql { 568260d8a6aSdanielk1977 PRAGMA main.table_info(trial); 569260d8a6aSdanielk1977 } 570260d8a6aSdanielk1977 } {0 col_main {} 0 {} 0} 571260d8a6aSdanielk1977} 572f96a3778Sdanielk1977 573f96a3778Sdanielk1977breakpoint 574f96a3778Sdanielk1977do_test pragma-6.7 { 575f96a3778Sdanielk1977 execsql { 576f96a3778Sdanielk1977 CREATE TABLE test_table( 577f96a3778Sdanielk1977 one INT NOT NULL DEFAULT -1, 578f96a3778Sdanielk1977 two text, 579f96a3778Sdanielk1977 three VARCHAR(45, 65) DEFAULT 'abcde', 580f96a3778Sdanielk1977 four REAL DEFAULT X'abcdef', 581f96a3778Sdanielk1977 five DEFAULT CURRENT_TIME 582f96a3778Sdanielk1977 ); 583f96a3778Sdanielk1977 PRAGMA table_info(test_table); 584f96a3778Sdanielk1977 } 585f96a3778Sdanielk1977} [concat \ 586f96a3778Sdanielk1977 {0 one INT 1 -1 0} \ 587f96a3778Sdanielk1977 {1 two text 0 {} 0} \ 588f96a3778Sdanielk1977 {2 three {VARCHAR(45, 65)} 0 'abcde' 0} \ 589f96a3778Sdanielk1977 {3 four REAL 0 X'abcdef' 0} \ 590f96a3778Sdanielk1977 {4 five {} 0 CURRENT_TIME 0} \ 591f96a3778Sdanielk1977] 59227188fb5Sdanielk1977} ;# ifcapable schema_pragmas 5935260f7e9Sdrh# Miscellaneous tests 5945260f7e9Sdrh# 59527188fb5Sdanielk1977ifcapable schema_pragmas { 5965260f7e9Sdrhdo_test pragma-7.1 { 5975260f7e9Sdrh # Make sure a pragma knows to read the schema if it needs to 5985260f7e9Sdrh db close 5995260f7e9Sdrh sqlite3 db test.db 6005260f7e9Sdrh execsql { 6015260f7e9Sdrh pragma index_list(t3); 6025260f7e9Sdrh } 6035260f7e9Sdrh} {0 t3i1 0 1 sqlite_autoindex_t3_1 1} 60427188fb5Sdanielk1977} ;# ifcapable schema_pragmas 6056c62608fSdrhifcapable {utf16} { 6065260f7e9Sdrh do_test pragma-7.2 { 6075260f7e9Sdrh db close 6085260f7e9Sdrh sqlite3 db test.db 6095260f7e9Sdrh catchsql { 6105260f7e9Sdrh pragma encoding=bogus; 6115260f7e9Sdrh } 6125260f7e9Sdrh } {1 {unsupported encoding: bogus}} 6136c62608fSdrh} 61453c0f748Sdanielk1977ifcapable tempdb { 6155260f7e9Sdrh do_test pragma-7.3 { 6165260f7e9Sdrh db close 6175260f7e9Sdrh sqlite3 db test.db 6185260f7e9Sdrh execsql { 6195260f7e9Sdrh pragma lock_status; 6205260f7e9Sdrh } 6215260f7e9Sdrh } {main unlocked temp closed} 62253c0f748Sdanielk1977} else { 62353c0f748Sdanielk1977 do_test pragma-7.3 { 62453c0f748Sdanielk1977 db close 62553c0f748Sdanielk1977 sqlite3 db test.db 62653c0f748Sdanielk1977 execsql { 62753c0f748Sdanielk1977 pragma lock_status; 62853c0f748Sdanielk1977 } 62953c0f748Sdanielk1977 } {main unlocked} 63053c0f748Sdanielk1977} 6315260f7e9Sdrh 6325260f7e9Sdrh 633dae2495bSdanielk1977#---------------------------------------------------------------------- 634b92b70bbSdanielk1977# Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA 635b92b70bbSdanielk1977# user_version" statements. 636dae2495bSdanielk1977# 637b92b70bbSdanielk1977# pragma-8.1: PRAGMA schema_version 638b92b70bbSdanielk1977# pragma-8.2: PRAGMA user_version 639dae2495bSdanielk1977# 640dae2495bSdanielk1977 64111cf9fbcSdanielk1977ifcapable schema_version { 64211cf9fbcSdanielk1977 643b92b70bbSdanielk1977# First check that we can set the schema version and then retrieve the 644dae2495bSdanielk1977# same value. 645dae2495bSdanielk1977do_test pragma-8.1.1 { 646dae2495bSdanielk1977 execsql { 647b92b70bbSdanielk1977 PRAGMA schema_version = 105; 648dae2495bSdanielk1977 } 649dae2495bSdanielk1977} {} 650dae2495bSdanielk1977do_test pragma-8.1.2 { 65125403650Sdrh execsql2 { 652b92b70bbSdanielk1977 PRAGMA schema_version; 653dae2495bSdanielk1977 } 65425403650Sdrh} {schema_version 105} 655dae2495bSdanielk1977do_test pragma-8.1.3 { 656dae2495bSdanielk1977 execsql { 657b92b70bbSdanielk1977 PRAGMA schema_version = 106; 658dae2495bSdanielk1977 } 659dae2495bSdanielk1977} {} 660dae2495bSdanielk1977do_test pragma-8.1.4 { 661dae2495bSdanielk1977 execsql { 662b92b70bbSdanielk1977 PRAGMA schema_version; 663dae2495bSdanielk1977 } 664dae2495bSdanielk1977} 106 665dae2495bSdanielk1977 666b92b70bbSdanielk1977# Check that creating a table modifies the schema-version (this is really 667b92b70bbSdanielk1977# to verify that the value being read is in fact the schema version). 668dae2495bSdanielk1977do_test pragma-8.1.5 { 669dae2495bSdanielk1977 execsql { 670dae2495bSdanielk1977 CREATE TABLE t4(a, b, c); 671dae2495bSdanielk1977 INSERT INTO t4 VALUES(1, 2, 3); 672dae2495bSdanielk1977 SELECT * FROM t4; 673dae2495bSdanielk1977 } 674dae2495bSdanielk1977} {1 2 3} 675dae2495bSdanielk1977do_test pragma-8.1.6 { 676dae2495bSdanielk1977 execsql { 677b92b70bbSdanielk1977 PRAGMA schema_version; 678dae2495bSdanielk1977 } 679dae2495bSdanielk1977} 107 680dae2495bSdanielk1977 681dae2495bSdanielk1977# Now open a second connection to the database. Ensure that changing the 682b92b70bbSdanielk1977# schema-version using the first connection forces the second connection 683dae2495bSdanielk1977# to reload the schema. This has to be done using the C-API test functions, 684dae2495bSdanielk1977# because the TCL API accounts for SCHEMA_ERROR and retries the query. 685dae2495bSdanielk1977do_test pragma-8.1.7 { 686dddca286Sdrh sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] 687dae2495bSdanielk1977 execsql { 688dae2495bSdanielk1977 SELECT * FROM t4; 689dae2495bSdanielk1977 } db2 690dae2495bSdanielk1977} {1 2 3} 691dae2495bSdanielk1977do_test pragma-8.1.8 { 692dae2495bSdanielk1977 execsql { 693b92b70bbSdanielk1977 PRAGMA schema_version = 108; 694dae2495bSdanielk1977 } 695dae2495bSdanielk1977} {} 696dae2495bSdanielk1977do_test pragma-8.1.9 { 697dae2495bSdanielk1977 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY] 698dae2495bSdanielk1977 sqlite3_step $::STMT 699dae2495bSdanielk1977} SQLITE_ERROR 700dae2495bSdanielk1977do_test pragma-8.1.10 { 701dae2495bSdanielk1977 sqlite3_finalize $::STMT 702dae2495bSdanielk1977} SQLITE_SCHEMA 703dae2495bSdanielk1977 704b92b70bbSdanielk1977# Make sure the schema-version can be manipulated in an attached database. 705dae2495bSdanielk1977file delete -force test2.db 706dae2495bSdanielk1977file delete -force test2.db-journal 7075a8f9374Sdanielk1977ifcapable attach { 708dae2495bSdanielk1977 do_test pragma-8.1.11 { 709dae2495bSdanielk1977 execsql { 710dae2495bSdanielk1977 ATTACH 'test2.db' AS aux; 711dae2495bSdanielk1977 CREATE TABLE aux.t1(a, b, c); 712b92b70bbSdanielk1977 PRAGMA aux.schema_version = 205; 713dae2495bSdanielk1977 } 714dae2495bSdanielk1977 } {} 715dae2495bSdanielk1977 do_test pragma-8.1.12 { 716dae2495bSdanielk1977 execsql { 717b92b70bbSdanielk1977 PRAGMA aux.schema_version; 718dae2495bSdanielk1977 } 719dae2495bSdanielk1977 } 205 7205a8f9374Sdanielk1977} 721dae2495bSdanielk1977do_test pragma-8.1.13 { 722dae2495bSdanielk1977 execsql { 723b92b70bbSdanielk1977 PRAGMA schema_version; 724dae2495bSdanielk1977 } 725dae2495bSdanielk1977} 108 726dae2495bSdanielk1977 727b92b70bbSdanielk1977# And check that modifying the schema-version in an attached database 728dae2495bSdanielk1977# forces the second connection to reload the schema. 7295a8f9374Sdanielk1977ifcapable attach { 730dae2495bSdanielk1977 do_test pragma-8.1.14 { 731dddca286Sdrh sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] 732dae2495bSdanielk1977 execsql { 733dae2495bSdanielk1977 ATTACH 'test2.db' AS aux; 734dae2495bSdanielk1977 SELECT * FROM aux.t1; 735dae2495bSdanielk1977 } db2 736dae2495bSdanielk1977 } {} 737dae2495bSdanielk1977 do_test pragma-8.1.15 { 738dae2495bSdanielk1977 execsql { 739b92b70bbSdanielk1977 PRAGMA aux.schema_version = 206; 740dae2495bSdanielk1977 } 741dae2495bSdanielk1977 } {} 742dae2495bSdanielk1977 do_test pragma-8.1.16 { 743dae2495bSdanielk1977 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY] 744dae2495bSdanielk1977 sqlite3_step $::STMT 745dae2495bSdanielk1977 } SQLITE_ERROR 746dae2495bSdanielk1977 do_test pragma-8.1.17 { 747dae2495bSdanielk1977 sqlite3_finalize $::STMT 748dae2495bSdanielk1977 } SQLITE_SCHEMA 749dae2495bSdanielk1977 do_test pragma-8.1.18 { 750dae2495bSdanielk1977 db2 close 751dae2495bSdanielk1977 } {} 7525a8f9374Sdanielk1977} 753dae2495bSdanielk1977 754b92b70bbSdanielk1977# Now test that the user-version can be read and written (and that we aren't 755b92b70bbSdanielk1977# accidentally manipulating the schema-version instead). 756dae2495bSdanielk1977do_test pragma-8.2.1 { 75725403650Sdrh execsql2 { 758b92b70bbSdanielk1977 PRAGMA user_version; 759dae2495bSdanielk1977 } 76025403650Sdrh} {user_version 0} 761dae2495bSdanielk1977do_test pragma-8.2.2 { 762dae2495bSdanielk1977 execsql { 763b92b70bbSdanielk1977 PRAGMA user_version = 2; 764dae2495bSdanielk1977 } 765dae2495bSdanielk1977} {} 766802d69a7Sdrhdo_test pragma-8.2.3.1 { 76725403650Sdrh execsql2 { 768b92b70bbSdanielk1977 PRAGMA user_version; 769dae2495bSdanielk1977 } 77025403650Sdrh} {user_version 2} 771802d69a7Sdrhdo_test pragma-8.2.3.2 { 772802d69a7Sdrh db close 773802d69a7Sdrh sqlite3 db test.db 774802d69a7Sdrh execsql { 775802d69a7Sdrh PRAGMA user_version; 776802d69a7Sdrh } 777802d69a7Sdrh} {2} 778802d69a7Sdrhdo_test pragma-8.2.4.1 { 779dae2495bSdanielk1977 execsql { 780b92b70bbSdanielk1977 PRAGMA schema_version; 781dae2495bSdanielk1977 } 782dae2495bSdanielk1977} {108} 783802d69a7Sdrhifcapable vacuum { 784802d69a7Sdrh do_test pragma-8.2.4.2 { 785802d69a7Sdrh execsql { 786802d69a7Sdrh VACUUM; 787802d69a7Sdrh PRAGMA user_version; 788802d69a7Sdrh } 789802d69a7Sdrh } {2} 790802d69a7Sdrh do_test pragma-8.2.4.3 { 791802d69a7Sdrh execsql { 792802d69a7Sdrh PRAGMA schema_version; 793802d69a7Sdrh } 794802d69a7Sdrh } {109} 795802d69a7Sdrh} 7965a8f9374Sdanielk1977 7975a8f9374Sdanielk1977ifcapable attach { 798802d69a7Sdrh db eval {ATTACH 'test2.db' AS aux} 799dae2495bSdanielk1977 800b92b70bbSdanielk1977 # Check that the user-version in the auxilary database can be manipulated ( 801dae2495bSdanielk1977 # and that we aren't accidentally manipulating the same in the main db). 802dae2495bSdanielk1977 do_test pragma-8.2.5 { 803dae2495bSdanielk1977 execsql { 804b92b70bbSdanielk1977 PRAGMA aux.user_version; 805dae2495bSdanielk1977 } 806dae2495bSdanielk1977 } {0} 807dae2495bSdanielk1977 do_test pragma-8.2.6 { 808dae2495bSdanielk1977 execsql { 809b92b70bbSdanielk1977 PRAGMA aux.user_version = 3; 810dae2495bSdanielk1977 } 811dae2495bSdanielk1977 } {} 812dae2495bSdanielk1977 do_test pragma-8.2.7 { 813dae2495bSdanielk1977 execsql { 814b92b70bbSdanielk1977 PRAGMA aux.user_version; 815dae2495bSdanielk1977 } 816dae2495bSdanielk1977 } {3} 817dae2495bSdanielk1977 do_test pragma-8.2.8 { 818dae2495bSdanielk1977 execsql { 819b92b70bbSdanielk1977 PRAGMA main.user_version; 820dae2495bSdanielk1977 } 821dae2495bSdanielk1977 } {2} 822dae2495bSdanielk1977 823b92b70bbSdanielk1977 # Now check that a ROLLBACK resets the user-version if it has been modified 824dae2495bSdanielk1977 # within a transaction. 825dae2495bSdanielk1977 do_test pragma-8.2.9 { 826dae2495bSdanielk1977 execsql { 827dae2495bSdanielk1977 BEGIN; 828b92b70bbSdanielk1977 PRAGMA aux.user_version = 10; 829b92b70bbSdanielk1977 PRAGMA user_version = 11; 830dae2495bSdanielk1977 } 831dae2495bSdanielk1977 } {} 832dae2495bSdanielk1977 do_test pragma-8.2.10 { 833dae2495bSdanielk1977 execsql { 834b92b70bbSdanielk1977 PRAGMA aux.user_version; 835dae2495bSdanielk1977 } 836dae2495bSdanielk1977 } {10} 837dae2495bSdanielk1977 do_test pragma-8.2.11 { 838dae2495bSdanielk1977 execsql { 839b92b70bbSdanielk1977 PRAGMA main.user_version; 840dae2495bSdanielk1977 } 841dae2495bSdanielk1977 } {11} 842dae2495bSdanielk1977 do_test pragma-8.2.12 { 843dae2495bSdanielk1977 execsql { 844dae2495bSdanielk1977 ROLLBACK; 845b92b70bbSdanielk1977 PRAGMA aux.user_version; 846dae2495bSdanielk1977 } 847dae2495bSdanielk1977 } {3} 848dae2495bSdanielk1977 do_test pragma-8.2.13 { 849dae2495bSdanielk1977 execsql { 850b92b70bbSdanielk1977 PRAGMA main.user_version; 851dae2495bSdanielk1977 } 852dae2495bSdanielk1977 } {2} 8535a8f9374Sdanielk1977} 854dae2495bSdanielk1977 855b92b70bbSdanielk1977# Try a negative value for the user-version 856dae2495bSdanielk1977do_test pragma-8.2.14 { 857dae2495bSdanielk1977 execsql { 858b92b70bbSdanielk1977 PRAGMA user_version = -450; 859dae2495bSdanielk1977 } 860dae2495bSdanielk1977} {} 861dae2495bSdanielk1977do_test pragma-8.2.15 { 862dae2495bSdanielk1977 execsql { 863b92b70bbSdanielk1977 PRAGMA user_version; 864dae2495bSdanielk1977 } 865dae2495bSdanielk1977} {-450} 866d9c847dcSdanielk1977} ; # ifcapable schema_version 867d9c847dcSdanielk1977 868d19744f3Sdrh# Check to see if TEMP_STORE is memory or disk. Return strings 869d19744f3Sdrh# "memory" or "disk" as appropriate. 870d19744f3Sdrh# 871d19744f3Sdrhproc check_temp_store {} { 872d19744f3Sdrh db eval {CREATE TEMP TABLE IF NOT EXISTS a(b)} 873d19744f3Sdrh db eval {PRAGMA database_list} { 874d19744f3Sdrh if {$name=="temp"} { 87517b90b53Sdanielk1977 set bt [btree_from_db db 1] 87617b90b53Sdanielk1977 if {[btree_ismemdb $bt]} { 877d19744f3Sdrh return "memory" 878d19744f3Sdrh } 87917b90b53Sdanielk1977 return "disk" 880d19744f3Sdrh } 881d19744f3Sdrh } 882d19744f3Sdrh return "unknown" 883d19744f3Sdrh} 884d19744f3Sdrh 8859a09a3caStpoindex 8869a09a3caStpoindex# Test temp_store and temp_store_directory pragmas 8879a09a3caStpoindex# 888268283bcSdrhifcapable pager_pragmas { 8899a09a3caStpoindexdo_test pragma-9.1 { 8909a09a3caStpoindex db close 8919a09a3caStpoindex sqlite3 db test.db 8929a09a3caStpoindex execsql { 8939a09a3caStpoindex PRAGMA temp_store; 8949a09a3caStpoindex } 8959a09a3caStpoindex} {0} 896d19744f3Sdrhif {$TEMP_STORE<=1} { 897d19744f3Sdrh do_test pragma-9.1.1 { 898d19744f3Sdrh check_temp_store 899d19744f3Sdrh } {disk} 900d19744f3Sdrh} else { 901d19744f3Sdrh do_test pragma-9.1.1 { 902d19744f3Sdrh check_temp_store 903d19744f3Sdrh } {memory} 904d19744f3Sdrh} 905d19744f3Sdrh 9069a09a3caStpoindexdo_test pragma-9.2 { 907d19744f3Sdrh db close 908d19744f3Sdrh sqlite3 db test.db 9099a09a3caStpoindex execsql { 9109a09a3caStpoindex PRAGMA temp_store=file; 9119a09a3caStpoindex PRAGMA temp_store; 9129a09a3caStpoindex } 9139a09a3caStpoindex} {1} 914d19744f3Sdrhif {$TEMP_STORE==3} { 915d19744f3Sdrh # When TEMP_STORE is 3, always use memory regardless of pragma settings. 916d19744f3Sdrh do_test pragma-9.2.1 { 917d19744f3Sdrh check_temp_store 918d19744f3Sdrh } {memory} 919d19744f3Sdrh} else { 920d19744f3Sdrh do_test pragma-9.2.1 { 921d19744f3Sdrh check_temp_store 922d19744f3Sdrh } {disk} 923d19744f3Sdrh} 924d19744f3Sdrh 9259a09a3caStpoindexdo_test pragma-9.3 { 926d19744f3Sdrh db close 927d19744f3Sdrh sqlite3 db test.db 9289a09a3caStpoindex execsql { 9299a09a3caStpoindex PRAGMA temp_store=memory; 9309a09a3caStpoindex PRAGMA temp_store; 9319a09a3caStpoindex } 9329a09a3caStpoindex} {2} 933d19744f3Sdrhif {$TEMP_STORE==0} { 934d19744f3Sdrh # When TEMP_STORE is 0, always use the disk regardless of pragma settings. 935d19744f3Sdrh do_test pragma-9.3.1 { 936d19744f3Sdrh check_temp_store 937d19744f3Sdrh } {disk} 938d19744f3Sdrh} else { 939d19744f3Sdrh do_test pragma-9.3.1 { 940d19744f3Sdrh check_temp_store 941d19744f3Sdrh } {memory} 942d19744f3Sdrh} 943d19744f3Sdrh 9449a09a3caStpoindexdo_test pragma-9.4 { 9459a09a3caStpoindex execsql { 9469a09a3caStpoindex PRAGMA temp_store_directory; 9479a09a3caStpoindex } 9489a09a3caStpoindex} {} 94978f82d1eSdrhifcapable wsd { 9509a09a3caStpoindex do_test pragma-9.5 { 951181ddaa1Sdanielk1977 set pwd [string map {' ''} [file nativename [pwd]]] 952268283bcSdrh execsql " 953268283bcSdrh PRAGMA temp_store_directory='$pwd'; 9549a09a3caStpoindex " 9559a09a3caStpoindex } {} 9569a09a3caStpoindex do_test pragma-9.6 { 9579a09a3caStpoindex execsql { 9589a09a3caStpoindex PRAGMA temp_store_directory; 9599a09a3caStpoindex } 960181ddaa1Sdanielk1977 } [list [file nativename [pwd]]] 9619a09a3caStpoindex do_test pragma-9.7 { 962268283bcSdrh catchsql { 9639a09a3caStpoindex PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR'; 9649a09a3caStpoindex } 965268283bcSdrh } {1 {not a writable directory}} 9669a09a3caStpoindex do_test pragma-9.8 { 9679a09a3caStpoindex execsql { 9689a09a3caStpoindex PRAGMA temp_store_directory=''; 9699a09a3caStpoindex } 9709a09a3caStpoindex } {} 9711e9daa6aSdrh if {![info exists TEMP_STORE] || $TEMP_STORE<=1} { 97253c0f748Sdanielk1977 ifcapable tempdb { 9739a09a3caStpoindex do_test pragma-9.9 { 9749a09a3caStpoindex execsql { 9759a09a3caStpoindex PRAGMA temp_store_directory; 9769a09a3caStpoindex PRAGMA temp_store=FILE; 9779a09a3caStpoindex CREATE TEMP TABLE temp_store_directory_test(a integer); 9789a09a3caStpoindex INSERT INTO temp_store_directory_test values (2); 9799a09a3caStpoindex SELECT * FROM temp_store_directory_test; 9809a09a3caStpoindex } 9819a09a3caStpoindex } {2} 9829a09a3caStpoindex do_test pragma-9.10 { 983268283bcSdrh catchsql " 984268283bcSdrh PRAGMA temp_store_directory='$pwd'; 9859a09a3caStpoindex SELECT * FROM temp_store_directory_test; 9869a09a3caStpoindex " 987268283bcSdrh } {1 {no such table: temp_store_directory_test}} 9881e9daa6aSdrh } 9891e9daa6aSdrh } 99078f82d1eSdrh} 99195b289b6Sdanielk1977do_test pragma-9.11 { 99295b289b6Sdanielk1977 execsql { 99395b289b6Sdanielk1977 PRAGMA temp_store = 0; 99495b289b6Sdanielk1977 PRAGMA temp_store; 99595b289b6Sdanielk1977 } 99695b289b6Sdanielk1977} {0} 99795b289b6Sdanielk1977do_test pragma-9.12 { 99895b289b6Sdanielk1977 execsql { 99995b289b6Sdanielk1977 PRAGMA temp_store = 1; 100095b289b6Sdanielk1977 PRAGMA temp_store; 100195b289b6Sdanielk1977 } 100295b289b6Sdanielk1977} {1} 100395b289b6Sdanielk1977do_test pragma-9.13 { 100495b289b6Sdanielk1977 execsql { 100595b289b6Sdanielk1977 PRAGMA temp_store = 2; 100695b289b6Sdanielk1977 PRAGMA temp_store; 100795b289b6Sdanielk1977 } 100895b289b6Sdanielk1977} {2} 100995b289b6Sdanielk1977do_test pragma-9.14 { 101095b289b6Sdanielk1977 execsql { 101195b289b6Sdanielk1977 PRAGMA temp_store = 3; 101295b289b6Sdanielk1977 PRAGMA temp_store; 101395b289b6Sdanielk1977 } 101495b289b6Sdanielk1977} {0} 101595b289b6Sdanielk1977do_test pragma-9.15 { 101695b289b6Sdanielk1977 catchsql { 101795b289b6Sdanielk1977 BEGIN EXCLUSIVE; 101895b289b6Sdanielk1977 CREATE TEMP TABLE temp_table(t); 101995b289b6Sdanielk1977 INSERT INTO temp_table VALUES('valuable data'); 102095b289b6Sdanielk1977 PRAGMA temp_store = 1; 102195b289b6Sdanielk1977 } 102295b289b6Sdanielk1977} {1 {temporary storage cannot be changed from within a transaction}} 102395b289b6Sdanielk1977do_test pragma-9.16 { 102495b289b6Sdanielk1977 execsql { 102595b289b6Sdanielk1977 SELECT * FROM temp_table; 102695b289b6Sdanielk1977 COMMIT; 102795b289b6Sdanielk1977 } 102895b289b6Sdanielk1977} {{valuable data}} 1029983e2309Sdanielk1977 1030983e2309Sdanielk1977do_test pragma-9.17 { 1031983e2309Sdanielk1977 execsql { 1032983e2309Sdanielk1977 INSERT INTO temp_table VALUES('valuable data II'); 1033983e2309Sdanielk1977 SELECT * FROM temp_table; 1034983e2309Sdanielk1977 } 1035983e2309Sdanielk1977} {{valuable data} {valuable data II}} 1036983e2309Sdanielk1977 1037983e2309Sdanielk1977do_test pragma-9.18 { 1038983e2309Sdanielk1977 set rc [catch { 1039983e2309Sdanielk1977 db eval {SELECT t FROM temp_table} { 1040983e2309Sdanielk1977 execsql {pragma temp_store = 1} 1041983e2309Sdanielk1977 } 1042983e2309Sdanielk1977 } msg] 1043983e2309Sdanielk1977 list $rc $msg 1044983e2309Sdanielk1977} {1 {temporary storage cannot be changed from within a transaction}} 1045983e2309Sdanielk1977 1046268283bcSdrh} ;# ifcapable pager_pragmas 10479a09a3caStpoindex 1048cc6bd383Sdanielk1977ifcapable trigger { 1049cc6bd383Sdanielk1977 1050cc6bd383Sdanielk1977do_test pragma-10.0 { 1051cc6bd383Sdanielk1977 catchsql { 1052cc6bd383Sdanielk1977 DROP TABLE main.t1; 1053cc6bd383Sdanielk1977 } 1054cc6bd383Sdanielk1977 execsql { 1055cc6bd383Sdanielk1977 PRAGMA count_changes = 1; 1056cc6bd383Sdanielk1977 1057cc6bd383Sdanielk1977 CREATE TABLE t1(a PRIMARY KEY); 1058cc6bd383Sdanielk1977 CREATE TABLE t1_mirror(a); 1059cc6bd383Sdanielk1977 CREATE TABLE t1_mirror2(a); 1060cc6bd383Sdanielk1977 CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN 1061cc6bd383Sdanielk1977 INSERT INTO t1_mirror VALUES(new.a); 1062cc6bd383Sdanielk1977 END; 1063cc6bd383Sdanielk1977 CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN 1064cc6bd383Sdanielk1977 INSERT INTO t1_mirror2 VALUES(new.a); 1065cc6bd383Sdanielk1977 END; 1066cc6bd383Sdanielk1977 CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN 1067cc6bd383Sdanielk1977 UPDATE t1_mirror SET a = new.a WHERE a = old.a; 1068cc6bd383Sdanielk1977 END; 1069cc6bd383Sdanielk1977 CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN 1070cc6bd383Sdanielk1977 UPDATE t1_mirror2 SET a = new.a WHERE a = old.a; 1071cc6bd383Sdanielk1977 END; 1072cc6bd383Sdanielk1977 CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN 1073cc6bd383Sdanielk1977 DELETE FROM t1_mirror WHERE a = old.a; 1074cc6bd383Sdanielk1977 END; 1075cc6bd383Sdanielk1977 CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN 1076cc6bd383Sdanielk1977 DELETE FROM t1_mirror2 WHERE a = old.a; 1077cc6bd383Sdanielk1977 END; 1078cc6bd383Sdanielk1977 } 1079cc6bd383Sdanielk1977} {} 1080cc6bd383Sdanielk1977 1081cc6bd383Sdanielk1977do_test pragma-10.1 { 1082cc6bd383Sdanielk1977 execsql { 1083cc6bd383Sdanielk1977 INSERT INTO t1 VALUES(randstr(10,10)); 1084cc6bd383Sdanielk1977 } 1085cc6bd383Sdanielk1977} {1} 1086cc6bd383Sdanielk1977do_test pragma-10.2 { 1087cc6bd383Sdanielk1977 execsql { 1088cc6bd383Sdanielk1977 UPDATE t1 SET a = randstr(10,10); 1089cc6bd383Sdanielk1977 } 1090cc6bd383Sdanielk1977} {1} 1091cc6bd383Sdanielk1977do_test pragma-10.3 { 1092cc6bd383Sdanielk1977 execsql { 1093cc6bd383Sdanielk1977 DELETE FROM t1; 1094cc6bd383Sdanielk1977 } 1095cc6bd383Sdanielk1977} {1} 1096cc6bd383Sdanielk1977 1097cc6bd383Sdanielk1977} ;# ifcapable trigger 1098cc6bd383Sdanielk1977 109948af65aeSdanielk1977ifcapable schema_pragmas { 110048af65aeSdanielk1977 do_test pragma-11.1 { 110148af65aeSdanielk1977 execsql2 { 110248af65aeSdanielk1977 pragma collation_list; 110348af65aeSdanielk1977 } 11049b5adfa2Sdrh } {seq 0 name NOCASE seq 1 name RTRIM seq 2 name BINARY} 110548af65aeSdanielk1977 do_test pragma-11.2 { 110648af65aeSdanielk1977 db collate New_Collation blah... 110748af65aeSdanielk1977 execsql { 110848af65aeSdanielk1977 pragma collation_list; 110948af65aeSdanielk1977 } 11109b5adfa2Sdrh } {0 New_Collation 1 NOCASE 2 RTRIM 3 BINARY} 111148af65aeSdanielk1977} 111248af65aeSdanielk1977 1113ddfb2f03Sdanielk1977ifcapable schema_pragmas&&tempdb { 1114ddfb2f03Sdanielk1977 do_test pragma-12.1 { 1115ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1116ddfb2f03Sdanielk1977 execsql { 1117ddfb2f03Sdanielk1977 PRAGMA temp.table_info('abc'); 1118ddfb2f03Sdanielk1977 } db2 1119ddfb2f03Sdanielk1977 } {} 1120ddfb2f03Sdanielk1977 db2 close 1121ddfb2f03Sdanielk1977 1122ddfb2f03Sdanielk1977 do_test pragma-12.2 { 1123ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1124ddfb2f03Sdanielk1977 execsql { 1125ddfb2f03Sdanielk1977 PRAGMA temp.default_cache_size = 200; 1126ddfb2f03Sdanielk1977 PRAGMA temp.default_cache_size; 1127ddfb2f03Sdanielk1977 } db2 1128ddfb2f03Sdanielk1977 } {200} 1129ddfb2f03Sdanielk1977 db2 close 1130ddfb2f03Sdanielk1977 1131ddfb2f03Sdanielk1977 do_test pragma-12.3 { 1132ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1133ddfb2f03Sdanielk1977 execsql { 1134ddfb2f03Sdanielk1977 PRAGMA temp.cache_size = 400; 1135ddfb2f03Sdanielk1977 PRAGMA temp.cache_size; 1136ddfb2f03Sdanielk1977 } db2 1137ddfb2f03Sdanielk1977 } {400} 1138ddfb2f03Sdanielk1977 db2 close 1139ddfb2f03Sdanielk1977} 1140ddfb2f03Sdanielk1977 11414b2688abSdanielk1977ifcapable bloblit { 11424b2688abSdanielk1977 114305a82983Sdrhdo_test pragma-13.1 { 114405a82983Sdrh execsql { 114505a82983Sdrh DROP TABLE IF EXISTS t4; 114605a82983Sdrh PRAGMA vdbe_trace=on; 114705a82983Sdrh PRAGMA vdbe_listing=on; 114805a82983Sdrh PRAGMA sql_trace=on; 114905a82983Sdrh CREATE TABLE t4(a INTEGER PRIMARY KEY,b); 115005a82983Sdrh INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789'); 115105a82983Sdrh INSERT INTO t4(b) VALUES(randstr(30,30)); 115205a82983Sdrh INSERT INTO t4(b) VALUES(1.23456); 115305a82983Sdrh INSERT INTO t4(b) VALUES(NULL); 115405a82983Sdrh INSERT INTO t4(b) VALUES(0); 115505a82983Sdrh INSERT INTO t4(b) SELECT b||b||b||b FROM t4; 115605a82983Sdrh SELECT * FROM t4; 115705a82983Sdrh } 115805a82983Sdrh execsql { 115905a82983Sdrh PRAGMA vdbe_trace=off; 116005a82983Sdrh PRAGMA vdbe_listing=off; 116105a82983Sdrh PRAGMA sql_trace=off; 116205a82983Sdrh } 116305a82983Sdrh} {} 116405a82983Sdrh 11654b2688abSdanielk1977} ;# ifcapable bloblit 11664b2688abSdanielk1977 116759a93791Sdanielk1977ifcapable pager_pragmas { 116859a93791Sdanielk1977 db close 116959a93791Sdanielk1977 file delete -force test.db 117059a93791Sdanielk1977 sqlite3 db test.db 117159a93791Sdanielk1977 117259a93791Sdanielk1977 do_test pragma-14.1 { 117359a93791Sdanielk1977 execsql { pragma auto_vacuum = 0 } 117459a93791Sdanielk1977 execsql { pragma page_count } 117559a93791Sdanielk1977 } {0} 117659a93791Sdanielk1977 117759a93791Sdanielk1977 do_test pragma-14.2 { 117859a93791Sdanielk1977 execsql { 117959a93791Sdanielk1977 CREATE TABLE abc(a, b, c); 118059a93791Sdanielk1977 PRAGMA page_count; 118159a93791Sdanielk1977 } 118259a93791Sdanielk1977 } {2} 118359a93791Sdanielk1977 118459a93791Sdanielk1977 do_test pragma-14.3 { 118559a93791Sdanielk1977 execsql { 118659a93791Sdanielk1977 BEGIN; 118759a93791Sdanielk1977 CREATE TABLE def(a, b, c); 118859a93791Sdanielk1977 PRAGMA page_count; 118959a93791Sdanielk1977 } 119059a93791Sdanielk1977 } {3} 119159a93791Sdanielk1977 119259a93791Sdanielk1977 do_test pragma-14.4 { 119359a93791Sdanielk1977 set page_size [db one {pragma page_size}] 119459a93791Sdanielk1977 expr [file size test.db] / $page_size 119559a93791Sdanielk1977 } {2} 119659a93791Sdanielk1977 119759a93791Sdanielk1977 do_test pragma-14.5 { 119859a93791Sdanielk1977 execsql { 119959a93791Sdanielk1977 ROLLBACK; 120059a93791Sdanielk1977 PRAGMA page_count; 120159a93791Sdanielk1977 } 120259a93791Sdanielk1977 } {2} 120359a93791Sdanielk1977 120459a93791Sdanielk1977 do_test pragma-14.6 { 120559a93791Sdanielk1977 file delete -force test2.db 120659a93791Sdanielk1977 sqlite3 db2 test2.db 120759a93791Sdanielk1977 execsql { 120859a93791Sdanielk1977 PRAGMA auto_vacuum = 0; 120959a93791Sdanielk1977 CREATE TABLE t1(a, b, c); 121059a93791Sdanielk1977 CREATE TABLE t2(a, b, c); 121159a93791Sdanielk1977 CREATE TABLE t3(a, b, c); 121259a93791Sdanielk1977 CREATE TABLE t4(a, b, c); 121359a93791Sdanielk1977 } db2 121459a93791Sdanielk1977 db2 close 121559a93791Sdanielk1977 execsql { 121659a93791Sdanielk1977 ATTACH 'test2.db' AS aux; 121759a93791Sdanielk1977 PRAGMA aux.page_count; 121859a93791Sdanielk1977 } 121959a93791Sdanielk1977 } {5} 122059a93791Sdanielk1977} 122159a93791Sdanielk1977 12228cf6c554Sdanielk1977# Test that the value set using the cache_size pragma is not reset when the 12238cf6c554Sdanielk1977# schema is reloaded. 12248cf6c554Sdanielk1977# 12258cf6c554Sdanielk1977ifcapable pager_pragmas { 12268cf6c554Sdanielk1977 db close 12278cf6c554Sdanielk1977 sqlite3 db test.db 12288cf6c554Sdanielk1977 do_test pragma-15.1 { 12298cf6c554Sdanielk1977 execsql { 12308cf6c554Sdanielk1977 PRAGMA cache_size=59; 12318cf6c554Sdanielk1977 PRAGMA cache_size; 12328cf6c554Sdanielk1977 } 12338cf6c554Sdanielk1977 } {59} 12348cf6c554Sdanielk1977 do_test pragma-15.2 { 12358cf6c554Sdanielk1977 sqlite3 db2 test.db 12368cf6c554Sdanielk1977 execsql { 12378cf6c554Sdanielk1977 CREATE TABLE newtable(a, b, c); 12388cf6c554Sdanielk1977 } db2 12398cf6c554Sdanielk1977 db2 close 12408cf6c554Sdanielk1977 } {} 12418cf6c554Sdanielk1977 do_test pragma-15.3 { 12428cf6c554Sdanielk1977 # Evaluating this statement will cause the schema to be reloaded (because 12438cf6c554Sdanielk1977 # the schema was changed by another connection in pragma-15.2). At one 12448cf6c554Sdanielk1977 # point there was a bug that reset the cache_size to its default value 12458cf6c554Sdanielk1977 # when this happened. 12468cf6c554Sdanielk1977 execsql { SELECT * FROM sqlite_master } 12478cf6c554Sdanielk1977 execsql { PRAGMA cache_size } 12488cf6c554Sdanielk1977 } {59} 12498cf6c554Sdanielk1977} 12508cf6c554Sdanielk1977 12515558a8a6Sdanielk1977# Reset the sqlite3_temp_directory variable for the next run of tests: 12525558a8a6Sdanielk1977sqlite3 dbX :memory: 12535558a8a6Sdanielk1977dbX eval {PRAGMA temp_store_directory = ""} 12545558a8a6Sdanielk1977dbX close 12555558a8a6Sdanielk1977 1256*aebf413dSaswiftifcapable lock_proxy_pragmas { 1257*aebf413dSaswift set sqlite_hostid_num 1 1258*aebf413dSaswift 1259*aebf413dSaswift set using_proxy 0 1260*aebf413dSaswift foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] { 1261*aebf413dSaswift set using_proxy $value 1262*aebf413dSaswift } 1263*aebf413dSaswift 1264*aebf413dSaswift # Test the lock_proxy_file pragmas. 1265*aebf413dSaswift # 1266*aebf413dSaswift db close 1267*aebf413dSaswift set env(SQLITE_FORCE_PROXY_LOCKING) "0" 1268*aebf413dSaswift 1269*aebf413dSaswift sqlite3 db test.db 1270*aebf413dSaswift do_test pragma-16.1 { 1271*aebf413dSaswift execsql { 1272*aebf413dSaswift PRAGMA lock_proxy_file="mylittleproxy"; 1273*aebf413dSaswift select * from sqlite_master; 1274*aebf413dSaswift } 1275*aebf413dSaswift execsql { 1276*aebf413dSaswift PRAGMA lock_proxy_file; 1277*aebf413dSaswift } 1278*aebf413dSaswift } {mylittleproxy} 1279*aebf413dSaswift 1280*aebf413dSaswift do_test pragma-16.2 { 1281*aebf413dSaswift sqlite3 db2 test.db 1282*aebf413dSaswift execsql { 1283*aebf413dSaswift PRAGMA lock_proxy_file="mylittleproxy"; 1284*aebf413dSaswift } db2 1285*aebf413dSaswift } {} 1286*aebf413dSaswift 1287*aebf413dSaswift db2 close 1288*aebf413dSaswift do_test pragma-16.2.1 { 1289*aebf413dSaswift sqlite3 db2 test.db 1290*aebf413dSaswift execsql { 1291*aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1292*aebf413dSaswift select * from sqlite_master; 1293*aebf413dSaswift } db2 1294*aebf413dSaswift execsql { 1295*aebf413dSaswift PRAGMA lock_proxy_file; 1296*aebf413dSaswift } db2 1297*aebf413dSaswift } {mylittleproxy} 1298*aebf413dSaswift 1299*aebf413dSaswift db2 close 1300*aebf413dSaswift do_test pragma-16.3 { 1301*aebf413dSaswift sqlite3 db2 test.db 1302*aebf413dSaswift execsql { 1303*aebf413dSaswift PRAGMA lock_proxy_file="myotherproxy"; 1304*aebf413dSaswift } db2 1305*aebf413dSaswift catchsql { 1306*aebf413dSaswift select * from sqlite_master; 1307*aebf413dSaswift } db2 1308*aebf413dSaswift } {1 {database is locked}} 1309*aebf413dSaswift 1310*aebf413dSaswift do_test pragma-16.4 { 1311*aebf413dSaswift db2 close 1312*aebf413dSaswift db close 1313*aebf413dSaswift sqlite3 db2 test.db 1314*aebf413dSaswift execsql { 1315*aebf413dSaswift PRAGMA lock_proxy_file="myoriginalproxy"; 1316*aebf413dSaswift PRAGMA lock_proxy_file="myotherproxy"; 1317*aebf413dSaswift PRAGMA lock_proxy_file; 1318*aebf413dSaswift } db2 1319*aebf413dSaswift } {myotherproxy} 1320*aebf413dSaswift 1321*aebf413dSaswift db2 close 1322*aebf413dSaswift set env(SQLITE_FORCE_PROXY_LOCKING) "1" 1323*aebf413dSaswift do_test pragma-16.5 { 1324*aebf413dSaswift sqlite3 db2 test.db 1325*aebf413dSaswift execsql { 1326*aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1327*aebf413dSaswift PRAGMA lock_proxy_file; 1328*aebf413dSaswift } db2 1329*aebf413dSaswift } {myotherproxy} 1330*aebf413dSaswift 1331*aebf413dSaswift do_test pragma-16.6 { 1332*aebf413dSaswift db2 close 1333*aebf413dSaswift sqlite3 db2 test2.db 1334*aebf413dSaswift set lockpath [execsql { 1335*aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1336*aebf413dSaswift PRAGMA lock_proxy_file; 1337*aebf413dSaswift } db2] 1338*aebf413dSaswift string match "*test2.db:auto:" $lockpath 1339*aebf413dSaswift } {1} 1340*aebf413dSaswift 1341*aebf413dSaswift set sqlite_hostid_num 2 1342*aebf413dSaswift do_test pragma-16.7 { 1343*aebf413dSaswift sqlite3 db test2.db 1344*aebf413dSaswift execsql { 1345*aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1346*aebf413dSaswift } 1347*aebf413dSaswift catchsql { 1348*aebf413dSaswift select * from sqlite_master; 1349*aebf413dSaswift } 1350*aebf413dSaswift } {1 {database is locked}} 1351*aebf413dSaswift db close 1352*aebf413dSaswift 1353*aebf413dSaswift do_test pragma-16.8 { 1354*aebf413dSaswift sqlite3 db test2.db 1355*aebf413dSaswift catchsql { 1356*aebf413dSaswift select * from sqlite_master; 1357*aebf413dSaswift } 1358*aebf413dSaswift } {1 {database is locked}} 1359*aebf413dSaswift 1360*aebf413dSaswift db2 close 1361*aebf413dSaswift do_test pragma-16.8.1 { 1362*aebf413dSaswift execsql { 1363*aebf413dSaswift PRAGMA lock_proxy_file="yetanotherproxy"; 1364*aebf413dSaswift PRAGMA lock_proxy_file; 1365*aebf413dSaswift } 1366*aebf413dSaswift } {yetanotherproxy} 1367*aebf413dSaswift do_test pragma-16.8.2 { 1368*aebf413dSaswift execsql { 1369*aebf413dSaswift create table mine(x); 1370*aebf413dSaswift } 1371*aebf413dSaswift } {} 1372*aebf413dSaswift 1373*aebf413dSaswift db close 1374*aebf413dSaswift do_test pragma-16.9 { 1375*aebf413dSaswift sqlite3 db proxytest.db 1376*aebf413dSaswift set lockpath2 [execsql { 1377*aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1378*aebf413dSaswift PRAGMA lock_proxy_file; 1379*aebf413dSaswift } db] 1380*aebf413dSaswift string match "*proxytest.db:auto:" $lockpath2 1381*aebf413dSaswift } {1} 1382*aebf413dSaswift 1383*aebf413dSaswift set env(SQLITE_FORCE_PROXY_LOCKING) $using_proxy 1384*aebf413dSaswift set sqlite_hostid_num 0 1385*aebf413dSaswift} 1386cd61c281Sdrhfinish_test 1387