blob: 629718a75089459c1bac5dd858e3162785f7d077 [file] [log] [blame]
danb483eba2012-10-13 19:58:11 +00001# 2012 October 13
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# 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.
15#
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.
20#
21
22set testdir [file dirname $argv0]
23source $testdir/tester.tcl
mistachkin06befd12012-10-13 20:20:09 +000024set testprefix backup4
danb483eba2012-10-13 19:58:11 +000025
26#-------------------------------------------------------------------------
27# At one point this test was failing because [db] was using an out of
28# date schema in test case 1.2.
29#
30do_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}
36
37do_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} {}
47
48do_execsql_test 1.2 {
49 SELECT * FROM t1 WHERE x='one';
50 PRAGMA integrity_check;
51} {one two ok}
52
53db close
54forcedelete test.db
55forcedelete test.db2
56sqlite3 db test.db
57
58#-------------------------------------------------------------------------
59# Test that if the source is zero bytes, the destination database
60# consists of a single page only.
61#
62do_execsql_test 2.1 {
63 CREATE TABLE t1(a, b);
64 CREATE INDEX i1 ON t1(a, b);
65}
66
67do_test 2.2 { file size test.db } 3072
68
69do_test 2.3 {
70 sqlite3 db1 test.db2
71 db1 backup test.db
72 db1 close
73 file size test.db
74} {1024}
75
76do_test 2.4 { file size test.db2 } 0
77
78db close
79forcedelete test.db
80forcedelete test.db2
81sqlite3 db test.db
82
83#-------------------------------------------------------------------------
84# Test that if the destination has a page-size larger than the implicit
85# page-size of the source, the final destination database still consists
86# of a single page.
87#
88do_execsql_test 3.1 {
89 PRAGMA page_size = 4096;
90 CREATE TABLE t1(a, b);
91 CREATE INDEX i1 ON t1(a, b);
92}
93
94do_test 3.2 { file size test.db } 12288
95
96do_test 3.3 {
97 sqlite3 db1 test.db2
98 db1 backup test.db
99 db1 close
100 file size test.db
101} {1024}
102
103do_test 3.4 { file size test.db2 } 0
104
105finish_test
106