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 869d356fbeSdrh# EVIDENCE-OF: R-24197-42751 PRAGMA database.cache_size; PRAGMA 879d356fbeSdrh# database.cache_size = pages; PRAGMA database.cache_size = -kibibytes; 889d356fbeSdrh# Query or change the suggested maximum number of database disk pages 899d356fbeSdrh# that SQLite will hold in memory at once per open database file. 909d356fbeSdrh# 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 { 1029d356fbeSdrh # EVIDENCE-OF: R-42059-47211 If the argument N is positive then the 1039d356fbeSdrh # 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} 671*7be0fd9cSdrh 672*7be0fd9cSdrh# EVIDENCE-OF: R-23114-21695 The auxiliary index-columns are not shown 673*7be0fd9cSdrh# by the index_info pragma, but they are listed by the index_xinfo 674*7be0fd9cSdrh# pragma. 675*7be0fd9cSdrh# 676*7be0fd9cSdrhdo_test pragma-6.5.1b { 677*7be0fd9cSdrh capture_pragma db out {PRAGMA index_xinfo(t3i1)} 678*7be0fd9cSdrh db eval {SELECT seqno, cid, name FROM out ORDER BY seqno} 679*7be0fd9cSdrh} {0 0 a 1 1 b 2 -1 {}} 680*7be0fd9cSdrh 681*7be0fd9cSdrh 682*7be0fd9cSdrh# EVIDENCE-OF: R-62725-03366 PRAGMA database.index_info(index-name); 683*7be0fd9cSdrh# This pragma returns one row for each key column in the named index. 684*7be0fd9cSdrh# 685*7be0fd9cSdrh# (The first column of output from PRAGMA index_info is...) 686*7be0fd9cSdrh# EVIDENCE-OF: R-34186-52914 The rank of the column within the index. (0 687*7be0fd9cSdrh# means left-most.) 688*7be0fd9cSdrh# 689*7be0fd9cSdrh# (The second column of output from PRAGMA index_info is...) 690*7be0fd9cSdrh# EVIDENCE-OF: R-65019-08383 The rank of the column within the table 691*7be0fd9cSdrh# being indexed. 692*7be0fd9cSdrh# 693*7be0fd9cSdrh# (The third column of output from PRAGMA index_info is...) 694*7be0fd9cSdrh# EVIDENCE-OF: R-09773-34266 The name of the column being indexed. 695*7be0fd9cSdrh# 696*7be0fd9cSdrhdo_execsql_test pragma-6.5.1c { 697*7be0fd9cSdrh CREATE INDEX t3i2 ON t3(b,a); 698*7be0fd9cSdrh PRAGMA index_info='t3i2'; 699*7be0fd9cSdrh DROP INDEX t3i2; 700*7be0fd9cSdrh} {0 1 b 1 0 a} 701*7be0fd9cSdrh 702d2cb50b7Sdrhdo_test pragma-6.5.2 { 703d2cb50b7Sdrh execsql { 704d2cb50b7Sdrh pragma index_info(t3i1_bogus); 705d2cb50b7Sdrh } 706d2cb50b7Sdrh} {} 707260d8a6aSdanielk1977 708260d8a6aSdanielk1977ifcapable tempdb { 709260d8a6aSdanielk1977 # Test for ticket #3320. When a temp table of the same name exists, make 710260d8a6aSdanielk1977 # sure the schema of the main table can still be queried using 711260d8a6aSdanielk1977 # "pragma table_info": 712260d8a6aSdanielk1977 do_test pragma-6.6.1 { 713260d8a6aSdanielk1977 execsql { 714260d8a6aSdanielk1977 CREATE TABLE trial(col_main); 715260d8a6aSdanielk1977 CREATE TEMP TABLE trial(col_temp); 716260d8a6aSdanielk1977 } 717260d8a6aSdanielk1977 } {} 718260d8a6aSdanielk1977 do_test pragma-6.6.2 { 719260d8a6aSdanielk1977 execsql { 720260d8a6aSdanielk1977 PRAGMA table_info(trial); 721260d8a6aSdanielk1977 } 722260d8a6aSdanielk1977 } {0 col_temp {} 0 {} 0} 723260d8a6aSdanielk1977 do_test pragma-6.6.3 { 724260d8a6aSdanielk1977 execsql { 725260d8a6aSdanielk1977 PRAGMA temp.table_info(trial); 726260d8a6aSdanielk1977 } 727260d8a6aSdanielk1977 } {0 col_temp {} 0 {} 0} 728260d8a6aSdanielk1977 do_test pragma-6.6.4 { 729260d8a6aSdanielk1977 execsql { 730260d8a6aSdanielk1977 PRAGMA main.table_info(trial); 731260d8a6aSdanielk1977 } 732260d8a6aSdanielk1977 } {0 col_main {} 0 {} 0} 733260d8a6aSdanielk1977} 734f96a3778Sdanielk1977 735f96a3778Sdanielk1977do_test pragma-6.7 { 736f96a3778Sdanielk1977 execsql { 737f96a3778Sdanielk1977 CREATE TABLE test_table( 738f96a3778Sdanielk1977 one INT NOT NULL DEFAULT -1, 739f96a3778Sdanielk1977 two text, 740f96a3778Sdanielk1977 three VARCHAR(45, 65) DEFAULT 'abcde', 741f96a3778Sdanielk1977 four REAL DEFAULT X'abcdef', 742f96a3778Sdanielk1977 five DEFAULT CURRENT_TIME 743f96a3778Sdanielk1977 ); 744f96a3778Sdanielk1977 } 745c228be5bSdrh capture_pragma db out {PRAGMA table_info(test_table)} 746c228be5bSdrh db eval {SELECT cid, "name", type, "notnull", dflt_value, pk FROM out 747c228be5bSdrh ORDER BY cid} 748f96a3778Sdanielk1977} [concat \ 749f96a3778Sdanielk1977 {0 one INT 1 -1 0} \ 750f96a3778Sdanielk1977 {1 two text 0 {} 0} \ 751f96a3778Sdanielk1977 {2 three {VARCHAR(45, 65)} 0 'abcde' 0} \ 752f96a3778Sdanielk1977 {3 four REAL 0 X'abcdef' 0} \ 753f96a3778Sdanielk1977 {4 five {} 0 CURRENT_TIME 0} \ 754f96a3778Sdanielk1977] 75527188fb5Sdanielk1977} ;# ifcapable schema_pragmas 7565260f7e9Sdrh# Miscellaneous tests 7575260f7e9Sdrh# 75827188fb5Sdanielk1977ifcapable schema_pragmas { 759*7be0fd9cSdrh# EVIDENCE-OF: R-63500-32024 PRAGMA database.index_list(table-name); 760*7be0fd9cSdrh# This pragma returns one row for each index associated with the given 761*7be0fd9cSdrh# table. 762d2cb50b7Sdrhdo_test pragma-7.1.1 { 7635260f7e9Sdrh # Make sure a pragma knows to read the schema if it needs to 7645260f7e9Sdrh db close 7655260f7e9Sdrh sqlite3 db test.db 766c228be5bSdrh capture_pragma db out "PRAGMA index_list(t3)" 767c228be5bSdrh db eval {SELECT name, "origin" FROM out ORDER BY name DESC} 768c228be5bSdrh} {t3i1 c sqlite_autoindex_t3_1 u} 769d2cb50b7Sdrhdo_test pragma-7.1.2 { 770d2cb50b7Sdrh execsql { 771d2cb50b7Sdrh pragma index_list(t3_bogus); 772d2cb50b7Sdrh } 773d2cb50b7Sdrh} {} 77427188fb5Sdanielk1977} ;# ifcapable schema_pragmas 7756c62608fSdrhifcapable {utf16} { 776cb354603Sdan if {[permutation] == ""} { 7775260f7e9Sdrh do_test pragma-7.2 { 7785260f7e9Sdrh db close 7795260f7e9Sdrh sqlite3 db test.db 7805260f7e9Sdrh catchsql { 7815260f7e9Sdrh pragma encoding=bogus; 7825260f7e9Sdrh } 7835260f7e9Sdrh } {1 {unsupported encoding: bogus}} 7846c62608fSdrh } 785cb354603Sdan} 78653c0f748Sdanielk1977ifcapable tempdb { 7875260f7e9Sdrh do_test pragma-7.3 { 7885260f7e9Sdrh db close 7895260f7e9Sdrh sqlite3 db test.db 7905260f7e9Sdrh execsql { 7915260f7e9Sdrh pragma lock_status; 7925260f7e9Sdrh } 7935260f7e9Sdrh } {main unlocked temp closed} 79453c0f748Sdanielk1977} else { 79553c0f748Sdanielk1977 do_test pragma-7.3 { 79653c0f748Sdanielk1977 db close 79753c0f748Sdanielk1977 sqlite3 db test.db 79853c0f748Sdanielk1977 execsql { 79953c0f748Sdanielk1977 pragma lock_status; 80053c0f748Sdanielk1977 } 80153c0f748Sdanielk1977 } {main unlocked} 80253c0f748Sdanielk1977} 8035260f7e9Sdrh 8045260f7e9Sdrh 805dae2495bSdanielk1977#---------------------------------------------------------------------- 806b92b70bbSdanielk1977# Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA 807b92b70bbSdanielk1977# user_version" statements. 808dae2495bSdanielk1977# 809b92b70bbSdanielk1977# pragma-8.1: PRAGMA schema_version 810b92b70bbSdanielk1977# pragma-8.2: PRAGMA user_version 811dae2495bSdanielk1977# 812dae2495bSdanielk1977 81311cf9fbcSdanielk1977ifcapable schema_version { 81411cf9fbcSdanielk1977 815b92b70bbSdanielk1977# First check that we can set the schema version and then retrieve the 816dae2495bSdanielk1977# same value. 817dae2495bSdanielk1977do_test pragma-8.1.1 { 818dae2495bSdanielk1977 execsql { 819b92b70bbSdanielk1977 PRAGMA schema_version = 105; 820dae2495bSdanielk1977 } 821dae2495bSdanielk1977} {} 822dae2495bSdanielk1977do_test pragma-8.1.2 { 82325403650Sdrh execsql2 { 824b92b70bbSdanielk1977 PRAGMA schema_version; 825dae2495bSdanielk1977 } 82625403650Sdrh} {schema_version 105} 827dae2495bSdanielk1977do_test pragma-8.1.3 { 828dae2495bSdanielk1977 execsql { 829b92b70bbSdanielk1977 PRAGMA schema_version = 106; 830dae2495bSdanielk1977 } 831dae2495bSdanielk1977} {} 832dae2495bSdanielk1977do_test pragma-8.1.4 { 833dae2495bSdanielk1977 execsql { 834b92b70bbSdanielk1977 PRAGMA schema_version; 835dae2495bSdanielk1977 } 836dae2495bSdanielk1977} 106 837dae2495bSdanielk1977 838b92b70bbSdanielk1977# Check that creating a table modifies the schema-version (this is really 839b92b70bbSdanielk1977# to verify that the value being read is in fact the schema version). 840dae2495bSdanielk1977do_test pragma-8.1.5 { 841dae2495bSdanielk1977 execsql { 842dae2495bSdanielk1977 CREATE TABLE t4(a, b, c); 843dae2495bSdanielk1977 INSERT INTO t4 VALUES(1, 2, 3); 844dae2495bSdanielk1977 SELECT * FROM t4; 845dae2495bSdanielk1977 } 846dae2495bSdanielk1977} {1 2 3} 847dae2495bSdanielk1977do_test pragma-8.1.6 { 848dae2495bSdanielk1977 execsql { 849b92b70bbSdanielk1977 PRAGMA schema_version; 850dae2495bSdanielk1977 } 851dae2495bSdanielk1977} 107 852dae2495bSdanielk1977 853dae2495bSdanielk1977# Now open a second connection to the database. Ensure that changing the 854b92b70bbSdanielk1977# schema-version using the first connection forces the second connection 855dae2495bSdanielk1977# to reload the schema. This has to be done using the C-API test functions, 856dae2495bSdanielk1977# because the TCL API accounts for SCHEMA_ERROR and retries the query. 857dae2495bSdanielk1977do_test pragma-8.1.7 { 858dddca286Sdrh sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] 859dae2495bSdanielk1977 execsql { 860dae2495bSdanielk1977 SELECT * FROM t4; 861dae2495bSdanielk1977 } db2 862dae2495bSdanielk1977} {1 2 3} 863dae2495bSdanielk1977do_test pragma-8.1.8 { 864dae2495bSdanielk1977 execsql { 865b92b70bbSdanielk1977 PRAGMA schema_version = 108; 866dae2495bSdanielk1977 } 867dae2495bSdanielk1977} {} 868dae2495bSdanielk1977do_test pragma-8.1.9 { 869dae2495bSdanielk1977 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY] 870dae2495bSdanielk1977 sqlite3_step $::STMT 871dae2495bSdanielk1977} SQLITE_ERROR 872dae2495bSdanielk1977do_test pragma-8.1.10 { 873dae2495bSdanielk1977 sqlite3_finalize $::STMT 874dae2495bSdanielk1977} SQLITE_SCHEMA 875dae2495bSdanielk1977 876b92b70bbSdanielk1977# Make sure the schema-version can be manipulated in an attached database. 877fda06befSmistachkinforcedelete test2.db 878fda06befSmistachkinforcedelete test2.db-journal 8795a8f9374Sdanielk1977ifcapable attach { 880dae2495bSdanielk1977 do_test pragma-8.1.11 { 881dae2495bSdanielk1977 execsql { 882dae2495bSdanielk1977 ATTACH 'test2.db' AS aux; 883dae2495bSdanielk1977 CREATE TABLE aux.t1(a, b, c); 884b92b70bbSdanielk1977 PRAGMA aux.schema_version = 205; 885dae2495bSdanielk1977 } 886dae2495bSdanielk1977 } {} 887dae2495bSdanielk1977 do_test pragma-8.1.12 { 888dae2495bSdanielk1977 execsql { 889b92b70bbSdanielk1977 PRAGMA aux.schema_version; 890dae2495bSdanielk1977 } 891dae2495bSdanielk1977 } 205 8925a8f9374Sdanielk1977} 893dae2495bSdanielk1977do_test pragma-8.1.13 { 894dae2495bSdanielk1977 execsql { 895b92b70bbSdanielk1977 PRAGMA schema_version; 896dae2495bSdanielk1977 } 897dae2495bSdanielk1977} 108 898dae2495bSdanielk1977 899b92b70bbSdanielk1977# And check that modifying the schema-version in an attached database 900dae2495bSdanielk1977# forces the second connection to reload the schema. 9015a8f9374Sdanielk1977ifcapable attach { 902dae2495bSdanielk1977 do_test pragma-8.1.14 { 903dddca286Sdrh sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] 904dae2495bSdanielk1977 execsql { 905dae2495bSdanielk1977 ATTACH 'test2.db' AS aux; 906dae2495bSdanielk1977 SELECT * FROM aux.t1; 907dae2495bSdanielk1977 } db2 908dae2495bSdanielk1977 } {} 909dae2495bSdanielk1977 do_test pragma-8.1.15 { 910dae2495bSdanielk1977 execsql { 911b92b70bbSdanielk1977 PRAGMA aux.schema_version = 206; 912dae2495bSdanielk1977 } 913dae2495bSdanielk1977 } {} 914dae2495bSdanielk1977 do_test pragma-8.1.16 { 915dae2495bSdanielk1977 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY] 916dae2495bSdanielk1977 sqlite3_step $::STMT 917dae2495bSdanielk1977 } SQLITE_ERROR 918dae2495bSdanielk1977 do_test pragma-8.1.17 { 919dae2495bSdanielk1977 sqlite3_finalize $::STMT 920dae2495bSdanielk1977 } SQLITE_SCHEMA 921dae2495bSdanielk1977 do_test pragma-8.1.18 { 922dae2495bSdanielk1977 db2 close 923dae2495bSdanielk1977 } {} 9245a8f9374Sdanielk1977} 925dae2495bSdanielk1977 926b92b70bbSdanielk1977# Now test that the user-version can be read and written (and that we aren't 927b92b70bbSdanielk1977# accidentally manipulating the schema-version instead). 928dae2495bSdanielk1977do_test pragma-8.2.1 { 92925403650Sdrh execsql2 { 930b92b70bbSdanielk1977 PRAGMA user_version; 931dae2495bSdanielk1977 } 93225403650Sdrh} {user_version 0} 933dae2495bSdanielk1977do_test pragma-8.2.2 { 934dae2495bSdanielk1977 execsql { 935b92b70bbSdanielk1977 PRAGMA user_version = 2; 936dae2495bSdanielk1977 } 937dae2495bSdanielk1977} {} 938802d69a7Sdrhdo_test pragma-8.2.3.1 { 93925403650Sdrh execsql2 { 940b92b70bbSdanielk1977 PRAGMA user_version; 941dae2495bSdanielk1977 } 94225403650Sdrh} {user_version 2} 943802d69a7Sdrhdo_test pragma-8.2.3.2 { 944802d69a7Sdrh db close 945802d69a7Sdrh sqlite3 db test.db 946802d69a7Sdrh execsql { 947802d69a7Sdrh PRAGMA user_version; 948802d69a7Sdrh } 949802d69a7Sdrh} {2} 950802d69a7Sdrhdo_test pragma-8.2.4.1 { 951dae2495bSdanielk1977 execsql { 952b92b70bbSdanielk1977 PRAGMA schema_version; 953dae2495bSdanielk1977 } 954dae2495bSdanielk1977} {108} 955802d69a7Sdrhifcapable vacuum { 956802d69a7Sdrh do_test pragma-8.2.4.2 { 957802d69a7Sdrh execsql { 958802d69a7Sdrh VACUUM; 959802d69a7Sdrh PRAGMA user_version; 960802d69a7Sdrh } 961802d69a7Sdrh } {2} 962802d69a7Sdrh do_test pragma-8.2.4.3 { 963802d69a7Sdrh execsql { 964802d69a7Sdrh PRAGMA schema_version; 965802d69a7Sdrh } 966802d69a7Sdrh } {109} 967802d69a7Sdrh} 9685a8f9374Sdanielk1977 9695a8f9374Sdanielk1977ifcapable attach { 970802d69a7Sdrh db eval {ATTACH 'test2.db' AS aux} 971dae2495bSdanielk1977 972b92b70bbSdanielk1977 # Check that the user-version in the auxilary database can be manipulated ( 973dae2495bSdanielk1977 # and that we aren't accidentally manipulating the same in the main db). 974dae2495bSdanielk1977 do_test pragma-8.2.5 { 975dae2495bSdanielk1977 execsql { 976b92b70bbSdanielk1977 PRAGMA aux.user_version; 977dae2495bSdanielk1977 } 978dae2495bSdanielk1977 } {0} 979dae2495bSdanielk1977 do_test pragma-8.2.6 { 980dae2495bSdanielk1977 execsql { 981b92b70bbSdanielk1977 PRAGMA aux.user_version = 3; 982dae2495bSdanielk1977 } 983dae2495bSdanielk1977 } {} 984dae2495bSdanielk1977 do_test pragma-8.2.7 { 985dae2495bSdanielk1977 execsql { 986b92b70bbSdanielk1977 PRAGMA aux.user_version; 987dae2495bSdanielk1977 } 988dae2495bSdanielk1977 } {3} 989dae2495bSdanielk1977 do_test pragma-8.2.8 { 990dae2495bSdanielk1977 execsql { 991b92b70bbSdanielk1977 PRAGMA main.user_version; 992dae2495bSdanielk1977 } 993dae2495bSdanielk1977 } {2} 994dae2495bSdanielk1977 995b92b70bbSdanielk1977 # Now check that a ROLLBACK resets the user-version if it has been modified 996dae2495bSdanielk1977 # within a transaction. 997dae2495bSdanielk1977 do_test pragma-8.2.9 { 998dae2495bSdanielk1977 execsql { 999dae2495bSdanielk1977 BEGIN; 1000b92b70bbSdanielk1977 PRAGMA aux.user_version = 10; 1001b92b70bbSdanielk1977 PRAGMA user_version = 11; 1002dae2495bSdanielk1977 } 1003dae2495bSdanielk1977 } {} 1004dae2495bSdanielk1977 do_test pragma-8.2.10 { 1005dae2495bSdanielk1977 execsql { 1006b92b70bbSdanielk1977 PRAGMA aux.user_version; 1007dae2495bSdanielk1977 } 1008dae2495bSdanielk1977 } {10} 1009dae2495bSdanielk1977 do_test pragma-8.2.11 { 1010dae2495bSdanielk1977 execsql { 1011b92b70bbSdanielk1977 PRAGMA main.user_version; 1012dae2495bSdanielk1977 } 1013dae2495bSdanielk1977 } {11} 1014dae2495bSdanielk1977 do_test pragma-8.2.12 { 1015dae2495bSdanielk1977 execsql { 1016dae2495bSdanielk1977 ROLLBACK; 1017b92b70bbSdanielk1977 PRAGMA aux.user_version; 1018dae2495bSdanielk1977 } 1019dae2495bSdanielk1977 } {3} 1020dae2495bSdanielk1977 do_test pragma-8.2.13 { 1021dae2495bSdanielk1977 execsql { 1022b92b70bbSdanielk1977 PRAGMA main.user_version; 1023dae2495bSdanielk1977 } 1024dae2495bSdanielk1977 } {2} 10255a8f9374Sdanielk1977} 1026dae2495bSdanielk1977 1027b92b70bbSdanielk1977# Try a negative value for the user-version 1028dae2495bSdanielk1977do_test pragma-8.2.14 { 1029dae2495bSdanielk1977 execsql { 1030b92b70bbSdanielk1977 PRAGMA user_version = -450; 1031dae2495bSdanielk1977 } 1032dae2495bSdanielk1977} {} 1033dae2495bSdanielk1977do_test pragma-8.2.15 { 1034dae2495bSdanielk1977 execsql { 1035b92b70bbSdanielk1977 PRAGMA user_version; 1036dae2495bSdanielk1977 } 1037dae2495bSdanielk1977} {-450} 1038d9c847dcSdanielk1977} ; # ifcapable schema_version 1039d9c847dcSdanielk1977 1040d19744f3Sdrh# Check to see if TEMP_STORE is memory or disk. Return strings 1041d19744f3Sdrh# "memory" or "disk" as appropriate. 1042d19744f3Sdrh# 1043d19744f3Sdrhproc check_temp_store {} { 1044d19744f3Sdrh db eval {CREATE TEMP TABLE IF NOT EXISTS a(b)} 1045d19744f3Sdrh db eval {PRAGMA database_list} { 1046d19744f3Sdrh if {$name=="temp"} { 104717b90b53Sdanielk1977 set bt [btree_from_db db 1] 104817b90b53Sdanielk1977 if {[btree_ismemdb $bt]} { 1049d19744f3Sdrh return "memory" 1050d19744f3Sdrh } 105117b90b53Sdanielk1977 return "disk" 1052d19744f3Sdrh } 1053d19744f3Sdrh } 1054d19744f3Sdrh return "unknown" 1055d19744f3Sdrh} 1056d19744f3Sdrh 10574ee09b4bSdrh# Application_ID 10584ee09b4bSdrh# 10594ee09b4bSdrhdo_test pragma-8.3.1 { 10604ee09b4bSdrh execsql { 10614ee09b4bSdrh PRAGMA application_id; 10624ee09b4bSdrh } 10634ee09b4bSdrh} {0} 10644ee09b4bSdrhdo_test pragma-8.3.2 { 10654ee09b4bSdrh execsql {PRAGMA Application_ID(12345); PRAGMA application_id;} 10664ee09b4bSdrh} {12345} 10679a09a3caStpoindex 10689a09a3caStpoindex# Test temp_store and temp_store_directory pragmas 10699a09a3caStpoindex# 1070268283bcSdrhifcapable pager_pragmas { 10719a09a3caStpoindexdo_test pragma-9.1 { 10729a09a3caStpoindex db close 10739a09a3caStpoindex sqlite3 db test.db 10749a09a3caStpoindex execsql { 10759a09a3caStpoindex PRAGMA temp_store; 10769a09a3caStpoindex } 10779a09a3caStpoindex} {0} 1078d19744f3Sdrhif {$TEMP_STORE<=1} { 1079d19744f3Sdrh do_test pragma-9.1.1 { 1080d19744f3Sdrh check_temp_store 1081d19744f3Sdrh } {disk} 1082d19744f3Sdrh} else { 1083d19744f3Sdrh do_test pragma-9.1.1 { 1084d19744f3Sdrh check_temp_store 1085d19744f3Sdrh } {memory} 1086d19744f3Sdrh} 1087d19744f3Sdrh 10889a09a3caStpoindexdo_test pragma-9.2 { 1089d19744f3Sdrh db close 1090d19744f3Sdrh sqlite3 db test.db 10919a09a3caStpoindex execsql { 10929a09a3caStpoindex PRAGMA temp_store=file; 10939a09a3caStpoindex PRAGMA temp_store; 10949a09a3caStpoindex } 10959a09a3caStpoindex} {1} 1096d19744f3Sdrhif {$TEMP_STORE==3} { 1097d19744f3Sdrh # When TEMP_STORE is 3, always use memory regardless of pragma settings. 1098d19744f3Sdrh do_test pragma-9.2.1 { 1099d19744f3Sdrh check_temp_store 1100d19744f3Sdrh } {memory} 1101d19744f3Sdrh} else { 1102d19744f3Sdrh do_test pragma-9.2.1 { 1103d19744f3Sdrh check_temp_store 1104d19744f3Sdrh } {disk} 1105d19744f3Sdrh} 1106d19744f3Sdrh 11079a09a3caStpoindexdo_test pragma-9.3 { 1108d19744f3Sdrh db close 1109d19744f3Sdrh sqlite3 db test.db 11109a09a3caStpoindex execsql { 11119a09a3caStpoindex PRAGMA temp_store=memory; 11129a09a3caStpoindex PRAGMA temp_store; 11139a09a3caStpoindex } 11149a09a3caStpoindex} {2} 1115d19744f3Sdrhif {$TEMP_STORE==0} { 1116d19744f3Sdrh # When TEMP_STORE is 0, always use the disk regardless of pragma settings. 1117d19744f3Sdrh do_test pragma-9.3.1 { 1118d19744f3Sdrh check_temp_store 1119d19744f3Sdrh } {disk} 1120d19744f3Sdrh} else { 1121d19744f3Sdrh do_test pragma-9.3.1 { 1122d19744f3Sdrh check_temp_store 1123d19744f3Sdrh } {memory} 1124d19744f3Sdrh} 1125d19744f3Sdrh 11269a09a3caStpoindexdo_test pragma-9.4 { 11279a09a3caStpoindex execsql { 11289a09a3caStpoindex PRAGMA temp_store_directory; 11299a09a3caStpoindex } 11309a09a3caStpoindex} {} 113178f82d1eSdrhifcapable wsd { 11329a09a3caStpoindex do_test pragma-9.5 { 1133f8a78464Smistachkin set pwd [string map {' ''} [file nativename [get_pwd]]] 1134268283bcSdrh execsql " 1135268283bcSdrh PRAGMA temp_store_directory='$pwd'; 11369a09a3caStpoindex " 11379a09a3caStpoindex } {} 11389a09a3caStpoindex do_test pragma-9.6 { 11399a09a3caStpoindex execsql { 11409a09a3caStpoindex PRAGMA temp_store_directory; 11419a09a3caStpoindex } 1142f8a78464Smistachkin } [list [file nativename [get_pwd]]] 11439a09a3caStpoindex do_test pragma-9.7 { 1144268283bcSdrh catchsql { 11459a09a3caStpoindex PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR'; 11469a09a3caStpoindex } 1147268283bcSdrh } {1 {not a writable directory}} 11489a09a3caStpoindex do_test pragma-9.8 { 11499a09a3caStpoindex execsql { 11509a09a3caStpoindex PRAGMA temp_store_directory=''; 11519a09a3caStpoindex } 11529a09a3caStpoindex } {} 11531e9daa6aSdrh if {![info exists TEMP_STORE] || $TEMP_STORE<=1} { 115453c0f748Sdanielk1977 ifcapable tempdb { 11559a09a3caStpoindex do_test pragma-9.9 { 11569a09a3caStpoindex execsql { 11579a09a3caStpoindex PRAGMA temp_store_directory; 11589a09a3caStpoindex PRAGMA temp_store=FILE; 11599a09a3caStpoindex CREATE TEMP TABLE temp_store_directory_test(a integer); 11609a09a3caStpoindex INSERT INTO temp_store_directory_test values (2); 11619a09a3caStpoindex SELECT * FROM temp_store_directory_test; 11629a09a3caStpoindex } 11639a09a3caStpoindex } {2} 11649a09a3caStpoindex do_test pragma-9.10 { 1165268283bcSdrh catchsql " 1166268283bcSdrh PRAGMA temp_store_directory='$pwd'; 11679a09a3caStpoindex SELECT * FROM temp_store_directory_test; 11689a09a3caStpoindex " 1169268283bcSdrh } {1 {no such table: temp_store_directory_test}} 11701e9daa6aSdrh } 11711e9daa6aSdrh } 117278f82d1eSdrh} 117395b289b6Sdanielk1977do_test pragma-9.11 { 117495b289b6Sdanielk1977 execsql { 117595b289b6Sdanielk1977 PRAGMA temp_store = 0; 117695b289b6Sdanielk1977 PRAGMA temp_store; 117795b289b6Sdanielk1977 } 117895b289b6Sdanielk1977} {0} 117995b289b6Sdanielk1977do_test pragma-9.12 { 118095b289b6Sdanielk1977 execsql { 118195b289b6Sdanielk1977 PRAGMA temp_store = 1; 118295b289b6Sdanielk1977 PRAGMA temp_store; 118395b289b6Sdanielk1977 } 118495b289b6Sdanielk1977} {1} 118595b289b6Sdanielk1977do_test pragma-9.13 { 118695b289b6Sdanielk1977 execsql { 118795b289b6Sdanielk1977 PRAGMA temp_store = 2; 118895b289b6Sdanielk1977 PRAGMA temp_store; 118995b289b6Sdanielk1977 } 119095b289b6Sdanielk1977} {2} 119195b289b6Sdanielk1977do_test pragma-9.14 { 119295b289b6Sdanielk1977 execsql { 119395b289b6Sdanielk1977 PRAGMA temp_store = 3; 119495b289b6Sdanielk1977 PRAGMA temp_store; 119595b289b6Sdanielk1977 } 119695b289b6Sdanielk1977} {0} 119795b289b6Sdanielk1977do_test pragma-9.15 { 119895b289b6Sdanielk1977 catchsql { 119995b289b6Sdanielk1977 BEGIN EXCLUSIVE; 120095b289b6Sdanielk1977 CREATE TEMP TABLE temp_table(t); 120195b289b6Sdanielk1977 INSERT INTO temp_table VALUES('valuable data'); 120295b289b6Sdanielk1977 PRAGMA temp_store = 1; 120395b289b6Sdanielk1977 } 120495b289b6Sdanielk1977} {1 {temporary storage cannot be changed from within a transaction}} 120595b289b6Sdanielk1977do_test pragma-9.16 { 120695b289b6Sdanielk1977 execsql { 120795b289b6Sdanielk1977 SELECT * FROM temp_table; 120895b289b6Sdanielk1977 COMMIT; 120995b289b6Sdanielk1977 } 121095b289b6Sdanielk1977} {{valuable data}} 1211983e2309Sdanielk1977 1212983e2309Sdanielk1977do_test pragma-9.17 { 1213983e2309Sdanielk1977 execsql { 1214983e2309Sdanielk1977 INSERT INTO temp_table VALUES('valuable data II'); 1215983e2309Sdanielk1977 SELECT * FROM temp_table; 1216983e2309Sdanielk1977 } 1217983e2309Sdanielk1977} {{valuable data} {valuable data II}} 1218983e2309Sdanielk1977 1219983e2309Sdanielk1977do_test pragma-9.18 { 1220983e2309Sdanielk1977 set rc [catch { 1221983e2309Sdanielk1977 db eval {SELECT t FROM temp_table} { 1222983e2309Sdanielk1977 execsql {pragma temp_store = 1} 1223983e2309Sdanielk1977 } 1224983e2309Sdanielk1977 } msg] 1225983e2309Sdanielk1977 list $rc $msg 1226983e2309Sdanielk1977} {1 {temporary storage cannot be changed from within a transaction}} 1227983e2309Sdanielk1977 1228268283bcSdrh} ;# ifcapable pager_pragmas 12299a09a3caStpoindex 1230cc6bd383Sdanielk1977ifcapable trigger { 1231cc6bd383Sdanielk1977 1232cc6bd383Sdanielk1977do_test pragma-10.0 { 1233cc6bd383Sdanielk1977 catchsql { 1234cc6bd383Sdanielk1977 DROP TABLE main.t1; 1235cc6bd383Sdanielk1977 } 1236cc6bd383Sdanielk1977 execsql { 1237cc6bd383Sdanielk1977 PRAGMA count_changes = 1; 1238cc6bd383Sdanielk1977 1239cc6bd383Sdanielk1977 CREATE TABLE t1(a PRIMARY KEY); 1240cc6bd383Sdanielk1977 CREATE TABLE t1_mirror(a); 1241cc6bd383Sdanielk1977 CREATE TABLE t1_mirror2(a); 1242cc6bd383Sdanielk1977 CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN 1243cc6bd383Sdanielk1977 INSERT INTO t1_mirror VALUES(new.a); 1244cc6bd383Sdanielk1977 END; 1245cc6bd383Sdanielk1977 CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN 1246cc6bd383Sdanielk1977 INSERT INTO t1_mirror2 VALUES(new.a); 1247cc6bd383Sdanielk1977 END; 1248cc6bd383Sdanielk1977 CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN 1249cc6bd383Sdanielk1977 UPDATE t1_mirror SET a = new.a WHERE a = old.a; 1250cc6bd383Sdanielk1977 END; 1251cc6bd383Sdanielk1977 CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN 1252cc6bd383Sdanielk1977 UPDATE t1_mirror2 SET a = new.a WHERE a = old.a; 1253cc6bd383Sdanielk1977 END; 1254cc6bd383Sdanielk1977 CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN 1255cc6bd383Sdanielk1977 DELETE FROM t1_mirror WHERE a = old.a; 1256cc6bd383Sdanielk1977 END; 1257cc6bd383Sdanielk1977 CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN 1258cc6bd383Sdanielk1977 DELETE FROM t1_mirror2 WHERE a = old.a; 1259cc6bd383Sdanielk1977 END; 1260cc6bd383Sdanielk1977 } 1261cc6bd383Sdanielk1977} {} 1262cc6bd383Sdanielk1977 1263cc6bd383Sdanielk1977do_test pragma-10.1 { 1264cc6bd383Sdanielk1977 execsql { 1265cc6bd383Sdanielk1977 INSERT INTO t1 VALUES(randstr(10,10)); 1266cc6bd383Sdanielk1977 } 1267cc6bd383Sdanielk1977} {1} 1268cc6bd383Sdanielk1977do_test pragma-10.2 { 1269cc6bd383Sdanielk1977 execsql { 1270cc6bd383Sdanielk1977 UPDATE t1 SET a = randstr(10,10); 1271cc6bd383Sdanielk1977 } 1272cc6bd383Sdanielk1977} {1} 1273cc6bd383Sdanielk1977do_test pragma-10.3 { 1274cc6bd383Sdanielk1977 execsql { 1275cc6bd383Sdanielk1977 DELETE FROM t1; 1276cc6bd383Sdanielk1977 } 1277cc6bd383Sdanielk1977} {1} 1278cc6bd383Sdanielk1977 1279cc6bd383Sdanielk1977} ;# ifcapable trigger 1280cc6bd383Sdanielk1977 128148af65aeSdanielk1977ifcapable schema_pragmas { 128248af65aeSdanielk1977 do_test pragma-11.1 { 128348af65aeSdanielk1977 execsql2 { 128448af65aeSdanielk1977 pragma collation_list; 128548af65aeSdanielk1977 } 12862d823315Sdrh } {seq 0 name RTRIM seq 1 name NOCASE seq 2 name BINARY} 128748af65aeSdanielk1977 do_test pragma-11.2 { 128848af65aeSdanielk1977 db collate New_Collation blah... 128948af65aeSdanielk1977 execsql { 129048af65aeSdanielk1977 pragma collation_list; 129148af65aeSdanielk1977 } 12922d823315Sdrh } {0 New_Collation 1 RTRIM 2 NOCASE 3 BINARY} 129348af65aeSdanielk1977} 129448af65aeSdanielk1977 1295ddfb2f03Sdanielk1977ifcapable schema_pragmas&&tempdb { 1296ddfb2f03Sdanielk1977 do_test pragma-12.1 { 1297ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1298ddfb2f03Sdanielk1977 execsql { 1299ddfb2f03Sdanielk1977 PRAGMA temp.table_info('abc'); 1300ddfb2f03Sdanielk1977 } db2 1301ddfb2f03Sdanielk1977 } {} 1302ddfb2f03Sdanielk1977 db2 close 1303ddfb2f03Sdanielk1977 1304ddfb2f03Sdanielk1977 do_test pragma-12.2 { 1305ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1306ddfb2f03Sdanielk1977 execsql { 1307ddfb2f03Sdanielk1977 PRAGMA temp.default_cache_size = 200; 1308ddfb2f03Sdanielk1977 PRAGMA temp.default_cache_size; 1309ddfb2f03Sdanielk1977 } db2 1310ddfb2f03Sdanielk1977 } {200} 1311ddfb2f03Sdanielk1977 db2 close 1312ddfb2f03Sdanielk1977 1313ddfb2f03Sdanielk1977 do_test pragma-12.3 { 1314ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1315ddfb2f03Sdanielk1977 execsql { 1316ddfb2f03Sdanielk1977 PRAGMA temp.cache_size = 400; 1317ddfb2f03Sdanielk1977 PRAGMA temp.cache_size; 1318ddfb2f03Sdanielk1977 } db2 1319ddfb2f03Sdanielk1977 } {400} 1320ddfb2f03Sdanielk1977 db2 close 1321ddfb2f03Sdanielk1977} 1322ddfb2f03Sdanielk1977 13234b2688abSdanielk1977ifcapable bloblit { 13244b2688abSdanielk1977 132505a82983Sdrhdo_test pragma-13.1 { 132605a82983Sdrh execsql { 132705a82983Sdrh DROP TABLE IF EXISTS t4; 132805a82983Sdrh PRAGMA vdbe_trace=on; 132905a82983Sdrh PRAGMA vdbe_listing=on; 133005a82983Sdrh PRAGMA sql_trace=on; 133105a82983Sdrh CREATE TABLE t4(a INTEGER PRIMARY KEY,b); 133205a82983Sdrh INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789'); 133305a82983Sdrh INSERT INTO t4(b) VALUES(randstr(30,30)); 133405a82983Sdrh INSERT INTO t4(b) VALUES(1.23456); 133505a82983Sdrh INSERT INTO t4(b) VALUES(NULL); 133605a82983Sdrh INSERT INTO t4(b) VALUES(0); 133705a82983Sdrh INSERT INTO t4(b) SELECT b||b||b||b FROM t4; 133805a82983Sdrh SELECT * FROM t4; 133905a82983Sdrh } 134005a82983Sdrh execsql { 134105a82983Sdrh PRAGMA vdbe_trace=off; 134205a82983Sdrh PRAGMA vdbe_listing=off; 134305a82983Sdrh PRAGMA sql_trace=off; 134405a82983Sdrh } 134505a82983Sdrh} {} 134605a82983Sdrh 13474b2688abSdanielk1977} ;# ifcapable bloblit 13484b2688abSdanielk1977 134959a93791Sdanielk1977ifcapable pager_pragmas { 135059a93791Sdanielk1977 db close 1351fda06befSmistachkin forcedelete test.db 135259a93791Sdanielk1977 sqlite3 db test.db 135359a93791Sdanielk1977 135451a74d4cSdrh # EVIDENCE-OF: R-13905-26312 PRAGMA database.page_count; Return the 135551a74d4cSdrh # total number of pages in the database file. 135651a74d4cSdrh # 135759a93791Sdanielk1977 do_test pragma-14.1 { 135859a93791Sdanielk1977 execsql { pragma auto_vacuum = 0 } 135951a74d4cSdrh execsql { pragma page_count; pragma main.page_count } 136051a74d4cSdrh } {0 0} 136159a93791Sdanielk1977 136259a93791Sdanielk1977 do_test pragma-14.2 { 136359a93791Sdanielk1977 execsql { 136459a93791Sdanielk1977 CREATE TABLE abc(a, b, c); 136559a93791Sdanielk1977 PRAGMA page_count; 136651a74d4cSdrh PRAGMA main.page_count; 136751a74d4cSdrh PRAGMA temp.page_count; 136859a93791Sdanielk1977 } 136951a74d4cSdrh } {2 2 0} 13705d16a9a6Sdrh do_test pragma-14.2uc { 13715d16a9a6Sdrh execsql {pragma PAGE_COUNT} 13725d16a9a6Sdrh } {2} 137359a93791Sdanielk1977 137459a93791Sdanielk1977 do_test pragma-14.3 { 137559a93791Sdanielk1977 execsql { 137659a93791Sdanielk1977 BEGIN; 137759a93791Sdanielk1977 CREATE TABLE def(a, b, c); 137859a93791Sdanielk1977 PRAGMA page_count; 137959a93791Sdanielk1977 } 138059a93791Sdanielk1977 } {3} 13815d16a9a6Sdrh do_test pragma-14.3uc { 13825d16a9a6Sdrh execsql {pragma PAGE_COUNT} 13835d16a9a6Sdrh } {3} 138459a93791Sdanielk1977 138559a93791Sdanielk1977 do_test pragma-14.4 { 138659a93791Sdanielk1977 set page_size [db one {pragma page_size}] 138759a93791Sdanielk1977 expr [file size test.db] / $page_size 138859a93791Sdanielk1977 } {2} 138959a93791Sdanielk1977 139059a93791Sdanielk1977 do_test pragma-14.5 { 139159a93791Sdanielk1977 execsql { 139259a93791Sdanielk1977 ROLLBACK; 139359a93791Sdanielk1977 PRAGMA page_count; 139459a93791Sdanielk1977 } 139559a93791Sdanielk1977 } {2} 139659a93791Sdanielk1977 139759a93791Sdanielk1977 do_test pragma-14.6 { 1398fda06befSmistachkin forcedelete test2.db 139959a93791Sdanielk1977 sqlite3 db2 test2.db 140059a93791Sdanielk1977 execsql { 140159a93791Sdanielk1977 PRAGMA auto_vacuum = 0; 140259a93791Sdanielk1977 CREATE TABLE t1(a, b, c); 140359a93791Sdanielk1977 CREATE TABLE t2(a, b, c); 140459a93791Sdanielk1977 CREATE TABLE t3(a, b, c); 140559a93791Sdanielk1977 CREATE TABLE t4(a, b, c); 140659a93791Sdanielk1977 } db2 140759a93791Sdanielk1977 db2 close 140859a93791Sdanielk1977 execsql { 140959a93791Sdanielk1977 ATTACH 'test2.db' AS aux; 141059a93791Sdanielk1977 PRAGMA aux.page_count; 141159a93791Sdanielk1977 } 141259a93791Sdanielk1977 } {5} 14135d16a9a6Sdrh do_test pragma-14.6uc { 14145d16a9a6Sdrh execsql {pragma AUX.PAGE_COUNT} 14155d16a9a6Sdrh } {5} 141659a93791Sdanielk1977} 141759a93791Sdanielk1977 14188cf6c554Sdanielk1977# Test that the value set using the cache_size pragma is not reset when the 14198cf6c554Sdanielk1977# schema is reloaded. 14208cf6c554Sdanielk1977# 14218cf6c554Sdanielk1977ifcapable pager_pragmas { 14228cf6c554Sdanielk1977 db close 14238cf6c554Sdanielk1977 sqlite3 db test.db 14248cf6c554Sdanielk1977 do_test pragma-15.1 { 14258cf6c554Sdanielk1977 execsql { 14268cf6c554Sdanielk1977 PRAGMA cache_size=59; 14278cf6c554Sdanielk1977 PRAGMA cache_size; 14288cf6c554Sdanielk1977 } 14298cf6c554Sdanielk1977 } {59} 14308cf6c554Sdanielk1977 do_test pragma-15.2 { 14318cf6c554Sdanielk1977 sqlite3 db2 test.db 14328cf6c554Sdanielk1977 execsql { 14338cf6c554Sdanielk1977 CREATE TABLE newtable(a, b, c); 14348cf6c554Sdanielk1977 } db2 14358cf6c554Sdanielk1977 db2 close 14368cf6c554Sdanielk1977 } {} 14378cf6c554Sdanielk1977 do_test pragma-15.3 { 14388cf6c554Sdanielk1977 # Evaluating this statement will cause the schema to be reloaded (because 14398cf6c554Sdanielk1977 # the schema was changed by another connection in pragma-15.2). At one 14408cf6c554Sdanielk1977 # point there was a bug that reset the cache_size to its default value 14418cf6c554Sdanielk1977 # when this happened. 14428cf6c554Sdanielk1977 execsql { SELECT * FROM sqlite_master } 14438cf6c554Sdanielk1977 execsql { PRAGMA cache_size } 14448cf6c554Sdanielk1977 } {59} 14458cf6c554Sdanielk1977} 14468cf6c554Sdanielk1977 14475558a8a6Sdanielk1977# Reset the sqlite3_temp_directory variable for the next run of tests: 14485558a8a6Sdanielk1977sqlite3 dbX :memory: 14495558a8a6Sdanielk1977dbX eval {PRAGMA temp_store_directory = ""} 14505558a8a6Sdanielk1977dbX close 14515558a8a6Sdanielk1977 1452838cce43Sdanielk1977ifcapable lock_proxy_pragmas&&prefer_proxy_locking { 1453aebf413dSaswift set sqlite_hostid_num 1 1454aebf413dSaswift 1455aebf413dSaswift set using_proxy 0 1456aebf413dSaswift foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] { 1457aebf413dSaswift set using_proxy $value 1458aebf413dSaswift } 1459aebf413dSaswift 1460aebf413dSaswift # Test the lock_proxy_file pragmas. 1461aebf413dSaswift # 1462aebf413dSaswift db close 1463aebf413dSaswift set env(SQLITE_FORCE_PROXY_LOCKING) "0" 1464aebf413dSaswift 1465aebf413dSaswift sqlite3 db test.db 1466aebf413dSaswift do_test pragma-16.1 { 1467aebf413dSaswift execsql { 1468aebf413dSaswift PRAGMA lock_proxy_file="mylittleproxy"; 1469aebf413dSaswift select * from sqlite_master; 1470aebf413dSaswift } 1471aebf413dSaswift execsql { 1472aebf413dSaswift PRAGMA lock_proxy_file; 1473aebf413dSaswift } 1474aebf413dSaswift } {mylittleproxy} 1475aebf413dSaswift 1476aebf413dSaswift do_test pragma-16.2 { 1477aebf413dSaswift sqlite3 db2 test.db 1478aebf413dSaswift execsql { 1479aebf413dSaswift PRAGMA lock_proxy_file="mylittleproxy"; 1480aebf413dSaswift } db2 1481aebf413dSaswift } {} 1482aebf413dSaswift 1483aebf413dSaswift db2 close 1484aebf413dSaswift do_test pragma-16.2.1 { 1485aebf413dSaswift sqlite3 db2 test.db 1486aebf413dSaswift execsql { 1487aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1488aebf413dSaswift select * from sqlite_master; 1489aebf413dSaswift } db2 1490aebf413dSaswift execsql { 1491aebf413dSaswift PRAGMA lock_proxy_file; 1492aebf413dSaswift } db2 1493aebf413dSaswift } {mylittleproxy} 1494aebf413dSaswift 1495aebf413dSaswift db2 close 1496aebf413dSaswift do_test pragma-16.3 { 1497aebf413dSaswift sqlite3 db2 test.db 1498aebf413dSaswift execsql { 1499aebf413dSaswift PRAGMA lock_proxy_file="myotherproxy"; 1500aebf413dSaswift } db2 1501aebf413dSaswift catchsql { 1502aebf413dSaswift select * from sqlite_master; 1503aebf413dSaswift } db2 1504aebf413dSaswift } {1 {database is locked}} 1505aebf413dSaswift 1506aebf413dSaswift do_test pragma-16.4 { 1507aebf413dSaswift db2 close 1508aebf413dSaswift db close 1509aebf413dSaswift sqlite3 db2 test.db 1510aebf413dSaswift execsql { 1511aebf413dSaswift PRAGMA lock_proxy_file="myoriginalproxy"; 1512aebf413dSaswift PRAGMA lock_proxy_file="myotherproxy"; 1513aebf413dSaswift PRAGMA lock_proxy_file; 1514aebf413dSaswift } db2 1515aebf413dSaswift } {myotherproxy} 1516aebf413dSaswift 1517aebf413dSaswift db2 close 1518aebf413dSaswift set env(SQLITE_FORCE_PROXY_LOCKING) "1" 1519aebf413dSaswift do_test pragma-16.5 { 1520aebf413dSaswift sqlite3 db2 test.db 1521aebf413dSaswift execsql { 1522aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1523aebf413dSaswift PRAGMA lock_proxy_file; 1524aebf413dSaswift } db2 1525aebf413dSaswift } {myotherproxy} 1526aebf413dSaswift 1527aebf413dSaswift do_test pragma-16.6 { 1528aebf413dSaswift db2 close 1529aebf413dSaswift sqlite3 db2 test2.db 1530aebf413dSaswift set lockpath [execsql { 1531aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1532aebf413dSaswift PRAGMA lock_proxy_file; 1533aebf413dSaswift } db2] 1534aebf413dSaswift string match "*test2.db:auto:" $lockpath 1535aebf413dSaswift } {1} 1536aebf413dSaswift 1537aebf413dSaswift set sqlite_hostid_num 2 1538aebf413dSaswift do_test pragma-16.7 { 153914d14607Sdan list [catch { 1540aebf413dSaswift sqlite3 db test2.db 1541aebf413dSaswift execsql { 1542aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1543aebf413dSaswift select * from sqlite_master; 1544aebf413dSaswift } 154514d14607Sdan } msg] $msg 1546aebf413dSaswift } {1 {database is locked}} 1547aebf413dSaswift db close 1548aebf413dSaswift 1549aebf413dSaswift do_test pragma-16.8 { 155014d14607Sdan list [catch { 1551aebf413dSaswift sqlite3 db test2.db 155214d14607Sdan execsql { select * from sqlite_master } 155314d14607Sdan } msg] $msg 1554aebf413dSaswift } {1 {database is locked}} 1555aebf413dSaswift 1556aebf413dSaswift db2 close 1557aebf413dSaswift do_test pragma-16.8.1 { 1558aebf413dSaswift execsql { 1559aebf413dSaswift PRAGMA lock_proxy_file="yetanotherproxy"; 1560aebf413dSaswift PRAGMA lock_proxy_file; 1561aebf413dSaswift } 1562aebf413dSaswift } {yetanotherproxy} 1563aebf413dSaswift do_test pragma-16.8.2 { 1564aebf413dSaswift execsql { 1565aebf413dSaswift create table mine(x); 1566aebf413dSaswift } 1567aebf413dSaswift } {} 1568aebf413dSaswift 1569aebf413dSaswift db close 1570aebf413dSaswift do_test pragma-16.9 { 1571aebf413dSaswift sqlite3 db proxytest.db 1572aebf413dSaswift set lockpath2 [execsql { 1573aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1574aebf413dSaswift PRAGMA lock_proxy_file; 1575aebf413dSaswift } db] 1576aebf413dSaswift string match "*proxytest.db:auto:" $lockpath2 1577aebf413dSaswift } {1} 1578aebf413dSaswift 1579aebf413dSaswift set env(SQLITE_FORCE_PROXY_LOCKING) $using_proxy 1580aebf413dSaswift set sqlite_hostid_num 0 1581aebf413dSaswift} 1582d2cb50b7Sdrh 1583d2cb50b7Sdrh# Parsing of auto_vacuum settings. 1584d2cb50b7Sdrh# 1585d2cb50b7Sdrhforeach {autovac_setting val} { 1586d2cb50b7Sdrh 0 0 1587d2cb50b7Sdrh 1 1 1588d2cb50b7Sdrh 2 2 1589d2cb50b7Sdrh 3 0 1590d2cb50b7Sdrh -1 0 1591d2cb50b7Sdrh none 0 1592d2cb50b7Sdrh NONE 0 1593d2cb50b7Sdrh NoNe 0 1594d2cb50b7Sdrh full 1 1595d2cb50b7Sdrh FULL 1 1596d2cb50b7Sdrh incremental 2 1597d2cb50b7Sdrh INCREMENTAL 2 1598d2cb50b7Sdrh -1234 0 1599d2cb50b7Sdrh 1234 0 1600d2cb50b7Sdrh} { 1601d2cb50b7Sdrh do_test pragma-17.1.$autovac_setting { 1602d2cb50b7Sdrh catch {db close} 1603d2cb50b7Sdrh sqlite3 db :memory: 1604d2cb50b7Sdrh execsql " 1605d2cb50b7Sdrh PRAGMA auto_vacuum=$::autovac_setting; 1606d2cb50b7Sdrh PRAGMA auto_vacuum; 1607d2cb50b7Sdrh " 1608d2cb50b7Sdrh } $val 1609d2cb50b7Sdrh} 1610d2cb50b7Sdrh 1611d2cb50b7Sdrh# Parsing of temp_store settings. 1612d2cb50b7Sdrh# 1613d2cb50b7Sdrhforeach {temp_setting val} { 1614d2cb50b7Sdrh 0 0 1615d2cb50b7Sdrh 1 1 1616d2cb50b7Sdrh 2 2 1617d2cb50b7Sdrh 3 0 1618d2cb50b7Sdrh -1 0 1619d2cb50b7Sdrh file 1 1620d2cb50b7Sdrh FILE 1 1621d2cb50b7Sdrh fIlE 1 1622d2cb50b7Sdrh memory 2 1623d2cb50b7Sdrh MEMORY 2 1624d2cb50b7Sdrh MeMoRy 2 1625d2cb50b7Sdrh} { 1626d2cb50b7Sdrh do_test pragma-18.1.$temp_setting { 1627d2cb50b7Sdrh catch {db close} 1628d2cb50b7Sdrh sqlite3 db :memory: 1629d2cb50b7Sdrh execsql " 1630d2cb50b7Sdrh PRAGMA temp_store=$::temp_setting; 1631d2cb50b7Sdrh PRAGMA temp_store=$::temp_setting; 1632d2cb50b7Sdrh PRAGMA temp_store; 1633d2cb50b7Sdrh " 1634d2cb50b7Sdrh } $val 1635d2cb50b7Sdrh} 1636d2cb50b7Sdrh 163792c700dbSdrh# The SQLITE_FCNTL_PRAGMA logic, with error handling. 163892c700dbSdrh# 163992c700dbSdrhdb close 164092c700dbSdrhtestvfs tvfs 164192c700dbSdrhsqlite3 db test.db -vfs tvfs 164292c700dbSdrhdo_test pragma-19.1 { 164392c700dbSdrh catchsql {PRAGMA error} 164492c700dbSdrh} {1 {SQL logic error or missing database}} 164592c700dbSdrhdo_test pragma-19.2 { 164692c700dbSdrh catchsql {PRAGMA error='This is the error message'} 164792c700dbSdrh} {1 {This is the error message}} 164892c700dbSdrhdo_test pragma-19.3 { 164992c700dbSdrh catchsql {PRAGMA error='7 This is the error message'} 165092c700dbSdrh} {1 {This is the error message}} 165192c700dbSdrhdo_test pragma-19.4 { 165292c700dbSdrh catchsql {PRAGMA error=7} 165392c700dbSdrh} {1 {out of memory}} 1654c8517f61Sdrhdo_test pragma-19.5 { 16555b044545Smistachkin file tail [lindex [execsql {PRAGMA filename}] 0] 1656c8517f61Sdrh} {test.db} 165792c700dbSdrh 1658cc71645bSdrhif {$tcl_platform(platform)=="windows"} { 1659a112d140Smistachkin# Test data_store_directory pragma 1660a112d140Smistachkin# 1661a112d140Smistachkindb close 1662a112d140Smistachkinsqlite3 db test.db 1663a112d140Smistachkinfile mkdir data_dir 1664a112d140Smistachkindo_test pragma-20.1 { 1665a112d140Smistachkin catchsql {PRAGMA data_store_directory} 1666a112d140Smistachkin} {0 {}} 1667a112d140Smistachkindo_test pragma-20.2 { 1668a112d140Smistachkin set pwd [string map {' ''} [file nativename [get_pwd]]] 1669a112d140Smistachkin catchsql "PRAGMA data_store_directory='$pwd';" 1670a112d140Smistachkin} {0 {}} 1671a112d140Smistachkindo_test pragma-20.3 { 1672a112d140Smistachkin catchsql {PRAGMA data_store_directory} 1673a112d140Smistachkin} [list 0 [list [file nativename [get_pwd]]]] 1674a112d140Smistachkindo_test pragma-20.4 { 1675a112d140Smistachkin set pwd [string map {' ''} [file nativename \ 1676a112d140Smistachkin [file join [get_pwd] data_dir]]] 1677a112d140Smistachkin catchsql "PRAGMA data_store_directory='$pwd';" 1678a112d140Smistachkin} {0 {}} 1679a112d140Smistachkindo_test pragma-20.5 { 1680a112d140Smistachkin sqlite3 db2 test2.db 1681a112d140Smistachkin catchsql "PRAGMA database_list;" db2 1682a112d140Smistachkin} [list 0 [list 0 main [file nativename \ 1683a112d140Smistachkin [file join [get_pwd] data_dir test2.db]]]] 1684a112d140Smistachkincatch {db2 close} 1685a112d140Smistachkindo_test pragma-20.6 { 1686a112d140Smistachkin sqlite3 db2 [file join [get_pwd] test2.db] 1687a112d140Smistachkin catchsql "PRAGMA database_list;" db2 1688a112d140Smistachkin} [list 0 [list 0 main [file nativename \ 1689a112d140Smistachkin [file join [get_pwd] test2.db]]]] 1690a112d140Smistachkincatch {db2 close} 1691a112d140Smistachkindo_test pragma-20.7 { 1692a112d140Smistachkin catchsql "PRAGMA data_store_directory='';" 1693a112d140Smistachkin} {0 {}} 1694a112d140Smistachkindo_test pragma-20.8 { 1695a112d140Smistachkin catchsql {PRAGMA data_store_directory} 1696a112d140Smistachkin} {0 {}} 169792c700dbSdrh 1698a112d140Smistachkinforcedelete data_dir 1699cc71645bSdrh} ;# endif windows 1700cd61c281Sdrh 17011fed5dabSdandatabase_may_be_corrupt 17021fed5dabSdan 17035885e762Sdando_test 21.1 { 17045885e762Sdan # Create a corrupt database in testerr.db. And a non-corrupt at test.db. 17055885e762Sdan # 17065885e762Sdan db close 17075885e762Sdan forcedelete test.db 17085885e762Sdan sqlite3 db test.db 17095885e762Sdan execsql { 17105885e762Sdan PRAGMA page_size = 1024; 17115885e762Sdan PRAGMA auto_vacuum = 0; 17125885e762Sdan CREATE TABLE t1(a PRIMARY KEY, b); 17135885e762Sdan INSERT INTO t1 VALUES(1, 1); 17145885e762Sdan } 17155885e762Sdan for {set i 0} {$i < 10} {incr i} { 17165885e762Sdan execsql { INSERT INTO t1 SELECT a + (1 << $i), b + (1 << $i) FROM t1 } 17175885e762Sdan } 17185885e762Sdan db close 17195885e762Sdan forcecopy test.db testerr.db 17205885e762Sdan hexio_write testerr.db 15000 [string repeat 55 100] 17215885e762Sdan} {100} 17225885e762Sdan 17235885e762Sdanset mainerr {*** in database main *** 17245885e762SdanMultiple uses for byte 672 of page 15} 17255885e762Sdanset auxerr {*** in database aux *** 17265885e762SdanMultiple uses for byte 672 of page 15} 17275885e762Sdan 1728597515d7Sdanset mainerr {/{\*\*\* in database main \*\*\* 1729597515d7SdanMultiple uses for byte 672 of page 15}.*/} 1730597515d7Sdanset auxerr {/{\*\*\* in database aux \*\*\* 1731597515d7SdanMultiple uses for byte 672 of page 15}.*/} 1732597515d7Sdan 17335885e762Sdando_test 22.2 { 17345885e762Sdan catch { db close } 17355885e762Sdan sqlite3 db testerr.db 17365885e762Sdan execsql { PRAGMA integrity_check } 1737597515d7Sdan} $mainerr 17385885e762Sdan 17395885e762Sdando_test 22.3.1 { 17405885e762Sdan catch { db close } 17415885e762Sdan sqlite3 db test.db 17425885e762Sdan execsql { 17435885e762Sdan ATTACH 'testerr.db' AS 'aux'; 17445885e762Sdan PRAGMA integrity_check; 17455885e762Sdan } 1746597515d7Sdan} $auxerr 17475885e762Sdando_test 22.3.2 { 17485885e762Sdan execsql { PRAGMA main.integrity_check; } 17495885e762Sdan} {ok} 17505885e762Sdando_test 22.3.3 { 17515885e762Sdan execsql { PRAGMA aux.integrity_check; } 1752597515d7Sdan} $auxerr 17535885e762Sdan 17545885e762Sdando_test 22.4.1 { 17555885e762Sdan catch { db close } 17565885e762Sdan sqlite3 db testerr.db 17575885e762Sdan execsql { 17585885e762Sdan ATTACH 'test.db' AS 'aux'; 17595885e762Sdan PRAGMA integrity_check; 17605885e762Sdan } 1761597515d7Sdan} $mainerr 17625885e762Sdando_test 22.4.2 { 17635885e762Sdan execsql { PRAGMA main.integrity_check; } 1764597515d7Sdan} $mainerr 17655885e762Sdando_test 22.4.3 { 17665885e762Sdan execsql { PRAGMA aux.integrity_check; } 17675885e762Sdan} {ok} 17685885e762Sdan 1769c95e01daSdrhdb close 1770c95e01daSdrhforcedelete test.db test.db-wal test.db-journal 1771c95e01daSdrhsqlite3 db test.db 1772c95e01daSdrhsqlite3 db2 test.db 1773c95e01daSdrhdo_test 23.1 { 1774c95e01daSdrh db eval { 1775c95e01daSdrh CREATE TABLE t1(a INTEGER PRIMARY KEY,b,c,d); 1776c95e01daSdrh CREATE INDEX i1 ON t1(b,c); 1777c95e01daSdrh CREATE INDEX i2 ON t1(c,d); 1778*7be0fd9cSdrh CREATE INDEX i2x ON t1(d COLLATE nocase, c DESC); 1779c95e01daSdrh CREATE TABLE t2(x INTEGER REFERENCES t1); 1780c95e01daSdrh } 1781c95e01daSdrh db2 eval {SELECT name FROM sqlite_master} 1782*7be0fd9cSdrh} {t1 i1 i2 i2x t2} 1783c228be5bSdrhdo_test 23.2a { 1784c95e01daSdrh db eval { 1785c95e01daSdrh DROP INDEX i2; 1786c95e01daSdrh CREATE INDEX i2 ON t1(c,d,b); 1787c95e01daSdrh } 1788c228be5bSdrh capture_pragma db2 out {PRAGMA index_info(i2)} 17895e7028c2Sdrh db2 eval {SELECT cid, name, '|' FROM out ORDER BY seqno} 17905e7028c2Sdrh} {2 c | 3 d | 1 b |} 1791*7be0fd9cSdrh 1792*7be0fd9cSdrh# EVIDENCE-OF: R-44874-46325 PRAGMA database.index_xinfo(index-name); 1793*7be0fd9cSdrh# This pragma returns information about every column in an index. 1794*7be0fd9cSdrh# 1795*7be0fd9cSdrh# EVIDENCE-OF: R-45970-35618 Unlike this index_info pragma, this pragma 1796*7be0fd9cSdrh# returns information about every column in the index, not just the key 1797*7be0fd9cSdrh# columns. 1798*7be0fd9cSdrh# 1799c228be5bSdrhdo_test 23.2b { 1800c228be5bSdrh capture_pragma db2 out {PRAGMA index_xinfo(i2)} 1801c228be5bSdrh db2 eval {SELECT cid, name, "desc", coll, "key", '|' FROM out ORDER BY seqno} 1802c228be5bSdrh} {2 c 0 BINARY 1 | 3 d 0 BINARY 1 | 1 b 0 BINARY 1 | -1 {} 0 BINARY 0 |} 1803*7be0fd9cSdrh 1804*7be0fd9cSdrh# (The first column of output from PRAGMA index_xinfo is...) 1805*7be0fd9cSdrh# EVIDENCE-OF: R-00197-14279 The rank of the column within the index. (0 1806*7be0fd9cSdrh# means left-most. Key columns come before auxiliary columns.) 1807*7be0fd9cSdrh# 1808*7be0fd9cSdrh# (The second column of output from PRAGMA index_xinfo is...) 1809*7be0fd9cSdrh# EVIDENCE-OF: R-40889-06838 The rank of the column within the table 1810*7be0fd9cSdrh# being indexed, or -1 if the index-column is the rowid of the table 1811*7be0fd9cSdrh# being indexed. 1812*7be0fd9cSdrh# 1813*7be0fd9cSdrh# (The third column of output from PRAGMA index_xinfo is...) 1814*7be0fd9cSdrh# EVIDENCE-OF: R-22751-28901 The name of the column being indexed, or 1815*7be0fd9cSdrh# NULL if the index-column is the rowid of the table being indexed. 1816*7be0fd9cSdrh# 1817*7be0fd9cSdrh# (The fourth column of output from PRAGMA index_xinfo is...) 1818*7be0fd9cSdrh# EVIDENCE-OF: R-11847-09179 1 if the index-column is sorted in reverse 1819*7be0fd9cSdrh# (DESC) order by the index and 0 otherwise. 1820*7be0fd9cSdrh# 1821*7be0fd9cSdrh# (The fifth column of output from PRAGMA index_xinfo is...) 1822*7be0fd9cSdrh# EVIDENCE-OF: R-15313-19540 The name for the collating sequence used to 1823*7be0fd9cSdrh# compare values in the index-column. 1824*7be0fd9cSdrh# 1825*7be0fd9cSdrh# (The sixth column of output from PRAGMA index_xinfo is...) 1826*7be0fd9cSdrh# EVIDENCE-OF: R-14310-64553 1 if the index-column is a key column and 0 1827*7be0fd9cSdrh# if the index-column is an auxiliary column. 1828*7be0fd9cSdrh# 1829*7be0fd9cSdrhdo_test 23.2c { 1830*7be0fd9cSdrh db2 eval {PRAGMA index_xinfo(i2)} 1831*7be0fd9cSdrh} {0 2 c 0 BINARY 1 1 3 d 0 BINARY 1 2 1 b 0 BINARY 1 3 -1 {} 0 BINARY 0} 1832*7be0fd9cSdrhdo_test 23.2d { 1833*7be0fd9cSdrh db2 eval {PRAGMA index_xinfo(i2x)} 1834*7be0fd9cSdrh} {0 3 d 0 nocase 1 1 2 c 1 BINARY 1 2 -1 {} 0 BINARY 0} 1835*7be0fd9cSdrh 1836*7be0fd9cSdrh# EVIDENCE-OF: R-63500-32024 PRAGMA database.index_list(table-name); 1837*7be0fd9cSdrh# This pragma returns one row for each index associated with the given 1838*7be0fd9cSdrh# table. 1839*7be0fd9cSdrh# 1840*7be0fd9cSdrh# (The first column of output from PRAGMA index_list is...) 1841*7be0fd9cSdrh# EVIDENCE-OF: R-02753-24748 A sequence number assigned to each index 1842*7be0fd9cSdrh# for internal tracking purposes. 1843*7be0fd9cSdrh# 1844*7be0fd9cSdrh# (The second column of output from PRAGMA index_list is...) 1845*7be0fd9cSdrh# EVIDENCE-OF: R-35496-03635 The name of the index. 1846*7be0fd9cSdrh# 1847*7be0fd9cSdrh# (The third column of output from PRAGMA index_list is...) 1848*7be0fd9cSdrh# EVIDENCE-OF: R-57301-64506 "1" if the index is UNIQUE and "0" if not. 1849*7be0fd9cSdrh# 1850*7be0fd9cSdrh# (The fourth column of output from PRAGMA index_list is...) 1851*7be0fd9cSdrh# EVIDENCE-OF: R-36609-39554 "c" if the index was created by a CREATE 1852*7be0fd9cSdrh# INDEX statement, "u" if the index was created by a UNIQUE constraint, 1853*7be0fd9cSdrh# or "pk" if the index was created by a PRIMARY KEY constraint. 1854*7be0fd9cSdrh# 1855c95e01daSdrhdo_test 23.3 { 1856c95e01daSdrh db eval { 1857c95e01daSdrh CREATE INDEX i3 ON t1(d,b,c); 1858c95e01daSdrh } 1859c228be5bSdrh capture_pragma db2 out {PRAGMA index_list(t1)} 1860*7be0fd9cSdrh db2 eval {SELECT seq, name, "unique", origin, '|' FROM out ORDER BY seq} 1861*7be0fd9cSdrh} {0 i3 0 c | 1 i2 0 c | 2 i2x 0 c | 3 i1 0 c |} 1862c95e01daSdrhdo_test 23.4 { 1863c95e01daSdrh db eval { 1864c95e01daSdrh ALTER TABLE t1 ADD COLUMN e; 1865c95e01daSdrh } 1866c95e01daSdrh db2 eval { 1867c95e01daSdrh PRAGMA table_info(t1); 1868c95e01daSdrh } 1869c95e01daSdrh} {/4 e {} 0 {} 0/} 1870c95e01daSdrhdo_test 23.5 { 1871c95e01daSdrh db eval { 1872c95e01daSdrh DROP TABLE t2; 1873c95e01daSdrh CREATE TABLE t2(x, y INTEGER REFERENCES t1); 1874c95e01daSdrh } 1875c95e01daSdrh db2 eval { 1876c95e01daSdrh PRAGMA foreign_key_list(t2); 1877c95e01daSdrh } 1878c95e01daSdrh} {0 0 t1 y {} {NO ACTION} {NO ACTION} NONE} 1879c95e01daSdrh 18801fed5dabSdandatabase_never_corrupt 1881cd61c281Sdrhfinish_test 1882