Debian Codegraph @

ext/rbu/rbu14.test

raw
1 # 2015 July 25
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 that an RBU data_xxx table may be a view instead of a regular
13 # table.
14 #
15
16 source [file join [file dirname [info script]] rbu_common.tcl]
17 if_no_rbu_support { finish_test ; return }
18 source $testdir/lock_common.tcl
19 set ::testprefix rbu14
20
21
22 foreach {tn schema} {
23 1 {
24 CREATE TABLE t1(a PRIMARY KEY, b, c);
25 CREATE TABLE t2(a PRIMARY KEY, b, c);
26 }
27 2 {
28 CREATE TABLE t1(a PRIMARY KEY, b, c);
29 CREATE TABLE t2(a PRIMARY KEY, b, c);
30 CREATE INDEX i1 ON t1(b, c);
31 CREATE INDEX i2 ON t2(b, c);
32 }
33 3 {
34 CREATE TABLE t1(a PRIMARY KEY, b, c) WITHOUT ROWID;
35 CREATE TABLE t2(a PRIMARY KEY, b, c) WITHOUT ROWID;
36 }
37 4 {
38 CREATE TABLE t1(a PRIMARY KEY, b, c) WITHOUT ROWID;
39 CREATE TABLE t2(a PRIMARY KEY, b, c) WITHOUT ROWID;
40 CREATE INDEX i1 ON t1(b, c);
41 CREATE INDEX i2 ON t2(b, c);
42 }
43 } {
44 reset_db
45
46 execsql $schema
47 execsql {
48 INSERT INTO t1 VALUES(50, 50, 50);
49 INSERT INTO t1 VALUES(51, 51, 51);
50 INSERT INTO t2 VALUES(50, 50, 50);
51 INSERT INTO t2 VALUES(51, 51, 51);
52 }
53
54 forcedelete rbu.db
55 do_execsql_test $tn.1 {
56 ATTACH 'rbu.db' AS rbu;
57 CREATE TABLE rbu.stuff(tbl, a, b, c, rbu_control);
58 INSERT INTO stuff VALUES
59 ('t1', 1, 2, 3, 0), -- insert into t1
60 ('t2', 4, 5, 6, 0), -- insert into t2
61 ('t1', 50, NULL, NULL, 1), -- delete from t1
62 ('t2', 51, NULL, NULL, 1); -- delete from t2
63
64 CREATE VIEW rbu.data_t1 AS
65 SELECT a, b, c, rbu_control FROM stuff WHERE tbl='t1';
66 CREATE VIEW rbu.data_t2 AS
67 SELECT a, b, c, rbu_control FROM stuff WHERE tbl='t2';
68 }
69
70 do_test $tn.2 {
71 while 1 {
72 sqlite3rbu rbu test.db rbu.db
73 set rc [rbu step]
74 rbu close
75 if {$rc != "SQLITE_OK"} break
76 }
77 set rc
78 } {SQLITE_DONE}
79
80 do_execsql_test $tn.3.1 {
81 SELECT * FROM t1 ORDER BY a;
82 } {1 2 3 51 51 51}
83
84 do_execsql_test $tn.3.2 {
85 SELECT * FROM t2 ORDER BY a;
86 } {4 5 6 50 50 50}
87
88 integrity_check $tn.4
89 }
90
91
92 finish_test