blob: 820ad4b68beaa0392b9d60306a02e84ab096622c [file] [log] [blame]
drh91b48aa2004-06-30 11:14:18 +00001# 2004 June 30
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# This file implements regression tests for SQLite library. The
12# focus of this file is verifying that a rollback in one statement
13# caused by an ON CONFLICT ROLLBACK clause aborts any other pending
14# statements.
15#
drhdddca282006-01-03 00:33:50 +000016# $Id: rollback.test,v 1.3 2006/01/03 00:33:50 drh Exp $
drh91b48aa2004-06-30 11:14:18 +000017
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20
drhdddca282006-01-03 00:33:50 +000021set DB [sqlite3_connection_pointer db]
drh91b48aa2004-06-30 11:14:18 +000022
23do_test rollback-1.1 {
24 execsql {
25 CREATE TABLE t1(a);
26 INSERT INTO t1 VALUES(1);
27 INSERT INTO t1 VALUES(2);
28 INSERT INTO t1 VALUES(3);
29 INSERT INTO t1 VALUES(4);
30 SELECT * FROM t1;
31 }
32} {1 2 3 4}
33
34do_test rollback-1.2 {
35 execsql {
36 CREATE TABLE t3(a unique on conflict rollback);
37 INSERT INTO t3 SELECT a FROM t1;
38 BEGIN;
39 INSERT INTO t1 SELECT * FROM t1;
40 }
41} {}
42do_test rollback-1.3 {
43 set STMT [sqlite3_prepare $DB "SELECT a FROM t1" -1 TAIL]
44 sqlite3_step $STMT
45} {SQLITE_ROW}
46
47# This causes a ROLLBACK, which deletes the table out from underneath the
48# SELECT statement.
49#
50do_test rollback-1.4 {
51 catchsql {
52 INSERT INTO t3 SELECT a FROM t1;
53 }
54} {1 {column a is not unique}}
55
56# Try to continue with the SELECT statement
57#
58do_test rollback-1.5 {
59 sqlite3_step $STMT
60} {SQLITE_ABORT}
61
62# Restart the SELECT statement
63#
64do_test rollback-1.6 {
65 sqlite3_reset $STMT
danielk1977656152c2005-01-12 13:04:54 +000066} {SQLITE_OK}
drh91b48aa2004-06-30 11:14:18 +000067do_test rollback-1.7 {
68 sqlite3_step $STMT
69} {SQLITE_ROW}
70do_test rollback-1.8 {
71 sqlite3_step $STMT
72} {SQLITE_ROW}
73do_test rollback-1.9 {
74 sqlite3_finalize $STMT
75} {SQLITE_OK}
76
77finish_test