xref: /sqlite-3.40.0/test/rollback.test (revision 74e4352a)
1# 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#
16# $Id: rollback.test,v 1.4 2006/01/17 09:35:02 danielk1977 Exp $
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20
21set DB [sqlite3_connection_pointer db]
22
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
34ifcapable conflict {
35  do_test rollback-1.2 {
36    execsql {
37      CREATE TABLE t3(a unique on conflict rollback);
38      INSERT INTO t3 SELECT a FROM t1;
39      BEGIN;
40      INSERT INTO t1 SELECT * FROM t1;
41    }
42  } {}
43}
44do_test rollback-1.3 {
45  set STMT [sqlite3_prepare $DB "SELECT a FROM t1" -1 TAIL]
46  sqlite3_step $STMT
47} {SQLITE_ROW}
48
49ifcapable conflict {
50  # This causes a ROLLBACK, which deletes the table out from underneath the
51  # SELECT statement.
52  #
53  do_test rollback-1.4 {
54    catchsql {
55      INSERT INTO t3 SELECT a FROM t1;
56    }
57  } {1 {column a is not unique}}
58
59  # Try to continue with the SELECT statement
60  #
61  do_test rollback-1.5 {
62    sqlite3_step $STMT
63  } {SQLITE_ABORT}
64}
65
66# Restart the SELECT statement
67#
68do_test rollback-1.6 {
69  sqlite3_reset $STMT
70} {SQLITE_OK}
71do_test rollback-1.7 {
72  sqlite3_step $STMT
73} {SQLITE_ROW}
74do_test rollback-1.8 {
75  sqlite3_step $STMT
76} {SQLITE_ROW}
77do_test rollback-1.9 {
78  sqlite3_finalize $STMT
79} {SQLITE_OK}
80
81finish_test
82