2 #pragma ident "%Z%%M% %I% %E% SMI"
6 # The author disclaims copyright to this source code. In place of
7 # a legal notice, here is a blessing:
9 # May you do good and not evil.
10 # May you find forgiveness for yourself and forgive others.
11 # May you share freely, never taking more than you give.
13 #***********************************************************************
14 # This file implements regression tests for SQLite library. The
15 # focus of this file is testing the VACUUM statement.
17 # $Id: vacuum.test,v 1.15 2004/02/14 16:31:04 drh Exp $
19 set testdir [file dirname $argv0]
20 source $testdir/tester.tcl
22 proc cksum {{db db}} {
23 set txt [$db eval {SELECT name, type, sql FROM sqlite_master}]\n
24 foreach tbl [$db eval {SELECT name FROM sqlite_master WHERE type='table'}] {
25 append txt [$db eval "SELECT * FROM $tbl"]\n
27 foreach prag {default_synchronous default_cache_size} {
28 append txt $prag-[$db eval "PRAGMA $prag"]\n
30 set cksum [string length $txt]-[md5 $txt]
31 # puts $cksum-[file size test.db]
37 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
38 INSERT INTO t1 VALUES(NULL,randstr(10,100),randstr(5,50));
39 INSERT INTO t1 VALUES(123456,randstr(10,100),randstr(5,50));
40 INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
41 INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
42 INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
43 INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
44 INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
45 INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
46 INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
47 CREATE INDEX i1 ON t1(b,c);
48 CREATE TABLE t2 AS SELECT * FROM t1;
52 set ::size1 [file size test.db]
63 expr {[file size test.db]<$::size1}
68 CREATE TABLE t2 AS SELECT * FROM t1;
69 CREATE TABLE t3 AS SELECT * FROM t1;
70 CREATE VIEW v1 AS SELECT b, c FROM t3;
71 CREATE TRIGGER r1 AFTER DELETE ON t2 BEGIN
77 set ::size1 [file size test.db]
88 expr {[file size test.db]<$::size1}
97 } {1 {cannot VACUUM from within a transaction}}
98 catch {db eval COMMIT}
103 CREATE TABLE t4 AS SELECT * FROM t1;
104 CREATE TABLE t5 AS SELECT * FROM t1;
109 set ::cksum [cksum db2]
118 catch {db2 eval {SELECT count(*) FROM sqlite_master}}
122 # Ticket #427. Make sure VACUUM works when the EMPTY_RESULT_CALLBACKS
123 # pragma is turned on.
131 PRAGMA empty_result_callbacks=on;
136 # Ticket #464. Make sure VACUUM works with the sqlite_compile() API.
140 set DB [sqlite db test.db]
141 set VM [sqlite_compile $DB {VACUUM} TAIL]
142 sqlite_step $VM N VALUES COLNAMES
148 # Ticket #515. VACUUM after deleting and recreating the table that
153 file delete -force test.db
156 CREATE TABLE Test (TestID int primary key);
157 INSERT INTO Test VALUES (NULL);
158 CREATE VIEW viewTest AS SELECT * FROM Test;
161 CREATE TEMP TABLE tempTest (TestID int primary key, Test2 int NULL);
162 INSERT INTO tempTest SELECT TestID, 1 FROM Test;
164 CREATE TABLE Test(TestID int primary key, Test2 int NULL);
165 INSERT INTO Test SELECT * FROM tempTest;