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 86b3366b99Sdrh# EVIDENCE-OF: R-13861-56665 PRAGMA schema.cache_size; PRAGMA 87b3366b99Sdrh# schema.cache_size = pages; PRAGMA schema.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} 1896841b1cbSdrhdo_test pragma-1.11.1 { 1906841b1cbSdrh execsql { 1916841b1cbSdrh PRAGMA synchronous=EXTRA; 1926841b1cbSdrh PRAGMA cache_size; 1936841b1cbSdrh PRAGMA default_cache_size; 1946841b1cbSdrh PRAGMA synchronous; 1956841b1cbSdrh } 1966841b1cbSdrh} {123 123 3} 1976841b1cbSdrhdo_test pragma-1.11.2 { 1984303feedSdrh execsql { 1994303feedSdrh PRAGMA synchronous=FULL; 2004303feedSdrh PRAGMA cache_size; 2014303feedSdrh PRAGMA default_cache_size; 2024303feedSdrh PRAGMA synchronous; 2034303feedSdrh } 20491cf71b0Sdanielk1977} {123 123 2} 20591cf71b0Sdanielk1977do_test pragma-1.12 { 2064303feedSdrh db close 207dddca286Sdrh sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db] 2084303feedSdrh execsql { 2094303feedSdrh PRAGMA cache_size; 2104303feedSdrh PRAGMA default_cache_size; 2114303feedSdrh PRAGMA synchronous; 2124303feedSdrh } 21391cf71b0Sdanielk1977} {123 123 2} 21491cf71b0Sdanielk1977 2155260f7e9Sdrh# Make sure the pragma handler understands numeric values in addition 2165260f7e9Sdrh# to keywords like "off" and "full". 2175260f7e9Sdrh# 2185260f7e9Sdrhdo_test pragma-1.13 { 2195260f7e9Sdrh execsql { 2205260f7e9Sdrh PRAGMA synchronous=0; 2215260f7e9Sdrh PRAGMA synchronous; 2225260f7e9Sdrh } 2235260f7e9Sdrh} {0} 2245260f7e9Sdrhdo_test pragma-1.14 { 2255260f7e9Sdrh execsql { 2265260f7e9Sdrh PRAGMA synchronous=2; 2275260f7e9Sdrh PRAGMA synchronous; 2285260f7e9Sdrh } 2295260f7e9Sdrh} {2} 23059ac655dSdrhdo_test pragma-1.14.1 { 23159ac655dSdrh execsql { 23259ac655dSdrh PRAGMA synchronous=4; 23359ac655dSdrh PRAGMA synchronous; 23459ac655dSdrh } 2356841b1cbSdrh} {4} 23659ac655dSdrhdo_test pragma-1.14.2 { 23759ac655dSdrh execsql { 238d99d2836Sdrh PRAGMA synchronous=3; 239d99d2836Sdrh PRAGMA synchronous; 240d99d2836Sdrh } 2416841b1cbSdrh} {3} 242d99d2836Sdrhdo_test pragma-1.14.3 { 243d99d2836Sdrh execsql { 2446841b1cbSdrh PRAGMA synchronous=8; 2456841b1cbSdrh PRAGMA synchronous; 2466841b1cbSdrh } 2476841b1cbSdrh} {0} 2486841b1cbSdrhdo_test pragma-1.14.4 { 2496841b1cbSdrh execsql { 25059ac655dSdrh PRAGMA synchronous=10; 25159ac655dSdrh PRAGMA synchronous; 25259ac655dSdrh } 25359ac655dSdrh} {2} 254b84b38fdSdan 255b84b38fdSdando_execsql_test 1.15.1 { 256b84b38fdSdan PRAGMA default_cache_size = 0; 257b84b38fdSdan} 258b84b38fdSdando_execsql_test 1.15.2 { 259b84b38fdSdan PRAGMA default_cache_size; 260b84b38fdSdan} $DFLT_CACHE_SZ 261b84b38fdSdando_execsql_test 1.15.3 { 262b84b38fdSdan PRAGMA default_cache_size = -500; 263b84b38fdSdan} 264b84b38fdSdando_execsql_test 1.15.4 { 265b84b38fdSdan PRAGMA default_cache_size; 266b84b38fdSdan} 500 267b84b38fdSdando_execsql_test 1.15.3 { 268b84b38fdSdan PRAGMA default_cache_size = 500; 269b84b38fdSdan} 270b84b38fdSdando_execsql_test 1.15.4 { 271b84b38fdSdan PRAGMA default_cache_size; 272b84b38fdSdan} 500 273b84b38fdSdandb close 274b84b38fdSdanhexio_write test.db 48 FFFFFF00 275b84b38fdSdansqlite3 db test.db 276b84b38fdSdando_execsql_test 1.15.4 { 277b84b38fdSdan PRAGMA default_cache_size; 278b84b38fdSdan} 256 279c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 2805260f7e9Sdrh 2815260f7e9Sdrh# Test turning "flag" pragmas on and off. 2825260f7e9Sdrh# 2836338c762Sdanielk1977ifcapable debug { 2846338c762Sdanielk1977 # Pragma "vdbe_listing" is only available if compiled with SQLITE_DEBUG 2856338c762Sdanielk1977 # 2865260f7e9Sdrh do_test pragma-1.15 { 2875260f7e9Sdrh execsql { 2885260f7e9Sdrh PRAGMA vdbe_listing=YES; 2895260f7e9Sdrh PRAGMA vdbe_listing; 2905260f7e9Sdrh } 2915260f7e9Sdrh } {1} 2925260f7e9Sdrh do_test pragma-1.16 { 2935260f7e9Sdrh execsql { 2945260f7e9Sdrh PRAGMA vdbe_listing=NO; 2955260f7e9Sdrh PRAGMA vdbe_listing; 2965260f7e9Sdrh } 2975260f7e9Sdrh } {0} 2986338c762Sdanielk1977} 2996338c762Sdanielk1977 3005260f7e9Sdrhdo_test pragma-1.17 { 3015260f7e9Sdrh execsql { 3025260f7e9Sdrh PRAGMA parser_trace=ON; 3035260f7e9Sdrh PRAGMA parser_trace=OFF; 3045260f7e9Sdrh } 3055260f7e9Sdrh} {} 3065260f7e9Sdrhdo_test pragma-1.18 { 3075260f7e9Sdrh execsql { 3085260f7e9Sdrh PRAGMA bogus = -1234; -- Parsing of negative values 3095260f7e9Sdrh } 3105260f7e9Sdrh} {} 3115260f7e9Sdrh 31291cf71b0Sdanielk1977# Test modifying the safety_level of an attached database. 3135a8f9374Sdanielk1977ifcapable pager_pragmas&&attach { 31491cf71b0Sdanielk1977 do_test pragma-2.1 { 315fda06befSmistachkin forcedelete test2.db 316fda06befSmistachkin forcedelete test2.db-journal 3174303feedSdrh execsql { 31891cf71b0Sdanielk1977 ATTACH 'test2.db' AS aux; 3194303feedSdrh } 32091cf71b0Sdanielk1977 } {} 32191cf71b0Sdanielk1977 do_test pragma-2.2 { 3224303feedSdrh execsql { 32391cf71b0Sdanielk1977 pragma aux.synchronous; 3244303feedSdrh } 32591cf71b0Sdanielk1977 } {2} 32691cf71b0Sdanielk1977 do_test pragma-2.3 { 32791cf71b0Sdanielk1977 execsql { 32891cf71b0Sdanielk1977 pragma aux.synchronous = OFF; 32991cf71b0Sdanielk1977 pragma aux.synchronous; 33091cf71b0Sdanielk1977 pragma synchronous; 33191cf71b0Sdanielk1977 } 33291cf71b0Sdanielk1977 } {0 2} 33391cf71b0Sdanielk1977 do_test pragma-2.4 { 33491cf71b0Sdanielk1977 execsql { 33591cf71b0Sdanielk1977 pragma aux.synchronous = ON; 33691cf71b0Sdanielk1977 pragma synchronous; 33791cf71b0Sdanielk1977 pragma aux.synchronous; 33891cf71b0Sdanielk1977 } 33991cf71b0Sdanielk1977 } {2 1} 340c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 3414303feedSdrh 342ed717fe3Sdrh# Construct a corrupted index and make sure the integrity_check 343ed717fe3Sdrh# pragma finds it. 344ed717fe3Sdrh# 34525d6543dSdrh# These tests won't work if the database is encrypted 34625d6543dSdrh# 347ed717fe3Sdrhdo_test pragma-3.1 { 3481e9daa6aSdrh db close 349fda06befSmistachkin forcedelete test.db test.db-journal 3501e9daa6aSdrh sqlite3 db test.db 351ed717fe3Sdrh execsql { 3521e9daa6aSdrh PRAGMA auto_vacuum=OFF; 353ed717fe3Sdrh BEGIN; 354ed717fe3Sdrh CREATE TABLE t2(a,b,c); 355ed717fe3Sdrh CREATE INDEX i2 ON t2(a); 356ed717fe3Sdrh INSERT INTO t2 VALUES(11,2,3); 357ed717fe3Sdrh INSERT INTO t2 VALUES(22,3,4); 358ed717fe3Sdrh COMMIT; 359ed717fe3Sdrh SELECT rowid, * from t2; 360ed717fe3Sdrh } 361ed717fe3Sdrh} {1 11 2 3 2 22 3 4} 3625a8f9374Sdanielk1977ifcapable attach { 36340e016e4Sdrh if {![sqlite3 -has-codec] && $sqlite_options(integrityck)} { 364ed717fe3Sdrh do_test pragma-3.2 { 365bb8a279eSdrh db eval {SELECT rootpage FROM sqlite_master WHERE name='i2'} break 366bb8a279eSdrh set pgsz [db eval {PRAGMA page_size}] 367bb8a279eSdrh # overwrite the header on the rootpage of the index in order to 368bb8a279eSdrh # make the index appear to be empty. 369bb8a279eSdrh # 370bb8a279eSdrh set offset [expr {$pgsz*($rootpage-1)}] 371bb8a279eSdrh hexio_write test.db $offset 0a00000000040000000000 372bb8a279eSdrh db close 373bb8a279eSdrh sqlite3 db test.db 374ed717fe3Sdrh execsql {PRAGMA integrity_check} 3756fbe41acSdrh } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} 37691cf71b0Sdanielk1977 do_test pragma-3.3 { 3771dcdbc06Sdrh execsql {PRAGMA integrity_check=1} 3786fbe41acSdrh } {{row 1 missing from index i2}} 3791dcdbc06Sdrh do_test pragma-3.4 { 38091cf71b0Sdanielk1977 execsql { 3811dcdbc06Sdrh ATTACH DATABASE 'test.db' AS t2; 3821dcdbc06Sdrh PRAGMA integrity_check 38391cf71b0Sdanielk1977 } 3846fbe41acSdrh } {{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}} 3851dcdbc06Sdrh do_test pragma-3.5 { 3861dcdbc06Sdrh execsql { 387bb8a279eSdrh PRAGMA integrity_check=4 3881dcdbc06Sdrh } 3896fbe41acSdrh } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2}} 390*17d2d592Sdrh do_catchsql_test pragma-3.6 { 3911dcdbc06Sdrh PRAGMA integrity_check=xyz 392*17d2d592Sdrh } {1 {no such table: xyz}} 393*17d2d592Sdrh do_catchsql_test pragma-3.6b { 394*17d2d592Sdrh PRAGMA integrity_check=t2 395*17d2d592Sdrh } {0 {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}} 396*17d2d592Sdrh do_catchsql_test pragma-3.6c { 397*17d2d592Sdrh PRAGMA integrity_check=sqlite_schema 398*17d2d592Sdrh } {0 ok} 3991dcdbc06Sdrh do_test pragma-3.7 { 4001dcdbc06Sdrh execsql { 4011dcdbc06Sdrh PRAGMA integrity_check=0 4021dcdbc06Sdrh } 4036fbe41acSdrh } {{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}} 4041dcdbc06Sdrh 4051dcdbc06Sdrh # Add additional corruption by appending unused pages to the end of 4061dcdbc06Sdrh # the database file testerr.db 4071dcdbc06Sdrh # 4081dcdbc06Sdrh do_test pragma-3.8 { 4091dcdbc06Sdrh execsql {DETACH t2} 410fda06befSmistachkin forcedelete testerr.db testerr.db-journal 411e3d559adSdrh set out [open testerr.db w] 412e3d559adSdrh fconfigure $out -translation binary 413e3d559adSdrh set in [open test.db r] 414e3d559adSdrh fconfigure $in -translation binary 4151dcdbc06Sdrh puts -nonewline $out [read $in] 4161dcdbc06Sdrh seek $in 0 4171dcdbc06Sdrh puts -nonewline $out [read $in] 4181dcdbc06Sdrh close $in 4191dcdbc06Sdrh close $out 420dd3cd977Sdrh hexio_write testerr.db 28 00000000 4211dcdbc06Sdrh execsql {REINDEX t2} 4221dcdbc06Sdrh execsql {PRAGMA integrity_check} 4231dcdbc06Sdrh } {ok} 42441c58b78Sdanielk1977 do_test pragma-3.8.1 { 42541c58b78Sdanielk1977 execsql {PRAGMA quick_check} 42641c58b78Sdanielk1977 } {ok} 4275d16a9a6Sdrh do_test pragma-3.8.2 { 4285d16a9a6Sdrh execsql {PRAGMA QUICK_CHECK} 4295d16a9a6Sdrh } {ok} 430*17d2d592Sdrh do_test pragma-3.9a { 4311dcdbc06Sdrh execsql { 4321dcdbc06Sdrh ATTACH 'testerr.db' AS t2; 4331dcdbc06Sdrh PRAGMA integrity_check 4341dcdbc06Sdrh } 4351dcdbc06Sdrh } {{*** in database t2 *** 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}} 439*17d2d592Sdrh do_execsql_test pragma-3.9b { 440*17d2d592Sdrh PRAGMA t2.integrity_check=t2; 441*17d2d592Sdrh } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} 442*17d2d592Sdrh do_execsql_test pragma-3.9c { 443*17d2d592Sdrh PRAGMA t2.integrity_check=sqlite_schema; 444*17d2d592Sdrh } {ok} 4451dcdbc06Sdrh do_test pragma-3.10 { 4461dcdbc06Sdrh execsql { 4471dcdbc06Sdrh PRAGMA integrity_check=1 4481dcdbc06Sdrh } 4491dcdbc06Sdrh } {{*** in database t2 *** 4501dcdbc06SdrhPage 4 is never used}} 4511dcdbc06Sdrh do_test pragma-3.11 { 4521dcdbc06Sdrh execsql { 4531dcdbc06Sdrh PRAGMA integrity_check=5 4541dcdbc06Sdrh } 4551dcdbc06Sdrh } {{*** in database t2 *** 4561dcdbc06SdrhPage 4 is never used 4571dcdbc06SdrhPage 5 is never used 4586fbe41acSdrhPage 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2}} 4591dcdbc06Sdrh do_test pragma-3.12 { 4601dcdbc06Sdrh execsql { 4611dcdbc06Sdrh PRAGMA integrity_check=4 4621dcdbc06Sdrh } 4631dcdbc06Sdrh } {{*** in database t2 *** 4641dcdbc06SdrhPage 4 is never used 4651dcdbc06SdrhPage 5 is never used 4666fbe41acSdrhPage 6 is never used} {row 1 missing from index i2}} 4671dcdbc06Sdrh do_test pragma-3.13 { 4681dcdbc06Sdrh execsql { 4691dcdbc06Sdrh PRAGMA integrity_check=3 4701dcdbc06Sdrh } 4711dcdbc06Sdrh } {{*** in database t2 *** 4721dcdbc06SdrhPage 4 is never used 4731dcdbc06SdrhPage 5 is never used 4741dcdbc06SdrhPage 6 is never used}} 4751dcdbc06Sdrh do_test pragma-3.14 { 4761dcdbc06Sdrh execsql { 4771dcdbc06Sdrh PRAGMA integrity_check(2) 4781dcdbc06Sdrh } 4791dcdbc06Sdrh } {{*** in database t2 *** 4801dcdbc06SdrhPage 4 is never used 4811dcdbc06SdrhPage 5 is never used}} 4821dcdbc06Sdrh do_test pragma-3.15 { 4831dcdbc06Sdrh execsql { 4841dcdbc06Sdrh ATTACH 'testerr.db' AS t3; 4851dcdbc06Sdrh PRAGMA integrity_check 4861dcdbc06Sdrh } 4871dcdbc06Sdrh } {{*** in database t2 *** 4881dcdbc06SdrhPage 4 is never used 4891dcdbc06SdrhPage 5 is never used 4906fbe41acSdrhPage 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 *** 4911dcdbc06SdrhPage 4 is never used 4921dcdbc06SdrhPage 5 is never used 4936fbe41acSdrhPage 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}} 4941dcdbc06Sdrh do_test pragma-3.16 { 4951dcdbc06Sdrh execsql { 496bb8a279eSdrh PRAGMA integrity_check(10) 4971dcdbc06Sdrh } 4981dcdbc06Sdrh } {{*** in database t2 *** 4991dcdbc06SdrhPage 4 is never used 5001dcdbc06SdrhPage 5 is never used 5016fbe41acSdrhPage 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 *** 5021dcdbc06SdrhPage 4 is never used 5031dcdbc06SdrhPage 5 is never used 5046fbe41acSdrhPage 6 is never used} {row 1 missing from index i2}} 5051dcdbc06Sdrh do_test pragma-3.17 { 5061dcdbc06Sdrh execsql { 507bb8a279eSdrh PRAGMA integrity_check=8 5081dcdbc06Sdrh } 5091dcdbc06Sdrh } {{*** in database t2 *** 5101dcdbc06SdrhPage 4 is never used 5111dcdbc06SdrhPage 5 is never used 5126fbe41acSdrhPage 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 *** 5131dcdbc06SdrhPage 4 is never used 5141dcdbc06SdrhPage 5 is never used}} 5151dcdbc06Sdrh do_test pragma-3.18 { 5161dcdbc06Sdrh execsql { 5171dcdbc06Sdrh PRAGMA integrity_check=4 5181dcdbc06Sdrh } 5191dcdbc06Sdrh } {{*** in database t2 *** 5201dcdbc06SdrhPage 4 is never used 5211dcdbc06SdrhPage 5 is never used 5226fbe41acSdrhPage 6 is never used} {row 1 missing from index i2}} 5231dcdbc06Sdrh } 524d2cb50b7Sdrh do_test pragma-3.19 { 525d2cb50b7Sdrh catch {db close} 526fda06befSmistachkin forcedelete test.db test.db-journal 527d2cb50b7Sdrh sqlite3 db test.db 528d2cb50b7Sdrh db eval {PRAGMA integrity_check} 529d2cb50b7Sdrh } {ok} 5305a8f9374Sdanielk1977} 531cefc87fcSdrh 532cefc87fcSdrh# Verify that PRAGMA integrity_check catches UNIQUE and NOT NULL 533cefc87fcSdrh# constraint violations. 534cefc87fcSdrh# 5356ab91a7aSdrhsqlite3_db_config db DEFENSIVE 0 536cefc87fcSdrhdo_execsql_test pragma-3.20 { 537cefc87fcSdrh CREATE TABLE t1(a,b); 538cefc87fcSdrh CREATE INDEX t1a ON t1(a); 539cefc87fcSdrh INSERT INTO t1 VALUES(1,1),(2,2),(3,3),(2,4),(NULL,5),(NULL,6); 540cefc87fcSdrh PRAGMA writable_schema=ON; 541cefc87fcSdrh UPDATE sqlite_master SET sql='CREATE UNIQUE INDEX t1a ON t1(a)' 542cefc87fcSdrh WHERE name='t1a'; 543cefc87fcSdrh UPDATE sqlite_master SET sql='CREATE TABLE t1(a NOT NULL,b)' 544cefc87fcSdrh WHERE name='t1'; 545cefc87fcSdrh PRAGMA writable_schema=OFF; 546cefc87fcSdrh ALTER TABLE t1 RENAME TO t1x; 547cefc87fcSdrh PRAGMA integrity_check; 548cefc87fcSdrh} {{non-unique entry in index t1a} {NULL value in t1x.a} {non-unique entry in index t1a} {NULL value in t1x.a}} 549cefc87fcSdrhdo_execsql_test pragma-3.21 { 550cefc87fcSdrh PRAGMA integrity_check(3); 551cefc87fcSdrh} {{non-unique entry in index t1a} {NULL value in t1x.a} {non-unique entry in index t1a}} 552cefc87fcSdrhdo_execsql_test pragma-3.22 { 553cefc87fcSdrh PRAGMA integrity_check(2); 554cefc87fcSdrh} {{non-unique entry in index t1a} {NULL value in t1x.a}} 5557efa426eSdrhdo_execsql_test pragma-3.23 { 556cefc87fcSdrh PRAGMA integrity_check(1); 557cefc87fcSdrh} {{non-unique entry in index t1a}} 55891cf71b0Sdanielk1977 5597efa426eSdrh# PRAGMA integrity check (or more specifically the sqlite3BtreeCount() 5607efa426eSdrh# interface) used to leave index cursors in an inconsistent state 5617efa426eSdrh# which could result in an assertion fault in sqlite3BtreeKey() 5627efa426eSdrh# called from saveCursorPosition() if content is removed from the 5637efa426eSdrh# index while the integrity_check is still running. This test verifies 5647efa426eSdrh# that problem has been fixed. 5657efa426eSdrh# 5667efa426eSdrhdo_test pragma-3.30 { 5677efa426eSdrh db close 5687efa426eSdrh delete_file test.db 5697efa426eSdrh sqlite3 db test.db 5707efa426eSdrh db eval { 5717efa426eSdrh CREATE TABLE t1(a,b,c); 5727efa426eSdrh WITH RECURSIVE 5737efa426eSdrh c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<100) 5747efa426eSdrh INSERT INTO t1(a,b,c) SELECT i, printf('xyz%08x',i), 2000-i FROM c; 5757efa426eSdrh CREATE INDEX t1a ON t1(a); 5767efa426eSdrh CREATE INDEX t1bc ON t1(b,c); 5777efa426eSdrh } 5787efa426eSdrh db eval {PRAGMA integrity_check} { 5797efa426eSdrh db eval {DELETE FROM t1} 5807efa426eSdrh } 5817efa426eSdrh} {} 5827efa426eSdrh 58391cf71b0Sdanielk1977# Test modifying the cache_size of an attached database. 5845a8f9374Sdanielk1977ifcapable pager_pragmas&&attach { 58591cf71b0Sdanielk1977do_test pragma-4.1 { 58691cf71b0Sdanielk1977 execsql { 5871e9daa6aSdrh ATTACH 'test2.db' AS aux; 58891cf71b0Sdanielk1977 pragma aux.cache_size; 58991cf71b0Sdanielk1977 pragma aux.default_cache_size; 59091cf71b0Sdanielk1977 } 5911e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] 5921bdd9b57Sdrhdo_test pragma-4.2 { 5931bdd9b57Sdrh execsql { 59491cf71b0Sdanielk1977 pragma aux.cache_size = 50; 59591cf71b0Sdanielk1977 pragma aux.cache_size; 59691cf71b0Sdanielk1977 pragma aux.default_cache_size; 5971bdd9b57Sdrh } 5981e9daa6aSdrh} [list 50 $DFLT_CACHE_SZ] 5991bdd9b57Sdrhdo_test pragma-4.3 { 6001bdd9b57Sdrh execsql { 60191cf71b0Sdanielk1977 pragma aux.default_cache_size = 456; 60291cf71b0Sdanielk1977 pragma aux.cache_size; 60391cf71b0Sdanielk1977 pragma aux.default_cache_size; 6041bdd9b57Sdrh } 60591cf71b0Sdanielk1977} {456 456} 6061bdd9b57Sdrhdo_test pragma-4.4 { 6071bdd9b57Sdrh execsql { 60891cf71b0Sdanielk1977 pragma cache_size; 60991cf71b0Sdanielk1977 pragma default_cache_size; 6101bdd9b57Sdrh } 6111e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] 6121bdd9b57Sdrhdo_test pragma-4.5 { 6131bdd9b57Sdrh execsql { 61491cf71b0Sdanielk1977 DETACH aux; 61591cf71b0Sdanielk1977 ATTACH 'test3.db' AS aux; 61691cf71b0Sdanielk1977 pragma aux.cache_size; 61791cf71b0Sdanielk1977 pragma aux.default_cache_size; 6181bdd9b57Sdrh } 6191e9daa6aSdrh} [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] 6201bdd9b57Sdrhdo_test pragma-4.6 { 6211bdd9b57Sdrh execsql { 62291cf71b0Sdanielk1977 DETACH aux; 62391cf71b0Sdanielk1977 ATTACH 'test2.db' AS aux; 62491cf71b0Sdanielk1977 pragma aux.cache_size; 62591cf71b0Sdanielk1977 pragma aux.default_cache_size; 6261bdd9b57Sdrh } 62791cf71b0Sdanielk1977} {456 456} 628c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 6291bdd9b57Sdrh 63091cf71b0Sdanielk1977# Test that modifying the sync-level in the middle of a transaction is 63191cf71b0Sdanielk1977# disallowed. 632c7b4a44cSdanielk1977ifcapable pager_pragmas { 63391cf71b0Sdanielk1977do_test pragma-5.0 { 6341bdd9b57Sdrh execsql { 63591cf71b0Sdanielk1977 pragma synchronous; 6361bdd9b57Sdrh } 63791cf71b0Sdanielk1977} {2} 63891cf71b0Sdanielk1977do_test pragma-5.1 { 6391bdd9b57Sdrh catchsql { 6401bdd9b57Sdrh BEGIN; 64191cf71b0Sdanielk1977 pragma synchronous = OFF; 6421bdd9b57Sdrh } 64391cf71b0Sdanielk1977} {1 {Safety level may not be changed inside a transaction}} 64491cf71b0Sdanielk1977do_test pragma-5.2 { 64591cf71b0Sdanielk1977 execsql { 64691cf71b0Sdanielk1977 pragma synchronous; 64791cf71b0Sdanielk1977 } 64891cf71b0Sdanielk1977} {2} 6495260f7e9Sdrhcatchsql {COMMIT;} 650c7b4a44cSdanielk1977} ;# ifcapable pager_pragmas 6515260f7e9Sdrh 6525260f7e9Sdrh# Test schema-query pragmas 6535260f7e9Sdrh# 65427188fb5Sdanielk1977ifcapable schema_pragmas { 6555a8f9374Sdanielk1977ifcapable tempdb&&attach { 6565260f7e9Sdrh do_test pragma-6.1 { 657956bc92cSdrh set res {} 65840e016e4Sdrh execsql {SELECT * FROM sqlite_temp_master} 6595260f7e9Sdrh foreach {idx name file} [execsql {pragma database_list}] { 6605260f7e9Sdrh lappend res $idx $name 6615260f7e9Sdrh } 6625260f7e9Sdrh set res 663a71aa001Sdrh } {0 main 1 temp 2 aux} 66453c0f748Sdanielk1977} 6655260f7e9Sdrhdo_test pragma-6.2 { 6665260f7e9Sdrh execsql { 667a6dddd9bSdrh CREATE TABLE t2(a TYPE_X, b [TYPE_Y], c "TYPE_Z"); 6685260f7e9Sdrh pragma table_info(t2) 6695260f7e9Sdrh } 670a6dddd9bSdrh} {0 a TYPE_X 0 {} 0 1 b TYPE_Y 0 {} 0 2 c TYPE_Z 0 {} 0} 671d2cb50b7Sdrhdo_test pragma-6.2.1 { 672d2cb50b7Sdrh execsql { 673d2cb50b7Sdrh pragma table_info; 674d2cb50b7Sdrh } 675d2cb50b7Sdrh} {} 676736c7d4bSdrhdb nullvalue <<NULL>> 677417ec638Sdrhdo_test pragma-6.2.2 { 678417ec638Sdrh execsql { 679736c7d4bSdrh CREATE TABLE t5( 680736c7d4bSdrh a TEXT DEFAULT CURRENT_TIMESTAMP, 681736c7d4bSdrh b DEFAULT (5+3), 682736c7d4bSdrh c TEXT, 683736c7d4bSdrh d INTEGER DEFAULT NULL, 684384b7fe2Sdrh e TEXT DEFAULT '', 685384b7fe2Sdrh UNIQUE(b,c,d), 686384b7fe2Sdrh PRIMARY KEY(e,b,c) 687736c7d4bSdrh ); 688417ec638Sdrh PRAGMA table_info(t5); 689417ec638Sdrh } 690384b7fe2Sdrh} {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} 691736c7d4bSdrhdb nullvalue {} 692384b7fe2Sdrhdo_test pragma-6.2.3 { 693384b7fe2Sdrh execsql { 694384b7fe2Sdrh CREATE TABLE t2_3(a,b INTEGER PRIMARY KEY,c); 695384b7fe2Sdrh pragma table_info(t2_3) 696384b7fe2Sdrh } 697384b7fe2Sdrh} {0 a {} 0 {} 0 1 b INTEGER 0 {} 1 2 c {} 0 {} 0} 6986bf89570Sdrhifcapable {foreignkey} { 699d2cb50b7Sdrh do_test pragma-6.3.1 { 7005260f7e9Sdrh execsql { 7015260f7e9Sdrh CREATE TABLE t3(a int references t2(b), b UNIQUE); 7025260f7e9Sdrh pragma foreign_key_list(t3); 7035260f7e9Sdrh } 7041da40a38Sdan } {0 0 t2 a b {NO ACTION} {NO ACTION} NONE} 705d2cb50b7Sdrh do_test pragma-6.3.2 { 706d2cb50b7Sdrh execsql { 707d2cb50b7Sdrh pragma foreign_key_list; 708d2cb50b7Sdrh } 709d2cb50b7Sdrh } {} 710d2cb50b7Sdrh do_test pragma-6.3.3 { 711d2cb50b7Sdrh execsql { 712d2cb50b7Sdrh pragma foreign_key_list(t3_bogus); 713d2cb50b7Sdrh } 714d2cb50b7Sdrh } {} 715d2cb50b7Sdrh do_test pragma-6.3.4 { 716d2cb50b7Sdrh execsql { 717d2cb50b7Sdrh pragma foreign_key_list(t5); 718d2cb50b7Sdrh } 719d2cb50b7Sdrh } {} 7205260f7e9Sdrh do_test pragma-6.4 { 721c228be5bSdrh capture_pragma db out { 7225260f7e9Sdrh pragma index_list(t3); 7235260f7e9Sdrh } 724c228be5bSdrh db eval {SELECT seq, "name", "unique" FROM out ORDER BY seq} 7253ef26156Sdrh } {0 sqlite_autoindex_t3_1 1} 7266bf89570Sdrh} 7276bf89570Sdrhifcapable {!foreignkey} { 7286bf89570Sdrh execsql {CREATE TABLE t3(a,b UNIQUE)} 7296bf89570Sdrh} 730d2cb50b7Sdrhdo_test pragma-6.5.1 { 7315260f7e9Sdrh execsql { 7325260f7e9Sdrh CREATE INDEX t3i1 ON t3(a,b); 733c228be5bSdrh } 734c228be5bSdrh capture_pragma db out { 7355260f7e9Sdrh pragma index_info(t3i1); 7365260f7e9Sdrh } 737c228be5bSdrh db eval {SELECT seqno, cid, name FROM out ORDER BY seqno} 7385260f7e9Sdrh} {0 0 a 1 1 b} 7397be0fd9cSdrh 7407be0fd9cSdrh# EVIDENCE-OF: R-23114-21695 The auxiliary index-columns are not shown 7417be0fd9cSdrh# by the index_info pragma, but they are listed by the index_xinfo 7427be0fd9cSdrh# pragma. 7437be0fd9cSdrh# 7447be0fd9cSdrhdo_test pragma-6.5.1b { 7457be0fd9cSdrh capture_pragma db out {PRAGMA index_xinfo(t3i1)} 7467be0fd9cSdrh db eval {SELECT seqno, cid, name FROM out ORDER BY seqno} 7477be0fd9cSdrh} {0 0 a 1 1 b 2 -1 {}} 7487be0fd9cSdrh 7497be0fd9cSdrh 750b3366b99Sdrh# EVIDENCE-OF: R-29448-60346 PRAGMA schema.index_info(index-name); This 751b3366b99Sdrh# pragma returns one row for each key column in the named index. 7527be0fd9cSdrh# 7537be0fd9cSdrh# (The first column of output from PRAGMA index_info is...) 7547be0fd9cSdrh# EVIDENCE-OF: R-34186-52914 The rank of the column within the index. (0 7557be0fd9cSdrh# means left-most.) 7567be0fd9cSdrh# 7577be0fd9cSdrh# (The second column of output from PRAGMA index_info is...) 7587be0fd9cSdrh# EVIDENCE-OF: R-65019-08383 The rank of the column within the table 7597be0fd9cSdrh# being indexed. 7607be0fd9cSdrh# 7617be0fd9cSdrh# (The third column of output from PRAGMA index_info is...) 7627be0fd9cSdrh# EVIDENCE-OF: R-09773-34266 The name of the column being indexed. 7637be0fd9cSdrh# 7647be0fd9cSdrhdo_execsql_test pragma-6.5.1c { 7657be0fd9cSdrh CREATE INDEX t3i2 ON t3(b,a); 7667be0fd9cSdrh PRAGMA index_info='t3i2'; 7677be0fd9cSdrh DROP INDEX t3i2; 7687be0fd9cSdrh} {0 1 b 1 0 a} 7697be0fd9cSdrh 770d2cb50b7Sdrhdo_test pragma-6.5.2 { 771d2cb50b7Sdrh execsql { 772d2cb50b7Sdrh pragma index_info(t3i1_bogus); 773d2cb50b7Sdrh } 774d2cb50b7Sdrh} {} 775260d8a6aSdanielk1977 776260d8a6aSdanielk1977ifcapable tempdb { 777260d8a6aSdanielk1977 # Test for ticket #3320. When a temp table of the same name exists, make 778260d8a6aSdanielk1977 # sure the schema of the main table can still be queried using 779260d8a6aSdanielk1977 # "pragma table_info": 780260d8a6aSdanielk1977 do_test pragma-6.6.1 { 781260d8a6aSdanielk1977 execsql { 782260d8a6aSdanielk1977 CREATE TABLE trial(col_main); 783260d8a6aSdanielk1977 CREATE TEMP TABLE trial(col_temp); 784260d8a6aSdanielk1977 } 785260d8a6aSdanielk1977 } {} 786260d8a6aSdanielk1977 do_test pragma-6.6.2 { 787260d8a6aSdanielk1977 execsql { 788260d8a6aSdanielk1977 PRAGMA table_info(trial); 789260d8a6aSdanielk1977 } 790260d8a6aSdanielk1977 } {0 col_temp {} 0 {} 0} 791260d8a6aSdanielk1977 do_test pragma-6.6.3 { 792260d8a6aSdanielk1977 execsql { 793260d8a6aSdanielk1977 PRAGMA temp.table_info(trial); 794260d8a6aSdanielk1977 } 795260d8a6aSdanielk1977 } {0 col_temp {} 0 {} 0} 796260d8a6aSdanielk1977 do_test pragma-6.6.4 { 797260d8a6aSdanielk1977 execsql { 798260d8a6aSdanielk1977 PRAGMA main.table_info(trial); 799260d8a6aSdanielk1977 } 800260d8a6aSdanielk1977 } {0 col_main {} 0 {} 0} 801260d8a6aSdanielk1977} 802f96a3778Sdanielk1977 803f96a3778Sdanielk1977do_test pragma-6.7 { 804f96a3778Sdanielk1977 execsql { 805f96a3778Sdanielk1977 CREATE TABLE test_table( 806f96a3778Sdanielk1977 one INT NOT NULL DEFAULT -1, 807f96a3778Sdanielk1977 two text, 808f96a3778Sdanielk1977 three VARCHAR(45, 65) DEFAULT 'abcde', 809f96a3778Sdanielk1977 four REAL DEFAULT X'abcdef', 810f96a3778Sdanielk1977 five DEFAULT CURRENT_TIME 811f96a3778Sdanielk1977 ); 812f96a3778Sdanielk1977 } 813c228be5bSdrh capture_pragma db out {PRAGMA table_info(test_table)} 814c228be5bSdrh db eval {SELECT cid, "name", type, "notnull", dflt_value, pk FROM out 815c228be5bSdrh ORDER BY cid} 816f96a3778Sdanielk1977} [concat \ 817f96a3778Sdanielk1977 {0 one INT 1 -1 0} \ 818f96a3778Sdanielk1977 {1 two text 0 {} 0} \ 819f96a3778Sdanielk1977 {2 three {VARCHAR(45, 65)} 0 'abcde' 0} \ 820f96a3778Sdanielk1977 {3 four REAL 0 X'abcdef' 0} \ 821f96a3778Sdanielk1977 {4 five {} 0 CURRENT_TIME 0} \ 822f96a3778Sdanielk1977] 8231b678969Sdrhdo_test pragma-6.8 { 8241b678969Sdrh execsql { 8251b678969Sdrh CREATE TABLE t68(a,b,c,PRIMARY KEY(a,b,a,c)); 8261b678969Sdrh PRAGMA table_info(t68); 8271b678969Sdrh } 8281b678969Sdrh} [concat \ 8291b678969Sdrh {0 a {} 0 {} 1} \ 8301b678969Sdrh {1 b {} 0 {} 2} \ 8311b678969Sdrh {2 c {} 0 {} 4} \ 8321b678969Sdrh] 83327188fb5Sdanielk1977} ;# ifcapable schema_pragmas 8345260f7e9Sdrh# Miscellaneous tests 8355260f7e9Sdrh# 83627188fb5Sdanielk1977ifcapable schema_pragmas { 837b3366b99Sdrh# EVIDENCE-OF: R-64103-17776 PRAGMA schema.index_list(table-name); This 838b3366b99Sdrh# pragma returns one row for each index associated with the given table. 839b3366b99Sdrh# 840d2cb50b7Sdrhdo_test pragma-7.1.1 { 8415260f7e9Sdrh # Make sure a pragma knows to read the schema if it needs to 8425260f7e9Sdrh db close 8435260f7e9Sdrh sqlite3 db test.db 844c228be5bSdrh capture_pragma db out "PRAGMA index_list(t3)" 845c228be5bSdrh db eval {SELECT name, "origin" FROM out ORDER BY name DESC} 846c228be5bSdrh} {t3i1 c sqlite_autoindex_t3_1 u} 847d2cb50b7Sdrhdo_test pragma-7.1.2 { 848d2cb50b7Sdrh execsql { 849d2cb50b7Sdrh pragma index_list(t3_bogus); 850d2cb50b7Sdrh } 851d2cb50b7Sdrh} {} 85227188fb5Sdanielk1977} ;# ifcapable schema_pragmas 8536c62608fSdrhifcapable {utf16} { 854cb354603Sdan if {[permutation] == ""} { 8555260f7e9Sdrh do_test pragma-7.2 { 8565260f7e9Sdrh db close 8575260f7e9Sdrh sqlite3 db test.db 8585260f7e9Sdrh catchsql { 8595260f7e9Sdrh pragma encoding=bogus; 8605260f7e9Sdrh } 8615260f7e9Sdrh } {1 {unsupported encoding: bogus}} 8626c62608fSdrh } 863cb354603Sdan} 86453c0f748Sdanielk1977ifcapable tempdb { 8655260f7e9Sdrh do_test pragma-7.3 { 8665260f7e9Sdrh db close 8675260f7e9Sdrh sqlite3 db test.db 8685260f7e9Sdrh execsql { 8695260f7e9Sdrh pragma lock_status; 8705260f7e9Sdrh } 8715260f7e9Sdrh } {main unlocked temp closed} 87253c0f748Sdanielk1977} else { 87353c0f748Sdanielk1977 do_test pragma-7.3 { 87453c0f748Sdanielk1977 db close 87553c0f748Sdanielk1977 sqlite3 db test.db 87653c0f748Sdanielk1977 execsql { 87753c0f748Sdanielk1977 pragma lock_status; 87853c0f748Sdanielk1977 } 87953c0f748Sdanielk1977 } {main unlocked} 88053c0f748Sdanielk1977} 8815260f7e9Sdrh 8825260f7e9Sdrh 883dae2495bSdanielk1977#---------------------------------------------------------------------- 884b92b70bbSdanielk1977# Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA 885b92b70bbSdanielk1977# user_version" statements. 886dae2495bSdanielk1977# 887b92b70bbSdanielk1977# pragma-8.1: PRAGMA schema_version 888b92b70bbSdanielk1977# pragma-8.2: PRAGMA user_version 889dae2495bSdanielk1977# 890dae2495bSdanielk1977 89111cf9fbcSdanielk1977ifcapable schema_version { 89211cf9fbcSdanielk1977 893b92b70bbSdanielk1977# First check that we can set the schema version and then retrieve the 894dae2495bSdanielk1977# same value. 895dae2495bSdanielk1977do_test pragma-8.1.1 { 896dae2495bSdanielk1977 execsql { 897b92b70bbSdanielk1977 PRAGMA schema_version = 105; 898dae2495bSdanielk1977 } 899dae2495bSdanielk1977} {} 900dae2495bSdanielk1977do_test pragma-8.1.2 { 90125403650Sdrh execsql2 { 902b92b70bbSdanielk1977 PRAGMA schema_version; 903dae2495bSdanielk1977 } 90425403650Sdrh} {schema_version 105} 905dae2495bSdanielk1977do_test pragma-8.1.3 { 906dae2495bSdanielk1977 execsql { 907b92b70bbSdanielk1977 PRAGMA schema_version = 106; 908dae2495bSdanielk1977 } 909dae2495bSdanielk1977} {} 910dae2495bSdanielk1977do_test pragma-8.1.4 { 911dae2495bSdanielk1977 execsql { 912b92b70bbSdanielk1977 PRAGMA schema_version; 913dae2495bSdanielk1977 } 914dae2495bSdanielk1977} 106 915dae2495bSdanielk1977 916b92b70bbSdanielk1977# Check that creating a table modifies the schema-version (this is really 917b92b70bbSdanielk1977# to verify that the value being read is in fact the schema version). 918dae2495bSdanielk1977do_test pragma-8.1.5 { 919dae2495bSdanielk1977 execsql { 920dae2495bSdanielk1977 CREATE TABLE t4(a, b, c); 921dae2495bSdanielk1977 INSERT INTO t4 VALUES(1, 2, 3); 922dae2495bSdanielk1977 SELECT * FROM t4; 923dae2495bSdanielk1977 } 924dae2495bSdanielk1977} {1 2 3} 925dae2495bSdanielk1977do_test pragma-8.1.6 { 926dae2495bSdanielk1977 execsql { 927b92b70bbSdanielk1977 PRAGMA schema_version; 928dae2495bSdanielk1977 } 929dae2495bSdanielk1977} 107 930dae2495bSdanielk1977 931dae2495bSdanielk1977# Now open a second connection to the database. Ensure that changing the 932b92b70bbSdanielk1977# schema-version using the first connection forces the second connection 933dae2495bSdanielk1977# to reload the schema. This has to be done using the C-API test functions, 934dae2495bSdanielk1977# because the TCL API accounts for SCHEMA_ERROR and retries the query. 935dae2495bSdanielk1977do_test pragma-8.1.7 { 936dddca286Sdrh sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] 937dae2495bSdanielk1977 execsql { 938dae2495bSdanielk1977 SELECT * FROM t4; 939dae2495bSdanielk1977 } db2 940dae2495bSdanielk1977} {1 2 3} 941dae2495bSdanielk1977do_test pragma-8.1.8 { 942dae2495bSdanielk1977 execsql { 943b92b70bbSdanielk1977 PRAGMA schema_version = 108; 944dae2495bSdanielk1977 } 945dae2495bSdanielk1977} {} 946dae2495bSdanielk1977do_test pragma-8.1.9 { 947dae2495bSdanielk1977 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY] 948dae2495bSdanielk1977 sqlite3_step $::STMT 949dae2495bSdanielk1977} SQLITE_ERROR 950dae2495bSdanielk1977do_test pragma-8.1.10 { 951dae2495bSdanielk1977 sqlite3_finalize $::STMT 952dae2495bSdanielk1977} SQLITE_SCHEMA 953dae2495bSdanielk1977 954b92b70bbSdanielk1977# Make sure the schema-version can be manipulated in an attached database. 955fda06befSmistachkinforcedelete test2.db 956fda06befSmistachkinforcedelete test2.db-journal 9575a8f9374Sdanielk1977ifcapable attach { 958dae2495bSdanielk1977 do_test pragma-8.1.11 { 959dae2495bSdanielk1977 execsql { 960dae2495bSdanielk1977 ATTACH 'test2.db' AS aux; 961dae2495bSdanielk1977 CREATE TABLE aux.t1(a, b, c); 962b92b70bbSdanielk1977 PRAGMA aux.schema_version = 205; 963dae2495bSdanielk1977 } 964dae2495bSdanielk1977 } {} 965dae2495bSdanielk1977 do_test pragma-8.1.12 { 966dae2495bSdanielk1977 execsql { 967b92b70bbSdanielk1977 PRAGMA aux.schema_version; 968dae2495bSdanielk1977 } 969dae2495bSdanielk1977 } 205 9705a8f9374Sdanielk1977} 971dae2495bSdanielk1977do_test pragma-8.1.13 { 972dae2495bSdanielk1977 execsql { 973b92b70bbSdanielk1977 PRAGMA schema_version; 974dae2495bSdanielk1977 } 975dae2495bSdanielk1977} 108 976dae2495bSdanielk1977 977b92b70bbSdanielk1977# And check that modifying the schema-version in an attached database 978dae2495bSdanielk1977# forces the second connection to reload the schema. 9795a8f9374Sdanielk1977ifcapable attach { 980dae2495bSdanielk1977 do_test pragma-8.1.14 { 981dddca286Sdrh sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] 982dae2495bSdanielk1977 execsql { 983dae2495bSdanielk1977 ATTACH 'test2.db' AS aux; 984dae2495bSdanielk1977 SELECT * FROM aux.t1; 985dae2495bSdanielk1977 } db2 986dae2495bSdanielk1977 } {} 987dae2495bSdanielk1977 do_test pragma-8.1.15 { 988dae2495bSdanielk1977 execsql { 989b92b70bbSdanielk1977 PRAGMA aux.schema_version = 206; 990dae2495bSdanielk1977 } 991dae2495bSdanielk1977 } {} 992dae2495bSdanielk1977 do_test pragma-8.1.16 { 993dae2495bSdanielk1977 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY] 994dae2495bSdanielk1977 sqlite3_step $::STMT 995dae2495bSdanielk1977 } SQLITE_ERROR 996dae2495bSdanielk1977 do_test pragma-8.1.17 { 997dae2495bSdanielk1977 sqlite3_finalize $::STMT 998dae2495bSdanielk1977 } SQLITE_SCHEMA 999dae2495bSdanielk1977 do_test pragma-8.1.18 { 1000dae2495bSdanielk1977 db2 close 1001dae2495bSdanielk1977 } {} 10025a8f9374Sdanielk1977} 1003dae2495bSdanielk1977 1004b92b70bbSdanielk1977# Now test that the user-version can be read and written (and that we aren't 1005b92b70bbSdanielk1977# accidentally manipulating the schema-version instead). 1006dae2495bSdanielk1977do_test pragma-8.2.1 { 100725403650Sdrh execsql2 { 1008b92b70bbSdanielk1977 PRAGMA user_version; 1009dae2495bSdanielk1977 } 101025403650Sdrh} {user_version 0} 1011dae2495bSdanielk1977do_test pragma-8.2.2 { 1012dae2495bSdanielk1977 execsql { 1013b92b70bbSdanielk1977 PRAGMA user_version = 2; 1014dae2495bSdanielk1977 } 1015dae2495bSdanielk1977} {} 1016802d69a7Sdrhdo_test pragma-8.2.3.1 { 101725403650Sdrh execsql2 { 1018b92b70bbSdanielk1977 PRAGMA user_version; 1019dae2495bSdanielk1977 } 102025403650Sdrh} {user_version 2} 1021802d69a7Sdrhdo_test pragma-8.2.3.2 { 1022802d69a7Sdrh db close 1023802d69a7Sdrh sqlite3 db test.db 1024802d69a7Sdrh execsql { 1025802d69a7Sdrh PRAGMA user_version; 1026802d69a7Sdrh } 1027802d69a7Sdrh} {2} 1028802d69a7Sdrhdo_test pragma-8.2.4.1 { 1029dae2495bSdanielk1977 execsql { 1030b92b70bbSdanielk1977 PRAGMA schema_version; 1031dae2495bSdanielk1977 } 1032dae2495bSdanielk1977} {108} 1033802d69a7Sdrhifcapable vacuum { 1034802d69a7Sdrh do_test pragma-8.2.4.2 { 1035802d69a7Sdrh execsql { 1036802d69a7Sdrh VACUUM; 1037802d69a7Sdrh PRAGMA user_version; 1038802d69a7Sdrh } 1039802d69a7Sdrh } {2} 1040802d69a7Sdrh do_test pragma-8.2.4.3 { 1041802d69a7Sdrh execsql { 1042802d69a7Sdrh PRAGMA schema_version; 1043802d69a7Sdrh } 1044802d69a7Sdrh } {109} 1045802d69a7Sdrh} 10465a8f9374Sdanielk1977 10475a8f9374Sdanielk1977ifcapable attach { 1048802d69a7Sdrh db eval {ATTACH 'test2.db' AS aux} 1049dae2495bSdanielk1977 1050b92b70bbSdanielk1977 # Check that the user-version in the auxilary database can be manipulated ( 1051dae2495bSdanielk1977 # and that we aren't accidentally manipulating the same in the main db). 1052dae2495bSdanielk1977 do_test pragma-8.2.5 { 1053dae2495bSdanielk1977 execsql { 1054b92b70bbSdanielk1977 PRAGMA aux.user_version; 1055dae2495bSdanielk1977 } 1056dae2495bSdanielk1977 } {0} 1057dae2495bSdanielk1977 do_test pragma-8.2.6 { 1058dae2495bSdanielk1977 execsql { 1059b92b70bbSdanielk1977 PRAGMA aux.user_version = 3; 1060dae2495bSdanielk1977 } 1061dae2495bSdanielk1977 } {} 1062dae2495bSdanielk1977 do_test pragma-8.2.7 { 1063dae2495bSdanielk1977 execsql { 1064b92b70bbSdanielk1977 PRAGMA aux.user_version; 1065dae2495bSdanielk1977 } 1066dae2495bSdanielk1977 } {3} 1067dae2495bSdanielk1977 do_test pragma-8.2.8 { 1068dae2495bSdanielk1977 execsql { 1069b92b70bbSdanielk1977 PRAGMA main.user_version; 1070dae2495bSdanielk1977 } 1071dae2495bSdanielk1977 } {2} 1072dae2495bSdanielk1977 1073b92b70bbSdanielk1977 # Now check that a ROLLBACK resets the user-version if it has been modified 1074dae2495bSdanielk1977 # within a transaction. 1075dae2495bSdanielk1977 do_test pragma-8.2.9 { 1076dae2495bSdanielk1977 execsql { 1077dae2495bSdanielk1977 BEGIN; 1078b92b70bbSdanielk1977 PRAGMA aux.user_version = 10; 1079b92b70bbSdanielk1977 PRAGMA user_version = 11; 1080dae2495bSdanielk1977 } 1081dae2495bSdanielk1977 } {} 1082dae2495bSdanielk1977 do_test pragma-8.2.10 { 1083dae2495bSdanielk1977 execsql { 1084b92b70bbSdanielk1977 PRAGMA aux.user_version; 1085dae2495bSdanielk1977 } 1086dae2495bSdanielk1977 } {10} 1087dae2495bSdanielk1977 do_test pragma-8.2.11 { 1088dae2495bSdanielk1977 execsql { 1089b92b70bbSdanielk1977 PRAGMA main.user_version; 1090dae2495bSdanielk1977 } 1091dae2495bSdanielk1977 } {11} 1092dae2495bSdanielk1977 do_test pragma-8.2.12 { 1093dae2495bSdanielk1977 execsql { 1094dae2495bSdanielk1977 ROLLBACK; 1095b92b70bbSdanielk1977 PRAGMA aux.user_version; 1096dae2495bSdanielk1977 } 1097dae2495bSdanielk1977 } {3} 1098dae2495bSdanielk1977 do_test pragma-8.2.13 { 1099dae2495bSdanielk1977 execsql { 1100b92b70bbSdanielk1977 PRAGMA main.user_version; 1101dae2495bSdanielk1977 } 1102dae2495bSdanielk1977 } {2} 11035a8f9374Sdanielk1977} 1104dae2495bSdanielk1977 1105b92b70bbSdanielk1977# Try a negative value for the user-version 1106dae2495bSdanielk1977do_test pragma-8.2.14 { 1107dae2495bSdanielk1977 execsql { 1108b92b70bbSdanielk1977 PRAGMA user_version = -450; 1109dae2495bSdanielk1977 } 1110dae2495bSdanielk1977} {} 1111dae2495bSdanielk1977do_test pragma-8.2.15 { 1112dae2495bSdanielk1977 execsql { 1113b92b70bbSdanielk1977 PRAGMA user_version; 1114dae2495bSdanielk1977 } 1115dae2495bSdanielk1977} {-450} 1116d9c847dcSdanielk1977} ; # ifcapable schema_version 1117d9c847dcSdanielk1977 1118d19744f3Sdrh# Check to see if TEMP_STORE is memory or disk. Return strings 1119d19744f3Sdrh# "memory" or "disk" as appropriate. 1120d19744f3Sdrh# 1121d19744f3Sdrhproc check_temp_store {} { 11229131ab93Sdan db eval { 11239131ab93Sdan PRAGMA temp.cache_size = 1; 11249131ab93Sdan CREATE TEMP TABLE IF NOT EXISTS a(b); 11259131ab93Sdan DELETE FROM a; 11269131ab93Sdan INSERT INTO a VALUES(randomblob(1000)); 11279131ab93Sdan INSERT INTO a SELECT * FROM a; 11289131ab93Sdan INSERT INTO a SELECT * FROM a; 11299131ab93Sdan INSERT INTO a SELECT * FROM a; 11309131ab93Sdan INSERT INTO a SELECT * FROM a; 11319131ab93Sdan INSERT INTO a SELECT * FROM a; 11329131ab93Sdan INSERT INTO a SELECT * FROM a; 11339131ab93Sdan INSERT INTO a SELECT * FROM a; 11349131ab93Sdan INSERT INTO a SELECT * FROM a; 11359131ab93Sdan } 1136d19744f3Sdrh db eval {PRAGMA database_list} { 1137d19744f3Sdrh if {$name=="temp"} { 113817b90b53Sdanielk1977 set bt [btree_from_db db 1] 113917b90b53Sdanielk1977 if {[btree_ismemdb $bt]} { 1140d19744f3Sdrh return "memory" 1141d19744f3Sdrh } 114217b90b53Sdanielk1977 return "disk" 1143d19744f3Sdrh } 1144d19744f3Sdrh } 1145d19744f3Sdrh return "unknown" 1146d19744f3Sdrh} 1147d19744f3Sdrh 11484ee09b4bSdrh# Application_ID 11494ee09b4bSdrh# 11504ee09b4bSdrhdo_test pragma-8.3.1 { 11514ee09b4bSdrh execsql { 11524ee09b4bSdrh PRAGMA application_id; 11534ee09b4bSdrh } 11544ee09b4bSdrh} {0} 11554ee09b4bSdrhdo_test pragma-8.3.2 { 11564ee09b4bSdrh execsql {PRAGMA Application_ID(12345); PRAGMA application_id;} 11574ee09b4bSdrh} {12345} 11589a09a3caStpoindex 11599a09a3caStpoindex# Test temp_store and temp_store_directory pragmas 11609a09a3caStpoindex# 1161268283bcSdrhifcapable pager_pragmas { 11629a09a3caStpoindexdo_test pragma-9.1 { 11639a09a3caStpoindex db close 11649a09a3caStpoindex sqlite3 db test.db 11659a09a3caStpoindex execsql { 11669a09a3caStpoindex PRAGMA temp_store; 11679a09a3caStpoindex } 11689a09a3caStpoindex} {0} 1169d19744f3Sdrhif {$TEMP_STORE<=1} { 1170d19744f3Sdrh do_test pragma-9.1.1 { 1171d19744f3Sdrh check_temp_store 1172d19744f3Sdrh } {disk} 1173d19744f3Sdrh} else { 1174d19744f3Sdrh do_test pragma-9.1.1 { 1175d19744f3Sdrh check_temp_store 1176d19744f3Sdrh } {memory} 1177d19744f3Sdrh} 1178d19744f3Sdrh 11799a09a3caStpoindexdo_test pragma-9.2 { 1180d19744f3Sdrh db close 1181d19744f3Sdrh sqlite3 db test.db 11829a09a3caStpoindex execsql { 11839a09a3caStpoindex PRAGMA temp_store=file; 11849a09a3caStpoindex PRAGMA temp_store; 11859a09a3caStpoindex } 11869a09a3caStpoindex} {1} 1187d19744f3Sdrhif {$TEMP_STORE==3} { 1188d19744f3Sdrh # When TEMP_STORE is 3, always use memory regardless of pragma settings. 1189d19744f3Sdrh do_test pragma-9.2.1 { 1190d19744f3Sdrh check_temp_store 1191d19744f3Sdrh } {memory} 1192d19744f3Sdrh} else { 1193d19744f3Sdrh do_test pragma-9.2.1 { 1194d19744f3Sdrh check_temp_store 1195d19744f3Sdrh } {disk} 1196d19744f3Sdrh} 1197d19744f3Sdrh 11989a09a3caStpoindexdo_test pragma-9.3 { 1199d19744f3Sdrh db close 1200d19744f3Sdrh sqlite3 db test.db 12019a09a3caStpoindex execsql { 12029a09a3caStpoindex PRAGMA temp_store=memory; 12039a09a3caStpoindex PRAGMA temp_store; 12049a09a3caStpoindex } 12059a09a3caStpoindex} {2} 1206d19744f3Sdrhif {$TEMP_STORE==0} { 1207d19744f3Sdrh # When TEMP_STORE is 0, always use the disk regardless of pragma settings. 1208d19744f3Sdrh do_test pragma-9.3.1 { 1209d19744f3Sdrh check_temp_store 1210d19744f3Sdrh } {disk} 1211d19744f3Sdrh} else { 1212d19744f3Sdrh do_test pragma-9.3.1 { 1213d19744f3Sdrh check_temp_store 1214d19744f3Sdrh } {memory} 1215d19744f3Sdrh} 1216d19744f3Sdrh 12179a09a3caStpoindexdo_test pragma-9.4 { 12189a09a3caStpoindex execsql { 12199a09a3caStpoindex PRAGMA temp_store_directory; 12209a09a3caStpoindex } 12219a09a3caStpoindex} {} 122278f82d1eSdrhifcapable wsd { 12239a09a3caStpoindex do_test pragma-9.5 { 1224f8a78464Smistachkin set pwd [string map {' ''} [file nativename [get_pwd]]] 1225268283bcSdrh execsql " 1226268283bcSdrh PRAGMA temp_store_directory='$pwd'; 12279a09a3caStpoindex " 12289a09a3caStpoindex } {} 12299a09a3caStpoindex do_test pragma-9.6 { 12309a09a3caStpoindex execsql { 12319a09a3caStpoindex PRAGMA temp_store_directory; 12329a09a3caStpoindex } 1233f8a78464Smistachkin } [list [file nativename [get_pwd]]] 12349a09a3caStpoindex do_test pragma-9.7 { 1235268283bcSdrh catchsql { 12369a09a3caStpoindex PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR'; 12379a09a3caStpoindex } 1238268283bcSdrh } {1 {not a writable directory}} 12399a09a3caStpoindex do_test pragma-9.8 { 12409a09a3caStpoindex execsql { 12419a09a3caStpoindex PRAGMA temp_store_directory=''; 12429a09a3caStpoindex } 12439a09a3caStpoindex } {} 12441e9daa6aSdrh if {![info exists TEMP_STORE] || $TEMP_STORE<=1} { 124553c0f748Sdanielk1977 ifcapable tempdb { 12469a09a3caStpoindex do_test pragma-9.9 { 12479a09a3caStpoindex execsql { 12489a09a3caStpoindex PRAGMA temp_store_directory; 12499a09a3caStpoindex PRAGMA temp_store=FILE; 12509a09a3caStpoindex CREATE TEMP TABLE temp_store_directory_test(a integer); 12519a09a3caStpoindex INSERT INTO temp_store_directory_test values (2); 12529a09a3caStpoindex SELECT * FROM temp_store_directory_test; 12539a09a3caStpoindex } 12549a09a3caStpoindex } {2} 12559a09a3caStpoindex do_test pragma-9.10 { 1256268283bcSdrh catchsql " 1257268283bcSdrh PRAGMA temp_store_directory='$pwd'; 12589a09a3caStpoindex SELECT * FROM temp_store_directory_test; 12599a09a3caStpoindex " 1260268283bcSdrh } {1 {no such table: temp_store_directory_test}} 12611e9daa6aSdrh } 12621e9daa6aSdrh } 126378f82d1eSdrh} 126495b289b6Sdanielk1977do_test pragma-9.11 { 126595b289b6Sdanielk1977 execsql { 126695b289b6Sdanielk1977 PRAGMA temp_store = 0; 126795b289b6Sdanielk1977 PRAGMA temp_store; 126895b289b6Sdanielk1977 } 126995b289b6Sdanielk1977} {0} 127095b289b6Sdanielk1977do_test pragma-9.12 { 127195b289b6Sdanielk1977 execsql { 127295b289b6Sdanielk1977 PRAGMA temp_store = 1; 127395b289b6Sdanielk1977 PRAGMA temp_store; 127495b289b6Sdanielk1977 } 127595b289b6Sdanielk1977} {1} 127695b289b6Sdanielk1977do_test pragma-9.13 { 127795b289b6Sdanielk1977 execsql { 127895b289b6Sdanielk1977 PRAGMA temp_store = 2; 127995b289b6Sdanielk1977 PRAGMA temp_store; 128095b289b6Sdanielk1977 } 128195b289b6Sdanielk1977} {2} 128295b289b6Sdanielk1977do_test pragma-9.14 { 128395b289b6Sdanielk1977 execsql { 128495b289b6Sdanielk1977 PRAGMA temp_store = 3; 128595b289b6Sdanielk1977 PRAGMA temp_store; 128695b289b6Sdanielk1977 } 128795b289b6Sdanielk1977} {0} 128895b289b6Sdanielk1977do_test pragma-9.15 { 128995b289b6Sdanielk1977 catchsql { 129095b289b6Sdanielk1977 BEGIN EXCLUSIVE; 129195b289b6Sdanielk1977 CREATE TEMP TABLE temp_table(t); 129295b289b6Sdanielk1977 INSERT INTO temp_table VALUES('valuable data'); 129395b289b6Sdanielk1977 PRAGMA temp_store = 1; 129495b289b6Sdanielk1977 } 129595b289b6Sdanielk1977} {1 {temporary storage cannot be changed from within a transaction}} 129695b289b6Sdanielk1977do_test pragma-9.16 { 129795b289b6Sdanielk1977 execsql { 129895b289b6Sdanielk1977 SELECT * FROM temp_table; 129995b289b6Sdanielk1977 COMMIT; 130095b289b6Sdanielk1977 } 130195b289b6Sdanielk1977} {{valuable data}} 1302983e2309Sdanielk1977 1303983e2309Sdanielk1977do_test pragma-9.17 { 1304983e2309Sdanielk1977 execsql { 1305983e2309Sdanielk1977 INSERT INTO temp_table VALUES('valuable data II'); 1306983e2309Sdanielk1977 SELECT * FROM temp_table; 1307983e2309Sdanielk1977 } 1308983e2309Sdanielk1977} {{valuable data} {valuable data II}} 1309983e2309Sdanielk1977 1310983e2309Sdanielk1977do_test pragma-9.18 { 1311983e2309Sdanielk1977 set rc [catch { 1312983e2309Sdanielk1977 db eval {SELECT t FROM temp_table} { 1313983e2309Sdanielk1977 execsql {pragma temp_store = 1} 1314983e2309Sdanielk1977 } 1315983e2309Sdanielk1977 } msg] 1316983e2309Sdanielk1977 list $rc $msg 1317983e2309Sdanielk1977} {1 {temporary storage cannot be changed from within a transaction}} 1318983e2309Sdanielk1977 1319268283bcSdrh} ;# ifcapable pager_pragmas 13209a09a3caStpoindex 1321cc6bd383Sdanielk1977ifcapable trigger { 1322cc6bd383Sdanielk1977 1323cc6bd383Sdanielk1977do_test pragma-10.0 { 1324cc6bd383Sdanielk1977 catchsql { 1325cc6bd383Sdanielk1977 DROP TABLE main.t1; 1326cc6bd383Sdanielk1977 } 1327cc6bd383Sdanielk1977 execsql { 1328cc6bd383Sdanielk1977 PRAGMA count_changes = 1; 1329cc6bd383Sdanielk1977 1330cc6bd383Sdanielk1977 CREATE TABLE t1(a PRIMARY KEY); 1331cc6bd383Sdanielk1977 CREATE TABLE t1_mirror(a); 1332cc6bd383Sdanielk1977 CREATE TABLE t1_mirror2(a); 1333cc6bd383Sdanielk1977 CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN 1334cc6bd383Sdanielk1977 INSERT INTO t1_mirror VALUES(new.a); 1335cc6bd383Sdanielk1977 END; 1336cc6bd383Sdanielk1977 CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN 1337cc6bd383Sdanielk1977 INSERT INTO t1_mirror2 VALUES(new.a); 1338cc6bd383Sdanielk1977 END; 1339cc6bd383Sdanielk1977 CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN 1340cc6bd383Sdanielk1977 UPDATE t1_mirror SET a = new.a WHERE a = old.a; 1341cc6bd383Sdanielk1977 END; 1342cc6bd383Sdanielk1977 CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN 1343cc6bd383Sdanielk1977 UPDATE t1_mirror2 SET a = new.a WHERE a = old.a; 1344cc6bd383Sdanielk1977 END; 1345cc6bd383Sdanielk1977 CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN 1346cc6bd383Sdanielk1977 DELETE FROM t1_mirror WHERE a = old.a; 1347cc6bd383Sdanielk1977 END; 1348cc6bd383Sdanielk1977 CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN 1349cc6bd383Sdanielk1977 DELETE FROM t1_mirror2 WHERE a = old.a; 1350cc6bd383Sdanielk1977 END; 1351cc6bd383Sdanielk1977 } 1352cc6bd383Sdanielk1977} {} 1353cc6bd383Sdanielk1977 1354cc6bd383Sdanielk1977do_test pragma-10.1 { 1355cc6bd383Sdanielk1977 execsql { 1356cc6bd383Sdanielk1977 INSERT INTO t1 VALUES(randstr(10,10)); 1357cc6bd383Sdanielk1977 } 1358cc6bd383Sdanielk1977} {1} 1359cc6bd383Sdanielk1977do_test pragma-10.2 { 1360cc6bd383Sdanielk1977 execsql { 1361cc6bd383Sdanielk1977 UPDATE t1 SET a = randstr(10,10); 1362cc6bd383Sdanielk1977 } 1363cc6bd383Sdanielk1977} {1} 1364cc6bd383Sdanielk1977do_test pragma-10.3 { 1365cc6bd383Sdanielk1977 execsql { 1366cc6bd383Sdanielk1977 DELETE FROM t1; 1367cc6bd383Sdanielk1977 } 1368cc6bd383Sdanielk1977} {1} 1369cc6bd383Sdanielk1977 1370cc6bd383Sdanielk1977} ;# ifcapable trigger 1371cc6bd383Sdanielk1977 137248af65aeSdanielk1977ifcapable schema_pragmas { 137348af65aeSdanielk1977 do_test pragma-11.1 { 137448af65aeSdanielk1977 execsql2 { 137548af65aeSdanielk1977 pragma collation_list; 137648af65aeSdanielk1977 } 13772d823315Sdrh } {seq 0 name RTRIM seq 1 name NOCASE seq 2 name BINARY} 137848af65aeSdanielk1977 do_test pragma-11.2 { 137948af65aeSdanielk1977 db collate New_Collation blah... 138048af65aeSdanielk1977 execsql { 138148af65aeSdanielk1977 pragma collation_list; 138248af65aeSdanielk1977 } 13832d823315Sdrh } {0 New_Collation 1 RTRIM 2 NOCASE 3 BINARY} 138448af65aeSdanielk1977} 138548af65aeSdanielk1977 1386ddfb2f03Sdanielk1977ifcapable schema_pragmas&&tempdb { 1387ddfb2f03Sdanielk1977 do_test pragma-12.1 { 1388ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1389ddfb2f03Sdanielk1977 execsql { 1390ddfb2f03Sdanielk1977 PRAGMA temp.table_info('abc'); 1391ddfb2f03Sdanielk1977 } db2 1392ddfb2f03Sdanielk1977 } {} 1393ddfb2f03Sdanielk1977 db2 close 1394ddfb2f03Sdanielk1977 1395ddfb2f03Sdanielk1977 do_test pragma-12.2 { 1396ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1397ddfb2f03Sdanielk1977 execsql { 1398ddfb2f03Sdanielk1977 PRAGMA temp.default_cache_size = 200; 1399ddfb2f03Sdanielk1977 PRAGMA temp.default_cache_size; 1400ddfb2f03Sdanielk1977 } db2 1401ddfb2f03Sdanielk1977 } {200} 1402ddfb2f03Sdanielk1977 db2 close 1403ddfb2f03Sdanielk1977 1404ddfb2f03Sdanielk1977 do_test pragma-12.3 { 1405ddfb2f03Sdanielk1977 sqlite3 db2 test.db 1406ddfb2f03Sdanielk1977 execsql { 1407ddfb2f03Sdanielk1977 PRAGMA temp.cache_size = 400; 1408ddfb2f03Sdanielk1977 PRAGMA temp.cache_size; 1409ddfb2f03Sdanielk1977 } db2 1410ddfb2f03Sdanielk1977 } {400} 1411ddfb2f03Sdanielk1977 db2 close 1412ddfb2f03Sdanielk1977} 1413ddfb2f03Sdanielk1977 14144b2688abSdanielk1977ifcapable bloblit { 14154b2688abSdanielk1977 141605a82983Sdrhdo_test pragma-13.1 { 141705a82983Sdrh execsql { 141805a82983Sdrh DROP TABLE IF EXISTS t4; 141905a82983Sdrh PRAGMA vdbe_trace=on; 142005a82983Sdrh PRAGMA vdbe_listing=on; 142105a82983Sdrh PRAGMA sql_trace=on; 142205a82983Sdrh CREATE TABLE t4(a INTEGER PRIMARY KEY,b); 142305a82983Sdrh INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789'); 142405a82983Sdrh INSERT INTO t4(b) VALUES(randstr(30,30)); 142505a82983Sdrh INSERT INTO t4(b) VALUES(1.23456); 142605a82983Sdrh INSERT INTO t4(b) VALUES(NULL); 142705a82983Sdrh INSERT INTO t4(b) VALUES(0); 142805a82983Sdrh INSERT INTO t4(b) SELECT b||b||b||b FROM t4; 142905a82983Sdrh SELECT * FROM t4; 143005a82983Sdrh } 143105a82983Sdrh execsql { 143205a82983Sdrh PRAGMA vdbe_trace=off; 143305a82983Sdrh PRAGMA vdbe_listing=off; 143405a82983Sdrh PRAGMA sql_trace=off; 143505a82983Sdrh } 143605a82983Sdrh} {} 143705a82983Sdrh 14384b2688abSdanielk1977} ;# ifcapable bloblit 14394b2688abSdanielk1977 144059a93791Sdanielk1977ifcapable pager_pragmas { 144159a93791Sdanielk1977 db close 1442fda06befSmistachkin forcedelete test.db 144359a93791Sdanielk1977 sqlite3 db test.db 144459a93791Sdanielk1977 1445b3366b99Sdrh # EVIDENCE-OF: R-15672-33611 PRAGMA schema.page_count; Return the total 1446b3366b99Sdrh # number of pages in the database file. 144751a74d4cSdrh # 144859a93791Sdanielk1977 do_test pragma-14.1 { 144959a93791Sdanielk1977 execsql { pragma auto_vacuum = 0 } 145051a74d4cSdrh execsql { pragma page_count; pragma main.page_count } 145151a74d4cSdrh } {0 0} 145259a93791Sdanielk1977 145359a93791Sdanielk1977 do_test pragma-14.2 { 145459a93791Sdanielk1977 execsql { 145559a93791Sdanielk1977 CREATE TABLE abc(a, b, c); 145659a93791Sdanielk1977 PRAGMA page_count; 145751a74d4cSdrh PRAGMA main.page_count; 145851a74d4cSdrh PRAGMA temp.page_count; 145959a93791Sdanielk1977 } 146051a74d4cSdrh } {2 2 0} 14615d16a9a6Sdrh do_test pragma-14.2uc { 14625d16a9a6Sdrh execsql {pragma PAGE_COUNT} 14635d16a9a6Sdrh } {2} 146459a93791Sdanielk1977 146559a93791Sdanielk1977 do_test pragma-14.3 { 146659a93791Sdanielk1977 execsql { 146759a93791Sdanielk1977 BEGIN; 146859a93791Sdanielk1977 CREATE TABLE def(a, b, c); 146959a93791Sdanielk1977 PRAGMA page_count; 147059a93791Sdanielk1977 } 147159a93791Sdanielk1977 } {3} 14725d16a9a6Sdrh do_test pragma-14.3uc { 14735d16a9a6Sdrh execsql {pragma PAGE_COUNT} 14745d16a9a6Sdrh } {3} 147559a93791Sdanielk1977 147659a93791Sdanielk1977 do_test pragma-14.4 { 147759a93791Sdanielk1977 set page_size [db one {pragma page_size}] 147859a93791Sdanielk1977 expr [file size test.db] / $page_size 147959a93791Sdanielk1977 } {2} 148059a93791Sdanielk1977 148159a93791Sdanielk1977 do_test pragma-14.5 { 148259a93791Sdanielk1977 execsql { 148359a93791Sdanielk1977 ROLLBACK; 148459a93791Sdanielk1977 PRAGMA page_count; 148559a93791Sdanielk1977 } 148659a93791Sdanielk1977 } {2} 148759a93791Sdanielk1977 148859a93791Sdanielk1977 do_test pragma-14.6 { 1489fda06befSmistachkin forcedelete test2.db 149059a93791Sdanielk1977 sqlite3 db2 test2.db 149159a93791Sdanielk1977 execsql { 149259a93791Sdanielk1977 PRAGMA auto_vacuum = 0; 149359a93791Sdanielk1977 CREATE TABLE t1(a, b, c); 149459a93791Sdanielk1977 CREATE TABLE t2(a, b, c); 149559a93791Sdanielk1977 CREATE TABLE t3(a, b, c); 149659a93791Sdanielk1977 CREATE TABLE t4(a, b, c); 149759a93791Sdanielk1977 } db2 149859a93791Sdanielk1977 db2 close 149959a93791Sdanielk1977 execsql { 150059a93791Sdanielk1977 ATTACH 'test2.db' AS aux; 150159a93791Sdanielk1977 PRAGMA aux.page_count; 150259a93791Sdanielk1977 } 150359a93791Sdanielk1977 } {5} 15045d16a9a6Sdrh do_test pragma-14.6uc { 15055d16a9a6Sdrh execsql {pragma AUX.PAGE_COUNT} 15065d16a9a6Sdrh } {5} 150759a93791Sdanielk1977} 150859a93791Sdanielk1977 15098cf6c554Sdanielk1977# Test that the value set using the cache_size pragma is not reset when the 15108cf6c554Sdanielk1977# schema is reloaded. 15118cf6c554Sdanielk1977# 15128cf6c554Sdanielk1977ifcapable pager_pragmas { 15138cf6c554Sdanielk1977 db close 15148cf6c554Sdanielk1977 sqlite3 db test.db 15158cf6c554Sdanielk1977 do_test pragma-15.1 { 15168cf6c554Sdanielk1977 execsql { 15178cf6c554Sdanielk1977 PRAGMA cache_size=59; 15188cf6c554Sdanielk1977 PRAGMA cache_size; 15198cf6c554Sdanielk1977 } 15208cf6c554Sdanielk1977 } {59} 15218cf6c554Sdanielk1977 do_test pragma-15.2 { 15228cf6c554Sdanielk1977 sqlite3 db2 test.db 15238cf6c554Sdanielk1977 execsql { 15248cf6c554Sdanielk1977 CREATE TABLE newtable(a, b, c); 15258cf6c554Sdanielk1977 } db2 15268cf6c554Sdanielk1977 db2 close 15278cf6c554Sdanielk1977 } {} 15288cf6c554Sdanielk1977 do_test pragma-15.3 { 15298cf6c554Sdanielk1977 # Evaluating this statement will cause the schema to be reloaded (because 15308cf6c554Sdanielk1977 # the schema was changed by another connection in pragma-15.2). At one 15318cf6c554Sdanielk1977 # point there was a bug that reset the cache_size to its default value 15328cf6c554Sdanielk1977 # when this happened. 15338cf6c554Sdanielk1977 execsql { SELECT * FROM sqlite_master } 15348cf6c554Sdanielk1977 execsql { PRAGMA cache_size } 15358cf6c554Sdanielk1977 } {59} 15368cf6c554Sdanielk1977} 15378cf6c554Sdanielk1977 15385558a8a6Sdanielk1977# Reset the sqlite3_temp_directory variable for the next run of tests: 15395558a8a6Sdanielk1977sqlite3 dbX :memory: 15405558a8a6Sdanielk1977dbX eval {PRAGMA temp_store_directory = ""} 15415558a8a6Sdanielk1977dbX close 15425558a8a6Sdanielk1977 1543838cce43Sdanielk1977ifcapable lock_proxy_pragmas&&prefer_proxy_locking { 1544aebf413dSaswift set sqlite_hostid_num 1 1545aebf413dSaswift 1546aebf413dSaswift set using_proxy 0 1547aebf413dSaswift foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] { 1548aebf413dSaswift set using_proxy $value 1549aebf413dSaswift } 1550aebf413dSaswift 1551aebf413dSaswift # Test the lock_proxy_file pragmas. 1552aebf413dSaswift # 1553aebf413dSaswift db close 1554aebf413dSaswift set env(SQLITE_FORCE_PROXY_LOCKING) "0" 1555aebf413dSaswift 1556aebf413dSaswift sqlite3 db test.db 1557aebf413dSaswift do_test pragma-16.1 { 1558aebf413dSaswift execsql { 1559aebf413dSaswift PRAGMA lock_proxy_file="mylittleproxy"; 1560aebf413dSaswift select * from sqlite_master; 1561aebf413dSaswift } 1562aebf413dSaswift execsql { 1563aebf413dSaswift PRAGMA lock_proxy_file; 1564aebf413dSaswift } 1565aebf413dSaswift } {mylittleproxy} 1566aebf413dSaswift 1567aebf413dSaswift do_test pragma-16.2 { 1568aebf413dSaswift sqlite3 db2 test.db 1569aebf413dSaswift execsql { 1570aebf413dSaswift PRAGMA lock_proxy_file="mylittleproxy"; 1571aebf413dSaswift } db2 1572aebf413dSaswift } {} 1573aebf413dSaswift 1574aebf413dSaswift db2 close 1575aebf413dSaswift do_test pragma-16.2.1 { 1576aebf413dSaswift sqlite3 db2 test.db 1577aebf413dSaswift execsql { 1578aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1579aebf413dSaswift select * from sqlite_master; 1580aebf413dSaswift } db2 1581aebf413dSaswift execsql { 1582aebf413dSaswift PRAGMA lock_proxy_file; 1583aebf413dSaswift } db2 1584aebf413dSaswift } {mylittleproxy} 1585aebf413dSaswift 1586aebf413dSaswift db2 close 1587aebf413dSaswift do_test pragma-16.3 { 1588aebf413dSaswift sqlite3 db2 test.db 1589aebf413dSaswift execsql { 1590aebf413dSaswift PRAGMA lock_proxy_file="myotherproxy"; 1591aebf413dSaswift } db2 1592aebf413dSaswift catchsql { 1593aebf413dSaswift select * from sqlite_master; 1594aebf413dSaswift } db2 1595aebf413dSaswift } {1 {database is locked}} 1596aebf413dSaswift 1597aebf413dSaswift do_test pragma-16.4 { 1598aebf413dSaswift db2 close 1599aebf413dSaswift db close 1600aebf413dSaswift sqlite3 db2 test.db 1601aebf413dSaswift execsql { 1602aebf413dSaswift PRAGMA lock_proxy_file="myoriginalproxy"; 1603aebf413dSaswift PRAGMA lock_proxy_file="myotherproxy"; 1604aebf413dSaswift PRAGMA lock_proxy_file; 1605aebf413dSaswift } db2 1606aebf413dSaswift } {myotherproxy} 1607aebf413dSaswift 1608aebf413dSaswift db2 close 1609aebf413dSaswift set env(SQLITE_FORCE_PROXY_LOCKING) "1" 1610aebf413dSaswift do_test pragma-16.5 { 1611aebf413dSaswift sqlite3 db2 test.db 1612aebf413dSaswift execsql { 1613aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1614aebf413dSaswift PRAGMA lock_proxy_file; 1615aebf413dSaswift } db2 1616aebf413dSaswift } {myotherproxy} 1617aebf413dSaswift 1618aebf413dSaswift do_test pragma-16.6 { 1619aebf413dSaswift db2 close 1620aebf413dSaswift sqlite3 db2 test2.db 1621aebf413dSaswift set lockpath [execsql { 1622aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1623aebf413dSaswift PRAGMA lock_proxy_file; 1624aebf413dSaswift } db2] 1625aebf413dSaswift string match "*test2.db:auto:" $lockpath 1626aebf413dSaswift } {1} 1627aebf413dSaswift 1628aebf413dSaswift set sqlite_hostid_num 2 1629aebf413dSaswift do_test pragma-16.7 { 163014d14607Sdan list [catch { 1631aebf413dSaswift sqlite3 db test2.db 1632aebf413dSaswift execsql { 1633aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1634aebf413dSaswift select * from sqlite_master; 1635aebf413dSaswift } 163614d14607Sdan } msg] $msg 1637aebf413dSaswift } {1 {database is locked}} 1638aebf413dSaswift db close 1639aebf413dSaswift 1640aebf413dSaswift do_test pragma-16.8 { 164114d14607Sdan list [catch { 1642aebf413dSaswift sqlite3 db test2.db 164314d14607Sdan execsql { select * from sqlite_master } 164414d14607Sdan } msg] $msg 1645aebf413dSaswift } {1 {database is locked}} 1646aebf413dSaswift 1647aebf413dSaswift db2 close 1648aebf413dSaswift do_test pragma-16.8.1 { 1649aebf413dSaswift execsql { 1650aebf413dSaswift PRAGMA lock_proxy_file="yetanotherproxy"; 1651aebf413dSaswift PRAGMA lock_proxy_file; 1652aebf413dSaswift } 1653aebf413dSaswift } {yetanotherproxy} 1654aebf413dSaswift do_test pragma-16.8.2 { 1655aebf413dSaswift execsql { 1656aebf413dSaswift create table mine(x); 1657aebf413dSaswift } 1658aebf413dSaswift } {} 1659aebf413dSaswift 1660aebf413dSaswift db close 1661aebf413dSaswift do_test pragma-16.9 { 1662aebf413dSaswift sqlite3 db proxytest.db 1663aebf413dSaswift set lockpath2 [execsql { 1664aebf413dSaswift PRAGMA lock_proxy_file=":auto:"; 1665aebf413dSaswift PRAGMA lock_proxy_file; 1666aebf413dSaswift } db] 1667aebf413dSaswift string match "*proxytest.db:auto:" $lockpath2 1668aebf413dSaswift } {1} 1669aebf413dSaswift 1670aebf413dSaswift set env(SQLITE_FORCE_PROXY_LOCKING) $using_proxy 1671aebf413dSaswift set sqlite_hostid_num 0 1672aebf413dSaswift} 1673d2cb50b7Sdrh 1674d2cb50b7Sdrh# Parsing of auto_vacuum settings. 1675d2cb50b7Sdrh# 1676d2cb50b7Sdrhforeach {autovac_setting val} { 1677d2cb50b7Sdrh 0 0 1678d2cb50b7Sdrh 1 1 1679d2cb50b7Sdrh 2 2 1680d2cb50b7Sdrh 3 0 1681d2cb50b7Sdrh -1 0 1682d2cb50b7Sdrh none 0 1683d2cb50b7Sdrh NONE 0 1684d2cb50b7Sdrh NoNe 0 1685d2cb50b7Sdrh full 1 1686d2cb50b7Sdrh FULL 1 1687d2cb50b7Sdrh incremental 2 1688d2cb50b7Sdrh INCREMENTAL 2 1689d2cb50b7Sdrh -1234 0 1690d2cb50b7Sdrh 1234 0 1691d2cb50b7Sdrh} { 1692d2cb50b7Sdrh do_test pragma-17.1.$autovac_setting { 1693d2cb50b7Sdrh catch {db close} 1694d2cb50b7Sdrh sqlite3 db :memory: 1695d2cb50b7Sdrh execsql " 1696d2cb50b7Sdrh PRAGMA auto_vacuum=$::autovac_setting; 1697d2cb50b7Sdrh PRAGMA auto_vacuum; 1698d2cb50b7Sdrh " 1699d2cb50b7Sdrh } $val 1700d2cb50b7Sdrh} 1701d2cb50b7Sdrh 1702d2cb50b7Sdrh# Parsing of temp_store settings. 1703d2cb50b7Sdrh# 1704d2cb50b7Sdrhforeach {temp_setting val} { 1705d2cb50b7Sdrh 0 0 1706d2cb50b7Sdrh 1 1 1707d2cb50b7Sdrh 2 2 1708d2cb50b7Sdrh 3 0 1709d2cb50b7Sdrh -1 0 1710d2cb50b7Sdrh file 1 1711d2cb50b7Sdrh FILE 1 1712d2cb50b7Sdrh fIlE 1 1713d2cb50b7Sdrh memory 2 1714d2cb50b7Sdrh MEMORY 2 1715d2cb50b7Sdrh MeMoRy 2 1716d2cb50b7Sdrh} { 1717d2cb50b7Sdrh do_test pragma-18.1.$temp_setting { 1718d2cb50b7Sdrh catch {db close} 1719d2cb50b7Sdrh sqlite3 db :memory: 1720d2cb50b7Sdrh execsql " 1721d2cb50b7Sdrh PRAGMA temp_store=$::temp_setting; 1722d2cb50b7Sdrh PRAGMA temp_store=$::temp_setting; 1723d2cb50b7Sdrh PRAGMA temp_store; 1724d2cb50b7Sdrh " 1725d2cb50b7Sdrh } $val 1726d2cb50b7Sdrh} 1727d2cb50b7Sdrh 172892c700dbSdrh# The SQLITE_FCNTL_PRAGMA logic, with error handling. 172992c700dbSdrh# 173092c700dbSdrhdb close 173192c700dbSdrhtestvfs tvfs 173292c700dbSdrhsqlite3 db test.db -vfs tvfs 173392c700dbSdrhdo_test pragma-19.1 { 173492c700dbSdrh catchsql {PRAGMA error} 1735a690ff36Sdrh} {1 {SQL logic error}} 173692c700dbSdrhdo_test pragma-19.2 { 173792c700dbSdrh catchsql {PRAGMA error='This is the error message'} 173892c700dbSdrh} {1 {This is the error message}} 173992c700dbSdrhdo_test pragma-19.3 { 174092c700dbSdrh catchsql {PRAGMA error='7 This is the error message'} 174192c700dbSdrh} {1 {This is the error message}} 174292c700dbSdrhdo_test pragma-19.4 { 174392c700dbSdrh catchsql {PRAGMA error=7} 174492c700dbSdrh} {1 {out of memory}} 1745c8517f61Sdrhdo_test pragma-19.5 { 17465b044545Smistachkin file tail [lindex [execsql {PRAGMA filename}] 0] 1747c8517f61Sdrh} {test.db} 174892c700dbSdrh 1749cc71645bSdrhif {$tcl_platform(platform)=="windows"} { 1750a112d140Smistachkin# Test data_store_directory pragma 1751a112d140Smistachkin# 1752a112d140Smistachkindb close 1753a112d140Smistachkinsqlite3 db test.db 1754a112d140Smistachkinfile mkdir data_dir 1755a112d140Smistachkindo_test pragma-20.1 { 1756a112d140Smistachkin catchsql {PRAGMA data_store_directory} 1757a112d140Smistachkin} {0 {}} 1758a112d140Smistachkindo_test pragma-20.2 { 1759a112d140Smistachkin set pwd [string map {' ''} [file nativename [get_pwd]]] 1760a112d140Smistachkin catchsql "PRAGMA data_store_directory='$pwd';" 1761a112d140Smistachkin} {0 {}} 1762a112d140Smistachkindo_test pragma-20.3 { 1763a112d140Smistachkin catchsql {PRAGMA data_store_directory} 1764a112d140Smistachkin} [list 0 [list [file nativename [get_pwd]]]] 1765a112d140Smistachkindo_test pragma-20.4 { 1766a112d140Smistachkin set pwd [string map {' ''} [file nativename \ 1767a112d140Smistachkin [file join [get_pwd] data_dir]]] 1768a112d140Smistachkin catchsql "PRAGMA data_store_directory='$pwd';" 1769a112d140Smistachkin} {0 {}} 1770a112d140Smistachkindo_test pragma-20.5 { 1771a112d140Smistachkin sqlite3 db2 test2.db 1772a112d140Smistachkin catchsql "PRAGMA database_list;" db2 1773a112d140Smistachkin} [list 0 [list 0 main [file nativename \ 1774a112d140Smistachkin [file join [get_pwd] data_dir test2.db]]]] 1775a112d140Smistachkincatch {db2 close} 1776a112d140Smistachkindo_test pragma-20.6 { 1777a112d140Smistachkin sqlite3 db2 [file join [get_pwd] test2.db] 1778a112d140Smistachkin catchsql "PRAGMA database_list;" db2 1779a112d140Smistachkin} [list 0 [list 0 main [file nativename \ 1780a112d140Smistachkin [file join [get_pwd] test2.db]]]] 1781a112d140Smistachkincatch {db2 close} 1782a112d140Smistachkindo_test pragma-20.7 { 1783a112d140Smistachkin catchsql "PRAGMA data_store_directory='';" 1784a112d140Smistachkin} {0 {}} 1785a112d140Smistachkindo_test pragma-20.8 { 1786a112d140Smistachkin catchsql {PRAGMA data_store_directory} 1787a112d140Smistachkin} {0 {}} 178892c700dbSdrh 1789a112d140Smistachkinforcedelete data_dir 1790cc71645bSdrh} ;# endif windows 1791cd61c281Sdrh 17921fed5dabSdandatabase_may_be_corrupt 17937da56b4fSdrhif {![nonzero_reserved_bytes]} { 17941fed5dabSdan 17955885e762Sdan do_test 21.1 { 17965885e762Sdan # Create a corrupt database in testerr.db. And a non-corrupt at test.db. 17975885e762Sdan # 17985885e762Sdan db close 17995885e762Sdan forcedelete test.db 18005885e762Sdan sqlite3 db test.db 18015885e762Sdan execsql { 18025885e762Sdan PRAGMA page_size = 1024; 18035885e762Sdan PRAGMA auto_vacuum = 0; 18045885e762Sdan CREATE TABLE t1(a PRIMARY KEY, b); 18055885e762Sdan INSERT INTO t1 VALUES(1, 1); 18065885e762Sdan } 18075885e762Sdan for {set i 0} {$i < 10} {incr i} { 18085885e762Sdan execsql { INSERT INTO t1 SELECT a + (1 << $i), b + (1 << $i) FROM t1 } 18095885e762Sdan } 18105885e762Sdan db close 18115885e762Sdan forcecopy test.db testerr.db 18125885e762Sdan hexio_write testerr.db 15000 [string repeat 55 100] 18135885e762Sdan } {100} 18145885e762Sdan 18155885e762Sdan set mainerr {*** in database main *** 18165885e762SdanMultiple uses for byte 672 of page 15} 18175885e762Sdan set auxerr {*** in database aux *** 18185885e762SdanMultiple uses for byte 672 of page 15} 18195885e762Sdan 1820597515d7Sdan set mainerr {/{\*\*\* in database main \*\*\* 1821597515d7SdanMultiple uses for byte 672 of page 15}.*/} 1822597515d7Sdan set auxerr {/{\*\*\* in database aux \*\*\* 1823597515d7SdanMultiple uses for byte 672 of page 15}.*/} 1824597515d7Sdan 18255885e762Sdan do_test 22.2 { 18265885e762Sdan catch { db close } 18275885e762Sdan sqlite3 db testerr.db 18285885e762Sdan execsql { PRAGMA integrity_check } 1829597515d7Sdan } $mainerr 18305885e762Sdan 18315885e762Sdan do_test 22.3.1 { 18325885e762Sdan catch { db close } 18335885e762Sdan sqlite3 db test.db 18345885e762Sdan execsql { 18355885e762Sdan ATTACH 'testerr.db' AS 'aux'; 18365885e762Sdan PRAGMA integrity_check; 18375885e762Sdan } 1838597515d7Sdan } $auxerr 18395885e762Sdan do_test 22.3.2 { 18405885e762Sdan execsql { PRAGMA main.integrity_check; } 18415885e762Sdan } {ok} 18425885e762Sdan do_test 22.3.3 { 18435885e762Sdan execsql { PRAGMA aux.integrity_check; } 1844597515d7Sdan } $auxerr 18455885e762Sdan 18465885e762Sdan do_test 22.4.1 { 18475885e762Sdan catch { db close } 18485885e762Sdan sqlite3 db testerr.db 18495885e762Sdan execsql { 18505885e762Sdan ATTACH 'test.db' AS 'aux'; 18515885e762Sdan PRAGMA integrity_check; 18525885e762Sdan } 1853597515d7Sdan } $mainerr 18545885e762Sdan do_test 22.4.2 { 18555885e762Sdan execsql { PRAGMA main.integrity_check; } 1856597515d7Sdan } $mainerr 18575885e762Sdan do_test 22.4.3 { 18585885e762Sdan execsql { PRAGMA aux.integrity_check; } 18595885e762Sdan } {ok} 18607da56b4fSdrh} 18615885e762Sdan 1862c95e01daSdrhdb close 1863c95e01daSdrhforcedelete test.db test.db-wal test.db-journal 1864c95e01daSdrhsqlite3 db test.db 1865c95e01daSdrhsqlite3 db2 test.db 1866c95e01daSdrhdo_test 23.1 { 1867c95e01daSdrh db eval { 1868c95e01daSdrh CREATE TABLE t1(a INTEGER PRIMARY KEY,b,c,d); 1869c95e01daSdrh CREATE INDEX i1 ON t1(b,c); 1870c95e01daSdrh CREATE INDEX i2 ON t1(c,d); 18717be0fd9cSdrh CREATE INDEX i2x ON t1(d COLLATE nocase, c DESC); 18725f419b3bSdrh CREATE INDEX i3 ON t1(d,b+c,c); 1873c95e01daSdrh CREATE TABLE t2(x INTEGER REFERENCES t1); 1874c95e01daSdrh } 1875c95e01daSdrh db2 eval {SELECT name FROM sqlite_master} 18765f419b3bSdrh} {t1 i1 i2 i2x i3 t2} 1877c228be5bSdrhdo_test 23.2a { 1878c95e01daSdrh db eval { 1879c95e01daSdrh DROP INDEX i2; 1880c95e01daSdrh CREATE INDEX i2 ON t1(c,d,b); 1881c95e01daSdrh } 1882c228be5bSdrh capture_pragma db2 out {PRAGMA index_info(i2)} 18835e7028c2Sdrh db2 eval {SELECT cid, name, '|' FROM out ORDER BY seqno} 18845e7028c2Sdrh} {2 c | 3 d | 1 b |} 18857be0fd9cSdrh 1886b3366b99Sdrh# EVIDENCE-OF: R-56143-29319 PRAGMA schema.index_xinfo(index-name); This 1887b3366b99Sdrh# pragma returns information about every column in an index. 18887be0fd9cSdrh# 18897be0fd9cSdrh# EVIDENCE-OF: R-45970-35618 Unlike this index_info pragma, this pragma 18907be0fd9cSdrh# returns information about every column in the index, not just the key 18917be0fd9cSdrh# columns. 18927be0fd9cSdrh# 1893c228be5bSdrhdo_test 23.2b { 1894c228be5bSdrh capture_pragma db2 out {PRAGMA index_xinfo(i2)} 1895c228be5bSdrh db2 eval {SELECT cid, name, "desc", coll, "key", '|' FROM out ORDER BY seqno} 1896c228be5bSdrh} {2 c 0 BINARY 1 | 3 d 0 BINARY 1 | 1 b 0 BINARY 1 | -1 {} 0 BINARY 0 |} 18977be0fd9cSdrh 18987be0fd9cSdrh# (The first column of output from PRAGMA index_xinfo is...) 18997be0fd9cSdrh# EVIDENCE-OF: R-00197-14279 The rank of the column within the index. (0 19007be0fd9cSdrh# means left-most. Key columns come before auxiliary columns.) 19017be0fd9cSdrh# 19027be0fd9cSdrh# (The second column of output from PRAGMA index_xinfo is...) 19035f419b3bSdrh# EVIDENCE-OF: R-06603-49335 The rank of the column within the table 19047be0fd9cSdrh# being indexed, or -1 if the index-column is the rowid of the table 19055f419b3bSdrh# being indexed and -2 if the index is on an expression. 19067be0fd9cSdrh# 19077be0fd9cSdrh# (The third column of output from PRAGMA index_xinfo is...) 19085f419b3bSdrh# EVIDENCE-OF: R-40641-22898 The name of the column being indexed, or 19095f419b3bSdrh# NULL if the index-column is the rowid of the table being indexed or an 19105f419b3bSdrh# expression. 19117be0fd9cSdrh# 19127be0fd9cSdrh# (The fourth column of output from PRAGMA index_xinfo is...) 19137be0fd9cSdrh# EVIDENCE-OF: R-11847-09179 1 if the index-column is sorted in reverse 19147be0fd9cSdrh# (DESC) order by the index and 0 otherwise. 19157be0fd9cSdrh# 19167be0fd9cSdrh# (The fifth column of output from PRAGMA index_xinfo is...) 19177be0fd9cSdrh# EVIDENCE-OF: R-15313-19540 The name for the collating sequence used to 19187be0fd9cSdrh# compare values in the index-column. 19197be0fd9cSdrh# 19207be0fd9cSdrh# (The sixth column of output from PRAGMA index_xinfo is...) 19217be0fd9cSdrh# EVIDENCE-OF: R-14310-64553 1 if the index-column is a key column and 0 19227be0fd9cSdrh# if the index-column is an auxiliary column. 19237be0fd9cSdrh# 19247be0fd9cSdrhdo_test 23.2c { 19257be0fd9cSdrh db2 eval {PRAGMA index_xinfo(i2)} 19267be0fd9cSdrh} {0 2 c 0 BINARY 1 1 3 d 0 BINARY 1 2 1 b 0 BINARY 1 3 -1 {} 0 BINARY 0} 19277be0fd9cSdrhdo_test 23.2d { 19287be0fd9cSdrh db2 eval {PRAGMA index_xinfo(i2x)} 19297be0fd9cSdrh} {0 3 d 0 nocase 1 1 2 c 1 BINARY 1 2 -1 {} 0 BINARY 0} 19305f419b3bSdrhdo_test 23.2e { 19315f419b3bSdrh db2 eval {PRAGMA index_xinfo(i3)} 19325f419b3bSdrh} {0 3 d 0 BINARY 1 1 -2 {} 0 BINARY 1 2 2 c 0 BINARY 1 3 -1 {} 0 BINARY 0} 19337be0fd9cSdrh 1934b3366b99Sdrh# EVIDENCE-OF: R-64103-17776 PRAGMA schema.index_list(table-name); This 1935b3366b99Sdrh# pragma returns one row for each index associated with the given table. 19367be0fd9cSdrh# 19377be0fd9cSdrh# (The first column of output from PRAGMA index_list is...) 19387be0fd9cSdrh# EVIDENCE-OF: R-02753-24748 A sequence number assigned to each index 19397be0fd9cSdrh# for internal tracking purposes. 19407be0fd9cSdrh# 19417be0fd9cSdrh# (The second column of output from PRAGMA index_list is...) 19427be0fd9cSdrh# EVIDENCE-OF: R-35496-03635 The name of the index. 19437be0fd9cSdrh# 19447be0fd9cSdrh# (The third column of output from PRAGMA index_list is...) 19457be0fd9cSdrh# EVIDENCE-OF: R-57301-64506 "1" if the index is UNIQUE and "0" if not. 19467be0fd9cSdrh# 19477be0fd9cSdrh# (The fourth column of output from PRAGMA index_list is...) 19487be0fd9cSdrh# EVIDENCE-OF: R-36609-39554 "c" if the index was created by a CREATE 19497be0fd9cSdrh# INDEX statement, "u" if the index was created by a UNIQUE constraint, 19507be0fd9cSdrh# or "pk" if the index was created by a PRIMARY KEY constraint. 19517be0fd9cSdrh# 1952c95e01daSdrhdo_test 23.3 { 1953c95e01daSdrh db eval { 19545f419b3bSdrh DROP INDEX IF EXISTS i3; 1955c95e01daSdrh CREATE INDEX i3 ON t1(d,b,c); 1956c95e01daSdrh } 1957c228be5bSdrh capture_pragma db2 out {PRAGMA index_list(t1)} 19587be0fd9cSdrh db2 eval {SELECT seq, name, "unique", origin, '|' FROM out ORDER BY seq} 19597be0fd9cSdrh} {0 i3 0 c | 1 i2 0 c | 2 i2x 0 c | 3 i1 0 c |} 1960c95e01daSdrhdo_test 23.4 { 1961c95e01daSdrh db eval { 1962c95e01daSdrh ALTER TABLE t1 ADD COLUMN e; 1963c95e01daSdrh } 1964c95e01daSdrh db2 eval { 1965c95e01daSdrh PRAGMA table_info(t1); 1966c95e01daSdrh } 1967c95e01daSdrh} {/4 e {} 0 {} 0/} 1968c95e01daSdrhdo_test 23.5 { 1969c95e01daSdrh db eval { 1970c95e01daSdrh DROP TABLE t2; 1971c95e01daSdrh CREATE TABLE t2(x, y INTEGER REFERENCES t1); 1972c95e01daSdrh } 1973c95e01daSdrh db2 eval { 1974c95e01daSdrh PRAGMA foreign_key_list(t2); 1975c95e01daSdrh } 1976c95e01daSdrh} {0 0 t1 y {} {NO ACTION} {NO ACTION} NONE} 19773e1e14d8Sdrhdb2 close 1978c95e01daSdrh 1979efeaec36Sdrhifcapable !has_codec { 198038413723Sdan reset_db 198138413723Sdan do_execsql_test 24.0 { 198238413723Sdan PRAGMA page_size = 1024; 198338413723Sdan CREATE TABLE t1(a, b, c); 198438413723Sdan CREATE INDEX i1 ON t1(b); 198538413723Sdan INSERT INTO t1 VALUES('a', 'b', 'c'); 198638413723Sdan PRAGMA integrity_check; 198738413723Sdan } {ok} 198838413723Sdan 198938413723Sdan set r [db one {SELECT rootpage FROM sqlite_master WHERE name = 't1'}] 199038413723Sdan db close 199138413723Sdan hexio_write test.db [expr $r*1024 - 16] 000000000000000701040f0f1f616263 199238413723Sdan 199338413723Sdan sqlite3 db test.db 199438413723Sdan do_catchsql_test 24.1 { 199538413723Sdan SELECT * FROM t1; 199638413723Sdan } {1 {database disk image is malformed}} 199738413723Sdan do_catchsql_test 24.2 { 199838413723Sdan PRAGMA integrity_check; 199974588cebSdrh } {0 {{database disk image is malformed}}} 2000efeaec36Sdrh} 20011fed5dabSdandatabase_never_corrupt 2002cd61c281Sdrhfinish_test 2003