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 / rbu9.test

125 lines · 3007 bytes Raw Blame History
1# 2014 November 21
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# Test RBU with virtual tables. And tables with no PRIMARY KEY declarations.
13#
14
15source [file join [file dirname [info script]] rbu_common.tcl]
16if_no_rbu_support { finish_test ; return }
17set ::testprefix rbu9
18
19ifcapable !fts3 {
20 finish_test
21 return
22}
23
24do_execsql_test 1.1 {
25 CREATE VIRTUAL TABLE f1 USING fts4(a, b, c);
26 INSERT INTO f1(rowid, a, b, c) VALUES(11, 'a', 'b', 'c');
27 INSERT INTO f1(rowid, a, b, c) VALUES(12, 'd', 'e', 'f');
28 INSERT INTO f1(rowid, a, b, c) VALUES(13, 'g', 'h', 'i');
29}
30
31do_test 1.1 {
32 forcedelete rbu.db
33 sqlite3 db2 rbu.db
34 db2 eval {
35 CREATE TABLE data_f1(rbu_rowid, a, b, c, rbu_control);
36 INSERT INTO data_f1 VALUES(14, 'x', 'y', 'z', 0); -- INSERT
37 INSERT INTO data_f1 VALUES(11, NULL, NULL, NULL, 1); -- DELETE
38 INSERT INTO data_f1 VALUES(13, NULL, NULL, 'X', '..x'); -- UPDATE
39 }
40 db2 close
41} {}
42
43do_test 1.2.1 {
44 while 1 {
45 sqlite3rbu rbu test.db rbu.db
46 set rc [rbu step]
47 if {$rc != "SQLITE_OK"} break
48 rbu close
49 }
50 rbu close
51} {SQLITE_DONE}
52
53do_execsql_test 1.2.2 { SELECT rowid, * FROM f1 } {
54 12 d e f
55 13 g h X
56 14 x y z
57}
58do_execsql_test 1.2.3 { INSERT INTO f1(f1) VALUES('integrity-check') }
59integrity_check 1.2.4
60
61#-------------------------------------------------------------------------
62# Tables with no PK declaration.
63#
64
65# Run the RBU in file $rbu on target database $target until completion.
66#
67proc run_rbu {target rbu} {
68 sqlite3rbu rbu $target $rbu
69 while { [rbu step]=="SQLITE_OK" } {}
70 rbu close
71}
72
73foreach {tn idx} {
74 1 { }
75 2 {
76 CREATE INDEX i1 ON t1(a);
77 }
78 3 {
79 CREATE INDEX i1 ON t1(b, c);
80 CREATE INDEX i2 ON t1(c, b);
81 CREATE INDEX i3 ON t1(a, a, a, b, b, b, c, c, c);
82 }
83} {
84
85 reset_db
86 do_execsql_test 2.$tn.1 {
87 CREATE TABLE t1(a, b, c);
88 INSERT INTO t1 VALUES(1, 2, 3);
89 INSERT INTO t1 VALUES(4, 5, 6);
90 INSERT INTO t1(rowid, a, b, c) VALUES(-1, 'a', 'b', 'c');
91 INSERT INTO t1(rowid, a, b, c) VALUES(-2, 'd', 'e', 'f');
92 }
93
94 db eval $idx
95
96 do_test 2.$tn.2 {
97 forcedelete rbu.db
98 sqlite3 db2 rbu.db
99 db2 eval {
100 CREATE TABLE data_t1(rbu_rowid, a, b, c, rbu_control);
101 INSERT INTO data_t1 VALUES(3, 'x', 'y', 'z', 0);
102 INSERT INTO data_t1 VALUES(NULL, 'X', 'Y', 'Z', 0);
103 INSERT INTO data_t1 VALUES('1', NULL, NULL, NULL, 1);
104 INSERT INTO data_t1 VALUES(-2, NULL, NULL, 'fff', '..x');
105 }
106 db2 close
107 } {}
108
109 run_rbu test.db rbu.db
110
111 do_execsql_test 2.$tn.3 {
112 SELECT rowid, a, b, c FROM t1 ORDER BY rowid;
113 } {
114 -2 d e fff
115 -1 a b c
116 2 4 5 6
117 3 x y z
118 4 X Y Z
119 }
120
121 integrity_check 2.$tn.4
122}
123
124
125finish_test