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. The
12 # focus of this file is testing the VACUUM statement.
14 # $Id: vacuum2.test,v 1.10 2009/02/18 20:31:18 drh Exp $
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
19 # Do not use a codec for tests in this file, as the database file is
20 # manipulated directly using tcl scripts (using the [hexio_write] command).
24 # If the VACUUM statement is disabled in the current build, skip all
25 # the tests in this file.
27 ifcapable {!vacuum||!autoinc} {
36 # Ticket #1121 - make sure vacuum works if all autoincrement tables
41 CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT, y);
47 # Ticket #2518. Make sure vacuum increments the change counter
48 # in the database header.
54 INSERT INTO t1 VALUES(1);
56 hexio_get_int [hexio_read test.db 24 4]
57 } [expr {[hexio_get_int [hexio_read test.db 24 4]]+3}]
62 hexio_get_int [hexio_read test.db 24 4]
63 } [expr {[hexio_get_int [hexio_read test.db 24 4]]+1}]
65 ############################################################################
66 # Verify that we can use the auto_vacuum pragma to request a new
67 # autovacuum setting, do a VACUUM, and the new setting takes effect.
68 # Make sure this happens correctly even if there are multiple open
69 # connections to the same database file.
72 set pageSize [db eval {pragma page_size}]
74 # We are currently not autovacuuming so the database should be 3 pages
75 # in size. 1 page for each of sqlite_master, t1, and t2.
79 INSERT INTO t1 VALUES('hello');
80 INSERT INTO t2 VALUES('out there');
82 expr {[file size test.db]/$pageSize}
89 # Convert the database to an autovacuumed database.
90 ifcapable autovacuum {
93 PRAGMA auto_vacuum=FULL;
96 expr {[file size test.db]/$pageSize}
102 do_test vacuum2-3.5 {
105 do_test vacuum2-3.6 {
106 execsql {PRAGMA integrity_check} db2
108 do_test vacuum2-3.7 {
109 execsql {PRAGMA integrity_check} db
112 # Convert the database back to a non-autovacuumed database.
113 do_test vacuum2-3.13 {
115 PRAGMA auto_vacuum=NONE;
118 expr {[file size test.db]/$pageSize}
120 do_test vacuum2-3.14 {
123 do_test vacuum2-3.15 {
126 do_test vacuum2-3.16 {
127 execsql {PRAGMA integrity_check} db2
129 do_test vacuum2-3.17 {
130 execsql {PRAGMA integrity_check} db
135 ifcapable autovacuum {
136 do_test vacuum2-4.1 {
141 pragma auto_vacuum=1;
142 create table t(a, b);
143 insert into t values(1, 2);
144 insert into t values(1, 2);
145 pragma auto_vacuum=0;
150 do_test vacuum2-4.2 {
152 pragma auto_vacuum=1;
157 do_test vacuum2-4.3 {
159 pragma integrity_check
162 do_test vacuum2-4.4 {
169 do_test vacuum2-4.5 { # Ticket #3663
171 pragma auto_vacuum=2;
176 do_test vacuum2-4.6 {
178 pragma integrity_check
181 do_test vacuum2-4.7 {
191 #-------------------------------------------------------------------------
192 # The following block of tests verify the behaviour of the library when
193 # a database is VACUUMed when there are one or more unfinalized SQL
194 # statements reading the same database using the same db handle.
199 do_execsql_test vacuum2-5.1 {
200 CREATE TABLE t1(a PRIMARY KEY, b UNIQUE);
201 INSERT INTO t1 VALUES(1, randomblob(500));
202 INSERT INTO t1 SELECT a+1, randomblob(500) FROM t1; -- 2
203 INSERT INTO t1 SELECT a+2, randomblob(500) FROM t1; -- 4
204 INSERT INTO t1 SELECT a+4, randomblob(500) FROM t1; -- 8
205 INSERT INTO t1 SELECT a+8, randomblob(500) FROM t1; -- 16
208 do_test vacuum2-5.2 {
210 db eval {SELECT a, b FROM t1} { if {$a == 8} { execsql VACUUM } }
212 } {1 {cannot VACUUM - SQL statements in progress}}
214 do_test vacuum2-5.3 {
216 db eval {SELECT 1, 2, 3} { execsql VACUUM }
218 } {1 {cannot VACUUM - SQL statements in progress}}
220 do_test vacuum2-5.4 {
223 db eval {SELECT a, b FROM t1 WHERE a<=10} {
224 if {$a==6} { set res [catchsql VACUUM] }
228 } {1 2 3 4 5 6 7 8 9 10 {1 {cannot VACUUM - SQL statements in progress}}}