sl@0
|
1 |
# 2004 June 30
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
# This file implements regression tests for SQLite library. The
|
sl@0
|
12 |
# focus of this file is verifying that a rollback in one statement
|
sl@0
|
13 |
# caused by an ON CONFLICT ROLLBACK clause aborts any other pending
|
sl@0
|
14 |
# statements.
|
sl@0
|
15 |
#
|
sl@0
|
16 |
# $Id: rollback.test,v 1.6 2007/09/12 17:01:45 danielk1977 Exp $
|
sl@0
|
17 |
|
sl@0
|
18 |
set testdir [file dirname $argv0]
|
sl@0
|
19 |
source $testdir/tester.tcl
|
sl@0
|
20 |
|
sl@0
|
21 |
set DB [sqlite3_connection_pointer db]
|
sl@0
|
22 |
|
sl@0
|
23 |
do_test rollback-1.1 {
|
sl@0
|
24 |
execsql {
|
sl@0
|
25 |
CREATE TABLE t1(a);
|
sl@0
|
26 |
INSERT INTO t1 VALUES(1);
|
sl@0
|
27 |
INSERT INTO t1 VALUES(2);
|
sl@0
|
28 |
INSERT INTO t1 VALUES(3);
|
sl@0
|
29 |
INSERT INTO t1 VALUES(4);
|
sl@0
|
30 |
SELECT * FROM t1;
|
sl@0
|
31 |
}
|
sl@0
|
32 |
} {1 2 3 4}
|
sl@0
|
33 |
|
sl@0
|
34 |
ifcapable conflict {
|
sl@0
|
35 |
do_test rollback-1.2 {
|
sl@0
|
36 |
execsql {
|
sl@0
|
37 |
CREATE TABLE t3(a unique on conflict rollback);
|
sl@0
|
38 |
INSERT INTO t3 SELECT a FROM t1;
|
sl@0
|
39 |
BEGIN;
|
sl@0
|
40 |
INSERT INTO t1 SELECT * FROM t1;
|
sl@0
|
41 |
}
|
sl@0
|
42 |
} {}
|
sl@0
|
43 |
}
|
sl@0
|
44 |
do_test rollback-1.3 {
|
sl@0
|
45 |
set STMT [sqlite3_prepare $DB "SELECT a FROM t1" -1 TAIL]
|
sl@0
|
46 |
sqlite3_step $STMT
|
sl@0
|
47 |
} {SQLITE_ROW}
|
sl@0
|
48 |
|
sl@0
|
49 |
ifcapable conflict {
|
sl@0
|
50 |
# This causes a ROLLBACK, which deletes the table out from underneath the
|
sl@0
|
51 |
# SELECT statement.
|
sl@0
|
52 |
#
|
sl@0
|
53 |
do_test rollback-1.4 {
|
sl@0
|
54 |
catchsql {
|
sl@0
|
55 |
INSERT INTO t3 SELECT a FROM t1;
|
sl@0
|
56 |
}
|
sl@0
|
57 |
} {1 {column a is not unique}}
|
sl@0
|
58 |
|
sl@0
|
59 |
# Try to continue with the SELECT statement
|
sl@0
|
60 |
#
|
sl@0
|
61 |
do_test rollback-1.5 {
|
sl@0
|
62 |
sqlite3_step $STMT
|
sl@0
|
63 |
} {SQLITE_ERROR}
|
sl@0
|
64 |
|
sl@0
|
65 |
# Restart the SELECT statement
|
sl@0
|
66 |
#
|
sl@0
|
67 |
do_test rollback-1.6 { sqlite3_reset $STMT } {SQLITE_ABORT}
|
sl@0
|
68 |
} else {
|
sl@0
|
69 |
do_test rollback-1.6 { sqlite3_reset $STMT } {SQLITE_OK}
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
do_test rollback-1.7 {
|
sl@0
|
73 |
sqlite3_step $STMT
|
sl@0
|
74 |
} {SQLITE_ROW}
|
sl@0
|
75 |
do_test rollback-1.8 {
|
sl@0
|
76 |
sqlite3_step $STMT
|
sl@0
|
77 |
} {SQLITE_ROW}
|
sl@0
|
78 |
do_test rollback-1.9 {
|
sl@0
|
79 |
sqlite3_finalize $STMT
|
sl@0
|
80 |
} {SQLITE_OK}
|
sl@0
|
81 |
|
sl@0
|
82 |
finish_test
|