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 # Delete the preexisting database to avoid the special setup
34 # that the "all.test" script does.
37 delete_file test.db test.db-journal
38 delete_file test3.db test3.db-journal
39 sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
40 db eval {PRAGMA auto_vacuum=0}
44 PRAGMA freelist_count;
49 CREATE TABLE abc(a, b, c);
50 PRAGMA freelist_count;
56 PRAGMA freelist_count;
61 PRAGMA main.freelist_count;
66 forcedelete test2.db-journal
71 ATTACH 'test2.db' AS aux;
72 PRAGMA aux.auto_vacuum=OFF;
73 PRAGMA aux.freelist_count;
78 CREATE TABLE aux.abc(a, b, c);
79 PRAGMA aux.freelist_count;
83 set ::val [string repeat 0123456789 1000]
85 INSERT INTO aux.abc VALUES(1, 2, $::val);
86 PRAGMA aux.freelist_count;
90 expr {[file size test2.db] / 1024}
95 PRAGMA aux.freelist_count;
101 PRAGMA aux.freelist_count;
102 PRAGMA main.freelist_count;
103 PRAGMA freelist_count;
106 do_test pragma2-3.2 {
108 PRAGMA freelist_count = 500;
109 PRAGMA freelist_count;
112 do_test pragma2-3.3 {
114 PRAGMA aux.freelist_count = 500;
115 PRAGMA aux.freelist_count;
120 # Default setting of PRAGMA cache_spill is always ON
122 # EVIDENCE-OF: R-51036-62828 PRAGMA cache_spill; PRAGMA
123 # cache_spill=boolean;
125 # EVIDENCE-OF: R-23955-02765 Cache_spill is enabled by default
128 delete_file test.db test.db-journal
129 delete_file test2.db test2.db-journal
131 do_execsql_test pragma2-4.1 {
133 PRAGMA main.cache_spill;
134 PRAGMA temp.cache_spill;
136 do_execsql_test pragma2-4.2 {
137 PRAGMA cache_spill=OFF;
139 PRAGMA main.cache_spill;
140 PRAGMA temp.cache_spill;
142 do_execsql_test pragma2-4.3 {
143 PRAGMA page_size=1024;
144 PRAGMA cache_size=50;
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;
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;
160 PRAGMA cache_spill=ON;
162 sqlite3_release_memory
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.
168 do_test pragma2-4.4 {
174 } {main exclusive temp unknown} ;# EXCLUSIVE lock due to cache spill
175 do_test pragma2-4.5 {
178 PRAGMA cache_spill=OFF;
183 } {main reserved temp unknown} ;# No cache spill, so no exclusive lock
185 # Verify that newly attached databases inherit the cache_spill=OFF
188 do_execsql_test pragma2-4.6 {
190 ATTACH 'test2.db' AS aux1;
191 PRAGMA aux1.cache_size=50;
195 } {main unlocked temp unknown aux1 reserved}
196 do_execsql_test pragma2-4.7 {
199 sqlite3_release_memory
200 do_execsql_test pragma2-4.8 {
201 PRAGMA cache_spill=ON; -- Applies to all databases
205 } {main unlocked temp unknown aux1 exclusive}