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
|
# 2024-02-03
#
# 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.
#
#***********************************************************************
#
# ROLLBACK in the middle of an RTREE query
#
if {![info exists testdir]} {
set testdir [file join [file dirname [info script]] .. .. test]
}
source $testdir/tester.tcl
set testprefix rtreeJ
ifcapable !rtree { finish_test ; return }
do_execsql_test 1.0 {
CREATE VIRTUAL TABLE t1 USING rtree(id, x1, x2);
INSERT INTO t1 VALUES(1, 1, 1), (2, 2, 2);
} {}
do_execsql_test 1.1 {
SELECT * FROM t1
} {1 1.0 1.0 2 2.0 2.0}
# If a ROLLBACK occurs that backs out changes to the RTREE, then
# all pending queries to the RTREE are aborted.
#
do_test 1.2 {
db eval {
BEGIN;
INSERT INTO t1 VALUES(3, 3, 3);
INSERT INTO t1 VALUES(4, 4, 4);
}
set rc [catch {
db eval { SELECT * FROM t1 } {
if {$id==1} {
db eval { ROLLBACK }
}
lappend res $id $x1 $x2
}
} msg]
list $rc $msg
} {1 {query aborted}}
do_execsql_test 1.3 {
SELECT * FROM t1;
} {1 1.0 1.0 2 2.0 2.0}
# A COMMIT of changes to the RTREE does not affect pending queries
#
do_test 1.4 {
set res {}
db eval {
BEGIN;
INSERT INTO t1 VALUES(5, 5, 5);
INSERT INTO t1 VALUES(6, 6, 6);
}
db eval { SELECT * FROM t1 } {
if {$id==1} {
db eval { COMMIT }
}
lappend res $id $x1 $x2
}
set res
} {1 1.0 1.0 2 2.0 2.0 5 5.0 5.0 6 6.0 6.0}
do_execsql_test 1.5 {
SELECT * FROM t1;
} {1 1.0 1.0 2 2.0 2.0 5 5.0 5.0 6 6.0 6.0}
do_execsql_test 1.6 {
DELETE FROM t1;
INSERT INTO t1 VALUES(1,1,1),(2,2,2),(3,3,3),(4,4,4);
CREATE TABLE t2(x);
SELECT * FROM t1;
} {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0 4 4.0 4.0}
# A rollback that does not affect the rtree table because
# the rtree table has not been written to does not cause
# a query abort.
#
do_test 1.7 {
set res {}
db eval {
BEGIN;
INSERT INTO t2(x) VALUES(12345);
}
db eval { SELECT * FROM t1 } {
if {$id==1} {
db eval { ROLLBACK }
}
lappend res $id $x1 $x2
}
set res
} {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0 4 4.0 4.0}
# ROLLBACK TO that affects the RTREE does cause a query abort.
#
do_test 1.8 {
db eval {
DELETE FROM t1 WHERE rowid>1;
BEGIN;
DELETE FROM t2;
INSERT INTO t2(x) VALUES(23456);
SAVEPOINT 'one';
INSERT INTO t1 VALUES(2,2,2),(3,3,3);
}
set rc [catch {
db eval { SELECT * FROM t1 } {
if {$id==1} {
db eval { ROLLBACK TO 'one'; }
}
lappend res $id $x1 $x2
}
} msg]
list $rc $msg
} {1 {query aborted}}
do_execsql_test 1.9 {
COMMIT;
SELECT * FROM t1;
} {1 1.0 1.0}
# ROLLBACK TO that does not affect the RTREE does not cause a query abort.
#
do_execsql_test 1.10 {
DELETE FROM t1;
INSERT INTO t1 VALUES(1,1,1),(2,2,2),(3,3,3);
BEGIN;
DELETE FROM t2;
INSERT INTO t2(x) VALUES(34567);
SAVEPOINT 'one';
INSERT INTO t2(x) VALUES('a string');
SELECT * FROM t1;
} {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0}
do_test 1.11 {
set rc [catch {
set res {}
db eval { SELECT * FROM t1 } {
if {$id==2} {
# db eval { ROLLBACK TO 'one'; }
}
lappend res $id $x1 $x2
}
set res
} msg]
list $rc $msg
} {0 {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0}}
do_execsql_test 1.12 {
COMMIT;
SELECT * FROM t1;
} {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0}
#----------------------------------------------------------------------
reset_db
do_execsql_test 2.0 {
CREATE VIRTUAL TABLE t1 USING rtree(id, x1, x2);
INSERT INTO t1 VALUES(1, 1, 1), (2, 2, 2);
CREATE TABLE t2(x);
} {}
do_test 2.1 {
db eval {
BEGIN;
INSERT INTO t1 VALUES(3, 3, 3);
PRAGMA writable_schema = RESET;
}
set rc [catch {
db eval { SELECT x1, x2 FROM t1 } {
if {$x1==1} {
db eval { ROLLBACK }
}
lappend res $x1 $x2
}
} msg]
list $rc $msg
} {1 {query aborted}}
do_execsql_test 2.1 {
CREATE TABLE bak_node(nodeno, data);
CREATE TABLE bak_parent(nodeno, parentnode);
CREATE TABLE bak_rowid(rowid, nodeno);
}
proc save_t1 {} {
db eval {
DELETE FROM bak_node;
DELETE FROM bak_parent;
DELETE FROM bak_rowid;
INSERT INTO bak_node SELECT * FROM t1_node;
INSERT INTO bak_parent SELECT * FROM t1_parent;
INSERT INTO bak_rowid SELECT * FROM t1_rowid;
}
}
proc restore_t1 {} {
db eval {
DELETE FROM t1_node;
DELETE FROM t1_parent;
DELETE FROM t1_rowid;
INSERT INTO t1_node SELECT * FROM bak_node;
INSERT INTO t1_parent SELECT * FROM bak_parent;
INSERT INTO t1_rowid SELECT * FROM bak_rowid;
}
}
do_test 2.3 {
save_t1
db eval {
INSERT INTO t1 VALUES(3, 3, 3);
}
set rc [catch {
db eval { SELECT rowid, x1, x2 FROM t1 } {
if {$x1==1} {
restore_t1
}
lappend res $x1 $x2
}
} msg]
list $rc $msg
} {1 {query aborted}}
do_execsql_test 2.4 {
SELECT * FROM t1
} {1 1.0 1.0 2 2.0 2.0}
do_test 2.5 {
save_t1
db eval {
INSERT INTO t1 VALUES(3, 3, 3);
}
set rc [catch {
db eval { SELECT x1 FROM t1 } {
if {$x1==1} {
restore_t1
}
lappend res $x1 $x2
}
} msg]
list $rc $msg
} {1 {query aborted}}
do_execsql_test 2.6 {
SELECT * FROM t1
} {1 1.0 1.0 2 2.0 2.0}
do_test 2.7 {
save_t1
db eval {
INSERT INTO t1 VALUES(3, 3, 3);
}
set ::res [list]
set rc [catch {
db eval { SELECT 'abc' FROM t1 } {
if {$::res==[list]} {
restore_t1
set ::bDone 1
}
lappend res abc
}
} msg]
set res
} {abc abc abc}
do_execsql_test 2.6 {
SELECT * FROM t1
} {1 1.0 1.0 2 2.0 2.0}
finish_test
|