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*bb8a279eSdrh# $Id: pragma.test,v 1.59 2008/03/19 00:21:31 drh 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. 3491cf71b0Sdanielk1977# 3591cf71b0Sdanielk1977 3605a82983Sdrhifcapable !pragma { 3705a82983Sdrh finish_test 3805a82983Sdrh return 3905a82983Sdrh} 4005a82983Sdrh 41cd61c281Sdrh# Delete the preexisting database to avoid the special setup 42cd61c281Sdrh# that the "all.test" script does. 43cd61c281Sdrh# 44cd61c281Sdrhdb close 4525403650Sdrhfile delete test.db test.db-journal 4625403650Sdrhfile delete test3.db test3.db-journal 47dddca286Sdrhsqlite3 db test.db; set DB [sqlite3_connection_pointer db] 48cd61c281Sdrh 491e9daa6aSdrh 50c7b4a44cSdanielk1977ifcapable pager_pragmas { 511e9daa6aSdrhset DFLT_CACHE_SZ [db one {PRAGMA default_cache_size}] 521e9daa6aSdrhset TEMP_CACHE_SZ [db one {PRAGMA temp.default_cache_size}] 53cd61c281Sdrhdo_test pragma-1.1 { 54cd61c281Sdrh execsql { 55cd61c281Sdrh PRAGMA cache_size; 56cd61c281Sdrh PRAGMA default_cache_size; 57cd61c281Sdrh PRAGMA synchronous; 58cd61c281Sdrh } 591e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] 60cd61c281Sdrhdo_test pragma-1.2 { 61cd61c281Sdrh execsql { 62eb43e5c7Sdrh PRAGMA synchronous=OFF; 63cd61c281Sdrh PRAGMA cache_size=1234; 64cd61c281Sdrh PRAGMA cache_size; 65cd61c281Sdrh PRAGMA default_cache_size; 66cd61c281Sdrh PRAGMA synchronous; 67cd61c281Sdrh } 681e9daa6aSdrh} [list 1234 $DFLT_CACHE_SZ 0] 69cd61c281Sdrhdo_test pragma-1.3 { 70cd61c281Sdrh db close 71ef4ac8f9Sdrh sqlite3 db test.db 72cd61c281Sdrh execsql { 73cd61c281Sdrh PRAGMA cache_size; 74cd61c281Sdrh PRAGMA default_cache_size; 75cd61c281Sdrh PRAGMA synchronous; 76cd61c281Sdrh } 771e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] 78cd61c281Sdrhdo_test pragma-1.4 { 79cd61c281Sdrh execsql { 80cd61c281Sdrh PRAGMA synchronous=OFF; 81cd61c281Sdrh PRAGMA cache_size; 82cd61c281Sdrh PRAGMA default_cache_size; 83cd61c281Sdrh PRAGMA synchronous; 84cd61c281Sdrh } 851e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 0] 86cd61c281Sdrhdo_test pragma-1.5 { 87cd61c281Sdrh execsql { 88cd61c281Sdrh PRAGMA cache_size=4321; 89cd61c281Sdrh PRAGMA cache_size; 90cd61c281Sdrh PRAGMA default_cache_size; 91cd61c281Sdrh PRAGMA synchronous; 92cd61c281Sdrh } 931e9daa6aSdrh} [list 4321 $DFLT_CACHE_SZ 0] 94cd61c281Sdrhdo_test pragma-1.6 { 95cd61c281Sdrh execsql { 96cd61c281Sdrh PRAGMA synchronous=ON; 97cd61c281Sdrh PRAGMA cache_size; 98cd61c281Sdrh PRAGMA default_cache_size; 99cd61c281Sdrh PRAGMA synchronous; 100cd61c281Sdrh } 1011e9daa6aSdrh} [list 4321 $DFLT_CACHE_SZ 1] 102cd61c281Sdrhdo_test pragma-1.7 { 103cd61c281Sdrh db close 104ef4ac8f9Sdrh sqlite3 db test.db 105cd61c281Sdrh execsql { 106cd61c281Sdrh PRAGMA cache_size; 107cd61c281Sdrh PRAGMA default_cache_size; 108cd61c281Sdrh PRAGMA synchronous; 109cd61c281Sdrh } 1101e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] 111cd61c281Sdrhdo_test pragma-1.8 { 112cd61c281Sdrh execsql { 113cd61c281Sdrh PRAGMA default_cache_size=123; 114cd61c281Sdrh PRAGMA cache_size; 115cd61c281Sdrh PRAGMA default_cache_size; 116cd61c281Sdrh PRAGMA synchronous; 117cd61c281Sdrh } 11891cf71b0Sdanielk1977} {123 123 2} 119802d69a7Sdrhdo_test pragma-1.9.1 { 120cd61c281Sdrh db close 121dddca286Sdrh sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db] 122cd61c281Sdrh execsql { 123cd61c281Sdrh PRAGMA cache_size; 124cd61c281Sdrh PRAGMA default_cache_size; 125cd61c281Sdrh PRAGMA synchronous; 126cd61c281Sdrh } 12791cf71b0Sdanielk1977} {123 123 2} 128802d69a7Sdrhifcapable vacuum { 129802d69a7Sdrh do_test pragma-1.9.2 { 130802d69a7Sdrh execsql { 131802d69a7Sdrh VACUUM; 132802d69a7Sdrh PRAGMA cache_size; 133802d69a7Sdrh PRAGMA default_cache_size; 134802d69a7Sdrh PRAGMA synchronous; 135802d69a7Sdrh } 136802d69a7Sdrh } {123 123 2} 137802d69a7Sdrh} 13891cf71b0Sdanielk1977do_test pragma-1.10 { 1395a38705eSdrh execsql { 1404303feedSdrh PRAGMA synchronous=NORMAL; 1414303feedSdrh PRAGMA cache_size; 1424303feedSdrh PRAGMA default_cache_size; 1434303feedSdrh PRAGMA synchronous; 1444303feedSdrh } 14591cf71b0Sdanielk1977} {123 123 1} 14691cf71b0Sdanielk1977do_test pragma-1.11 { 1474303feedSdrh execsql { 1484303feedSdrh PRAGMA synchronous=FULL; 1494303feedSdrh PRAGMA cache_size; 1504303feedSdrh PRAGMA default_cache_size; 1514303feedSdrh PRAGMA synchronous; 1524303feedSdrh } 15391cf71b0Sdanielk1977} {123 123 2} 15491cf71b0Sdanielk1977do_test pragma-1.12 { 1554303feedSdrh db close 156dddca286Sdrh sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db] 1574303feedSdrh execsql { 1584303feedSdrh PRAGMA cache_size; 1594303feedSdrh PRAGMA default_cache_size; 1604303feedSdrh PRAGMA synchronous; 1614303feedSdrh } 16291cf71b0Sdanielk1977} {123 123 2} 16391cf71b0Sdanielk1977 1645260f7e9Sdrh# Make sure the pragma handler understands numeric values in addition 1655260f7e9Sdrh# to keywords like "off" and "full". 1665260f7e9Sdrh# 1675260f7e9Sdrhdo_test pragma-1.13 { 1685260f7e9Sdrh execsql { 1695260f7e9Sdrh PRAGMA synchronous=0; 1705260f7e9Sdrh PRAGMA synchronous; 1715260f7e9Sdrh } 1725260f7e9Sdrh} {0} 1735260f7e9Sdrhdo_test pragma-1.14 { 1745260f7e9Sdrh execsql { 1755260f7e9Sdrh PRAGMA synchronous=2; 1765260f7e9Sdrh PRAGMA synchronous; 1775260f7e9Sdrh } 1785260f7e9Sdrh} {2} 179c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 1805260f7e9Sdrh 1815260f7e9Sdrh# Test turning "flag" pragmas on and off. 1825260f7e9Sdrh# 1836338c762Sdanielk1977ifcapable debug { 1846338c762Sdanielk1977 # Pragma "vdbe_listing" is only available if compiled with SQLITE_DEBUG 1856338c762Sdanielk1977 # 1865260f7e9Sdrh do_test pragma-1.15 { 1875260f7e9Sdrh execsql { 1885260f7e9Sdrh PRAGMA vdbe_listing=YES; 1895260f7e9Sdrh PRAGMA vdbe_listing; 1905260f7e9Sdrh } 1915260f7e9Sdrh } {1} 1925260f7e9Sdrh do_test pragma-1.16 { 1935260f7e9Sdrh execsql { 1945260f7e9Sdrh PRAGMA vdbe_listing=NO; 1955260f7e9Sdrh PRAGMA vdbe_listing; 1965260f7e9Sdrh } 1975260f7e9Sdrh } {0} 1986338c762Sdanielk1977} 1996338c762Sdanielk1977 2005260f7e9Sdrhdo_test pragma-1.17 { 2015260f7e9Sdrh execsql { 2025260f7e9Sdrh PRAGMA parser_trace=ON; 2035260f7e9Sdrh PRAGMA parser_trace=OFF; 2045260f7e9Sdrh } 2055260f7e9Sdrh} {} 2065260f7e9Sdrhdo_test pragma-1.18 { 2075260f7e9Sdrh execsql { 2085260f7e9Sdrh PRAGMA bogus = -1234; -- Parsing of negative values 2095260f7e9Sdrh } 2105260f7e9Sdrh} {} 2115260f7e9Sdrh 21291cf71b0Sdanielk1977# Test modifying the safety_level of an attached database. 2135a8f9374Sdanielk1977ifcapable pager_pragmas&&attach { 21491cf71b0Sdanielk1977 do_test pragma-2.1 { 21591cf71b0Sdanielk1977 file delete -force test2.db 21691cf71b0Sdanielk1977 file delete -force test2.db-journal 2174303feedSdrh execsql { 21891cf71b0Sdanielk1977 ATTACH 'test2.db' AS aux; 2194303feedSdrh } 22091cf71b0Sdanielk1977 } {} 22191cf71b0Sdanielk1977 do_test pragma-2.2 { 2224303feedSdrh execsql { 22391cf71b0Sdanielk1977 pragma aux.synchronous; 2244303feedSdrh } 22591cf71b0Sdanielk1977 } {2} 22691cf71b0Sdanielk1977 do_test pragma-2.3 { 22791cf71b0Sdanielk1977 execsql { 22891cf71b0Sdanielk1977 pragma aux.synchronous = OFF; 22991cf71b0Sdanielk1977 pragma aux.synchronous; 23091cf71b0Sdanielk1977 pragma synchronous; 23191cf71b0Sdanielk1977 } 23291cf71b0Sdanielk1977 } {0 2} 23391cf71b0Sdanielk1977 do_test pragma-2.4 { 23491cf71b0Sdanielk1977 execsql { 23591cf71b0Sdanielk1977 pragma aux.synchronous = ON; 23691cf71b0Sdanielk1977 pragma synchronous; 23791cf71b0Sdanielk1977 pragma aux.synchronous; 23891cf71b0Sdanielk1977 } 23991cf71b0Sdanielk1977 } {2 1} 240c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 2414303feedSdrh 242ed717fe3Sdrh# Construct a corrupted index and make sure the integrity_check 243ed717fe3Sdrh# pragma finds it. 244ed717fe3Sdrh# 24525d6543dSdrh# These tests won't work if the database is encrypted 24625d6543dSdrh# 247ed717fe3Sdrhdo_test pragma-3.1 { 2481e9daa6aSdrh db close 2491e9daa6aSdrh file delete -force test.db test.db-journal 2501e9daa6aSdrh sqlite3 db test.db 251ed717fe3Sdrh execsql { 2521e9daa6aSdrh PRAGMA auto_vacuum=OFF; 253ed717fe3Sdrh BEGIN; 254ed717fe3Sdrh CREATE TABLE t2(a,b,c); 255ed717fe3Sdrh CREATE INDEX i2 ON t2(a); 256ed717fe3Sdrh INSERT INTO t2 VALUES(11,2,3); 257ed717fe3Sdrh INSERT INTO t2 VALUES(22,3,4); 258ed717fe3Sdrh COMMIT; 259ed717fe3Sdrh SELECT rowid, * from t2; 260ed717fe3Sdrh } 261ed717fe3Sdrh} {1 11 2 3 2 22 3 4} 2625a8f9374Sdanielk1977ifcapable attach { 26340e016e4Sdrh if {![sqlite3 -has-codec] && $sqlite_options(integrityck)} { 264ed717fe3Sdrh do_test pragma-3.2 { 265*bb8a279eSdrh db eval {SELECT rootpage FROM sqlite_master WHERE name='i2'} break 266*bb8a279eSdrh set pgsz [db eval {PRAGMA page_size}] 267*bb8a279eSdrh # overwrite the header on the rootpage of the index in order to 268*bb8a279eSdrh # make the index appear to be empty. 269*bb8a279eSdrh # 270*bb8a279eSdrh set offset [expr {$pgsz*($rootpage-1)}] 271*bb8a279eSdrh hexio_write test.db $offset 0a00000000040000000000 272*bb8a279eSdrh db close 273*bb8a279eSdrh sqlite3 db test.db 274ed717fe3Sdrh execsql {PRAGMA integrity_check} 275*bb8a279eSdrh } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}} 27691cf71b0Sdanielk1977 do_test pragma-3.3 { 2771dcdbc06Sdrh execsql {PRAGMA integrity_check=1} 2781dcdbc06Sdrh } {{rowid 1 missing from index i2}} 2791dcdbc06Sdrh do_test pragma-3.4 { 28091cf71b0Sdanielk1977 execsql { 2811dcdbc06Sdrh ATTACH DATABASE 'test.db' AS t2; 2821dcdbc06Sdrh PRAGMA integrity_check 28391cf71b0Sdanielk1977 } 284*bb8a279eSdrh } {{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}} 2851dcdbc06Sdrh do_test pragma-3.5 { 2861dcdbc06Sdrh execsql { 287*bb8a279eSdrh PRAGMA integrity_check=4 2881dcdbc06Sdrh } 289*bb8a279eSdrh } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2}} 2901dcdbc06Sdrh do_test pragma-3.6 { 2911dcdbc06Sdrh execsql { 2921dcdbc06Sdrh PRAGMA integrity_check=xyz 2931dcdbc06Sdrh } 294*bb8a279eSdrh } {{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}} 2951dcdbc06Sdrh do_test pragma-3.7 { 2961dcdbc06Sdrh execsql { 2971dcdbc06Sdrh PRAGMA integrity_check=0 2981dcdbc06Sdrh } 299*bb8a279eSdrh } {{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}} 3001dcdbc06Sdrh 3011dcdbc06Sdrh # Add additional corruption by appending unused pages to the end of 3021dcdbc06Sdrh # the database file testerr.db 3031dcdbc06Sdrh # 3041dcdbc06Sdrh do_test pragma-3.8 { 3051dcdbc06Sdrh execsql {DETACH t2} 3061dcdbc06Sdrh file delete -force testerr.db testerr.db-journal 307e3d559adSdrh set out [open testerr.db w] 308e3d559adSdrh fconfigure $out -translation binary 309e3d559adSdrh set in [open test.db r] 310e3d559adSdrh fconfigure $in -translation binary 3111dcdbc06Sdrh puts -nonewline $out [read $in] 3121dcdbc06Sdrh seek $in 0 3131dcdbc06Sdrh puts -nonewline $out [read $in] 3141dcdbc06Sdrh close $in 3151dcdbc06Sdrh close $out 3161dcdbc06Sdrh execsql {REINDEX t2} 3171dcdbc06Sdrh execsql {PRAGMA integrity_check} 3181dcdbc06Sdrh } {ok} 31941c58b78Sdanielk1977 do_test pragma-3.8.1 { 32041c58b78Sdanielk1977 execsql {PRAGMA quick_check} 32141c58b78Sdanielk1977 } {ok} 3221dcdbc06Sdrh do_test pragma-3.9 { 3231dcdbc06Sdrh execsql { 3241dcdbc06Sdrh ATTACH 'testerr.db' AS t2; 3251dcdbc06Sdrh PRAGMA integrity_check 3261dcdbc06Sdrh } 3271dcdbc06Sdrh } {{*** in database t2 *** 3281dcdbc06SdrhPage 4 is never used 3291dcdbc06SdrhPage 5 is never used 330*bb8a279eSdrhPage 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}} 3311dcdbc06Sdrh do_test pragma-3.10 { 3321dcdbc06Sdrh execsql { 3331dcdbc06Sdrh PRAGMA integrity_check=1 3341dcdbc06Sdrh } 3351dcdbc06Sdrh } {{*** in database t2 *** 3361dcdbc06SdrhPage 4 is never used}} 3371dcdbc06Sdrh do_test pragma-3.11 { 3381dcdbc06Sdrh execsql { 3391dcdbc06Sdrh PRAGMA integrity_check=5 3401dcdbc06Sdrh } 3411dcdbc06Sdrh } {{*** in database t2 *** 3421dcdbc06SdrhPage 4 is never used 3431dcdbc06SdrhPage 5 is never used 344*bb8a279eSdrhPage 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2}} 3451dcdbc06Sdrh do_test pragma-3.12 { 3461dcdbc06Sdrh execsql { 3471dcdbc06Sdrh PRAGMA integrity_check=4 3481dcdbc06Sdrh } 3491dcdbc06Sdrh } {{*** in database t2 *** 3501dcdbc06SdrhPage 4 is never used 3511dcdbc06SdrhPage 5 is never used 3521dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}} 3531dcdbc06Sdrh do_test pragma-3.13 { 3541dcdbc06Sdrh execsql { 3551dcdbc06Sdrh PRAGMA integrity_check=3 3561dcdbc06Sdrh } 3571dcdbc06Sdrh } {{*** in database t2 *** 3581dcdbc06SdrhPage 4 is never used 3591dcdbc06SdrhPage 5 is never used 3601dcdbc06SdrhPage 6 is never used}} 3611dcdbc06Sdrh do_test pragma-3.14 { 3621dcdbc06Sdrh execsql { 3631dcdbc06Sdrh PRAGMA integrity_check(2) 3641dcdbc06Sdrh } 3651dcdbc06Sdrh } {{*** in database t2 *** 3661dcdbc06SdrhPage 4 is never used 3671dcdbc06SdrhPage 5 is never used}} 3681dcdbc06Sdrh do_test pragma-3.15 { 3691dcdbc06Sdrh execsql { 3701dcdbc06Sdrh ATTACH 'testerr.db' AS t3; 3711dcdbc06Sdrh PRAGMA integrity_check 3721dcdbc06Sdrh } 3731dcdbc06Sdrh } {{*** in database t2 *** 3741dcdbc06SdrhPage 4 is never used 3751dcdbc06SdrhPage 5 is never used 376*bb8a279eSdrhPage 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 *** 3771dcdbc06SdrhPage 4 is never used 3781dcdbc06SdrhPage 5 is never used 379*bb8a279eSdrhPage 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}} 3801dcdbc06Sdrh do_test pragma-3.16 { 3811dcdbc06Sdrh execsql { 382*bb8a279eSdrh PRAGMA integrity_check(10) 3831dcdbc06Sdrh } 3841dcdbc06Sdrh } {{*** in database t2 *** 3851dcdbc06SdrhPage 4 is never used 3861dcdbc06SdrhPage 5 is never used 387*bb8a279eSdrhPage 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 *** 3881dcdbc06SdrhPage 4 is never used 3891dcdbc06SdrhPage 5 is never used 3901dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}} 3911dcdbc06Sdrh do_test pragma-3.17 { 3921dcdbc06Sdrh execsql { 393*bb8a279eSdrh PRAGMA integrity_check=8 3941dcdbc06Sdrh } 3951dcdbc06Sdrh } {{*** in database t2 *** 3961dcdbc06SdrhPage 4 is never used 3971dcdbc06SdrhPage 5 is never used 398*bb8a279eSdrhPage 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 *** 3991dcdbc06SdrhPage 4 is never used 4001dcdbc06SdrhPage 5 is never used}} 4011dcdbc06Sdrh do_test pragma-3.18 { 4021dcdbc06Sdrh execsql { 4031dcdbc06Sdrh PRAGMA integrity_check=4 4041dcdbc06Sdrh } 4051dcdbc06Sdrh } {{*** in database t2 *** 4061dcdbc06SdrhPage 4 is never used 4071dcdbc06SdrhPage 5 is never used 4081dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}} 4091dcdbc06Sdrh } 4101dcdbc06Sdrh do_test pragma-3.99 { 4111dcdbc06Sdrh catchsql {DETACH t3} 4121dcdbc06Sdrh catchsql {DETACH t2} 41390ddb123Sdrh file delete -force testerr.db testerr.db-journal 41405a6f4acSdrh catchsql {DROP INDEX i2} 4151dcdbc06Sdrh } {0 {}} 4165a8f9374Sdanielk1977} 41791cf71b0Sdanielk1977 41891cf71b0Sdanielk1977# Test modifying the cache_size of an attached database. 4195a8f9374Sdanielk1977ifcapable pager_pragmas&&attach { 42091cf71b0Sdanielk1977do_test pragma-4.1 { 42191cf71b0Sdanielk1977 execsql { 4221e9daa6aSdrh ATTACH 'test2.db' AS aux; 42391cf71b0Sdanielk1977 pragma aux.cache_size; 42491cf71b0Sdanielk1977 pragma aux.default_cache_size; 42591cf71b0Sdanielk1977 } 4261e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] 4271bdd9b57Sdrhdo_test pragma-4.2 { 4281bdd9b57Sdrh execsql { 42991cf71b0Sdanielk1977 pragma aux.cache_size = 50; 43091cf71b0Sdanielk1977 pragma aux.cache_size; 43191cf71b0Sdanielk1977 pragma aux.default_cache_size; 4321bdd9b57Sdrh } 4331e9daa6aSdrh} [list 50 $DFLT_CACHE_SZ] 4341bdd9b57Sdrhdo_test pragma-4.3 { 4351bdd9b57Sdrh execsql { 43691cf71b0Sdanielk1977 pragma aux.default_cache_size = 456; 43791cf71b0Sdanielk1977 pragma aux.cache_size; 43891cf71b0Sdanielk1977 pragma aux.default_cache_size; 4391bdd9b57Sdrh } 44091cf71b0Sdanielk1977} {456 456} 4411bdd9b57Sdrhdo_test pragma-4.4 { 4421bdd9b57Sdrh execsql { 44391cf71b0Sdanielk1977 pragma cache_size; 44491cf71b0Sdanielk1977 pragma default_cache_size; 4451bdd9b57Sdrh } 4461e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] 4471bdd9b57Sdrhdo_test pragma-4.5 { 4481bdd9b57Sdrh execsql { 44991cf71b0Sdanielk1977 DETACH aux; 45091cf71b0Sdanielk1977 ATTACH 'test3.db' AS aux; 45191cf71b0Sdanielk1977 pragma aux.cache_size; 45291cf71b0Sdanielk1977 pragma aux.default_cache_size; 4531bdd9b57Sdrh } 4541e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] 4551bdd9b57Sdrhdo_test pragma-4.6 { 4561bdd9b57Sdrh execsql { 45791cf71b0Sdanielk1977 DETACH aux; 45891cf71b0Sdanielk1977 ATTACH 'test2.db' AS aux; 45991cf71b0Sdanielk1977 pragma aux.cache_size; 46091cf71b0Sdanielk1977 pragma aux.default_cache_size; 4611bdd9b57Sdrh } 46291cf71b0Sdanielk1977} {456 456} 463c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 4641bdd9b57Sdrh 46591cf71b0Sdanielk1977# Test that modifying the sync-level in the middle of a transaction is 46691cf71b0Sdanielk1977# disallowed. 467c7b4a44cSdanielk1977ifcapable pager_pragmas { 46891cf71b0Sdanielk1977do_test pragma-5.0 { 4691bdd9b57Sdrh execsql { 47091cf71b0Sdanielk1977 pragma synchronous; 4711bdd9b57Sdrh } 47291cf71b0Sdanielk1977} {2} 47391cf71b0Sdanielk1977do_test pragma-5.1 { 4741bdd9b57Sdrh catchsql { 4751bdd9b57Sdrh BEGIN; 47691cf71b0Sdanielk1977 pragma synchronous = OFF; 4771bdd9b57Sdrh } 47891cf71b0Sdanielk1977} {1 {Safety level may not be changed inside a transaction}} 47991cf71b0Sdanielk1977do_test pragma-5.2 { 48091cf71b0Sdanielk1977 execsql { 48191cf71b0Sdanielk1977 pragma synchronous; 48291cf71b0Sdanielk1977 } 48391cf71b0Sdanielk1977} {2} 4845260f7e9Sdrhcatchsql {COMMIT;} 485c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 4865260f7e9Sdrh 4875260f7e9Sdrh# Test schema-query pragmas 4885260f7e9Sdrh# 48927188fb5Sdanielk1977ifcapable schema_pragmas { 4905a8f9374Sdanielk1977ifcapable tempdb&&attach { 4915260f7e9Sdrh do_test pragma-6.1 { 492956bc92cSdrh set res {} 49340e016e4Sdrh execsql {SELECT * FROM sqlite_temp_master} 4945260f7e9Sdrh foreach {idx name file} [execsql {pragma database_list}] { 4955260f7e9Sdrh lappend res $idx $name 4965260f7e9Sdrh } 4975260f7e9Sdrh set res 498a71aa001Sdrh } {0 main 1 temp 2 aux} 49953c0f748Sdanielk1977} 5005260f7e9Sdrhdo_test pragma-6.2 { 5015260f7e9Sdrh execsql { 5025260f7e9Sdrh pragma table_info(t2) 5035260f7e9Sdrh } 504bfa8b102Sdrh} {0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0} 505736c7d4bSdrhdb nullvalue <<NULL>> 506417ec638Sdrhdo_test pragma-6.2.2 { 507417ec638Sdrh execsql { 508736c7d4bSdrh CREATE TABLE t5( 509736c7d4bSdrh a TEXT DEFAULT CURRENT_TIMESTAMP, 510736c7d4bSdrh b DEFAULT (5+3), 511736c7d4bSdrh c TEXT, 512736c7d4bSdrh d INTEGER DEFAULT NULL, 513736c7d4bSdrh e TEXT DEFAULT '' 514736c7d4bSdrh ); 515417ec638Sdrh PRAGMA table_info(t5); 516417ec638Sdrh } 517736c7d4bSdrh} {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} 518736c7d4bSdrhdb nullvalue {} 5196bf89570Sdrhifcapable {foreignkey} { 5205260f7e9Sdrh do_test pragma-6.3 { 5215260f7e9Sdrh execsql { 5225260f7e9Sdrh CREATE TABLE t3(a int references t2(b), b UNIQUE); 5235260f7e9Sdrh pragma foreign_key_list(t3); 5245260f7e9Sdrh } 5255260f7e9Sdrh } {0 0 t2 a b} 5265260f7e9Sdrh do_test pragma-6.4 { 5275260f7e9Sdrh execsql { 5285260f7e9Sdrh pragma index_list(t3); 5295260f7e9Sdrh } 5305260f7e9Sdrh } {0 sqlite_autoindex_t3_1 1} 5316bf89570Sdrh} 5326bf89570Sdrhifcapable {!foreignkey} { 5336bf89570Sdrh execsql {CREATE TABLE t3(a,b UNIQUE)} 5346bf89570Sdrh} 5355260f7e9Sdrhdo_test pragma-6.5 { 5365260f7e9Sdrh execsql { 5375260f7e9Sdrh CREATE INDEX t3i1 ON t3(a,b); 5385260f7e9Sdrh pragma index_info(t3i1); 5395260f7e9Sdrh } 5405260f7e9Sdrh} {0 0 a 1 1 b} 54127188fb5Sdanielk1977} ;# ifcapable schema_pragmas 5425260f7e9Sdrh# Miscellaneous tests 5435260f7e9Sdrh# 54427188fb5Sdanielk1977ifcapable schema_pragmas { 5455260f7e9Sdrhdo_test pragma-7.1 { 5465260f7e9Sdrh # Make sure a pragma knows to read the schema if it needs to 5475260f7e9Sdrh db close 5485260f7e9Sdrh sqlite3 db test.db 5495260f7e9Sdrh execsql { 5505260f7e9Sdrh pragma index_list(t3); 5515260f7e9Sdrh } 5525260f7e9Sdrh} {0 t3i1 0 1 sqlite_autoindex_t3_1 1} 55327188fb5Sdanielk1977} ;# ifcapable schema_pragmas 5546c62608fSdrhifcapable {utf16} { 5555260f7e9Sdrh do_test pragma-7.2 { 5565260f7e9Sdrh db close 5575260f7e9Sdrh sqlite3 db test.db 5585260f7e9Sdrh catchsql { 5595260f7e9Sdrh pragma encoding=bogus; 5605260f7e9Sdrh } 5615260f7e9Sdrh } {1 {unsupported encoding: bogus}} 5626c62608fSdrh} 56353c0f748Sdanielk1977ifcapable tempdb { 5645260f7e9Sdrh do_test pragma-7.3 { 5655260f7e9Sdrh db close 5665260f7e9Sdrh sqlite3 db test.db 5675260f7e9Sdrh execsql { 5685260f7e9Sdrh pragma lock_status; 5695260f7e9Sdrh } 5705260f7e9Sdrh } {main unlocked temp closed} 57153c0f748Sdanielk1977} else { 57253c0f748Sdanielk1977 do_test pragma-7.3 { 57353c0f748Sdanielk1977 db close 57453c0f748Sdanielk1977 sqlite3 db test.db 57553c0f748Sdanielk1977 execsql { 57653c0f748Sdanielk1977 pragma lock_status; 57753c0f748Sdanielk1977 } 57853c0f748Sdanielk1977 } {main unlocked} 57953c0f748Sdanielk1977} 5805260f7e9Sdrh 5815260f7e9Sdrh 582dae2495bSdanielk1977#---------------------------------------------------------------------- 583b92b70bbSdanielk1977# Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA 584b92b70bbSdanielk1977# user_version" statements. 585dae2495bSdanielk1977# 586b92b70bbSdanielk1977# pragma-8.1: PRAGMA schema_version 587b92b70bbSdanielk1977# pragma-8.2: PRAGMA user_version 588dae2495bSdanielk1977# 589dae2495bSdanielk1977 59011cf9fbcSdanielk1977ifcapable schema_version { 59111cf9fbcSdanielk1977 592b92b70bbSdanielk1977# First check that we can set the schema version and then retrieve the 593dae2495bSdanielk1977# same value. 594dae2495bSdanielk1977do_test pragma-8.1.1 { 595dae2495bSdanielk1977 execsql { 596b92b70bbSdanielk1977 PRAGMA schema_version = 105; 597dae2495bSdanielk1977 } 598dae2495bSdanielk1977} {} 599dae2495bSdanielk1977do_test pragma-8.1.2 { 60025403650Sdrh execsql2 { 601b92b70bbSdanielk1977 PRAGMA schema_version; 602dae2495bSdanielk1977 } 60325403650Sdrh} {schema_version 105} 604dae2495bSdanielk1977do_test pragma-8.1.3 { 605dae2495bSdanielk1977 execsql { 606b92b70bbSdanielk1977 PRAGMA schema_version = 106; 607dae2495bSdanielk1977 } 608dae2495bSdanielk1977} {} 609dae2495bSdanielk1977do_test pragma-8.1.4 { 610dae2495bSdanielk1977 execsql { 611b92b70bbSdanielk1977 PRAGMA schema_version; 612dae2495bSdanielk1977 } 613dae2495bSdanielk1977} 106 614dae2495bSdanielk1977 615b92b70bbSdanielk1977# Check that creating a table modifies the schema-version (this is really 616b92b70bbSdanielk1977# to verify that the value being read is in fact the schema version). 617dae2495bSdanielk1977do_test pragma-8.1.5 { 618dae2495bSdanielk1977 execsql { 619dae2495bSdanielk1977 CREATE TABLE t4(a, b, c); 620dae2495bSdanielk1977 INSERT INTO t4 VALUES(1, 2, 3); 621dae2495bSdanielk1977 SELECT * FROM t4; 622dae2495bSdanielk1977 } 623dae2495bSdanielk1977} {1 2 3} 624dae2495bSdanielk1977do_test pragma-8.1.6 { 625dae2495bSdanielk1977 execsql { 626b92b70bbSdanielk1977 PRAGMA schema_version; 627dae2495bSdanielk1977 } 628dae2495bSdanielk1977} 107 629dae2495bSdanielk1977 630dae2495bSdanielk1977# Now open a second connection to the database. Ensure that changing the 631b92b70bbSdanielk1977# schema-version using the first connection forces the second connection 632dae2495bSdanielk1977# to reload the schema. This has to be done using the C-API test functions, 633dae2495bSdanielk1977# because the TCL API accounts for SCHEMA_ERROR and retries the query. 634dae2495bSdanielk1977do_test pragma-8.1.7 { 635dddca286Sdrh sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] 636dae2495bSdanielk1977 execsql { 637dae2495bSdanielk1977 SELECT * FROM t4; 638dae2495bSdanielk1977 } db2 639dae2495bSdanielk1977} {1 2 3} 640dae2495bSdanielk1977do_test pragma-8.1.8 { 641dae2495bSdanielk1977 execsql { 642b92b70bbSdanielk1977 PRAGMA schema_version = 108; 643dae2495bSdanielk1977 } 644dae2495bSdanielk1977} {} 645dae2495bSdanielk1977do_test pragma-8.1.9 { 646dae2495bSdanielk1977 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY] 647dae2495bSdanielk1977 sqlite3_step $::STMT 648dae2495bSdanielk1977} SQLITE_ERROR 649dae2495bSdanielk1977do_test pragma-8.1.10 { 650dae2495bSdanielk1977 sqlite3_finalize $::STMT 651dae2495bSdanielk1977} SQLITE_SCHEMA 652dae2495bSdanielk1977 653b92b70bbSdanielk1977# Make sure the schema-version can be manipulated in an attached database. 654dae2495bSdanielk1977file delete -force test2.db 655dae2495bSdanielk1977file delete -force test2.db-journal 6565a8f9374Sdanielk1977ifcapable attach { 657dae2495bSdanielk1977 do_test pragma-8.1.11 { 658dae2495bSdanielk1977 execsql { 659dae2495bSdanielk1977 ATTACH 'test2.db' AS aux; 660dae2495bSdanielk1977 CREATE TABLE aux.t1(a, b, c); 661b92b70bbSdanielk1977 PRAGMA aux.schema_version = 205; 662dae2495bSdanielk1977 } 663dae2495bSdanielk1977 } {} 664dae2495bSdanielk1977 do_test pragma-8.1.12 { 665dae2495bSdanielk1977 execsql { 666b92b70bbSdanielk1977 PRAGMA aux.schema_version; 667dae2495bSdanielk1977 } 668dae2495bSdanielk1977 } 205 6695a8f9374Sdanielk1977} 670dae2495bSdanielk1977do_test pragma-8.1.13 { 671dae2495bSdanielk1977 execsql { 672b92b70bbSdanielk1977 PRAGMA schema_version; 673dae2495bSdanielk1977 } 674dae2495bSdanielk1977} 108 675dae2495bSdanielk1977 676b92b70bbSdanielk1977# And check that modifying the schema-version in an attached database 677dae2495bSdanielk1977# forces the second connection to reload the schema. 6785a8f9374Sdanielk1977ifcapable attach { 679dae2495bSdanielk1977 do_test pragma-8.1.14 { 680dddca286Sdrh sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] 681dae2495bSdanielk1977 execsql { 682dae2495bSdanielk1977 ATTACH 'test2.db' AS aux; 683dae2495bSdanielk1977 SELECT * FROM aux.t1; 684dae2495bSdanielk1977 } db2 685dae2495bSdanielk1977 } {} 686dae2495bSdanielk1977 do_test pragma-8.1.15 { 687dae2495bSdanielk1977 execsql { 688b92b70bbSdanielk1977 PRAGMA aux.schema_version = 206; 689dae2495bSdanielk1977 } 690dae2495bSdanielk1977 } {} 691dae2495bSdanielk1977 do_test pragma-8.1.16 { 692dae2495bSdanielk1977 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY] 693dae2495bSdanielk1977 sqlite3_step $::STMT 694dae2495bSdanielk1977 } SQLITE_ERROR 695dae2495bSdanielk1977 do_test pragma-8.1.17 { 696dae2495bSdanielk1977 sqlite3_finalize $::STMT 697dae2495bSdanielk1977 } SQLITE_SCHEMA 698dae2495bSdanielk1977 do_test pragma-8.1.18 { 699dae2495bSdanielk1977 db2 close 700dae2495bSdanielk1977 } {} 7015a8f9374Sdanielk1977} 702dae2495bSdanielk1977 703b92b70bbSdanielk1977# Now test that the user-version can be read and written (and that we aren't 704b92b70bbSdanielk1977# accidentally manipulating the schema-version instead). 705dae2495bSdanielk1977do_test pragma-8.2.1 { 70625403650Sdrh execsql2 { 707b92b70bbSdanielk1977 PRAGMA user_version; 708dae2495bSdanielk1977 } 70925403650Sdrh} {user_version 0} 710dae2495bSdanielk1977do_test pragma-8.2.2 { 711dae2495bSdanielk1977 execsql { 712b92b70bbSdanielk1977 PRAGMA user_version = 2; 713dae2495bSdanielk1977 } 714dae2495bSdanielk1977} {} 715802d69a7Sdrhdo_test pragma-8.2.3.1 { 71625403650Sdrh execsql2 { 717b92b70bbSdanielk1977 PRAGMA user_version; 718dae2495bSdanielk1977 } 71925403650Sdrh} {user_version 2} 720802d69a7Sdrhdo_test pragma-8.2.3.2 { 721802d69a7Sdrh db close 722802d69a7Sdrh sqlite3 db test.db 723802d69a7Sdrh execsql { 724802d69a7Sdrh PRAGMA user_version; 725802d69a7Sdrh } 726802d69a7Sdrh} {2} 727802d69a7Sdrhdo_test pragma-8.2.4.1 { 728dae2495bSdanielk1977 execsql { 729b92b70bbSdanielk1977 PRAGMA schema_version; 730dae2495bSdanielk1977 } 731dae2495bSdanielk1977} {108} 732802d69a7Sdrhifcapable vacuum { 733802d69a7Sdrh do_test pragma-8.2.4.2 { 734802d69a7Sdrh execsql { 735802d69a7Sdrh VACUUM; 736802d69a7Sdrh PRAGMA user_version; 737802d69a7Sdrh } 738802d69a7Sdrh } {2} 739802d69a7Sdrh do_test pragma-8.2.4.3 { 740802d69a7Sdrh execsql { 741802d69a7Sdrh PRAGMA schema_version; 742802d69a7Sdrh } 743802d69a7Sdrh } {109} 744802d69a7Sdrh} 7455a8f9374Sdanielk1977 7465a8f9374Sdanielk1977ifcapable attach { 747802d69a7Sdrh db eval {ATTACH 'test2.db' AS aux} 748dae2495bSdanielk1977 749b92b70bbSdanielk1977 # Check that the user-version in the auxilary database can be manipulated ( 750dae2495bSdanielk1977 # and that we aren't accidentally manipulating the same in the main db). 751dae2495bSdanielk1977 do_test pragma-8.2.5 { 752dae2495bSdanielk1977 execsql { 753b92b70bbSdanielk1977 PRAGMA aux.user_version; 754dae2495bSdanielk1977 } 755dae2495bSdanielk1977 } {0} 756dae2495bSdanielk1977 do_test pragma-8.2.6 { 757dae2495bSdanielk1977 execsql { 758b92b70bbSdanielk1977 PRAGMA aux.user_version = 3; 759dae2495bSdanielk1977 } 760dae2495bSdanielk1977 } {} 761dae2495bSdanielk1977 do_test pragma-8.2.7 { 762dae2495bSdanielk1977 execsql { 763b92b70bbSdanielk1977 PRAGMA aux.user_version; 764dae2495bSdanielk1977 } 765dae2495bSdanielk1977 } {3} 766dae2495bSdanielk1977 do_test pragma-8.2.8 { 767dae2495bSdanielk1977 execsql { 768b92b70bbSdanielk1977 PRAGMA main.user_version; 769dae2495bSdanielk1977 } 770dae2495bSdanielk1977 } {2} 771dae2495bSdanielk1977 772b92b70bbSdanielk1977 # Now check that a ROLLBACK resets the user-version if it has been modified 773dae2495bSdanielk1977 # within a transaction. 774dae2495bSdanielk1977 do_test pragma-8.2.9 { 775dae2495bSdanielk1977 execsql { 776dae2495bSdanielk1977 BEGIN; 777b92b70bbSdanielk1977 PRAGMA aux.user_version = 10; 778b92b70bbSdanielk1977 PRAGMA user_version = 11; 779dae2495bSdanielk1977 } 780dae2495bSdanielk1977 } {} 781dae2495bSdanielk1977 do_test pragma-8.2.10 { 782dae2495bSdanielk1977 execsql { 783b92b70bbSdanielk1977 PRAGMA aux.user_version; 784dae2495bSdanielk1977 } 785dae2495bSdanielk1977 } {10} 786dae2495bSdanielk1977 do_test pragma-8.2.11 { 787dae2495bSdanielk1977 execsql { 788b92b70bbSdanielk1977 PRAGMA main.user_version; 789dae2495bSdanielk1977 } 790dae2495bSdanielk1977 } {11} 791dae2495bSdanielk1977 do_test pragma-8.2.12 { 792dae2495bSdanielk1977 execsql { 793dae2495bSdanielk1977 ROLLBACK; 794b92b70bbSdanielk1977 PRAGMA aux.user_version; 795dae2495bSdanielk1977 } 796dae2495bSdanielk1977 } {3} 797dae2495bSdanielk1977 do_test pragma-8.2.13 { 798dae2495bSdanielk1977 execsql { 799b92b70bbSdanielk1977 PRAGMA main.user_version; 800dae2495bSdanielk1977 } 801dae2495bSdanielk1977 } {2} 8025a8f9374Sdanielk1977} 803dae2495bSdanielk1977 804b92b70bbSdanielk1977# Try a negative value for the user-version 805dae2495bSdanielk1977do_test pragma-8.2.14 { 806dae2495bSdanielk1977 execsql { 807b92b70bbSdanielk1977 PRAGMA user_version = -450; 808dae2495bSdanielk1977 } 809dae2495bSdanielk1977} {} 810dae2495bSdanielk1977do_test pragma-8.2.15 { 811dae2495bSdanielk1977 execsql { 812b92b70bbSdanielk1977 PRAGMA user_version; 813dae2495bSdanielk1977 } 814dae2495bSdanielk1977} {-450} 815d9c847dcSdanielk1977} ; # ifcapable schema_version 816d9c847dcSdanielk1977 817d19744f3Sdrh# Check to see if TEMP_STORE is memory or disk. Return strings 818d19744f3Sdrh# "memory" or "disk" as appropriate. 819d19744f3Sdrh# 820d19744f3Sdrhproc check_temp_store {} { 821d19744f3Sdrh db eval {CREATE TEMP TABLE IF NOT EXISTS a(b)} 822d19744f3Sdrh db eval {PRAGMA database_list} { 823d19744f3Sdrh if {$name=="temp"} { 824d19744f3Sdrh if {$file==""} { 825d19744f3Sdrh return "memory" 826d19744f3Sdrh } else { 827d19744f3Sdrh return "disk" 828d19744f3Sdrh } 829d19744f3Sdrh } 830d19744f3Sdrh } 831d19744f3Sdrh return "unknown" 832d19744f3Sdrh} 833d19744f3Sdrh 8349a09a3caStpoindex 8359a09a3caStpoindex# Test temp_store and temp_store_directory pragmas 8369a09a3caStpoindex# 837268283bcSdrhifcapable pager_pragmas { 8389a09a3caStpoindexdo_test pragma-9.1 { 8399a09a3caStpoindex db close 8409a09a3caStpoindex sqlite3 db test.db 8419a09a3caStpoindex execsql { 8429a09a3caStpoindex PRAGMA temp_store; 8439a09a3caStpoindex } 8449a09a3caStpoindex} {0} 845d19744f3Sdrhif {$TEMP_STORE<=1} { 846d19744f3Sdrh do_test pragma-9.1.1 { 847d19744f3Sdrh check_temp_store 848d19744f3Sdrh } {disk} 849d19744f3Sdrh} else { 850d19744f3Sdrh do_test pragma-9.1.1 { 851d19744f3Sdrh check_temp_store 852d19744f3Sdrh } {memory} 853d19744f3Sdrh} 854d19744f3Sdrh 8559a09a3caStpoindexdo_test pragma-9.2 { 856d19744f3Sdrh db close 857d19744f3Sdrh sqlite3 db test.db 8589a09a3caStpoindex execsql { 8599a09a3caStpoindex PRAGMA temp_store=file; 8609a09a3caStpoindex PRAGMA temp_store; 8619a09a3caStpoindex } 8629a09a3caStpoindex} {1} 863d19744f3Sdrhif {$TEMP_STORE==3} { 864d19744f3Sdrh # When TEMP_STORE is 3, always use memory regardless of pragma settings. 865d19744f3Sdrh do_test pragma-9.2.1 { 866d19744f3Sdrh check_temp_store 867d19744f3Sdrh } {memory} 868d19744f3Sdrh} else { 869d19744f3Sdrh do_test pragma-9.2.1 { 870d19744f3Sdrh check_temp_store 871d19744f3Sdrh } {disk} 872d19744f3Sdrh} 873d19744f3Sdrh 8749a09a3caStpoindexdo_test pragma-9.3 { 875d19744f3Sdrh db close 876d19744f3Sdrh sqlite3 db test.db 8779a09a3caStpoindex execsql { 8789a09a3caStpoindex PRAGMA temp_store=memory; 8799a09a3caStpoindex PRAGMA temp_store; 8809a09a3caStpoindex } 8819a09a3caStpoindex} {2} 882d19744f3Sdrhif {$TEMP_STORE==0} { 883d19744f3Sdrh # When TEMP_STORE is 0, always use the disk regardless of pragma settings. 884d19744f3Sdrh do_test pragma-9.3.1 { 885d19744f3Sdrh check_temp_store 886d19744f3Sdrh } {disk} 887d19744f3Sdrh} else { 888d19744f3Sdrh do_test pragma-9.3.1 { 889d19744f3Sdrh check_temp_store 890d19744f3Sdrh } {memory} 891d19744f3Sdrh} 892d19744f3Sdrh 8939a09a3caStpoindexdo_test pragma-9.4 { 8949a09a3caStpoindex execsql { 8959a09a3caStpoindex PRAGMA temp_store_directory; 8969a09a3caStpoindex } 8979a09a3caStpoindex} {} 8989a09a3caStpoindexdo_test pragma-9.5 { 899268283bcSdrh set pwd [string map {' ''} [pwd]] 900268283bcSdrh execsql " 901268283bcSdrh PRAGMA temp_store_directory='$pwd'; 9029a09a3caStpoindex " 9039a09a3caStpoindex} {} 9049a09a3caStpoindexdo_test pragma-9.6 { 9059a09a3caStpoindex execsql { 9069a09a3caStpoindex PRAGMA temp_store_directory; 9079a09a3caStpoindex } 9081941a3e8Sdrh} [list [pwd]] 9099a09a3caStpoindexdo_test pragma-9.7 { 910268283bcSdrh catchsql { 9119a09a3caStpoindex PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR'; 9129a09a3caStpoindex } 913268283bcSdrh} {1 {not a writable directory}} 9149a09a3caStpoindexdo_test pragma-9.8 { 9159a09a3caStpoindex execsql { 9169a09a3caStpoindex PRAGMA temp_store_directory=''; 9179a09a3caStpoindex } 9189a09a3caStpoindex} {} 9191e9daa6aSdrhif {![info exists TEMP_STORE] || $TEMP_STORE<=1} { 92053c0f748Sdanielk1977 ifcapable tempdb { 9219a09a3caStpoindex do_test pragma-9.9 { 9229a09a3caStpoindex execsql { 9239a09a3caStpoindex PRAGMA temp_store_directory; 9249a09a3caStpoindex PRAGMA temp_store=FILE; 9259a09a3caStpoindex CREATE TEMP TABLE temp_store_directory_test(a integer); 9269a09a3caStpoindex INSERT INTO temp_store_directory_test values (2); 9279a09a3caStpoindex SELECT * FROM temp_store_directory_test; 9289a09a3caStpoindex } 9299a09a3caStpoindex } {2} 9309a09a3caStpoindex do_test pragma-9.10 { 931268283bcSdrh catchsql " 932268283bcSdrh PRAGMA temp_store_directory='$pwd'; 9339a09a3caStpoindex SELECT * FROM temp_store_directory_test; 9349a09a3caStpoindex " 935268283bcSdrh } {1 {no such table: temp_store_directory_test}} 9361e9daa6aSdrh } 9371e9daa6aSdrh} 93895b289b6Sdanielk1977do_test pragma-9.11 { 93995b289b6Sdanielk1977 execsql { 94095b289b6Sdanielk1977 PRAGMA temp_store = 0; 94195b289b6Sdanielk1977 PRAGMA temp_store; 94295b289b6Sdanielk1977 } 94395b289b6Sdanielk1977} {0} 94495b289b6Sdanielk1977do_test pragma-9.12 { 94595b289b6Sdanielk1977 execsql { 94695b289b6Sdanielk1977 PRAGMA temp_store = 1; 94795b289b6Sdanielk1977 PRAGMA temp_store; 94895b289b6Sdanielk1977 } 94995b289b6Sdanielk1977} {1} 95095b289b6Sdanielk1977do_test pragma-9.13 { 95195b289b6Sdanielk1977 execsql { 95295b289b6Sdanielk1977 PRAGMA temp_store = 2; 95395b289b6Sdanielk1977 PRAGMA temp_store; 95495b289b6Sdanielk1977 } 95595b289b6Sdanielk1977} {2} 95695b289b6Sdanielk1977do_test pragma-9.14 { 95795b289b6Sdanielk1977 execsql { 95895b289b6Sdanielk1977 PRAGMA temp_store = 3; 95995b289b6Sdanielk1977 PRAGMA temp_store; 96095b289b6Sdanielk1977 } 96195b289b6Sdanielk1977} {0} 96295b289b6Sdanielk1977breakpoint 96395b289b6Sdanielk1977do_test pragma-9.15 { 96495b289b6Sdanielk1977 catchsql { 96595b289b6Sdanielk1977 BEGIN EXCLUSIVE; 96695b289b6Sdanielk1977 CREATE TEMP TABLE temp_table(t); 96795b289b6Sdanielk1977 INSERT INTO temp_table VALUES('valuable data'); 96895b289b6Sdanielk1977 PRAGMA temp_store = 1; 96995b289b6Sdanielk1977 } 97095b289b6Sdanielk1977} {1 {temporary storage cannot be changed from within a transaction}} 97195b289b6Sdanielk1977do_test pragma-9.16 { 97295b289b6Sdanielk1977 execsql { 97395b289b6Sdanielk1977 SELECT * FROM temp_table; 97495b289b6Sdanielk1977 COMMIT; 97595b289b6Sdanielk1977 } 97695b289b6Sdanielk1977} {{valuable data}} 977268283bcSdrh} ;# ifcapable pager_pragmas 9789a09a3caStpoindex 979cc6bd383Sdanielk1977ifcapable trigger { 980cc6bd383Sdanielk1977 981cc6bd383Sdanielk1977do_test pragma-10.0 { 982cc6bd383Sdanielk1977 catchsql { 983cc6bd383Sdanielk1977 DROP TABLE main.t1; 984cc6bd383Sdanielk1977 } 985cc6bd383Sdanielk1977 execsql { 986cc6bd383Sdanielk1977 PRAGMA count_changes = 1; 987cc6bd383Sdanielk1977 988cc6bd383Sdanielk1977 CREATE TABLE t1(a PRIMARY KEY); 989cc6bd383Sdanielk1977 CREATE TABLE t1_mirror(a); 990cc6bd383Sdanielk1977 CREATE TABLE t1_mirror2(a); 991cc6bd383Sdanielk1977 CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN 992cc6bd383Sdanielk1977 INSERT INTO t1_mirror VALUES(new.a); 993cc6bd383Sdanielk1977 END; 994cc6bd383Sdanielk1977 CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN 995cc6bd383Sdanielk1977 INSERT INTO t1_mirror2 VALUES(new.a); 996cc6bd383Sdanielk1977 END; 997cc6bd383Sdanielk1977 CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN 998cc6bd383Sdanielk1977 UPDATE t1_mirror SET a = new.a WHERE a = old.a; 999cc6bd383Sdanielk1977 END; 1000cc6bd383Sdanielk1977 CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN 1001cc6bd383Sdanielk1977 UPDATE t1_mirror2 SET a = new.a WHERE a = old.a; 1002cc6bd383Sdanielk1977 END; 1003cc6bd383Sdanielk1977 CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN 1004cc6bd383Sdanielk1977 DELETE FROM t1_mirror WHERE a = old.a; 1005cc6bd383Sdanielk1977 END; 1006cc6bd383Sdanielk1977 CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN 1007cc6bd383Sdanielk1977 DELETE FROM t1_mirror2 WHERE a = old.a; 1008cc6bd383Sdanielk1977 END; 1009cc6bd383Sdanielk1977 } 1010cc6bd383Sdanielk1977} {} 1011cc6bd383Sdanielk1977 1012cc6bd383Sdanielk1977do_test pragma-10.1 { 1013cc6bd383Sdanielk1977 execsql { 1014cc6bd383Sdanielk1977 INSERT INTO t1 VALUES(randstr(10,10)); 1015cc6bd383Sdanielk1977 } 1016cc6bd383Sdanielk1977} {1} 1017cc6bd383Sdanielk1977do_test pragma-10.2 { 1018cc6bd383Sdanielk1977 execsql { 1019cc6bd383Sdanielk1977 UPDATE t1 SET a = randstr(10,10); 1020cc6bd383Sdanielk1977 } 1021cc6bd383Sdanielk1977} {1} 1022cc6bd383Sdanielk1977do_test pragma-10.3 { 1023cc6bd383Sdanielk1977 execsql { 1024cc6bd383Sdanielk1977 DELETE FROM t1; 1025cc6bd383Sdanielk1977 } 1026cc6bd383Sdanielk1977} {1} 1027cc6bd383Sdanielk1977 1028cc6bd383Sdanielk1977} ;# ifcapable trigger 1029cc6bd383Sdanielk1977 103048af65aeSdanielk1977ifcapable schema_pragmas { 103148af65aeSdanielk1977 do_test pragma-11.1 { 103248af65aeSdanielk1977 execsql2 { 103348af65aeSdanielk1977 pragma collation_list; 103448af65aeSdanielk1977 } 10359b5adfa2Sdrh } {seq 0 name NOCASE seq 1 name RTRIM seq 2 name BINARY} 103648af65aeSdanielk1977 do_test pragma-11.2 { 103748af65aeSdanielk1977 db collate New_Collation blah... 103848af65aeSdanielk1977 execsql { 103948af65aeSdanielk1977 pragma collation_list; 104048af65aeSdanielk1977 } 10419b5adfa2Sdrh } {0 New_Collation 1 NOCASE 2 RTRIM 3 BINARY} 104248af65aeSdanielk1977} 104348af65aeSdanielk1977 1044ddfb2f03Sdanielk1977ifcapable schema_pragmas&&tempdb { 1045ddfb2f03Sdanielk1977 do_test pragma-12.1 { 1046ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1047ddfb2f03Sdanielk1977 execsql { 1048ddfb2f03Sdanielk1977 PRAGMA temp.table_info('abc'); 1049ddfb2f03Sdanielk1977 } db2 1050ddfb2f03Sdanielk1977 } {} 1051ddfb2f03Sdanielk1977 db2 close 1052ddfb2f03Sdanielk1977 1053ddfb2f03Sdanielk1977 do_test pragma-12.2 { 1054ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1055ddfb2f03Sdanielk1977 execsql { 1056ddfb2f03Sdanielk1977 PRAGMA temp.default_cache_size = 200; 1057ddfb2f03Sdanielk1977 PRAGMA temp.default_cache_size; 1058ddfb2f03Sdanielk1977 } db2 1059ddfb2f03Sdanielk1977 } {200} 1060ddfb2f03Sdanielk1977 db2 close 1061ddfb2f03Sdanielk1977 1062ddfb2f03Sdanielk1977 do_test pragma-12.3 { 1063ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1064ddfb2f03Sdanielk1977 execsql { 1065ddfb2f03Sdanielk1977 PRAGMA temp.cache_size = 400; 1066ddfb2f03Sdanielk1977 PRAGMA temp.cache_size; 1067ddfb2f03Sdanielk1977 } db2 1068ddfb2f03Sdanielk1977 } {400} 1069ddfb2f03Sdanielk1977 db2 close 1070ddfb2f03Sdanielk1977} 1071ddfb2f03Sdanielk1977 10724b2688abSdanielk1977ifcapable bloblit { 10734b2688abSdanielk1977 107405a82983Sdrhdo_test pragma-13.1 { 107505a82983Sdrh execsql { 107605a82983Sdrh DROP TABLE IF EXISTS t4; 107705a82983Sdrh PRAGMA vdbe_trace=on; 107805a82983Sdrh PRAGMA vdbe_listing=on; 107905a82983Sdrh PRAGMA sql_trace=on; 108005a82983Sdrh CREATE TABLE t4(a INTEGER PRIMARY KEY,b); 108105a82983Sdrh INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789'); 108205a82983Sdrh INSERT INTO t4(b) VALUES(randstr(30,30)); 108305a82983Sdrh INSERT INTO t4(b) VALUES(1.23456); 108405a82983Sdrh INSERT INTO t4(b) VALUES(NULL); 108505a82983Sdrh INSERT INTO t4(b) VALUES(0); 108605a82983Sdrh INSERT INTO t4(b) SELECT b||b||b||b FROM t4; 108705a82983Sdrh SELECT * FROM t4; 108805a82983Sdrh } 108905a82983Sdrh execsql { 109005a82983Sdrh PRAGMA vdbe_trace=off; 109105a82983Sdrh PRAGMA vdbe_listing=off; 109205a82983Sdrh PRAGMA sql_trace=off; 109305a82983Sdrh } 109405a82983Sdrh} {} 109505a82983Sdrh 10964b2688abSdanielk1977} ;# ifcapable bloblit 10974b2688abSdanielk1977 10985558a8a6Sdanielk1977# Reset the sqlite3_temp_directory variable for the next run of tests: 10995558a8a6Sdanielk1977sqlite3 dbX :memory: 11005558a8a6Sdanielk1977dbX eval {PRAGMA temp_store_directory = ""} 11015558a8a6Sdanielk1977dbX close 11025558a8a6Sdanielk1977 1103cd61c281Sdrhfinish_test 1104