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*417ec638Sdrh# $Id: pragma.test,v 1.44 2006/08/14 14:23:43 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 45cd61c281Sdrhfile delete test.db 46dddca286Sdrhsqlite3 db test.db; set DB [sqlite3_connection_pointer db] 47cd61c281Sdrh 48c7b4a44cSdanielk1977ifcapable pager_pragmas { 49cd61c281Sdrhdo_test pragma-1.1 { 50cd61c281Sdrh execsql { 51cd61c281Sdrh PRAGMA cache_size; 52cd61c281Sdrh PRAGMA default_cache_size; 53cd61c281Sdrh PRAGMA synchronous; 54cd61c281Sdrh } 5591cf71b0Sdanielk1977} {2000 2000 2} 56cd61c281Sdrhdo_test pragma-1.2 { 57cd61c281Sdrh execsql { 58eb43e5c7Sdrh PRAGMA synchronous=OFF; 59cd61c281Sdrh PRAGMA cache_size=1234; 60cd61c281Sdrh PRAGMA cache_size; 61cd61c281Sdrh PRAGMA default_cache_size; 62cd61c281Sdrh PRAGMA synchronous; 63cd61c281Sdrh } 64eb43e5c7Sdrh} {1234 2000 0} 65cd61c281Sdrhdo_test pragma-1.3 { 66cd61c281Sdrh db close 67ef4ac8f9Sdrh sqlite3 db test.db 68cd61c281Sdrh execsql { 69cd61c281Sdrh PRAGMA cache_size; 70cd61c281Sdrh PRAGMA default_cache_size; 71cd61c281Sdrh PRAGMA synchronous; 72cd61c281Sdrh } 7391cf71b0Sdanielk1977} {2000 2000 2} 74cd61c281Sdrhdo_test pragma-1.4 { 75cd61c281Sdrh execsql { 76cd61c281Sdrh PRAGMA synchronous=OFF; 77cd61c281Sdrh PRAGMA cache_size; 78cd61c281Sdrh PRAGMA default_cache_size; 79cd61c281Sdrh PRAGMA synchronous; 80cd61c281Sdrh } 8191cf71b0Sdanielk1977} {2000 2000 0} 82cd61c281Sdrhdo_test pragma-1.5 { 83cd61c281Sdrh execsql { 84cd61c281Sdrh PRAGMA cache_size=4321; 85cd61c281Sdrh PRAGMA cache_size; 86cd61c281Sdrh PRAGMA default_cache_size; 87cd61c281Sdrh PRAGMA synchronous; 88cd61c281Sdrh } 8991cf71b0Sdanielk1977} {4321 2000 0} 90cd61c281Sdrhdo_test pragma-1.6 { 91cd61c281Sdrh execsql { 92cd61c281Sdrh PRAGMA synchronous=ON; 93cd61c281Sdrh PRAGMA cache_size; 94cd61c281Sdrh PRAGMA default_cache_size; 95cd61c281Sdrh PRAGMA synchronous; 96cd61c281Sdrh } 9791cf71b0Sdanielk1977} {4321 2000 1} 98cd61c281Sdrhdo_test pragma-1.7 { 99cd61c281Sdrh db close 100ef4ac8f9Sdrh sqlite3 db test.db 101cd61c281Sdrh execsql { 102cd61c281Sdrh PRAGMA cache_size; 103cd61c281Sdrh PRAGMA default_cache_size; 104cd61c281Sdrh PRAGMA synchronous; 105cd61c281Sdrh } 10691cf71b0Sdanielk1977} {2000 2000 2} 107cd61c281Sdrhdo_test pragma-1.8 { 108cd61c281Sdrh execsql { 109cd61c281Sdrh PRAGMA default_cache_size=123; 110cd61c281Sdrh PRAGMA cache_size; 111cd61c281Sdrh PRAGMA default_cache_size; 112cd61c281Sdrh PRAGMA synchronous; 113cd61c281Sdrh } 11491cf71b0Sdanielk1977} {123 123 2} 115802d69a7Sdrhdo_test pragma-1.9.1 { 116cd61c281Sdrh db close 117dddca286Sdrh sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db] 118cd61c281Sdrh execsql { 119cd61c281Sdrh PRAGMA cache_size; 120cd61c281Sdrh PRAGMA default_cache_size; 121cd61c281Sdrh PRAGMA synchronous; 122cd61c281Sdrh } 12391cf71b0Sdanielk1977} {123 123 2} 124802d69a7Sdrhifcapable vacuum { 125802d69a7Sdrh do_test pragma-1.9.2 { 126802d69a7Sdrh execsql { 127802d69a7Sdrh VACUUM; 128802d69a7Sdrh PRAGMA cache_size; 129802d69a7Sdrh PRAGMA default_cache_size; 130802d69a7Sdrh PRAGMA synchronous; 131802d69a7Sdrh } 132802d69a7Sdrh } {123 123 2} 133802d69a7Sdrh} 13491cf71b0Sdanielk1977do_test pragma-1.10 { 1355a38705eSdrh execsql { 1364303feedSdrh PRAGMA synchronous=NORMAL; 1374303feedSdrh PRAGMA cache_size; 1384303feedSdrh PRAGMA default_cache_size; 1394303feedSdrh PRAGMA synchronous; 1404303feedSdrh } 14191cf71b0Sdanielk1977} {123 123 1} 14291cf71b0Sdanielk1977do_test pragma-1.11 { 1434303feedSdrh execsql { 1444303feedSdrh PRAGMA synchronous=FULL; 1454303feedSdrh PRAGMA cache_size; 1464303feedSdrh PRAGMA default_cache_size; 1474303feedSdrh PRAGMA synchronous; 1484303feedSdrh } 14991cf71b0Sdanielk1977} {123 123 2} 15091cf71b0Sdanielk1977do_test pragma-1.12 { 1514303feedSdrh db close 152dddca286Sdrh sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db] 1534303feedSdrh execsql { 1544303feedSdrh PRAGMA cache_size; 1554303feedSdrh PRAGMA default_cache_size; 1564303feedSdrh PRAGMA synchronous; 1574303feedSdrh } 15891cf71b0Sdanielk1977} {123 123 2} 15991cf71b0Sdanielk1977 1605260f7e9Sdrh# Make sure the pragma handler understands numeric values in addition 1615260f7e9Sdrh# to keywords like "off" and "full". 1625260f7e9Sdrh# 1635260f7e9Sdrhdo_test pragma-1.13 { 1645260f7e9Sdrh execsql { 1655260f7e9Sdrh PRAGMA synchronous=0; 1665260f7e9Sdrh PRAGMA synchronous; 1675260f7e9Sdrh } 1685260f7e9Sdrh} {0} 1695260f7e9Sdrhdo_test pragma-1.14 { 1705260f7e9Sdrh execsql { 1715260f7e9Sdrh PRAGMA synchronous=2; 1725260f7e9Sdrh PRAGMA synchronous; 1735260f7e9Sdrh } 1745260f7e9Sdrh} {2} 175c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 1765260f7e9Sdrh 1775260f7e9Sdrh# Test turning "flag" pragmas on and off. 1785260f7e9Sdrh# 1795260f7e9Sdrhdo_test pragma-1.15 { 1805260f7e9Sdrh execsql { 1815260f7e9Sdrh PRAGMA vdbe_listing=YES; 1825260f7e9Sdrh PRAGMA vdbe_listing; 1835260f7e9Sdrh } 1845260f7e9Sdrh} {1} 1855260f7e9Sdrhdo_test pragma-1.16 { 1865260f7e9Sdrh execsql { 1875260f7e9Sdrh PRAGMA vdbe_listing=NO; 1885260f7e9Sdrh PRAGMA vdbe_listing; 1895260f7e9Sdrh } 1905260f7e9Sdrh} {0} 1915260f7e9Sdrhdo_test pragma-1.17 { 1925260f7e9Sdrh execsql { 1935260f7e9Sdrh PRAGMA parser_trace=ON; 1945260f7e9Sdrh PRAGMA parser_trace=OFF; 1955260f7e9Sdrh } 1965260f7e9Sdrh} {} 1975260f7e9Sdrhdo_test pragma-1.18 { 1985260f7e9Sdrh execsql { 1995260f7e9Sdrh PRAGMA bogus = -1234; -- Parsing of negative values 2005260f7e9Sdrh } 2015260f7e9Sdrh} {} 2025260f7e9Sdrh 20391cf71b0Sdanielk1977# Test modifying the safety_level of an attached database. 20491cf71b0Sdanielk1977do_test pragma-2.1 { 20591cf71b0Sdanielk1977 file delete -force test2.db 20691cf71b0Sdanielk1977 file delete -force test2.db-journal 2074303feedSdrh execsql { 20891cf71b0Sdanielk1977 ATTACH 'test2.db' AS aux; 2094303feedSdrh } 21091cf71b0Sdanielk1977} {} 211c7b4a44cSdanielk1977ifcapable pager_pragmas { 21291cf71b0Sdanielk1977do_test pragma-2.2 { 2134303feedSdrh execsql { 21491cf71b0Sdanielk1977 pragma aux.synchronous; 2154303feedSdrh } 21691cf71b0Sdanielk1977} {2} 21791cf71b0Sdanielk1977do_test pragma-2.3 { 21891cf71b0Sdanielk1977 execsql { 21991cf71b0Sdanielk1977 pragma aux.synchronous = OFF; 22091cf71b0Sdanielk1977 pragma aux.synchronous; 22191cf71b0Sdanielk1977 pragma synchronous; 22291cf71b0Sdanielk1977 } 22391cf71b0Sdanielk1977} {0 2} 22491cf71b0Sdanielk1977do_test pragma-2.4 { 22591cf71b0Sdanielk1977 execsql { 22691cf71b0Sdanielk1977 pragma aux.synchronous = ON; 22791cf71b0Sdanielk1977 pragma synchronous; 22891cf71b0Sdanielk1977 pragma aux.synchronous; 22991cf71b0Sdanielk1977 } 23091cf71b0Sdanielk1977} {2 1} 231c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 2324303feedSdrh 233ed717fe3Sdrh# Construct a corrupted index and make sure the integrity_check 234ed717fe3Sdrh# pragma finds it. 235ed717fe3Sdrh# 23625d6543dSdrh# These tests won't work if the database is encrypted 23725d6543dSdrh# 238ed717fe3Sdrhdo_test pragma-3.1 { 239ed717fe3Sdrh execsql { 240ed717fe3Sdrh BEGIN; 241ed717fe3Sdrh CREATE TABLE t2(a,b,c); 242ed717fe3Sdrh CREATE INDEX i2 ON t2(a); 243ed717fe3Sdrh INSERT INTO t2 VALUES(11,2,3); 244ed717fe3Sdrh INSERT INTO t2 VALUES(22,3,4); 245ed717fe3Sdrh COMMIT; 246ed717fe3Sdrh SELECT rowid, * from t2; 247ed717fe3Sdrh } 248ed717fe3Sdrh} {1 11 2 3 2 22 3 4} 24940e016e4Sdrhif {![sqlite3 -has-codec] && $sqlite_options(integrityck)} { 250ed717fe3Sdrh do_test pragma-3.2 { 251ed717fe3Sdrh set rootpage [execsql {SELECT rootpage FROM sqlite_master WHERE name='i2'}] 25296fc5fe6Sdanielk1977 set db [btree_open test.db 100 0] 253ed717fe3Sdrh btree_begin_transaction $db 254ed717fe3Sdrh set c [btree_cursor $db $rootpage 1] 255ed717fe3Sdrh btree_first $c 256ed717fe3Sdrh btree_delete $c 257ed717fe3Sdrh btree_commit $db 258ed717fe3Sdrh btree_close $db 259ed717fe3Sdrh execsql {PRAGMA integrity_check} 2604be295beSdrh } {{rowid 1 missing from index i2} {wrong # of entries in index i2}} 26125d6543dSdrh} 26291cf71b0Sdanielk1977do_test pragma-3.3 { 26391cf71b0Sdanielk1977 execsql { 26491cf71b0Sdanielk1977 DROP INDEX i2; 26591cf71b0Sdanielk1977 } 26691cf71b0Sdanielk1977} {} 26791cf71b0Sdanielk1977 26891cf71b0Sdanielk1977# Test modifying the cache_size of an attached database. 269c7b4a44cSdanielk1977ifcapable pager_pragmas { 27091cf71b0Sdanielk1977do_test pragma-4.1 { 27191cf71b0Sdanielk1977 execsql { 27291cf71b0Sdanielk1977 pragma aux.cache_size; 27391cf71b0Sdanielk1977 pragma aux.default_cache_size; 27491cf71b0Sdanielk1977 } 27591cf71b0Sdanielk1977} {2000 2000} 2761bdd9b57Sdrhdo_test pragma-4.2 { 2771bdd9b57Sdrh execsql { 27891cf71b0Sdanielk1977 pragma aux.cache_size = 50; 27991cf71b0Sdanielk1977 pragma aux.cache_size; 28091cf71b0Sdanielk1977 pragma aux.default_cache_size; 2811bdd9b57Sdrh } 28291cf71b0Sdanielk1977} {50 2000} 2831bdd9b57Sdrhdo_test pragma-4.3 { 2841bdd9b57Sdrh execsql { 28591cf71b0Sdanielk1977 pragma aux.default_cache_size = 456; 28691cf71b0Sdanielk1977 pragma aux.cache_size; 28791cf71b0Sdanielk1977 pragma aux.default_cache_size; 2881bdd9b57Sdrh } 28991cf71b0Sdanielk1977} {456 456} 2901bdd9b57Sdrhdo_test pragma-4.4 { 2911bdd9b57Sdrh execsql { 29291cf71b0Sdanielk1977 pragma cache_size; 29391cf71b0Sdanielk1977 pragma default_cache_size; 2941bdd9b57Sdrh } 29591cf71b0Sdanielk1977} {123 123} 2961bdd9b57Sdrhdo_test pragma-4.5 { 2971bdd9b57Sdrh execsql { 29891cf71b0Sdanielk1977 DETACH aux; 29991cf71b0Sdanielk1977 ATTACH 'test3.db' AS aux; 30091cf71b0Sdanielk1977 pragma aux.cache_size; 30191cf71b0Sdanielk1977 pragma aux.default_cache_size; 3021bdd9b57Sdrh } 30391cf71b0Sdanielk1977} {2000 2000} 3041bdd9b57Sdrhdo_test pragma-4.6 { 3051bdd9b57Sdrh execsql { 30691cf71b0Sdanielk1977 DETACH aux; 30791cf71b0Sdanielk1977 ATTACH 'test2.db' AS aux; 30891cf71b0Sdanielk1977 pragma aux.cache_size; 30991cf71b0Sdanielk1977 pragma aux.default_cache_size; 3101bdd9b57Sdrh } 31191cf71b0Sdanielk1977} {456 456} 312c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 3131bdd9b57Sdrh 31491cf71b0Sdanielk1977# Test that modifying the sync-level in the middle of a transaction is 31591cf71b0Sdanielk1977# disallowed. 316c7b4a44cSdanielk1977ifcapable pager_pragmas { 31791cf71b0Sdanielk1977do_test pragma-5.0 { 3181bdd9b57Sdrh execsql { 31991cf71b0Sdanielk1977 pragma synchronous; 3201bdd9b57Sdrh } 32191cf71b0Sdanielk1977} {2} 32291cf71b0Sdanielk1977do_test pragma-5.1 { 3231bdd9b57Sdrh catchsql { 3241bdd9b57Sdrh BEGIN; 32591cf71b0Sdanielk1977 pragma synchronous = OFF; 3261bdd9b57Sdrh } 32791cf71b0Sdanielk1977} {1 {Safety level may not be changed inside a transaction}} 32891cf71b0Sdanielk1977do_test pragma-5.2 { 32991cf71b0Sdanielk1977 execsql { 33091cf71b0Sdanielk1977 pragma synchronous; 33191cf71b0Sdanielk1977 } 33291cf71b0Sdanielk1977} {2} 3335260f7e9Sdrhcatchsql {COMMIT;} 334c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 3355260f7e9Sdrh 3365260f7e9Sdrh# Test schema-query pragmas 3375260f7e9Sdrh# 33827188fb5Sdanielk1977ifcapable schema_pragmas { 33953c0f748Sdanielk1977ifcapable tempdb { 3405260f7e9Sdrh do_test pragma-6.1 { 341956bc92cSdrh set res {} 34240e016e4Sdrh execsql {SELECT * FROM sqlite_temp_master} 3435260f7e9Sdrh foreach {idx name file} [execsql {pragma database_list}] { 3445260f7e9Sdrh lappend res $idx $name 3455260f7e9Sdrh } 3465260f7e9Sdrh set res 347a71aa001Sdrh } {0 main 1 temp 2 aux} 34853c0f748Sdanielk1977} 3495260f7e9Sdrhdo_test pragma-6.2 { 3505260f7e9Sdrh execsql { 3515260f7e9Sdrh pragma table_info(t2) 3525260f7e9Sdrh } 353bfa8b102Sdrh} {0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0} 354*417ec638Sdrhdo_test pragma-6.2.2 { 355*417ec638Sdrh execsql { 356*417ec638Sdrh CREATE TABLE t5(a TEXT DEFAULT CURRENT_TIMESTAMP, b DEFAULT (5+3)); 357*417ec638Sdrh PRAGMA table_info(t5); 358*417ec638Sdrh } 359*417ec638Sdrh} {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 0} 3606bf89570Sdrhifcapable {foreignkey} { 3615260f7e9Sdrh do_test pragma-6.3 { 3625260f7e9Sdrh execsql { 3635260f7e9Sdrh CREATE TABLE t3(a int references t2(b), b UNIQUE); 3645260f7e9Sdrh pragma foreign_key_list(t3); 3655260f7e9Sdrh } 3665260f7e9Sdrh } {0 0 t2 a b} 3675260f7e9Sdrh do_test pragma-6.4 { 3685260f7e9Sdrh execsql { 3695260f7e9Sdrh pragma index_list(t3); 3705260f7e9Sdrh } 3715260f7e9Sdrh } {0 sqlite_autoindex_t3_1 1} 3726bf89570Sdrh} 3736bf89570Sdrhifcapable {!foreignkey} { 3746bf89570Sdrh execsql {CREATE TABLE t3(a,b UNIQUE)} 3756bf89570Sdrh} 3765260f7e9Sdrhdo_test pragma-6.5 { 3775260f7e9Sdrh execsql { 3785260f7e9Sdrh CREATE INDEX t3i1 ON t3(a,b); 3795260f7e9Sdrh pragma index_info(t3i1); 3805260f7e9Sdrh } 3815260f7e9Sdrh} {0 0 a 1 1 b} 38227188fb5Sdanielk1977} ;# ifcapable schema_pragmas 3835260f7e9Sdrh# Miscellaneous tests 3845260f7e9Sdrh# 38527188fb5Sdanielk1977ifcapable schema_pragmas { 3865260f7e9Sdrhdo_test pragma-7.1 { 3875260f7e9Sdrh # Make sure a pragma knows to read the schema if it needs to 3885260f7e9Sdrh db close 3895260f7e9Sdrh sqlite3 db test.db 3905260f7e9Sdrh execsql { 3915260f7e9Sdrh pragma index_list(t3); 3925260f7e9Sdrh } 3935260f7e9Sdrh} {0 t3i1 0 1 sqlite_autoindex_t3_1 1} 39427188fb5Sdanielk1977} ;# ifcapable schema_pragmas 3956c62608fSdrhifcapable {utf16} { 3965260f7e9Sdrh do_test pragma-7.2 { 3975260f7e9Sdrh db close 3985260f7e9Sdrh sqlite3 db test.db 3995260f7e9Sdrh catchsql { 4005260f7e9Sdrh pragma encoding=bogus; 4015260f7e9Sdrh } 4025260f7e9Sdrh } {1 {unsupported encoding: bogus}} 4036c62608fSdrh} 40453c0f748Sdanielk1977ifcapable tempdb { 4055260f7e9Sdrh do_test pragma-7.3 { 4065260f7e9Sdrh db close 4075260f7e9Sdrh sqlite3 db test.db 4085260f7e9Sdrh execsql { 4095260f7e9Sdrh pragma lock_status; 4105260f7e9Sdrh } 4115260f7e9Sdrh } {main unlocked temp closed} 41253c0f748Sdanielk1977} else { 41353c0f748Sdanielk1977 do_test pragma-7.3 { 41453c0f748Sdanielk1977 db close 41553c0f748Sdanielk1977 sqlite3 db test.db 41653c0f748Sdanielk1977 execsql { 41753c0f748Sdanielk1977 pragma lock_status; 41853c0f748Sdanielk1977 } 41953c0f748Sdanielk1977 } {main unlocked} 42053c0f748Sdanielk1977} 4215260f7e9Sdrh 4225260f7e9Sdrh 423dae2495bSdanielk1977#---------------------------------------------------------------------- 424b92b70bbSdanielk1977# Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA 425b92b70bbSdanielk1977# user_version" statements. 426dae2495bSdanielk1977# 427b92b70bbSdanielk1977# pragma-8.1: PRAGMA schema_version 428b92b70bbSdanielk1977# pragma-8.2: PRAGMA user_version 429dae2495bSdanielk1977# 430dae2495bSdanielk1977 43111cf9fbcSdanielk1977ifcapable schema_version { 43211cf9fbcSdanielk1977 433b92b70bbSdanielk1977# First check that we can set the schema version and then retrieve the 434dae2495bSdanielk1977# same value. 435dae2495bSdanielk1977do_test pragma-8.1.1 { 436dae2495bSdanielk1977 execsql { 437b92b70bbSdanielk1977 PRAGMA schema_version = 105; 438dae2495bSdanielk1977 } 439dae2495bSdanielk1977} {} 440dae2495bSdanielk1977do_test pragma-8.1.2 { 441dae2495bSdanielk1977 execsql { 442b92b70bbSdanielk1977 PRAGMA schema_version; 443dae2495bSdanielk1977 } 444dae2495bSdanielk1977} 105 445dae2495bSdanielk1977do_test pragma-8.1.3 { 446dae2495bSdanielk1977 execsql { 447b92b70bbSdanielk1977 PRAGMA schema_version = 106; 448dae2495bSdanielk1977 } 449dae2495bSdanielk1977} {} 450dae2495bSdanielk1977do_test pragma-8.1.4 { 451dae2495bSdanielk1977 execsql { 452b92b70bbSdanielk1977 PRAGMA schema_version; 453dae2495bSdanielk1977 } 454dae2495bSdanielk1977} 106 455dae2495bSdanielk1977 456b92b70bbSdanielk1977# Check that creating a table modifies the schema-version (this is really 457b92b70bbSdanielk1977# to verify that the value being read is in fact the schema version). 458dae2495bSdanielk1977do_test pragma-8.1.5 { 459dae2495bSdanielk1977 execsql { 460dae2495bSdanielk1977 CREATE TABLE t4(a, b, c); 461dae2495bSdanielk1977 INSERT INTO t4 VALUES(1, 2, 3); 462dae2495bSdanielk1977 SELECT * FROM t4; 463dae2495bSdanielk1977 } 464dae2495bSdanielk1977} {1 2 3} 465dae2495bSdanielk1977do_test pragma-8.1.6 { 466dae2495bSdanielk1977 execsql { 467b92b70bbSdanielk1977 PRAGMA schema_version; 468dae2495bSdanielk1977 } 469dae2495bSdanielk1977} 107 470dae2495bSdanielk1977 471dae2495bSdanielk1977# Now open a second connection to the database. Ensure that changing the 472b92b70bbSdanielk1977# schema-version using the first connection forces the second connection 473dae2495bSdanielk1977# to reload the schema. This has to be done using the C-API test functions, 474dae2495bSdanielk1977# because the TCL API accounts for SCHEMA_ERROR and retries the query. 475dae2495bSdanielk1977do_test pragma-8.1.7 { 476dddca286Sdrh sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] 477dae2495bSdanielk1977 execsql { 478dae2495bSdanielk1977 SELECT * FROM t4; 479dae2495bSdanielk1977 } db2 480dae2495bSdanielk1977} {1 2 3} 481dae2495bSdanielk1977do_test pragma-8.1.8 { 482dae2495bSdanielk1977 execsql { 483b92b70bbSdanielk1977 PRAGMA schema_version = 108; 484dae2495bSdanielk1977 } 485dae2495bSdanielk1977} {} 486dae2495bSdanielk1977do_test pragma-8.1.9 { 487dae2495bSdanielk1977 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY] 488dae2495bSdanielk1977 sqlite3_step $::STMT 489dae2495bSdanielk1977} SQLITE_ERROR 490dae2495bSdanielk1977do_test pragma-8.1.10 { 491dae2495bSdanielk1977 sqlite3_finalize $::STMT 492dae2495bSdanielk1977} SQLITE_SCHEMA 493dae2495bSdanielk1977 494b92b70bbSdanielk1977# Make sure the schema-version can be manipulated in an attached database. 495dae2495bSdanielk1977file delete -force test2.db 496dae2495bSdanielk1977file delete -force test2.db-journal 497dae2495bSdanielk1977do_test pragma-8.1.11 { 498dae2495bSdanielk1977 execsql { 499dae2495bSdanielk1977 ATTACH 'test2.db' AS aux; 500dae2495bSdanielk1977 CREATE TABLE aux.t1(a, b, c); 501b92b70bbSdanielk1977 PRAGMA aux.schema_version = 205; 502dae2495bSdanielk1977 } 503dae2495bSdanielk1977} {} 504dae2495bSdanielk1977do_test pragma-8.1.12 { 505dae2495bSdanielk1977 execsql { 506b92b70bbSdanielk1977 PRAGMA aux.schema_version; 507dae2495bSdanielk1977 } 508dae2495bSdanielk1977} 205 509dae2495bSdanielk1977do_test pragma-8.1.13 { 510dae2495bSdanielk1977 execsql { 511b92b70bbSdanielk1977 PRAGMA schema_version; 512dae2495bSdanielk1977 } 513dae2495bSdanielk1977} 108 514dae2495bSdanielk1977 515b92b70bbSdanielk1977# And check that modifying the schema-version in an attached database 516dae2495bSdanielk1977# forces the second connection to reload the schema. 517dae2495bSdanielk1977do_test pragma-8.1.14 { 518dddca286Sdrh sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] 519dae2495bSdanielk1977 execsql { 520dae2495bSdanielk1977 ATTACH 'test2.db' AS aux; 521dae2495bSdanielk1977 SELECT * FROM aux.t1; 522dae2495bSdanielk1977 } db2 523dae2495bSdanielk1977} {} 524dae2495bSdanielk1977do_test pragma-8.1.15 { 525dae2495bSdanielk1977 execsql { 526b92b70bbSdanielk1977 PRAGMA aux.schema_version = 206; 527dae2495bSdanielk1977 } 528dae2495bSdanielk1977} {} 529dae2495bSdanielk1977do_test pragma-8.1.16 { 530dae2495bSdanielk1977 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY] 531dae2495bSdanielk1977 sqlite3_step $::STMT 532dae2495bSdanielk1977} SQLITE_ERROR 533dae2495bSdanielk1977do_test pragma-8.1.17 { 534dae2495bSdanielk1977 sqlite3_finalize $::STMT 535dae2495bSdanielk1977} SQLITE_SCHEMA 536dae2495bSdanielk1977do_test pragma-8.1.18 { 537dae2495bSdanielk1977 db2 close 538dae2495bSdanielk1977} {} 539dae2495bSdanielk1977 540b92b70bbSdanielk1977# Now test that the user-version can be read and written (and that we aren't 541b92b70bbSdanielk1977# accidentally manipulating the schema-version instead). 542dae2495bSdanielk1977do_test pragma-8.2.1 { 543dae2495bSdanielk1977 execsql { 544b92b70bbSdanielk1977 PRAGMA user_version; 545dae2495bSdanielk1977 } 546dae2495bSdanielk1977} {0} 547dae2495bSdanielk1977do_test pragma-8.2.2 { 548dae2495bSdanielk1977 execsql { 549b92b70bbSdanielk1977 PRAGMA user_version = 2; 550dae2495bSdanielk1977 } 551dae2495bSdanielk1977} {} 552802d69a7Sdrhdo_test pragma-8.2.3.1 { 553dae2495bSdanielk1977 execsql { 554b92b70bbSdanielk1977 PRAGMA user_version; 555dae2495bSdanielk1977 } 556dae2495bSdanielk1977} {2} 557802d69a7Sdrhdo_test pragma-8.2.3.2 { 558802d69a7Sdrh db close 559802d69a7Sdrh sqlite3 db test.db 560802d69a7Sdrh execsql { 561802d69a7Sdrh PRAGMA user_version; 562802d69a7Sdrh } 563802d69a7Sdrh} {2} 564802d69a7Sdrhdo_test pragma-8.2.4.1 { 565dae2495bSdanielk1977 execsql { 566b92b70bbSdanielk1977 PRAGMA schema_version; 567dae2495bSdanielk1977 } 568dae2495bSdanielk1977} {108} 569802d69a7Sdrhifcapable vacuum { 570802d69a7Sdrh do_test pragma-8.2.4.2 { 571802d69a7Sdrh execsql { 572802d69a7Sdrh VACUUM; 573802d69a7Sdrh PRAGMA user_version; 574802d69a7Sdrh } 575802d69a7Sdrh } {2} 576802d69a7Sdrh do_test pragma-8.2.4.3 { 577802d69a7Sdrh execsql { 578802d69a7Sdrh PRAGMA schema_version; 579802d69a7Sdrh } 580802d69a7Sdrh } {109} 581802d69a7Sdrh} 582802d69a7Sdrhdb eval {ATTACH 'test2.db' AS aux} 583dae2495bSdanielk1977 584b92b70bbSdanielk1977# Check that the user-version in the auxilary database can be manipulated ( 585dae2495bSdanielk1977# and that we aren't accidentally manipulating the same in the main db). 586dae2495bSdanielk1977do_test pragma-8.2.5 { 587dae2495bSdanielk1977 execsql { 588b92b70bbSdanielk1977 PRAGMA aux.user_version; 589dae2495bSdanielk1977 } 590dae2495bSdanielk1977} {0} 591dae2495bSdanielk1977do_test pragma-8.2.6 { 592dae2495bSdanielk1977 execsql { 593b92b70bbSdanielk1977 PRAGMA aux.user_version = 3; 594dae2495bSdanielk1977 } 595dae2495bSdanielk1977} {} 596dae2495bSdanielk1977do_test pragma-8.2.7 { 597dae2495bSdanielk1977 execsql { 598b92b70bbSdanielk1977 PRAGMA aux.user_version; 599dae2495bSdanielk1977 } 600dae2495bSdanielk1977} {3} 601dae2495bSdanielk1977do_test pragma-8.2.8 { 602dae2495bSdanielk1977 execsql { 603b92b70bbSdanielk1977 PRAGMA main.user_version; 604dae2495bSdanielk1977 } 605dae2495bSdanielk1977} {2} 606dae2495bSdanielk1977 607b92b70bbSdanielk1977# Now check that a ROLLBACK resets the user-version if it has been modified 608dae2495bSdanielk1977# within a transaction. 609dae2495bSdanielk1977do_test pragma-8.2.9 { 610dae2495bSdanielk1977 execsql { 611dae2495bSdanielk1977 BEGIN; 612b92b70bbSdanielk1977 PRAGMA aux.user_version = 10; 613b92b70bbSdanielk1977 PRAGMA user_version = 11; 614dae2495bSdanielk1977 } 615dae2495bSdanielk1977} {} 616dae2495bSdanielk1977do_test pragma-8.2.10 { 617dae2495bSdanielk1977 execsql { 618b92b70bbSdanielk1977 PRAGMA aux.user_version; 619dae2495bSdanielk1977 } 620dae2495bSdanielk1977} {10} 621dae2495bSdanielk1977do_test pragma-8.2.11 { 622dae2495bSdanielk1977 execsql { 623b92b70bbSdanielk1977 PRAGMA main.user_version; 624dae2495bSdanielk1977 } 625dae2495bSdanielk1977} {11} 626dae2495bSdanielk1977do_test pragma-8.2.12 { 627dae2495bSdanielk1977 execsql { 628dae2495bSdanielk1977 ROLLBACK; 629b92b70bbSdanielk1977 PRAGMA aux.user_version; 630dae2495bSdanielk1977 } 631dae2495bSdanielk1977} {3} 632dae2495bSdanielk1977do_test pragma-8.2.13 { 633dae2495bSdanielk1977 execsql { 634b92b70bbSdanielk1977 PRAGMA main.user_version; 635dae2495bSdanielk1977 } 636dae2495bSdanielk1977} {2} 637dae2495bSdanielk1977 638b92b70bbSdanielk1977# Try a negative value for the user-version 639dae2495bSdanielk1977do_test pragma-8.2.14 { 640dae2495bSdanielk1977 execsql { 641b92b70bbSdanielk1977 PRAGMA user_version = -450; 642dae2495bSdanielk1977 } 643dae2495bSdanielk1977} {} 644dae2495bSdanielk1977do_test pragma-8.2.15 { 645dae2495bSdanielk1977 execsql { 646b92b70bbSdanielk1977 PRAGMA user_version; 647dae2495bSdanielk1977 } 648dae2495bSdanielk1977} {-450} 649d9c847dcSdanielk1977} ; # ifcapable schema_version 650d9c847dcSdanielk1977 6519a09a3caStpoindex 6529a09a3caStpoindex# Test temp_store and temp_store_directory pragmas 6539a09a3caStpoindex# 654268283bcSdrhifcapable pager_pragmas { 6559a09a3caStpoindexdo_test pragma-9.1 { 6569a09a3caStpoindex db close 6579a09a3caStpoindex sqlite3 db test.db 6589a09a3caStpoindex execsql { 6599a09a3caStpoindex PRAGMA temp_store; 6609a09a3caStpoindex } 6619a09a3caStpoindex} {0} 6629a09a3caStpoindexdo_test pragma-9.2 { 6639a09a3caStpoindex execsql { 6649a09a3caStpoindex PRAGMA temp_store=file; 6659a09a3caStpoindex PRAGMA temp_store; 6669a09a3caStpoindex } 6679a09a3caStpoindex} {1} 6689a09a3caStpoindexdo_test pragma-9.3 { 6699a09a3caStpoindex execsql { 6709a09a3caStpoindex PRAGMA temp_store=memory; 6719a09a3caStpoindex PRAGMA temp_store; 6729a09a3caStpoindex } 6739a09a3caStpoindex} {2} 6749a09a3caStpoindexdo_test pragma-9.4 { 6759a09a3caStpoindex execsql { 6769a09a3caStpoindex PRAGMA temp_store_directory; 6779a09a3caStpoindex } 6789a09a3caStpoindex} {} 6799a09a3caStpoindexdo_test pragma-9.5 { 680268283bcSdrh set pwd [string map {' ''} [pwd]] 681268283bcSdrh execsql " 682268283bcSdrh PRAGMA temp_store_directory='$pwd'; 6839a09a3caStpoindex " 6849a09a3caStpoindex} {} 6859a09a3caStpoindexdo_test pragma-9.6 { 6869a09a3caStpoindex execsql { 6879a09a3caStpoindex PRAGMA temp_store_directory; 6889a09a3caStpoindex } 6899a09a3caStpoindex} [pwd] 6909a09a3caStpoindexdo_test pragma-9.7 { 691268283bcSdrh catchsql { 6929a09a3caStpoindex PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR'; 6939a09a3caStpoindex } 694268283bcSdrh} {1 {not a writable directory}} 6959a09a3caStpoindexdo_test pragma-9.8 { 6969a09a3caStpoindex execsql { 6979a09a3caStpoindex PRAGMA temp_store_directory=''; 6989a09a3caStpoindex } 6999a09a3caStpoindex} {} 70053c0f748Sdanielk1977ifcapable tempdb { 7019a09a3caStpoindex do_test pragma-9.9 { 7029a09a3caStpoindex execsql { 7039a09a3caStpoindex PRAGMA temp_store_directory; 7049a09a3caStpoindex PRAGMA temp_store=FILE; 7059a09a3caStpoindex CREATE TEMP TABLE temp_store_directory_test(a integer); 7069a09a3caStpoindex INSERT INTO temp_store_directory_test values (2); 7079a09a3caStpoindex SELECT * FROM temp_store_directory_test; 7089a09a3caStpoindex } 7099a09a3caStpoindex } {2} 71053c0f748Sdanielk1977} 7119a09a3caStpoindexdo_test pragma-9.10 { 712268283bcSdrh catchsql " 713268283bcSdrh PRAGMA temp_store_directory='$pwd'; 7149a09a3caStpoindex SELECT * FROM temp_store_directory_test; 7159a09a3caStpoindex " 716268283bcSdrh} {1 {no such table: temp_store_directory_test}} 717268283bcSdrh} ;# ifcapable pager_pragmas 7189a09a3caStpoindex 719cc6bd383Sdanielk1977ifcapable trigger { 720cc6bd383Sdanielk1977 721cc6bd383Sdanielk1977do_test pragma-10.0 { 722cc6bd383Sdanielk1977 catchsql { 723cc6bd383Sdanielk1977 DROP TABLE main.t1; 724cc6bd383Sdanielk1977 } 725cc6bd383Sdanielk1977 execsql { 726cc6bd383Sdanielk1977 PRAGMA count_changes = 1; 727cc6bd383Sdanielk1977 728cc6bd383Sdanielk1977 CREATE TABLE t1(a PRIMARY KEY); 729cc6bd383Sdanielk1977 CREATE TABLE t1_mirror(a); 730cc6bd383Sdanielk1977 CREATE TABLE t1_mirror2(a); 731cc6bd383Sdanielk1977 CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN 732cc6bd383Sdanielk1977 INSERT INTO t1_mirror VALUES(new.a); 733cc6bd383Sdanielk1977 END; 734cc6bd383Sdanielk1977 CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN 735cc6bd383Sdanielk1977 INSERT INTO t1_mirror2 VALUES(new.a); 736cc6bd383Sdanielk1977 END; 737cc6bd383Sdanielk1977 CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN 738cc6bd383Sdanielk1977 UPDATE t1_mirror SET a = new.a WHERE a = old.a; 739cc6bd383Sdanielk1977 END; 740cc6bd383Sdanielk1977 CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN 741cc6bd383Sdanielk1977 UPDATE t1_mirror2 SET a = new.a WHERE a = old.a; 742cc6bd383Sdanielk1977 END; 743cc6bd383Sdanielk1977 CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN 744cc6bd383Sdanielk1977 DELETE FROM t1_mirror WHERE a = old.a; 745cc6bd383Sdanielk1977 END; 746cc6bd383Sdanielk1977 CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN 747cc6bd383Sdanielk1977 DELETE FROM t1_mirror2 WHERE a = old.a; 748cc6bd383Sdanielk1977 END; 749cc6bd383Sdanielk1977 } 750cc6bd383Sdanielk1977} {} 751cc6bd383Sdanielk1977 752cc6bd383Sdanielk1977do_test pragma-10.1 { 753cc6bd383Sdanielk1977 execsql { 754cc6bd383Sdanielk1977 INSERT INTO t1 VALUES(randstr(10,10)); 755cc6bd383Sdanielk1977 } 756cc6bd383Sdanielk1977} {1} 757cc6bd383Sdanielk1977do_test pragma-10.2 { 758cc6bd383Sdanielk1977 execsql { 759cc6bd383Sdanielk1977 UPDATE t1 SET a = randstr(10,10); 760cc6bd383Sdanielk1977 } 761cc6bd383Sdanielk1977} {1} 762cc6bd383Sdanielk1977do_test pragma-10.3 { 763cc6bd383Sdanielk1977 execsql { 764cc6bd383Sdanielk1977 DELETE FROM t1; 765cc6bd383Sdanielk1977 } 766cc6bd383Sdanielk1977} {1} 767cc6bd383Sdanielk1977 768cc6bd383Sdanielk1977} ;# ifcapable trigger 769cc6bd383Sdanielk1977 77048af65aeSdanielk1977ifcapable schema_pragmas { 77148af65aeSdanielk1977 do_test pragma-11.1 { 77248af65aeSdanielk1977 execsql2 { 77348af65aeSdanielk1977 pragma collation_list; 77448af65aeSdanielk1977 } 77548af65aeSdanielk1977 } {seq 0 name NOCASE seq 1 name BINARY} 77648af65aeSdanielk1977 do_test pragma-11.2 { 77748af65aeSdanielk1977 db collate New_Collation blah... 77848af65aeSdanielk1977 execsql { 77948af65aeSdanielk1977 pragma collation_list; 78048af65aeSdanielk1977 } 78148af65aeSdanielk1977 } {0 New_Collation 1 NOCASE 2 BINARY} 78248af65aeSdanielk1977} 78348af65aeSdanielk1977 784ddfb2f03Sdanielk1977ifcapable schema_pragmas&&tempdb { 785ddfb2f03Sdanielk1977 do_test pragma-12.1 { 786ddfb2f03Sdanielk1977 sqlite3 db2 test.db 787ddfb2f03Sdanielk1977 execsql { 788ddfb2f03Sdanielk1977 PRAGMA temp.table_info('abc'); 789ddfb2f03Sdanielk1977 } db2 790ddfb2f03Sdanielk1977 } {} 791ddfb2f03Sdanielk1977 db2 close 792ddfb2f03Sdanielk1977 793ddfb2f03Sdanielk1977 do_test pragma-12.2 { 794ddfb2f03Sdanielk1977 sqlite3 db2 test.db 795ddfb2f03Sdanielk1977 execsql { 796ddfb2f03Sdanielk1977 PRAGMA temp.default_cache_size = 200; 797ddfb2f03Sdanielk1977 PRAGMA temp.default_cache_size; 798ddfb2f03Sdanielk1977 } db2 799ddfb2f03Sdanielk1977 } {200} 800ddfb2f03Sdanielk1977 db2 close 801ddfb2f03Sdanielk1977 802ddfb2f03Sdanielk1977 do_test pragma-12.3 { 803ddfb2f03Sdanielk1977 sqlite3 db2 test.db 804ddfb2f03Sdanielk1977 execsql { 805ddfb2f03Sdanielk1977 PRAGMA temp.cache_size = 400; 806ddfb2f03Sdanielk1977 PRAGMA temp.cache_size; 807ddfb2f03Sdanielk1977 } db2 808ddfb2f03Sdanielk1977 } {400} 809ddfb2f03Sdanielk1977 db2 close 810ddfb2f03Sdanielk1977} 811ddfb2f03Sdanielk1977 8124b2688abSdanielk1977ifcapable bloblit { 8134b2688abSdanielk1977 81405a82983Sdrhdo_test pragma-13.1 { 81505a82983Sdrh execsql { 81605a82983Sdrh DROP TABLE IF EXISTS t4; 81705a82983Sdrh PRAGMA vdbe_trace=on; 81805a82983Sdrh PRAGMA vdbe_listing=on; 81905a82983Sdrh PRAGMA sql_trace=on; 82005a82983Sdrh CREATE TABLE t4(a INTEGER PRIMARY KEY,b); 82105a82983Sdrh INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789'); 82205a82983Sdrh INSERT INTO t4(b) VALUES(randstr(30,30)); 82305a82983Sdrh INSERT INTO t4(b) VALUES(1.23456); 82405a82983Sdrh INSERT INTO t4(b) VALUES(NULL); 82505a82983Sdrh INSERT INTO t4(b) VALUES(0); 82605a82983Sdrh INSERT INTO t4(b) SELECT b||b||b||b FROM t4; 82705a82983Sdrh SELECT * FROM t4; 82805a82983Sdrh } 82905a82983Sdrh execsql { 83005a82983Sdrh PRAGMA vdbe_trace=off; 83105a82983Sdrh PRAGMA vdbe_listing=off; 83205a82983Sdrh PRAGMA sql_trace=off; 83305a82983Sdrh } 83405a82983Sdrh} {} 83505a82983Sdrh 8364b2688abSdanielk1977} ;# ifcapable bloblit 8374b2688abSdanielk1977 8385558a8a6Sdanielk1977# Reset the sqlite3_temp_directory variable for the next run of tests: 8395558a8a6Sdanielk1977sqlite3 dbX :memory: 8405558a8a6Sdanielk1977dbX eval {PRAGMA temp_store_directory = ""} 8415558a8a6Sdanielk1977dbX close 8425558a8a6Sdanielk1977 843cd61c281Sdrhfinish_test 844