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*e3d559adSdrh# $Id: pragma.test,v 1.51 2007/01/27 14:26:07 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 49c7b4a44cSdanielk1977ifcapable pager_pragmas { 50cd61c281Sdrhdo_test pragma-1.1 { 51cd61c281Sdrh execsql { 52cd61c281Sdrh PRAGMA cache_size; 53cd61c281Sdrh PRAGMA default_cache_size; 54cd61c281Sdrh PRAGMA synchronous; 55cd61c281Sdrh } 5691cf71b0Sdanielk1977} {2000 2000 2} 57cd61c281Sdrhdo_test pragma-1.2 { 58cd61c281Sdrh execsql { 59eb43e5c7Sdrh PRAGMA synchronous=OFF; 60cd61c281Sdrh PRAGMA cache_size=1234; 61cd61c281Sdrh PRAGMA cache_size; 62cd61c281Sdrh PRAGMA default_cache_size; 63cd61c281Sdrh PRAGMA synchronous; 64cd61c281Sdrh } 65eb43e5c7Sdrh} {1234 2000 0} 66cd61c281Sdrhdo_test pragma-1.3 { 67cd61c281Sdrh db close 68ef4ac8f9Sdrh sqlite3 db test.db 69cd61c281Sdrh execsql { 70cd61c281Sdrh PRAGMA cache_size; 71cd61c281Sdrh PRAGMA default_cache_size; 72cd61c281Sdrh PRAGMA synchronous; 73cd61c281Sdrh } 7491cf71b0Sdanielk1977} {2000 2000 2} 75cd61c281Sdrhdo_test pragma-1.4 { 76cd61c281Sdrh execsql { 77cd61c281Sdrh PRAGMA synchronous=OFF; 78cd61c281Sdrh PRAGMA cache_size; 79cd61c281Sdrh PRAGMA default_cache_size; 80cd61c281Sdrh PRAGMA synchronous; 81cd61c281Sdrh } 8291cf71b0Sdanielk1977} {2000 2000 0} 83cd61c281Sdrhdo_test pragma-1.5 { 84cd61c281Sdrh execsql { 85cd61c281Sdrh PRAGMA cache_size=4321; 86cd61c281Sdrh PRAGMA cache_size; 87cd61c281Sdrh PRAGMA default_cache_size; 88cd61c281Sdrh PRAGMA synchronous; 89cd61c281Sdrh } 9091cf71b0Sdanielk1977} {4321 2000 0} 91cd61c281Sdrhdo_test pragma-1.6 { 92cd61c281Sdrh execsql { 93cd61c281Sdrh PRAGMA synchronous=ON; 94cd61c281Sdrh PRAGMA cache_size; 95cd61c281Sdrh PRAGMA default_cache_size; 96cd61c281Sdrh PRAGMA synchronous; 97cd61c281Sdrh } 9891cf71b0Sdanielk1977} {4321 2000 1} 99cd61c281Sdrhdo_test pragma-1.7 { 100cd61c281Sdrh db close 101ef4ac8f9Sdrh sqlite3 db test.db 102cd61c281Sdrh execsql { 103cd61c281Sdrh PRAGMA cache_size; 104cd61c281Sdrh PRAGMA default_cache_size; 105cd61c281Sdrh PRAGMA synchronous; 106cd61c281Sdrh } 10791cf71b0Sdanielk1977} {2000 2000 2} 108cd61c281Sdrhdo_test pragma-1.8 { 109cd61c281Sdrh execsql { 110cd61c281Sdrh PRAGMA default_cache_size=123; 111cd61c281Sdrh PRAGMA cache_size; 112cd61c281Sdrh PRAGMA default_cache_size; 113cd61c281Sdrh PRAGMA synchronous; 114cd61c281Sdrh } 11591cf71b0Sdanielk1977} {123 123 2} 116802d69a7Sdrhdo_test pragma-1.9.1 { 117cd61c281Sdrh db close 118dddca286Sdrh sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db] 119cd61c281Sdrh execsql { 120cd61c281Sdrh PRAGMA cache_size; 121cd61c281Sdrh PRAGMA default_cache_size; 122cd61c281Sdrh PRAGMA synchronous; 123cd61c281Sdrh } 12491cf71b0Sdanielk1977} {123 123 2} 125802d69a7Sdrhifcapable vacuum { 126802d69a7Sdrh do_test pragma-1.9.2 { 127802d69a7Sdrh execsql { 128802d69a7Sdrh VACUUM; 129802d69a7Sdrh PRAGMA cache_size; 130802d69a7Sdrh PRAGMA default_cache_size; 131802d69a7Sdrh PRAGMA synchronous; 132802d69a7Sdrh } 133802d69a7Sdrh } {123 123 2} 134802d69a7Sdrh} 13591cf71b0Sdanielk1977do_test pragma-1.10 { 1365a38705eSdrh execsql { 1374303feedSdrh PRAGMA synchronous=NORMAL; 1384303feedSdrh PRAGMA cache_size; 1394303feedSdrh PRAGMA default_cache_size; 1404303feedSdrh PRAGMA synchronous; 1414303feedSdrh } 14291cf71b0Sdanielk1977} {123 123 1} 14391cf71b0Sdanielk1977do_test pragma-1.11 { 1444303feedSdrh execsql { 1454303feedSdrh PRAGMA synchronous=FULL; 1464303feedSdrh PRAGMA cache_size; 1474303feedSdrh PRAGMA default_cache_size; 1484303feedSdrh PRAGMA synchronous; 1494303feedSdrh } 15091cf71b0Sdanielk1977} {123 123 2} 15191cf71b0Sdanielk1977do_test pragma-1.12 { 1524303feedSdrh db close 153dddca286Sdrh sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db] 1544303feedSdrh execsql { 1554303feedSdrh PRAGMA cache_size; 1564303feedSdrh PRAGMA default_cache_size; 1574303feedSdrh PRAGMA synchronous; 1584303feedSdrh } 15991cf71b0Sdanielk1977} {123 123 2} 16091cf71b0Sdanielk1977 1615260f7e9Sdrh# Make sure the pragma handler understands numeric values in addition 1625260f7e9Sdrh# to keywords like "off" and "full". 1635260f7e9Sdrh# 1645260f7e9Sdrhdo_test pragma-1.13 { 1655260f7e9Sdrh execsql { 1665260f7e9Sdrh PRAGMA synchronous=0; 1675260f7e9Sdrh PRAGMA synchronous; 1685260f7e9Sdrh } 1695260f7e9Sdrh} {0} 1705260f7e9Sdrhdo_test pragma-1.14 { 1715260f7e9Sdrh execsql { 1725260f7e9Sdrh PRAGMA synchronous=2; 1735260f7e9Sdrh PRAGMA synchronous; 1745260f7e9Sdrh } 1755260f7e9Sdrh} {2} 176c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 1775260f7e9Sdrh 1785260f7e9Sdrh# Test turning "flag" pragmas on and off. 1795260f7e9Sdrh# 1805260f7e9Sdrhdo_test pragma-1.15 { 1815260f7e9Sdrh execsql { 1825260f7e9Sdrh PRAGMA vdbe_listing=YES; 1835260f7e9Sdrh PRAGMA vdbe_listing; 1845260f7e9Sdrh } 1855260f7e9Sdrh} {1} 1865260f7e9Sdrhdo_test pragma-1.16 { 1875260f7e9Sdrh execsql { 1885260f7e9Sdrh PRAGMA vdbe_listing=NO; 1895260f7e9Sdrh PRAGMA vdbe_listing; 1905260f7e9Sdrh } 1915260f7e9Sdrh} {0} 1925260f7e9Sdrhdo_test pragma-1.17 { 1935260f7e9Sdrh execsql { 1945260f7e9Sdrh PRAGMA parser_trace=ON; 1955260f7e9Sdrh PRAGMA parser_trace=OFF; 1965260f7e9Sdrh } 1975260f7e9Sdrh} {} 1985260f7e9Sdrhdo_test pragma-1.18 { 1995260f7e9Sdrh execsql { 2005260f7e9Sdrh PRAGMA bogus = -1234; -- Parsing of negative values 2015260f7e9Sdrh } 2025260f7e9Sdrh} {} 2035260f7e9Sdrh 20491cf71b0Sdanielk1977# Test modifying the safety_level of an attached database. 20591cf71b0Sdanielk1977do_test pragma-2.1 { 20691cf71b0Sdanielk1977 file delete -force test2.db 20791cf71b0Sdanielk1977 file delete -force test2.db-journal 2084303feedSdrh execsql { 20991cf71b0Sdanielk1977 ATTACH 'test2.db' AS aux; 2104303feedSdrh } 21191cf71b0Sdanielk1977} {} 212c7b4a44cSdanielk1977ifcapable pager_pragmas { 21391cf71b0Sdanielk1977do_test pragma-2.2 { 2144303feedSdrh execsql { 21591cf71b0Sdanielk1977 pragma aux.synchronous; 2164303feedSdrh } 21791cf71b0Sdanielk1977} {2} 21891cf71b0Sdanielk1977do_test pragma-2.3 { 21991cf71b0Sdanielk1977 execsql { 22091cf71b0Sdanielk1977 pragma aux.synchronous = OFF; 22191cf71b0Sdanielk1977 pragma aux.synchronous; 22291cf71b0Sdanielk1977 pragma synchronous; 22391cf71b0Sdanielk1977 } 22491cf71b0Sdanielk1977} {0 2} 22591cf71b0Sdanielk1977do_test pragma-2.4 { 22691cf71b0Sdanielk1977 execsql { 22791cf71b0Sdanielk1977 pragma aux.synchronous = ON; 22891cf71b0Sdanielk1977 pragma synchronous; 22991cf71b0Sdanielk1977 pragma aux.synchronous; 23091cf71b0Sdanielk1977 } 23191cf71b0Sdanielk1977} {2 1} 232c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 2334303feedSdrh 234ed717fe3Sdrh# Construct a corrupted index and make sure the integrity_check 235ed717fe3Sdrh# pragma finds it. 236ed717fe3Sdrh# 23725d6543dSdrh# These tests won't work if the database is encrypted 23825d6543dSdrh# 239ed717fe3Sdrhdo_test pragma-3.1 { 240ed717fe3Sdrh execsql { 241ed717fe3Sdrh BEGIN; 242ed717fe3Sdrh CREATE TABLE t2(a,b,c); 243ed717fe3Sdrh CREATE INDEX i2 ON t2(a); 244ed717fe3Sdrh INSERT INTO t2 VALUES(11,2,3); 245ed717fe3Sdrh INSERT INTO t2 VALUES(22,3,4); 246ed717fe3Sdrh COMMIT; 247ed717fe3Sdrh SELECT rowid, * from t2; 248ed717fe3Sdrh } 249ed717fe3Sdrh} {1 11 2 3 2 22 3 4} 25040e016e4Sdrhif {![sqlite3 -has-codec] && $sqlite_options(integrityck)} { 251ed717fe3Sdrh do_test pragma-3.2 { 252ed717fe3Sdrh set rootpage [execsql {SELECT rootpage FROM sqlite_master WHERE name='i2'}] 25396fc5fe6Sdanielk1977 set db [btree_open test.db 100 0] 254ed717fe3Sdrh btree_begin_transaction $db 255ed717fe3Sdrh set c [btree_cursor $db $rootpage 1] 256ed717fe3Sdrh btree_first $c 257ed717fe3Sdrh btree_delete $c 258ed717fe3Sdrh btree_commit $db 259ed717fe3Sdrh btree_close $db 260ed717fe3Sdrh execsql {PRAGMA integrity_check} 2614be295beSdrh } {{rowid 1 missing from index i2} {wrong # of entries in index i2}} 26291cf71b0Sdanielk1977 do_test pragma-3.3 { 2631dcdbc06Sdrh execsql {PRAGMA integrity_check=1} 2641dcdbc06Sdrh } {{rowid 1 missing from index i2}} 2651dcdbc06Sdrh do_test pragma-3.4 { 26691cf71b0Sdanielk1977 execsql { 2671dcdbc06Sdrh ATTACH DATABASE 'test.db' AS t2; 2681dcdbc06Sdrh PRAGMA integrity_check 26991cf71b0Sdanielk1977 } 2701dcdbc06Sdrh } {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {wrong # of entries in index i2}} 2711dcdbc06Sdrh do_test pragma-3.5 { 2721dcdbc06Sdrh execsql { 2731dcdbc06Sdrh PRAGMA integrity_check=3 2741dcdbc06Sdrh } 2751dcdbc06Sdrh } {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2}} 2761dcdbc06Sdrh do_test pragma-3.6 { 2771dcdbc06Sdrh execsql { 2781dcdbc06Sdrh PRAGMA integrity_check=xyz 2791dcdbc06Sdrh } 2801dcdbc06Sdrh } {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {wrong # of entries in index i2}} 2811dcdbc06Sdrh do_test pragma-3.7 { 2821dcdbc06Sdrh execsql { 2831dcdbc06Sdrh PRAGMA integrity_check=0 2841dcdbc06Sdrh } 2851dcdbc06Sdrh } {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {wrong # of entries in index i2}} 2861dcdbc06Sdrh 2871dcdbc06Sdrh # Add additional corruption by appending unused pages to the end of 2881dcdbc06Sdrh # the database file testerr.db 2891dcdbc06Sdrh # 2901dcdbc06Sdrh do_test pragma-3.8 { 2911dcdbc06Sdrh execsql {DETACH t2} 2921dcdbc06Sdrh file delete -force testerr.db testerr.db-journal 293*e3d559adSdrh set out [open testerr.db w] 294*e3d559adSdrh fconfigure $out -translation binary 295*e3d559adSdrh set in [open test.db r] 296*e3d559adSdrh fconfigure $in -translation binary 2971dcdbc06Sdrh puts -nonewline $out [read $in] 2981dcdbc06Sdrh seek $in 0 2991dcdbc06Sdrh puts -nonewline $out [read $in] 3001dcdbc06Sdrh close $in 3011dcdbc06Sdrh close $out 3021dcdbc06Sdrh execsql {REINDEX t2} 3031dcdbc06Sdrh execsql {PRAGMA integrity_check} 3041dcdbc06Sdrh } {ok} 3051dcdbc06Sdrh do_test pragma-3.9 { 3061dcdbc06Sdrh execsql { 3071dcdbc06Sdrh ATTACH 'testerr.db' AS t2; 3081dcdbc06Sdrh PRAGMA integrity_check 3091dcdbc06Sdrh } 3101dcdbc06Sdrh } {{*** in database t2 *** 3111dcdbc06SdrhPage 4 is never used 3121dcdbc06SdrhPage 5 is never used 3131dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2}} 3141dcdbc06Sdrh do_test pragma-3.10 { 3151dcdbc06Sdrh execsql { 3161dcdbc06Sdrh PRAGMA integrity_check=1 3171dcdbc06Sdrh } 3181dcdbc06Sdrh } {{*** in database t2 *** 3191dcdbc06SdrhPage 4 is never used}} 3201dcdbc06Sdrh do_test pragma-3.11 { 3211dcdbc06Sdrh execsql { 3221dcdbc06Sdrh PRAGMA integrity_check=5 3231dcdbc06Sdrh } 3241dcdbc06Sdrh } {{*** in database t2 *** 3251dcdbc06SdrhPage 4 is never used 3261dcdbc06SdrhPage 5 is never used 3271dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2}} 3281dcdbc06Sdrh do_test pragma-3.12 { 3291dcdbc06Sdrh execsql { 3301dcdbc06Sdrh PRAGMA integrity_check=4 3311dcdbc06Sdrh } 3321dcdbc06Sdrh } {{*** in database t2 *** 3331dcdbc06SdrhPage 4 is never used 3341dcdbc06SdrhPage 5 is never used 3351dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}} 3361dcdbc06Sdrh do_test pragma-3.13 { 3371dcdbc06Sdrh execsql { 3381dcdbc06Sdrh PRAGMA integrity_check=3 3391dcdbc06Sdrh } 3401dcdbc06Sdrh } {{*** in database t2 *** 3411dcdbc06SdrhPage 4 is never used 3421dcdbc06SdrhPage 5 is never used 3431dcdbc06SdrhPage 6 is never used}} 3441dcdbc06Sdrh do_test pragma-3.14 { 3451dcdbc06Sdrh execsql { 3461dcdbc06Sdrh PRAGMA integrity_check(2) 3471dcdbc06Sdrh } 3481dcdbc06Sdrh } {{*** in database t2 *** 3491dcdbc06SdrhPage 4 is never used 3501dcdbc06SdrhPage 5 is never used}} 3511dcdbc06Sdrh do_test pragma-3.15 { 3521dcdbc06Sdrh execsql { 3531dcdbc06Sdrh ATTACH 'testerr.db' AS t3; 3541dcdbc06Sdrh PRAGMA integrity_check 3551dcdbc06Sdrh } 3561dcdbc06Sdrh } {{*** in database t2 *** 3571dcdbc06SdrhPage 4 is never used 3581dcdbc06SdrhPage 5 is never used 3591dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2} {*** in database t3 *** 3601dcdbc06SdrhPage 4 is never used 3611dcdbc06SdrhPage 5 is never used 3621dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2}} 3631dcdbc06Sdrh do_test pragma-3.16 { 3641dcdbc06Sdrh execsql { 3651dcdbc06Sdrh PRAGMA integrity_check(9) 3661dcdbc06Sdrh } 3671dcdbc06Sdrh } {{*** in database t2 *** 3681dcdbc06SdrhPage 4 is never used 3691dcdbc06SdrhPage 5 is never used 3701dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2} {*** in database t3 *** 3711dcdbc06SdrhPage 4 is never used 3721dcdbc06SdrhPage 5 is never used 3731dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}} 3741dcdbc06Sdrh do_test pragma-3.17 { 3751dcdbc06Sdrh execsql { 3761dcdbc06Sdrh PRAGMA integrity_check=7 3771dcdbc06Sdrh } 3781dcdbc06Sdrh } {{*** in database t2 *** 3791dcdbc06SdrhPage 4 is never used 3801dcdbc06SdrhPage 5 is never used 3811dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2} {*** in database t3 *** 3821dcdbc06SdrhPage 4 is never used 3831dcdbc06SdrhPage 5 is never used}} 3841dcdbc06Sdrh do_test pragma-3.18 { 3851dcdbc06Sdrh execsql { 3861dcdbc06Sdrh PRAGMA integrity_check=4 3871dcdbc06Sdrh } 3881dcdbc06Sdrh } {{*** in database t2 *** 3891dcdbc06SdrhPage 4 is never used 3901dcdbc06SdrhPage 5 is never used 3911dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}} 3921dcdbc06Sdrh} 3931dcdbc06Sdrhdo_test pragma-3.99 { 3941dcdbc06Sdrh catchsql {DETACH t3} 3951dcdbc06Sdrh catchsql {DETACH t2} 39690ddb123Sdrh file delete -force testerr.db testerr.db-journal 39705a6f4acSdrh catchsql {DROP INDEX i2} 3981dcdbc06Sdrh} {0 {}} 39991cf71b0Sdanielk1977 40091cf71b0Sdanielk1977# Test modifying the cache_size of an attached database. 401c7b4a44cSdanielk1977ifcapable pager_pragmas { 40291cf71b0Sdanielk1977do_test pragma-4.1 { 40391cf71b0Sdanielk1977 execsql { 40491cf71b0Sdanielk1977 pragma aux.cache_size; 40591cf71b0Sdanielk1977 pragma aux.default_cache_size; 40691cf71b0Sdanielk1977 } 40791cf71b0Sdanielk1977} {2000 2000} 4081bdd9b57Sdrhdo_test pragma-4.2 { 4091bdd9b57Sdrh execsql { 41091cf71b0Sdanielk1977 pragma aux.cache_size = 50; 41191cf71b0Sdanielk1977 pragma aux.cache_size; 41291cf71b0Sdanielk1977 pragma aux.default_cache_size; 4131bdd9b57Sdrh } 41491cf71b0Sdanielk1977} {50 2000} 4151bdd9b57Sdrhdo_test pragma-4.3 { 4161bdd9b57Sdrh execsql { 41791cf71b0Sdanielk1977 pragma aux.default_cache_size = 456; 41891cf71b0Sdanielk1977 pragma aux.cache_size; 41991cf71b0Sdanielk1977 pragma aux.default_cache_size; 4201bdd9b57Sdrh } 42191cf71b0Sdanielk1977} {456 456} 4221bdd9b57Sdrhdo_test pragma-4.4 { 4231bdd9b57Sdrh execsql { 42491cf71b0Sdanielk1977 pragma cache_size; 42591cf71b0Sdanielk1977 pragma default_cache_size; 4261bdd9b57Sdrh } 42791cf71b0Sdanielk1977} {123 123} 4281bdd9b57Sdrhdo_test pragma-4.5 { 4291bdd9b57Sdrh execsql { 43091cf71b0Sdanielk1977 DETACH aux; 43191cf71b0Sdanielk1977 ATTACH 'test3.db' AS aux; 43291cf71b0Sdanielk1977 pragma aux.cache_size; 43391cf71b0Sdanielk1977 pragma aux.default_cache_size; 4341bdd9b57Sdrh } 43591cf71b0Sdanielk1977} {2000 2000} 4361bdd9b57Sdrhdo_test pragma-4.6 { 4371bdd9b57Sdrh execsql { 43891cf71b0Sdanielk1977 DETACH aux; 43991cf71b0Sdanielk1977 ATTACH 'test2.db' AS aux; 44091cf71b0Sdanielk1977 pragma aux.cache_size; 44191cf71b0Sdanielk1977 pragma aux.default_cache_size; 4421bdd9b57Sdrh } 44391cf71b0Sdanielk1977} {456 456} 444c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 4451bdd9b57Sdrh 44691cf71b0Sdanielk1977# Test that modifying the sync-level in the middle of a transaction is 44791cf71b0Sdanielk1977# disallowed. 448c7b4a44cSdanielk1977ifcapable pager_pragmas { 44991cf71b0Sdanielk1977do_test pragma-5.0 { 4501bdd9b57Sdrh execsql { 45191cf71b0Sdanielk1977 pragma synchronous; 4521bdd9b57Sdrh } 45391cf71b0Sdanielk1977} {2} 45491cf71b0Sdanielk1977do_test pragma-5.1 { 4551bdd9b57Sdrh catchsql { 4561bdd9b57Sdrh BEGIN; 45791cf71b0Sdanielk1977 pragma synchronous = OFF; 4581bdd9b57Sdrh } 45991cf71b0Sdanielk1977} {1 {Safety level may not be changed inside a transaction}} 46091cf71b0Sdanielk1977do_test pragma-5.2 { 46191cf71b0Sdanielk1977 execsql { 46291cf71b0Sdanielk1977 pragma synchronous; 46391cf71b0Sdanielk1977 } 46491cf71b0Sdanielk1977} {2} 4655260f7e9Sdrhcatchsql {COMMIT;} 466c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 4675260f7e9Sdrh 4685260f7e9Sdrh# Test schema-query pragmas 4695260f7e9Sdrh# 47027188fb5Sdanielk1977ifcapable schema_pragmas { 47153c0f748Sdanielk1977ifcapable tempdb { 4725260f7e9Sdrh do_test pragma-6.1 { 473956bc92cSdrh set res {} 47440e016e4Sdrh execsql {SELECT * FROM sqlite_temp_master} 4755260f7e9Sdrh foreach {idx name file} [execsql {pragma database_list}] { 4765260f7e9Sdrh lappend res $idx $name 4775260f7e9Sdrh } 4785260f7e9Sdrh set res 479a71aa001Sdrh } {0 main 1 temp 2 aux} 48053c0f748Sdanielk1977} 4815260f7e9Sdrhdo_test pragma-6.2 { 4825260f7e9Sdrh execsql { 4835260f7e9Sdrh pragma table_info(t2) 4845260f7e9Sdrh } 485bfa8b102Sdrh} {0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0} 486736c7d4bSdrhdb nullvalue <<NULL>> 487417ec638Sdrhdo_test pragma-6.2.2 { 488417ec638Sdrh execsql { 489736c7d4bSdrh CREATE TABLE t5( 490736c7d4bSdrh a TEXT DEFAULT CURRENT_TIMESTAMP, 491736c7d4bSdrh b DEFAULT (5+3), 492736c7d4bSdrh c TEXT, 493736c7d4bSdrh d INTEGER DEFAULT NULL, 494736c7d4bSdrh e TEXT DEFAULT '' 495736c7d4bSdrh ); 496417ec638Sdrh PRAGMA table_info(t5); 497417ec638Sdrh } 498736c7d4bSdrh} {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} 499736c7d4bSdrhdb nullvalue {} 5006bf89570Sdrhifcapable {foreignkey} { 5015260f7e9Sdrh do_test pragma-6.3 { 5025260f7e9Sdrh execsql { 5035260f7e9Sdrh CREATE TABLE t3(a int references t2(b), b UNIQUE); 5045260f7e9Sdrh pragma foreign_key_list(t3); 5055260f7e9Sdrh } 5065260f7e9Sdrh } {0 0 t2 a b} 5075260f7e9Sdrh do_test pragma-6.4 { 5085260f7e9Sdrh execsql { 5095260f7e9Sdrh pragma index_list(t3); 5105260f7e9Sdrh } 5115260f7e9Sdrh } {0 sqlite_autoindex_t3_1 1} 5126bf89570Sdrh} 5136bf89570Sdrhifcapable {!foreignkey} { 5146bf89570Sdrh execsql {CREATE TABLE t3(a,b UNIQUE)} 5156bf89570Sdrh} 5165260f7e9Sdrhdo_test pragma-6.5 { 5175260f7e9Sdrh execsql { 5185260f7e9Sdrh CREATE INDEX t3i1 ON t3(a,b); 5195260f7e9Sdrh pragma index_info(t3i1); 5205260f7e9Sdrh } 5215260f7e9Sdrh} {0 0 a 1 1 b} 52227188fb5Sdanielk1977} ;# ifcapable schema_pragmas 5235260f7e9Sdrh# Miscellaneous tests 5245260f7e9Sdrh# 52527188fb5Sdanielk1977ifcapable schema_pragmas { 5265260f7e9Sdrhdo_test pragma-7.1 { 5275260f7e9Sdrh # Make sure a pragma knows to read the schema if it needs to 5285260f7e9Sdrh db close 5295260f7e9Sdrh sqlite3 db test.db 5305260f7e9Sdrh execsql { 5315260f7e9Sdrh pragma index_list(t3); 5325260f7e9Sdrh } 5335260f7e9Sdrh} {0 t3i1 0 1 sqlite_autoindex_t3_1 1} 53427188fb5Sdanielk1977} ;# ifcapable schema_pragmas 5356c62608fSdrhifcapable {utf16} { 5365260f7e9Sdrh do_test pragma-7.2 { 5375260f7e9Sdrh db close 5385260f7e9Sdrh sqlite3 db test.db 5395260f7e9Sdrh catchsql { 5405260f7e9Sdrh pragma encoding=bogus; 5415260f7e9Sdrh } 5425260f7e9Sdrh } {1 {unsupported encoding: bogus}} 5436c62608fSdrh} 54453c0f748Sdanielk1977ifcapable tempdb { 5455260f7e9Sdrh do_test pragma-7.3 { 5465260f7e9Sdrh db close 5475260f7e9Sdrh sqlite3 db test.db 5485260f7e9Sdrh execsql { 5495260f7e9Sdrh pragma lock_status; 5505260f7e9Sdrh } 5515260f7e9Sdrh } {main unlocked temp closed} 55253c0f748Sdanielk1977} else { 55353c0f748Sdanielk1977 do_test pragma-7.3 { 55453c0f748Sdanielk1977 db close 55553c0f748Sdanielk1977 sqlite3 db test.db 55653c0f748Sdanielk1977 execsql { 55753c0f748Sdanielk1977 pragma lock_status; 55853c0f748Sdanielk1977 } 55953c0f748Sdanielk1977 } {main unlocked} 56053c0f748Sdanielk1977} 5615260f7e9Sdrh 5625260f7e9Sdrh 563dae2495bSdanielk1977#---------------------------------------------------------------------- 564b92b70bbSdanielk1977# Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA 565b92b70bbSdanielk1977# user_version" statements. 566dae2495bSdanielk1977# 567b92b70bbSdanielk1977# pragma-8.1: PRAGMA schema_version 568b92b70bbSdanielk1977# pragma-8.2: PRAGMA user_version 569dae2495bSdanielk1977# 570dae2495bSdanielk1977 57111cf9fbcSdanielk1977ifcapable schema_version { 57211cf9fbcSdanielk1977 573b92b70bbSdanielk1977# First check that we can set the schema version and then retrieve the 574dae2495bSdanielk1977# same value. 575dae2495bSdanielk1977do_test pragma-8.1.1 { 576dae2495bSdanielk1977 execsql { 577b92b70bbSdanielk1977 PRAGMA schema_version = 105; 578dae2495bSdanielk1977 } 579dae2495bSdanielk1977} {} 580dae2495bSdanielk1977do_test pragma-8.1.2 { 58125403650Sdrh execsql2 { 582b92b70bbSdanielk1977 PRAGMA schema_version; 583dae2495bSdanielk1977 } 58425403650Sdrh} {schema_version 105} 585dae2495bSdanielk1977do_test pragma-8.1.3 { 586dae2495bSdanielk1977 execsql { 587b92b70bbSdanielk1977 PRAGMA schema_version = 106; 588dae2495bSdanielk1977 } 589dae2495bSdanielk1977} {} 590dae2495bSdanielk1977do_test pragma-8.1.4 { 591dae2495bSdanielk1977 execsql { 592b92b70bbSdanielk1977 PRAGMA schema_version; 593dae2495bSdanielk1977 } 594dae2495bSdanielk1977} 106 595dae2495bSdanielk1977 596b92b70bbSdanielk1977# Check that creating a table modifies the schema-version (this is really 597b92b70bbSdanielk1977# to verify that the value being read is in fact the schema version). 598dae2495bSdanielk1977do_test pragma-8.1.5 { 599dae2495bSdanielk1977 execsql { 600dae2495bSdanielk1977 CREATE TABLE t4(a, b, c); 601dae2495bSdanielk1977 INSERT INTO t4 VALUES(1, 2, 3); 602dae2495bSdanielk1977 SELECT * FROM t4; 603dae2495bSdanielk1977 } 604dae2495bSdanielk1977} {1 2 3} 605dae2495bSdanielk1977do_test pragma-8.1.6 { 606dae2495bSdanielk1977 execsql { 607b92b70bbSdanielk1977 PRAGMA schema_version; 608dae2495bSdanielk1977 } 609dae2495bSdanielk1977} 107 610dae2495bSdanielk1977 611dae2495bSdanielk1977# Now open a second connection to the database. Ensure that changing the 612b92b70bbSdanielk1977# schema-version using the first connection forces the second connection 613dae2495bSdanielk1977# to reload the schema. This has to be done using the C-API test functions, 614dae2495bSdanielk1977# because the TCL API accounts for SCHEMA_ERROR and retries the query. 615dae2495bSdanielk1977do_test pragma-8.1.7 { 616dddca286Sdrh sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] 617dae2495bSdanielk1977 execsql { 618dae2495bSdanielk1977 SELECT * FROM t4; 619dae2495bSdanielk1977 } db2 620dae2495bSdanielk1977} {1 2 3} 621dae2495bSdanielk1977do_test pragma-8.1.8 { 622dae2495bSdanielk1977 execsql { 623b92b70bbSdanielk1977 PRAGMA schema_version = 108; 624dae2495bSdanielk1977 } 625dae2495bSdanielk1977} {} 626dae2495bSdanielk1977do_test pragma-8.1.9 { 627dae2495bSdanielk1977 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY] 628dae2495bSdanielk1977 sqlite3_step $::STMT 629dae2495bSdanielk1977} SQLITE_ERROR 630dae2495bSdanielk1977do_test pragma-8.1.10 { 631dae2495bSdanielk1977 sqlite3_finalize $::STMT 632dae2495bSdanielk1977} SQLITE_SCHEMA 633dae2495bSdanielk1977 634b92b70bbSdanielk1977# Make sure the schema-version can be manipulated in an attached database. 635dae2495bSdanielk1977file delete -force test2.db 636dae2495bSdanielk1977file delete -force test2.db-journal 637dae2495bSdanielk1977do_test pragma-8.1.11 { 638dae2495bSdanielk1977 execsql { 639dae2495bSdanielk1977 ATTACH 'test2.db' AS aux; 640dae2495bSdanielk1977 CREATE TABLE aux.t1(a, b, c); 641b92b70bbSdanielk1977 PRAGMA aux.schema_version = 205; 642dae2495bSdanielk1977 } 643dae2495bSdanielk1977} {} 644dae2495bSdanielk1977do_test pragma-8.1.12 { 645dae2495bSdanielk1977 execsql { 646b92b70bbSdanielk1977 PRAGMA aux.schema_version; 647dae2495bSdanielk1977 } 648dae2495bSdanielk1977} 205 649dae2495bSdanielk1977do_test pragma-8.1.13 { 650dae2495bSdanielk1977 execsql { 651b92b70bbSdanielk1977 PRAGMA schema_version; 652dae2495bSdanielk1977 } 653dae2495bSdanielk1977} 108 654dae2495bSdanielk1977 655b92b70bbSdanielk1977# And check that modifying the schema-version in an attached database 656dae2495bSdanielk1977# forces the second connection to reload the schema. 657dae2495bSdanielk1977do_test pragma-8.1.14 { 658dddca286Sdrh sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] 659dae2495bSdanielk1977 execsql { 660dae2495bSdanielk1977 ATTACH 'test2.db' AS aux; 661dae2495bSdanielk1977 SELECT * FROM aux.t1; 662dae2495bSdanielk1977 } db2 663dae2495bSdanielk1977} {} 664dae2495bSdanielk1977do_test pragma-8.1.15 { 665dae2495bSdanielk1977 execsql { 666b92b70bbSdanielk1977 PRAGMA aux.schema_version = 206; 667dae2495bSdanielk1977 } 668dae2495bSdanielk1977} {} 669dae2495bSdanielk1977do_test pragma-8.1.16 { 670dae2495bSdanielk1977 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY] 671dae2495bSdanielk1977 sqlite3_step $::STMT 672dae2495bSdanielk1977} SQLITE_ERROR 673dae2495bSdanielk1977do_test pragma-8.1.17 { 674dae2495bSdanielk1977 sqlite3_finalize $::STMT 675dae2495bSdanielk1977} SQLITE_SCHEMA 676dae2495bSdanielk1977do_test pragma-8.1.18 { 677dae2495bSdanielk1977 db2 close 678dae2495bSdanielk1977} {} 679dae2495bSdanielk1977 680b92b70bbSdanielk1977# Now test that the user-version can be read and written (and that we aren't 681b92b70bbSdanielk1977# accidentally manipulating the schema-version instead). 682dae2495bSdanielk1977do_test pragma-8.2.1 { 68325403650Sdrh execsql2 { 684b92b70bbSdanielk1977 PRAGMA user_version; 685dae2495bSdanielk1977 } 68625403650Sdrh} {user_version 0} 687dae2495bSdanielk1977do_test pragma-8.2.2 { 688dae2495bSdanielk1977 execsql { 689b92b70bbSdanielk1977 PRAGMA user_version = 2; 690dae2495bSdanielk1977 } 691dae2495bSdanielk1977} {} 692802d69a7Sdrhdo_test pragma-8.2.3.1 { 69325403650Sdrh execsql2 { 694b92b70bbSdanielk1977 PRAGMA user_version; 695dae2495bSdanielk1977 } 69625403650Sdrh} {user_version 2} 697802d69a7Sdrhdo_test pragma-8.2.3.2 { 698802d69a7Sdrh db close 699802d69a7Sdrh sqlite3 db test.db 700802d69a7Sdrh execsql { 701802d69a7Sdrh PRAGMA user_version; 702802d69a7Sdrh } 703802d69a7Sdrh} {2} 704802d69a7Sdrhdo_test pragma-8.2.4.1 { 705dae2495bSdanielk1977 execsql { 706b92b70bbSdanielk1977 PRAGMA schema_version; 707dae2495bSdanielk1977 } 708dae2495bSdanielk1977} {108} 709802d69a7Sdrhifcapable vacuum { 710802d69a7Sdrh do_test pragma-8.2.4.2 { 711802d69a7Sdrh execsql { 712802d69a7Sdrh VACUUM; 713802d69a7Sdrh PRAGMA user_version; 714802d69a7Sdrh } 715802d69a7Sdrh } {2} 716802d69a7Sdrh do_test pragma-8.2.4.3 { 717802d69a7Sdrh execsql { 718802d69a7Sdrh PRAGMA schema_version; 719802d69a7Sdrh } 720802d69a7Sdrh } {109} 721802d69a7Sdrh} 722802d69a7Sdrhdb eval {ATTACH 'test2.db' AS aux} 723dae2495bSdanielk1977 724b92b70bbSdanielk1977# Check that the user-version in the auxilary database can be manipulated ( 725dae2495bSdanielk1977# and that we aren't accidentally manipulating the same in the main db). 726dae2495bSdanielk1977do_test pragma-8.2.5 { 727dae2495bSdanielk1977 execsql { 728b92b70bbSdanielk1977 PRAGMA aux.user_version; 729dae2495bSdanielk1977 } 730dae2495bSdanielk1977} {0} 731dae2495bSdanielk1977do_test pragma-8.2.6 { 732dae2495bSdanielk1977 execsql { 733b92b70bbSdanielk1977 PRAGMA aux.user_version = 3; 734dae2495bSdanielk1977 } 735dae2495bSdanielk1977} {} 736dae2495bSdanielk1977do_test pragma-8.2.7 { 737dae2495bSdanielk1977 execsql { 738b92b70bbSdanielk1977 PRAGMA aux.user_version; 739dae2495bSdanielk1977 } 740dae2495bSdanielk1977} {3} 741dae2495bSdanielk1977do_test pragma-8.2.8 { 742dae2495bSdanielk1977 execsql { 743b92b70bbSdanielk1977 PRAGMA main.user_version; 744dae2495bSdanielk1977 } 745dae2495bSdanielk1977} {2} 746dae2495bSdanielk1977 747b92b70bbSdanielk1977# Now check that a ROLLBACK resets the user-version if it has been modified 748dae2495bSdanielk1977# within a transaction. 749dae2495bSdanielk1977do_test pragma-8.2.9 { 750dae2495bSdanielk1977 execsql { 751dae2495bSdanielk1977 BEGIN; 752b92b70bbSdanielk1977 PRAGMA aux.user_version = 10; 753b92b70bbSdanielk1977 PRAGMA user_version = 11; 754dae2495bSdanielk1977 } 755dae2495bSdanielk1977} {} 756dae2495bSdanielk1977do_test pragma-8.2.10 { 757dae2495bSdanielk1977 execsql { 758b92b70bbSdanielk1977 PRAGMA aux.user_version; 759dae2495bSdanielk1977 } 760dae2495bSdanielk1977} {10} 761dae2495bSdanielk1977do_test pragma-8.2.11 { 762dae2495bSdanielk1977 execsql { 763b92b70bbSdanielk1977 PRAGMA main.user_version; 764dae2495bSdanielk1977 } 765dae2495bSdanielk1977} {11} 766dae2495bSdanielk1977do_test pragma-8.2.12 { 767dae2495bSdanielk1977 execsql { 768dae2495bSdanielk1977 ROLLBACK; 769b92b70bbSdanielk1977 PRAGMA aux.user_version; 770dae2495bSdanielk1977 } 771dae2495bSdanielk1977} {3} 772dae2495bSdanielk1977do_test pragma-8.2.13 { 773dae2495bSdanielk1977 execsql { 774b92b70bbSdanielk1977 PRAGMA main.user_version; 775dae2495bSdanielk1977 } 776dae2495bSdanielk1977} {2} 777dae2495bSdanielk1977 778b92b70bbSdanielk1977# Try a negative value for the user-version 779dae2495bSdanielk1977do_test pragma-8.2.14 { 780dae2495bSdanielk1977 execsql { 781b92b70bbSdanielk1977 PRAGMA user_version = -450; 782dae2495bSdanielk1977 } 783dae2495bSdanielk1977} {} 784dae2495bSdanielk1977do_test pragma-8.2.15 { 785dae2495bSdanielk1977 execsql { 786b92b70bbSdanielk1977 PRAGMA user_version; 787dae2495bSdanielk1977 } 788dae2495bSdanielk1977} {-450} 789d9c847dcSdanielk1977} ; # ifcapable schema_version 790d9c847dcSdanielk1977 7919a09a3caStpoindex 7929a09a3caStpoindex# Test temp_store and temp_store_directory pragmas 7939a09a3caStpoindex# 794268283bcSdrhifcapable pager_pragmas { 7959a09a3caStpoindexdo_test pragma-9.1 { 7969a09a3caStpoindex db close 7979a09a3caStpoindex sqlite3 db test.db 7989a09a3caStpoindex execsql { 7999a09a3caStpoindex PRAGMA temp_store; 8009a09a3caStpoindex } 8019a09a3caStpoindex} {0} 8029a09a3caStpoindexdo_test pragma-9.2 { 8039a09a3caStpoindex execsql { 8049a09a3caStpoindex PRAGMA temp_store=file; 8059a09a3caStpoindex PRAGMA temp_store; 8069a09a3caStpoindex } 8079a09a3caStpoindex} {1} 8089a09a3caStpoindexdo_test pragma-9.3 { 8099a09a3caStpoindex execsql { 8109a09a3caStpoindex PRAGMA temp_store=memory; 8119a09a3caStpoindex PRAGMA temp_store; 8129a09a3caStpoindex } 8139a09a3caStpoindex} {2} 8149a09a3caStpoindexdo_test pragma-9.4 { 8159a09a3caStpoindex execsql { 8169a09a3caStpoindex PRAGMA temp_store_directory; 8179a09a3caStpoindex } 8189a09a3caStpoindex} {} 8199a09a3caStpoindexdo_test pragma-9.5 { 820268283bcSdrh set pwd [string map {' ''} [pwd]] 821268283bcSdrh execsql " 822268283bcSdrh PRAGMA temp_store_directory='$pwd'; 8239a09a3caStpoindex " 8249a09a3caStpoindex} {} 8259a09a3caStpoindexdo_test pragma-9.6 { 8269a09a3caStpoindex execsql { 8279a09a3caStpoindex PRAGMA temp_store_directory; 8289a09a3caStpoindex } 8291941a3e8Sdrh} [list [pwd]] 8309a09a3caStpoindexdo_test pragma-9.7 { 831268283bcSdrh catchsql { 8329a09a3caStpoindex PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR'; 8339a09a3caStpoindex } 834268283bcSdrh} {1 {not a writable directory}} 8359a09a3caStpoindexdo_test pragma-9.8 { 8369a09a3caStpoindex execsql { 8379a09a3caStpoindex PRAGMA temp_store_directory=''; 8389a09a3caStpoindex } 8399a09a3caStpoindex} {} 84053c0f748Sdanielk1977ifcapable tempdb { 8419a09a3caStpoindex do_test pragma-9.9 { 8429a09a3caStpoindex execsql { 8439a09a3caStpoindex PRAGMA temp_store_directory; 8449a09a3caStpoindex PRAGMA temp_store=FILE; 8459a09a3caStpoindex CREATE TEMP TABLE temp_store_directory_test(a integer); 8469a09a3caStpoindex INSERT INTO temp_store_directory_test values (2); 8479a09a3caStpoindex SELECT * FROM temp_store_directory_test; 8489a09a3caStpoindex } 8499a09a3caStpoindex } {2} 85053c0f748Sdanielk1977} 8519a09a3caStpoindexdo_test pragma-9.10 { 852268283bcSdrh catchsql " 853268283bcSdrh PRAGMA temp_store_directory='$pwd'; 8549a09a3caStpoindex SELECT * FROM temp_store_directory_test; 8559a09a3caStpoindex " 856268283bcSdrh} {1 {no such table: temp_store_directory_test}} 857268283bcSdrh} ;# ifcapable pager_pragmas 8589a09a3caStpoindex 859cc6bd383Sdanielk1977ifcapable trigger { 860cc6bd383Sdanielk1977 861cc6bd383Sdanielk1977do_test pragma-10.0 { 862cc6bd383Sdanielk1977 catchsql { 863cc6bd383Sdanielk1977 DROP TABLE main.t1; 864cc6bd383Sdanielk1977 } 865cc6bd383Sdanielk1977 execsql { 866cc6bd383Sdanielk1977 PRAGMA count_changes = 1; 867cc6bd383Sdanielk1977 868cc6bd383Sdanielk1977 CREATE TABLE t1(a PRIMARY KEY); 869cc6bd383Sdanielk1977 CREATE TABLE t1_mirror(a); 870cc6bd383Sdanielk1977 CREATE TABLE t1_mirror2(a); 871cc6bd383Sdanielk1977 CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN 872cc6bd383Sdanielk1977 INSERT INTO t1_mirror VALUES(new.a); 873cc6bd383Sdanielk1977 END; 874cc6bd383Sdanielk1977 CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN 875cc6bd383Sdanielk1977 INSERT INTO t1_mirror2 VALUES(new.a); 876cc6bd383Sdanielk1977 END; 877cc6bd383Sdanielk1977 CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN 878cc6bd383Sdanielk1977 UPDATE t1_mirror SET a = new.a WHERE a = old.a; 879cc6bd383Sdanielk1977 END; 880cc6bd383Sdanielk1977 CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN 881cc6bd383Sdanielk1977 UPDATE t1_mirror2 SET a = new.a WHERE a = old.a; 882cc6bd383Sdanielk1977 END; 883cc6bd383Sdanielk1977 CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN 884cc6bd383Sdanielk1977 DELETE FROM t1_mirror WHERE a = old.a; 885cc6bd383Sdanielk1977 END; 886cc6bd383Sdanielk1977 CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN 887cc6bd383Sdanielk1977 DELETE FROM t1_mirror2 WHERE a = old.a; 888cc6bd383Sdanielk1977 END; 889cc6bd383Sdanielk1977 } 890cc6bd383Sdanielk1977} {} 891cc6bd383Sdanielk1977 892cc6bd383Sdanielk1977do_test pragma-10.1 { 893cc6bd383Sdanielk1977 execsql { 894cc6bd383Sdanielk1977 INSERT INTO t1 VALUES(randstr(10,10)); 895cc6bd383Sdanielk1977 } 896cc6bd383Sdanielk1977} {1} 897cc6bd383Sdanielk1977do_test pragma-10.2 { 898cc6bd383Sdanielk1977 execsql { 899cc6bd383Sdanielk1977 UPDATE t1 SET a = randstr(10,10); 900cc6bd383Sdanielk1977 } 901cc6bd383Sdanielk1977} {1} 902cc6bd383Sdanielk1977do_test pragma-10.3 { 903cc6bd383Sdanielk1977 execsql { 904cc6bd383Sdanielk1977 DELETE FROM t1; 905cc6bd383Sdanielk1977 } 906cc6bd383Sdanielk1977} {1} 907cc6bd383Sdanielk1977 908cc6bd383Sdanielk1977} ;# ifcapable trigger 909cc6bd383Sdanielk1977 91048af65aeSdanielk1977ifcapable schema_pragmas { 91148af65aeSdanielk1977 do_test pragma-11.1 { 91248af65aeSdanielk1977 execsql2 { 91348af65aeSdanielk1977 pragma collation_list; 91448af65aeSdanielk1977 } 91548af65aeSdanielk1977 } {seq 0 name NOCASE seq 1 name BINARY} 91648af65aeSdanielk1977 do_test pragma-11.2 { 91748af65aeSdanielk1977 db collate New_Collation blah... 91848af65aeSdanielk1977 execsql { 91948af65aeSdanielk1977 pragma collation_list; 92048af65aeSdanielk1977 } 92148af65aeSdanielk1977 } {0 New_Collation 1 NOCASE 2 BINARY} 92248af65aeSdanielk1977} 92348af65aeSdanielk1977 924ddfb2f03Sdanielk1977ifcapable schema_pragmas&&tempdb { 925ddfb2f03Sdanielk1977 do_test pragma-12.1 { 926ddfb2f03Sdanielk1977 sqlite3 db2 test.db 927ddfb2f03Sdanielk1977 execsql { 928ddfb2f03Sdanielk1977 PRAGMA temp.table_info('abc'); 929ddfb2f03Sdanielk1977 } db2 930ddfb2f03Sdanielk1977 } {} 931ddfb2f03Sdanielk1977 db2 close 932ddfb2f03Sdanielk1977 933ddfb2f03Sdanielk1977 do_test pragma-12.2 { 934ddfb2f03Sdanielk1977 sqlite3 db2 test.db 935ddfb2f03Sdanielk1977 execsql { 936ddfb2f03Sdanielk1977 PRAGMA temp.default_cache_size = 200; 937ddfb2f03Sdanielk1977 PRAGMA temp.default_cache_size; 938ddfb2f03Sdanielk1977 } db2 939ddfb2f03Sdanielk1977 } {200} 940ddfb2f03Sdanielk1977 db2 close 941ddfb2f03Sdanielk1977 942ddfb2f03Sdanielk1977 do_test pragma-12.3 { 943ddfb2f03Sdanielk1977 sqlite3 db2 test.db 944ddfb2f03Sdanielk1977 execsql { 945ddfb2f03Sdanielk1977 PRAGMA temp.cache_size = 400; 946ddfb2f03Sdanielk1977 PRAGMA temp.cache_size; 947ddfb2f03Sdanielk1977 } db2 948ddfb2f03Sdanielk1977 } {400} 949ddfb2f03Sdanielk1977 db2 close 950ddfb2f03Sdanielk1977} 951ddfb2f03Sdanielk1977 9524b2688abSdanielk1977ifcapable bloblit { 9534b2688abSdanielk1977 95405a82983Sdrhdo_test pragma-13.1 { 95505a82983Sdrh execsql { 95605a82983Sdrh DROP TABLE IF EXISTS t4; 95705a82983Sdrh PRAGMA vdbe_trace=on; 95805a82983Sdrh PRAGMA vdbe_listing=on; 95905a82983Sdrh PRAGMA sql_trace=on; 96005a82983Sdrh CREATE TABLE t4(a INTEGER PRIMARY KEY,b); 96105a82983Sdrh INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789'); 96205a82983Sdrh INSERT INTO t4(b) VALUES(randstr(30,30)); 96305a82983Sdrh INSERT INTO t4(b) VALUES(1.23456); 96405a82983Sdrh INSERT INTO t4(b) VALUES(NULL); 96505a82983Sdrh INSERT INTO t4(b) VALUES(0); 96605a82983Sdrh INSERT INTO t4(b) SELECT b||b||b||b FROM t4; 96705a82983Sdrh SELECT * FROM t4; 96805a82983Sdrh } 96905a82983Sdrh execsql { 97005a82983Sdrh PRAGMA vdbe_trace=off; 97105a82983Sdrh PRAGMA vdbe_listing=off; 97205a82983Sdrh PRAGMA sql_trace=off; 97305a82983Sdrh } 97405a82983Sdrh} {} 97505a82983Sdrh 9764b2688abSdanielk1977} ;# ifcapable bloblit 9774b2688abSdanielk1977 9785558a8a6Sdanielk1977# Reset the sqlite3_temp_directory variable for the next run of tests: 9795558a8a6Sdanielk1977sqlite3 dbX :memory: 9805558a8a6Sdanielk1977dbX eval {PRAGMA temp_store_directory = ""} 9815558a8a6Sdanielk1977dbX close 9825558a8a6Sdanielk1977 983cd61c281Sdrhfinish_test 984