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.2 2005/01/12 13:04:55 danielk1977 Exp $ 17 18set testdir [file dirname $argv0] 19source $testdir/tester.tcl 20 21db close 22set DB [sqlite3 db test.db] 23 24do_test rollback-1.1 { 25 execsql { 26 CREATE TABLE t1(a); 27 INSERT INTO t1 VALUES(1); 28 INSERT INTO t1 VALUES(2); 29 INSERT INTO t1 VALUES(3); 30 INSERT INTO t1 VALUES(4); 31 SELECT * FROM t1; 32 } 33} {1 2 3 4} 34 35do_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} {} 43do_test rollback-1.3 { 44 set STMT [sqlite3_prepare $DB "SELECT a FROM t1" -1 TAIL] 45 sqlite3_step $STMT 46} {SQLITE_ROW} 47 48# This causes a ROLLBACK, which deletes the table out from underneath the 49# SELECT statement. 50# 51do_test rollback-1.4 { 52 catchsql { 53 INSERT INTO t3 SELECT a FROM t1; 54 } 55} {1 {column a is not unique}} 56 57# Try to continue with the SELECT statement 58# 59do_test rollback-1.5 { 60 sqlite3_step $STMT 61} {SQLITE_ABORT} 62 63# Restart the SELECT statement 64# 65do_test rollback-1.6 { 66 sqlite3_reset $STMT 67} {SQLITE_OK} 68do_test rollback-1.7 { 69 sqlite3_step $STMT 70} {SQLITE_ROW} 71do_test rollback-1.8 { 72 sqlite3_step $STMT 73} {SQLITE_ROW} 74do_test rollback-1.9 { 75 sqlite3_finalize $STMT 76} {SQLITE_OK} 77 78finish_test 79