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} 222*59ac655dSdrhdo_test pragma-1.14.1 { 223*59ac655dSdrh execsql { 224*59ac655dSdrh PRAGMA synchronous=4; 225*59ac655dSdrh PRAGMA synchronous; 226*59ac655dSdrh } 227*59ac655dSdrh} {0} 228*59ac655dSdrhdo_test pragma-1.14.2 { 229*59ac655dSdrh execsql { 230*59ac655dSdrh PRAGMA synchronous=10; 231*59ac655dSdrh PRAGMA synchronous; 232*59ac655dSdrh } 233*59ac655dSdrh} {2} 234c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 2355260f7e9Sdrh 2365260f7e9Sdrh# Test turning "flag" pragmas on and off. 2375260f7e9Sdrh# 2386338c762Sdanielk1977ifcapable debug { 2396338c762Sdanielk1977 # Pragma "vdbe_listing" is only available if compiled with SQLITE_DEBUG 2406338c762Sdanielk1977 # 2415260f7e9Sdrh do_test pragma-1.15 { 2425260f7e9Sdrh execsql { 2435260f7e9Sdrh PRAGMA vdbe_listing=YES; 2445260f7e9Sdrh PRAGMA vdbe_listing; 2455260f7e9Sdrh } 2465260f7e9Sdrh } {1} 2475260f7e9Sdrh do_test pragma-1.16 { 2485260f7e9Sdrh execsql { 2495260f7e9Sdrh PRAGMA vdbe_listing=NO; 2505260f7e9Sdrh PRAGMA vdbe_listing; 2515260f7e9Sdrh } 2525260f7e9Sdrh } {0} 2536338c762Sdanielk1977} 2546338c762Sdanielk1977 2555260f7e9Sdrhdo_test pragma-1.17 { 2565260f7e9Sdrh execsql { 2575260f7e9Sdrh PRAGMA parser_trace=ON; 2585260f7e9Sdrh PRAGMA parser_trace=OFF; 2595260f7e9Sdrh } 2605260f7e9Sdrh} {} 2615260f7e9Sdrhdo_test pragma-1.18 { 2625260f7e9Sdrh execsql { 2635260f7e9Sdrh PRAGMA bogus = -1234; -- Parsing of negative values 2645260f7e9Sdrh } 2655260f7e9Sdrh} {} 2665260f7e9Sdrh 26791cf71b0Sdanielk1977# Test modifying the safety_level of an attached database. 2685a8f9374Sdanielk1977ifcapable pager_pragmas&&attach { 26991cf71b0Sdanielk1977 do_test pragma-2.1 { 270fda06befSmistachkin forcedelete test2.db 271fda06befSmistachkin forcedelete test2.db-journal 2724303feedSdrh execsql { 27391cf71b0Sdanielk1977 ATTACH 'test2.db' AS aux; 2744303feedSdrh } 27591cf71b0Sdanielk1977 } {} 27691cf71b0Sdanielk1977 do_test pragma-2.2 { 2774303feedSdrh execsql { 27891cf71b0Sdanielk1977 pragma aux.synchronous; 2794303feedSdrh } 28091cf71b0Sdanielk1977 } {2} 28191cf71b0Sdanielk1977 do_test pragma-2.3 { 28291cf71b0Sdanielk1977 execsql { 28391cf71b0Sdanielk1977 pragma aux.synchronous = OFF; 28491cf71b0Sdanielk1977 pragma aux.synchronous; 28591cf71b0Sdanielk1977 pragma synchronous; 28691cf71b0Sdanielk1977 } 28791cf71b0Sdanielk1977 } {0 2} 28891cf71b0Sdanielk1977 do_test pragma-2.4 { 28991cf71b0Sdanielk1977 execsql { 29091cf71b0Sdanielk1977 pragma aux.synchronous = ON; 29191cf71b0Sdanielk1977 pragma synchronous; 29291cf71b0Sdanielk1977 pragma aux.synchronous; 29391cf71b0Sdanielk1977 } 29491cf71b0Sdanielk1977 } {2 1} 295c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 2964303feedSdrh 297ed717fe3Sdrh# Construct a corrupted index and make sure the integrity_check 298ed717fe3Sdrh# pragma finds it. 299ed717fe3Sdrh# 30025d6543dSdrh# These tests won't work if the database is encrypted 30125d6543dSdrh# 302ed717fe3Sdrhdo_test pragma-3.1 { 3031e9daa6aSdrh db close 304fda06befSmistachkin forcedelete test.db test.db-journal 3051e9daa6aSdrh sqlite3 db test.db 306ed717fe3Sdrh execsql { 3071e9daa6aSdrh PRAGMA auto_vacuum=OFF; 308ed717fe3Sdrh BEGIN; 309ed717fe3Sdrh CREATE TABLE t2(a,b,c); 310ed717fe3Sdrh CREATE INDEX i2 ON t2(a); 311ed717fe3Sdrh INSERT INTO t2 VALUES(11,2,3); 312ed717fe3Sdrh INSERT INTO t2 VALUES(22,3,4); 313ed717fe3Sdrh COMMIT; 314ed717fe3Sdrh SELECT rowid, * from t2; 315ed717fe3Sdrh } 316ed717fe3Sdrh} {1 11 2 3 2 22 3 4} 3175a8f9374Sdanielk1977ifcapable attach { 31840e016e4Sdrh if {![sqlite3 -has-codec] && $sqlite_options(integrityck)} { 319ed717fe3Sdrh do_test pragma-3.2 { 320bb8a279eSdrh db eval {SELECT rootpage FROM sqlite_master WHERE name='i2'} break 321bb8a279eSdrh set pgsz [db eval {PRAGMA page_size}] 322bb8a279eSdrh # overwrite the header on the rootpage of the index in order to 323bb8a279eSdrh # make the index appear to be empty. 324bb8a279eSdrh # 325bb8a279eSdrh set offset [expr {$pgsz*($rootpage-1)}] 326bb8a279eSdrh hexio_write test.db $offset 0a00000000040000000000 327bb8a279eSdrh db close 328bb8a279eSdrh sqlite3 db test.db 329ed717fe3Sdrh execsql {PRAGMA integrity_check} 3306fbe41acSdrh } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} 33191cf71b0Sdanielk1977 do_test pragma-3.3 { 3321dcdbc06Sdrh execsql {PRAGMA integrity_check=1} 3336fbe41acSdrh } {{row 1 missing from index i2}} 3341dcdbc06Sdrh do_test pragma-3.4 { 33591cf71b0Sdanielk1977 execsql { 3361dcdbc06Sdrh ATTACH DATABASE 'test.db' AS t2; 3371dcdbc06Sdrh PRAGMA integrity_check 33891cf71b0Sdanielk1977 } 3396fbe41acSdrh } {{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}} 3401dcdbc06Sdrh do_test pragma-3.5 { 3411dcdbc06Sdrh execsql { 342bb8a279eSdrh PRAGMA integrity_check=4 3431dcdbc06Sdrh } 3446fbe41acSdrh } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2}} 3451dcdbc06Sdrh do_test pragma-3.6 { 3461dcdbc06Sdrh execsql { 3471dcdbc06Sdrh PRAGMA integrity_check=xyz 3481dcdbc06Sdrh } 3496fbe41acSdrh } {{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}} 3501dcdbc06Sdrh do_test pragma-3.7 { 3511dcdbc06Sdrh execsql { 3521dcdbc06Sdrh PRAGMA integrity_check=0 3531dcdbc06Sdrh } 3546fbe41acSdrh } {{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}} 3551dcdbc06Sdrh 3561dcdbc06Sdrh # Add additional corruption by appending unused pages to the end of 3571dcdbc06Sdrh # the database file testerr.db 3581dcdbc06Sdrh # 3591dcdbc06Sdrh do_test pragma-3.8 { 3601dcdbc06Sdrh execsql {DETACH t2} 361fda06befSmistachkin forcedelete testerr.db testerr.db-journal 362e3d559adSdrh set out [open testerr.db w] 363e3d559adSdrh fconfigure $out -translation binary 364e3d559adSdrh set in [open test.db r] 365e3d559adSdrh fconfigure $in -translation binary 3661dcdbc06Sdrh puts -nonewline $out [read $in] 3671dcdbc06Sdrh seek $in 0 3681dcdbc06Sdrh puts -nonewline $out [read $in] 3691dcdbc06Sdrh close $in 3701dcdbc06Sdrh close $out 371dd3cd977Sdrh hexio_write testerr.db 28 00000000 3721dcdbc06Sdrh execsql {REINDEX t2} 3731dcdbc06Sdrh execsql {PRAGMA integrity_check} 3741dcdbc06Sdrh } {ok} 37541c58b78Sdanielk1977 do_test pragma-3.8.1 { 37641c58b78Sdanielk1977 execsql {PRAGMA quick_check} 37741c58b78Sdanielk1977 } {ok} 3785d16a9a6Sdrh do_test pragma-3.8.2 { 3795d16a9a6Sdrh execsql {PRAGMA QUICK_CHECK} 3805d16a9a6Sdrh } {ok} 3811dcdbc06Sdrh do_test pragma-3.9 { 3821dcdbc06Sdrh execsql { 3831dcdbc06Sdrh ATTACH 'testerr.db' AS t2; 3841dcdbc06Sdrh PRAGMA integrity_check 3851dcdbc06Sdrh } 3861dcdbc06Sdrh } {{*** in database t2 *** 3871dcdbc06SdrhPage 4 is never used 3881dcdbc06SdrhPage 5 is never used 3896fbe41acSdrhPage 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} 3901dcdbc06Sdrh do_test pragma-3.10 { 3911dcdbc06Sdrh execsql { 3921dcdbc06Sdrh PRAGMA integrity_check=1 3931dcdbc06Sdrh } 3941dcdbc06Sdrh } {{*** in database t2 *** 3951dcdbc06SdrhPage 4 is never used}} 3961dcdbc06Sdrh do_test pragma-3.11 { 3971dcdbc06Sdrh execsql { 3981dcdbc06Sdrh PRAGMA integrity_check=5 3991dcdbc06Sdrh } 4001dcdbc06Sdrh } {{*** in database t2 *** 4011dcdbc06SdrhPage 4 is never used 4021dcdbc06SdrhPage 5 is never used 4036fbe41acSdrhPage 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2}} 4041dcdbc06Sdrh do_test pragma-3.12 { 4051dcdbc06Sdrh execsql { 4061dcdbc06Sdrh PRAGMA integrity_check=4 4071dcdbc06Sdrh } 4081dcdbc06Sdrh } {{*** in database t2 *** 4091dcdbc06SdrhPage 4 is never used 4101dcdbc06SdrhPage 5 is never used 4116fbe41acSdrhPage 6 is never used} {row 1 missing from index i2}} 4121dcdbc06Sdrh do_test pragma-3.13 { 4131dcdbc06Sdrh execsql { 4141dcdbc06Sdrh PRAGMA integrity_check=3 4151dcdbc06Sdrh } 4161dcdbc06Sdrh } {{*** in database t2 *** 4171dcdbc06SdrhPage 4 is never used 4181dcdbc06SdrhPage 5 is never used 4191dcdbc06SdrhPage 6 is never used}} 4201dcdbc06Sdrh do_test pragma-3.14 { 4211dcdbc06Sdrh execsql { 4221dcdbc06Sdrh PRAGMA integrity_check(2) 4231dcdbc06Sdrh } 4241dcdbc06Sdrh } {{*** in database t2 *** 4251dcdbc06SdrhPage 4 is never used 4261dcdbc06SdrhPage 5 is never used}} 4271dcdbc06Sdrh do_test pragma-3.15 { 4281dcdbc06Sdrh execsql { 4291dcdbc06Sdrh ATTACH 'testerr.db' AS t3; 4301dcdbc06Sdrh PRAGMA integrity_check 4311dcdbc06Sdrh } 4321dcdbc06Sdrh } {{*** in database t2 *** 4331dcdbc06SdrhPage 4 is never used 4341dcdbc06SdrhPage 5 is never used 4356fbe41acSdrhPage 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 *** 4361dcdbc06SdrhPage 4 is never used 4371dcdbc06SdrhPage 5 is never used 4386fbe41acSdrhPage 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} 4391dcdbc06Sdrh do_test pragma-3.16 { 4401dcdbc06Sdrh execsql { 441bb8a279eSdrh PRAGMA integrity_check(10) 4421dcdbc06Sdrh } 4431dcdbc06Sdrh } {{*** in database t2 *** 4441dcdbc06SdrhPage 4 is never used 4451dcdbc06SdrhPage 5 is never used 4466fbe41acSdrhPage 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 *** 4471dcdbc06SdrhPage 4 is never used 4481dcdbc06SdrhPage 5 is never used 4496fbe41acSdrhPage 6 is never used} {row 1 missing from index i2}} 4501dcdbc06Sdrh do_test pragma-3.17 { 4511dcdbc06Sdrh execsql { 452bb8a279eSdrh PRAGMA integrity_check=8 4531dcdbc06Sdrh } 4541dcdbc06Sdrh } {{*** in database t2 *** 4551dcdbc06SdrhPage 4 is never used 4561dcdbc06SdrhPage 5 is never used 4576fbe41acSdrhPage 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 *** 4581dcdbc06SdrhPage 4 is never used 4591dcdbc06SdrhPage 5 is never used}} 4601dcdbc06Sdrh do_test pragma-3.18 { 4611dcdbc06Sdrh execsql { 4621dcdbc06Sdrh PRAGMA integrity_check=4 4631dcdbc06Sdrh } 4641dcdbc06Sdrh } {{*** in database t2 *** 4651dcdbc06SdrhPage 4 is never used 4661dcdbc06SdrhPage 5 is never used 4676fbe41acSdrhPage 6 is never used} {row 1 missing from index i2}} 4681dcdbc06Sdrh } 469d2cb50b7Sdrh do_test pragma-3.19 { 470d2cb50b7Sdrh catch {db close} 471fda06befSmistachkin forcedelete test.db test.db-journal 472d2cb50b7Sdrh sqlite3 db test.db 473d2cb50b7Sdrh db eval {PRAGMA integrity_check} 474d2cb50b7Sdrh } {ok} 4755a8f9374Sdanielk1977} 476cefc87fcSdrh 477cefc87fcSdrh# Verify that PRAGMA integrity_check catches UNIQUE and NOT NULL 478cefc87fcSdrh# constraint violations. 479cefc87fcSdrh# 480cefc87fcSdrhdo_execsql_test pragma-3.20 { 481cefc87fcSdrh CREATE TABLE t1(a,b); 482cefc87fcSdrh CREATE INDEX t1a ON t1(a); 483cefc87fcSdrh INSERT INTO t1 VALUES(1,1),(2,2),(3,3),(2,4),(NULL,5),(NULL,6); 484cefc87fcSdrh PRAGMA writable_schema=ON; 485cefc87fcSdrh UPDATE sqlite_master SET sql='CREATE UNIQUE INDEX t1a ON t1(a)' 486cefc87fcSdrh WHERE name='t1a'; 487cefc87fcSdrh UPDATE sqlite_master SET sql='CREATE TABLE t1(a NOT NULL,b)' 488cefc87fcSdrh WHERE name='t1'; 489cefc87fcSdrh PRAGMA writable_schema=OFF; 490cefc87fcSdrh ALTER TABLE t1 RENAME TO t1x; 491cefc87fcSdrh PRAGMA integrity_check; 492cefc87fcSdrh} {{non-unique entry in index t1a} {NULL value in t1x.a} {non-unique entry in index t1a} {NULL value in t1x.a}} 493cefc87fcSdrhdo_execsql_test pragma-3.21 { 494cefc87fcSdrh PRAGMA integrity_check(3); 495cefc87fcSdrh} {{non-unique entry in index t1a} {NULL value in t1x.a} {non-unique entry in index t1a}} 496cefc87fcSdrhdo_execsql_test pragma-3.22 { 497cefc87fcSdrh PRAGMA integrity_check(2); 498cefc87fcSdrh} {{non-unique entry in index t1a} {NULL value in t1x.a}} 4997efa426eSdrhdo_execsql_test pragma-3.23 { 500cefc87fcSdrh PRAGMA integrity_check(1); 501cefc87fcSdrh} {{non-unique entry in index t1a}} 50291cf71b0Sdanielk1977 5037efa426eSdrh# PRAGMA integrity check (or more specifically the sqlite3BtreeCount() 5047efa426eSdrh# interface) used to leave index cursors in an inconsistent state 5057efa426eSdrh# which could result in an assertion fault in sqlite3BtreeKey() 5067efa426eSdrh# called from saveCursorPosition() if content is removed from the 5077efa426eSdrh# index while the integrity_check is still running. This test verifies 5087efa426eSdrh# that problem has been fixed. 5097efa426eSdrh# 5107efa426eSdrhdo_test pragma-3.30 { 5117efa426eSdrh db close 5127efa426eSdrh delete_file test.db 5137efa426eSdrh sqlite3 db test.db 5147efa426eSdrh db eval { 5157efa426eSdrh CREATE TABLE t1(a,b,c); 5167efa426eSdrh WITH RECURSIVE 5177efa426eSdrh c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<100) 5187efa426eSdrh INSERT INTO t1(a,b,c) SELECT i, printf('xyz%08x',i), 2000-i FROM c; 5197efa426eSdrh CREATE INDEX t1a ON t1(a); 5207efa426eSdrh CREATE INDEX t1bc ON t1(b,c); 5217efa426eSdrh } 5227efa426eSdrh db eval {PRAGMA integrity_check} { 5237efa426eSdrh db eval {DELETE FROM t1} 5247efa426eSdrh } 5257efa426eSdrh} {} 5267efa426eSdrh 52791cf71b0Sdanielk1977# Test modifying the cache_size of an attached database. 5285a8f9374Sdanielk1977ifcapable pager_pragmas&&attach { 52991cf71b0Sdanielk1977do_test pragma-4.1 { 53091cf71b0Sdanielk1977 execsql { 5311e9daa6aSdrh ATTACH 'test2.db' AS aux; 53291cf71b0Sdanielk1977 pragma aux.cache_size; 53391cf71b0Sdanielk1977 pragma aux.default_cache_size; 53491cf71b0Sdanielk1977 } 5351e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] 5361bdd9b57Sdrhdo_test pragma-4.2 { 5371bdd9b57Sdrh execsql { 53891cf71b0Sdanielk1977 pragma aux.cache_size = 50; 53991cf71b0Sdanielk1977 pragma aux.cache_size; 54091cf71b0Sdanielk1977 pragma aux.default_cache_size; 5411bdd9b57Sdrh } 5421e9daa6aSdrh} [list 50 $DFLT_CACHE_SZ] 5431bdd9b57Sdrhdo_test pragma-4.3 { 5441bdd9b57Sdrh execsql { 54591cf71b0Sdanielk1977 pragma aux.default_cache_size = 456; 54691cf71b0Sdanielk1977 pragma aux.cache_size; 54791cf71b0Sdanielk1977 pragma aux.default_cache_size; 5481bdd9b57Sdrh } 54991cf71b0Sdanielk1977} {456 456} 5501bdd9b57Sdrhdo_test pragma-4.4 { 5511bdd9b57Sdrh execsql { 55291cf71b0Sdanielk1977 pragma cache_size; 55391cf71b0Sdanielk1977 pragma default_cache_size; 5541bdd9b57Sdrh } 5551e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] 5561bdd9b57Sdrhdo_test pragma-4.5 { 5571bdd9b57Sdrh execsql { 55891cf71b0Sdanielk1977 DETACH aux; 55991cf71b0Sdanielk1977 ATTACH 'test3.db' AS aux; 56091cf71b0Sdanielk1977 pragma aux.cache_size; 56191cf71b0Sdanielk1977 pragma aux.default_cache_size; 5621bdd9b57Sdrh } 5631e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] 5641bdd9b57Sdrhdo_test pragma-4.6 { 5651bdd9b57Sdrh execsql { 56691cf71b0Sdanielk1977 DETACH aux; 56791cf71b0Sdanielk1977 ATTACH 'test2.db' AS aux; 56891cf71b0Sdanielk1977 pragma aux.cache_size; 56991cf71b0Sdanielk1977 pragma aux.default_cache_size; 5701bdd9b57Sdrh } 57191cf71b0Sdanielk1977} {456 456} 572c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 5731bdd9b57Sdrh 57491cf71b0Sdanielk1977# Test that modifying the sync-level in the middle of a transaction is 57591cf71b0Sdanielk1977# disallowed. 576c7b4a44cSdanielk1977ifcapable pager_pragmas { 57791cf71b0Sdanielk1977do_test pragma-5.0 { 5781bdd9b57Sdrh execsql { 57991cf71b0Sdanielk1977 pragma synchronous; 5801bdd9b57Sdrh } 58191cf71b0Sdanielk1977} {2} 58291cf71b0Sdanielk1977do_test pragma-5.1 { 5831bdd9b57Sdrh catchsql { 5841bdd9b57Sdrh BEGIN; 58591cf71b0Sdanielk1977 pragma synchronous = OFF; 5861bdd9b57Sdrh } 58791cf71b0Sdanielk1977} {1 {Safety level may not be changed inside a transaction}} 58891cf71b0Sdanielk1977do_test pragma-5.2 { 58991cf71b0Sdanielk1977 execsql { 59091cf71b0Sdanielk1977 pragma synchronous; 59191cf71b0Sdanielk1977 } 59291cf71b0Sdanielk1977} {2} 5935260f7e9Sdrhcatchsql {COMMIT;} 594c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 5955260f7e9Sdrh 5965260f7e9Sdrh# Test schema-query pragmas 5975260f7e9Sdrh# 59827188fb5Sdanielk1977ifcapable schema_pragmas { 5995a8f9374Sdanielk1977ifcapable tempdb&&attach { 6005260f7e9Sdrh do_test pragma-6.1 { 601956bc92cSdrh set res {} 60240e016e4Sdrh execsql {SELECT * FROM sqlite_temp_master} 6035260f7e9Sdrh foreach {idx name file} [execsql {pragma database_list}] { 6045260f7e9Sdrh lappend res $idx $name 6055260f7e9Sdrh } 6065260f7e9Sdrh set res 607a71aa001Sdrh } {0 main 1 temp 2 aux} 60853c0f748Sdanielk1977} 6095260f7e9Sdrhdo_test pragma-6.2 { 6105260f7e9Sdrh execsql { 611d2cb50b7Sdrh CREATE TABLE t2(a,b,c); 6125260f7e9Sdrh pragma table_info(t2) 6135260f7e9Sdrh } 614bfa8b102Sdrh} {0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0} 615d2cb50b7Sdrhdo_test pragma-6.2.1 { 616d2cb50b7Sdrh execsql { 617d2cb50b7Sdrh pragma table_info; 618d2cb50b7Sdrh } 619d2cb50b7Sdrh} {} 620736c7d4bSdrhdb nullvalue <<NULL>> 621417ec638Sdrhdo_test pragma-6.2.2 { 622417ec638Sdrh execsql { 623736c7d4bSdrh CREATE TABLE t5( 624736c7d4bSdrh a TEXT DEFAULT CURRENT_TIMESTAMP, 625736c7d4bSdrh b DEFAULT (5+3), 626736c7d4bSdrh c TEXT, 627736c7d4bSdrh d INTEGER DEFAULT NULL, 628384b7fe2Sdrh e TEXT DEFAULT '', 629384b7fe2Sdrh UNIQUE(b,c,d), 630384b7fe2Sdrh PRIMARY KEY(e,b,c) 631736c7d4bSdrh ); 632417ec638Sdrh PRAGMA table_info(t5); 633417ec638Sdrh } 634384b7fe2Sdrh} {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} 635736c7d4bSdrhdb nullvalue {} 636384b7fe2Sdrhdo_test pragma-6.2.3 { 637384b7fe2Sdrh execsql { 638384b7fe2Sdrh CREATE TABLE t2_3(a,b INTEGER PRIMARY KEY,c); 639384b7fe2Sdrh pragma table_info(t2_3) 640384b7fe2Sdrh } 641384b7fe2Sdrh} {0 a {} 0 {} 0 1 b INTEGER 0 {} 1 2 c {} 0 {} 0} 6426bf89570Sdrhifcapable {foreignkey} { 643d2cb50b7Sdrh do_test pragma-6.3.1 { 6445260f7e9Sdrh execsql { 6455260f7e9Sdrh CREATE TABLE t3(a int references t2(b), b UNIQUE); 6465260f7e9Sdrh pragma foreign_key_list(t3); 6475260f7e9Sdrh } 6481da40a38Sdan } {0 0 t2 a b {NO ACTION} {NO ACTION} NONE} 649d2cb50b7Sdrh do_test pragma-6.3.2 { 650d2cb50b7Sdrh execsql { 651d2cb50b7Sdrh pragma foreign_key_list; 652d2cb50b7Sdrh } 653d2cb50b7Sdrh } {} 654d2cb50b7Sdrh do_test pragma-6.3.3 { 655d2cb50b7Sdrh execsql { 656d2cb50b7Sdrh pragma foreign_key_list(t3_bogus); 657d2cb50b7Sdrh } 658d2cb50b7Sdrh } {} 659d2cb50b7Sdrh do_test pragma-6.3.4 { 660d2cb50b7Sdrh execsql { 661d2cb50b7Sdrh pragma foreign_key_list(t5); 662d2cb50b7Sdrh } 663d2cb50b7Sdrh } {} 6645260f7e9Sdrh do_test pragma-6.4 { 665c228be5bSdrh capture_pragma db out { 6665260f7e9Sdrh pragma index_list(t3); 6675260f7e9Sdrh } 668c228be5bSdrh db eval {SELECT seq, "name", "unique" FROM out ORDER BY seq} 6693ef26156Sdrh } {0 sqlite_autoindex_t3_1 1} 6706bf89570Sdrh} 6716bf89570Sdrhifcapable {!foreignkey} { 6726bf89570Sdrh execsql {CREATE TABLE t3(a,b UNIQUE)} 6736bf89570Sdrh} 674d2cb50b7Sdrhdo_test pragma-6.5.1 { 6755260f7e9Sdrh execsql { 6765260f7e9Sdrh CREATE INDEX t3i1 ON t3(a,b); 677c228be5bSdrh } 678c228be5bSdrh capture_pragma db out { 6795260f7e9Sdrh pragma index_info(t3i1); 6805260f7e9Sdrh } 681c228be5bSdrh db eval {SELECT seqno, cid, name FROM out ORDER BY seqno} 6825260f7e9Sdrh} {0 0 a 1 1 b} 6837be0fd9cSdrh 6847be0fd9cSdrh# EVIDENCE-OF: R-23114-21695 The auxiliary index-columns are not shown 6857be0fd9cSdrh# by the index_info pragma, but they are listed by the index_xinfo 6867be0fd9cSdrh# pragma. 6877be0fd9cSdrh# 6887be0fd9cSdrhdo_test pragma-6.5.1b { 6897be0fd9cSdrh capture_pragma db out {PRAGMA index_xinfo(t3i1)} 6907be0fd9cSdrh db eval {SELECT seqno, cid, name FROM out ORDER BY seqno} 6917be0fd9cSdrh} {0 0 a 1 1 b 2 -1 {}} 6927be0fd9cSdrh 6937be0fd9cSdrh 6947be0fd9cSdrh# EVIDENCE-OF: R-62725-03366 PRAGMA database.index_info(index-name); 6957be0fd9cSdrh# This pragma returns one row for each key column in the named index. 6967be0fd9cSdrh# 6977be0fd9cSdrh# (The first column of output from PRAGMA index_info is...) 6987be0fd9cSdrh# EVIDENCE-OF: R-34186-52914 The rank of the column within the index. (0 6997be0fd9cSdrh# means left-most.) 7007be0fd9cSdrh# 7017be0fd9cSdrh# (The second column of output from PRAGMA index_info is...) 7027be0fd9cSdrh# EVIDENCE-OF: R-65019-08383 The rank of the column within the table 7037be0fd9cSdrh# being indexed. 7047be0fd9cSdrh# 7057be0fd9cSdrh# (The third column of output from PRAGMA index_info is...) 7067be0fd9cSdrh# EVIDENCE-OF: R-09773-34266 The name of the column being indexed. 7077be0fd9cSdrh# 7087be0fd9cSdrhdo_execsql_test pragma-6.5.1c { 7097be0fd9cSdrh CREATE INDEX t3i2 ON t3(b,a); 7107be0fd9cSdrh PRAGMA index_info='t3i2'; 7117be0fd9cSdrh DROP INDEX t3i2; 7127be0fd9cSdrh} {0 1 b 1 0 a} 7137be0fd9cSdrh 714d2cb50b7Sdrhdo_test pragma-6.5.2 { 715d2cb50b7Sdrh execsql { 716d2cb50b7Sdrh pragma index_info(t3i1_bogus); 717d2cb50b7Sdrh } 718d2cb50b7Sdrh} {} 719260d8a6aSdanielk1977 720260d8a6aSdanielk1977ifcapable tempdb { 721260d8a6aSdanielk1977 # Test for ticket #3320. When a temp table of the same name exists, make 722260d8a6aSdanielk1977 # sure the schema of the main table can still be queried using 723260d8a6aSdanielk1977 # "pragma table_info": 724260d8a6aSdanielk1977 do_test pragma-6.6.1 { 725260d8a6aSdanielk1977 execsql { 726260d8a6aSdanielk1977 CREATE TABLE trial(col_main); 727260d8a6aSdanielk1977 CREATE TEMP TABLE trial(col_temp); 728260d8a6aSdanielk1977 } 729260d8a6aSdanielk1977 } {} 730260d8a6aSdanielk1977 do_test pragma-6.6.2 { 731260d8a6aSdanielk1977 execsql { 732260d8a6aSdanielk1977 PRAGMA table_info(trial); 733260d8a6aSdanielk1977 } 734260d8a6aSdanielk1977 } {0 col_temp {} 0 {} 0} 735260d8a6aSdanielk1977 do_test pragma-6.6.3 { 736260d8a6aSdanielk1977 execsql { 737260d8a6aSdanielk1977 PRAGMA temp.table_info(trial); 738260d8a6aSdanielk1977 } 739260d8a6aSdanielk1977 } {0 col_temp {} 0 {} 0} 740260d8a6aSdanielk1977 do_test pragma-6.6.4 { 741260d8a6aSdanielk1977 execsql { 742260d8a6aSdanielk1977 PRAGMA main.table_info(trial); 743260d8a6aSdanielk1977 } 744260d8a6aSdanielk1977 } {0 col_main {} 0 {} 0} 745260d8a6aSdanielk1977} 746f96a3778Sdanielk1977 747f96a3778Sdanielk1977do_test pragma-6.7 { 748f96a3778Sdanielk1977 execsql { 749f96a3778Sdanielk1977 CREATE TABLE test_table( 750f96a3778Sdanielk1977 one INT NOT NULL DEFAULT -1, 751f96a3778Sdanielk1977 two text, 752f96a3778Sdanielk1977 three VARCHAR(45, 65) DEFAULT 'abcde', 753f96a3778Sdanielk1977 four REAL DEFAULT X'abcdef', 754f96a3778Sdanielk1977 five DEFAULT CURRENT_TIME 755f96a3778Sdanielk1977 ); 756f96a3778Sdanielk1977 } 757c228be5bSdrh capture_pragma db out {PRAGMA table_info(test_table)} 758c228be5bSdrh db eval {SELECT cid, "name", type, "notnull", dflt_value, pk FROM out 759c228be5bSdrh ORDER BY cid} 760f96a3778Sdanielk1977} [concat \ 761f96a3778Sdanielk1977 {0 one INT 1 -1 0} \ 762f96a3778Sdanielk1977 {1 two text 0 {} 0} \ 763f96a3778Sdanielk1977 {2 three {VARCHAR(45, 65)} 0 'abcde' 0} \ 764f96a3778Sdanielk1977 {3 four REAL 0 X'abcdef' 0} \ 765f96a3778Sdanielk1977 {4 five {} 0 CURRENT_TIME 0} \ 766f96a3778Sdanielk1977] 7671b678969Sdrhdo_test pragma-6.8 { 7681b678969Sdrh execsql { 7691b678969Sdrh CREATE TABLE t68(a,b,c,PRIMARY KEY(a,b,a,c)); 7701b678969Sdrh PRAGMA table_info(t68); 7711b678969Sdrh } 7721b678969Sdrh} [concat \ 7731b678969Sdrh {0 a {} 0 {} 1} \ 7741b678969Sdrh {1 b {} 0 {} 2} \ 7751b678969Sdrh {2 c {} 0 {} 4} \ 7761b678969Sdrh] 77727188fb5Sdanielk1977} ;# ifcapable schema_pragmas 7785260f7e9Sdrh# Miscellaneous tests 7795260f7e9Sdrh# 78027188fb5Sdanielk1977ifcapable schema_pragmas { 7817be0fd9cSdrh# EVIDENCE-OF: R-63500-32024 PRAGMA database.index_list(table-name); 7827be0fd9cSdrh# This pragma returns one row for each index associated with the given 7837be0fd9cSdrh# table. 784d2cb50b7Sdrhdo_test pragma-7.1.1 { 7855260f7e9Sdrh # Make sure a pragma knows to read the schema if it needs to 7865260f7e9Sdrh db close 7875260f7e9Sdrh sqlite3 db test.db 788c228be5bSdrh capture_pragma db out "PRAGMA index_list(t3)" 789c228be5bSdrh db eval {SELECT name, "origin" FROM out ORDER BY name DESC} 790c228be5bSdrh} {t3i1 c sqlite_autoindex_t3_1 u} 791d2cb50b7Sdrhdo_test pragma-7.1.2 { 792d2cb50b7Sdrh execsql { 793d2cb50b7Sdrh pragma index_list(t3_bogus); 794d2cb50b7Sdrh } 795d2cb50b7Sdrh} {} 79627188fb5Sdanielk1977} ;# ifcapable schema_pragmas 7976c62608fSdrhifcapable {utf16} { 798cb354603Sdan if {[permutation] == ""} { 7995260f7e9Sdrh do_test pragma-7.2 { 8005260f7e9Sdrh db close 8015260f7e9Sdrh sqlite3 db test.db 8025260f7e9Sdrh catchsql { 8035260f7e9Sdrh pragma encoding=bogus; 8045260f7e9Sdrh } 8055260f7e9Sdrh } {1 {unsupported encoding: bogus}} 8066c62608fSdrh } 807cb354603Sdan} 80853c0f748Sdanielk1977ifcapable tempdb { 8095260f7e9Sdrh do_test pragma-7.3 { 8105260f7e9Sdrh db close 8115260f7e9Sdrh sqlite3 db test.db 8125260f7e9Sdrh execsql { 8135260f7e9Sdrh pragma lock_status; 8145260f7e9Sdrh } 8155260f7e9Sdrh } {main unlocked temp closed} 81653c0f748Sdanielk1977} else { 81753c0f748Sdanielk1977 do_test pragma-7.3 { 81853c0f748Sdanielk1977 db close 81953c0f748Sdanielk1977 sqlite3 db test.db 82053c0f748Sdanielk1977 execsql { 82153c0f748Sdanielk1977 pragma lock_status; 82253c0f748Sdanielk1977 } 82353c0f748Sdanielk1977 } {main unlocked} 82453c0f748Sdanielk1977} 8255260f7e9Sdrh 8265260f7e9Sdrh 827dae2495bSdanielk1977#---------------------------------------------------------------------- 828b92b70bbSdanielk1977# Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA 829b92b70bbSdanielk1977# user_version" statements. 830dae2495bSdanielk1977# 831b92b70bbSdanielk1977# pragma-8.1: PRAGMA schema_version 832b92b70bbSdanielk1977# pragma-8.2: PRAGMA user_version 833dae2495bSdanielk1977# 834dae2495bSdanielk1977 83511cf9fbcSdanielk1977ifcapable schema_version { 83611cf9fbcSdanielk1977 837b92b70bbSdanielk1977# First check that we can set the schema version and then retrieve the 838dae2495bSdanielk1977# same value. 839dae2495bSdanielk1977do_test pragma-8.1.1 { 840dae2495bSdanielk1977 execsql { 841b92b70bbSdanielk1977 PRAGMA schema_version = 105; 842dae2495bSdanielk1977 } 843dae2495bSdanielk1977} {} 844dae2495bSdanielk1977do_test pragma-8.1.2 { 84525403650Sdrh execsql2 { 846b92b70bbSdanielk1977 PRAGMA schema_version; 847dae2495bSdanielk1977 } 84825403650Sdrh} {schema_version 105} 849dae2495bSdanielk1977do_test pragma-8.1.3 { 850dae2495bSdanielk1977 execsql { 851b92b70bbSdanielk1977 PRAGMA schema_version = 106; 852dae2495bSdanielk1977 } 853dae2495bSdanielk1977} {} 854dae2495bSdanielk1977do_test pragma-8.1.4 { 855dae2495bSdanielk1977 execsql { 856b92b70bbSdanielk1977 PRAGMA schema_version; 857dae2495bSdanielk1977 } 858dae2495bSdanielk1977} 106 859dae2495bSdanielk1977 860b92b70bbSdanielk1977# Check that creating a table modifies the schema-version (this is really 861b92b70bbSdanielk1977# to verify that the value being read is in fact the schema version). 862dae2495bSdanielk1977do_test pragma-8.1.5 { 863dae2495bSdanielk1977 execsql { 864dae2495bSdanielk1977 CREATE TABLE t4(a, b, c); 865dae2495bSdanielk1977 INSERT INTO t4 VALUES(1, 2, 3); 866dae2495bSdanielk1977 SELECT * FROM t4; 867dae2495bSdanielk1977 } 868dae2495bSdanielk1977} {1 2 3} 869dae2495bSdanielk1977do_test pragma-8.1.6 { 870dae2495bSdanielk1977 execsql { 871b92b70bbSdanielk1977 PRAGMA schema_version; 872dae2495bSdanielk1977 } 873dae2495bSdanielk1977} 107 874dae2495bSdanielk1977 875dae2495bSdanielk1977# Now open a second connection to the database. Ensure that changing the 876b92b70bbSdanielk1977# schema-version using the first connection forces the second connection 877dae2495bSdanielk1977# to reload the schema. This has to be done using the C-API test functions, 878dae2495bSdanielk1977# because the TCL API accounts for SCHEMA_ERROR and retries the query. 879dae2495bSdanielk1977do_test pragma-8.1.7 { 880dddca286Sdrh sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] 881dae2495bSdanielk1977 execsql { 882dae2495bSdanielk1977 SELECT * FROM t4; 883dae2495bSdanielk1977 } db2 884dae2495bSdanielk1977} {1 2 3} 885dae2495bSdanielk1977do_test pragma-8.1.8 { 886dae2495bSdanielk1977 execsql { 887b92b70bbSdanielk1977 PRAGMA schema_version = 108; 888dae2495bSdanielk1977 } 889dae2495bSdanielk1977} {} 890dae2495bSdanielk1977do_test pragma-8.1.9 { 891dae2495bSdanielk1977 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY] 892dae2495bSdanielk1977 sqlite3_step $::STMT 893dae2495bSdanielk1977} SQLITE_ERROR 894dae2495bSdanielk1977do_test pragma-8.1.10 { 895dae2495bSdanielk1977 sqlite3_finalize $::STMT 896dae2495bSdanielk1977} SQLITE_SCHEMA 897dae2495bSdanielk1977 898b92b70bbSdanielk1977# Make sure the schema-version can be manipulated in an attached database. 899fda06befSmistachkinforcedelete test2.db 900fda06befSmistachkinforcedelete test2.db-journal 9015a8f9374Sdanielk1977ifcapable attach { 902dae2495bSdanielk1977 do_test pragma-8.1.11 { 903dae2495bSdanielk1977 execsql { 904dae2495bSdanielk1977 ATTACH 'test2.db' AS aux; 905dae2495bSdanielk1977 CREATE TABLE aux.t1(a, b, c); 906b92b70bbSdanielk1977 PRAGMA aux.schema_version = 205; 907dae2495bSdanielk1977 } 908dae2495bSdanielk1977 } {} 909dae2495bSdanielk1977 do_test pragma-8.1.12 { 910dae2495bSdanielk1977 execsql { 911b92b70bbSdanielk1977 PRAGMA aux.schema_version; 912dae2495bSdanielk1977 } 913dae2495bSdanielk1977 } 205 9145a8f9374Sdanielk1977} 915dae2495bSdanielk1977do_test pragma-8.1.13 { 916dae2495bSdanielk1977 execsql { 917b92b70bbSdanielk1977 PRAGMA schema_version; 918dae2495bSdanielk1977 } 919dae2495bSdanielk1977} 108 920dae2495bSdanielk1977 921b92b70bbSdanielk1977# And check that modifying the schema-version in an attached database 922dae2495bSdanielk1977# forces the second connection to reload the schema. 9235a8f9374Sdanielk1977ifcapable attach { 924dae2495bSdanielk1977 do_test pragma-8.1.14 { 925dddca286Sdrh sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] 926dae2495bSdanielk1977 execsql { 927dae2495bSdanielk1977 ATTACH 'test2.db' AS aux; 928dae2495bSdanielk1977 SELECT * FROM aux.t1; 929dae2495bSdanielk1977 } db2 930dae2495bSdanielk1977 } {} 931dae2495bSdanielk1977 do_test pragma-8.1.15 { 932dae2495bSdanielk1977 execsql { 933b92b70bbSdanielk1977 PRAGMA aux.schema_version = 206; 934dae2495bSdanielk1977 } 935dae2495bSdanielk1977 } {} 936dae2495bSdanielk1977 do_test pragma-8.1.16 { 937dae2495bSdanielk1977 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY] 938dae2495bSdanielk1977 sqlite3_step $::STMT 939dae2495bSdanielk1977 } SQLITE_ERROR 940dae2495bSdanielk1977 do_test pragma-8.1.17 { 941dae2495bSdanielk1977 sqlite3_finalize $::STMT 942dae2495bSdanielk1977 } SQLITE_SCHEMA 943dae2495bSdanielk1977 do_test pragma-8.1.18 { 944dae2495bSdanielk1977 db2 close 945dae2495bSdanielk1977 } {} 9465a8f9374Sdanielk1977} 947dae2495bSdanielk1977 948b92b70bbSdanielk1977# Now test that the user-version can be read and written (and that we aren't 949b92b70bbSdanielk1977# accidentally manipulating the schema-version instead). 950dae2495bSdanielk1977do_test pragma-8.2.1 { 95125403650Sdrh execsql2 { 952b92b70bbSdanielk1977 PRAGMA user_version; 953dae2495bSdanielk1977 } 95425403650Sdrh} {user_version 0} 955dae2495bSdanielk1977do_test pragma-8.2.2 { 956dae2495bSdanielk1977 execsql { 957b92b70bbSdanielk1977 PRAGMA user_version = 2; 958dae2495bSdanielk1977 } 959dae2495bSdanielk1977} {} 960802d69a7Sdrhdo_test pragma-8.2.3.1 { 96125403650Sdrh execsql2 { 962b92b70bbSdanielk1977 PRAGMA user_version; 963dae2495bSdanielk1977 } 96425403650Sdrh} {user_version 2} 965802d69a7Sdrhdo_test pragma-8.2.3.2 { 966802d69a7Sdrh db close 967802d69a7Sdrh sqlite3 db test.db 968802d69a7Sdrh execsql { 969802d69a7Sdrh PRAGMA user_version; 970802d69a7Sdrh } 971802d69a7Sdrh} {2} 972802d69a7Sdrhdo_test pragma-8.2.4.1 { 973dae2495bSdanielk1977 execsql { 974b92b70bbSdanielk1977 PRAGMA schema_version; 975dae2495bSdanielk1977 } 976dae2495bSdanielk1977} {108} 977802d69a7Sdrhifcapable vacuum { 978802d69a7Sdrh do_test pragma-8.2.4.2 { 979802d69a7Sdrh execsql { 980802d69a7Sdrh VACUUM; 981802d69a7Sdrh PRAGMA user_version; 982802d69a7Sdrh } 983802d69a7Sdrh } {2} 984802d69a7Sdrh do_test pragma-8.2.4.3 { 985802d69a7Sdrh execsql { 986802d69a7Sdrh PRAGMA schema_version; 987802d69a7Sdrh } 988802d69a7Sdrh } {109} 989802d69a7Sdrh} 9905a8f9374Sdanielk1977 9915a8f9374Sdanielk1977ifcapable attach { 992802d69a7Sdrh db eval {ATTACH 'test2.db' AS aux} 993dae2495bSdanielk1977 994b92b70bbSdanielk1977 # Check that the user-version in the auxilary database can be manipulated ( 995dae2495bSdanielk1977 # and that we aren't accidentally manipulating the same in the main db). 996dae2495bSdanielk1977 do_test pragma-8.2.5 { 997dae2495bSdanielk1977 execsql { 998b92b70bbSdanielk1977 PRAGMA aux.user_version; 999dae2495bSdanielk1977 } 1000dae2495bSdanielk1977 } {0} 1001dae2495bSdanielk1977 do_test pragma-8.2.6 { 1002dae2495bSdanielk1977 execsql { 1003b92b70bbSdanielk1977 PRAGMA aux.user_version = 3; 1004dae2495bSdanielk1977 } 1005dae2495bSdanielk1977 } {} 1006dae2495bSdanielk1977 do_test pragma-8.2.7 { 1007dae2495bSdanielk1977 execsql { 1008b92b70bbSdanielk1977 PRAGMA aux.user_version; 1009dae2495bSdanielk1977 } 1010dae2495bSdanielk1977 } {3} 1011dae2495bSdanielk1977 do_test pragma-8.2.8 { 1012dae2495bSdanielk1977 execsql { 1013b92b70bbSdanielk1977 PRAGMA main.user_version; 1014dae2495bSdanielk1977 } 1015dae2495bSdanielk1977 } {2} 1016dae2495bSdanielk1977 1017b92b70bbSdanielk1977 # Now check that a ROLLBACK resets the user-version if it has been modified 1018dae2495bSdanielk1977 # within a transaction. 1019dae2495bSdanielk1977 do_test pragma-8.2.9 { 1020dae2495bSdanielk1977 execsql { 1021dae2495bSdanielk1977 BEGIN; 1022b92b70bbSdanielk1977 PRAGMA aux.user_version = 10; 1023b92b70bbSdanielk1977 PRAGMA user_version = 11; 1024dae2495bSdanielk1977 } 1025dae2495bSdanielk1977 } {} 1026dae2495bSdanielk1977 do_test pragma-8.2.10 { 1027dae2495bSdanielk1977 execsql { 1028b92b70bbSdanielk1977 PRAGMA aux.user_version; 1029dae2495bSdanielk1977 } 1030dae2495bSdanielk1977 } {10} 1031dae2495bSdanielk1977 do_test pragma-8.2.11 { 1032dae2495bSdanielk1977 execsql { 1033b92b70bbSdanielk1977 PRAGMA main.user_version; 1034dae2495bSdanielk1977 } 1035dae2495bSdanielk1977 } {11} 1036dae2495bSdanielk1977 do_test pragma-8.2.12 { 1037dae2495bSdanielk1977 execsql { 1038dae2495bSdanielk1977 ROLLBACK; 1039b92b70bbSdanielk1977 PRAGMA aux.user_version; 1040dae2495bSdanielk1977 } 1041dae2495bSdanielk1977 } {3} 1042dae2495bSdanielk1977 do_test pragma-8.2.13 { 1043dae2495bSdanielk1977 execsql { 1044b92b70bbSdanielk1977 PRAGMA main.user_version; 1045dae2495bSdanielk1977 } 1046dae2495bSdanielk1977 } {2} 10475a8f9374Sdanielk1977} 1048dae2495bSdanielk1977 1049b92b70bbSdanielk1977# Try a negative value for the user-version 1050dae2495bSdanielk1977do_test pragma-8.2.14 { 1051dae2495bSdanielk1977 execsql { 1052b92b70bbSdanielk1977 PRAGMA user_version = -450; 1053dae2495bSdanielk1977 } 1054dae2495bSdanielk1977} {} 1055dae2495bSdanielk1977do_test pragma-8.2.15 { 1056dae2495bSdanielk1977 execsql { 1057b92b70bbSdanielk1977 PRAGMA user_version; 1058dae2495bSdanielk1977 } 1059dae2495bSdanielk1977} {-450} 1060d9c847dcSdanielk1977} ; # ifcapable schema_version 1061d9c847dcSdanielk1977 1062d19744f3Sdrh# Check to see if TEMP_STORE is memory or disk. Return strings 1063d19744f3Sdrh# "memory" or "disk" as appropriate. 1064d19744f3Sdrh# 1065d19744f3Sdrhproc check_temp_store {} { 1066d19744f3Sdrh db eval {CREATE TEMP TABLE IF NOT EXISTS a(b)} 1067d19744f3Sdrh db eval {PRAGMA database_list} { 1068d19744f3Sdrh if {$name=="temp"} { 106917b90b53Sdanielk1977 set bt [btree_from_db db 1] 107017b90b53Sdanielk1977 if {[btree_ismemdb $bt]} { 1071d19744f3Sdrh return "memory" 1072d19744f3Sdrh } 107317b90b53Sdanielk1977 return "disk" 1074d19744f3Sdrh } 1075d19744f3Sdrh } 1076d19744f3Sdrh return "unknown" 1077d19744f3Sdrh} 1078d19744f3Sdrh 10794ee09b4bSdrh# Application_ID 10804ee09b4bSdrh# 10814ee09b4bSdrhdo_test pragma-8.3.1 { 10824ee09b4bSdrh execsql { 10834ee09b4bSdrh PRAGMA application_id; 10844ee09b4bSdrh } 10854ee09b4bSdrh} {0} 10864ee09b4bSdrhdo_test pragma-8.3.2 { 10874ee09b4bSdrh execsql {PRAGMA Application_ID(12345); PRAGMA application_id;} 10884ee09b4bSdrh} {12345} 10899a09a3caStpoindex 10909a09a3caStpoindex# Test temp_store and temp_store_directory pragmas 10919a09a3caStpoindex# 1092268283bcSdrhifcapable pager_pragmas { 10939a09a3caStpoindexdo_test pragma-9.1 { 10949a09a3caStpoindex db close 10959a09a3caStpoindex sqlite3 db test.db 10969a09a3caStpoindex execsql { 10979a09a3caStpoindex PRAGMA temp_store; 10989a09a3caStpoindex } 10999a09a3caStpoindex} {0} 1100d19744f3Sdrhif {$TEMP_STORE<=1} { 1101d19744f3Sdrh do_test pragma-9.1.1 { 1102d19744f3Sdrh check_temp_store 1103d19744f3Sdrh } {disk} 1104d19744f3Sdrh} else { 1105d19744f3Sdrh do_test pragma-9.1.1 { 1106d19744f3Sdrh check_temp_store 1107d19744f3Sdrh } {memory} 1108d19744f3Sdrh} 1109d19744f3Sdrh 11109a09a3caStpoindexdo_test pragma-9.2 { 1111d19744f3Sdrh db close 1112d19744f3Sdrh sqlite3 db test.db 11139a09a3caStpoindex execsql { 11149a09a3caStpoindex PRAGMA temp_store=file; 11159a09a3caStpoindex PRAGMA temp_store; 11169a09a3caStpoindex } 11179a09a3caStpoindex} {1} 1118d19744f3Sdrhif {$TEMP_STORE==3} { 1119d19744f3Sdrh # When TEMP_STORE is 3, always use memory regardless of pragma settings. 1120d19744f3Sdrh do_test pragma-9.2.1 { 1121d19744f3Sdrh check_temp_store 1122d19744f3Sdrh } {memory} 1123d19744f3Sdrh} else { 1124d19744f3Sdrh do_test pragma-9.2.1 { 1125d19744f3Sdrh check_temp_store 1126d19744f3Sdrh } {disk} 1127d19744f3Sdrh} 1128d19744f3Sdrh 11299a09a3caStpoindexdo_test pragma-9.3 { 1130d19744f3Sdrh db close 1131d19744f3Sdrh sqlite3 db test.db 11329a09a3caStpoindex execsql { 11339a09a3caStpoindex PRAGMA temp_store=memory; 11349a09a3caStpoindex PRAGMA temp_store; 11359a09a3caStpoindex } 11369a09a3caStpoindex} {2} 1137d19744f3Sdrhif {$TEMP_STORE==0} { 1138d19744f3Sdrh # When TEMP_STORE is 0, always use the disk regardless of pragma settings. 1139d19744f3Sdrh do_test pragma-9.3.1 { 1140d19744f3Sdrh check_temp_store 1141d19744f3Sdrh } {disk} 1142d19744f3Sdrh} else { 1143d19744f3Sdrh do_test pragma-9.3.1 { 1144d19744f3Sdrh check_temp_store 1145d19744f3Sdrh } {memory} 1146d19744f3Sdrh} 1147d19744f3Sdrh 11489a09a3caStpoindexdo_test pragma-9.4 { 11499a09a3caStpoindex execsql { 11509a09a3caStpoindex PRAGMA temp_store_directory; 11519a09a3caStpoindex } 11529a09a3caStpoindex} {} 115378f82d1eSdrhifcapable wsd { 11549a09a3caStpoindex do_test pragma-9.5 { 1155f8a78464Smistachkin set pwd [string map {' ''} [file nativename [get_pwd]]] 1156268283bcSdrh execsql " 1157268283bcSdrh PRAGMA temp_store_directory='$pwd'; 11589a09a3caStpoindex " 11599a09a3caStpoindex } {} 11609a09a3caStpoindex do_test pragma-9.6 { 11619a09a3caStpoindex execsql { 11629a09a3caStpoindex PRAGMA temp_store_directory; 11639a09a3caStpoindex } 1164f8a78464Smistachkin } [list [file nativename [get_pwd]]] 11659a09a3caStpoindex do_test pragma-9.7 { 1166268283bcSdrh catchsql { 11679a09a3caStpoindex PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR'; 11689a09a3caStpoindex } 1169268283bcSdrh } {1 {not a writable directory}} 11709a09a3caStpoindex do_test pragma-9.8 { 11719a09a3caStpoindex execsql { 11729a09a3caStpoindex PRAGMA temp_store_directory=''; 11739a09a3caStpoindex } 11749a09a3caStpoindex } {} 11751e9daa6aSdrh if {![info exists TEMP_STORE] || $TEMP_STORE<=1} { 117653c0f748Sdanielk1977 ifcapable tempdb { 11779a09a3caStpoindex do_test pragma-9.9 { 11789a09a3caStpoindex execsql { 11799a09a3caStpoindex PRAGMA temp_store_directory; 11809a09a3caStpoindex PRAGMA temp_store=FILE; 11819a09a3caStpoindex CREATE TEMP TABLE temp_store_directory_test(a integer); 11829a09a3caStpoindex INSERT INTO temp_store_directory_test values (2); 11839a09a3caStpoindex SELECT * FROM temp_store_directory_test; 11849a09a3caStpoindex } 11859a09a3caStpoindex } {2} 11869a09a3caStpoindex do_test pragma-9.10 { 1187268283bcSdrh catchsql " 1188268283bcSdrh PRAGMA temp_store_directory='$pwd'; 11899a09a3caStpoindex SELECT * FROM temp_store_directory_test; 11909a09a3caStpoindex " 1191268283bcSdrh } {1 {no such table: temp_store_directory_test}} 11921e9daa6aSdrh } 11931e9daa6aSdrh } 119478f82d1eSdrh} 119595b289b6Sdanielk1977do_test pragma-9.11 { 119695b289b6Sdanielk1977 execsql { 119795b289b6Sdanielk1977 PRAGMA temp_store = 0; 119895b289b6Sdanielk1977 PRAGMA temp_store; 119995b289b6Sdanielk1977 } 120095b289b6Sdanielk1977} {0} 120195b289b6Sdanielk1977do_test pragma-9.12 { 120295b289b6Sdanielk1977 execsql { 120395b289b6Sdanielk1977 PRAGMA temp_store = 1; 120495b289b6Sdanielk1977 PRAGMA temp_store; 120595b289b6Sdanielk1977 } 120695b289b6Sdanielk1977} {1} 120795b289b6Sdanielk1977do_test pragma-9.13 { 120895b289b6Sdanielk1977 execsql { 120995b289b6Sdanielk1977 PRAGMA temp_store = 2; 121095b289b6Sdanielk1977 PRAGMA temp_store; 121195b289b6Sdanielk1977 } 121295b289b6Sdanielk1977} {2} 121395b289b6Sdanielk1977do_test pragma-9.14 { 121495b289b6Sdanielk1977 execsql { 121595b289b6Sdanielk1977 PRAGMA temp_store = 3; 121695b289b6Sdanielk1977 PRAGMA temp_store; 121795b289b6Sdanielk1977 } 121895b289b6Sdanielk1977} {0} 121995b289b6Sdanielk1977do_test pragma-9.15 { 122095b289b6Sdanielk1977 catchsql { 122195b289b6Sdanielk1977 BEGIN EXCLUSIVE; 122295b289b6Sdanielk1977 CREATE TEMP TABLE temp_table(t); 122395b289b6Sdanielk1977 INSERT INTO temp_table VALUES('valuable data'); 122495b289b6Sdanielk1977 PRAGMA temp_store = 1; 122595b289b6Sdanielk1977 } 122695b289b6Sdanielk1977} {1 {temporary storage cannot be changed from within a transaction}} 122795b289b6Sdanielk1977do_test pragma-9.16 { 122895b289b6Sdanielk1977 execsql { 122995b289b6Sdanielk1977 SELECT * FROM temp_table; 123095b289b6Sdanielk1977 COMMIT; 123195b289b6Sdanielk1977 } 123295b289b6Sdanielk1977} {{valuable data}} 1233983e2309Sdanielk1977 1234983e2309Sdanielk1977do_test pragma-9.17 { 1235983e2309Sdanielk1977 execsql { 1236983e2309Sdanielk1977 INSERT INTO temp_table VALUES('valuable data II'); 1237983e2309Sdanielk1977 SELECT * FROM temp_table; 1238983e2309Sdanielk1977 } 1239983e2309Sdanielk1977} {{valuable data} {valuable data II}} 1240983e2309Sdanielk1977 1241983e2309Sdanielk1977do_test pragma-9.18 { 1242983e2309Sdanielk1977 set rc [catch { 1243983e2309Sdanielk1977 db eval {SELECT t FROM temp_table} { 1244983e2309Sdanielk1977 execsql {pragma temp_store = 1} 1245983e2309Sdanielk1977 } 1246983e2309Sdanielk1977 } msg] 1247983e2309Sdanielk1977 list $rc $msg 1248983e2309Sdanielk1977} {1 {temporary storage cannot be changed from within a transaction}} 1249983e2309Sdanielk1977 1250268283bcSdrh} ;# ifcapable pager_pragmas 12519a09a3caStpoindex 1252cc6bd383Sdanielk1977ifcapable trigger { 1253cc6bd383Sdanielk1977 1254cc6bd383Sdanielk1977do_test pragma-10.0 { 1255cc6bd383Sdanielk1977 catchsql { 1256cc6bd383Sdanielk1977 DROP TABLE main.t1; 1257cc6bd383Sdanielk1977 } 1258cc6bd383Sdanielk1977 execsql { 1259cc6bd383Sdanielk1977 PRAGMA count_changes = 1; 1260cc6bd383Sdanielk1977 1261cc6bd383Sdanielk1977 CREATE TABLE t1(a PRIMARY KEY); 1262cc6bd383Sdanielk1977 CREATE TABLE t1_mirror(a); 1263cc6bd383Sdanielk1977 CREATE TABLE t1_mirror2(a); 1264cc6bd383Sdanielk1977 CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN 1265cc6bd383Sdanielk1977 INSERT INTO t1_mirror VALUES(new.a); 1266cc6bd383Sdanielk1977 END; 1267cc6bd383Sdanielk1977 CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN 1268cc6bd383Sdanielk1977 INSERT INTO t1_mirror2 VALUES(new.a); 1269cc6bd383Sdanielk1977 END; 1270cc6bd383Sdanielk1977 CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN 1271cc6bd383Sdanielk1977 UPDATE t1_mirror SET a = new.a WHERE a = old.a; 1272cc6bd383Sdanielk1977 END; 1273cc6bd383Sdanielk1977 CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN 1274cc6bd383Sdanielk1977 UPDATE t1_mirror2 SET a = new.a WHERE a = old.a; 1275cc6bd383Sdanielk1977 END; 1276cc6bd383Sdanielk1977 CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN 1277cc6bd383Sdanielk1977 DELETE FROM t1_mirror WHERE a = old.a; 1278cc6bd383Sdanielk1977 END; 1279cc6bd383Sdanielk1977 CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN 1280cc6bd383Sdanielk1977 DELETE FROM t1_mirror2 WHERE a = old.a; 1281cc6bd383Sdanielk1977 END; 1282cc6bd383Sdanielk1977 } 1283cc6bd383Sdanielk1977} {} 1284cc6bd383Sdanielk1977 1285cc6bd383Sdanielk1977do_test pragma-10.1 { 1286cc6bd383Sdanielk1977 execsql { 1287cc6bd383Sdanielk1977 INSERT INTO t1 VALUES(randstr(10,10)); 1288cc6bd383Sdanielk1977 } 1289cc6bd383Sdanielk1977} {1} 1290cc6bd383Sdanielk1977do_test pragma-10.2 { 1291cc6bd383Sdanielk1977 execsql { 1292cc6bd383Sdanielk1977 UPDATE t1 SET a = randstr(10,10); 1293cc6bd383Sdanielk1977 } 1294cc6bd383Sdanielk1977} {1} 1295cc6bd383Sdanielk1977do_test pragma-10.3 { 1296cc6bd383Sdanielk1977 execsql { 1297cc6bd383Sdanielk1977 DELETE FROM t1; 1298cc6bd383Sdanielk1977 } 1299cc6bd383Sdanielk1977} {1} 1300cc6bd383Sdanielk1977 1301cc6bd383Sdanielk1977} ;# ifcapable trigger 1302cc6bd383Sdanielk1977 130348af65aeSdanielk1977ifcapable schema_pragmas { 130448af65aeSdanielk1977 do_test pragma-11.1 { 130548af65aeSdanielk1977 execsql2 { 130648af65aeSdanielk1977 pragma collation_list; 130748af65aeSdanielk1977 } 13082d823315Sdrh } {seq 0 name RTRIM seq 1 name NOCASE seq 2 name BINARY} 130948af65aeSdanielk1977 do_test pragma-11.2 { 131048af65aeSdanielk1977 db collate New_Collation blah... 131148af65aeSdanielk1977 execsql { 131248af65aeSdanielk1977 pragma collation_list; 131348af65aeSdanielk1977 } 13142d823315Sdrh } {0 New_Collation 1 RTRIM 2 NOCASE 3 BINARY} 131548af65aeSdanielk1977} 131648af65aeSdanielk1977 1317ddfb2f03Sdanielk1977ifcapable schema_pragmas&&tempdb { 1318ddfb2f03Sdanielk1977 do_test pragma-12.1 { 1319ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1320ddfb2f03Sdanielk1977 execsql { 1321ddfb2f03Sdanielk1977 PRAGMA temp.table_info('abc'); 1322ddfb2f03Sdanielk1977 } db2 1323ddfb2f03Sdanielk1977 } {} 1324ddfb2f03Sdanielk1977 db2 close 1325ddfb2f03Sdanielk1977 1326ddfb2f03Sdanielk1977 do_test pragma-12.2 { 1327ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1328ddfb2f03Sdanielk1977 execsql { 1329ddfb2f03Sdanielk1977 PRAGMA temp.default_cache_size = 200; 1330ddfb2f03Sdanielk1977 PRAGMA temp.default_cache_size; 1331ddfb2f03Sdanielk1977 } db2 1332ddfb2f03Sdanielk1977 } {200} 1333ddfb2f03Sdanielk1977 db2 close 1334ddfb2f03Sdanielk1977 1335ddfb2f03Sdanielk1977 do_test pragma-12.3 { 1336ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1337ddfb2f03Sdanielk1977 execsql { 1338ddfb2f03Sdanielk1977 PRAGMA temp.cache_size = 400; 1339ddfb2f03Sdanielk1977 PRAGMA temp.cache_size; 1340ddfb2f03Sdanielk1977 } db2 1341ddfb2f03Sdanielk1977 } {400} 1342ddfb2f03Sdanielk1977 db2 close 1343ddfb2f03Sdanielk1977} 1344ddfb2f03Sdanielk1977 13454b2688abSdanielk1977ifcapable bloblit { 13464b2688abSdanielk1977 134705a82983Sdrhdo_test pragma-13.1 { 134805a82983Sdrh execsql { 134905a82983Sdrh DROP TABLE IF EXISTS t4; 135005a82983Sdrh PRAGMA vdbe_trace=on; 135105a82983Sdrh PRAGMA vdbe_listing=on; 135205a82983Sdrh PRAGMA sql_trace=on; 135305a82983Sdrh CREATE TABLE t4(a INTEGER PRIMARY KEY,b); 135405a82983Sdrh INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789'); 135505a82983Sdrh INSERT INTO t4(b) VALUES(randstr(30,30)); 135605a82983Sdrh INSERT INTO t4(b) VALUES(1.23456); 135705a82983Sdrh INSERT INTO t4(b) VALUES(NULL); 135805a82983Sdrh INSERT INTO t4(b) VALUES(0); 135905a82983Sdrh INSERT INTO t4(b) SELECT b||b||b||b FROM t4; 136005a82983Sdrh SELECT * FROM t4; 136105a82983Sdrh } 136205a82983Sdrh execsql { 136305a82983Sdrh PRAGMA vdbe_trace=off; 136405a82983Sdrh PRAGMA vdbe_listing=off; 136505a82983Sdrh PRAGMA sql_trace=off; 136605a82983Sdrh } 136705a82983Sdrh} {} 136805a82983Sdrh 13694b2688abSdanielk1977} ;# ifcapable bloblit 13704b2688abSdanielk1977 137159a93791Sdanielk1977ifcapable pager_pragmas { 137259a93791Sdanielk1977 db close 1373fda06befSmistachkin forcedelete test.db 137459a93791Sdanielk1977 sqlite3 db test.db 137559a93791Sdanielk1977 137651a74d4cSdrh # EVIDENCE-OF: R-13905-26312 PRAGMA database.page_count; Return the 137751a74d4cSdrh # total number of pages in the database file. 137851a74d4cSdrh # 137959a93791Sdanielk1977 do_test pragma-14.1 { 138059a93791Sdanielk1977 execsql { pragma auto_vacuum = 0 } 138151a74d4cSdrh execsql { pragma page_count; pragma main.page_count } 138251a74d4cSdrh } {0 0} 138359a93791Sdanielk1977 138459a93791Sdanielk1977 do_test pragma-14.2 { 138559a93791Sdanielk1977 execsql { 138659a93791Sdanielk1977 CREATE TABLE abc(a, b, c); 138759a93791Sdanielk1977 PRAGMA page_count; 138851a74d4cSdrh PRAGMA main.page_count; 138951a74d4cSdrh PRAGMA temp.page_count; 139059a93791Sdanielk1977 } 139151a74d4cSdrh } {2 2 0} 13925d16a9a6Sdrh do_test pragma-14.2uc { 13935d16a9a6Sdrh execsql {pragma PAGE_COUNT} 13945d16a9a6Sdrh } {2} 139559a93791Sdanielk1977 139659a93791Sdanielk1977 do_test pragma-14.3 { 139759a93791Sdanielk1977 execsql { 139859a93791Sdanielk1977 BEGIN; 139959a93791Sdanielk1977 CREATE TABLE def(a, b, c); 140059a93791Sdanielk1977 PRAGMA page_count; 140159a93791Sdanielk1977 } 140259a93791Sdanielk1977 } {3} 14035d16a9a6Sdrh do_test pragma-14.3uc { 14045d16a9a6Sdrh execsql {pragma PAGE_COUNT} 14055d16a9a6Sdrh } {3} 140659a93791Sdanielk1977 140759a93791Sdanielk1977 do_test pragma-14.4 { 140859a93791Sdanielk1977 set page_size [db one {pragma page_size}] 140959a93791Sdanielk1977 expr [file size test.db] / $page_size 141059a93791Sdanielk1977 } {2} 141159a93791Sdanielk1977 141259a93791Sdanielk1977 do_test pragma-14.5 { 141359a93791Sdanielk1977 execsql { 141459a93791Sdanielk1977 ROLLBACK; 141559a93791Sdanielk1977 PRAGMA page_count; 141659a93791Sdanielk1977 } 141759a93791Sdanielk1977 } {2} 141859a93791Sdanielk1977 141959a93791Sdanielk1977 do_test pragma-14.6 { 1420fda06befSmistachkin forcedelete test2.db 142159a93791Sdanielk1977 sqlite3 db2 test2.db 142259a93791Sdanielk1977 execsql { 142359a93791Sdanielk1977 PRAGMA auto_vacuum = 0; 142459a93791Sdanielk1977 CREATE TABLE t1(a, b, c); 142559a93791Sdanielk1977 CREATE TABLE t2(a, b, c); 142659a93791Sdanielk1977 CREATE TABLE t3(a, b, c); 142759a93791Sdanielk1977 CREATE TABLE t4(a, b, c); 142859a93791Sdanielk1977 } db2 142959a93791Sdanielk1977 db2 close 143059a93791Sdanielk1977 execsql { 143159a93791Sdanielk1977 ATTACH 'test2.db' AS aux; 143259a93791Sdanielk1977 PRAGMA aux.page_count; 143359a93791Sdanielk1977 } 143459a93791Sdanielk1977 } {5} 14355d16a9a6Sdrh do_test pragma-14.6uc { 14365d16a9a6Sdrh execsql {pragma AUX.PAGE_COUNT} 14375d16a9a6Sdrh } {5} 143859a93791Sdanielk1977} 143959a93791Sdanielk1977 14408cf6c554Sdanielk1977# Test that the value set using the cache_size pragma is not reset when the 14418cf6c554Sdanielk1977# schema is reloaded. 14428cf6c554Sdanielk1977# 14438cf6c554Sdanielk1977ifcapable pager_pragmas { 14448cf6c554Sdanielk1977 db close 14458cf6c554Sdanielk1977 sqlite3 db test.db 14468cf6c554Sdanielk1977 do_test pragma-15.1 { 14478cf6c554Sdanielk1977 execsql { 14488cf6c554Sdanielk1977 PRAGMA cache_size=59; 14498cf6c554Sdanielk1977 PRAGMA cache_size; 14508cf6c554Sdanielk1977 } 14518cf6c554Sdanielk1977 } {59} 14528cf6c554Sdanielk1977 do_test pragma-15.2 { 14538cf6c554Sdanielk1977 sqlite3 db2 test.db 14548cf6c554Sdanielk1977 execsql { 14558cf6c554Sdanielk1977 CREATE TABLE newtable(a, b, c); 14568cf6c554Sdanielk1977 } db2 14578cf6c554Sdanielk1977 db2 close 14588cf6c554Sdanielk1977 } {} 14598cf6c554Sdanielk1977 do_test pragma-15.3 { 14608cf6c554Sdanielk1977 # Evaluating this statement will cause the schema to be reloaded (because 14618cf6c554Sdanielk1977 # the schema was changed by another connection in pragma-15.2). At one 14628cf6c554Sdanielk1977 # point there was a bug that reset the cache_size to its default value 14638cf6c554Sdanielk1977 # when this happened. 14648cf6c554Sdanielk1977 execsql { SELECT * FROM sqlite_master } 14658cf6c554Sdanielk1977 execsql { PRAGMA cache_size } 14668cf6c554Sdanielk1977 } {59} 14678cf6c554Sdanielk1977} 14688cf6c554Sdanielk1977 14695558a8a6Sdanielk1977# Reset the sqlite3_temp_directory variable for the next run of tests: 14705558a8a6Sdanielk1977sqlite3 dbX :memory: 14715558a8a6Sdanielk1977dbX eval {PRAGMA temp_store_directory = ""} 14725558a8a6Sdanielk1977dbX close 14735558a8a6Sdanielk1977 1474838cce43Sdanielk1977ifcapable lock_proxy_pragmas&&prefer_proxy_locking { 1475aebf413dSaswift set sqlite_hostid_num 1 1476aebf413dSaswift 1477aebf413dSaswift set using_proxy 0 1478aebf413dSaswift foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] { 1479aebf413dSaswift set using_proxy $value 1480aebf413dSaswift } 1481aebf413dSaswift 1482aebf413dSaswift # Test the lock_proxy_file pragmas. 1483aebf413dSaswift # 1484aebf413dSaswift db close 1485aebf413dSaswift set env(SQLITE_FORCE_PROXY_LOCKING) "0" 1486aebf413dSaswift 1487aebf413dSaswift sqlite3 db test.db 1488aebf413dSaswift do_test pragma-16.1 { 1489aebf413dSaswift execsql { 1490aebf413dSaswift PRAGMA lock_proxy_file="mylittleproxy"; 1491aebf413dSaswift select * from sqlite_master; 1492aebf413dSaswift } 1493aebf413dSaswift execsql { 1494aebf413dSaswift PRAGMA lock_proxy_file; 1495aebf413dSaswift } 1496aebf413dSaswift } {mylittleproxy} 1497aebf413dSaswift 1498aebf413dSaswift do_test pragma-16.2 { 1499aebf413dSaswift sqlite3 db2 test.db 1500aebf413dSaswift execsql { 1501aebf413dSaswift PRAGMA lock_proxy_file="mylittleproxy"; 1502aebf413dSaswift } db2 1503aebf413dSaswift } {} 1504aebf413dSaswift 1505aebf413dSaswift db2 close 1506aebf413dSaswift do_test pragma-16.2.1 { 1507aebf413dSaswift sqlite3 db2 test.db 1508aebf413dSaswift execsql { 1509aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1510aebf413dSaswift select * from sqlite_master; 1511aebf413dSaswift } db2 1512aebf413dSaswift execsql { 1513aebf413dSaswift PRAGMA lock_proxy_file; 1514aebf413dSaswift } db2 1515aebf413dSaswift } {mylittleproxy} 1516aebf413dSaswift 1517aebf413dSaswift db2 close 1518aebf413dSaswift do_test pragma-16.3 { 1519aebf413dSaswift sqlite3 db2 test.db 1520aebf413dSaswift execsql { 1521aebf413dSaswift PRAGMA lock_proxy_file="myotherproxy"; 1522aebf413dSaswift } db2 1523aebf413dSaswift catchsql { 1524aebf413dSaswift select * from sqlite_master; 1525aebf413dSaswift } db2 1526aebf413dSaswift } {1 {database is locked}} 1527aebf413dSaswift 1528aebf413dSaswift do_test pragma-16.4 { 1529aebf413dSaswift db2 close 1530aebf413dSaswift db close 1531aebf413dSaswift sqlite3 db2 test.db 1532aebf413dSaswift execsql { 1533aebf413dSaswift PRAGMA lock_proxy_file="myoriginalproxy"; 1534aebf413dSaswift PRAGMA lock_proxy_file="myotherproxy"; 1535aebf413dSaswift PRAGMA lock_proxy_file; 1536aebf413dSaswift } db2 1537aebf413dSaswift } {myotherproxy} 1538aebf413dSaswift 1539aebf413dSaswift db2 close 1540aebf413dSaswift set env(SQLITE_FORCE_PROXY_LOCKING) "1" 1541aebf413dSaswift do_test pragma-16.5 { 1542aebf413dSaswift sqlite3 db2 test.db 1543aebf413dSaswift execsql { 1544aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1545aebf413dSaswift PRAGMA lock_proxy_file; 1546aebf413dSaswift } db2 1547aebf413dSaswift } {myotherproxy} 1548aebf413dSaswift 1549aebf413dSaswift do_test pragma-16.6 { 1550aebf413dSaswift db2 close 1551aebf413dSaswift sqlite3 db2 test2.db 1552aebf413dSaswift set lockpath [execsql { 1553aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1554aebf413dSaswift PRAGMA lock_proxy_file; 1555aebf413dSaswift } db2] 1556aebf413dSaswift string match "*test2.db:auto:" $lockpath 1557aebf413dSaswift } {1} 1558aebf413dSaswift 1559aebf413dSaswift set sqlite_hostid_num 2 1560aebf413dSaswift do_test pragma-16.7 { 156114d14607Sdan list [catch { 1562aebf413dSaswift sqlite3 db test2.db 1563aebf413dSaswift execsql { 1564aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1565aebf413dSaswift select * from sqlite_master; 1566aebf413dSaswift } 156714d14607Sdan } msg] $msg 1568aebf413dSaswift } {1 {database is locked}} 1569aebf413dSaswift db close 1570aebf413dSaswift 1571aebf413dSaswift do_test pragma-16.8 { 157214d14607Sdan list [catch { 1573aebf413dSaswift sqlite3 db test2.db 157414d14607Sdan execsql { select * from sqlite_master } 157514d14607Sdan } msg] $msg 1576aebf413dSaswift } {1 {database is locked}} 1577aebf413dSaswift 1578aebf413dSaswift db2 close 1579aebf413dSaswift do_test pragma-16.8.1 { 1580aebf413dSaswift execsql { 1581aebf413dSaswift PRAGMA lock_proxy_file="yetanotherproxy"; 1582aebf413dSaswift PRAGMA lock_proxy_file; 1583aebf413dSaswift } 1584aebf413dSaswift } {yetanotherproxy} 1585aebf413dSaswift do_test pragma-16.8.2 { 1586aebf413dSaswift execsql { 1587aebf413dSaswift create table mine(x); 1588aebf413dSaswift } 1589aebf413dSaswift } {} 1590aebf413dSaswift 1591aebf413dSaswift db close 1592aebf413dSaswift do_test pragma-16.9 { 1593aebf413dSaswift sqlite3 db proxytest.db 1594aebf413dSaswift set lockpath2 [execsql { 1595aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1596aebf413dSaswift PRAGMA lock_proxy_file; 1597aebf413dSaswift } db] 1598aebf413dSaswift string match "*proxytest.db:auto:" $lockpath2 1599aebf413dSaswift } {1} 1600aebf413dSaswift 1601aebf413dSaswift set env(SQLITE_FORCE_PROXY_LOCKING) $using_proxy 1602aebf413dSaswift set sqlite_hostid_num 0 1603aebf413dSaswift} 1604d2cb50b7Sdrh 1605d2cb50b7Sdrh# Parsing of auto_vacuum settings. 1606d2cb50b7Sdrh# 1607d2cb50b7Sdrhforeach {autovac_setting val} { 1608d2cb50b7Sdrh 0 0 1609d2cb50b7Sdrh 1 1 1610d2cb50b7Sdrh 2 2 1611d2cb50b7Sdrh 3 0 1612d2cb50b7Sdrh -1 0 1613d2cb50b7Sdrh none 0 1614d2cb50b7Sdrh NONE 0 1615d2cb50b7Sdrh NoNe 0 1616d2cb50b7Sdrh full 1 1617d2cb50b7Sdrh FULL 1 1618d2cb50b7Sdrh incremental 2 1619d2cb50b7Sdrh INCREMENTAL 2 1620d2cb50b7Sdrh -1234 0 1621d2cb50b7Sdrh 1234 0 1622d2cb50b7Sdrh} { 1623d2cb50b7Sdrh do_test pragma-17.1.$autovac_setting { 1624d2cb50b7Sdrh catch {db close} 1625d2cb50b7Sdrh sqlite3 db :memory: 1626d2cb50b7Sdrh execsql " 1627d2cb50b7Sdrh PRAGMA auto_vacuum=$::autovac_setting; 1628d2cb50b7Sdrh PRAGMA auto_vacuum; 1629d2cb50b7Sdrh " 1630d2cb50b7Sdrh } $val 1631d2cb50b7Sdrh} 1632d2cb50b7Sdrh 1633d2cb50b7Sdrh# Parsing of temp_store settings. 1634d2cb50b7Sdrh# 1635d2cb50b7Sdrhforeach {temp_setting val} { 1636d2cb50b7Sdrh 0 0 1637d2cb50b7Sdrh 1 1 1638d2cb50b7Sdrh 2 2 1639d2cb50b7Sdrh 3 0 1640d2cb50b7Sdrh -1 0 1641d2cb50b7Sdrh file 1 1642d2cb50b7Sdrh FILE 1 1643d2cb50b7Sdrh fIlE 1 1644d2cb50b7Sdrh memory 2 1645d2cb50b7Sdrh MEMORY 2 1646d2cb50b7Sdrh MeMoRy 2 1647d2cb50b7Sdrh} { 1648d2cb50b7Sdrh do_test pragma-18.1.$temp_setting { 1649d2cb50b7Sdrh catch {db close} 1650d2cb50b7Sdrh sqlite3 db :memory: 1651d2cb50b7Sdrh execsql " 1652d2cb50b7Sdrh PRAGMA temp_store=$::temp_setting; 1653d2cb50b7Sdrh PRAGMA temp_store=$::temp_setting; 1654d2cb50b7Sdrh PRAGMA temp_store; 1655d2cb50b7Sdrh " 1656d2cb50b7Sdrh } $val 1657d2cb50b7Sdrh} 1658d2cb50b7Sdrh 165992c700dbSdrh# The SQLITE_FCNTL_PRAGMA logic, with error handling. 166092c700dbSdrh# 166192c700dbSdrhdb close 166292c700dbSdrhtestvfs tvfs 166392c700dbSdrhsqlite3 db test.db -vfs tvfs 166492c700dbSdrhdo_test pragma-19.1 { 166592c700dbSdrh catchsql {PRAGMA error} 166692c700dbSdrh} {1 {SQL logic error or missing database}} 166792c700dbSdrhdo_test pragma-19.2 { 166892c700dbSdrh catchsql {PRAGMA error='This is the error message'} 166992c700dbSdrh} {1 {This is the error message}} 167092c700dbSdrhdo_test pragma-19.3 { 167192c700dbSdrh catchsql {PRAGMA error='7 This is the error message'} 167292c700dbSdrh} {1 {This is the error message}} 167392c700dbSdrhdo_test pragma-19.4 { 167492c700dbSdrh catchsql {PRAGMA error=7} 167592c700dbSdrh} {1 {out of memory}} 1676c8517f61Sdrhdo_test pragma-19.5 { 16775b044545Smistachkin file tail [lindex [execsql {PRAGMA filename}] 0] 1678c8517f61Sdrh} {test.db} 167992c700dbSdrh 1680cc71645bSdrhif {$tcl_platform(platform)=="windows"} { 1681a112d140Smistachkin# Test data_store_directory pragma 1682a112d140Smistachkin# 1683a112d140Smistachkindb close 1684a112d140Smistachkinsqlite3 db test.db 1685a112d140Smistachkinfile mkdir data_dir 1686a112d140Smistachkindo_test pragma-20.1 { 1687a112d140Smistachkin catchsql {PRAGMA data_store_directory} 1688a112d140Smistachkin} {0 {}} 1689a112d140Smistachkindo_test pragma-20.2 { 1690a112d140Smistachkin set pwd [string map {' ''} [file nativename [get_pwd]]] 1691a112d140Smistachkin catchsql "PRAGMA data_store_directory='$pwd';" 1692a112d140Smistachkin} {0 {}} 1693a112d140Smistachkindo_test pragma-20.3 { 1694a112d140Smistachkin catchsql {PRAGMA data_store_directory} 1695a112d140Smistachkin} [list 0 [list [file nativename [get_pwd]]]] 1696a112d140Smistachkindo_test pragma-20.4 { 1697a112d140Smistachkin set pwd [string map {' ''} [file nativename \ 1698a112d140Smistachkin [file join [get_pwd] data_dir]]] 1699a112d140Smistachkin catchsql "PRAGMA data_store_directory='$pwd';" 1700a112d140Smistachkin} {0 {}} 1701a112d140Smistachkindo_test pragma-20.5 { 1702a112d140Smistachkin sqlite3 db2 test2.db 1703a112d140Smistachkin catchsql "PRAGMA database_list;" db2 1704a112d140Smistachkin} [list 0 [list 0 main [file nativename \ 1705a112d140Smistachkin [file join [get_pwd] data_dir test2.db]]]] 1706a112d140Smistachkincatch {db2 close} 1707a112d140Smistachkindo_test pragma-20.6 { 1708a112d140Smistachkin sqlite3 db2 [file join [get_pwd] test2.db] 1709a112d140Smistachkin catchsql "PRAGMA database_list;" db2 1710a112d140Smistachkin} [list 0 [list 0 main [file nativename \ 1711a112d140Smistachkin [file join [get_pwd] test2.db]]]] 1712a112d140Smistachkincatch {db2 close} 1713a112d140Smistachkindo_test pragma-20.7 { 1714a112d140Smistachkin catchsql "PRAGMA data_store_directory='';" 1715a112d140Smistachkin} {0 {}} 1716a112d140Smistachkindo_test pragma-20.8 { 1717a112d140Smistachkin catchsql {PRAGMA data_store_directory} 1718a112d140Smistachkin} {0 {}} 171992c700dbSdrh 1720a112d140Smistachkinforcedelete data_dir 1721cc71645bSdrh} ;# endif windows 1722cd61c281Sdrh 17231fed5dabSdandatabase_may_be_corrupt 17241fed5dabSdan 17255885e762Sdando_test 21.1 { 17265885e762Sdan # Create a corrupt database in testerr.db. And a non-corrupt at test.db. 17275885e762Sdan # 17285885e762Sdan db close 17295885e762Sdan forcedelete test.db 17305885e762Sdan sqlite3 db test.db 17315885e762Sdan execsql { 17325885e762Sdan PRAGMA page_size = 1024; 17335885e762Sdan PRAGMA auto_vacuum = 0; 17345885e762Sdan CREATE TABLE t1(a PRIMARY KEY, b); 17355885e762Sdan INSERT INTO t1 VALUES(1, 1); 17365885e762Sdan } 17375885e762Sdan for {set i 0} {$i < 10} {incr i} { 17385885e762Sdan execsql { INSERT INTO t1 SELECT a + (1 << $i), b + (1 << $i) FROM t1 } 17395885e762Sdan } 17405885e762Sdan db close 17415885e762Sdan forcecopy test.db testerr.db 17425885e762Sdan hexio_write testerr.db 15000 [string repeat 55 100] 17435885e762Sdan} {100} 17445885e762Sdan 17455885e762Sdanset mainerr {*** in database main *** 17465885e762SdanMultiple uses for byte 672 of page 15} 17475885e762Sdanset auxerr {*** in database aux *** 17485885e762SdanMultiple uses for byte 672 of page 15} 17495885e762Sdan 1750597515d7Sdanset mainerr {/{\*\*\* in database main \*\*\* 1751597515d7SdanMultiple uses for byte 672 of page 15}.*/} 1752597515d7Sdanset auxerr {/{\*\*\* in database aux \*\*\* 1753597515d7SdanMultiple uses for byte 672 of page 15}.*/} 1754597515d7Sdan 17555885e762Sdando_test 22.2 { 17565885e762Sdan catch { db close } 17575885e762Sdan sqlite3 db testerr.db 17585885e762Sdan execsql { PRAGMA integrity_check } 1759597515d7Sdan} $mainerr 17605885e762Sdan 17615885e762Sdando_test 22.3.1 { 17625885e762Sdan catch { db close } 17635885e762Sdan sqlite3 db test.db 17645885e762Sdan execsql { 17655885e762Sdan ATTACH 'testerr.db' AS 'aux'; 17665885e762Sdan PRAGMA integrity_check; 17675885e762Sdan } 1768597515d7Sdan} $auxerr 17695885e762Sdando_test 22.3.2 { 17705885e762Sdan execsql { PRAGMA main.integrity_check; } 17715885e762Sdan} {ok} 17725885e762Sdando_test 22.3.3 { 17735885e762Sdan execsql { PRAGMA aux.integrity_check; } 1774597515d7Sdan} $auxerr 17755885e762Sdan 17765885e762Sdando_test 22.4.1 { 17775885e762Sdan catch { db close } 17785885e762Sdan sqlite3 db testerr.db 17795885e762Sdan execsql { 17805885e762Sdan ATTACH 'test.db' AS 'aux'; 17815885e762Sdan PRAGMA integrity_check; 17825885e762Sdan } 1783597515d7Sdan} $mainerr 17845885e762Sdando_test 22.4.2 { 17855885e762Sdan execsql { PRAGMA main.integrity_check; } 1786597515d7Sdan} $mainerr 17875885e762Sdando_test 22.4.3 { 17885885e762Sdan execsql { PRAGMA aux.integrity_check; } 17895885e762Sdan} {ok} 17905885e762Sdan 1791c95e01daSdrhdb close 1792c95e01daSdrhforcedelete test.db test.db-wal test.db-journal 1793c95e01daSdrhsqlite3 db test.db 1794c95e01daSdrhsqlite3 db2 test.db 1795c95e01daSdrhdo_test 23.1 { 1796c95e01daSdrh db eval { 1797c95e01daSdrh CREATE TABLE t1(a INTEGER PRIMARY KEY,b,c,d); 1798c95e01daSdrh CREATE INDEX i1 ON t1(b,c); 1799c95e01daSdrh CREATE INDEX i2 ON t1(c,d); 18007be0fd9cSdrh CREATE INDEX i2x ON t1(d COLLATE nocase, c DESC); 1801c95e01daSdrh CREATE TABLE t2(x INTEGER REFERENCES t1); 1802c95e01daSdrh } 1803c95e01daSdrh db2 eval {SELECT name FROM sqlite_master} 18047be0fd9cSdrh} {t1 i1 i2 i2x t2} 1805c228be5bSdrhdo_test 23.2a { 1806c95e01daSdrh db eval { 1807c95e01daSdrh DROP INDEX i2; 1808c95e01daSdrh CREATE INDEX i2 ON t1(c,d,b); 1809c95e01daSdrh } 1810c228be5bSdrh capture_pragma db2 out {PRAGMA index_info(i2)} 18115e7028c2Sdrh db2 eval {SELECT cid, name, '|' FROM out ORDER BY seqno} 18125e7028c2Sdrh} {2 c | 3 d | 1 b |} 18137be0fd9cSdrh 18147be0fd9cSdrh# EVIDENCE-OF: R-44874-46325 PRAGMA database.index_xinfo(index-name); 18157be0fd9cSdrh# This pragma returns information about every column in an index. 18167be0fd9cSdrh# 18177be0fd9cSdrh# EVIDENCE-OF: R-45970-35618 Unlike this index_info pragma, this pragma 18187be0fd9cSdrh# returns information about every column in the index, not just the key 18197be0fd9cSdrh# columns. 18207be0fd9cSdrh# 1821c228be5bSdrhdo_test 23.2b { 1822c228be5bSdrh capture_pragma db2 out {PRAGMA index_xinfo(i2)} 1823c228be5bSdrh db2 eval {SELECT cid, name, "desc", coll, "key", '|' FROM out ORDER BY seqno} 1824c228be5bSdrh} {2 c 0 BINARY 1 | 3 d 0 BINARY 1 | 1 b 0 BINARY 1 | -1 {} 0 BINARY 0 |} 18257be0fd9cSdrh 18267be0fd9cSdrh# (The first column of output from PRAGMA index_xinfo is...) 18277be0fd9cSdrh# EVIDENCE-OF: R-00197-14279 The rank of the column within the index. (0 18287be0fd9cSdrh# means left-most. Key columns come before auxiliary columns.) 18297be0fd9cSdrh# 18307be0fd9cSdrh# (The second column of output from PRAGMA index_xinfo is...) 18317be0fd9cSdrh# EVIDENCE-OF: R-40889-06838 The rank of the column within the table 18327be0fd9cSdrh# being indexed, or -1 if the index-column is the rowid of the table 18337be0fd9cSdrh# being indexed. 18347be0fd9cSdrh# 18357be0fd9cSdrh# (The third column of output from PRAGMA index_xinfo is...) 18367be0fd9cSdrh# EVIDENCE-OF: R-22751-28901 The name of the column being indexed, or 18377be0fd9cSdrh# NULL if the index-column is the rowid of the table being indexed. 18387be0fd9cSdrh# 18397be0fd9cSdrh# (The fourth column of output from PRAGMA index_xinfo is...) 18407be0fd9cSdrh# EVIDENCE-OF: R-11847-09179 1 if the index-column is sorted in reverse 18417be0fd9cSdrh# (DESC) order by the index and 0 otherwise. 18427be0fd9cSdrh# 18437be0fd9cSdrh# (The fifth column of output from PRAGMA index_xinfo is...) 18447be0fd9cSdrh# EVIDENCE-OF: R-15313-19540 The name for the collating sequence used to 18457be0fd9cSdrh# compare values in the index-column. 18467be0fd9cSdrh# 18477be0fd9cSdrh# (The sixth column of output from PRAGMA index_xinfo is...) 18487be0fd9cSdrh# EVIDENCE-OF: R-14310-64553 1 if the index-column is a key column and 0 18497be0fd9cSdrh# if the index-column is an auxiliary column. 18507be0fd9cSdrh# 18517be0fd9cSdrhdo_test 23.2c { 18527be0fd9cSdrh db2 eval {PRAGMA index_xinfo(i2)} 18537be0fd9cSdrh} {0 2 c 0 BINARY 1 1 3 d 0 BINARY 1 2 1 b 0 BINARY 1 3 -1 {} 0 BINARY 0} 18547be0fd9cSdrhdo_test 23.2d { 18557be0fd9cSdrh db2 eval {PRAGMA index_xinfo(i2x)} 18567be0fd9cSdrh} {0 3 d 0 nocase 1 1 2 c 1 BINARY 1 2 -1 {} 0 BINARY 0} 18577be0fd9cSdrh 18587be0fd9cSdrh# EVIDENCE-OF: R-63500-32024 PRAGMA database.index_list(table-name); 18597be0fd9cSdrh# This pragma returns one row for each index associated with the given 18607be0fd9cSdrh# table. 18617be0fd9cSdrh# 18627be0fd9cSdrh# (The first column of output from PRAGMA index_list is...) 18637be0fd9cSdrh# EVIDENCE-OF: R-02753-24748 A sequence number assigned to each index 18647be0fd9cSdrh# for internal tracking purposes. 18657be0fd9cSdrh# 18667be0fd9cSdrh# (The second column of output from PRAGMA index_list is...) 18677be0fd9cSdrh# EVIDENCE-OF: R-35496-03635 The name of the index. 18687be0fd9cSdrh# 18697be0fd9cSdrh# (The third column of output from PRAGMA index_list is...) 18707be0fd9cSdrh# EVIDENCE-OF: R-57301-64506 "1" if the index is UNIQUE and "0" if not. 18717be0fd9cSdrh# 18727be0fd9cSdrh# (The fourth column of output from PRAGMA index_list is...) 18737be0fd9cSdrh# EVIDENCE-OF: R-36609-39554 "c" if the index was created by a CREATE 18747be0fd9cSdrh# INDEX statement, "u" if the index was created by a UNIQUE constraint, 18757be0fd9cSdrh# or "pk" if the index was created by a PRIMARY KEY constraint. 18767be0fd9cSdrh# 1877c95e01daSdrhdo_test 23.3 { 1878c95e01daSdrh db eval { 1879c95e01daSdrh CREATE INDEX i3 ON t1(d,b,c); 1880c95e01daSdrh } 1881c228be5bSdrh capture_pragma db2 out {PRAGMA index_list(t1)} 18827be0fd9cSdrh db2 eval {SELECT seq, name, "unique", origin, '|' FROM out ORDER BY seq} 18837be0fd9cSdrh} {0 i3 0 c | 1 i2 0 c | 2 i2x 0 c | 3 i1 0 c |} 1884c95e01daSdrhdo_test 23.4 { 1885c95e01daSdrh db eval { 1886c95e01daSdrh ALTER TABLE t1 ADD COLUMN e; 1887c95e01daSdrh } 1888c95e01daSdrh db2 eval { 1889c95e01daSdrh PRAGMA table_info(t1); 1890c95e01daSdrh } 1891c95e01daSdrh} {/4 e {} 0 {} 0/} 1892c95e01daSdrhdo_test 23.5 { 1893c95e01daSdrh db eval { 1894c95e01daSdrh DROP TABLE t2; 1895c95e01daSdrh CREATE TABLE t2(x, y INTEGER REFERENCES t1); 1896c95e01daSdrh } 1897c95e01daSdrh db2 eval { 1898c95e01daSdrh PRAGMA foreign_key_list(t2); 1899c95e01daSdrh } 1900c95e01daSdrh} {0 0 t1 y {} {NO ACTION} {NO ACTION} NONE} 1901c95e01daSdrh 19021fed5dabSdandatabase_never_corrupt 1903cd61c281Sdrhfinish_test 1904