Snapshot of upstream SQLite 3.8.4.3
[sqlcipher.git] / test / backup4.test
blob417df80e552d502728dc719e0e72d6ea3c01cadb
1 # 2012 October 13
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # The tests in this file verify that if an empty database (zero bytes in 
13 # size) is used as the source of a backup operation, the final destination
14 # database is one page in size.
16 # The destination must consist of at least one page as truncating a 
17 # database file to zero bytes is equivalent to resetting the database
18 # schema cookie and change counter. Doing that could cause other clients
19 # to become confused and continue using out-of-date cache data.
22 set testdir [file dirname $argv0]
23 source $testdir/tester.tcl
24 set testprefix backup4
26 #-------------------------------------------------------------------------
27 # At one point this test was failing because [db] was using an out of
28 # date schema in test case 1.2.
30 do_execsql_test 1.0 {
31   CREATE TABLE t1(x, y, UNIQUE(x, y));
32   INSERT INTO t1 VALUES('one', 'two');
33   SELECT * FROM t1 WHERE x='one';
34   PRAGMA integrity_check;
35 } {one two ok}
37 do_test 1.1 {
38   sqlite3 db1 :memory:
39   db1 backup test.db
40   sqlite3 db1 test.db
41   db1 eval {
42     CREATE TABLE t1(x, y);
43     INSERT INTO t1 VALUES('one', 'two');
44   }
45   db1 close
46 } {}
48 do_execsql_test 1.2 {
49   SELECT * FROM t1 WHERE x='one';
50   PRAGMA integrity_check;
51 } {one two ok}
53 db close
54 forcedelete test.db
55 forcedelete test.db2
56 sqlite3 db test.db
58 #-------------------------------------------------------------------------
59 # Test that if the source is zero bytes, the destination database 
60 # consists of a single page only.
62 do_execsql_test 2.1 {
63   CREATE TABLE t1(a, b);
64   CREATE INDEX i1 ON t1(a, b);
66 do_test 2.2 { file size test.db } [expr $AUTOVACUUM ? 4096 : 3072]
68 do_test 2.3 {
69   sqlite3 db1 test.db2
70   db1 backup test.db
71   db1 close
72   file size test.db
73 } {1024}
75 do_test 2.4 { file size test.db2 } 0
77 db close
78 forcedelete test.db
79 forcedelete test.db2
80 sqlite3 db test.db
82 #-------------------------------------------------------------------------
83 # Test that if the destination has a page-size larger than the implicit
84 # page-size of the source, the final destination database still consists
85 # of a single page.
87 do_execsql_test 3.1 {
88   PRAGMA page_size = 4096;
89   CREATE TABLE t1(a, b);
90   CREATE INDEX i1 ON t1(a, b);
92 do_test 3.2 { file size test.db } [expr $AUTOVACUUM ? 16384 : 12288]
94 do_test 3.3 {
95   sqlite3 db1 test.db2
96   db1 backup test.db
97   db1 close
98   file size test.db
99 } {1024}
101 do_test 3.4 { file size test.db2 } 0
103 finish_test