OLD | NEW |
1 # 2002 March 6 | 1 # 2002 March 6 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
11 # This file implements regression tests for SQLite library. | 11 # This file implements regression tests for SQLite library. |
12 # | 12 # |
13 # This file implements tests for the PRAGMA command. | 13 # This file implements tests for the PRAGMA command. |
14 # | 14 # |
15 # $Id: pragma2.test,v 1.4 2007/10/09 08:29:33 danielk1977 Exp $ | 15 # $Id: pragma2.test,v 1.4 2007/10/09 08:29:33 danielk1977 Exp $ |
16 | 16 |
17 set testdir [file dirname $argv0] | 17 set testdir [file dirname $argv0] |
18 source $testdir/tester.tcl | 18 source $testdir/tester.tcl |
19 | 19 |
20 # Test organization: | 20 # Test organization: |
21 # | 21 # |
22 # pragma2-1.*: Test freelist_count pragma on the main database. | 22 # pragma2-1.*: Test freelist_count pragma on the main database. |
23 # pragma2-2.*: Test freelist_count pragma on an attached database. | 23 # pragma2-2.*: Test freelist_count pragma on an attached database. |
24 # pragma2-3.*: Test trying to write to the freelist_count is a no-op. | 24 # pragma2-3.*: Test trying to write to the freelist_count is a no-op. |
| 25 # pragma2-4.*: Tests for PRAGMA cache_spill |
25 # | 26 # |
26 | 27 |
27 ifcapable !pragma||!schema_pragmas { | 28 ifcapable !pragma||!schema_pragmas { |
28 finish_test | 29 finish_test |
29 return | 30 return |
30 } | 31 } |
31 | 32 |
32 # Delete the preexisting database to avoid the special setup | 33 # Delete the preexisting database to avoid the special setup |
33 # that the "all.test" script does. | 34 # that the "all.test" script does. |
34 # | 35 # |
35 db close | 36 db close |
36 file delete test.db test.db-journal | 37 delete_file test.db test.db-journal |
37 file delete test3.db test3.db-journal | 38 delete_file test3.db test3.db-journal |
38 sqlite3 db test.db; set DB [sqlite3_connection_pointer db] | 39 sqlite3 db test.db; set DB [sqlite3_connection_pointer db] |
39 db eval {PRAGMA auto_vacuum=0} | 40 db eval {PRAGMA auto_vacuum=0} |
40 | 41 |
41 do_test pragma2-1.1 { | 42 do_test pragma2-1.1 { |
42 execsql { | 43 execsql { |
43 PRAGMA freelist_count; | 44 PRAGMA freelist_count; |
44 } | 45 } |
45 } {0} | 46 } {0} |
46 do_test pragma2-1.2 { | 47 do_test pragma2-1.2 { |
47 execsql { | 48 execsql { |
48 CREATE TABLE abc(a, b, c); | 49 CREATE TABLE abc(a, b, c); |
49 PRAGMA freelist_count; | 50 PRAGMA freelist_count; |
50 } | 51 } |
51 } {0} | 52 } {0} |
52 do_test pragma2-1.3 { | 53 do_test pragma2-1.3 { |
53 execsql { | 54 execsql { |
54 DROP TABLE abc; | 55 DROP TABLE abc; |
55 PRAGMA freelist_count; | 56 PRAGMA freelist_count; |
56 } | 57 } |
57 } {1} | 58 } {1} |
58 do_test pragma2-1.4 { | 59 do_test pragma2-1.4 { |
59 execsql { | 60 execsql { |
60 PRAGMA main.freelist_count; | 61 PRAGMA main.freelist_count; |
61 } | 62 } |
62 } {1} | 63 } {1} |
63 | 64 |
64 file delete -force test2.db | 65 forcedelete test2.db |
65 file delete -force test2.db-journal | 66 forcedelete test2.db-journal |
66 | 67 |
67 ifcapable attach { | 68 ifcapable attach { |
68 do_test pragma2-2.1 { | 69 do_test pragma2-2.1 { |
69 execsql { | 70 execsql { |
70 ATTACH 'test2.db' AS aux; | 71 ATTACH 'test2.db' AS aux; |
71 PRAGMA aux.auto_vacuum=OFF; | 72 PRAGMA aux.auto_vacuum=OFF; |
72 PRAGMA aux.freelist_count; | 73 PRAGMA aux.freelist_count; |
73 } | 74 } |
74 } {0} | 75 } {0} |
75 do_test pragma2-2.2 { | 76 do_test pragma2-2.2 { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 } | 110 } |
110 } {1 1} | 111 } {1 1} |
111 do_test pragma2-3.3 { | 112 do_test pragma2-3.3 { |
112 execsql { | 113 execsql { |
113 PRAGMA aux.freelist_count = 500; | 114 PRAGMA aux.freelist_count = 500; |
114 PRAGMA aux.freelist_count; | 115 PRAGMA aux.freelist_count; |
115 } | 116 } |
116 } {9 9} | 117 } {9 9} |
117 } | 118 } |
118 | 119 |
| 120 # Default setting of PRAGMA cache_spill is always ON |
| 121 # |
| 122 # EVIDENCE-OF: R-51036-62828 PRAGMA cache_spill; PRAGMA |
| 123 # cache_spill=boolean; |
| 124 # |
| 125 # EVIDENCE-OF: R-23955-02765 Cache_spill is enabled by default |
| 126 # |
| 127 db close |
| 128 delete_file test.db test.db-journal |
| 129 delete_file test2.db test2.db-journal |
| 130 sqlite3 db test.db |
| 131 do_execsql_test pragma2-4.1 { |
| 132 PRAGMA cache_spill; |
| 133 PRAGMA main.cache_spill; |
| 134 PRAGMA temp.cache_spill; |
| 135 } {1 1 1} |
| 136 do_execsql_test pragma2-4.2 { |
| 137 PRAGMA cache_spill=OFF; |
| 138 PRAGMA cache_spill; |
| 139 PRAGMA main.cache_spill; |
| 140 PRAGMA temp.cache_spill; |
| 141 } {0 0 0} |
| 142 do_execsql_test pragma2-4.3 { |
| 143 PRAGMA page_size=1024; |
| 144 PRAGMA cache_size=50; |
| 145 BEGIN; |
| 146 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d); |
| 147 INSERT INTO t1 VALUES(1, randomblob(400), 1, randomblob(400)); |
| 148 INSERT INTO t1 SELECT a+1, randomblob(400), a+1, randomblob(400) FROM t1; |
| 149 INSERT INTO t1 SELECT a+2, randomblob(400), a+2, randomblob(400) FROM t1; |
| 150 INSERT INTO t1 SELECT a+4, randomblob(400), a+4, randomblob(400) FROM t1; |
| 151 INSERT INTO t1 SELECT a+8, randomblob(400), a+8, randomblob(400) FROM t1; |
| 152 INSERT INTO t1 SELECT a+16, randomblob(400), a+16, randomblob(400) FROM t1; |
| 153 INSERT INTO t1 SELECT a+32, randomblob(400), a+32, randomblob(400) FROM t1; |
| 154 INSERT INTO t1 SELECT a+64, randomblob(400), a+64, randomblob(400) FROM t1; |
| 155 COMMIT; |
| 156 ATTACH 'test2.db' AS aux1; |
| 157 CREATE TABLE aux1.t2(a INTEGER PRIMARY KEY, b, c, d); |
| 158 INSERT INTO t2 SELECT * FROM t1; |
| 159 DETACH aux1; |
| 160 PRAGMA cache_spill=ON; |
| 161 } {} |
| 162 sqlite3_release_memory |
| 163 # |
| 164 # EVIDENCE-OF: R-07634-40532 The cache_spill pragma enables or disables |
| 165 # the ability of the pager to spill dirty cache pages to the database |
| 166 # file in the middle of a transaction. |
| 167 # |
| 168 do_test pragma2-4.4 { |
| 169 db eval { |
| 170 BEGIN; |
| 171 UPDATE t1 SET c=c+1; |
| 172 PRAGMA lock_status; |
| 173 } |
| 174 } {main exclusive temp unknown} ;# EXCLUSIVE lock due to cache spill |
| 175 do_test pragma2-4.5 { |
| 176 db eval { |
| 177 COMMIT; |
| 178 PRAGMA cache_spill=OFF; |
| 179 BEGIN; |
| 180 UPDATE t1 SET c=c-1; |
| 181 PRAGMA lock_status; |
| 182 } |
| 183 } {main reserved temp unknown} ;# No cache spill, so no exclusive lock |
| 184 |
| 185 # Verify that newly attached databases inherit the cache_spill=OFF |
| 186 # setting. |
| 187 # |
| 188 do_execsql_test pragma2-4.6 { |
| 189 COMMIT; |
| 190 ATTACH 'test2.db' AS aux1; |
| 191 PRAGMA aux1.cache_size=50; |
| 192 BEGIN; |
| 193 UPDATE t2 SET c=c+1; |
| 194 PRAGMA lock_status; |
| 195 } {main unlocked temp unknown aux1 reserved} |
| 196 do_execsql_test pragma2-4.7 { |
| 197 COMMIT; |
| 198 } |
| 199 sqlite3_release_memory |
| 200 do_execsql_test pragma2-4.8 { |
| 201 PRAGMA cache_spill=ON; -- Applies to all databases |
| 202 BEGIN; |
| 203 UPDATE t2 SET c=c-1; |
| 204 PRAGMA lock_status; |
| 205 } {main unlocked temp unknown aux1 exclusive} |
| 206 |
| 207 |
119 finish_test | 208 finish_test |
OLD | NEW |