CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
backup4.test109 linesDownload Raw Back to test
1# 2012 October 132#3# The author disclaims copyright to this source code.  In place of4# 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 destination14# 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 database18# schema cookie and change counter. Doing that could cause other clients19# to become confused and continue using out-of-date cache data.20#21 22set testdir [file dirname $argv0]23source $testdir/tester.tcl24set testprefix backup425 26# The codec logic does not work for zero-length database files.  A database27# file must contain at least one page in order to be recognized as an28# encrypted database.29do_not_use_codec30 31#-------------------------------------------------------------------------32# At one point this test was failing because [db] was using an out of33# date schema in test case 1.2.34#35do_execsql_test 1.0 {36  CREATE TABLE t1(x, y, UNIQUE(x, y));37  INSERT INTO t1 VALUES('one', 'two');38  SELECT * FROM t1 WHERE x='one';39  PRAGMA integrity_check;40} {one two ok}41 42do_test 1.1 {43  sqlite3 db1 :memory:44  db1 backup test.db45  sqlite3 db1 test.db46  db1 eval {47    CREATE TABLE t1(x, y);48    INSERT INTO t1 VALUES('one', 'two');49  }50  db1 close51} {}52 53do_execsql_test 1.2 {54  SELECT * FROM t1 WHERE x='one';55  PRAGMA integrity_check;56} {one two ok}57 58db close59forcedelete test.db60forcedelete test.db261sqlite3 db test.db62 63#-------------------------------------------------------------------------64# Test that if the source is zero bytes, the destination database 65# consists of a single page only.66#67do_execsql_test 2.1 {68  CREATE TABLE t1(a, b);69  CREATE INDEX i1 ON t1(a, b);70}71do_test 2.2 { file size test.db } [expr $AUTOVACUUM ? 4096 : 3072]72 73do_test 2.3 {74  sqlite3 db1 test.db275  db1 backup test.db76  db1 close77  file size test.db78} {1024}79 80do_test 2.4 { file size test.db2 } 081 82db close83forcedelete test.db84forcedelete test.db285sqlite3 db test.db86 87#-------------------------------------------------------------------------88# Test that if the destination has a page-size larger than the implicit89# page-size of the source, the final destination database still consists90# of a single page.91#92do_execsql_test 3.1 {93  PRAGMA page_size = 4096;94  CREATE TABLE t1(a, b);95  CREATE INDEX i1 ON t1(a, b);96}97do_test 3.2 { file size test.db } [expr $AUTOVACUUM ? 16384 : 12288]98 99do_test 3.3 {100  sqlite3 db1 test.db2101  db1 backup test.db102  db1 close103  file size test.db104} {1024}105 106do_test 3.4 { file size test.db2 } 0107 108finish_test109