blob: bc99187d27e9729581a9f6f7d198425fce00ec5f [file] [log] [blame]
drhe77593f2012-03-31 17:50:12 +00001# 2012 March 31
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# Focus on the interaction between RELEASE and ROLLBACK TO with
13# pending query aborts. See ticket [27ca74af3c083f787a1c44b11fbb7c53bdbbcf1e].
14#
15
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18
19# The RELEASE of an inner savepoint should not effect pending queries.
20#
21do_test savepoint7-1.1 {
22 db eval {
23 CREATE TABLE t1(a,b,c);
24 CREATE TABLE t2(x,y,z);
25 INSERT INTO t1 VALUES(1,2,3);
26 INSERT INTO t1 VALUES(4,5,6);
27 INSERT INTO t1 VALUES(7,8,9);
28 SAVEPOINT x1;
29 }
30 db eval {SELECT * FROM t1} {
31 db eval {
32 SAVEPOINT x2;
33 INSERT INTO t2 VALUES($a,$b,$c);
34 RELEASE x2;
35 }
36 }
37 db eval {SELECT * FROM t2; RELEASE x1}
38} {1 2 3 4 5 6 7 8 9}
39
40do_test savepoint7-1.2 {
41 db eval {DELETE FROM t2;}
42 db eval {SELECT * FROM t1} {
43 db eval {
44 SAVEPOINT x2;
45 INSERT INTO t2 VALUES($a,$b,$c);
46 RELEASE x2;
47 }
48 }
49 db eval {SELECT * FROM t2}
50} {1 2 3 4 5 6 7 8 9}
51
52do_test savepoint7-1.3 {
53 db eval {DELETE FROM t2; BEGIN;}
54 db eval {SELECT * FROM t1} {
55 db eval {
56 SAVEPOINT x2;
57 INSERT INTO t2 VALUES($a,$b,$c);
58 RELEASE x2;
59 }
60 }
61 db eval {SELECT * FROM t2; ROLLBACK;}
62} {1 2 3 4 5 6 7 8 9}
63
64# However, a ROLLBACK of an inner savepoint will abort all queries, including
65# queries in outer contexts.
66#
67do_test savepoint7-2.1 {
68 db eval {DELETE FROM t2; SAVEPOINT x1;}
69 set rc [catch {
70 db eval {SELECT * FROM t1} {
71 db eval {
72 SAVEPOINT x2;
73 INSERT INTO t2 VALUES($a,$b,$c);
74 ROLLBACK TO x2;
75 }
76 }
77 } msg]
78 db eval {RELEASE x1}
79 list $rc $msg [db eval {SELECT * FROM t2}]
80} {1 {callback requested query abort} {}}
81
82do_test savepoint7-2.2 {
83 db eval {DELETE FROM t2;}
84 set rc [catch {
85 db eval {SELECT * FROM t1} {
86 db eval {
87 SAVEPOINT x2;
88 INSERT INTO t2 VALUES($a,$b,$c);
89 ROLLBACK TO x2;
90 }
91 }
92 } msg]
93 list $rc $msg [db eval {SELECT * FROM t2}]
94} {1 {callback requested query abort} {}}
95
96finish_test