3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # This file implements regression tests for the sessions module.
13 # Specifically, it tests that tables appear in the correct order
14 # within changesets and patchsets.
19 if {![info exists testdir]} {
20 set testdir [file join [file dirname [info script]] .. .. test]
22 source [file join [file dirname [info script]] session_common.tcl]
23 source $testdir/tester.tcl
24 ifcapable !session {finish_test; return}
25 set testprefix sessionF
30 # 1.*: Test that sqlite3session_changeset() and sqlite3session_patchset()
31 # output tables in the right order.
33 # 2.*: Test that sqlite3session_invert() does not modify the order of
34 # tables within a changeset.
36 # 3.*: Test that sqlite3session_concat outputs tables in the right order.
39 # Create a db schema to use.
42 CREATE TABLE t3(e PRIMARY KEY, f);
43 CREATE TABLE t1(a PRIMARY KEY, b);
44 CREATE TABLE t2(c PRIMARY KEY, d);
47 #-----------------------------------------------------------------------
48 # 1.* - changeset() and patchset().
51 foreach {tn setup result} {
55 {INSERT t2 0 X. {} {i 2 t two}}
56 {INSERT t1 0 X. {} {i 1 t one}}
57 {INSERT t3 0 X. {} {i 3 t three}}
64 {INSERT t1 0 X. {} {i 1 t one}}
65 {INSERT t2 0 X. {} {i 2 t two}}
66 {INSERT t3 0 X. {} {i 3 t three}}
74 {INSERT t3 0 X. {} {i 3 t three}}
75 {INSERT t2 0 X. {} {i 2 t two}}
76 {INSERT t1 0 X. {} {i 1 t one}}
84 sqlite3session S db main
87 do_execsql_test 1.$tn.1 {
88 INSERT INTO t2 VALUES(2, 'two');
89 INSERT INTO t1 VALUES(1, 'one');
90 INSERT INTO t3 VALUES(3, 'three');
93 do_changeset_test 1.1.$tn.2 S $result
94 do_patchset_test 1.1.$tn.3 S $result
99 foreach {tn setup result} {
103 {INSERT t2 0 X. {} {i 4 t four}}
104 {INSERT t2 0 X. {} {i 5 t five}}
105 {INSERT t1 0 X. {} {i 1 t one}}
106 {INSERT t3 0 X. {} {i 6 t six}}
113 {INSERT t1 0 X. {} {i 1 t one}}
114 {INSERT t2 0 X. {} {i 4 t four}}
115 {INSERT t2 0 X. {} {i 5 t five}}
116 {INSERT t3 0 X. {} {i 6 t six}}
124 {INSERT t3 0 X. {} {i 6 t six}}
125 {INSERT t2 0 X. {} {i 4 t four}}
126 {INSERT t2 0 X. {} {i 5 t five}}
127 {INSERT t1 0 X. {} {i 1 t one}}
135 sqlite3session S db main
138 do_execsql_test 1.$tn.1 {
139 INSERT INTO t2 VALUES(2, 'two');
140 INSERT INTO t1 VALUES(1, 'one');
142 INSERT INTO t2 VALUES(4, 'four');
143 INSERT INTO t2 VALUES(5, 'five');
144 INSERT INTO t3 VALUES(6, 'six');
147 do_changeset_test 1.2.$tn.2 S $result
148 do_patchset_test 1.2.$tn.2 S $result
153 #-------------------------------------------------------------------------
157 foreach {tn setup result} {
161 {DELETE t2 0 X. {i 4 t four} {}}
162 {DELETE t2 0 X. {i 5 t five} {}}
163 {DELETE t1 0 X. {i 1 t one} {}}
164 {DELETE t3 0 X. {i 6 t six} {}}
171 {DELETE t1 0 X. {i 1 t one} {}}
172 {DELETE t2 0 X. {i 4 t four} {}}
173 {DELETE t2 0 X. {i 5 t five} {}}
174 {DELETE t3 0 X. {i 6 t six} {}}
182 {DELETE t3 0 X. {i 6 t six} {}}
183 {DELETE t2 0 X. {i 4 t four} {}}
184 {DELETE t2 0 X. {i 5 t five} {}}
185 {DELETE t1 0 X. {i 1 t one} {}}
193 sqlite3session S db main
196 do_execsql_test 1.$tn.1 {
197 INSERT INTO t2 VALUES(2, 'two');
198 INSERT INTO t1 VALUES(1, 'one');
200 INSERT INTO t2 VALUES(4, 'four');
201 INSERT INTO t2 VALUES(5, 'five');
202 INSERT INTO t3 VALUES(6, 'six');
205 do_changeset_invert_test 2.$tn.2 S $result
210 #-------------------------------------------------------------------------
213 foreach {tn setup1 sql1 setup2 sql2 result} {
217 INSERT INTO t1 VALUES(1, 'one');
218 INSERT INTO t2 VALUES(2, 'two');
223 INSERT INTO t1 VALUES(3, 'three');
224 INSERT INTO t2 VALUES(4, 'four');
226 {INSERT t1 0 X. {} {i 1 t one}}
227 {INSERT t1 0 X. {} {i 3 t three}}
228 {INSERT t2 0 X. {} {i 2 t two}}
229 {INSERT t2 0 X. {} {i 4 t four}}
236 INSERT INTO t1 VALUES(1, 'one');
237 INSERT INTO t2 VALUES(2, 'two');
241 INSERT INTO t1 VALUES(3, 'three');
242 INSERT INTO t2 VALUES(4, 'four');
244 {INSERT t2 0 X. {} {i 2 t two}}
245 {INSERT t2 0 X. {} {i 4 t four}}
246 {INSERT t1 0 X. {} {i 1 t one}}
247 {INSERT t1 0 X. {} {i 3 t three}}
253 INSERT INTO t2 VALUES(2, 'two');
257 INSERT INTO t1 VALUES(3, 'three');
258 INSERT INTO t2 VALUES(4, 'four');
259 INSERT INTO t3 VALUES(5, 'five');
261 {INSERT t2 0 X. {} {i 2 t two}}
262 {INSERT t2 0 X. {} {i 4 t four}}
263 {INSERT t1 0 X. {} {i 3 t three}}
264 {INSERT t3 0 X. {} {i 5 t five}}
273 sqlite3session S db main
279 sqlite3session S db main
286 sqlite3session_foreach x [sqlite3changeset_concat $c1 $c2] {
290 do_test 3.$tn { set res } [list {*}$result]