interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / ext / rbu / rbusave.test

102 lines · 2515 bytes Raw Blame History
1# 2015 August 14
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
13source [file join [file dirname [info script]] rbu_common.tcl]
14if_no_rbu_support { finish_test ; return }
15set ::testprefix rbusave
16
17do_execsql_test 1.0 {
18 CREATE TABLE t1(a PRIMARY KEY, b, c) WITHOUT ROWID;
19 CREATE TABLE t2(a INTEGER PRIMARY KEY, b, c);
20 CREATE INDEX i1 ON t1(b);
21 CREATE INDEX i2 ON t2(c, b);
22
23 INSERT INTO t1 VALUES(1, 1, 1);
24 INSERT INTO t1 VALUES(2, 2, 2);
25 INSERT INTO t1 VALUES(3, 3, 3);
26
27 INSERT INTO t2 VALUES(1, 1, 1);
28 INSERT INTO t2 VALUES(2, 2, 2);
29 INSERT INTO t2 VALUES(3, 3, 3);
30}
31
32do_test 1.1 {
33 forcedelete test.db2
34 sqlite3 db2 test.db2
35 db2 eval {
36 CREATE TABLE data_t1(a, b, c, rbu_control);
37 INSERT INTO data_t1 VALUES(4, 4, 4, 0);
38 INSERT INTO data_t1 VALUES(2, NULL, NULL, 1);
39 INSERT INTO data_t1 VALUES(1, 'one', NULL, '.x.');
40
41 CREATE TABLE data_t2(a, b, c, rbu_control);
42 INSERT INTO data_t2 VALUES(4, 4, 4, 0);
43 INSERT INTO data_t2 VALUES(2, NULL, NULL, 1);
44 INSERT INTO data_t2 VALUES(1, 'one', NULL, '.x.');
45 }
46} {}
47
48proc test_to_bak {} {
49 foreach f {
50 test.db test.db-wal test.db-oal test.db-journal
51 test.db2 test.db2-wal test.db2-oal test.db2-journal
52 } {
53 set t [string map {test bak} $f]
54 forcedelete $t
55 if {[file exists $f]} { forcecopy $f $t }
56 }
57}
58
59do_test 1.2 {
60 test_to_bak
61 sqlite3rbu rrr bak.db bak.db2
62 set nStep 0
63 while {[rrr step]=="SQLITE_OK"} {incr nStep}
64 set res2 [rrr close]
65} {SQLITE_DONE}
66
67
68sqlite3rbu rbu test.db test.db2
69set res "SQLITE_OK"
70for {set i 1} {$res=="SQLITE_OK"} {incr i} {
71 set res [rbu step]
72
73 do_test 1.3.$i.1 {
74 rbu savestate
75 test_to_bak
76 sqlite3rbu rrr bak.db bak.db2
77 set nRem 0
78 while {[rrr step]=="SQLITE_OK"} {incr nRem}
79 set res2 [rrr close]
80 } {SQLITE_DONE}
81
82 do_test 1.3.$i.3 { expr $nRem+$i } [expr {$nStep + ($res=="SQLITE_DONE")}]
83
84 do_test 1.3.$i.3 {
85 sqlite3 bak bak.db
86 bak eval {
87 SELECT * FROM t1;
88 SELECT * FROM t2;
89 }
90 } {1 one 1 3 3 3 4 4 4 1 one 1 3 3 3 4 4 4}
91
92 bak close
93}
94
95do_test 1.4 { rbu close } {SQLITE_DONE}
96
97do_execsql_test 1.5 {
98 SELECT * FROM t1;
99 SELECT * FROM t2;
100} {1 one 1 3 3 3 4 4 4 1 one 1 3 3 3 4 4 4}
101
102finish_test