vacuum.test revision 2
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A# 2001 September 15
2N/A#
2N/A# The author disclaims copyright to this source code. In place of
2N/A# a legal notice, here is a blessing:
2N/A#
2N/A# May you do good and not evil.
2N/A# May you find forgiveness for yourself and forgive others.
2N/A# May you share freely, never taking more than you give.
2N/A#
2N/A#***********************************************************************
2N/A# This file implements regression tests for SQLite library. The
2N/A# focus of this file is testing the VACUUM statement.
2N/A#
2N/A# $Id: vacuum.test,v 1.15 2004/02/14 16:31:04 drh Exp $
2N/A
2N/Aset testdir [file dirname $argv0]
2N/Asource $testdir/tester.tcl
2N/A
2N/Aproc cksum {{db db}} {
2N/A set txt [$db eval {SELECT name, type, sql FROM sqlite_master}]\n
2N/A foreach tbl [$db eval {SELECT name FROM sqlite_master WHERE type='table'}] {
2N/A append txt [$db eval "SELECT * FROM $tbl"]\n
2N/A }
2N/A foreach prag {default_synchronous default_cache_size} {
2N/A append txt $prag-[$db eval "PRAGMA $prag"]\n
2N/A }
2N/A set cksum [string length $txt]-[md5 $txt]
2N/A # puts $cksum-[file size test.db]
2N/A return $cksum
2N/A}
2N/Ado_test vacuum-1.1 {
2N/A execsql {
2N/A BEGIN;
2N/A CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
2N/A INSERT INTO t1 VALUES(NULL,randstr(10,100),randstr(5,50));
2N/A INSERT INTO t1 VALUES(123456,randstr(10,100),randstr(5,50));
2N/A INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
2N/A INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
2N/A INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
2N/A INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
2N/A INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
2N/A INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
2N/A INSERT INTO t1 SELECT NULL, b||'-'||rowid, c||'-'||rowid FROM t1;
2N/A CREATE INDEX i1 ON t1(b,c);
2N/A CREATE TABLE t2 AS SELECT * FROM t1;
2N/A COMMIT;
2N/A DROP TABLE t2;
2N/A }
2N/A set ::size1 [file size test.db]
2N/A set ::cksum [cksum]
2N/A expr {$::cksum!=""}
2N/A} {1}
2N/Ado_test vacuum-1.2 {
2N/A execsql {
2N/A VACUUM;
2N/A }
2N/A cksum
2N/A} $cksum
2N/Ado_test vacuum-1.3 {
2N/A expr {[file size test.db]<$::size1}
2N/A} {1}
2N/Ado_test vacuum-1.4 {
2N/A execsql {
2N/A BEGIN;
2N/A CREATE TABLE t2 AS SELECT * FROM t1;
2N/A CREATE TABLE t3 AS SELECT * FROM t1;
2N/A CREATE VIEW v1 AS SELECT b, c FROM t3;
2N/A CREATE TRIGGER r1 AFTER DELETE ON t2 BEGIN
2N/A SELECT 1;
2N/A END;
2N/A COMMIT;
2N/A DROP TABLE t2;
2N/A }
2N/A set ::size1 [file size test.db]
2N/A set ::cksum [cksum]
2N/A expr {$::cksum!=""}
2N/A} {1}
2N/Ado_test vacuum-1.5 {
2N/A execsql {
2N/A VACUUM;
2N/A }
2N/A cksum
2N/A} $cksum
2N/Ado_test vacuum-1.6 {
2N/A expr {[file size test.db]<$::size1}
2N/A} {1}
2N/A
2N/Ado_test vacuum-2.1 {
2N/A catchsql {
2N/A BEGIN;
2N/A VACUUM;
2N/A COMMIT;
2N/A }
2N/A} {1 {cannot VACUUM from within a transaction}}
2N/Acatch {db eval COMMIT}
2N/Ado_test vacuum-2.2 {
2N/A sqlite db2 test.db
2N/A execsql {
2N/A BEGIN;
2N/A CREATE TABLE t4 AS SELECT * FROM t1;
2N/A CREATE TABLE t5 AS SELECT * FROM t1;
2N/A COMMIT;
2N/A DROP TABLE t4;
2N/A DROP TABLE t5;
2N/A } db2
2N/A set ::cksum [cksum db2]
2N/A catchsql {
2N/A VACUUM
2N/A }
2N/A} {0 {}}
2N/Ado_test vacuum-2.3 {
2N/A cksum
2N/A} $cksum
2N/Ado_test vacuum-2.4 {
2N/A catch {db2 eval {SELECT count(*) FROM sqlite_master}}
2N/A cksum db2
2N/A} $cksum
2N/A
2N/A# Ticket #427. Make sure VACUUM works when the EMPTY_RESULT_CALLBACKS
2N/A# pragma is turned on.
2N/A#
2N/Ado_test vacuum-3.1 {
2N/A db close
2N/A db2 close
2N/A file delete test.db
2N/A sqlite db test.db
2N/A execsql {
2N/A PRAGMA empty_result_callbacks=on;
2N/A VACUUM;
2N/A }
2N/A} {}
2N/A
2N/A# Ticket #464. Make sure VACUUM works with the sqlite_compile() API.
2N/A#
2N/Ado_test vacuum-4.1 {
2N/A db close
2N/A set DB [sqlite db test.db]
2N/A set VM [sqlite_compile $DB {VACUUM} TAIL]
2N/A sqlite_step $VM N VALUES COLNAMES
2N/A} {SQLITE_DONE}
2N/Ado_test vacuum-4.2 {
2N/A sqlite_finalize $VM
2N/A} {}
2N/A
2N/A# Ticket #515. VACUUM after deleting and recreating the table that
2N/A# a view refers to.
2N/A#
2N/Ado_test vacuum-5.1 {
2N/A db close
2N/A file delete -force test.db
2N/A sqlite db test.db
2N/A catchsql {
2N/A CREATE TABLE Test (TestID int primary key);
2N/A INSERT INTO Test VALUES (NULL);
2N/A CREATE VIEW viewTest AS SELECT * FROM Test;
2N/A
2N/A BEGIN;
2N/A CREATE TEMP TABLE tempTest (TestID int primary key, Test2 int NULL);
2N/A INSERT INTO tempTest SELECT TestID, 1 FROM Test;
2N/A DROP TABLE Test;
2N/A CREATE TABLE Test(TestID int primary key, Test2 int NULL);
2N/A INSERT INTO Test SELECT * FROM tempTest;
2N/A COMMIT;
2N/A VACUUM;
2N/A }
2N/A} {0 {}}
2N/Ado_test vacuum-5.2 {
2N/A catchsql {
2N/A VACUUM;
2N/A }
2N/A} {0 {}}
2N/A
2N/A# finish_test