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 195885e762Sdanset testprefix pragma 20cd61c281Sdrh 2168928b6cSdan# Do not use a codec for tests in this file, as the database file is 2268928b6cSdan# manipulated directly using tcl scripts (using the [hexio_write] command). 2368928b6cSdan# 2468928b6cSdando_not_use_codec 2568928b6cSdan 2691cf71b0Sdanielk1977# Test organization: 2791cf71b0Sdanielk1977# 2891cf71b0Sdanielk1977# pragma-1.*: Test cache_size, default_cache_size and synchronous on main db. 2991cf71b0Sdanielk1977# pragma-2.*: Test synchronous on attached db. 3091cf71b0Sdanielk1977# pragma-3.*: Test detection of table/index inconsistency by integrity_check. 3191cf71b0Sdanielk1977# pragma-4.*: Test cache_size and default_cache_size on attached db. 3291cf71b0Sdanielk1977# pragma-5.*: Test that pragma synchronous may not be used inside of a 3391cf71b0Sdanielk1977# transaction. 34cc6bd383Sdanielk1977# pragma-6.*: Test schema-query pragmas. 35cc6bd383Sdanielk1977# pragma-7.*: Miscellaneous tests. 36cc6bd383Sdanielk1977# pragma-8.*: Test user_version and schema_version pragmas. 379a09a3caStpoindex# pragma-9.*: Test temp_store and temp_store_directory. 38cc6bd383Sdanielk1977# pragma-10.*: Test the count_changes pragma in the presence of triggers. 3948af65aeSdanielk1977# pragma-11.*: Test the collation_list pragma. 4059a93791Sdanielk1977# pragma-14.*: Test the page_count pragma. 418cf6c554Sdanielk1977# pragma-15.*: Test that the value set using the cache_size pragma is not 428cf6c554Sdanielk1977# reset when the schema is reloaded. 43aebf413dSaswift# pragma-16.*: Test proxy locking 44a112d140Smistachkin# pragma-20.*: Test data_store_directory. 455885e762Sdan# pragma-22.*: Test that "PRAGMA [db].integrity_check" respects the "db" 465885e762Sdan# directive - if it is present. 4791cf71b0Sdanielk1977# 4891cf71b0Sdanielk1977 4905a82983Sdrhifcapable !pragma { 5005a82983Sdrh finish_test 5105a82983Sdrh return 5205a82983Sdrh} 5305a82983Sdrh 54c228be5bSdrh# Capture the output of a pragma in a TEMP table. 55c228be5bSdrh# 56c228be5bSdrhproc capture_pragma {db tabname sql} { 57c228be5bSdrh $db eval "DROP TABLE IF EXISTS temp.$tabname" 58c228be5bSdrh set once 1 59c228be5bSdrh $db eval $sql x { 60c228be5bSdrh if {$once} { 61c228be5bSdrh set once 0 62c228be5bSdrh set ins "INSERT INTO $tabname VALUES" 63c228be5bSdrh set crtab "CREATE TEMP TABLE $tabname " 64c228be5bSdrh set sep "(" 65c228be5bSdrh foreach col $x(*) { 66c228be5bSdrh append ins ${sep}\$x($col) 67c228be5bSdrh append crtab ${sep}\"$col\" 68c228be5bSdrh set sep , 69c228be5bSdrh } 70c228be5bSdrh append ins ) 71c228be5bSdrh append crtab ) 72c228be5bSdrh $db eval $crtab 73c228be5bSdrh } 74c228be5bSdrh $db eval $ins 75c228be5bSdrh } 76c228be5bSdrh} 77c228be5bSdrh 78cd61c281Sdrh# Delete the preexisting database to avoid the special setup 79cd61c281Sdrh# that the "all.test" script does. 80cd61c281Sdrh# 81cd61c281Sdrhdb close 82fda06befSmistachkindelete_file test.db test.db-journal 83fda06befSmistachkindelete_file test3.db test3.db-journal 84dddca286Sdrhsqlite3 db test.db; set DB [sqlite3_connection_pointer db] 85cd61c281Sdrh 86*9d356fbeSdrh# EVIDENCE-OF: R-24197-42751 PRAGMA database.cache_size; PRAGMA 87*9d356fbeSdrh# database.cache_size = pages; PRAGMA database.cache_size = -kibibytes; 88*9d356fbeSdrh# Query or change the suggested maximum number of database disk pages 89*9d356fbeSdrh# that SQLite will hold in memory at once per open database file. 90*9d356fbeSdrh# 91c7b4a44cSdanielk1977ifcapable pager_pragmas { 921e9daa6aSdrhset DFLT_CACHE_SZ [db one {PRAGMA default_cache_size}] 931e9daa6aSdrhset TEMP_CACHE_SZ [db one {PRAGMA temp.default_cache_size}] 94cd61c281Sdrhdo_test pragma-1.1 { 95cd61c281Sdrh execsql { 96cd61c281Sdrh PRAGMA cache_size; 97cd61c281Sdrh PRAGMA default_cache_size; 98cd61c281Sdrh PRAGMA synchronous; 99cd61c281Sdrh } 1001e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] 101cd61c281Sdrhdo_test pragma-1.2 { 102*9d356fbeSdrh # EVIDENCE-OF: R-42059-47211 If the argument N is positive then the 103*9d356fbeSdrh # suggested cache size is set to N. 104cd61c281Sdrh execsql { 105eb43e5c7Sdrh PRAGMA synchronous=OFF; 106cd61c281Sdrh PRAGMA cache_size=1234; 107cd61c281Sdrh PRAGMA cache_size; 108cd61c281Sdrh PRAGMA default_cache_size; 109cd61c281Sdrh PRAGMA synchronous; 110cd61c281Sdrh } 1111e9daa6aSdrh} [list 1234 $DFLT_CACHE_SZ 0] 112cd61c281Sdrhdo_test pragma-1.3 { 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.4 { 122cd61c281Sdrh execsql { 123cd61c281Sdrh PRAGMA synchronous=OFF; 124cd61c281Sdrh PRAGMA cache_size; 125cd61c281Sdrh PRAGMA default_cache_size; 126cd61c281Sdrh PRAGMA synchronous; 127cd61c281Sdrh } 1281e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 0] 129cd61c281Sdrhdo_test pragma-1.5 { 130cd61c281Sdrh execsql { 131d2cb50b7Sdrh PRAGMA cache_size=-4321; 132cd61c281Sdrh PRAGMA cache_size; 133cd61c281Sdrh PRAGMA default_cache_size; 134cd61c281Sdrh PRAGMA synchronous; 135cd61c281Sdrh } 1363b42abb3Sdrh} [list -4321 $DFLT_CACHE_SZ 0] 137cd61c281Sdrhdo_test pragma-1.6 { 138cd61c281Sdrh execsql { 139cd61c281Sdrh PRAGMA synchronous=ON; 140cd61c281Sdrh PRAGMA cache_size; 141cd61c281Sdrh PRAGMA default_cache_size; 142cd61c281Sdrh PRAGMA synchronous; 143cd61c281Sdrh } 1443b42abb3Sdrh} [list -4321 $DFLT_CACHE_SZ 1] 145cd61c281Sdrhdo_test pragma-1.7 { 146cd61c281Sdrh db close 147ef4ac8f9Sdrh sqlite3 db test.db 148cd61c281Sdrh execsql { 149cd61c281Sdrh PRAGMA cache_size; 150cd61c281Sdrh PRAGMA default_cache_size; 151cd61c281Sdrh PRAGMA synchronous; 152cd61c281Sdrh } 1531e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] 154cd61c281Sdrhdo_test pragma-1.8 { 155cd61c281Sdrh execsql { 156d2cb50b7Sdrh PRAGMA default_cache_size=-123; 157cd61c281Sdrh PRAGMA cache_size; 158cd61c281Sdrh PRAGMA default_cache_size; 159cd61c281Sdrh PRAGMA synchronous; 160cd61c281Sdrh } 16191cf71b0Sdanielk1977} {123 123 2} 162802d69a7Sdrhdo_test pragma-1.9.1 { 163cd61c281Sdrh db close 164dddca286Sdrh sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db] 165cd61c281Sdrh execsql { 166cd61c281Sdrh PRAGMA cache_size; 167cd61c281Sdrh PRAGMA default_cache_size; 168cd61c281Sdrh PRAGMA synchronous; 169cd61c281Sdrh } 17091cf71b0Sdanielk1977} {123 123 2} 171802d69a7Sdrhifcapable vacuum { 172802d69a7Sdrh do_test pragma-1.9.2 { 173802d69a7Sdrh execsql { 174802d69a7Sdrh VACUUM; 175802d69a7Sdrh PRAGMA cache_size; 176802d69a7Sdrh PRAGMA default_cache_size; 177802d69a7Sdrh PRAGMA synchronous; 178802d69a7Sdrh } 179802d69a7Sdrh } {123 123 2} 180802d69a7Sdrh} 18191cf71b0Sdanielk1977do_test pragma-1.10 { 1825a38705eSdrh execsql { 1834303feedSdrh PRAGMA synchronous=NORMAL; 1844303feedSdrh PRAGMA cache_size; 1854303feedSdrh PRAGMA default_cache_size; 1864303feedSdrh PRAGMA synchronous; 1874303feedSdrh } 18891cf71b0Sdanielk1977} {123 123 1} 18991cf71b0Sdanielk1977do_test pragma-1.11 { 1904303feedSdrh execsql { 1914303feedSdrh PRAGMA synchronous=FULL; 1924303feedSdrh PRAGMA cache_size; 1934303feedSdrh PRAGMA default_cache_size; 1944303feedSdrh PRAGMA synchronous; 1954303feedSdrh } 19691cf71b0Sdanielk1977} {123 123 2} 19791cf71b0Sdanielk1977do_test pragma-1.12 { 1984303feedSdrh db close 199dddca286Sdrh sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db] 2004303feedSdrh execsql { 2014303feedSdrh PRAGMA cache_size; 2024303feedSdrh PRAGMA default_cache_size; 2034303feedSdrh PRAGMA synchronous; 2044303feedSdrh } 20591cf71b0Sdanielk1977} {123 123 2} 20691cf71b0Sdanielk1977 2075260f7e9Sdrh# Make sure the pragma handler understands numeric values in addition 2085260f7e9Sdrh# to keywords like "off" and "full". 2095260f7e9Sdrh# 2105260f7e9Sdrhdo_test pragma-1.13 { 2115260f7e9Sdrh execsql { 2125260f7e9Sdrh PRAGMA synchronous=0; 2135260f7e9Sdrh PRAGMA synchronous; 2145260f7e9Sdrh } 2155260f7e9Sdrh} {0} 2165260f7e9Sdrhdo_test pragma-1.14 { 2175260f7e9Sdrh execsql { 2185260f7e9Sdrh PRAGMA synchronous=2; 2195260f7e9Sdrh PRAGMA synchronous; 2205260f7e9Sdrh } 2215260f7e9Sdrh} {2} 222c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 2235260f7e9Sdrh 2245260f7e9Sdrh# Test turning "flag" pragmas on and off. 2255260f7e9Sdrh# 2266338c762Sdanielk1977ifcapable debug { 2276338c762Sdanielk1977 # Pragma "vdbe_listing" is only available if compiled with SQLITE_DEBUG 2286338c762Sdanielk1977 # 2295260f7e9Sdrh do_test pragma-1.15 { 2305260f7e9Sdrh execsql { 2315260f7e9Sdrh PRAGMA vdbe_listing=YES; 2325260f7e9Sdrh PRAGMA vdbe_listing; 2335260f7e9Sdrh } 2345260f7e9Sdrh } {1} 2355260f7e9Sdrh do_test pragma-1.16 { 2365260f7e9Sdrh execsql { 2375260f7e9Sdrh PRAGMA vdbe_listing=NO; 2385260f7e9Sdrh PRAGMA vdbe_listing; 2395260f7e9Sdrh } 2405260f7e9Sdrh } {0} 2416338c762Sdanielk1977} 2426338c762Sdanielk1977 2435260f7e9Sdrhdo_test pragma-1.17 { 2445260f7e9Sdrh execsql { 2455260f7e9Sdrh PRAGMA parser_trace=ON; 2465260f7e9Sdrh PRAGMA parser_trace=OFF; 2475260f7e9Sdrh } 2485260f7e9Sdrh} {} 2495260f7e9Sdrhdo_test pragma-1.18 { 2505260f7e9Sdrh execsql { 2515260f7e9Sdrh PRAGMA bogus = -1234; -- Parsing of negative values 2525260f7e9Sdrh } 2535260f7e9Sdrh} {} 2545260f7e9Sdrh 25591cf71b0Sdanielk1977# Test modifying the safety_level of an attached database. 2565a8f9374Sdanielk1977ifcapable pager_pragmas&&attach { 25791cf71b0Sdanielk1977 do_test pragma-2.1 { 258fda06befSmistachkin forcedelete test2.db 259fda06befSmistachkin forcedelete test2.db-journal 2604303feedSdrh execsql { 26191cf71b0Sdanielk1977 ATTACH 'test2.db' AS aux; 2624303feedSdrh } 26391cf71b0Sdanielk1977 } {} 26491cf71b0Sdanielk1977 do_test pragma-2.2 { 2654303feedSdrh execsql { 26691cf71b0Sdanielk1977 pragma aux.synchronous; 2674303feedSdrh } 26891cf71b0Sdanielk1977 } {2} 26991cf71b0Sdanielk1977 do_test pragma-2.3 { 27091cf71b0Sdanielk1977 execsql { 27191cf71b0Sdanielk1977 pragma aux.synchronous = OFF; 27291cf71b0Sdanielk1977 pragma aux.synchronous; 27391cf71b0Sdanielk1977 pragma synchronous; 27491cf71b0Sdanielk1977 } 27591cf71b0Sdanielk1977 } {0 2} 27691cf71b0Sdanielk1977 do_test pragma-2.4 { 27791cf71b0Sdanielk1977 execsql { 27891cf71b0Sdanielk1977 pragma aux.synchronous = ON; 27991cf71b0Sdanielk1977 pragma synchronous; 28091cf71b0Sdanielk1977 pragma aux.synchronous; 28191cf71b0Sdanielk1977 } 28291cf71b0Sdanielk1977 } {2 1} 283c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 2844303feedSdrh 285ed717fe3Sdrh# Construct a corrupted index and make sure the integrity_check 286ed717fe3Sdrh# pragma finds it. 287ed717fe3Sdrh# 28825d6543dSdrh# These tests won't work if the database is encrypted 28925d6543dSdrh# 290ed717fe3Sdrhdo_test pragma-3.1 { 2911e9daa6aSdrh db close 292fda06befSmistachkin forcedelete test.db test.db-journal 2931e9daa6aSdrh sqlite3 db test.db 294ed717fe3Sdrh execsql { 2951e9daa6aSdrh PRAGMA auto_vacuum=OFF; 296ed717fe3Sdrh BEGIN; 297ed717fe3Sdrh CREATE TABLE t2(a,b,c); 298ed717fe3Sdrh CREATE INDEX i2 ON t2(a); 299ed717fe3Sdrh INSERT INTO t2 VALUES(11,2,3); 300ed717fe3Sdrh INSERT INTO t2 VALUES(22,3,4); 301ed717fe3Sdrh COMMIT; 302ed717fe3Sdrh SELECT rowid, * from t2; 303ed717fe3Sdrh } 304ed717fe3Sdrh} {1 11 2 3 2 22 3 4} 3055a8f9374Sdanielk1977ifcapable attach { 30640e016e4Sdrh if {![sqlite3 -has-codec] && $sqlite_options(integrityck)} { 307ed717fe3Sdrh do_test pragma-3.2 { 308bb8a279eSdrh db eval {SELECT rootpage FROM sqlite_master WHERE name='i2'} break 309bb8a279eSdrh set pgsz [db eval {PRAGMA page_size}] 310bb8a279eSdrh # overwrite the header on the rootpage of the index in order to 311bb8a279eSdrh # make the index appear to be empty. 312bb8a279eSdrh # 313bb8a279eSdrh set offset [expr {$pgsz*($rootpage-1)}] 314bb8a279eSdrh hexio_write test.db $offset 0a00000000040000000000 315bb8a279eSdrh db close 316bb8a279eSdrh sqlite3 db test.db 317ed717fe3Sdrh execsql {PRAGMA integrity_check} 3186fbe41acSdrh } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} 31991cf71b0Sdanielk1977 do_test pragma-3.3 { 3201dcdbc06Sdrh execsql {PRAGMA integrity_check=1} 3216fbe41acSdrh } {{row 1 missing from index i2}} 3221dcdbc06Sdrh do_test pragma-3.4 { 32391cf71b0Sdanielk1977 execsql { 3241dcdbc06Sdrh ATTACH DATABASE 'test.db' AS t2; 3251dcdbc06Sdrh PRAGMA integrity_check 32691cf71b0Sdanielk1977 } 3276fbe41acSdrh } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} 3281dcdbc06Sdrh do_test pragma-3.5 { 3291dcdbc06Sdrh execsql { 330bb8a279eSdrh PRAGMA integrity_check=4 3311dcdbc06Sdrh } 3326fbe41acSdrh } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2}} 3331dcdbc06Sdrh do_test pragma-3.6 { 3341dcdbc06Sdrh execsql { 3351dcdbc06Sdrh PRAGMA integrity_check=xyz 3361dcdbc06Sdrh } 3376fbe41acSdrh } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} 3381dcdbc06Sdrh do_test pragma-3.7 { 3391dcdbc06Sdrh execsql { 3401dcdbc06Sdrh PRAGMA integrity_check=0 3411dcdbc06Sdrh } 3426fbe41acSdrh } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} 3431dcdbc06Sdrh 3441dcdbc06Sdrh # Add additional corruption by appending unused pages to the end of 3451dcdbc06Sdrh # the database file testerr.db 3461dcdbc06Sdrh # 3471dcdbc06Sdrh do_test pragma-3.8 { 3481dcdbc06Sdrh execsql {DETACH t2} 349fda06befSmistachkin forcedelete testerr.db testerr.db-journal 350e3d559adSdrh set out [open testerr.db w] 351e3d559adSdrh fconfigure $out -translation binary 352e3d559adSdrh set in [open test.db r] 353e3d559adSdrh fconfigure $in -translation binary 3541dcdbc06Sdrh puts -nonewline $out [read $in] 3551dcdbc06Sdrh seek $in 0 3561dcdbc06Sdrh puts -nonewline $out [read $in] 3571dcdbc06Sdrh close $in 3581dcdbc06Sdrh close $out 359dd3cd977Sdrh hexio_write testerr.db 28 00000000 3601dcdbc06Sdrh execsql {REINDEX t2} 3611dcdbc06Sdrh execsql {PRAGMA integrity_check} 3621dcdbc06Sdrh } {ok} 36341c58b78Sdanielk1977 do_test pragma-3.8.1 { 36441c58b78Sdanielk1977 execsql {PRAGMA quick_check} 36541c58b78Sdanielk1977 } {ok} 3665d16a9a6Sdrh do_test pragma-3.8.2 { 3675d16a9a6Sdrh execsql {PRAGMA QUICK_CHECK} 3685d16a9a6Sdrh } {ok} 3691dcdbc06Sdrh do_test pragma-3.9 { 3701dcdbc06Sdrh execsql { 3711dcdbc06Sdrh ATTACH 'testerr.db' AS t2; 3721dcdbc06Sdrh PRAGMA integrity_check 3731dcdbc06Sdrh } 3741dcdbc06Sdrh } {{*** in database t2 *** 3751dcdbc06SdrhPage 4 is never used 3761dcdbc06SdrhPage 5 is never used 3776fbe41acSdrhPage 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} 3781dcdbc06Sdrh do_test pragma-3.10 { 3791dcdbc06Sdrh execsql { 3801dcdbc06Sdrh PRAGMA integrity_check=1 3811dcdbc06Sdrh } 3821dcdbc06Sdrh } {{*** in database t2 *** 3831dcdbc06SdrhPage 4 is never used}} 3841dcdbc06Sdrh do_test pragma-3.11 { 3851dcdbc06Sdrh execsql { 3861dcdbc06Sdrh PRAGMA integrity_check=5 3871dcdbc06Sdrh } 3881dcdbc06Sdrh } {{*** in database t2 *** 3891dcdbc06SdrhPage 4 is never used 3901dcdbc06SdrhPage 5 is never used 3916fbe41acSdrhPage 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2}} 3921dcdbc06Sdrh do_test pragma-3.12 { 3931dcdbc06Sdrh execsql { 3941dcdbc06Sdrh PRAGMA integrity_check=4 3951dcdbc06Sdrh } 3961dcdbc06Sdrh } {{*** in database t2 *** 3971dcdbc06SdrhPage 4 is never used 3981dcdbc06SdrhPage 5 is never used 3996fbe41acSdrhPage 6 is never used} {row 1 missing from index i2}} 4001dcdbc06Sdrh do_test pragma-3.13 { 4011dcdbc06Sdrh execsql { 4021dcdbc06Sdrh PRAGMA integrity_check=3 4031dcdbc06Sdrh } 4041dcdbc06Sdrh } {{*** in database t2 *** 4051dcdbc06SdrhPage 4 is never used 4061dcdbc06SdrhPage 5 is never used 4071dcdbc06SdrhPage 6 is never used}} 4081dcdbc06Sdrh do_test pragma-3.14 { 4091dcdbc06Sdrh execsql { 4101dcdbc06Sdrh PRAGMA integrity_check(2) 4111dcdbc06Sdrh } 4121dcdbc06Sdrh } {{*** in database t2 *** 4131dcdbc06SdrhPage 4 is never used 4141dcdbc06SdrhPage 5 is never used}} 4151dcdbc06Sdrh do_test pragma-3.15 { 4161dcdbc06Sdrh execsql { 4171dcdbc06Sdrh ATTACH 'testerr.db' AS t3; 4181dcdbc06Sdrh PRAGMA integrity_check 4191dcdbc06Sdrh } 4201dcdbc06Sdrh } {{*** in database t2 *** 4211dcdbc06SdrhPage 4 is never used 4221dcdbc06SdrhPage 5 is never used 4236fbe41acSdrhPage 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 *** 4241dcdbc06SdrhPage 4 is never used 4251dcdbc06SdrhPage 5 is never used 4266fbe41acSdrhPage 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} 4271dcdbc06Sdrh do_test pragma-3.16 { 4281dcdbc06Sdrh execsql { 429bb8a279eSdrh PRAGMA integrity_check(10) 4301dcdbc06Sdrh } 4311dcdbc06Sdrh } {{*** in database t2 *** 4321dcdbc06SdrhPage 4 is never used 4331dcdbc06SdrhPage 5 is never used 4346fbe41acSdrhPage 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 *** 4351dcdbc06SdrhPage 4 is never used 4361dcdbc06SdrhPage 5 is never used 4376fbe41acSdrhPage 6 is never used} {row 1 missing from index i2}} 4381dcdbc06Sdrh do_test pragma-3.17 { 4391dcdbc06Sdrh execsql { 440bb8a279eSdrh PRAGMA integrity_check=8 4411dcdbc06Sdrh } 4421dcdbc06Sdrh } {{*** in database t2 *** 4431dcdbc06SdrhPage 4 is never used 4441dcdbc06SdrhPage 5 is never used 4456fbe41acSdrhPage 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 *** 4461dcdbc06SdrhPage 4 is never used 4471dcdbc06SdrhPage 5 is never used}} 4481dcdbc06Sdrh do_test pragma-3.18 { 4491dcdbc06Sdrh execsql { 4501dcdbc06Sdrh PRAGMA integrity_check=4 4511dcdbc06Sdrh } 4521dcdbc06Sdrh } {{*** in database t2 *** 4531dcdbc06SdrhPage 4 is never used 4541dcdbc06SdrhPage 5 is never used 4556fbe41acSdrhPage 6 is never used} {row 1 missing from index i2}} 4561dcdbc06Sdrh } 457d2cb50b7Sdrh do_test pragma-3.19 { 458d2cb50b7Sdrh catch {db close} 459fda06befSmistachkin forcedelete test.db test.db-journal 460d2cb50b7Sdrh sqlite3 db test.db 461d2cb50b7Sdrh db eval {PRAGMA integrity_check} 462d2cb50b7Sdrh } {ok} 4635a8f9374Sdanielk1977} 464cefc87fcSdrh 465cefc87fcSdrh# Verify that PRAGMA integrity_check catches UNIQUE and NOT NULL 466cefc87fcSdrh# constraint violations. 467cefc87fcSdrh# 468cefc87fcSdrhdo_execsql_test pragma-3.20 { 469cefc87fcSdrh CREATE TABLE t1(a,b); 470cefc87fcSdrh CREATE INDEX t1a ON t1(a); 471cefc87fcSdrh INSERT INTO t1 VALUES(1,1),(2,2),(3,3),(2,4),(NULL,5),(NULL,6); 472cefc87fcSdrh PRAGMA writable_schema=ON; 473cefc87fcSdrh UPDATE sqlite_master SET sql='CREATE UNIQUE INDEX t1a ON t1(a)' 474cefc87fcSdrh WHERE name='t1a'; 475cefc87fcSdrh UPDATE sqlite_master SET sql='CREATE TABLE t1(a NOT NULL,b)' 476cefc87fcSdrh WHERE name='t1'; 477cefc87fcSdrh PRAGMA writable_schema=OFF; 478cefc87fcSdrh ALTER TABLE t1 RENAME TO t1x; 479cefc87fcSdrh PRAGMA integrity_check; 480cefc87fcSdrh} {{non-unique entry in index t1a} {NULL value in t1x.a} {non-unique entry in index t1a} {NULL value in t1x.a}} 481cefc87fcSdrhdo_execsql_test pragma-3.21 { 482cefc87fcSdrh PRAGMA integrity_check(3); 483cefc87fcSdrh} {{non-unique entry in index t1a} {NULL value in t1x.a} {non-unique entry in index t1a}} 484cefc87fcSdrhdo_execsql_test pragma-3.22 { 485cefc87fcSdrh PRAGMA integrity_check(2); 486cefc87fcSdrh} {{non-unique entry in index t1a} {NULL value in t1x.a}} 4877efa426eSdrhdo_execsql_test pragma-3.23 { 488cefc87fcSdrh PRAGMA integrity_check(1); 489cefc87fcSdrh} {{non-unique entry in index t1a}} 49091cf71b0Sdanielk1977 4917efa426eSdrh# PRAGMA integrity check (or more specifically the sqlite3BtreeCount() 4927efa426eSdrh# interface) used to leave index cursors in an inconsistent state 4937efa426eSdrh# which could result in an assertion fault in sqlite3BtreeKey() 4947efa426eSdrh# called from saveCursorPosition() if content is removed from the 4957efa426eSdrh# index while the integrity_check is still running. This test verifies 4967efa426eSdrh# that problem has been fixed. 4977efa426eSdrh# 4987efa426eSdrhdo_test pragma-3.30 { 4997efa426eSdrh db close 5007efa426eSdrh delete_file test.db 5017efa426eSdrh sqlite3 db test.db 5027efa426eSdrh db eval { 5037efa426eSdrh CREATE TABLE t1(a,b,c); 5047efa426eSdrh WITH RECURSIVE 5057efa426eSdrh c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<100) 5067efa426eSdrh INSERT INTO t1(a,b,c) SELECT i, printf('xyz%08x',i), 2000-i FROM c; 5077efa426eSdrh CREATE INDEX t1a ON t1(a); 5087efa426eSdrh CREATE INDEX t1bc ON t1(b,c); 5097efa426eSdrh } 5107efa426eSdrh db eval {PRAGMA integrity_check} { 5117efa426eSdrh db eval {DELETE FROM t1} 5127efa426eSdrh } 5137efa426eSdrh} {} 5147efa426eSdrh 51591cf71b0Sdanielk1977# Test modifying the cache_size of an attached database. 5165a8f9374Sdanielk1977ifcapable pager_pragmas&&attach { 51791cf71b0Sdanielk1977do_test pragma-4.1 { 51891cf71b0Sdanielk1977 execsql { 5191e9daa6aSdrh ATTACH 'test2.db' AS aux; 52091cf71b0Sdanielk1977 pragma aux.cache_size; 52191cf71b0Sdanielk1977 pragma aux.default_cache_size; 52291cf71b0Sdanielk1977 } 5231e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] 5241bdd9b57Sdrhdo_test pragma-4.2 { 5251bdd9b57Sdrh execsql { 52691cf71b0Sdanielk1977 pragma aux.cache_size = 50; 52791cf71b0Sdanielk1977 pragma aux.cache_size; 52891cf71b0Sdanielk1977 pragma aux.default_cache_size; 5291bdd9b57Sdrh } 5301e9daa6aSdrh} [list 50 $DFLT_CACHE_SZ] 5311bdd9b57Sdrhdo_test pragma-4.3 { 5321bdd9b57Sdrh execsql { 53391cf71b0Sdanielk1977 pragma aux.default_cache_size = 456; 53491cf71b0Sdanielk1977 pragma aux.cache_size; 53591cf71b0Sdanielk1977 pragma aux.default_cache_size; 5361bdd9b57Sdrh } 53791cf71b0Sdanielk1977} {456 456} 5381bdd9b57Sdrhdo_test pragma-4.4 { 5391bdd9b57Sdrh execsql { 54091cf71b0Sdanielk1977 pragma cache_size; 54191cf71b0Sdanielk1977 pragma default_cache_size; 5421bdd9b57Sdrh } 5431e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] 5441bdd9b57Sdrhdo_test pragma-4.5 { 5451bdd9b57Sdrh execsql { 54691cf71b0Sdanielk1977 DETACH aux; 54791cf71b0Sdanielk1977 ATTACH 'test3.db' AS aux; 54891cf71b0Sdanielk1977 pragma aux.cache_size; 54991cf71b0Sdanielk1977 pragma aux.default_cache_size; 5501bdd9b57Sdrh } 5511e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] 5521bdd9b57Sdrhdo_test pragma-4.6 { 5531bdd9b57Sdrh execsql { 55491cf71b0Sdanielk1977 DETACH aux; 55591cf71b0Sdanielk1977 ATTACH 'test2.db' AS aux; 55691cf71b0Sdanielk1977 pragma aux.cache_size; 55791cf71b0Sdanielk1977 pragma aux.default_cache_size; 5581bdd9b57Sdrh } 55991cf71b0Sdanielk1977} {456 456} 560c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 5611bdd9b57Sdrh 56291cf71b0Sdanielk1977# Test that modifying the sync-level in the middle of a transaction is 56391cf71b0Sdanielk1977# disallowed. 564c7b4a44cSdanielk1977ifcapable pager_pragmas { 56591cf71b0Sdanielk1977do_test pragma-5.0 { 5661bdd9b57Sdrh execsql { 56791cf71b0Sdanielk1977 pragma synchronous; 5681bdd9b57Sdrh } 56991cf71b0Sdanielk1977} {2} 57091cf71b0Sdanielk1977do_test pragma-5.1 { 5711bdd9b57Sdrh catchsql { 5721bdd9b57Sdrh BEGIN; 57391cf71b0Sdanielk1977 pragma synchronous = OFF; 5741bdd9b57Sdrh } 57591cf71b0Sdanielk1977} {1 {Safety level may not be changed inside a transaction}} 57691cf71b0Sdanielk1977do_test pragma-5.2 { 57791cf71b0Sdanielk1977 execsql { 57891cf71b0Sdanielk1977 pragma synchronous; 57991cf71b0Sdanielk1977 } 58091cf71b0Sdanielk1977} {2} 5815260f7e9Sdrhcatchsql {COMMIT;} 582c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 5835260f7e9Sdrh 5845260f7e9Sdrh# Test schema-query pragmas 5855260f7e9Sdrh# 58627188fb5Sdanielk1977ifcapable schema_pragmas { 5875a8f9374Sdanielk1977ifcapable tempdb&&attach { 5885260f7e9Sdrh do_test pragma-6.1 { 589956bc92cSdrh set res {} 59040e016e4Sdrh execsql {SELECT * FROM sqlite_temp_master} 5915260f7e9Sdrh foreach {idx name file} [execsql {pragma database_list}] { 5925260f7e9Sdrh lappend res $idx $name 5935260f7e9Sdrh } 5945260f7e9Sdrh set res 595a71aa001Sdrh } {0 main 1 temp 2 aux} 59653c0f748Sdanielk1977} 5975260f7e9Sdrhdo_test pragma-6.2 { 5985260f7e9Sdrh execsql { 599d2cb50b7Sdrh CREATE TABLE t2(a,b,c); 6005260f7e9Sdrh pragma table_info(t2) 6015260f7e9Sdrh } 602bfa8b102Sdrh} {0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0} 603d2cb50b7Sdrhdo_test pragma-6.2.1 { 604d2cb50b7Sdrh execsql { 605d2cb50b7Sdrh pragma table_info; 606d2cb50b7Sdrh } 607d2cb50b7Sdrh} {} 608736c7d4bSdrhdb nullvalue <<NULL>> 609417ec638Sdrhdo_test pragma-6.2.2 { 610417ec638Sdrh execsql { 611736c7d4bSdrh CREATE TABLE t5( 612736c7d4bSdrh a TEXT DEFAULT CURRENT_TIMESTAMP, 613736c7d4bSdrh b DEFAULT (5+3), 614736c7d4bSdrh c TEXT, 615736c7d4bSdrh d INTEGER DEFAULT NULL, 616384b7fe2Sdrh e TEXT DEFAULT '', 617384b7fe2Sdrh UNIQUE(b,c,d), 618384b7fe2Sdrh PRIMARY KEY(e,b,c) 619736c7d4bSdrh ); 620417ec638Sdrh PRAGMA table_info(t5); 621417ec638Sdrh } 622384b7fe2Sdrh} {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 2 2 c TEXT 0 <<NULL>> 3 3 d INTEGER 0 NULL 0 4 e TEXT 0 '' 1} 623736c7d4bSdrhdb nullvalue {} 624384b7fe2Sdrhdo_test pragma-6.2.3 { 625384b7fe2Sdrh execsql { 626384b7fe2Sdrh CREATE TABLE t2_3(a,b INTEGER PRIMARY KEY,c); 627384b7fe2Sdrh pragma table_info(t2_3) 628384b7fe2Sdrh } 629384b7fe2Sdrh} {0 a {} 0 {} 0 1 b INTEGER 0 {} 1 2 c {} 0 {} 0} 6306bf89570Sdrhifcapable {foreignkey} { 631d2cb50b7Sdrh do_test pragma-6.3.1 { 6325260f7e9Sdrh execsql { 6335260f7e9Sdrh CREATE TABLE t3(a int references t2(b), b UNIQUE); 6345260f7e9Sdrh pragma foreign_key_list(t3); 6355260f7e9Sdrh } 6361da40a38Sdan } {0 0 t2 a b {NO ACTION} {NO ACTION} NONE} 637d2cb50b7Sdrh do_test pragma-6.3.2 { 638d2cb50b7Sdrh execsql { 639d2cb50b7Sdrh pragma foreign_key_list; 640d2cb50b7Sdrh } 641d2cb50b7Sdrh } {} 642d2cb50b7Sdrh do_test pragma-6.3.3 { 643d2cb50b7Sdrh execsql { 644d2cb50b7Sdrh pragma foreign_key_list(t3_bogus); 645d2cb50b7Sdrh } 646d2cb50b7Sdrh } {} 647d2cb50b7Sdrh do_test pragma-6.3.4 { 648d2cb50b7Sdrh execsql { 649d2cb50b7Sdrh pragma foreign_key_list(t5); 650d2cb50b7Sdrh } 651d2cb50b7Sdrh } {} 6525260f7e9Sdrh do_test pragma-6.4 { 653c228be5bSdrh capture_pragma db out { 6545260f7e9Sdrh pragma index_list(t3); 6555260f7e9Sdrh } 656c228be5bSdrh db eval {SELECT seq, "name", "unique" FROM out ORDER BY seq} 6573ef26156Sdrh } {0 sqlite_autoindex_t3_1 1} 6586bf89570Sdrh} 6596bf89570Sdrhifcapable {!foreignkey} { 6606bf89570Sdrh execsql {CREATE TABLE t3(a,b UNIQUE)} 6616bf89570Sdrh} 662d2cb50b7Sdrhdo_test pragma-6.5.1 { 6635260f7e9Sdrh execsql { 6645260f7e9Sdrh CREATE INDEX t3i1 ON t3(a,b); 665c228be5bSdrh } 666c228be5bSdrh capture_pragma db out { 6675260f7e9Sdrh pragma index_info(t3i1); 6685260f7e9Sdrh } 669c228be5bSdrh db eval {SELECT seqno, cid, name FROM out ORDER BY seqno} 6705260f7e9Sdrh} {0 0 a 1 1 b} 671d2cb50b7Sdrhdo_test pragma-6.5.2 { 672d2cb50b7Sdrh execsql { 673d2cb50b7Sdrh pragma index_info(t3i1_bogus); 674d2cb50b7Sdrh } 675d2cb50b7Sdrh} {} 676260d8a6aSdanielk1977 677260d8a6aSdanielk1977ifcapable tempdb { 678260d8a6aSdanielk1977 # Test for ticket #3320. When a temp table of the same name exists, make 679260d8a6aSdanielk1977 # sure the schema of the main table can still be queried using 680260d8a6aSdanielk1977 # "pragma table_info": 681260d8a6aSdanielk1977 do_test pragma-6.6.1 { 682260d8a6aSdanielk1977 execsql { 683260d8a6aSdanielk1977 CREATE TABLE trial(col_main); 684260d8a6aSdanielk1977 CREATE TEMP TABLE trial(col_temp); 685260d8a6aSdanielk1977 } 686260d8a6aSdanielk1977 } {} 687260d8a6aSdanielk1977 do_test pragma-6.6.2 { 688260d8a6aSdanielk1977 execsql { 689260d8a6aSdanielk1977 PRAGMA table_info(trial); 690260d8a6aSdanielk1977 } 691260d8a6aSdanielk1977 } {0 col_temp {} 0 {} 0} 692260d8a6aSdanielk1977 do_test pragma-6.6.3 { 693260d8a6aSdanielk1977 execsql { 694260d8a6aSdanielk1977 PRAGMA temp.table_info(trial); 695260d8a6aSdanielk1977 } 696260d8a6aSdanielk1977 } {0 col_temp {} 0 {} 0} 697260d8a6aSdanielk1977 do_test pragma-6.6.4 { 698260d8a6aSdanielk1977 execsql { 699260d8a6aSdanielk1977 PRAGMA main.table_info(trial); 700260d8a6aSdanielk1977 } 701260d8a6aSdanielk1977 } {0 col_main {} 0 {} 0} 702260d8a6aSdanielk1977} 703f96a3778Sdanielk1977 704f96a3778Sdanielk1977do_test pragma-6.7 { 705f96a3778Sdanielk1977 execsql { 706f96a3778Sdanielk1977 CREATE TABLE test_table( 707f96a3778Sdanielk1977 one INT NOT NULL DEFAULT -1, 708f96a3778Sdanielk1977 two text, 709f96a3778Sdanielk1977 three VARCHAR(45, 65) DEFAULT 'abcde', 710f96a3778Sdanielk1977 four REAL DEFAULT X'abcdef', 711f96a3778Sdanielk1977 five DEFAULT CURRENT_TIME 712f96a3778Sdanielk1977 ); 713f96a3778Sdanielk1977 } 714c228be5bSdrh capture_pragma db out {PRAGMA table_info(test_table)} 715c228be5bSdrh db eval {SELECT cid, "name", type, "notnull", dflt_value, pk FROM out 716c228be5bSdrh ORDER BY cid} 717f96a3778Sdanielk1977} [concat \ 718f96a3778Sdanielk1977 {0 one INT 1 -1 0} \ 719f96a3778Sdanielk1977 {1 two text 0 {} 0} \ 720f96a3778Sdanielk1977 {2 three {VARCHAR(45, 65)} 0 'abcde' 0} \ 721f96a3778Sdanielk1977 {3 four REAL 0 X'abcdef' 0} \ 722f96a3778Sdanielk1977 {4 five {} 0 CURRENT_TIME 0} \ 723f96a3778Sdanielk1977] 72427188fb5Sdanielk1977} ;# ifcapable schema_pragmas 7255260f7e9Sdrh# Miscellaneous tests 7265260f7e9Sdrh# 72727188fb5Sdanielk1977ifcapable schema_pragmas { 728d2cb50b7Sdrhdo_test pragma-7.1.1 { 7295260f7e9Sdrh # Make sure a pragma knows to read the schema if it needs to 7305260f7e9Sdrh db close 7315260f7e9Sdrh sqlite3 db test.db 732c228be5bSdrh capture_pragma db out "PRAGMA index_list(t3)" 733c228be5bSdrh db eval {SELECT name, "origin" FROM out ORDER BY name DESC} 734c228be5bSdrh} {t3i1 c sqlite_autoindex_t3_1 u} 735d2cb50b7Sdrhdo_test pragma-7.1.2 { 736d2cb50b7Sdrh execsql { 737d2cb50b7Sdrh pragma index_list(t3_bogus); 738d2cb50b7Sdrh } 739d2cb50b7Sdrh} {} 74027188fb5Sdanielk1977} ;# ifcapable schema_pragmas 7416c62608fSdrhifcapable {utf16} { 742cb354603Sdan if {[permutation] == ""} { 7435260f7e9Sdrh do_test pragma-7.2 { 7445260f7e9Sdrh db close 7455260f7e9Sdrh sqlite3 db test.db 7465260f7e9Sdrh catchsql { 7475260f7e9Sdrh pragma encoding=bogus; 7485260f7e9Sdrh } 7495260f7e9Sdrh } {1 {unsupported encoding: bogus}} 7506c62608fSdrh } 751cb354603Sdan} 75253c0f748Sdanielk1977ifcapable tempdb { 7535260f7e9Sdrh do_test pragma-7.3 { 7545260f7e9Sdrh db close 7555260f7e9Sdrh sqlite3 db test.db 7565260f7e9Sdrh execsql { 7575260f7e9Sdrh pragma lock_status; 7585260f7e9Sdrh } 7595260f7e9Sdrh } {main unlocked temp closed} 76053c0f748Sdanielk1977} else { 76153c0f748Sdanielk1977 do_test pragma-7.3 { 76253c0f748Sdanielk1977 db close 76353c0f748Sdanielk1977 sqlite3 db test.db 76453c0f748Sdanielk1977 execsql { 76553c0f748Sdanielk1977 pragma lock_status; 76653c0f748Sdanielk1977 } 76753c0f748Sdanielk1977 } {main unlocked} 76853c0f748Sdanielk1977} 7695260f7e9Sdrh 7705260f7e9Sdrh 771dae2495bSdanielk1977#---------------------------------------------------------------------- 772b92b70bbSdanielk1977# Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA 773b92b70bbSdanielk1977# user_version" statements. 774dae2495bSdanielk1977# 775b92b70bbSdanielk1977# pragma-8.1: PRAGMA schema_version 776b92b70bbSdanielk1977# pragma-8.2: PRAGMA user_version 777dae2495bSdanielk1977# 778dae2495bSdanielk1977 77911cf9fbcSdanielk1977ifcapable schema_version { 78011cf9fbcSdanielk1977 781b92b70bbSdanielk1977# First check that we can set the schema version and then retrieve the 782dae2495bSdanielk1977# same value. 783dae2495bSdanielk1977do_test pragma-8.1.1 { 784dae2495bSdanielk1977 execsql { 785b92b70bbSdanielk1977 PRAGMA schema_version = 105; 786dae2495bSdanielk1977 } 787dae2495bSdanielk1977} {} 788dae2495bSdanielk1977do_test pragma-8.1.2 { 78925403650Sdrh execsql2 { 790b92b70bbSdanielk1977 PRAGMA schema_version; 791dae2495bSdanielk1977 } 79225403650Sdrh} {schema_version 105} 793dae2495bSdanielk1977do_test pragma-8.1.3 { 794dae2495bSdanielk1977 execsql { 795b92b70bbSdanielk1977 PRAGMA schema_version = 106; 796dae2495bSdanielk1977 } 797dae2495bSdanielk1977} {} 798dae2495bSdanielk1977do_test pragma-8.1.4 { 799dae2495bSdanielk1977 execsql { 800b92b70bbSdanielk1977 PRAGMA schema_version; 801dae2495bSdanielk1977 } 802dae2495bSdanielk1977} 106 803dae2495bSdanielk1977 804b92b70bbSdanielk1977# Check that creating a table modifies the schema-version (this is really 805b92b70bbSdanielk1977# to verify that the value being read is in fact the schema version). 806dae2495bSdanielk1977do_test pragma-8.1.5 { 807dae2495bSdanielk1977 execsql { 808dae2495bSdanielk1977 CREATE TABLE t4(a, b, c); 809dae2495bSdanielk1977 INSERT INTO t4 VALUES(1, 2, 3); 810dae2495bSdanielk1977 SELECT * FROM t4; 811dae2495bSdanielk1977 } 812dae2495bSdanielk1977} {1 2 3} 813dae2495bSdanielk1977do_test pragma-8.1.6 { 814dae2495bSdanielk1977 execsql { 815b92b70bbSdanielk1977 PRAGMA schema_version; 816dae2495bSdanielk1977 } 817dae2495bSdanielk1977} 107 818dae2495bSdanielk1977 819dae2495bSdanielk1977# Now open a second connection to the database. Ensure that changing the 820b92b70bbSdanielk1977# schema-version using the first connection forces the second connection 821dae2495bSdanielk1977# to reload the schema. This has to be done using the C-API test functions, 822dae2495bSdanielk1977# because the TCL API accounts for SCHEMA_ERROR and retries the query. 823dae2495bSdanielk1977do_test pragma-8.1.7 { 824dddca286Sdrh sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] 825dae2495bSdanielk1977 execsql { 826dae2495bSdanielk1977 SELECT * FROM t4; 827dae2495bSdanielk1977 } db2 828dae2495bSdanielk1977} {1 2 3} 829dae2495bSdanielk1977do_test pragma-8.1.8 { 830dae2495bSdanielk1977 execsql { 831b92b70bbSdanielk1977 PRAGMA schema_version = 108; 832dae2495bSdanielk1977 } 833dae2495bSdanielk1977} {} 834dae2495bSdanielk1977do_test pragma-8.1.9 { 835dae2495bSdanielk1977 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY] 836dae2495bSdanielk1977 sqlite3_step $::STMT 837dae2495bSdanielk1977} SQLITE_ERROR 838dae2495bSdanielk1977do_test pragma-8.1.10 { 839dae2495bSdanielk1977 sqlite3_finalize $::STMT 840dae2495bSdanielk1977} SQLITE_SCHEMA 841dae2495bSdanielk1977 842b92b70bbSdanielk1977# Make sure the schema-version can be manipulated in an attached database. 843fda06befSmistachkinforcedelete test2.db 844fda06befSmistachkinforcedelete test2.db-journal 8455a8f9374Sdanielk1977ifcapable attach { 846dae2495bSdanielk1977 do_test pragma-8.1.11 { 847dae2495bSdanielk1977 execsql { 848dae2495bSdanielk1977 ATTACH 'test2.db' AS aux; 849dae2495bSdanielk1977 CREATE TABLE aux.t1(a, b, c); 850b92b70bbSdanielk1977 PRAGMA aux.schema_version = 205; 851dae2495bSdanielk1977 } 852dae2495bSdanielk1977 } {} 853dae2495bSdanielk1977 do_test pragma-8.1.12 { 854dae2495bSdanielk1977 execsql { 855b92b70bbSdanielk1977 PRAGMA aux.schema_version; 856dae2495bSdanielk1977 } 857dae2495bSdanielk1977 } 205 8585a8f9374Sdanielk1977} 859dae2495bSdanielk1977do_test pragma-8.1.13 { 860dae2495bSdanielk1977 execsql { 861b92b70bbSdanielk1977 PRAGMA schema_version; 862dae2495bSdanielk1977 } 863dae2495bSdanielk1977} 108 864dae2495bSdanielk1977 865b92b70bbSdanielk1977# And check that modifying the schema-version in an attached database 866dae2495bSdanielk1977# forces the second connection to reload the schema. 8675a8f9374Sdanielk1977ifcapable attach { 868dae2495bSdanielk1977 do_test pragma-8.1.14 { 869dddca286Sdrh sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] 870dae2495bSdanielk1977 execsql { 871dae2495bSdanielk1977 ATTACH 'test2.db' AS aux; 872dae2495bSdanielk1977 SELECT * FROM aux.t1; 873dae2495bSdanielk1977 } db2 874dae2495bSdanielk1977 } {} 875dae2495bSdanielk1977 do_test pragma-8.1.15 { 876dae2495bSdanielk1977 execsql { 877b92b70bbSdanielk1977 PRAGMA aux.schema_version = 206; 878dae2495bSdanielk1977 } 879dae2495bSdanielk1977 } {} 880dae2495bSdanielk1977 do_test pragma-8.1.16 { 881dae2495bSdanielk1977 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY] 882dae2495bSdanielk1977 sqlite3_step $::STMT 883dae2495bSdanielk1977 } SQLITE_ERROR 884dae2495bSdanielk1977 do_test pragma-8.1.17 { 885dae2495bSdanielk1977 sqlite3_finalize $::STMT 886dae2495bSdanielk1977 } SQLITE_SCHEMA 887dae2495bSdanielk1977 do_test pragma-8.1.18 { 888dae2495bSdanielk1977 db2 close 889dae2495bSdanielk1977 } {} 8905a8f9374Sdanielk1977} 891dae2495bSdanielk1977 892b92b70bbSdanielk1977# Now test that the user-version can be read and written (and that we aren't 893b92b70bbSdanielk1977# accidentally manipulating the schema-version instead). 894dae2495bSdanielk1977do_test pragma-8.2.1 { 89525403650Sdrh execsql2 { 896b92b70bbSdanielk1977 PRAGMA user_version; 897dae2495bSdanielk1977 } 89825403650Sdrh} {user_version 0} 899dae2495bSdanielk1977do_test pragma-8.2.2 { 900dae2495bSdanielk1977 execsql { 901b92b70bbSdanielk1977 PRAGMA user_version = 2; 902dae2495bSdanielk1977 } 903dae2495bSdanielk1977} {} 904802d69a7Sdrhdo_test pragma-8.2.3.1 { 90525403650Sdrh execsql2 { 906b92b70bbSdanielk1977 PRAGMA user_version; 907dae2495bSdanielk1977 } 90825403650Sdrh} {user_version 2} 909802d69a7Sdrhdo_test pragma-8.2.3.2 { 910802d69a7Sdrh db close 911802d69a7Sdrh sqlite3 db test.db 912802d69a7Sdrh execsql { 913802d69a7Sdrh PRAGMA user_version; 914802d69a7Sdrh } 915802d69a7Sdrh} {2} 916802d69a7Sdrhdo_test pragma-8.2.4.1 { 917dae2495bSdanielk1977 execsql { 918b92b70bbSdanielk1977 PRAGMA schema_version; 919dae2495bSdanielk1977 } 920dae2495bSdanielk1977} {108} 921802d69a7Sdrhifcapable vacuum { 922802d69a7Sdrh do_test pragma-8.2.4.2 { 923802d69a7Sdrh execsql { 924802d69a7Sdrh VACUUM; 925802d69a7Sdrh PRAGMA user_version; 926802d69a7Sdrh } 927802d69a7Sdrh } {2} 928802d69a7Sdrh do_test pragma-8.2.4.3 { 929802d69a7Sdrh execsql { 930802d69a7Sdrh PRAGMA schema_version; 931802d69a7Sdrh } 932802d69a7Sdrh } {109} 933802d69a7Sdrh} 9345a8f9374Sdanielk1977 9355a8f9374Sdanielk1977ifcapable attach { 936802d69a7Sdrh db eval {ATTACH 'test2.db' AS aux} 937dae2495bSdanielk1977 938b92b70bbSdanielk1977 # Check that the user-version in the auxilary database can be manipulated ( 939dae2495bSdanielk1977 # and that we aren't accidentally manipulating the same in the main db). 940dae2495bSdanielk1977 do_test pragma-8.2.5 { 941dae2495bSdanielk1977 execsql { 942b92b70bbSdanielk1977 PRAGMA aux.user_version; 943dae2495bSdanielk1977 } 944dae2495bSdanielk1977 } {0} 945dae2495bSdanielk1977 do_test pragma-8.2.6 { 946dae2495bSdanielk1977 execsql { 947b92b70bbSdanielk1977 PRAGMA aux.user_version = 3; 948dae2495bSdanielk1977 } 949dae2495bSdanielk1977 } {} 950dae2495bSdanielk1977 do_test pragma-8.2.7 { 951dae2495bSdanielk1977 execsql { 952b92b70bbSdanielk1977 PRAGMA aux.user_version; 953dae2495bSdanielk1977 } 954dae2495bSdanielk1977 } {3} 955dae2495bSdanielk1977 do_test pragma-8.2.8 { 956dae2495bSdanielk1977 execsql { 957b92b70bbSdanielk1977 PRAGMA main.user_version; 958dae2495bSdanielk1977 } 959dae2495bSdanielk1977 } {2} 960dae2495bSdanielk1977 961b92b70bbSdanielk1977 # Now check that a ROLLBACK resets the user-version if it has been modified 962dae2495bSdanielk1977 # within a transaction. 963dae2495bSdanielk1977 do_test pragma-8.2.9 { 964dae2495bSdanielk1977 execsql { 965dae2495bSdanielk1977 BEGIN; 966b92b70bbSdanielk1977 PRAGMA aux.user_version = 10; 967b92b70bbSdanielk1977 PRAGMA user_version = 11; 968dae2495bSdanielk1977 } 969dae2495bSdanielk1977 } {} 970dae2495bSdanielk1977 do_test pragma-8.2.10 { 971dae2495bSdanielk1977 execsql { 972b92b70bbSdanielk1977 PRAGMA aux.user_version; 973dae2495bSdanielk1977 } 974dae2495bSdanielk1977 } {10} 975dae2495bSdanielk1977 do_test pragma-8.2.11 { 976dae2495bSdanielk1977 execsql { 977b92b70bbSdanielk1977 PRAGMA main.user_version; 978dae2495bSdanielk1977 } 979dae2495bSdanielk1977 } {11} 980dae2495bSdanielk1977 do_test pragma-8.2.12 { 981dae2495bSdanielk1977 execsql { 982dae2495bSdanielk1977 ROLLBACK; 983b92b70bbSdanielk1977 PRAGMA aux.user_version; 984dae2495bSdanielk1977 } 985dae2495bSdanielk1977 } {3} 986dae2495bSdanielk1977 do_test pragma-8.2.13 { 987dae2495bSdanielk1977 execsql { 988b92b70bbSdanielk1977 PRAGMA main.user_version; 989dae2495bSdanielk1977 } 990dae2495bSdanielk1977 } {2} 9915a8f9374Sdanielk1977} 992dae2495bSdanielk1977 993b92b70bbSdanielk1977# Try a negative value for the user-version 994dae2495bSdanielk1977do_test pragma-8.2.14 { 995dae2495bSdanielk1977 execsql { 996b92b70bbSdanielk1977 PRAGMA user_version = -450; 997dae2495bSdanielk1977 } 998dae2495bSdanielk1977} {} 999dae2495bSdanielk1977do_test pragma-8.2.15 { 1000dae2495bSdanielk1977 execsql { 1001b92b70bbSdanielk1977 PRAGMA user_version; 1002dae2495bSdanielk1977 } 1003dae2495bSdanielk1977} {-450} 1004d9c847dcSdanielk1977} ; # ifcapable schema_version 1005d9c847dcSdanielk1977 1006d19744f3Sdrh# Check to see if TEMP_STORE is memory or disk. Return strings 1007d19744f3Sdrh# "memory" or "disk" as appropriate. 1008d19744f3Sdrh# 1009d19744f3Sdrhproc check_temp_store {} { 1010d19744f3Sdrh db eval {CREATE TEMP TABLE IF NOT EXISTS a(b)} 1011d19744f3Sdrh db eval {PRAGMA database_list} { 1012d19744f3Sdrh if {$name=="temp"} { 101317b90b53Sdanielk1977 set bt [btree_from_db db 1] 101417b90b53Sdanielk1977 if {[btree_ismemdb $bt]} { 1015d19744f3Sdrh return "memory" 1016d19744f3Sdrh } 101717b90b53Sdanielk1977 return "disk" 1018d19744f3Sdrh } 1019d19744f3Sdrh } 1020d19744f3Sdrh return "unknown" 1021d19744f3Sdrh} 1022d19744f3Sdrh 10234ee09b4bSdrh# Application_ID 10244ee09b4bSdrh# 10254ee09b4bSdrhdo_test pragma-8.3.1 { 10264ee09b4bSdrh execsql { 10274ee09b4bSdrh PRAGMA application_id; 10284ee09b4bSdrh } 10294ee09b4bSdrh} {0} 10304ee09b4bSdrhdo_test pragma-8.3.2 { 10314ee09b4bSdrh execsql {PRAGMA Application_ID(12345); PRAGMA application_id;} 10324ee09b4bSdrh} {12345} 10339a09a3caStpoindex 10349a09a3caStpoindex# Test temp_store and temp_store_directory pragmas 10359a09a3caStpoindex# 1036268283bcSdrhifcapable pager_pragmas { 10379a09a3caStpoindexdo_test pragma-9.1 { 10389a09a3caStpoindex db close 10399a09a3caStpoindex sqlite3 db test.db 10409a09a3caStpoindex execsql { 10419a09a3caStpoindex PRAGMA temp_store; 10429a09a3caStpoindex } 10439a09a3caStpoindex} {0} 1044d19744f3Sdrhif {$TEMP_STORE<=1} { 1045d19744f3Sdrh do_test pragma-9.1.1 { 1046d19744f3Sdrh check_temp_store 1047d19744f3Sdrh } {disk} 1048d19744f3Sdrh} else { 1049d19744f3Sdrh do_test pragma-9.1.1 { 1050d19744f3Sdrh check_temp_store 1051d19744f3Sdrh } {memory} 1052d19744f3Sdrh} 1053d19744f3Sdrh 10549a09a3caStpoindexdo_test pragma-9.2 { 1055d19744f3Sdrh db close 1056d19744f3Sdrh sqlite3 db test.db 10579a09a3caStpoindex execsql { 10589a09a3caStpoindex PRAGMA temp_store=file; 10599a09a3caStpoindex PRAGMA temp_store; 10609a09a3caStpoindex } 10619a09a3caStpoindex} {1} 1062d19744f3Sdrhif {$TEMP_STORE==3} { 1063d19744f3Sdrh # When TEMP_STORE is 3, always use memory regardless of pragma settings. 1064d19744f3Sdrh do_test pragma-9.2.1 { 1065d19744f3Sdrh check_temp_store 1066d19744f3Sdrh } {memory} 1067d19744f3Sdrh} else { 1068d19744f3Sdrh do_test pragma-9.2.1 { 1069d19744f3Sdrh check_temp_store 1070d19744f3Sdrh } {disk} 1071d19744f3Sdrh} 1072d19744f3Sdrh 10739a09a3caStpoindexdo_test pragma-9.3 { 1074d19744f3Sdrh db close 1075d19744f3Sdrh sqlite3 db test.db 10769a09a3caStpoindex execsql { 10779a09a3caStpoindex PRAGMA temp_store=memory; 10789a09a3caStpoindex PRAGMA temp_store; 10799a09a3caStpoindex } 10809a09a3caStpoindex} {2} 1081d19744f3Sdrhif {$TEMP_STORE==0} { 1082d19744f3Sdrh # When TEMP_STORE is 0, always use the disk regardless of pragma settings. 1083d19744f3Sdrh do_test pragma-9.3.1 { 1084d19744f3Sdrh check_temp_store 1085d19744f3Sdrh } {disk} 1086d19744f3Sdrh} else { 1087d19744f3Sdrh do_test pragma-9.3.1 { 1088d19744f3Sdrh check_temp_store 1089d19744f3Sdrh } {memory} 1090d19744f3Sdrh} 1091d19744f3Sdrh 10929a09a3caStpoindexdo_test pragma-9.4 { 10939a09a3caStpoindex execsql { 10949a09a3caStpoindex PRAGMA temp_store_directory; 10959a09a3caStpoindex } 10969a09a3caStpoindex} {} 109778f82d1eSdrhifcapable wsd { 10989a09a3caStpoindex do_test pragma-9.5 { 1099f8a78464Smistachkin set pwd [string map {' ''} [file nativename [get_pwd]]] 1100268283bcSdrh execsql " 1101268283bcSdrh PRAGMA temp_store_directory='$pwd'; 11029a09a3caStpoindex " 11039a09a3caStpoindex } {} 11049a09a3caStpoindex do_test pragma-9.6 { 11059a09a3caStpoindex execsql { 11069a09a3caStpoindex PRAGMA temp_store_directory; 11079a09a3caStpoindex } 1108f8a78464Smistachkin } [list [file nativename [get_pwd]]] 11099a09a3caStpoindex do_test pragma-9.7 { 1110268283bcSdrh catchsql { 11119a09a3caStpoindex PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR'; 11129a09a3caStpoindex } 1113268283bcSdrh } {1 {not a writable directory}} 11149a09a3caStpoindex do_test pragma-9.8 { 11159a09a3caStpoindex execsql { 11169a09a3caStpoindex PRAGMA temp_store_directory=''; 11179a09a3caStpoindex } 11189a09a3caStpoindex } {} 11191e9daa6aSdrh if {![info exists TEMP_STORE] || $TEMP_STORE<=1} { 112053c0f748Sdanielk1977 ifcapable tempdb { 11219a09a3caStpoindex do_test pragma-9.9 { 11229a09a3caStpoindex execsql { 11239a09a3caStpoindex PRAGMA temp_store_directory; 11249a09a3caStpoindex PRAGMA temp_store=FILE; 11259a09a3caStpoindex CREATE TEMP TABLE temp_store_directory_test(a integer); 11269a09a3caStpoindex INSERT INTO temp_store_directory_test values (2); 11279a09a3caStpoindex SELECT * FROM temp_store_directory_test; 11289a09a3caStpoindex } 11299a09a3caStpoindex } {2} 11309a09a3caStpoindex do_test pragma-9.10 { 1131268283bcSdrh catchsql " 1132268283bcSdrh PRAGMA temp_store_directory='$pwd'; 11339a09a3caStpoindex SELECT * FROM temp_store_directory_test; 11349a09a3caStpoindex " 1135268283bcSdrh } {1 {no such table: temp_store_directory_test}} 11361e9daa6aSdrh } 11371e9daa6aSdrh } 113878f82d1eSdrh} 113995b289b6Sdanielk1977do_test pragma-9.11 { 114095b289b6Sdanielk1977 execsql { 114195b289b6Sdanielk1977 PRAGMA temp_store = 0; 114295b289b6Sdanielk1977 PRAGMA temp_store; 114395b289b6Sdanielk1977 } 114495b289b6Sdanielk1977} {0} 114595b289b6Sdanielk1977do_test pragma-9.12 { 114695b289b6Sdanielk1977 execsql { 114795b289b6Sdanielk1977 PRAGMA temp_store = 1; 114895b289b6Sdanielk1977 PRAGMA temp_store; 114995b289b6Sdanielk1977 } 115095b289b6Sdanielk1977} {1} 115195b289b6Sdanielk1977do_test pragma-9.13 { 115295b289b6Sdanielk1977 execsql { 115395b289b6Sdanielk1977 PRAGMA temp_store = 2; 115495b289b6Sdanielk1977 PRAGMA temp_store; 115595b289b6Sdanielk1977 } 115695b289b6Sdanielk1977} {2} 115795b289b6Sdanielk1977do_test pragma-9.14 { 115895b289b6Sdanielk1977 execsql { 115995b289b6Sdanielk1977 PRAGMA temp_store = 3; 116095b289b6Sdanielk1977 PRAGMA temp_store; 116195b289b6Sdanielk1977 } 116295b289b6Sdanielk1977} {0} 116395b289b6Sdanielk1977do_test pragma-9.15 { 116495b289b6Sdanielk1977 catchsql { 116595b289b6Sdanielk1977 BEGIN EXCLUSIVE; 116695b289b6Sdanielk1977 CREATE TEMP TABLE temp_table(t); 116795b289b6Sdanielk1977 INSERT INTO temp_table VALUES('valuable data'); 116895b289b6Sdanielk1977 PRAGMA temp_store = 1; 116995b289b6Sdanielk1977 } 117095b289b6Sdanielk1977} {1 {temporary storage cannot be changed from within a transaction}} 117195b289b6Sdanielk1977do_test pragma-9.16 { 117295b289b6Sdanielk1977 execsql { 117395b289b6Sdanielk1977 SELECT * FROM temp_table; 117495b289b6Sdanielk1977 COMMIT; 117595b289b6Sdanielk1977 } 117695b289b6Sdanielk1977} {{valuable data}} 1177983e2309Sdanielk1977 1178983e2309Sdanielk1977do_test pragma-9.17 { 1179983e2309Sdanielk1977 execsql { 1180983e2309Sdanielk1977 INSERT INTO temp_table VALUES('valuable data II'); 1181983e2309Sdanielk1977 SELECT * FROM temp_table; 1182983e2309Sdanielk1977 } 1183983e2309Sdanielk1977} {{valuable data} {valuable data II}} 1184983e2309Sdanielk1977 1185983e2309Sdanielk1977do_test pragma-9.18 { 1186983e2309Sdanielk1977 set rc [catch { 1187983e2309Sdanielk1977 db eval {SELECT t FROM temp_table} { 1188983e2309Sdanielk1977 execsql {pragma temp_store = 1} 1189983e2309Sdanielk1977 } 1190983e2309Sdanielk1977 } msg] 1191983e2309Sdanielk1977 list $rc $msg 1192983e2309Sdanielk1977} {1 {temporary storage cannot be changed from within a transaction}} 1193983e2309Sdanielk1977 1194268283bcSdrh} ;# ifcapable pager_pragmas 11959a09a3caStpoindex 1196cc6bd383Sdanielk1977ifcapable trigger { 1197cc6bd383Sdanielk1977 1198cc6bd383Sdanielk1977do_test pragma-10.0 { 1199cc6bd383Sdanielk1977 catchsql { 1200cc6bd383Sdanielk1977 DROP TABLE main.t1; 1201cc6bd383Sdanielk1977 } 1202cc6bd383Sdanielk1977 execsql { 1203cc6bd383Sdanielk1977 PRAGMA count_changes = 1; 1204cc6bd383Sdanielk1977 1205cc6bd383Sdanielk1977 CREATE TABLE t1(a PRIMARY KEY); 1206cc6bd383Sdanielk1977 CREATE TABLE t1_mirror(a); 1207cc6bd383Sdanielk1977 CREATE TABLE t1_mirror2(a); 1208cc6bd383Sdanielk1977 CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN 1209cc6bd383Sdanielk1977 INSERT INTO t1_mirror VALUES(new.a); 1210cc6bd383Sdanielk1977 END; 1211cc6bd383Sdanielk1977 CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN 1212cc6bd383Sdanielk1977 INSERT INTO t1_mirror2 VALUES(new.a); 1213cc6bd383Sdanielk1977 END; 1214cc6bd383Sdanielk1977 CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN 1215cc6bd383Sdanielk1977 UPDATE t1_mirror SET a = new.a WHERE a = old.a; 1216cc6bd383Sdanielk1977 END; 1217cc6bd383Sdanielk1977 CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN 1218cc6bd383Sdanielk1977 UPDATE t1_mirror2 SET a = new.a WHERE a = old.a; 1219cc6bd383Sdanielk1977 END; 1220cc6bd383Sdanielk1977 CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN 1221cc6bd383Sdanielk1977 DELETE FROM t1_mirror WHERE a = old.a; 1222cc6bd383Sdanielk1977 END; 1223cc6bd383Sdanielk1977 CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN 1224cc6bd383Sdanielk1977 DELETE FROM t1_mirror2 WHERE a = old.a; 1225cc6bd383Sdanielk1977 END; 1226cc6bd383Sdanielk1977 } 1227cc6bd383Sdanielk1977} {} 1228cc6bd383Sdanielk1977 1229cc6bd383Sdanielk1977do_test pragma-10.1 { 1230cc6bd383Sdanielk1977 execsql { 1231cc6bd383Sdanielk1977 INSERT INTO t1 VALUES(randstr(10,10)); 1232cc6bd383Sdanielk1977 } 1233cc6bd383Sdanielk1977} {1} 1234cc6bd383Sdanielk1977do_test pragma-10.2 { 1235cc6bd383Sdanielk1977 execsql { 1236cc6bd383Sdanielk1977 UPDATE t1 SET a = randstr(10,10); 1237cc6bd383Sdanielk1977 } 1238cc6bd383Sdanielk1977} {1} 1239cc6bd383Sdanielk1977do_test pragma-10.3 { 1240cc6bd383Sdanielk1977 execsql { 1241cc6bd383Sdanielk1977 DELETE FROM t1; 1242cc6bd383Sdanielk1977 } 1243cc6bd383Sdanielk1977} {1} 1244cc6bd383Sdanielk1977 1245cc6bd383Sdanielk1977} ;# ifcapable trigger 1246cc6bd383Sdanielk1977 124748af65aeSdanielk1977ifcapable schema_pragmas { 124848af65aeSdanielk1977 do_test pragma-11.1 { 124948af65aeSdanielk1977 execsql2 { 125048af65aeSdanielk1977 pragma collation_list; 125148af65aeSdanielk1977 } 12522d823315Sdrh } {seq 0 name RTRIM seq 1 name NOCASE seq 2 name BINARY} 125348af65aeSdanielk1977 do_test pragma-11.2 { 125448af65aeSdanielk1977 db collate New_Collation blah... 125548af65aeSdanielk1977 execsql { 125648af65aeSdanielk1977 pragma collation_list; 125748af65aeSdanielk1977 } 12582d823315Sdrh } {0 New_Collation 1 RTRIM 2 NOCASE 3 BINARY} 125948af65aeSdanielk1977} 126048af65aeSdanielk1977 1261ddfb2f03Sdanielk1977ifcapable schema_pragmas&&tempdb { 1262ddfb2f03Sdanielk1977 do_test pragma-12.1 { 1263ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1264ddfb2f03Sdanielk1977 execsql { 1265ddfb2f03Sdanielk1977 PRAGMA temp.table_info('abc'); 1266ddfb2f03Sdanielk1977 } db2 1267ddfb2f03Sdanielk1977 } {} 1268ddfb2f03Sdanielk1977 db2 close 1269ddfb2f03Sdanielk1977 1270ddfb2f03Sdanielk1977 do_test pragma-12.2 { 1271ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1272ddfb2f03Sdanielk1977 execsql { 1273ddfb2f03Sdanielk1977 PRAGMA temp.default_cache_size = 200; 1274ddfb2f03Sdanielk1977 PRAGMA temp.default_cache_size; 1275ddfb2f03Sdanielk1977 } db2 1276ddfb2f03Sdanielk1977 } {200} 1277ddfb2f03Sdanielk1977 db2 close 1278ddfb2f03Sdanielk1977 1279ddfb2f03Sdanielk1977 do_test pragma-12.3 { 1280ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1281ddfb2f03Sdanielk1977 execsql { 1282ddfb2f03Sdanielk1977 PRAGMA temp.cache_size = 400; 1283ddfb2f03Sdanielk1977 PRAGMA temp.cache_size; 1284ddfb2f03Sdanielk1977 } db2 1285ddfb2f03Sdanielk1977 } {400} 1286ddfb2f03Sdanielk1977 db2 close 1287ddfb2f03Sdanielk1977} 1288ddfb2f03Sdanielk1977 12894b2688abSdanielk1977ifcapable bloblit { 12904b2688abSdanielk1977 129105a82983Sdrhdo_test pragma-13.1 { 129205a82983Sdrh execsql { 129305a82983Sdrh DROP TABLE IF EXISTS t4; 129405a82983Sdrh PRAGMA vdbe_trace=on; 129505a82983Sdrh PRAGMA vdbe_listing=on; 129605a82983Sdrh PRAGMA sql_trace=on; 129705a82983Sdrh CREATE TABLE t4(a INTEGER PRIMARY KEY,b); 129805a82983Sdrh INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789'); 129905a82983Sdrh INSERT INTO t4(b) VALUES(randstr(30,30)); 130005a82983Sdrh INSERT INTO t4(b) VALUES(1.23456); 130105a82983Sdrh INSERT INTO t4(b) VALUES(NULL); 130205a82983Sdrh INSERT INTO t4(b) VALUES(0); 130305a82983Sdrh INSERT INTO t4(b) SELECT b||b||b||b FROM t4; 130405a82983Sdrh SELECT * FROM t4; 130505a82983Sdrh } 130605a82983Sdrh execsql { 130705a82983Sdrh PRAGMA vdbe_trace=off; 130805a82983Sdrh PRAGMA vdbe_listing=off; 130905a82983Sdrh PRAGMA sql_trace=off; 131005a82983Sdrh } 131105a82983Sdrh} {} 131205a82983Sdrh 13134b2688abSdanielk1977} ;# ifcapable bloblit 13144b2688abSdanielk1977 131559a93791Sdanielk1977ifcapable pager_pragmas { 131659a93791Sdanielk1977 db close 1317fda06befSmistachkin forcedelete test.db 131859a93791Sdanielk1977 sqlite3 db test.db 131959a93791Sdanielk1977 132059a93791Sdanielk1977 do_test pragma-14.1 { 132159a93791Sdanielk1977 execsql { pragma auto_vacuum = 0 } 132259a93791Sdanielk1977 execsql { pragma page_count } 132359a93791Sdanielk1977 } {0} 132459a93791Sdanielk1977 132559a93791Sdanielk1977 do_test pragma-14.2 { 132659a93791Sdanielk1977 execsql { 132759a93791Sdanielk1977 CREATE TABLE abc(a, b, c); 132859a93791Sdanielk1977 PRAGMA page_count; 132959a93791Sdanielk1977 } 133059a93791Sdanielk1977 } {2} 13315d16a9a6Sdrh do_test pragma-14.2uc { 13325d16a9a6Sdrh execsql {pragma PAGE_COUNT} 13335d16a9a6Sdrh } {2} 133459a93791Sdanielk1977 133559a93791Sdanielk1977 do_test pragma-14.3 { 133659a93791Sdanielk1977 execsql { 133759a93791Sdanielk1977 BEGIN; 133859a93791Sdanielk1977 CREATE TABLE def(a, b, c); 133959a93791Sdanielk1977 PRAGMA page_count; 134059a93791Sdanielk1977 } 134159a93791Sdanielk1977 } {3} 13425d16a9a6Sdrh do_test pragma-14.3uc { 13435d16a9a6Sdrh execsql {pragma PAGE_COUNT} 13445d16a9a6Sdrh } {3} 134559a93791Sdanielk1977 134659a93791Sdanielk1977 do_test pragma-14.4 { 134759a93791Sdanielk1977 set page_size [db one {pragma page_size}] 134859a93791Sdanielk1977 expr [file size test.db] / $page_size 134959a93791Sdanielk1977 } {2} 135059a93791Sdanielk1977 135159a93791Sdanielk1977 do_test pragma-14.5 { 135259a93791Sdanielk1977 execsql { 135359a93791Sdanielk1977 ROLLBACK; 135459a93791Sdanielk1977 PRAGMA page_count; 135559a93791Sdanielk1977 } 135659a93791Sdanielk1977 } {2} 135759a93791Sdanielk1977 135859a93791Sdanielk1977 do_test pragma-14.6 { 1359fda06befSmistachkin forcedelete test2.db 136059a93791Sdanielk1977 sqlite3 db2 test2.db 136159a93791Sdanielk1977 execsql { 136259a93791Sdanielk1977 PRAGMA auto_vacuum = 0; 136359a93791Sdanielk1977 CREATE TABLE t1(a, b, c); 136459a93791Sdanielk1977 CREATE TABLE t2(a, b, c); 136559a93791Sdanielk1977 CREATE TABLE t3(a, b, c); 136659a93791Sdanielk1977 CREATE TABLE t4(a, b, c); 136759a93791Sdanielk1977 } db2 136859a93791Sdanielk1977 db2 close 136959a93791Sdanielk1977 execsql { 137059a93791Sdanielk1977 ATTACH 'test2.db' AS aux; 137159a93791Sdanielk1977 PRAGMA aux.page_count; 137259a93791Sdanielk1977 } 137359a93791Sdanielk1977 } {5} 13745d16a9a6Sdrh do_test pragma-14.6uc { 13755d16a9a6Sdrh execsql {pragma AUX.PAGE_COUNT} 13765d16a9a6Sdrh } {5} 137759a93791Sdanielk1977} 137859a93791Sdanielk1977 13798cf6c554Sdanielk1977# Test that the value set using the cache_size pragma is not reset when the 13808cf6c554Sdanielk1977# schema is reloaded. 13818cf6c554Sdanielk1977# 13828cf6c554Sdanielk1977ifcapable pager_pragmas { 13838cf6c554Sdanielk1977 db close 13848cf6c554Sdanielk1977 sqlite3 db test.db 13858cf6c554Sdanielk1977 do_test pragma-15.1 { 13868cf6c554Sdanielk1977 execsql { 13878cf6c554Sdanielk1977 PRAGMA cache_size=59; 13888cf6c554Sdanielk1977 PRAGMA cache_size; 13898cf6c554Sdanielk1977 } 13908cf6c554Sdanielk1977 } {59} 13918cf6c554Sdanielk1977 do_test pragma-15.2 { 13928cf6c554Sdanielk1977 sqlite3 db2 test.db 13938cf6c554Sdanielk1977 execsql { 13948cf6c554Sdanielk1977 CREATE TABLE newtable(a, b, c); 13958cf6c554Sdanielk1977 } db2 13968cf6c554Sdanielk1977 db2 close 13978cf6c554Sdanielk1977 } {} 13988cf6c554Sdanielk1977 do_test pragma-15.3 { 13998cf6c554Sdanielk1977 # Evaluating this statement will cause the schema to be reloaded (because 14008cf6c554Sdanielk1977 # the schema was changed by another connection in pragma-15.2). At one 14018cf6c554Sdanielk1977 # point there was a bug that reset the cache_size to its default value 14028cf6c554Sdanielk1977 # when this happened. 14038cf6c554Sdanielk1977 execsql { SELECT * FROM sqlite_master } 14048cf6c554Sdanielk1977 execsql { PRAGMA cache_size } 14058cf6c554Sdanielk1977 } {59} 14068cf6c554Sdanielk1977} 14078cf6c554Sdanielk1977 14085558a8a6Sdanielk1977# Reset the sqlite3_temp_directory variable for the next run of tests: 14095558a8a6Sdanielk1977sqlite3 dbX :memory: 14105558a8a6Sdanielk1977dbX eval {PRAGMA temp_store_directory = ""} 14115558a8a6Sdanielk1977dbX close 14125558a8a6Sdanielk1977 1413838cce43Sdanielk1977ifcapable lock_proxy_pragmas&&prefer_proxy_locking { 1414aebf413dSaswift set sqlite_hostid_num 1 1415aebf413dSaswift 1416aebf413dSaswift set using_proxy 0 1417aebf413dSaswift foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] { 1418aebf413dSaswift set using_proxy $value 1419aebf413dSaswift } 1420aebf413dSaswift 1421aebf413dSaswift # Test the lock_proxy_file pragmas. 1422aebf413dSaswift # 1423aebf413dSaswift db close 1424aebf413dSaswift set env(SQLITE_FORCE_PROXY_LOCKING) "0" 1425aebf413dSaswift 1426aebf413dSaswift sqlite3 db test.db 1427aebf413dSaswift do_test pragma-16.1 { 1428aebf413dSaswift execsql { 1429aebf413dSaswift PRAGMA lock_proxy_file="mylittleproxy"; 1430aebf413dSaswift select * from sqlite_master; 1431aebf413dSaswift } 1432aebf413dSaswift execsql { 1433aebf413dSaswift PRAGMA lock_proxy_file; 1434aebf413dSaswift } 1435aebf413dSaswift } {mylittleproxy} 1436aebf413dSaswift 1437aebf413dSaswift do_test pragma-16.2 { 1438aebf413dSaswift sqlite3 db2 test.db 1439aebf413dSaswift execsql { 1440aebf413dSaswift PRAGMA lock_proxy_file="mylittleproxy"; 1441aebf413dSaswift } db2 1442aebf413dSaswift } {} 1443aebf413dSaswift 1444aebf413dSaswift db2 close 1445aebf413dSaswift do_test pragma-16.2.1 { 1446aebf413dSaswift sqlite3 db2 test.db 1447aebf413dSaswift execsql { 1448aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1449aebf413dSaswift select * from sqlite_master; 1450aebf413dSaswift } db2 1451aebf413dSaswift execsql { 1452aebf413dSaswift PRAGMA lock_proxy_file; 1453aebf413dSaswift } db2 1454aebf413dSaswift } {mylittleproxy} 1455aebf413dSaswift 1456aebf413dSaswift db2 close 1457aebf413dSaswift do_test pragma-16.3 { 1458aebf413dSaswift sqlite3 db2 test.db 1459aebf413dSaswift execsql { 1460aebf413dSaswift PRAGMA lock_proxy_file="myotherproxy"; 1461aebf413dSaswift } db2 1462aebf413dSaswift catchsql { 1463aebf413dSaswift select * from sqlite_master; 1464aebf413dSaswift } db2 1465aebf413dSaswift } {1 {database is locked}} 1466aebf413dSaswift 1467aebf413dSaswift do_test pragma-16.4 { 1468aebf413dSaswift db2 close 1469aebf413dSaswift db close 1470aebf413dSaswift sqlite3 db2 test.db 1471aebf413dSaswift execsql { 1472aebf413dSaswift PRAGMA lock_proxy_file="myoriginalproxy"; 1473aebf413dSaswift PRAGMA lock_proxy_file="myotherproxy"; 1474aebf413dSaswift PRAGMA lock_proxy_file; 1475aebf413dSaswift } db2 1476aebf413dSaswift } {myotherproxy} 1477aebf413dSaswift 1478aebf413dSaswift db2 close 1479aebf413dSaswift set env(SQLITE_FORCE_PROXY_LOCKING) "1" 1480aebf413dSaswift do_test pragma-16.5 { 1481aebf413dSaswift sqlite3 db2 test.db 1482aebf413dSaswift execsql { 1483aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1484aebf413dSaswift PRAGMA lock_proxy_file; 1485aebf413dSaswift } db2 1486aebf413dSaswift } {myotherproxy} 1487aebf413dSaswift 1488aebf413dSaswift do_test pragma-16.6 { 1489aebf413dSaswift db2 close 1490aebf413dSaswift sqlite3 db2 test2.db 1491aebf413dSaswift set lockpath [execsql { 1492aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1493aebf413dSaswift PRAGMA lock_proxy_file; 1494aebf413dSaswift } db2] 1495aebf413dSaswift string match "*test2.db:auto:" $lockpath 1496aebf413dSaswift } {1} 1497aebf413dSaswift 1498aebf413dSaswift set sqlite_hostid_num 2 1499aebf413dSaswift do_test pragma-16.7 { 150014d14607Sdan list [catch { 1501aebf413dSaswift sqlite3 db test2.db 1502aebf413dSaswift execsql { 1503aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1504aebf413dSaswift select * from sqlite_master; 1505aebf413dSaswift } 150614d14607Sdan } msg] $msg 1507aebf413dSaswift } {1 {database is locked}} 1508aebf413dSaswift db close 1509aebf413dSaswift 1510aebf413dSaswift do_test pragma-16.8 { 151114d14607Sdan list [catch { 1512aebf413dSaswift sqlite3 db test2.db 151314d14607Sdan execsql { select * from sqlite_master } 151414d14607Sdan } msg] $msg 1515aebf413dSaswift } {1 {database is locked}} 1516aebf413dSaswift 1517aebf413dSaswift db2 close 1518aebf413dSaswift do_test pragma-16.8.1 { 1519aebf413dSaswift execsql { 1520aebf413dSaswift PRAGMA lock_proxy_file="yetanotherproxy"; 1521aebf413dSaswift PRAGMA lock_proxy_file; 1522aebf413dSaswift } 1523aebf413dSaswift } {yetanotherproxy} 1524aebf413dSaswift do_test pragma-16.8.2 { 1525aebf413dSaswift execsql { 1526aebf413dSaswift create table mine(x); 1527aebf413dSaswift } 1528aebf413dSaswift } {} 1529aebf413dSaswift 1530aebf413dSaswift db close 1531aebf413dSaswift do_test pragma-16.9 { 1532aebf413dSaswift sqlite3 db proxytest.db 1533aebf413dSaswift set lockpath2 [execsql { 1534aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1535aebf413dSaswift PRAGMA lock_proxy_file; 1536aebf413dSaswift } db] 1537aebf413dSaswift string match "*proxytest.db:auto:" $lockpath2 1538aebf413dSaswift } {1} 1539aebf413dSaswift 1540aebf413dSaswift set env(SQLITE_FORCE_PROXY_LOCKING) $using_proxy 1541aebf413dSaswift set sqlite_hostid_num 0 1542aebf413dSaswift} 1543d2cb50b7Sdrh 1544d2cb50b7Sdrh# Parsing of auto_vacuum settings. 1545d2cb50b7Sdrh# 1546d2cb50b7Sdrhforeach {autovac_setting val} { 1547d2cb50b7Sdrh 0 0 1548d2cb50b7Sdrh 1 1 1549d2cb50b7Sdrh 2 2 1550d2cb50b7Sdrh 3 0 1551d2cb50b7Sdrh -1 0 1552d2cb50b7Sdrh none 0 1553d2cb50b7Sdrh NONE 0 1554d2cb50b7Sdrh NoNe 0 1555d2cb50b7Sdrh full 1 1556d2cb50b7Sdrh FULL 1 1557d2cb50b7Sdrh incremental 2 1558d2cb50b7Sdrh INCREMENTAL 2 1559d2cb50b7Sdrh -1234 0 1560d2cb50b7Sdrh 1234 0 1561d2cb50b7Sdrh} { 1562d2cb50b7Sdrh do_test pragma-17.1.$autovac_setting { 1563d2cb50b7Sdrh catch {db close} 1564d2cb50b7Sdrh sqlite3 db :memory: 1565d2cb50b7Sdrh execsql " 1566d2cb50b7Sdrh PRAGMA auto_vacuum=$::autovac_setting; 1567d2cb50b7Sdrh PRAGMA auto_vacuum; 1568d2cb50b7Sdrh " 1569d2cb50b7Sdrh } $val 1570d2cb50b7Sdrh} 1571d2cb50b7Sdrh 1572d2cb50b7Sdrh# Parsing of temp_store settings. 1573d2cb50b7Sdrh# 1574d2cb50b7Sdrhforeach {temp_setting val} { 1575d2cb50b7Sdrh 0 0 1576d2cb50b7Sdrh 1 1 1577d2cb50b7Sdrh 2 2 1578d2cb50b7Sdrh 3 0 1579d2cb50b7Sdrh -1 0 1580d2cb50b7Sdrh file 1 1581d2cb50b7Sdrh FILE 1 1582d2cb50b7Sdrh fIlE 1 1583d2cb50b7Sdrh memory 2 1584d2cb50b7Sdrh MEMORY 2 1585d2cb50b7Sdrh MeMoRy 2 1586d2cb50b7Sdrh} { 1587d2cb50b7Sdrh do_test pragma-18.1.$temp_setting { 1588d2cb50b7Sdrh catch {db close} 1589d2cb50b7Sdrh sqlite3 db :memory: 1590d2cb50b7Sdrh execsql " 1591d2cb50b7Sdrh PRAGMA temp_store=$::temp_setting; 1592d2cb50b7Sdrh PRAGMA temp_store=$::temp_setting; 1593d2cb50b7Sdrh PRAGMA temp_store; 1594d2cb50b7Sdrh " 1595d2cb50b7Sdrh } $val 1596d2cb50b7Sdrh} 1597d2cb50b7Sdrh 159892c700dbSdrh# The SQLITE_FCNTL_PRAGMA logic, with error handling. 159992c700dbSdrh# 160092c700dbSdrhdb close 160192c700dbSdrhtestvfs tvfs 160292c700dbSdrhsqlite3 db test.db -vfs tvfs 160392c700dbSdrhdo_test pragma-19.1 { 160492c700dbSdrh catchsql {PRAGMA error} 160592c700dbSdrh} {1 {SQL logic error or missing database}} 160692c700dbSdrhdo_test pragma-19.2 { 160792c700dbSdrh catchsql {PRAGMA error='This is the error message'} 160892c700dbSdrh} {1 {This is the error message}} 160992c700dbSdrhdo_test pragma-19.3 { 161092c700dbSdrh catchsql {PRAGMA error='7 This is the error message'} 161192c700dbSdrh} {1 {This is the error message}} 161292c700dbSdrhdo_test pragma-19.4 { 161392c700dbSdrh catchsql {PRAGMA error=7} 161492c700dbSdrh} {1 {out of memory}} 1615c8517f61Sdrhdo_test pragma-19.5 { 16165b044545Smistachkin file tail [lindex [execsql {PRAGMA filename}] 0] 1617c8517f61Sdrh} {test.db} 161892c700dbSdrh 1619cc71645bSdrhif {$tcl_platform(platform)=="windows"} { 1620a112d140Smistachkin# Test data_store_directory pragma 1621a112d140Smistachkin# 1622a112d140Smistachkindb close 1623a112d140Smistachkinsqlite3 db test.db 1624a112d140Smistachkinfile mkdir data_dir 1625a112d140Smistachkindo_test pragma-20.1 { 1626a112d140Smistachkin catchsql {PRAGMA data_store_directory} 1627a112d140Smistachkin} {0 {}} 1628a112d140Smistachkindo_test pragma-20.2 { 1629a112d140Smistachkin set pwd [string map {' ''} [file nativename [get_pwd]]] 1630a112d140Smistachkin catchsql "PRAGMA data_store_directory='$pwd';" 1631a112d140Smistachkin} {0 {}} 1632a112d140Smistachkindo_test pragma-20.3 { 1633a112d140Smistachkin catchsql {PRAGMA data_store_directory} 1634a112d140Smistachkin} [list 0 [list [file nativename [get_pwd]]]] 1635a112d140Smistachkindo_test pragma-20.4 { 1636a112d140Smistachkin set pwd [string map {' ''} [file nativename \ 1637a112d140Smistachkin [file join [get_pwd] data_dir]]] 1638a112d140Smistachkin catchsql "PRAGMA data_store_directory='$pwd';" 1639a112d140Smistachkin} {0 {}} 1640a112d140Smistachkindo_test pragma-20.5 { 1641a112d140Smistachkin sqlite3 db2 test2.db 1642a112d140Smistachkin catchsql "PRAGMA database_list;" db2 1643a112d140Smistachkin} [list 0 [list 0 main [file nativename \ 1644a112d140Smistachkin [file join [get_pwd] data_dir test2.db]]]] 1645a112d140Smistachkincatch {db2 close} 1646a112d140Smistachkindo_test pragma-20.6 { 1647a112d140Smistachkin sqlite3 db2 [file join [get_pwd] test2.db] 1648a112d140Smistachkin catchsql "PRAGMA database_list;" db2 1649a112d140Smistachkin} [list 0 [list 0 main [file nativename \ 1650a112d140Smistachkin [file join [get_pwd] test2.db]]]] 1651a112d140Smistachkincatch {db2 close} 1652a112d140Smistachkindo_test pragma-20.7 { 1653a112d140Smistachkin catchsql "PRAGMA data_store_directory='';" 1654a112d140Smistachkin} {0 {}} 1655a112d140Smistachkindo_test pragma-20.8 { 1656a112d140Smistachkin catchsql {PRAGMA data_store_directory} 1657a112d140Smistachkin} {0 {}} 165892c700dbSdrh 1659a112d140Smistachkinforcedelete data_dir 1660cc71645bSdrh} ;# endif windows 1661cd61c281Sdrh 16621fed5dabSdandatabase_may_be_corrupt 16631fed5dabSdan 16645885e762Sdando_test 21.1 { 16655885e762Sdan # Create a corrupt database in testerr.db. And a non-corrupt at test.db. 16665885e762Sdan # 16675885e762Sdan db close 16685885e762Sdan forcedelete test.db 16695885e762Sdan sqlite3 db test.db 16705885e762Sdan execsql { 16715885e762Sdan PRAGMA page_size = 1024; 16725885e762Sdan PRAGMA auto_vacuum = 0; 16735885e762Sdan CREATE TABLE t1(a PRIMARY KEY, b); 16745885e762Sdan INSERT INTO t1 VALUES(1, 1); 16755885e762Sdan } 16765885e762Sdan for {set i 0} {$i < 10} {incr i} { 16775885e762Sdan execsql { INSERT INTO t1 SELECT a + (1 << $i), b + (1 << $i) FROM t1 } 16785885e762Sdan } 16795885e762Sdan db close 16805885e762Sdan forcecopy test.db testerr.db 16815885e762Sdan hexio_write testerr.db 15000 [string repeat 55 100] 16825885e762Sdan} {100} 16835885e762Sdan 16845885e762Sdanset mainerr {*** in database main *** 16855885e762SdanMultiple uses for byte 672 of page 15} 16865885e762Sdanset auxerr {*** in database aux *** 16875885e762SdanMultiple uses for byte 672 of page 15} 16885885e762Sdan 1689597515d7Sdanset mainerr {/{\*\*\* in database main \*\*\* 1690597515d7SdanMultiple uses for byte 672 of page 15}.*/} 1691597515d7Sdanset auxerr {/{\*\*\* in database aux \*\*\* 1692597515d7SdanMultiple uses for byte 672 of page 15}.*/} 1693597515d7Sdan 16945885e762Sdando_test 22.2 { 16955885e762Sdan catch { db close } 16965885e762Sdan sqlite3 db testerr.db 16975885e762Sdan execsql { PRAGMA integrity_check } 1698597515d7Sdan} $mainerr 16995885e762Sdan 17005885e762Sdando_test 22.3.1 { 17015885e762Sdan catch { db close } 17025885e762Sdan sqlite3 db test.db 17035885e762Sdan execsql { 17045885e762Sdan ATTACH 'testerr.db' AS 'aux'; 17055885e762Sdan PRAGMA integrity_check; 17065885e762Sdan } 1707597515d7Sdan} $auxerr 17085885e762Sdando_test 22.3.2 { 17095885e762Sdan execsql { PRAGMA main.integrity_check; } 17105885e762Sdan} {ok} 17115885e762Sdando_test 22.3.3 { 17125885e762Sdan execsql { PRAGMA aux.integrity_check; } 1713597515d7Sdan} $auxerr 17145885e762Sdan 17155885e762Sdando_test 22.4.1 { 17165885e762Sdan catch { db close } 17175885e762Sdan sqlite3 db testerr.db 17185885e762Sdan execsql { 17195885e762Sdan ATTACH 'test.db' AS 'aux'; 17205885e762Sdan PRAGMA integrity_check; 17215885e762Sdan } 1722597515d7Sdan} $mainerr 17235885e762Sdando_test 22.4.2 { 17245885e762Sdan execsql { PRAGMA main.integrity_check; } 1725597515d7Sdan} $mainerr 17265885e762Sdando_test 22.4.3 { 17275885e762Sdan execsql { PRAGMA aux.integrity_check; } 17285885e762Sdan} {ok} 17295885e762Sdan 1730c95e01daSdrhdb close 1731c95e01daSdrhforcedelete test.db test.db-wal test.db-journal 1732c95e01daSdrhsqlite3 db test.db 1733c95e01daSdrhsqlite3 db2 test.db 1734c95e01daSdrhdo_test 23.1 { 1735c95e01daSdrh db eval { 1736c95e01daSdrh CREATE TABLE t1(a INTEGER PRIMARY KEY,b,c,d); 1737c95e01daSdrh CREATE INDEX i1 ON t1(b,c); 1738c95e01daSdrh CREATE INDEX i2 ON t1(c,d); 1739c95e01daSdrh CREATE TABLE t2(x INTEGER REFERENCES t1); 1740c95e01daSdrh } 1741c95e01daSdrh db2 eval {SELECT name FROM sqlite_master} 1742c95e01daSdrh} {t1 i1 i2 t2} 1743c228be5bSdrhdo_test 23.2a { 1744c95e01daSdrh db eval { 1745c95e01daSdrh DROP INDEX i2; 1746c95e01daSdrh CREATE INDEX i2 ON t1(c,d,b); 1747c95e01daSdrh } 1748c228be5bSdrh capture_pragma db2 out {PRAGMA index_info(i2)} 1749c228be5bSdrh db2 eval {SELECT cid, name, "desc", coll, "key", '|' FROM out ORDER BY seqno} 1750c228be5bSdrh} {2 c 0 BINARY 1 | 3 d 0 BINARY 1 | 1 b 0 BINARY 1 |} 1751c228be5bSdrhdo_test 23.2b { 17524bb8cb09Sdrhbreakpoint; 1753c228be5bSdrh capture_pragma db2 out {PRAGMA index_xinfo(i2)} 1754c228be5bSdrh db2 eval {SELECT cid, name, "desc", coll, "key", '|' FROM out ORDER BY seqno} 1755c228be5bSdrh} {2 c 0 BINARY 1 | 3 d 0 BINARY 1 | 1 b 0 BINARY 1 | -1 {} 0 BINARY 0 |} 1756c95e01daSdrhdo_test 23.3 { 1757c95e01daSdrh db eval { 1758c95e01daSdrh CREATE INDEX i3 ON t1(d,b,c); 1759c95e01daSdrh } 1760c228be5bSdrh capture_pragma db2 out {PRAGMA index_list(t1)} 1761c228be5bSdrh db2 eval {SELECT name, "unique", origin FROM out ORDER BY seq} 1762c228be5bSdrh} {i3 0 c i2 0 c i1 0 c} 1763c95e01daSdrhdo_test 23.4 { 1764c95e01daSdrh db eval { 1765c95e01daSdrh ALTER TABLE t1 ADD COLUMN e; 1766c95e01daSdrh } 1767c95e01daSdrh db2 eval { 1768c95e01daSdrh PRAGMA table_info(t1); 1769c95e01daSdrh } 1770c95e01daSdrh} {/4 e {} 0 {} 0/} 1771c95e01daSdrhdo_test 23.5 { 1772c95e01daSdrh db eval { 1773c95e01daSdrh DROP TABLE t2; 1774c95e01daSdrh CREATE TABLE t2(x, y INTEGER REFERENCES t1); 1775c95e01daSdrh } 1776c95e01daSdrh db2 eval { 1777c95e01daSdrh PRAGMA foreign_key_list(t2); 1778c95e01daSdrh } 1779c95e01daSdrh} {0 0 t1 y {} {NO ACTION} {NO ACTION} NONE} 1780c95e01daSdrh 17811fed5dabSdandatabase_never_corrupt 1782cd61c281Sdrhfinish_test 1783