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 # ROLLBACK in the middle of an RTREE query
14 if {![info exists testdir]} {
15 set testdir [file join [file dirname [info script]] .. .. test]
17 source $testdir/tester.tcl
19 ifcapable !rtree { finish_test ; return }
22 CREATE VIRTUAL TABLE t1 USING rtree(id, x1, x2);
23 INSERT INTO t1 VALUES(1, 1, 1), (2, 2, 2);
28 } {1 1.0 1.0 2 2.0 2.0}
30 # If a ROLLBACK occurs that backs out changes to the RTREE, then
31 # all pending queries to the RTREE are aborted.
36 INSERT INTO t1 VALUES(3, 3, 3);
37 INSERT INTO t1 VALUES(4, 4, 4);
40 db eval { SELECT * FROM t1 } {
44 lappend res $id $x1 $x2
52 } {1 1.0 1.0 2 2.0 2.0}
54 # A COMMIT of changes to the RTREE does not affect pending queries
60 INSERT INTO t1 VALUES(5, 5, 5);
61 INSERT INTO t1 VALUES(6, 6, 6);
63 db eval { SELECT * FROM t1 } {
67 lappend res $id $x1 $x2
70 } {1 1.0 1.0 2 2.0 2.0 5 5.0 5.0 6 6.0 6.0}
74 } {1 1.0 1.0 2 2.0 2.0 5 5.0 5.0 6 6.0 6.0}
78 INSERT INTO t1 VALUES(1,1,1),(2,2,2),(3,3,3),(4,4,4);
81 } {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0 4 4.0 4.0}
83 # A rollback that does not affect the rtree table because
84 # the rtree table has not been written to does not cause
91 INSERT INTO t2(x) VALUES(12345);
93 db eval { SELECT * FROM t1 } {
97 lappend res $id $x1 $x2
100 } {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0 4 4.0 4.0}
102 # ROLLBACK TO that affects the RTREE does cause a query abort.
106 DELETE FROM t1 WHERE rowid>1;
109 INSERT INTO t2(x) VALUES(23456);
111 INSERT INTO t1 VALUES(2,2,2),(3,3,3);
114 db eval { SELECT * FROM t1 } {
116 db eval { ROLLBACK TO 'one'; }
118 lappend res $id $x1 $x2
122 } {1 {query aborted}}
124 do_execsql_test 1.9 {
129 # ROLLBACK TO that does not affect the RTREE does not cause a query abort.
131 do_execsql_test 1.10 {
133 INSERT INTO t1 VALUES(1,1,1),(2,2,2),(3,3,3);
136 INSERT INTO t2(x) VALUES(34567);
138 INSERT INTO t2(x) VALUES('a string');
140 } {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0}
144 db eval { SELECT * FROM t1 } {
146 # db eval { ROLLBACK TO 'one'; }
148 lappend res $id $x1 $x2
153 } {0 {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0}}
155 do_execsql_test 1.12 {
158 } {1 1.0 1.0 2 2.0 2.0 3 3.0 3.0}
160 #----------------------------------------------------------------------
163 do_execsql_test 2.0 {
164 CREATE VIRTUAL TABLE t1 USING rtree(id, x1, x2);
165 INSERT INTO t1 VALUES(1, 1, 1), (2, 2, 2);
172 INSERT INTO t1 VALUES(3, 3, 3);
173 PRAGMA writable_schema = RESET;
177 db eval { SELECT x1, x2 FROM t1 } {
185 } {1 {query aborted}}
187 do_execsql_test 2.1 {
188 CREATE TABLE bak_node(nodeno, data);
189 CREATE TABLE bak_parent(nodeno, parentnode);
190 CREATE TABLE bak_rowid(rowid, nodeno);
194 DELETE FROM bak_node;
195 DELETE FROM bak_parent;
196 DELETE FROM bak_rowid;
197 INSERT INTO bak_node SELECT * FROM t1_node;
198 INSERT INTO bak_parent SELECT * FROM t1_parent;
199 INSERT INTO bak_rowid SELECT * FROM t1_rowid;
205 DELETE FROM t1_parent;
206 DELETE FROM t1_rowid;
207 INSERT INTO t1_node SELECT * FROM bak_node;
208 INSERT INTO t1_parent SELECT * FROM bak_parent;
209 INSERT INTO t1_rowid SELECT * FROM bak_rowid;
216 INSERT INTO t1 VALUES(3, 3, 3);
219 db eval { SELECT rowid, x1, x2 FROM t1 } {
227 } {1 {query aborted}}
228 do_execsql_test 2.4 {
230 } {1 1.0 1.0 2 2.0 2.0}
235 INSERT INTO t1 VALUES(3, 3, 3);
238 db eval { SELECT x1 FROM t1 } {
246 } {1 {query aborted}}
247 do_execsql_test 2.6 {
249 } {1 1.0 1.0 2 2.0 2.0}
254 INSERT INTO t1 VALUES(3, 3, 3);
258 db eval { SELECT 'abc' FROM t1 } {
259 if {$::res==[list]} {
268 do_execsql_test 2.6 {
270 } {1 1.0 1.0 2 2.0 2.0}