sl@0: # 2005 February 15 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. The sl@0: # focus of this file is testing the VACUUM statement. sl@0: # sl@0: # $Id: vacuum2.test,v 1.8 2008/08/23 16:17:56 danielk1977 Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: # If the VACUUM statement is disabled in the current build, skip all sl@0: # the tests in this file. sl@0: # sl@0: ifcapable {!vacuum||!autoinc} { sl@0: finish_test sl@0: return sl@0: } sl@0: if $AUTOVACUUM { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: # Ticket #1121 - make sure vacuum works if all autoincrement tables sl@0: # have been deleted. sl@0: # sl@0: do_test vacuum2-1.1 { sl@0: execsql { sl@0: CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT, y); sl@0: DROP TABLE t1; sl@0: VACUUM; sl@0: } sl@0: } {} sl@0: sl@0: # Ticket #2518. Make sure vacuum increments the change counter sl@0: # in the database header. sl@0: # sl@0: do_test vacuum2-2.1 { sl@0: execsql { sl@0: CREATE TABLE t1(x); sl@0: CREATE TABLE t2(y); sl@0: INSERT INTO t1 VALUES(1); sl@0: } sl@0: hexio_get_int [hexio_read test.db 24 4] sl@0: } [expr {[hexio_get_int [hexio_read test.db 24 4]]+3}] sl@0: do_test vacuum2-2.1 { sl@0: execsql { sl@0: VACUUM sl@0: } sl@0: hexio_get_int [hexio_read test.db 24 4] sl@0: } [expr {[hexio_get_int [hexio_read test.db 24 4]]+1}] sl@0: sl@0: ############################################################################ sl@0: # Verify that we can use the auto_vacuum pragma to request a new sl@0: # autovacuum setting, do a VACUUM, and the new setting takes effect. sl@0: # Make sure this happens correctly even if there are multiple open sl@0: # connections to the same database file. sl@0: # sl@0: sqlite3 db2 test.db sl@0: set pageSize [db eval {pragma page_size}] sl@0: sl@0: # We are currently not autovacuuming so the database should be 3 pages sl@0: # in size. 1 page for each of sqlite_master, t1, and t2. sl@0: # sl@0: do_test vacuum2-3.1 { sl@0: execsql { sl@0: INSERT INTO t1 VALUES('hello'); sl@0: INSERT INTO t2 VALUES('out there'); sl@0: } sl@0: expr {[file size test.db]/$pageSize} sl@0: } {3} sl@0: set cksum [cksum] sl@0: do_test vacuum2-3.2 { sl@0: cksum db2 sl@0: } $cksum sl@0: sl@0: # Convert the database to an autovacuumed database. sl@0: do_test vacuum2-3.3 { sl@0: execsql { sl@0: PRAGMA auto_vacuum=FULL; sl@0: VACUUM; sl@0: } sl@0: expr {[file size test.db]/$pageSize} sl@0: } {4} sl@0: do_test vacuum2-3.4 { sl@0: cksum db2 sl@0: } $cksum sl@0: do_test vacuum2-3.5 { sl@0: cksum sl@0: } $cksum sl@0: do_test vacuum2-3.6 { sl@0: execsql {PRAGMA integrity_check} db2 sl@0: } {ok} sl@0: do_test vacuum2-3.7 { sl@0: execsql {PRAGMA integrity_check} db sl@0: } {ok} sl@0: sl@0: # Convert the database back to a non-autovacuumed database. sl@0: do_test vacuum2-3.13 { sl@0: execsql { sl@0: PRAGMA auto_vacuum=NONE; sl@0: VACUUM; sl@0: } sl@0: expr {[file size test.db]/$pageSize} sl@0: } {3} sl@0: do_test vacuum2-3.14 { sl@0: cksum db2 sl@0: } $cksum sl@0: do_test vacuum2-3.15 { sl@0: cksum sl@0: } $cksum sl@0: do_test vacuum2-3.16 { sl@0: execsql {PRAGMA integrity_check} db2 sl@0: } {ok} sl@0: do_test vacuum2-3.17 { sl@0: execsql {PRAGMA integrity_check} db sl@0: } {ok} sl@0: sl@0: db2 close sl@0: sl@0: ifcapable autovacuum { sl@0: do_test vacuum2-4.1 { sl@0: db close sl@0: file delete -force test.db sl@0: sqlite3 db test.db sl@0: execsql { sl@0: pragma auto_vacuum=1; sl@0: create table t(a, b); sl@0: insert into t values(1, 2); sl@0: insert into t values(1, 2); sl@0: pragma auto_vacuum=0; sl@0: vacuum; sl@0: pragma auto_vacuum; sl@0: } sl@0: } {0} sl@0: do_test vacuum2-4.2 { sl@0: execsql { sl@0: pragma auto_vacuum=1; sl@0: vacuum; sl@0: pragma auto_vacuum; sl@0: } sl@0: } {1} sl@0: do_test vacuum2-4.3 { sl@0: execsql { sl@0: pragma integrity_check sl@0: } sl@0: } {ok} sl@0: do_test vacuum2-4.4 { sl@0: execsql { sl@0: pragma auto_vacuum; sl@0: } sl@0: } {1} sl@0: } sl@0: sl@0: finish_test