3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file implements tests for the PRAGMA command.
15 # $Id: pragma2.test,v 1.4 2007/10/09 08:29:33 danielk1977 Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
22 # pragma2-1.*: Test freelist_count pragma on the main 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.
25 # pragma2-4.*: Tests for PRAGMA cache_spill
28 ifcapable !pragma||!schema_pragmas {
33 test_set_config_pagecache 0 0
35 # Delete the preexisting database to avoid the special setup
36 # that the "all.test" script does.
39 delete_file test.db test.db-journal
40 delete_file test3.db test3.db-journal
41 sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
42 db eval {PRAGMA auto_vacuum=0}
45 # EVIDENCE-OF: R-11211-21323 PRAGMA schema.freelist_count; Return the
46 # number of unused pages in the database file.
50 PRAGMA freelist_count;
55 CREATE TABLE abc(a, b, c);
56 PRAGMA freelist_count;
62 PRAGMA freelist_count;
67 PRAGMA main.freelist_count;
72 forcedelete test2.db-journal
77 ATTACH 'test2.db' AS aux;
78 PRAGMA aux.auto_vacuum=OFF;
79 PRAGMA aux.freelist_count;
84 CREATE TABLE aux.abc(a, b, c);
85 PRAGMA aux.freelist_count;
89 set ::val [string repeat 0123456789 1000]
91 INSERT INTO aux.abc VALUES(1, 2, $::val);
92 PRAGMA aux.freelist_count;
96 expr {[file size test2.db] / 1024}
101 PRAGMA aux.freelist_count;
105 do_test pragma2-3.1 {
107 PRAGMA aux.freelist_count;
108 PRAGMA main.freelist_count;
109 PRAGMA freelist_count;
112 do_test pragma2-3.2 {
114 PRAGMA freelist_count = 500;
115 PRAGMA freelist_count;
118 do_test pragma2-3.3 {
120 PRAGMA aux.freelist_count = 500;
121 PRAGMA aux.freelist_count;
126 # Default setting of PRAGMA cache_spill is always ON
128 # EVIDENCE-OF: R-63549-59887 PRAGMA cache_spill; PRAGMA
129 # cache_spill=boolean; PRAGMA schema.cache_spill=N;
131 # EVIDENCE-OF: R-23955-02765 Cache_spill is enabled by default
134 delete_file test.db test.db-journal
135 delete_file test2.db test2.db-journal
137 do_execsql_test pragma2-4.1 {
138 PRAGMA main.cache_size=2000;
139 PRAGMA temp.cache_size=2000;
141 PRAGMA main.cache_spill;
142 PRAGMA temp.cache_spill;
144 do_execsql_test pragma2-4.2 {
145 PRAGMA cache_spill=OFF;
147 PRAGMA main.cache_spill;
148 PRAGMA temp.cache_spill;
150 do_execsql_test pragma2-4.3 {
151 PRAGMA page_size=1024;
152 PRAGMA cache_size=50;
154 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d);
155 INSERT INTO t1 VALUES(1, randomblob(400), 1, randomblob(400));
156 INSERT INTO t1 SELECT a+1, randomblob(400), a+1, randomblob(400) FROM t1;
157 INSERT INTO t1 SELECT a+2, randomblob(400), a+2, randomblob(400) FROM t1;
158 INSERT INTO t1 SELECT a+4, randomblob(400), a+4, randomblob(400) FROM t1;
159 INSERT INTO t1 SELECT a+8, randomblob(400), a+8, randomblob(400) FROM t1;
160 INSERT INTO t1 SELECT a+16, randomblob(400), a+16, randomblob(400) FROM t1;
161 INSERT INTO t1 SELECT a+32, randomblob(400), a+32, randomblob(400) FROM t1;
162 INSERT INTO t1 SELECT a+64, randomblob(400), a+64, randomblob(400) FROM t1;
164 ATTACH 'test2.db' AS aux1;
165 CREATE TABLE aux1.t2(a INTEGER PRIMARY KEY, b, c, d);
166 INSERT INTO t2 SELECT * FROM t1;
168 PRAGMA cache_spill=ON;
170 sqlite3_release_memory
172 # EVIDENCE-OF: R-07634-40532 The cache_spill pragma enables or disables
173 # the ability of the pager to spill dirty cache pages to the database
174 # file in the middle of a transaction.
176 do_test pragma2-4.4 {
182 } {main exclusive temp unknown} ;# EXCLUSIVE lock due to cache spill
183 do_test pragma2-4.5.1 {
186 PRAGMA cache_spill=OFF;
192 } {0 main reserved temp unknown} ;# No cache spill, so no exclusive lock
195 # EVIDENCE-OF: R-34657-61226 The "PRAGMA cache_spill=N" form of this
196 # pragma sets a minimum cache size threshold required for spilling to
198 do_test pragma2-4.5.2 {
201 PRAGMA cache_spill=100000;
207 } {100000 main reserved temp unknown} ;# Big spill threshold -> no excl lock
208 ifcapable !memorymanage {
209 do_test pragma2-4.5.3 {
212 PRAGMA cache_spill=25;
213 PRAGMA main.cache_spill;
218 } {50 main exclusive temp unknown} ;# Small cache spill -> exclusive lock
219 do_test pragma2-4.5.4 {
222 PRAGMA cache_spill(-25);
223 PRAGMA main.cache_spill;
228 } {50 main exclusive temp unknown} ;# Small cache spill -> exclusive lock
232 # Verify that newly attached databases inherit the cache_spill=OFF
235 do_execsql_test pragma2-4.6 {
237 PRAGMA cache_spill=OFF;
238 ATTACH 'test2.db' AS aux1;
239 PRAGMA aux1.cache_size=50;
243 } {main unlocked temp unknown aux1 reserved}
244 do_execsql_test pragma2-4.7 {
247 sqlite3_release_memory
248 do_execsql_test pragma2-4.8 {
249 PRAGMA cache_spill=ON; -- Applies to all databases
253 } {main unlocked temp unknown aux1 exclusive}
258 do_execsql_test pragma2-5.1 {
259 PRAGMA page_size=16384;
262 PRAGMA cache_spill=YES;
265 do_execsql_test pragma2-5.2 {
266 PRAGMA cache_spill=NO;
269 do_execsql_test pragma2-5.3 {
270 PRAGMA cache_spill(-51);
274 test_restore_config_pagecache