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# 15838cce43Sdanielk1977# $Id: pragma.test,v 1.73 2009/01/12 14:01:45 danielk1977 Exp $ 16cd61c281Sdrh 17cd61c281Sdrhset testdir [file dirname $argv0] 18cd61c281Sdrhsource $testdir/tester.tcl 19cd61c281Sdrh 2068928b6cSdan# Do not use a codec for tests in this file, as the database file is 2168928b6cSdan# manipulated directly using tcl scripts (using the [hexio_write] command). 2268928b6cSdan# 2368928b6cSdando_not_use_codec 2468928b6cSdan 2591cf71b0Sdanielk1977# Test organization: 2691cf71b0Sdanielk1977# 2791cf71b0Sdanielk1977# pragma-1.*: Test cache_size, default_cache_size and synchronous on main db. 2891cf71b0Sdanielk1977# pragma-2.*: Test synchronous on attached db. 2991cf71b0Sdanielk1977# pragma-3.*: Test detection of table/index inconsistency by integrity_check. 3091cf71b0Sdanielk1977# pragma-4.*: Test cache_size and default_cache_size on attached db. 3191cf71b0Sdanielk1977# pragma-5.*: Test that pragma synchronous may not be used inside of a 3291cf71b0Sdanielk1977# transaction. 33cc6bd383Sdanielk1977# pragma-6.*: Test schema-query pragmas. 34cc6bd383Sdanielk1977# pragma-7.*: Miscellaneous tests. 35cc6bd383Sdanielk1977# pragma-8.*: Test user_version and schema_version pragmas. 369a09a3caStpoindex# pragma-9.*: Test temp_store and temp_store_directory. 37cc6bd383Sdanielk1977# pragma-10.*: Test the count_changes pragma in the presence of triggers. 3848af65aeSdanielk1977# pragma-11.*: Test the collation_list pragma. 3959a93791Sdanielk1977# pragma-14.*: Test the page_count pragma. 408cf6c554Sdanielk1977# pragma-15.*: Test that the value set using the cache_size pragma is not 418cf6c554Sdanielk1977# reset when the schema is reloaded. 42aebf413dSaswift# pragma-16.*: Test proxy locking 43*a112d140Smistachkin# pragma-20.*: Test data_store_directory. 4491cf71b0Sdanielk1977# 4591cf71b0Sdanielk1977 4605a82983Sdrhifcapable !pragma { 4705a82983Sdrh finish_test 4805a82983Sdrh return 4905a82983Sdrh} 5005a82983Sdrh 51cd61c281Sdrh# Delete the preexisting database to avoid the special setup 52cd61c281Sdrh# that the "all.test" script does. 53cd61c281Sdrh# 54cd61c281Sdrhdb close 55fda06befSmistachkindelete_file test.db test.db-journal 56fda06befSmistachkindelete_file test3.db test3.db-journal 57dddca286Sdrhsqlite3 db test.db; set DB [sqlite3_connection_pointer db] 58cd61c281Sdrh 591e9daa6aSdrh 60c7b4a44cSdanielk1977ifcapable pager_pragmas { 611e9daa6aSdrhset DFLT_CACHE_SZ [db one {PRAGMA default_cache_size}] 621e9daa6aSdrhset TEMP_CACHE_SZ [db one {PRAGMA temp.default_cache_size}] 63cd61c281Sdrhdo_test pragma-1.1 { 64cd61c281Sdrh execsql { 65cd61c281Sdrh PRAGMA cache_size; 66cd61c281Sdrh PRAGMA default_cache_size; 67cd61c281Sdrh PRAGMA synchronous; 68cd61c281Sdrh } 691e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] 70cd61c281Sdrhdo_test pragma-1.2 { 71cd61c281Sdrh execsql { 72eb43e5c7Sdrh PRAGMA synchronous=OFF; 73cd61c281Sdrh PRAGMA cache_size=1234; 74cd61c281Sdrh PRAGMA cache_size; 75cd61c281Sdrh PRAGMA default_cache_size; 76cd61c281Sdrh PRAGMA synchronous; 77cd61c281Sdrh } 781e9daa6aSdrh} [list 1234 $DFLT_CACHE_SZ 0] 79cd61c281Sdrhdo_test pragma-1.3 { 80cd61c281Sdrh db close 81ef4ac8f9Sdrh sqlite3 db test.db 82cd61c281Sdrh execsql { 83cd61c281Sdrh PRAGMA cache_size; 84cd61c281Sdrh PRAGMA default_cache_size; 85cd61c281Sdrh PRAGMA synchronous; 86cd61c281Sdrh } 871e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] 88cd61c281Sdrhdo_test pragma-1.4 { 89cd61c281Sdrh execsql { 90cd61c281Sdrh PRAGMA synchronous=OFF; 91cd61c281Sdrh PRAGMA cache_size; 92cd61c281Sdrh PRAGMA default_cache_size; 93cd61c281Sdrh PRAGMA synchronous; 94cd61c281Sdrh } 951e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 0] 96cd61c281Sdrhdo_test pragma-1.5 { 97cd61c281Sdrh execsql { 98d2cb50b7Sdrh PRAGMA cache_size=-4321; 99cd61c281Sdrh PRAGMA cache_size; 100cd61c281Sdrh PRAGMA default_cache_size; 101cd61c281Sdrh PRAGMA synchronous; 102cd61c281Sdrh } 1033b42abb3Sdrh} [list -4321 $DFLT_CACHE_SZ 0] 104cd61c281Sdrhdo_test pragma-1.6 { 105cd61c281Sdrh execsql { 106cd61c281Sdrh PRAGMA synchronous=ON; 107cd61c281Sdrh PRAGMA cache_size; 108cd61c281Sdrh PRAGMA default_cache_size; 109cd61c281Sdrh PRAGMA synchronous; 110cd61c281Sdrh } 1113b42abb3Sdrh} [list -4321 $DFLT_CACHE_SZ 1] 112cd61c281Sdrhdo_test pragma-1.7 { 113cd61c281Sdrh db close 114ef4ac8f9Sdrh sqlite3 db test.db 115cd61c281Sdrh execsql { 116cd61c281Sdrh PRAGMA cache_size; 117cd61c281Sdrh PRAGMA default_cache_size; 118cd61c281Sdrh PRAGMA synchronous; 119cd61c281Sdrh } 1201e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] 121cd61c281Sdrhdo_test pragma-1.8 { 122cd61c281Sdrh execsql { 123d2cb50b7Sdrh PRAGMA default_cache_size=-123; 124cd61c281Sdrh PRAGMA cache_size; 125cd61c281Sdrh PRAGMA default_cache_size; 126cd61c281Sdrh PRAGMA synchronous; 127cd61c281Sdrh } 12891cf71b0Sdanielk1977} {123 123 2} 129802d69a7Sdrhdo_test pragma-1.9.1 { 130cd61c281Sdrh db close 131dddca286Sdrh sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db] 132cd61c281Sdrh execsql { 133cd61c281Sdrh PRAGMA cache_size; 134cd61c281Sdrh PRAGMA default_cache_size; 135cd61c281Sdrh PRAGMA synchronous; 136cd61c281Sdrh } 13791cf71b0Sdanielk1977} {123 123 2} 138802d69a7Sdrhifcapable vacuum { 139802d69a7Sdrh do_test pragma-1.9.2 { 140802d69a7Sdrh execsql { 141802d69a7Sdrh VACUUM; 142802d69a7Sdrh PRAGMA cache_size; 143802d69a7Sdrh PRAGMA default_cache_size; 144802d69a7Sdrh PRAGMA synchronous; 145802d69a7Sdrh } 146802d69a7Sdrh } {123 123 2} 147802d69a7Sdrh} 14891cf71b0Sdanielk1977do_test pragma-1.10 { 1495a38705eSdrh execsql { 1504303feedSdrh PRAGMA synchronous=NORMAL; 1514303feedSdrh PRAGMA cache_size; 1524303feedSdrh PRAGMA default_cache_size; 1534303feedSdrh PRAGMA synchronous; 1544303feedSdrh } 15591cf71b0Sdanielk1977} {123 123 1} 15691cf71b0Sdanielk1977do_test pragma-1.11 { 1574303feedSdrh execsql { 1584303feedSdrh PRAGMA synchronous=FULL; 1594303feedSdrh PRAGMA cache_size; 1604303feedSdrh PRAGMA default_cache_size; 1614303feedSdrh PRAGMA synchronous; 1624303feedSdrh } 16391cf71b0Sdanielk1977} {123 123 2} 16491cf71b0Sdanielk1977do_test pragma-1.12 { 1654303feedSdrh db close 166dddca286Sdrh sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db] 1674303feedSdrh execsql { 1684303feedSdrh PRAGMA cache_size; 1694303feedSdrh PRAGMA default_cache_size; 1704303feedSdrh PRAGMA synchronous; 1714303feedSdrh } 17291cf71b0Sdanielk1977} {123 123 2} 17391cf71b0Sdanielk1977 1745260f7e9Sdrh# Make sure the pragma handler understands numeric values in addition 1755260f7e9Sdrh# to keywords like "off" and "full". 1765260f7e9Sdrh# 1775260f7e9Sdrhdo_test pragma-1.13 { 1785260f7e9Sdrh execsql { 1795260f7e9Sdrh PRAGMA synchronous=0; 1805260f7e9Sdrh PRAGMA synchronous; 1815260f7e9Sdrh } 1825260f7e9Sdrh} {0} 1835260f7e9Sdrhdo_test pragma-1.14 { 1845260f7e9Sdrh execsql { 1855260f7e9Sdrh PRAGMA synchronous=2; 1865260f7e9Sdrh PRAGMA synchronous; 1875260f7e9Sdrh } 1885260f7e9Sdrh} {2} 189c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 1905260f7e9Sdrh 1915260f7e9Sdrh# Test turning "flag" pragmas on and off. 1925260f7e9Sdrh# 1936338c762Sdanielk1977ifcapable debug { 1946338c762Sdanielk1977 # Pragma "vdbe_listing" is only available if compiled with SQLITE_DEBUG 1956338c762Sdanielk1977 # 1965260f7e9Sdrh do_test pragma-1.15 { 1975260f7e9Sdrh execsql { 1985260f7e9Sdrh PRAGMA vdbe_listing=YES; 1995260f7e9Sdrh PRAGMA vdbe_listing; 2005260f7e9Sdrh } 2015260f7e9Sdrh } {1} 2025260f7e9Sdrh do_test pragma-1.16 { 2035260f7e9Sdrh execsql { 2045260f7e9Sdrh PRAGMA vdbe_listing=NO; 2055260f7e9Sdrh PRAGMA vdbe_listing; 2065260f7e9Sdrh } 2075260f7e9Sdrh } {0} 2086338c762Sdanielk1977} 2096338c762Sdanielk1977 2105260f7e9Sdrhdo_test pragma-1.17 { 2115260f7e9Sdrh execsql { 2125260f7e9Sdrh PRAGMA parser_trace=ON; 2135260f7e9Sdrh PRAGMA parser_trace=OFF; 2145260f7e9Sdrh } 2155260f7e9Sdrh} {} 2165260f7e9Sdrhdo_test pragma-1.18 { 2175260f7e9Sdrh execsql { 2185260f7e9Sdrh PRAGMA bogus = -1234; -- Parsing of negative values 2195260f7e9Sdrh } 2205260f7e9Sdrh} {} 2215260f7e9Sdrh 22291cf71b0Sdanielk1977# Test modifying the safety_level of an attached database. 2235a8f9374Sdanielk1977ifcapable pager_pragmas&&attach { 22491cf71b0Sdanielk1977 do_test pragma-2.1 { 225fda06befSmistachkin forcedelete test2.db 226fda06befSmistachkin forcedelete test2.db-journal 2274303feedSdrh execsql { 22891cf71b0Sdanielk1977 ATTACH 'test2.db' AS aux; 2294303feedSdrh } 23091cf71b0Sdanielk1977 } {} 23191cf71b0Sdanielk1977 do_test pragma-2.2 { 2324303feedSdrh execsql { 23391cf71b0Sdanielk1977 pragma aux.synchronous; 2344303feedSdrh } 23591cf71b0Sdanielk1977 } {2} 23691cf71b0Sdanielk1977 do_test pragma-2.3 { 23791cf71b0Sdanielk1977 execsql { 23891cf71b0Sdanielk1977 pragma aux.synchronous = OFF; 23991cf71b0Sdanielk1977 pragma aux.synchronous; 24091cf71b0Sdanielk1977 pragma synchronous; 24191cf71b0Sdanielk1977 } 24291cf71b0Sdanielk1977 } {0 2} 24391cf71b0Sdanielk1977 do_test pragma-2.4 { 24491cf71b0Sdanielk1977 execsql { 24591cf71b0Sdanielk1977 pragma aux.synchronous = ON; 24691cf71b0Sdanielk1977 pragma synchronous; 24791cf71b0Sdanielk1977 pragma aux.synchronous; 24891cf71b0Sdanielk1977 } 24991cf71b0Sdanielk1977 } {2 1} 250c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 2514303feedSdrh 252ed717fe3Sdrh# Construct a corrupted index and make sure the integrity_check 253ed717fe3Sdrh# pragma finds it. 254ed717fe3Sdrh# 25525d6543dSdrh# These tests won't work if the database is encrypted 25625d6543dSdrh# 257ed717fe3Sdrhdo_test pragma-3.1 { 2581e9daa6aSdrh db close 259fda06befSmistachkin forcedelete test.db test.db-journal 2601e9daa6aSdrh sqlite3 db test.db 261ed717fe3Sdrh execsql { 2621e9daa6aSdrh PRAGMA auto_vacuum=OFF; 263ed717fe3Sdrh BEGIN; 264ed717fe3Sdrh CREATE TABLE t2(a,b,c); 265ed717fe3Sdrh CREATE INDEX i2 ON t2(a); 266ed717fe3Sdrh INSERT INTO t2 VALUES(11,2,3); 267ed717fe3Sdrh INSERT INTO t2 VALUES(22,3,4); 268ed717fe3Sdrh COMMIT; 269ed717fe3Sdrh SELECT rowid, * from t2; 270ed717fe3Sdrh } 271ed717fe3Sdrh} {1 11 2 3 2 22 3 4} 2725a8f9374Sdanielk1977ifcapable attach { 27340e016e4Sdrh if {![sqlite3 -has-codec] && $sqlite_options(integrityck)} { 274ed717fe3Sdrh do_test pragma-3.2 { 275bb8a279eSdrh db eval {SELECT rootpage FROM sqlite_master WHERE name='i2'} break 276bb8a279eSdrh set pgsz [db eval {PRAGMA page_size}] 277bb8a279eSdrh # overwrite the header on the rootpage of the index in order to 278bb8a279eSdrh # make the index appear to be empty. 279bb8a279eSdrh # 280bb8a279eSdrh set offset [expr {$pgsz*($rootpage-1)}] 281bb8a279eSdrh hexio_write test.db $offset 0a00000000040000000000 282bb8a279eSdrh db close 283bb8a279eSdrh sqlite3 db test.db 284ed717fe3Sdrh execsql {PRAGMA integrity_check} 285bb8a279eSdrh } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}} 28691cf71b0Sdanielk1977 do_test pragma-3.3 { 2871dcdbc06Sdrh execsql {PRAGMA integrity_check=1} 2881dcdbc06Sdrh } {{rowid 1 missing from index i2}} 2891dcdbc06Sdrh do_test pragma-3.4 { 29091cf71b0Sdanielk1977 execsql { 2911dcdbc06Sdrh ATTACH DATABASE 'test.db' AS t2; 2921dcdbc06Sdrh PRAGMA integrity_check 29391cf71b0Sdanielk1977 } 294bb8a279eSdrh } {{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.5 { 2961dcdbc06Sdrh execsql { 297bb8a279eSdrh PRAGMA integrity_check=4 2981dcdbc06Sdrh } 299bb8a279eSdrh } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2}} 3001dcdbc06Sdrh do_test pragma-3.6 { 3011dcdbc06Sdrh execsql { 3021dcdbc06Sdrh PRAGMA integrity_check=xyz 3031dcdbc06Sdrh } 304bb8a279eSdrh } {{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}} 3051dcdbc06Sdrh do_test pragma-3.7 { 3061dcdbc06Sdrh execsql { 3071dcdbc06Sdrh PRAGMA integrity_check=0 3081dcdbc06Sdrh } 309bb8a279eSdrh } {{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}} 3101dcdbc06Sdrh 3111dcdbc06Sdrh # Add additional corruption by appending unused pages to the end of 3121dcdbc06Sdrh # the database file testerr.db 3131dcdbc06Sdrh # 3141dcdbc06Sdrh do_test pragma-3.8 { 3151dcdbc06Sdrh execsql {DETACH t2} 316fda06befSmistachkin forcedelete testerr.db testerr.db-journal 317e3d559adSdrh set out [open testerr.db w] 318e3d559adSdrh fconfigure $out -translation binary 319e3d559adSdrh set in [open test.db r] 320e3d559adSdrh fconfigure $in -translation binary 3211dcdbc06Sdrh puts -nonewline $out [read $in] 3221dcdbc06Sdrh seek $in 0 3231dcdbc06Sdrh puts -nonewline $out [read $in] 3241dcdbc06Sdrh close $in 3251dcdbc06Sdrh close $out 326dd3cd977Sdrh hexio_write testerr.db 28 00000000 3271dcdbc06Sdrh execsql {REINDEX t2} 3281dcdbc06Sdrh execsql {PRAGMA integrity_check} 3291dcdbc06Sdrh } {ok} 33041c58b78Sdanielk1977 do_test pragma-3.8.1 { 33141c58b78Sdanielk1977 execsql {PRAGMA quick_check} 33241c58b78Sdanielk1977 } {ok} 3335d16a9a6Sdrh do_test pragma-3.8.2 { 3345d16a9a6Sdrh execsql {PRAGMA QUICK_CHECK} 3355d16a9a6Sdrh } {ok} 3361dcdbc06Sdrh do_test pragma-3.9 { 3371dcdbc06Sdrh execsql { 3381dcdbc06Sdrh ATTACH 'testerr.db' AS t2; 3391dcdbc06Sdrh PRAGMA integrity_check 3401dcdbc06Sdrh } 3411dcdbc06Sdrh } {{*** in database t2 *** 3421dcdbc06SdrhPage 4 is never used 3431dcdbc06SdrhPage 5 is never used 344bb8a279eSdrhPage 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}} 3451dcdbc06Sdrh do_test pragma-3.10 { 3461dcdbc06Sdrh execsql { 3471dcdbc06Sdrh PRAGMA integrity_check=1 3481dcdbc06Sdrh } 3491dcdbc06Sdrh } {{*** in database t2 *** 3501dcdbc06SdrhPage 4 is never used}} 3511dcdbc06Sdrh do_test pragma-3.11 { 3521dcdbc06Sdrh execsql { 3531dcdbc06Sdrh PRAGMA integrity_check=5 3541dcdbc06Sdrh } 3551dcdbc06Sdrh } {{*** in database t2 *** 3561dcdbc06SdrhPage 4 is never used 3571dcdbc06SdrhPage 5 is never used 358bb8a279eSdrhPage 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2}} 3591dcdbc06Sdrh do_test pragma-3.12 { 3601dcdbc06Sdrh execsql { 3611dcdbc06Sdrh PRAGMA integrity_check=4 3621dcdbc06Sdrh } 3631dcdbc06Sdrh } {{*** in database t2 *** 3641dcdbc06SdrhPage 4 is never used 3651dcdbc06SdrhPage 5 is never used 3661dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}} 3671dcdbc06Sdrh do_test pragma-3.13 { 3681dcdbc06Sdrh execsql { 3691dcdbc06Sdrh PRAGMA integrity_check=3 3701dcdbc06Sdrh } 3711dcdbc06Sdrh } {{*** in database t2 *** 3721dcdbc06SdrhPage 4 is never used 3731dcdbc06SdrhPage 5 is never used 3741dcdbc06SdrhPage 6 is never used}} 3751dcdbc06Sdrh do_test pragma-3.14 { 3761dcdbc06Sdrh execsql { 3771dcdbc06Sdrh PRAGMA integrity_check(2) 3781dcdbc06Sdrh } 3791dcdbc06Sdrh } {{*** in database t2 *** 3801dcdbc06SdrhPage 4 is never used 3811dcdbc06SdrhPage 5 is never used}} 3821dcdbc06Sdrh do_test pragma-3.15 { 3831dcdbc06Sdrh execsql { 3841dcdbc06Sdrh ATTACH 'testerr.db' AS t3; 3851dcdbc06Sdrh PRAGMA integrity_check 3861dcdbc06Sdrh } 3871dcdbc06Sdrh } {{*** in database t2 *** 3881dcdbc06SdrhPage 4 is never used 3891dcdbc06SdrhPage 5 is never used 390bb8a279eSdrhPage 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 *** 3911dcdbc06SdrhPage 4 is never used 3921dcdbc06SdrhPage 5 is never used 393bb8a279eSdrhPage 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}} 3941dcdbc06Sdrh do_test pragma-3.16 { 3951dcdbc06Sdrh execsql { 396bb8a279eSdrh PRAGMA integrity_check(10) 3971dcdbc06Sdrh } 3981dcdbc06Sdrh } {{*** in database t2 *** 3991dcdbc06SdrhPage 4 is never used 4001dcdbc06SdrhPage 5 is never used 401bb8a279eSdrhPage 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 *** 4021dcdbc06SdrhPage 4 is never used 4031dcdbc06SdrhPage 5 is never used 4041dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}} 4051dcdbc06Sdrh do_test pragma-3.17 { 4061dcdbc06Sdrh execsql { 407bb8a279eSdrh PRAGMA integrity_check=8 4081dcdbc06Sdrh } 4091dcdbc06Sdrh } {{*** in database t2 *** 4101dcdbc06SdrhPage 4 is never used 4111dcdbc06SdrhPage 5 is never used 412bb8a279eSdrhPage 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 *** 4131dcdbc06SdrhPage 4 is never used 4141dcdbc06SdrhPage 5 is never used}} 4151dcdbc06Sdrh do_test pragma-3.18 { 4161dcdbc06Sdrh execsql { 4171dcdbc06Sdrh PRAGMA integrity_check=4 4181dcdbc06Sdrh } 4191dcdbc06Sdrh } {{*** in database t2 *** 4201dcdbc06SdrhPage 4 is never used 4211dcdbc06SdrhPage 5 is never used 4221dcdbc06SdrhPage 6 is never used} {rowid 1 missing from index i2}} 4231dcdbc06Sdrh } 424d2cb50b7Sdrh do_test pragma-3.19 { 425d2cb50b7Sdrh catch {db close} 426fda06befSmistachkin forcedelete test.db test.db-journal 427d2cb50b7Sdrh sqlite3 db test.db 428d2cb50b7Sdrh db eval {PRAGMA integrity_check} 429d2cb50b7Sdrh } {ok} 4305a8f9374Sdanielk1977} 431d2cb50b7Sdrh#exit 43291cf71b0Sdanielk1977 43391cf71b0Sdanielk1977# Test modifying the cache_size of an attached database. 4345a8f9374Sdanielk1977ifcapable pager_pragmas&&attach { 43591cf71b0Sdanielk1977do_test pragma-4.1 { 43691cf71b0Sdanielk1977 execsql { 4371e9daa6aSdrh ATTACH 'test2.db' AS aux; 43891cf71b0Sdanielk1977 pragma aux.cache_size; 43991cf71b0Sdanielk1977 pragma aux.default_cache_size; 44091cf71b0Sdanielk1977 } 4411e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] 4421bdd9b57Sdrhdo_test pragma-4.2 { 4431bdd9b57Sdrh execsql { 44491cf71b0Sdanielk1977 pragma aux.cache_size = 50; 44591cf71b0Sdanielk1977 pragma aux.cache_size; 44691cf71b0Sdanielk1977 pragma aux.default_cache_size; 4471bdd9b57Sdrh } 4481e9daa6aSdrh} [list 50 $DFLT_CACHE_SZ] 4491bdd9b57Sdrhdo_test pragma-4.3 { 4501bdd9b57Sdrh execsql { 45191cf71b0Sdanielk1977 pragma aux.default_cache_size = 456; 45291cf71b0Sdanielk1977 pragma aux.cache_size; 45391cf71b0Sdanielk1977 pragma aux.default_cache_size; 4541bdd9b57Sdrh } 45591cf71b0Sdanielk1977} {456 456} 4561bdd9b57Sdrhdo_test pragma-4.4 { 4571bdd9b57Sdrh execsql { 45891cf71b0Sdanielk1977 pragma cache_size; 45991cf71b0Sdanielk1977 pragma default_cache_size; 4601bdd9b57Sdrh } 4611e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] 4621bdd9b57Sdrhdo_test pragma-4.5 { 4631bdd9b57Sdrh execsql { 46491cf71b0Sdanielk1977 DETACH aux; 46591cf71b0Sdanielk1977 ATTACH 'test3.db' AS aux; 46691cf71b0Sdanielk1977 pragma aux.cache_size; 46791cf71b0Sdanielk1977 pragma aux.default_cache_size; 4681bdd9b57Sdrh } 4691e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] 4701bdd9b57Sdrhdo_test pragma-4.6 { 4711bdd9b57Sdrh execsql { 47291cf71b0Sdanielk1977 DETACH aux; 47391cf71b0Sdanielk1977 ATTACH 'test2.db' AS aux; 47491cf71b0Sdanielk1977 pragma aux.cache_size; 47591cf71b0Sdanielk1977 pragma aux.default_cache_size; 4761bdd9b57Sdrh } 47791cf71b0Sdanielk1977} {456 456} 478c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 4791bdd9b57Sdrh 48091cf71b0Sdanielk1977# Test that modifying the sync-level in the middle of a transaction is 48191cf71b0Sdanielk1977# disallowed. 482c7b4a44cSdanielk1977ifcapable pager_pragmas { 48391cf71b0Sdanielk1977do_test pragma-5.0 { 4841bdd9b57Sdrh execsql { 48591cf71b0Sdanielk1977 pragma synchronous; 4861bdd9b57Sdrh } 48791cf71b0Sdanielk1977} {2} 48891cf71b0Sdanielk1977do_test pragma-5.1 { 4891bdd9b57Sdrh catchsql { 4901bdd9b57Sdrh BEGIN; 49191cf71b0Sdanielk1977 pragma synchronous = OFF; 4921bdd9b57Sdrh } 49391cf71b0Sdanielk1977} {1 {Safety level may not be changed inside a transaction}} 49491cf71b0Sdanielk1977do_test pragma-5.2 { 49591cf71b0Sdanielk1977 execsql { 49691cf71b0Sdanielk1977 pragma synchronous; 49791cf71b0Sdanielk1977 } 49891cf71b0Sdanielk1977} {2} 4995260f7e9Sdrhcatchsql {COMMIT;} 500c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 5015260f7e9Sdrh 5025260f7e9Sdrh# Test schema-query pragmas 5035260f7e9Sdrh# 50427188fb5Sdanielk1977ifcapable schema_pragmas { 5055a8f9374Sdanielk1977ifcapable tempdb&&attach { 5065260f7e9Sdrh do_test pragma-6.1 { 507956bc92cSdrh set res {} 50840e016e4Sdrh execsql {SELECT * FROM sqlite_temp_master} 5095260f7e9Sdrh foreach {idx name file} [execsql {pragma database_list}] { 5105260f7e9Sdrh lappend res $idx $name 5115260f7e9Sdrh } 5125260f7e9Sdrh set res 513a71aa001Sdrh } {0 main 1 temp 2 aux} 51453c0f748Sdanielk1977} 5155260f7e9Sdrhdo_test pragma-6.2 { 5165260f7e9Sdrh execsql { 517d2cb50b7Sdrh CREATE TABLE t2(a,b,c); 5185260f7e9Sdrh pragma table_info(t2) 5195260f7e9Sdrh } 520bfa8b102Sdrh} {0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0} 521d2cb50b7Sdrhdo_test pragma-6.2.1 { 522d2cb50b7Sdrh execsql { 523d2cb50b7Sdrh pragma table_info; 524d2cb50b7Sdrh } 525d2cb50b7Sdrh} {} 526736c7d4bSdrhdb nullvalue <<NULL>> 527417ec638Sdrhdo_test pragma-6.2.2 { 528417ec638Sdrh execsql { 529736c7d4bSdrh CREATE TABLE t5( 530736c7d4bSdrh a TEXT DEFAULT CURRENT_TIMESTAMP, 531736c7d4bSdrh b DEFAULT (5+3), 532736c7d4bSdrh c TEXT, 533736c7d4bSdrh d INTEGER DEFAULT NULL, 534736c7d4bSdrh e TEXT DEFAULT '' 535736c7d4bSdrh ); 536417ec638Sdrh PRAGMA table_info(t5); 537417ec638Sdrh } 538736c7d4bSdrh} {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} 539736c7d4bSdrhdb nullvalue {} 5406bf89570Sdrhifcapable {foreignkey} { 541d2cb50b7Sdrh do_test pragma-6.3.1 { 5425260f7e9Sdrh execsql { 5435260f7e9Sdrh CREATE TABLE t3(a int references t2(b), b UNIQUE); 5445260f7e9Sdrh pragma foreign_key_list(t3); 5455260f7e9Sdrh } 5461da40a38Sdan } {0 0 t2 a b {NO ACTION} {NO ACTION} NONE} 547d2cb50b7Sdrh do_test pragma-6.3.2 { 548d2cb50b7Sdrh execsql { 549d2cb50b7Sdrh pragma foreign_key_list; 550d2cb50b7Sdrh } 551d2cb50b7Sdrh } {} 552d2cb50b7Sdrh do_test pragma-6.3.3 { 553d2cb50b7Sdrh execsql { 554d2cb50b7Sdrh pragma foreign_key_list(t3_bogus); 555d2cb50b7Sdrh } 556d2cb50b7Sdrh } {} 557d2cb50b7Sdrh do_test pragma-6.3.4 { 558d2cb50b7Sdrh execsql { 559d2cb50b7Sdrh pragma foreign_key_list(t5); 560d2cb50b7Sdrh } 561d2cb50b7Sdrh } {} 5625260f7e9Sdrh do_test pragma-6.4 { 5635260f7e9Sdrh execsql { 5645260f7e9Sdrh pragma index_list(t3); 5655260f7e9Sdrh } 5665260f7e9Sdrh } {0 sqlite_autoindex_t3_1 1} 5676bf89570Sdrh} 5686bf89570Sdrhifcapable {!foreignkey} { 5696bf89570Sdrh execsql {CREATE TABLE t3(a,b UNIQUE)} 5706bf89570Sdrh} 571d2cb50b7Sdrhdo_test pragma-6.5.1 { 5725260f7e9Sdrh execsql { 5735260f7e9Sdrh CREATE INDEX t3i1 ON t3(a,b); 5745260f7e9Sdrh pragma index_info(t3i1); 5755260f7e9Sdrh } 5765260f7e9Sdrh} {0 0 a 1 1 b} 577d2cb50b7Sdrhdo_test pragma-6.5.2 { 578d2cb50b7Sdrh execsql { 579d2cb50b7Sdrh pragma index_info(t3i1_bogus); 580d2cb50b7Sdrh } 581d2cb50b7Sdrh} {} 582260d8a6aSdanielk1977 583260d8a6aSdanielk1977ifcapable tempdb { 584260d8a6aSdanielk1977 # Test for ticket #3320. When a temp table of the same name exists, make 585260d8a6aSdanielk1977 # sure the schema of the main table can still be queried using 586260d8a6aSdanielk1977 # "pragma table_info": 587260d8a6aSdanielk1977 do_test pragma-6.6.1 { 588260d8a6aSdanielk1977 execsql { 589260d8a6aSdanielk1977 CREATE TABLE trial(col_main); 590260d8a6aSdanielk1977 CREATE TEMP TABLE trial(col_temp); 591260d8a6aSdanielk1977 } 592260d8a6aSdanielk1977 } {} 593260d8a6aSdanielk1977 do_test pragma-6.6.2 { 594260d8a6aSdanielk1977 execsql { 595260d8a6aSdanielk1977 PRAGMA table_info(trial); 596260d8a6aSdanielk1977 } 597260d8a6aSdanielk1977 } {0 col_temp {} 0 {} 0} 598260d8a6aSdanielk1977 do_test pragma-6.6.3 { 599260d8a6aSdanielk1977 execsql { 600260d8a6aSdanielk1977 PRAGMA temp.table_info(trial); 601260d8a6aSdanielk1977 } 602260d8a6aSdanielk1977 } {0 col_temp {} 0 {} 0} 603260d8a6aSdanielk1977 do_test pragma-6.6.4 { 604260d8a6aSdanielk1977 execsql { 605260d8a6aSdanielk1977 PRAGMA main.table_info(trial); 606260d8a6aSdanielk1977 } 607260d8a6aSdanielk1977 } {0 col_main {} 0 {} 0} 608260d8a6aSdanielk1977} 609f96a3778Sdanielk1977 610f96a3778Sdanielk1977do_test pragma-6.7 { 611f96a3778Sdanielk1977 execsql { 612f96a3778Sdanielk1977 CREATE TABLE test_table( 613f96a3778Sdanielk1977 one INT NOT NULL DEFAULT -1, 614f96a3778Sdanielk1977 two text, 615f96a3778Sdanielk1977 three VARCHAR(45, 65) DEFAULT 'abcde', 616f96a3778Sdanielk1977 four REAL DEFAULT X'abcdef', 617f96a3778Sdanielk1977 five DEFAULT CURRENT_TIME 618f96a3778Sdanielk1977 ); 619f96a3778Sdanielk1977 PRAGMA table_info(test_table); 620f96a3778Sdanielk1977 } 621f96a3778Sdanielk1977} [concat \ 622f96a3778Sdanielk1977 {0 one INT 1 -1 0} \ 623f96a3778Sdanielk1977 {1 two text 0 {} 0} \ 624f96a3778Sdanielk1977 {2 three {VARCHAR(45, 65)} 0 'abcde' 0} \ 625f96a3778Sdanielk1977 {3 four REAL 0 X'abcdef' 0} \ 626f96a3778Sdanielk1977 {4 five {} 0 CURRENT_TIME 0} \ 627f96a3778Sdanielk1977] 62827188fb5Sdanielk1977} ;# ifcapable schema_pragmas 6295260f7e9Sdrh# Miscellaneous tests 6305260f7e9Sdrh# 63127188fb5Sdanielk1977ifcapable schema_pragmas { 632d2cb50b7Sdrhdo_test pragma-7.1.1 { 6335260f7e9Sdrh # Make sure a pragma knows to read the schema if it needs to 6345260f7e9Sdrh db close 6355260f7e9Sdrh sqlite3 db test.db 6365260f7e9Sdrh execsql { 6375260f7e9Sdrh pragma index_list(t3); 6385260f7e9Sdrh } 6395260f7e9Sdrh} {0 t3i1 0 1 sqlite_autoindex_t3_1 1} 640d2cb50b7Sdrhdo_test pragma-7.1.2 { 641d2cb50b7Sdrh execsql { 642d2cb50b7Sdrh pragma index_list(t3_bogus); 643d2cb50b7Sdrh } 644d2cb50b7Sdrh} {} 64527188fb5Sdanielk1977} ;# ifcapable schema_pragmas 6466c62608fSdrhifcapable {utf16} { 647cb354603Sdan if {[permutation] == ""} { 6485260f7e9Sdrh do_test pragma-7.2 { 6495260f7e9Sdrh db close 6505260f7e9Sdrh sqlite3 db test.db 6515260f7e9Sdrh catchsql { 6525260f7e9Sdrh pragma encoding=bogus; 6535260f7e9Sdrh } 6545260f7e9Sdrh } {1 {unsupported encoding: bogus}} 6556c62608fSdrh } 656cb354603Sdan} 65753c0f748Sdanielk1977ifcapable tempdb { 6585260f7e9Sdrh do_test pragma-7.3 { 6595260f7e9Sdrh db close 6605260f7e9Sdrh sqlite3 db test.db 6615260f7e9Sdrh execsql { 6625260f7e9Sdrh pragma lock_status; 6635260f7e9Sdrh } 6645260f7e9Sdrh } {main unlocked temp closed} 66553c0f748Sdanielk1977} else { 66653c0f748Sdanielk1977 do_test pragma-7.3 { 66753c0f748Sdanielk1977 db close 66853c0f748Sdanielk1977 sqlite3 db test.db 66953c0f748Sdanielk1977 execsql { 67053c0f748Sdanielk1977 pragma lock_status; 67153c0f748Sdanielk1977 } 67253c0f748Sdanielk1977 } {main unlocked} 67353c0f748Sdanielk1977} 6745260f7e9Sdrh 6755260f7e9Sdrh 676dae2495bSdanielk1977#---------------------------------------------------------------------- 677b92b70bbSdanielk1977# Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA 678b92b70bbSdanielk1977# user_version" statements. 679dae2495bSdanielk1977# 680b92b70bbSdanielk1977# pragma-8.1: PRAGMA schema_version 681b92b70bbSdanielk1977# pragma-8.2: PRAGMA user_version 682dae2495bSdanielk1977# 683dae2495bSdanielk1977 68411cf9fbcSdanielk1977ifcapable schema_version { 68511cf9fbcSdanielk1977 686b92b70bbSdanielk1977# First check that we can set the schema version and then retrieve the 687dae2495bSdanielk1977# same value. 688dae2495bSdanielk1977do_test pragma-8.1.1 { 689dae2495bSdanielk1977 execsql { 690b92b70bbSdanielk1977 PRAGMA schema_version = 105; 691dae2495bSdanielk1977 } 692dae2495bSdanielk1977} {} 693dae2495bSdanielk1977do_test pragma-8.1.2 { 69425403650Sdrh execsql2 { 695b92b70bbSdanielk1977 PRAGMA schema_version; 696dae2495bSdanielk1977 } 69725403650Sdrh} {schema_version 105} 698dae2495bSdanielk1977do_test pragma-8.1.3 { 699dae2495bSdanielk1977 execsql { 700b92b70bbSdanielk1977 PRAGMA schema_version = 106; 701dae2495bSdanielk1977 } 702dae2495bSdanielk1977} {} 703dae2495bSdanielk1977do_test pragma-8.1.4 { 704dae2495bSdanielk1977 execsql { 705b92b70bbSdanielk1977 PRAGMA schema_version; 706dae2495bSdanielk1977 } 707dae2495bSdanielk1977} 106 708dae2495bSdanielk1977 709b92b70bbSdanielk1977# Check that creating a table modifies the schema-version (this is really 710b92b70bbSdanielk1977# to verify that the value being read is in fact the schema version). 711dae2495bSdanielk1977do_test pragma-8.1.5 { 712dae2495bSdanielk1977 execsql { 713dae2495bSdanielk1977 CREATE TABLE t4(a, b, c); 714dae2495bSdanielk1977 INSERT INTO t4 VALUES(1, 2, 3); 715dae2495bSdanielk1977 SELECT * FROM t4; 716dae2495bSdanielk1977 } 717dae2495bSdanielk1977} {1 2 3} 718dae2495bSdanielk1977do_test pragma-8.1.6 { 719dae2495bSdanielk1977 execsql { 720b92b70bbSdanielk1977 PRAGMA schema_version; 721dae2495bSdanielk1977 } 722dae2495bSdanielk1977} 107 723dae2495bSdanielk1977 724dae2495bSdanielk1977# Now open a second connection to the database. Ensure that changing the 725b92b70bbSdanielk1977# schema-version using the first connection forces the second connection 726dae2495bSdanielk1977# to reload the schema. This has to be done using the C-API test functions, 727dae2495bSdanielk1977# because the TCL API accounts for SCHEMA_ERROR and retries the query. 728dae2495bSdanielk1977do_test pragma-8.1.7 { 729dddca286Sdrh sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] 730dae2495bSdanielk1977 execsql { 731dae2495bSdanielk1977 SELECT * FROM t4; 732dae2495bSdanielk1977 } db2 733dae2495bSdanielk1977} {1 2 3} 734dae2495bSdanielk1977do_test pragma-8.1.8 { 735dae2495bSdanielk1977 execsql { 736b92b70bbSdanielk1977 PRAGMA schema_version = 108; 737dae2495bSdanielk1977 } 738dae2495bSdanielk1977} {} 739dae2495bSdanielk1977do_test pragma-8.1.9 { 740dae2495bSdanielk1977 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY] 741dae2495bSdanielk1977 sqlite3_step $::STMT 742dae2495bSdanielk1977} SQLITE_ERROR 743dae2495bSdanielk1977do_test pragma-8.1.10 { 744dae2495bSdanielk1977 sqlite3_finalize $::STMT 745dae2495bSdanielk1977} SQLITE_SCHEMA 746dae2495bSdanielk1977 747b92b70bbSdanielk1977# Make sure the schema-version can be manipulated in an attached database. 748fda06befSmistachkinforcedelete test2.db 749fda06befSmistachkinforcedelete test2.db-journal 7505a8f9374Sdanielk1977ifcapable attach { 751dae2495bSdanielk1977 do_test pragma-8.1.11 { 752dae2495bSdanielk1977 execsql { 753dae2495bSdanielk1977 ATTACH 'test2.db' AS aux; 754dae2495bSdanielk1977 CREATE TABLE aux.t1(a, b, c); 755b92b70bbSdanielk1977 PRAGMA aux.schema_version = 205; 756dae2495bSdanielk1977 } 757dae2495bSdanielk1977 } {} 758dae2495bSdanielk1977 do_test pragma-8.1.12 { 759dae2495bSdanielk1977 execsql { 760b92b70bbSdanielk1977 PRAGMA aux.schema_version; 761dae2495bSdanielk1977 } 762dae2495bSdanielk1977 } 205 7635a8f9374Sdanielk1977} 764dae2495bSdanielk1977do_test pragma-8.1.13 { 765dae2495bSdanielk1977 execsql { 766b92b70bbSdanielk1977 PRAGMA schema_version; 767dae2495bSdanielk1977 } 768dae2495bSdanielk1977} 108 769dae2495bSdanielk1977 770b92b70bbSdanielk1977# And check that modifying the schema-version in an attached database 771dae2495bSdanielk1977# forces the second connection to reload the schema. 7725a8f9374Sdanielk1977ifcapable attach { 773dae2495bSdanielk1977 do_test pragma-8.1.14 { 774dddca286Sdrh sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] 775dae2495bSdanielk1977 execsql { 776dae2495bSdanielk1977 ATTACH 'test2.db' AS aux; 777dae2495bSdanielk1977 SELECT * FROM aux.t1; 778dae2495bSdanielk1977 } db2 779dae2495bSdanielk1977 } {} 780dae2495bSdanielk1977 do_test pragma-8.1.15 { 781dae2495bSdanielk1977 execsql { 782b92b70bbSdanielk1977 PRAGMA aux.schema_version = 206; 783dae2495bSdanielk1977 } 784dae2495bSdanielk1977 } {} 785dae2495bSdanielk1977 do_test pragma-8.1.16 { 786dae2495bSdanielk1977 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY] 787dae2495bSdanielk1977 sqlite3_step $::STMT 788dae2495bSdanielk1977 } SQLITE_ERROR 789dae2495bSdanielk1977 do_test pragma-8.1.17 { 790dae2495bSdanielk1977 sqlite3_finalize $::STMT 791dae2495bSdanielk1977 } SQLITE_SCHEMA 792dae2495bSdanielk1977 do_test pragma-8.1.18 { 793dae2495bSdanielk1977 db2 close 794dae2495bSdanielk1977 } {} 7955a8f9374Sdanielk1977} 796dae2495bSdanielk1977 797b92b70bbSdanielk1977# Now test that the user-version can be read and written (and that we aren't 798b92b70bbSdanielk1977# accidentally manipulating the schema-version instead). 799dae2495bSdanielk1977do_test pragma-8.2.1 { 80025403650Sdrh execsql2 { 801b92b70bbSdanielk1977 PRAGMA user_version; 802dae2495bSdanielk1977 } 80325403650Sdrh} {user_version 0} 804dae2495bSdanielk1977do_test pragma-8.2.2 { 805dae2495bSdanielk1977 execsql { 806b92b70bbSdanielk1977 PRAGMA user_version = 2; 807dae2495bSdanielk1977 } 808dae2495bSdanielk1977} {} 809802d69a7Sdrhdo_test pragma-8.2.3.1 { 81025403650Sdrh execsql2 { 811b92b70bbSdanielk1977 PRAGMA user_version; 812dae2495bSdanielk1977 } 81325403650Sdrh} {user_version 2} 814802d69a7Sdrhdo_test pragma-8.2.3.2 { 815802d69a7Sdrh db close 816802d69a7Sdrh sqlite3 db test.db 817802d69a7Sdrh execsql { 818802d69a7Sdrh PRAGMA user_version; 819802d69a7Sdrh } 820802d69a7Sdrh} {2} 821802d69a7Sdrhdo_test pragma-8.2.4.1 { 822dae2495bSdanielk1977 execsql { 823b92b70bbSdanielk1977 PRAGMA schema_version; 824dae2495bSdanielk1977 } 825dae2495bSdanielk1977} {108} 826802d69a7Sdrhifcapable vacuum { 827802d69a7Sdrh do_test pragma-8.2.4.2 { 828802d69a7Sdrh execsql { 829802d69a7Sdrh VACUUM; 830802d69a7Sdrh PRAGMA user_version; 831802d69a7Sdrh } 832802d69a7Sdrh } {2} 833802d69a7Sdrh do_test pragma-8.2.4.3 { 834802d69a7Sdrh execsql { 835802d69a7Sdrh PRAGMA schema_version; 836802d69a7Sdrh } 837802d69a7Sdrh } {109} 838802d69a7Sdrh} 8395a8f9374Sdanielk1977 8405a8f9374Sdanielk1977ifcapable attach { 841802d69a7Sdrh db eval {ATTACH 'test2.db' AS aux} 842dae2495bSdanielk1977 843b92b70bbSdanielk1977 # Check that the user-version in the auxilary database can be manipulated ( 844dae2495bSdanielk1977 # and that we aren't accidentally manipulating the same in the main db). 845dae2495bSdanielk1977 do_test pragma-8.2.5 { 846dae2495bSdanielk1977 execsql { 847b92b70bbSdanielk1977 PRAGMA aux.user_version; 848dae2495bSdanielk1977 } 849dae2495bSdanielk1977 } {0} 850dae2495bSdanielk1977 do_test pragma-8.2.6 { 851dae2495bSdanielk1977 execsql { 852b92b70bbSdanielk1977 PRAGMA aux.user_version = 3; 853dae2495bSdanielk1977 } 854dae2495bSdanielk1977 } {} 855dae2495bSdanielk1977 do_test pragma-8.2.7 { 856dae2495bSdanielk1977 execsql { 857b92b70bbSdanielk1977 PRAGMA aux.user_version; 858dae2495bSdanielk1977 } 859dae2495bSdanielk1977 } {3} 860dae2495bSdanielk1977 do_test pragma-8.2.8 { 861dae2495bSdanielk1977 execsql { 862b92b70bbSdanielk1977 PRAGMA main.user_version; 863dae2495bSdanielk1977 } 864dae2495bSdanielk1977 } {2} 865dae2495bSdanielk1977 866b92b70bbSdanielk1977 # Now check that a ROLLBACK resets the user-version if it has been modified 867dae2495bSdanielk1977 # within a transaction. 868dae2495bSdanielk1977 do_test pragma-8.2.9 { 869dae2495bSdanielk1977 execsql { 870dae2495bSdanielk1977 BEGIN; 871b92b70bbSdanielk1977 PRAGMA aux.user_version = 10; 872b92b70bbSdanielk1977 PRAGMA user_version = 11; 873dae2495bSdanielk1977 } 874dae2495bSdanielk1977 } {} 875dae2495bSdanielk1977 do_test pragma-8.2.10 { 876dae2495bSdanielk1977 execsql { 877b92b70bbSdanielk1977 PRAGMA aux.user_version; 878dae2495bSdanielk1977 } 879dae2495bSdanielk1977 } {10} 880dae2495bSdanielk1977 do_test pragma-8.2.11 { 881dae2495bSdanielk1977 execsql { 882b92b70bbSdanielk1977 PRAGMA main.user_version; 883dae2495bSdanielk1977 } 884dae2495bSdanielk1977 } {11} 885dae2495bSdanielk1977 do_test pragma-8.2.12 { 886dae2495bSdanielk1977 execsql { 887dae2495bSdanielk1977 ROLLBACK; 888b92b70bbSdanielk1977 PRAGMA aux.user_version; 889dae2495bSdanielk1977 } 890dae2495bSdanielk1977 } {3} 891dae2495bSdanielk1977 do_test pragma-8.2.13 { 892dae2495bSdanielk1977 execsql { 893b92b70bbSdanielk1977 PRAGMA main.user_version; 894dae2495bSdanielk1977 } 895dae2495bSdanielk1977 } {2} 8965a8f9374Sdanielk1977} 897dae2495bSdanielk1977 898b92b70bbSdanielk1977# Try a negative value for the user-version 899dae2495bSdanielk1977do_test pragma-8.2.14 { 900dae2495bSdanielk1977 execsql { 901b92b70bbSdanielk1977 PRAGMA user_version = -450; 902dae2495bSdanielk1977 } 903dae2495bSdanielk1977} {} 904dae2495bSdanielk1977do_test pragma-8.2.15 { 905dae2495bSdanielk1977 execsql { 906b92b70bbSdanielk1977 PRAGMA user_version; 907dae2495bSdanielk1977 } 908dae2495bSdanielk1977} {-450} 909d9c847dcSdanielk1977} ; # ifcapable schema_version 910d9c847dcSdanielk1977 911d19744f3Sdrh# Check to see if TEMP_STORE is memory or disk. Return strings 912d19744f3Sdrh# "memory" or "disk" as appropriate. 913d19744f3Sdrh# 914d19744f3Sdrhproc check_temp_store {} { 915d19744f3Sdrh db eval {CREATE TEMP TABLE IF NOT EXISTS a(b)} 916d19744f3Sdrh db eval {PRAGMA database_list} { 917d19744f3Sdrh if {$name=="temp"} { 91817b90b53Sdanielk1977 set bt [btree_from_db db 1] 91917b90b53Sdanielk1977 if {[btree_ismemdb $bt]} { 920d19744f3Sdrh return "memory" 921d19744f3Sdrh } 92217b90b53Sdanielk1977 return "disk" 923d19744f3Sdrh } 924d19744f3Sdrh } 925d19744f3Sdrh return "unknown" 926d19744f3Sdrh} 927d19744f3Sdrh 9289a09a3caStpoindex 9299a09a3caStpoindex# Test temp_store and temp_store_directory pragmas 9309a09a3caStpoindex# 931268283bcSdrhifcapable pager_pragmas { 9329a09a3caStpoindexdo_test pragma-9.1 { 9339a09a3caStpoindex db close 9349a09a3caStpoindex sqlite3 db test.db 9359a09a3caStpoindex execsql { 9369a09a3caStpoindex PRAGMA temp_store; 9379a09a3caStpoindex } 9389a09a3caStpoindex} {0} 939d19744f3Sdrhif {$TEMP_STORE<=1} { 940d19744f3Sdrh do_test pragma-9.1.1 { 941d19744f3Sdrh check_temp_store 942d19744f3Sdrh } {disk} 943d19744f3Sdrh} else { 944d19744f3Sdrh do_test pragma-9.1.1 { 945d19744f3Sdrh check_temp_store 946d19744f3Sdrh } {memory} 947d19744f3Sdrh} 948d19744f3Sdrh 9499a09a3caStpoindexdo_test pragma-9.2 { 950d19744f3Sdrh db close 951d19744f3Sdrh sqlite3 db test.db 9529a09a3caStpoindex execsql { 9539a09a3caStpoindex PRAGMA temp_store=file; 9549a09a3caStpoindex PRAGMA temp_store; 9559a09a3caStpoindex } 9569a09a3caStpoindex} {1} 957d19744f3Sdrhif {$TEMP_STORE==3} { 958d19744f3Sdrh # When TEMP_STORE is 3, always use memory regardless of pragma settings. 959d19744f3Sdrh do_test pragma-9.2.1 { 960d19744f3Sdrh check_temp_store 961d19744f3Sdrh } {memory} 962d19744f3Sdrh} else { 963d19744f3Sdrh do_test pragma-9.2.1 { 964d19744f3Sdrh check_temp_store 965d19744f3Sdrh } {disk} 966d19744f3Sdrh} 967d19744f3Sdrh 9689a09a3caStpoindexdo_test pragma-9.3 { 969d19744f3Sdrh db close 970d19744f3Sdrh sqlite3 db test.db 9719a09a3caStpoindex execsql { 9729a09a3caStpoindex PRAGMA temp_store=memory; 9739a09a3caStpoindex PRAGMA temp_store; 9749a09a3caStpoindex } 9759a09a3caStpoindex} {2} 976d19744f3Sdrhif {$TEMP_STORE==0} { 977d19744f3Sdrh # When TEMP_STORE is 0, always use the disk regardless of pragma settings. 978d19744f3Sdrh do_test pragma-9.3.1 { 979d19744f3Sdrh check_temp_store 980d19744f3Sdrh } {disk} 981d19744f3Sdrh} else { 982d19744f3Sdrh do_test pragma-9.3.1 { 983d19744f3Sdrh check_temp_store 984d19744f3Sdrh } {memory} 985d19744f3Sdrh} 986d19744f3Sdrh 9879a09a3caStpoindexdo_test pragma-9.4 { 9889a09a3caStpoindex execsql { 9899a09a3caStpoindex PRAGMA temp_store_directory; 9909a09a3caStpoindex } 9919a09a3caStpoindex} {} 99278f82d1eSdrhifcapable wsd { 9939a09a3caStpoindex do_test pragma-9.5 { 994f8a78464Smistachkin set pwd [string map {' ''} [file nativename [get_pwd]]] 995268283bcSdrh execsql " 996268283bcSdrh PRAGMA temp_store_directory='$pwd'; 9979a09a3caStpoindex " 9989a09a3caStpoindex } {} 9999a09a3caStpoindex do_test pragma-9.6 { 10009a09a3caStpoindex execsql { 10019a09a3caStpoindex PRAGMA temp_store_directory; 10029a09a3caStpoindex } 1003f8a78464Smistachkin } [list [file nativename [get_pwd]]] 10049a09a3caStpoindex do_test pragma-9.7 { 1005268283bcSdrh catchsql { 10069a09a3caStpoindex PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR'; 10079a09a3caStpoindex } 1008268283bcSdrh } {1 {not a writable directory}} 10099a09a3caStpoindex do_test pragma-9.8 { 10109a09a3caStpoindex execsql { 10119a09a3caStpoindex PRAGMA temp_store_directory=''; 10129a09a3caStpoindex } 10139a09a3caStpoindex } {} 10141e9daa6aSdrh if {![info exists TEMP_STORE] || $TEMP_STORE<=1} { 101553c0f748Sdanielk1977 ifcapable tempdb { 10169a09a3caStpoindex do_test pragma-9.9 { 10179a09a3caStpoindex execsql { 10189a09a3caStpoindex PRAGMA temp_store_directory; 10199a09a3caStpoindex PRAGMA temp_store=FILE; 10209a09a3caStpoindex CREATE TEMP TABLE temp_store_directory_test(a integer); 10219a09a3caStpoindex INSERT INTO temp_store_directory_test values (2); 10229a09a3caStpoindex SELECT * FROM temp_store_directory_test; 10239a09a3caStpoindex } 10249a09a3caStpoindex } {2} 10259a09a3caStpoindex do_test pragma-9.10 { 1026268283bcSdrh catchsql " 1027268283bcSdrh PRAGMA temp_store_directory='$pwd'; 10289a09a3caStpoindex SELECT * FROM temp_store_directory_test; 10299a09a3caStpoindex " 1030268283bcSdrh } {1 {no such table: temp_store_directory_test}} 10311e9daa6aSdrh } 10321e9daa6aSdrh } 103378f82d1eSdrh} 103495b289b6Sdanielk1977do_test pragma-9.11 { 103595b289b6Sdanielk1977 execsql { 103695b289b6Sdanielk1977 PRAGMA temp_store = 0; 103795b289b6Sdanielk1977 PRAGMA temp_store; 103895b289b6Sdanielk1977 } 103995b289b6Sdanielk1977} {0} 104095b289b6Sdanielk1977do_test pragma-9.12 { 104195b289b6Sdanielk1977 execsql { 104295b289b6Sdanielk1977 PRAGMA temp_store = 1; 104395b289b6Sdanielk1977 PRAGMA temp_store; 104495b289b6Sdanielk1977 } 104595b289b6Sdanielk1977} {1} 104695b289b6Sdanielk1977do_test pragma-9.13 { 104795b289b6Sdanielk1977 execsql { 104895b289b6Sdanielk1977 PRAGMA temp_store = 2; 104995b289b6Sdanielk1977 PRAGMA temp_store; 105095b289b6Sdanielk1977 } 105195b289b6Sdanielk1977} {2} 105295b289b6Sdanielk1977do_test pragma-9.14 { 105395b289b6Sdanielk1977 execsql { 105495b289b6Sdanielk1977 PRAGMA temp_store = 3; 105595b289b6Sdanielk1977 PRAGMA temp_store; 105695b289b6Sdanielk1977 } 105795b289b6Sdanielk1977} {0} 105895b289b6Sdanielk1977do_test pragma-9.15 { 105995b289b6Sdanielk1977 catchsql { 106095b289b6Sdanielk1977 BEGIN EXCLUSIVE; 106195b289b6Sdanielk1977 CREATE TEMP TABLE temp_table(t); 106295b289b6Sdanielk1977 INSERT INTO temp_table VALUES('valuable data'); 106395b289b6Sdanielk1977 PRAGMA temp_store = 1; 106495b289b6Sdanielk1977 } 106595b289b6Sdanielk1977} {1 {temporary storage cannot be changed from within a transaction}} 106695b289b6Sdanielk1977do_test pragma-9.16 { 106795b289b6Sdanielk1977 execsql { 106895b289b6Sdanielk1977 SELECT * FROM temp_table; 106995b289b6Sdanielk1977 COMMIT; 107095b289b6Sdanielk1977 } 107195b289b6Sdanielk1977} {{valuable data}} 1072983e2309Sdanielk1977 1073983e2309Sdanielk1977do_test pragma-9.17 { 1074983e2309Sdanielk1977 execsql { 1075983e2309Sdanielk1977 INSERT INTO temp_table VALUES('valuable data II'); 1076983e2309Sdanielk1977 SELECT * FROM temp_table; 1077983e2309Sdanielk1977 } 1078983e2309Sdanielk1977} {{valuable data} {valuable data II}} 1079983e2309Sdanielk1977 1080983e2309Sdanielk1977do_test pragma-9.18 { 1081983e2309Sdanielk1977 set rc [catch { 1082983e2309Sdanielk1977 db eval {SELECT t FROM temp_table} { 1083983e2309Sdanielk1977 execsql {pragma temp_store = 1} 1084983e2309Sdanielk1977 } 1085983e2309Sdanielk1977 } msg] 1086983e2309Sdanielk1977 list $rc $msg 1087983e2309Sdanielk1977} {1 {temporary storage cannot be changed from within a transaction}} 1088983e2309Sdanielk1977 1089268283bcSdrh} ;# ifcapable pager_pragmas 10909a09a3caStpoindex 1091cc6bd383Sdanielk1977ifcapable trigger { 1092cc6bd383Sdanielk1977 1093cc6bd383Sdanielk1977do_test pragma-10.0 { 1094cc6bd383Sdanielk1977 catchsql { 1095cc6bd383Sdanielk1977 DROP TABLE main.t1; 1096cc6bd383Sdanielk1977 } 1097cc6bd383Sdanielk1977 execsql { 1098cc6bd383Sdanielk1977 PRAGMA count_changes = 1; 1099cc6bd383Sdanielk1977 1100cc6bd383Sdanielk1977 CREATE TABLE t1(a PRIMARY KEY); 1101cc6bd383Sdanielk1977 CREATE TABLE t1_mirror(a); 1102cc6bd383Sdanielk1977 CREATE TABLE t1_mirror2(a); 1103cc6bd383Sdanielk1977 CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN 1104cc6bd383Sdanielk1977 INSERT INTO t1_mirror VALUES(new.a); 1105cc6bd383Sdanielk1977 END; 1106cc6bd383Sdanielk1977 CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN 1107cc6bd383Sdanielk1977 INSERT INTO t1_mirror2 VALUES(new.a); 1108cc6bd383Sdanielk1977 END; 1109cc6bd383Sdanielk1977 CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN 1110cc6bd383Sdanielk1977 UPDATE t1_mirror SET a = new.a WHERE a = old.a; 1111cc6bd383Sdanielk1977 END; 1112cc6bd383Sdanielk1977 CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN 1113cc6bd383Sdanielk1977 UPDATE t1_mirror2 SET a = new.a WHERE a = old.a; 1114cc6bd383Sdanielk1977 END; 1115cc6bd383Sdanielk1977 CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN 1116cc6bd383Sdanielk1977 DELETE FROM t1_mirror WHERE a = old.a; 1117cc6bd383Sdanielk1977 END; 1118cc6bd383Sdanielk1977 CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN 1119cc6bd383Sdanielk1977 DELETE FROM t1_mirror2 WHERE a = old.a; 1120cc6bd383Sdanielk1977 END; 1121cc6bd383Sdanielk1977 } 1122cc6bd383Sdanielk1977} {} 1123cc6bd383Sdanielk1977 1124cc6bd383Sdanielk1977do_test pragma-10.1 { 1125cc6bd383Sdanielk1977 execsql { 1126cc6bd383Sdanielk1977 INSERT INTO t1 VALUES(randstr(10,10)); 1127cc6bd383Sdanielk1977 } 1128cc6bd383Sdanielk1977} {1} 1129cc6bd383Sdanielk1977do_test pragma-10.2 { 1130cc6bd383Sdanielk1977 execsql { 1131cc6bd383Sdanielk1977 UPDATE t1 SET a = randstr(10,10); 1132cc6bd383Sdanielk1977 } 1133cc6bd383Sdanielk1977} {1} 1134cc6bd383Sdanielk1977do_test pragma-10.3 { 1135cc6bd383Sdanielk1977 execsql { 1136cc6bd383Sdanielk1977 DELETE FROM t1; 1137cc6bd383Sdanielk1977 } 1138cc6bd383Sdanielk1977} {1} 1139cc6bd383Sdanielk1977 1140cc6bd383Sdanielk1977} ;# ifcapable trigger 1141cc6bd383Sdanielk1977 114248af65aeSdanielk1977ifcapable schema_pragmas { 114348af65aeSdanielk1977 do_test pragma-11.1 { 114448af65aeSdanielk1977 execsql2 { 114548af65aeSdanielk1977 pragma collation_list; 114648af65aeSdanielk1977 } 11479b5adfa2Sdrh } {seq 0 name NOCASE seq 1 name RTRIM seq 2 name BINARY} 114848af65aeSdanielk1977 do_test pragma-11.2 { 114948af65aeSdanielk1977 db collate New_Collation blah... 115048af65aeSdanielk1977 execsql { 115148af65aeSdanielk1977 pragma collation_list; 115248af65aeSdanielk1977 } 11539b5adfa2Sdrh } {0 New_Collation 1 NOCASE 2 RTRIM 3 BINARY} 115448af65aeSdanielk1977} 115548af65aeSdanielk1977 1156ddfb2f03Sdanielk1977ifcapable schema_pragmas&&tempdb { 1157ddfb2f03Sdanielk1977 do_test pragma-12.1 { 1158ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1159ddfb2f03Sdanielk1977 execsql { 1160ddfb2f03Sdanielk1977 PRAGMA temp.table_info('abc'); 1161ddfb2f03Sdanielk1977 } db2 1162ddfb2f03Sdanielk1977 } {} 1163ddfb2f03Sdanielk1977 db2 close 1164ddfb2f03Sdanielk1977 1165ddfb2f03Sdanielk1977 do_test pragma-12.2 { 1166ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1167ddfb2f03Sdanielk1977 execsql { 1168ddfb2f03Sdanielk1977 PRAGMA temp.default_cache_size = 200; 1169ddfb2f03Sdanielk1977 PRAGMA temp.default_cache_size; 1170ddfb2f03Sdanielk1977 } db2 1171ddfb2f03Sdanielk1977 } {200} 1172ddfb2f03Sdanielk1977 db2 close 1173ddfb2f03Sdanielk1977 1174ddfb2f03Sdanielk1977 do_test pragma-12.3 { 1175ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1176ddfb2f03Sdanielk1977 execsql { 1177ddfb2f03Sdanielk1977 PRAGMA temp.cache_size = 400; 1178ddfb2f03Sdanielk1977 PRAGMA temp.cache_size; 1179ddfb2f03Sdanielk1977 } db2 1180ddfb2f03Sdanielk1977 } {400} 1181ddfb2f03Sdanielk1977 db2 close 1182ddfb2f03Sdanielk1977} 1183ddfb2f03Sdanielk1977 11844b2688abSdanielk1977ifcapable bloblit { 11854b2688abSdanielk1977 118605a82983Sdrhdo_test pragma-13.1 { 118705a82983Sdrh execsql { 118805a82983Sdrh DROP TABLE IF EXISTS t4; 118905a82983Sdrh PRAGMA vdbe_trace=on; 119005a82983Sdrh PRAGMA vdbe_listing=on; 119105a82983Sdrh PRAGMA sql_trace=on; 119205a82983Sdrh CREATE TABLE t4(a INTEGER PRIMARY KEY,b); 119305a82983Sdrh INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789'); 119405a82983Sdrh INSERT INTO t4(b) VALUES(randstr(30,30)); 119505a82983Sdrh INSERT INTO t4(b) VALUES(1.23456); 119605a82983Sdrh INSERT INTO t4(b) VALUES(NULL); 119705a82983Sdrh INSERT INTO t4(b) VALUES(0); 119805a82983Sdrh INSERT INTO t4(b) SELECT b||b||b||b FROM t4; 119905a82983Sdrh SELECT * FROM t4; 120005a82983Sdrh } 120105a82983Sdrh execsql { 120205a82983Sdrh PRAGMA vdbe_trace=off; 120305a82983Sdrh PRAGMA vdbe_listing=off; 120405a82983Sdrh PRAGMA sql_trace=off; 120505a82983Sdrh } 120605a82983Sdrh} {} 120705a82983Sdrh 12084b2688abSdanielk1977} ;# ifcapable bloblit 12094b2688abSdanielk1977 121059a93791Sdanielk1977ifcapable pager_pragmas { 121159a93791Sdanielk1977 db close 1212fda06befSmistachkin forcedelete test.db 121359a93791Sdanielk1977 sqlite3 db test.db 121459a93791Sdanielk1977 121559a93791Sdanielk1977 do_test pragma-14.1 { 121659a93791Sdanielk1977 execsql { pragma auto_vacuum = 0 } 121759a93791Sdanielk1977 execsql { pragma page_count } 121859a93791Sdanielk1977 } {0} 121959a93791Sdanielk1977 122059a93791Sdanielk1977 do_test pragma-14.2 { 122159a93791Sdanielk1977 execsql { 122259a93791Sdanielk1977 CREATE TABLE abc(a, b, c); 122359a93791Sdanielk1977 PRAGMA page_count; 122459a93791Sdanielk1977 } 122559a93791Sdanielk1977 } {2} 12265d16a9a6Sdrh do_test pragma-14.2uc { 12275d16a9a6Sdrh execsql {pragma PAGE_COUNT} 12285d16a9a6Sdrh } {2} 122959a93791Sdanielk1977 123059a93791Sdanielk1977 do_test pragma-14.3 { 123159a93791Sdanielk1977 execsql { 123259a93791Sdanielk1977 BEGIN; 123359a93791Sdanielk1977 CREATE TABLE def(a, b, c); 123459a93791Sdanielk1977 PRAGMA page_count; 123559a93791Sdanielk1977 } 123659a93791Sdanielk1977 } {3} 12375d16a9a6Sdrh do_test pragma-14.3uc { 12385d16a9a6Sdrh execsql {pragma PAGE_COUNT} 12395d16a9a6Sdrh } {3} 124059a93791Sdanielk1977 124159a93791Sdanielk1977 do_test pragma-14.4 { 124259a93791Sdanielk1977 set page_size [db one {pragma page_size}] 124359a93791Sdanielk1977 expr [file size test.db] / $page_size 124459a93791Sdanielk1977 } {2} 124559a93791Sdanielk1977 124659a93791Sdanielk1977 do_test pragma-14.5 { 124759a93791Sdanielk1977 execsql { 124859a93791Sdanielk1977 ROLLBACK; 124959a93791Sdanielk1977 PRAGMA page_count; 125059a93791Sdanielk1977 } 125159a93791Sdanielk1977 } {2} 125259a93791Sdanielk1977 125359a93791Sdanielk1977 do_test pragma-14.6 { 1254fda06befSmistachkin forcedelete test2.db 125559a93791Sdanielk1977 sqlite3 db2 test2.db 125659a93791Sdanielk1977 execsql { 125759a93791Sdanielk1977 PRAGMA auto_vacuum = 0; 125859a93791Sdanielk1977 CREATE TABLE t1(a, b, c); 125959a93791Sdanielk1977 CREATE TABLE t2(a, b, c); 126059a93791Sdanielk1977 CREATE TABLE t3(a, b, c); 126159a93791Sdanielk1977 CREATE TABLE t4(a, b, c); 126259a93791Sdanielk1977 } db2 126359a93791Sdanielk1977 db2 close 126459a93791Sdanielk1977 execsql { 126559a93791Sdanielk1977 ATTACH 'test2.db' AS aux; 126659a93791Sdanielk1977 PRAGMA aux.page_count; 126759a93791Sdanielk1977 } 126859a93791Sdanielk1977 } {5} 12695d16a9a6Sdrh do_test pragma-14.6uc { 12705d16a9a6Sdrh execsql {pragma AUX.PAGE_COUNT} 12715d16a9a6Sdrh } {5} 127259a93791Sdanielk1977} 127359a93791Sdanielk1977 12748cf6c554Sdanielk1977# Test that the value set using the cache_size pragma is not reset when the 12758cf6c554Sdanielk1977# schema is reloaded. 12768cf6c554Sdanielk1977# 12778cf6c554Sdanielk1977ifcapable pager_pragmas { 12788cf6c554Sdanielk1977 db close 12798cf6c554Sdanielk1977 sqlite3 db test.db 12808cf6c554Sdanielk1977 do_test pragma-15.1 { 12818cf6c554Sdanielk1977 execsql { 12828cf6c554Sdanielk1977 PRAGMA cache_size=59; 12838cf6c554Sdanielk1977 PRAGMA cache_size; 12848cf6c554Sdanielk1977 } 12858cf6c554Sdanielk1977 } {59} 12868cf6c554Sdanielk1977 do_test pragma-15.2 { 12878cf6c554Sdanielk1977 sqlite3 db2 test.db 12888cf6c554Sdanielk1977 execsql { 12898cf6c554Sdanielk1977 CREATE TABLE newtable(a, b, c); 12908cf6c554Sdanielk1977 } db2 12918cf6c554Sdanielk1977 db2 close 12928cf6c554Sdanielk1977 } {} 12938cf6c554Sdanielk1977 do_test pragma-15.3 { 12948cf6c554Sdanielk1977 # Evaluating this statement will cause the schema to be reloaded (because 12958cf6c554Sdanielk1977 # the schema was changed by another connection in pragma-15.2). At one 12968cf6c554Sdanielk1977 # point there was a bug that reset the cache_size to its default value 12978cf6c554Sdanielk1977 # when this happened. 12988cf6c554Sdanielk1977 execsql { SELECT * FROM sqlite_master } 12998cf6c554Sdanielk1977 execsql { PRAGMA cache_size } 13008cf6c554Sdanielk1977 } {59} 13018cf6c554Sdanielk1977} 13028cf6c554Sdanielk1977 13035558a8a6Sdanielk1977# Reset the sqlite3_temp_directory variable for the next run of tests: 13045558a8a6Sdanielk1977sqlite3 dbX :memory: 13055558a8a6Sdanielk1977dbX eval {PRAGMA temp_store_directory = ""} 13065558a8a6Sdanielk1977dbX close 13075558a8a6Sdanielk1977 1308838cce43Sdanielk1977ifcapable lock_proxy_pragmas&&prefer_proxy_locking { 1309aebf413dSaswift set sqlite_hostid_num 1 1310aebf413dSaswift 1311aebf413dSaswift set using_proxy 0 1312aebf413dSaswift foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] { 1313aebf413dSaswift set using_proxy $value 1314aebf413dSaswift } 1315aebf413dSaswift 1316aebf413dSaswift # Test the lock_proxy_file pragmas. 1317aebf413dSaswift # 1318aebf413dSaswift db close 1319aebf413dSaswift set env(SQLITE_FORCE_PROXY_LOCKING) "0" 1320aebf413dSaswift 1321aebf413dSaswift sqlite3 db test.db 1322aebf413dSaswift do_test pragma-16.1 { 1323aebf413dSaswift execsql { 1324aebf413dSaswift PRAGMA lock_proxy_file="mylittleproxy"; 1325aebf413dSaswift select * from sqlite_master; 1326aebf413dSaswift } 1327aebf413dSaswift execsql { 1328aebf413dSaswift PRAGMA lock_proxy_file; 1329aebf413dSaswift } 1330aebf413dSaswift } {mylittleproxy} 1331aebf413dSaswift 1332aebf413dSaswift do_test pragma-16.2 { 1333aebf413dSaswift sqlite3 db2 test.db 1334aebf413dSaswift execsql { 1335aebf413dSaswift PRAGMA lock_proxy_file="mylittleproxy"; 1336aebf413dSaswift } db2 1337aebf413dSaswift } {} 1338aebf413dSaswift 1339aebf413dSaswift db2 close 1340aebf413dSaswift do_test pragma-16.2.1 { 1341aebf413dSaswift sqlite3 db2 test.db 1342aebf413dSaswift execsql { 1343aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1344aebf413dSaswift select * from sqlite_master; 1345aebf413dSaswift } db2 1346aebf413dSaswift execsql { 1347aebf413dSaswift PRAGMA lock_proxy_file; 1348aebf413dSaswift } db2 1349aebf413dSaswift } {mylittleproxy} 1350aebf413dSaswift 1351aebf413dSaswift db2 close 1352aebf413dSaswift do_test pragma-16.3 { 1353aebf413dSaswift sqlite3 db2 test.db 1354aebf413dSaswift execsql { 1355aebf413dSaswift PRAGMA lock_proxy_file="myotherproxy"; 1356aebf413dSaswift } db2 1357aebf413dSaswift catchsql { 1358aebf413dSaswift select * from sqlite_master; 1359aebf413dSaswift } db2 1360aebf413dSaswift } {1 {database is locked}} 1361aebf413dSaswift 1362aebf413dSaswift do_test pragma-16.4 { 1363aebf413dSaswift db2 close 1364aebf413dSaswift db close 1365aebf413dSaswift sqlite3 db2 test.db 1366aebf413dSaswift execsql { 1367aebf413dSaswift PRAGMA lock_proxy_file="myoriginalproxy"; 1368aebf413dSaswift PRAGMA lock_proxy_file="myotherproxy"; 1369aebf413dSaswift PRAGMA lock_proxy_file; 1370aebf413dSaswift } db2 1371aebf413dSaswift } {myotherproxy} 1372aebf413dSaswift 1373aebf413dSaswift db2 close 1374aebf413dSaswift set env(SQLITE_FORCE_PROXY_LOCKING) "1" 1375aebf413dSaswift do_test pragma-16.5 { 1376aebf413dSaswift sqlite3 db2 test.db 1377aebf413dSaswift execsql { 1378aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1379aebf413dSaswift PRAGMA lock_proxy_file; 1380aebf413dSaswift } db2 1381aebf413dSaswift } {myotherproxy} 1382aebf413dSaswift 1383aebf413dSaswift do_test pragma-16.6 { 1384aebf413dSaswift db2 close 1385aebf413dSaswift sqlite3 db2 test2.db 1386aebf413dSaswift set lockpath [execsql { 1387aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1388aebf413dSaswift PRAGMA lock_proxy_file; 1389aebf413dSaswift } db2] 1390aebf413dSaswift string match "*test2.db:auto:" $lockpath 1391aebf413dSaswift } {1} 1392aebf413dSaswift 1393aebf413dSaswift set sqlite_hostid_num 2 1394aebf413dSaswift do_test pragma-16.7 { 139514d14607Sdan list [catch { 1396aebf413dSaswift sqlite3 db test2.db 1397aebf413dSaswift execsql { 1398aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1399aebf413dSaswift select * from sqlite_master; 1400aebf413dSaswift } 140114d14607Sdan } msg] $msg 1402aebf413dSaswift } {1 {database is locked}} 1403aebf413dSaswift db close 1404aebf413dSaswift 1405aebf413dSaswift do_test pragma-16.8 { 140614d14607Sdan list [catch { 1407aebf413dSaswift sqlite3 db test2.db 140814d14607Sdan execsql { select * from sqlite_master } 140914d14607Sdan } msg] $msg 1410aebf413dSaswift } {1 {database is locked}} 1411aebf413dSaswift 1412aebf413dSaswift db2 close 1413aebf413dSaswift do_test pragma-16.8.1 { 1414aebf413dSaswift execsql { 1415aebf413dSaswift PRAGMA lock_proxy_file="yetanotherproxy"; 1416aebf413dSaswift PRAGMA lock_proxy_file; 1417aebf413dSaswift } 1418aebf413dSaswift } {yetanotherproxy} 1419aebf413dSaswift do_test pragma-16.8.2 { 1420aebf413dSaswift execsql { 1421aebf413dSaswift create table mine(x); 1422aebf413dSaswift } 1423aebf413dSaswift } {} 1424aebf413dSaswift 1425aebf413dSaswift db close 1426aebf413dSaswift do_test pragma-16.9 { 1427aebf413dSaswift sqlite3 db proxytest.db 1428aebf413dSaswift set lockpath2 [execsql { 1429aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1430aebf413dSaswift PRAGMA lock_proxy_file; 1431aebf413dSaswift } db] 1432aebf413dSaswift string match "*proxytest.db:auto:" $lockpath2 1433aebf413dSaswift } {1} 1434aebf413dSaswift 1435aebf413dSaswift set env(SQLITE_FORCE_PROXY_LOCKING) $using_proxy 1436aebf413dSaswift set sqlite_hostid_num 0 1437aebf413dSaswift} 1438d2cb50b7Sdrh 1439d2cb50b7Sdrh# Parsing of auto_vacuum settings. 1440d2cb50b7Sdrh# 1441d2cb50b7Sdrhforeach {autovac_setting val} { 1442d2cb50b7Sdrh 0 0 1443d2cb50b7Sdrh 1 1 1444d2cb50b7Sdrh 2 2 1445d2cb50b7Sdrh 3 0 1446d2cb50b7Sdrh -1 0 1447d2cb50b7Sdrh none 0 1448d2cb50b7Sdrh NONE 0 1449d2cb50b7Sdrh NoNe 0 1450d2cb50b7Sdrh full 1 1451d2cb50b7Sdrh FULL 1 1452d2cb50b7Sdrh incremental 2 1453d2cb50b7Sdrh INCREMENTAL 2 1454d2cb50b7Sdrh -1234 0 1455d2cb50b7Sdrh 1234 0 1456d2cb50b7Sdrh} { 1457d2cb50b7Sdrh do_test pragma-17.1.$autovac_setting { 1458d2cb50b7Sdrh catch {db close} 1459d2cb50b7Sdrh sqlite3 db :memory: 1460d2cb50b7Sdrh execsql " 1461d2cb50b7Sdrh PRAGMA auto_vacuum=$::autovac_setting; 1462d2cb50b7Sdrh PRAGMA auto_vacuum; 1463d2cb50b7Sdrh " 1464d2cb50b7Sdrh } $val 1465d2cb50b7Sdrh} 1466d2cb50b7Sdrh 1467d2cb50b7Sdrh# Parsing of temp_store settings. 1468d2cb50b7Sdrh# 1469d2cb50b7Sdrhforeach {temp_setting val} { 1470d2cb50b7Sdrh 0 0 1471d2cb50b7Sdrh 1 1 1472d2cb50b7Sdrh 2 2 1473d2cb50b7Sdrh 3 0 1474d2cb50b7Sdrh -1 0 1475d2cb50b7Sdrh file 1 1476d2cb50b7Sdrh FILE 1 1477d2cb50b7Sdrh fIlE 1 1478d2cb50b7Sdrh memory 2 1479d2cb50b7Sdrh MEMORY 2 1480d2cb50b7Sdrh MeMoRy 2 1481d2cb50b7Sdrh} { 1482d2cb50b7Sdrh do_test pragma-18.1.$temp_setting { 1483d2cb50b7Sdrh catch {db close} 1484d2cb50b7Sdrh sqlite3 db :memory: 1485d2cb50b7Sdrh execsql " 1486d2cb50b7Sdrh PRAGMA temp_store=$::temp_setting; 1487d2cb50b7Sdrh PRAGMA temp_store=$::temp_setting; 1488d2cb50b7Sdrh PRAGMA temp_store; 1489d2cb50b7Sdrh " 1490d2cb50b7Sdrh } $val 1491d2cb50b7Sdrh} 1492d2cb50b7Sdrh 149392c700dbSdrh# The SQLITE_FCNTL_PRAGMA logic, with error handling. 149492c700dbSdrh# 149592c700dbSdrhdb close 149692c700dbSdrhtestvfs tvfs 149792c700dbSdrhsqlite3 db test.db -vfs tvfs 149892c700dbSdrhdo_test pragma-19.1 { 149992c700dbSdrh catchsql {PRAGMA error} 150092c700dbSdrh} {1 {SQL logic error or missing database}} 150192c700dbSdrhdo_test pragma-19.2 { 150292c700dbSdrh catchsql {PRAGMA error='This is the error message'} 150392c700dbSdrh} {1 {This is the error message}} 150492c700dbSdrhdo_test pragma-19.3 { 150592c700dbSdrh catchsql {PRAGMA error='7 This is the error message'} 150692c700dbSdrh} {1 {This is the error message}} 150792c700dbSdrhdo_test pragma-19.4 { 150892c700dbSdrh catchsql {PRAGMA error=7} 150992c700dbSdrh} {1 {out of memory}} 1510c8517f61Sdrhdo_test pragma-19.5 { 15115b044545Smistachkin file tail [lindex [execsql {PRAGMA filename}] 0] 1512c8517f61Sdrh} {test.db} 151392c700dbSdrh 1514cc71645bSdrhif {$tcl_platform(platform)=="windows"} { 1515*a112d140Smistachkin# Test data_store_directory pragma 1516*a112d140Smistachkin# 1517*a112d140Smistachkindb close 1518*a112d140Smistachkinsqlite3 db test.db 1519*a112d140Smistachkinfile mkdir data_dir 1520*a112d140Smistachkindo_test pragma-20.1 { 1521*a112d140Smistachkin catchsql {PRAGMA data_store_directory} 1522*a112d140Smistachkin} {0 {}} 1523*a112d140Smistachkindo_test pragma-20.2 { 1524*a112d140Smistachkin set pwd [string map {' ''} [file nativename [get_pwd]]] 1525*a112d140Smistachkin catchsql "PRAGMA data_store_directory='$pwd';" 1526*a112d140Smistachkin} {0 {}} 1527*a112d140Smistachkindo_test pragma-20.3 { 1528*a112d140Smistachkin catchsql {PRAGMA data_store_directory} 1529*a112d140Smistachkin} [list 0 [list [file nativename [get_pwd]]]] 1530*a112d140Smistachkindo_test pragma-20.4 { 1531*a112d140Smistachkin set pwd [string map {' ''} [file nativename \ 1532*a112d140Smistachkin [file join [get_pwd] data_dir]]] 1533*a112d140Smistachkin catchsql "PRAGMA data_store_directory='$pwd';" 1534*a112d140Smistachkin} {0 {}} 1535*a112d140Smistachkindo_test pragma-20.5 { 1536*a112d140Smistachkin sqlite3 db2 test2.db 1537*a112d140Smistachkin catchsql "PRAGMA database_list;" db2 1538*a112d140Smistachkin} [list 0 [list 0 main [file nativename \ 1539*a112d140Smistachkin [file join [get_pwd] data_dir test2.db]]]] 1540*a112d140Smistachkincatch {db2 close} 1541*a112d140Smistachkindo_test pragma-20.6 { 1542*a112d140Smistachkin sqlite3 db2 [file join [get_pwd] test2.db] 1543*a112d140Smistachkin catchsql "PRAGMA database_list;" db2 1544*a112d140Smistachkin} [list 0 [list 0 main [file nativename \ 1545*a112d140Smistachkin [file join [get_pwd] test2.db]]]] 1546*a112d140Smistachkincatch {db2 close} 1547*a112d140Smistachkindo_test pragma-20.7 { 1548*a112d140Smistachkin catchsql "PRAGMA data_store_directory='';" 1549*a112d140Smistachkin} {0 {}} 1550*a112d140Smistachkindo_test pragma-20.8 { 1551*a112d140Smistachkin catchsql {PRAGMA data_store_directory} 1552*a112d140Smistachkin} {0 {}} 155392c700dbSdrh 1554*a112d140Smistachkinforcedelete data_dir 1555cc71645bSdrh} ;# endif windows 1556cd61c281Sdrh 1557cd61c281Sdrhfinish_test 1558