summaryrefslogtreecommitdiffstats
path: root/test/backup5.test
blob: c789adfa691678372b2654c2850409967765ed2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# 2014 November 13
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix backup5

forcedelete test2.db

do_execsql_test 1.0 {
  CREATE TABLE t1(a, b);
  CREATE TABLE t2(a, b);
  INSERT INTO t2 VALUES(1, 1);
  INSERT INTO t2 VALUES(2, 2);
  INSERT INTO t2 VALUES(3, 3);
}

do_test 1.1 {
  forcecopy test.db test.db2
  db eval {
    DROP TABLE t2;
    INSERT INTO t1 VALUES(zeroblob(1000), zeroblob(1000));
    INSERT INTO t1 VALUES(randomblob(1000), randomblob(1000));
  }
} {}

do_test 1.2 {
  sqlite3 db2 test.db2
  set stmt [sqlite3_prepare_v2 db2 "SELECT * FROM t2" -1 dummy]
  sqlite3_step $stmt
} {SQLITE_ROW}

do_test 1.3 {
  list [catch { sqlite3_backup B db2 main db main } msg] $msg
} {1 {sqlite3_backup_init() failed}}

do_test 1.4 {
  sqlite3_errmsg db2
} {destination database is in use}

do_test 1.5 {
  sqlite3_reset $stmt
  sqlite3_backup B db2 main db main
  B step 200
  B finish
} {SQLITE_OK}

do_test 1.6 {
  list [sqlite3_step $stmt] [sqlite3_finalize $stmt]
} {SQLITE_ERROR SQLITE_ERROR}

do_test 1.7 {
  sqlite3_errmsg db2
} {no such table: t2}

finish_test