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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
# 2011 Mar 16
#
# 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.
#
#***********************************************************************
#
# The focus of this file is testing the session module.
#
if {![info exists testdir]} {
set testdir [file join [file dirname [info script]] .. .. test]
}
source [file join [file dirname [info script]] session_common.tcl]
source $testdir/tester.tcl
ifcapable !session {finish_test; return}
set testprefix sessionrowid
do_execsql_test 0.0 {
CREATE TABLE t1(a, b);
}
foreach {tn rowid bEmpty} {
1 0 1
2 1 0
3 -1 1
} {
do_test 0.$tn {
sqlite3session S db main
if {$rowid>=0} { S object_config rowid $rowid }
S attach t1
execsql { INSERT INTO t1 VALUES(1, 2); }
expr [string length [S changeset]]==0
} $bEmpty
S delete
}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 1.0 {
CREATE TABLE t1(a, b);
}
do_iterator_test 1.1 t1 {
INSERT INTO t1 VALUES('i', 'one');
} {
{INSERT t1 0 X.. {} {i 1 t i t one}}
}
do_execsql_test 1.2 {
SELECT rowid, * FROM t1
} {1 i one}
do_iterator_test 1.3 t1 {
UPDATE t1 SET b='two'
} {
{UPDATE t1 0 X.. {i 1 {} {} t one} {{} {} {} {} t two}}
}
do_iterator_test 1.4 t1 {
DELETE FROM t1;
} {
{DELETE t1 0 X.. {i 1 t i t two} {}}
}
do_iterator_test 1.5 t1 {
INSERT INTO t1(rowid, a, b) VALUES(14, 'hello', 'world');
INSERT INTO t1(rowid, a, b) VALUES(NULL, 'yes', 'no');
INSERT INTO t1(rowid, a, b) VALUES(-123, 'ii', 'iii');
} {
{INSERT t1 0 X.. {} {i -123 t ii t iii}}
{INSERT t1 0 X.. {} {i 15 t yes t no}}
{INSERT t1 0 X.. {} {i 14 t hello t world}}
}
do_iterator_test 1.6 t1 {
UPDATE t1 SET a='deluxe' WHERE rowid=14;
DELETE FROM t1 WHERE rowid=-123;
INSERT INTO t1 VALUES('x', 'xi');
} {
{DELETE t1 0 X.. {i -123 t ii t iii} {}}
{UPDATE t1 0 X.. {i 14 t hello {} {}} {{} {} t deluxe {} {}}}
{INSERT t1 0 X.. {} {i 16 t x t xi}}
}
#-------------------------------------------------------------------------
reset_db
forcedelete test.db2
sqlite3 db2 test.db2
do_execsql_test 2.0 {
CREATE TABLE t1(a, b);
}
do_execsql_test -db db2 2.0.1 {
CREATE TABLE t1(a, b);
}
proc xConflict {args} {
puts "CONFLICT!"
return "OMIT"
}
do_test 2.1 {
set C [changeset_from_sql {
INSERT INTO t1 VALUES('abc', 'def');
}]
sqlite3changeset_apply db2 $C xConflict
execsql { SELECT * FROM t1 } db2
} {abc def}
do_test 2.2 {
set C [changeset_from_sql {
UPDATE t1 SET b='hello'
}]
sqlite3changeset_apply db2 $C xConflict
execsql { SELECT * FROM t1 } db2
} {abc hello}
do_test 2.3 {
set C [changeset_from_sql {
DELETE FROM t1 WHERE b='hello'
}]
sqlite3changeset_apply db2 $C xConflict
execsql { SELECT * FROM t1 } db2
} {}
do_test 2.4 {
do_then_apply_sql {
INSERT INTO t1 VALUES('i', 'one');
INSERT INTO t1 VALUES('ii', 'two');
INSERT INTO t1 VALUES('iii', 'three');
INSERT INTO t1 VALUES('iv', 'four');
}
compare_db db db2
} {}
do_test 2.5 {
do_then_apply_sql {
DELETE FROM t1 WHERE a='ii';
UPDATE t1 SET b='THREE' WHERE a='iii';
UPDATE t1 SET a='III' WHERE a='iii';
INSERT INTO t1 VALUES('v', 'five');
}
compare_db db db2
} {}
do_execsql_test 2.6 {SELECT * FROM t1} {i one III THREE iv four v five}
do_execsql_test -db db2 2.7 {SELECT * FROM t1} {i one III THREE iv four v five}
#-------------------------------------------------------------------------
db2 close
reset_db
forcedelete test.db2
sqlite3 db2 test.db2
set init_sql {
CREATE TABlE t4(a, b);
CREATE INDEX t4a ON t4(a);
CREATE UNIQUE INDEX t4b ON t4(b);
}
do_execsql_test 3.0 $init_sql
do_execsql_test -db db2 3.0a $init_sql
do_execsql_test -db db2 3.1 {
INSERT INTO t4(rowid, a, b) VALUES(43, 'hello', 'world');
}
do_conflict_test 3.2 -sql {
INSERT INTO t4(rowid, a, b) VALUES(43, 'abc', 'def');
} -tables t4 -conflicts {
{INSERT t4 CONFLICT {i 43 t abc t def} {i 43 t hello t world}}
}
do_execsql_test -db db2 3.3 {
SELECT * FROM t4
} {hello world}
do_execsql_test 3.4 { DELETE FROM t4 }
do_conflict_test 3.5 -sql {
INSERT INTO t4(rowid, a, b) VALUES(43, 'abc', 'def');
} -tables t4 -conflicts {
{INSERT t4 CONFLICT {i 43 t abc t def} {i 43 t hello t world}}
} -policy REPLACE
do_execsql_test -db db2 3.6 {
SELECT * FROM t4
} {abc def}
do_execsql_test 3.7 { DELETE FROM t4 }
do_conflict_test 3.8 -sql {
INSERT INTO t4(rowid, a, b) VALUES(45, 'xyz', 'def');
} -tables t4 -conflicts {
{INSERT t4 CONSTRAINT {i 45 t xyz t def}}
}
do_execsql_test -db db2 3.9 {
SELECT * FROM t4
} {abc def}
do_execsql_test -db db 3.10a { DELETE FROM t4 }
do_execsql_test -db db2 3.10b { DELETE FROM t4 }
do_execsql_test -db db 3.11a {
INSERT INTO t4(rowid, a, b) VALUES(111, 'one', 'one');
INSERT INTO t4(rowid, a, b) VALUES(222, 'two', 'two');
}
do_execsql_test -db db2 3.11b {
INSERT INTO t4(rowid, a, b) VALUES(111, 'one', 'blip');
}
do_conflict_test 3.12 -sql {
DELETE FROM t4 WHERE a='one';
} -tables t4 -conflicts {
{DELETE t4 DATA {i 111 t one t one} {i 111 t one t blip}}
}
do_execsql_test -db db2 3.13 {
SELECT * FROM t4
} {one blip}
do_conflict_test 3.14 -sql {
DELETE FROM t4 WHERE a='two';
} -tables t4 -conflicts {
{DELETE t4 NOTFOUND {i 222 t two t two}}
}
do_execsql_test -db db2 3.15 {
SELECT * FROM t4
} {one blip}
do_execsql_test -db db 3.16a { DELETE FROM t4 }
do_execsql_test -db db2 3.16b { DELETE FROM t4 }
do_execsql_test -db db 3.17a {
INSERT INTO t4(rowid, a, b) VALUES(111, 'one', 'one');
INSERT INTO t4(rowid, a, b) VALUES(222, 'two', 'two');
}
do_execsql_test -db db2 3.17b {
INSERT INTO t4(rowid, a, b) VALUES(111, 'one', 'blip');
}
do_conflict_test 3.18 -sql {
UPDATE t4 SET b='xyz' WHERE a='one'
} -tables t4 -conflicts {
{UPDATE t4 DATA {i 111 {} {} t one} {{} {} {} {} t xyz} {i 111 t one t blip}}
}
do_execsql_test -db db2 3.19 {
SELECT * FROM t4
} {one blip}
do_conflict_test 3.20 -sql {
UPDATE t4 SET b='123' WHERE a='two'
} -tables t4 -conflicts {
{UPDATE t4 NOTFOUND {i 222 {} {} t two} {{} {} {} {} t 123}}
}
do_execsql_test -db db2 3.21 {
SELECT * FROM t4
} {one blip}
db2 close
#--------------------------------------------------------------------------
breakpoint
do_diff_test 4.0 {
CREATE TABLE t1(x, y);
CREATE TABLE aux.t1(x, y);
INSERT INTO t1 VALUES(1, 2);
}
do_diff_test 4.1 {
CREATE TABLE t1(x, y);
CREATE TABLE aux.t1(x, y);
INSERT INTO aux.t1 VALUES(1, 2);
}
do_diff_test 4.2 {
CREATE TABLE t1(x, y);
CREATE TABLE aux.t1(x, y);
INSERT INTO t1(rowid, x, y) VALUES(413, 'hello', 'there');
INSERT INTO aux.t1(rowid, x, y) VALUES(413, 'hello', 'world');
}
finish_test
|