1b483eba0Sdan# 2012 October 13 2b483eba0Sdan# 3b483eba0Sdan# The author disclaims copyright to this source code. In place of 4b483eba0Sdan# a legal notice, here is a blessing: 5b483eba0Sdan# 6b483eba0Sdan# May you do good and not evil. 7b483eba0Sdan# May you find forgiveness for yourself and forgive others. 8b483eba0Sdan# May you share freely, never taking more than you give. 9b483eba0Sdan# 10b483eba0Sdan#*********************************************************************** 11b483eba0Sdan# 12b483eba0Sdan# The tests in this file verify that if an empty database (zero bytes in 13b483eba0Sdan# size) is used as the source of a backup operation, the final destination 14b483eba0Sdan# database is one page in size. 15b483eba0Sdan# 16b483eba0Sdan# The destination must consist of at least one page as truncating a 17b483eba0Sdan# database file to zero bytes is equivalent to resetting the database 18b483eba0Sdan# schema cookie and change counter. Doing that could cause other clients 19b483eba0Sdan# to become confused and continue using out-of-date cache data. 20b483eba0Sdan# 21b483eba0Sdan 22b483eba0Sdanset testdir [file dirname $argv0] 23b483eba0Sdansource $testdir/tester.tcl 2406befd1eSmistachkinset testprefix backup4 25b483eba0Sdan 26*af3906a7Sdrh# The codec logic does not work for zero-length database files. A database 27*af3906a7Sdrh# file must contain at least one page in order to be recognized as an 28*af3906a7Sdrh# encrypted database. 29*af3906a7Sdrhdo_not_use_codec 30*af3906a7Sdrh 31b483eba0Sdan#------------------------------------------------------------------------- 32b483eba0Sdan# At one point this test was failing because [db] was using an out of 33b483eba0Sdan# date schema in test case 1.2. 34b483eba0Sdan# 35b483eba0Sdando_execsql_test 1.0 { 36b483eba0Sdan CREATE TABLE t1(x, y, UNIQUE(x, y)); 37b483eba0Sdan INSERT INTO t1 VALUES('one', 'two'); 38b483eba0Sdan SELECT * FROM t1 WHERE x='one'; 39b483eba0Sdan PRAGMA integrity_check; 40b483eba0Sdan} {one two ok} 41b483eba0Sdan 42b483eba0Sdando_test 1.1 { 43b483eba0Sdan sqlite3 db1 :memory: 44b483eba0Sdan db1 backup test.db 45b483eba0Sdan sqlite3 db1 test.db 46b483eba0Sdan db1 eval { 47b483eba0Sdan CREATE TABLE t1(x, y); 48b483eba0Sdan INSERT INTO t1 VALUES('one', 'two'); 49b483eba0Sdan } 50b483eba0Sdan db1 close 51b483eba0Sdan} {} 52b483eba0Sdan 53b483eba0Sdando_execsql_test 1.2 { 54b483eba0Sdan SELECT * FROM t1 WHERE x='one'; 55b483eba0Sdan PRAGMA integrity_check; 56b483eba0Sdan} {one two ok} 57b483eba0Sdan 58b483eba0Sdandb close 59b483eba0Sdanforcedelete test.db 60b483eba0Sdanforcedelete test.db2 61b483eba0Sdansqlite3 db test.db 62b483eba0Sdan 63b483eba0Sdan#------------------------------------------------------------------------- 64b483eba0Sdan# Test that if the source is zero bytes, the destination database 65b483eba0Sdan# consists of a single page only. 66b483eba0Sdan# 67b483eba0Sdando_execsql_test 2.1 { 68b483eba0Sdan CREATE TABLE t1(a, b); 69b483eba0Sdan CREATE INDEX i1 ON t1(a, b); 70b483eba0Sdan} 718411b25cSdando_test 2.2 { file size test.db } [expr $AUTOVACUUM ? 4096 : 3072] 72b483eba0Sdan 73b483eba0Sdando_test 2.3 { 74b483eba0Sdan sqlite3 db1 test.db2 75b483eba0Sdan db1 backup test.db 76b483eba0Sdan db1 close 77b483eba0Sdan file size test.db 78b483eba0Sdan} {1024} 79b483eba0Sdan 80b483eba0Sdando_test 2.4 { file size test.db2 } 0 81b483eba0Sdan 82b483eba0Sdandb close 83b483eba0Sdanforcedelete test.db 84b483eba0Sdanforcedelete test.db2 85b483eba0Sdansqlite3 db test.db 86b483eba0Sdan 87b483eba0Sdan#------------------------------------------------------------------------- 88b483eba0Sdan# Test that if the destination has a page-size larger than the implicit 89b483eba0Sdan# page-size of the source, the final destination database still consists 90b483eba0Sdan# of a single page. 91b483eba0Sdan# 92b483eba0Sdando_execsql_test 3.1 { 93b483eba0Sdan PRAGMA page_size = 4096; 94b483eba0Sdan CREATE TABLE t1(a, b); 95b483eba0Sdan CREATE INDEX i1 ON t1(a, b); 96b483eba0Sdan} 978411b25cSdando_test 3.2 { file size test.db } [expr $AUTOVACUUM ? 16384 : 12288] 98b483eba0Sdan 99b483eba0Sdando_test 3.3 { 100b483eba0Sdan sqlite3 db1 test.db2 101b483eba0Sdan db1 backup test.db 102b483eba0Sdan db1 close 103b483eba0Sdan file size test.db 104b483eba0Sdan} {1024} 105b483eba0Sdan 106b483eba0Sdando_test 3.4 { file size test.db2 } 0 107b483eba0Sdan 108b483eba0Sdanfinish_test 109