1# 2016-08-19 2# 3# The author disclaims copyright to this source code. In place of 4# a legal notice, here is a blessing: 5# 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. 9# 10#*********************************************************************** 11# 12# This file implements a test for VACUUM on attached databases. 13# 14 15set testdir [file dirname $argv0] 16source $testdir/tester.tcl 17 18# If the VACUUM statement is disabled in the current build, skip all 19# the tests in this file. 20# 21ifcapable !vacuum { 22 finish_test 23 return 24} 25 26forcedelete test2.db test3.db 27do_execsql_test vacuum5-1.1 { 28 PRAGMA auto_vacuum = 0; 29 CREATE TABLE main.t1(a,b); 30 WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<1000) 31 INSERT INTO t1(a,b) SELECT x, randomblob(1000) FROM c; 32 CREATE TEMP TABLE ttemp(x,y); 33 INSERT INTO ttemp SELECT * FROM t1; 34 ATTACH 'test2.db' AS x2; 35 ATTACH 'test3.db' AS x3; 36 CREATE TABLE x2.t2(c,d); 37 INSERT INTO t2 SELECT * FROM t1; 38 CREATE TABLE x3.t3(e,f); 39 INSERT INTO t3 SELECT * FROM t1; 40 DELETE FROM t1 WHERE (rowid%3)!=0; 41 DELETE FROM t2 WHERE (rowid%4)!=0; 42 DELETE FROM t3 WHERE (rowid%5)!=0; 43 PRAGMA main.integrity_check; 44 PRAGMA x2.integrity_check; 45 PRAGMA x3.integrity_check; 46} {ok ok ok} 47set size1 [file size test.db] 48set size2 [file size test2.db] 49set size3 [file size test3.db] 50 51do_execsql_test vacuum5-1.2.1 { 52 VACUUM main; 53} {} 54do_test vacuum5-1.2.2 { 55 expr {[file size test.db]<$size1} 56} {1} 57do_test vacuum5-1.2.3 { 58 file size test2.db 59} $size2 60do_test vacuum5-1.2.4 { 61 file size test3.db 62} $size3 63set size1 [file size test.db] 64do_execsql_test vacuum-1.2.5 { 65 DELETE FROM t1; 66 PRAGMA main.integrity_check; 67} {ok} 68 69do_execsql_test vacuum5-1.3.1 { 70 VACUUM x2; 71} {} 72do_test vacuum5-1.3.2 { 73 file size test.db 74} $size1 75do_test vacuum5-1.3.3 { 76 expr {[file size test2.db]<$size2} 77} 1 78do_test vacuum5-1.3.4 { 79 file size test3.db 80} $size3 81set size2 [file size test2.db] 82do_execsql_test vacuum-1.3.5 { 83 DELETE FROM t2; 84 PRAGMA x2.integrity_check; 85} {ok} 86 87do_execsql_test vacuum5-1.4.1 { 88 VACUUM x3; 89} {} 90do_test vacuum5-1.3.2 { 91 file size test.db 92} $size1 93do_test vacuum5-1.3.3 { 94 file size test2.db 95} $size2 96do_test vacuum5-1.3.4 { 97 expr {[file size test3.db]<$size3} 98} 1 99 100# VACUUM is a no-op on the TEMP table 101# 102set sizeTemp [db one {PRAGMA temp.page_count}] 103do_execsql_test vacuum5-1.4.1 { 104 VACUUM temp; 105} {} 106do_execsql_test vacuum5-1.4.2 { 107 PRAGMA temp.page_count; 108} $sizeTemp 109 110do_catchsql_test vacuum5-2.0 { 111 VACUUM olaf; 112} {1 {unknown database olaf}} 113 114finish_test 115