sl@0: # 2004 June 30 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. The sl@0: # focus of this file is verifying that a rollback in one statement sl@0: # caused by an ON CONFLICT ROLLBACK clause aborts any other pending sl@0: # statements. sl@0: # sl@0: # $Id: rollback.test,v 1.6 2007/09/12 17:01:45 danielk1977 Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: set DB [sqlite3_connection_pointer db] sl@0: sl@0: do_test rollback-1.1 { sl@0: execsql { sl@0: CREATE TABLE t1(a); sl@0: INSERT INTO t1 VALUES(1); sl@0: INSERT INTO t1 VALUES(2); sl@0: INSERT INTO t1 VALUES(3); sl@0: INSERT INTO t1 VALUES(4); sl@0: SELECT * FROM t1; sl@0: } sl@0: } {1 2 3 4} sl@0: sl@0: ifcapable conflict { sl@0: do_test rollback-1.2 { sl@0: execsql { sl@0: CREATE TABLE t3(a unique on conflict rollback); sl@0: INSERT INTO t3 SELECT a FROM t1; sl@0: BEGIN; sl@0: INSERT INTO t1 SELECT * FROM t1; sl@0: } sl@0: } {} sl@0: } sl@0: do_test rollback-1.3 { sl@0: set STMT [sqlite3_prepare $DB "SELECT a FROM t1" -1 TAIL] sl@0: sqlite3_step $STMT sl@0: } {SQLITE_ROW} sl@0: sl@0: ifcapable conflict { sl@0: # This causes a ROLLBACK, which deletes the table out from underneath the sl@0: # SELECT statement. sl@0: # sl@0: do_test rollback-1.4 { sl@0: catchsql { sl@0: INSERT INTO t3 SELECT a FROM t1; sl@0: } sl@0: } {1 {column a is not unique}} sl@0: sl@0: # Try to continue with the SELECT statement sl@0: # sl@0: do_test rollback-1.5 { sl@0: sqlite3_step $STMT sl@0: } {SQLITE_ERROR} sl@0: sl@0: # Restart the SELECT statement sl@0: # sl@0: do_test rollback-1.6 { sqlite3_reset $STMT } {SQLITE_ABORT} sl@0: } else { sl@0: do_test rollback-1.6 { sqlite3_reset $STMT } {SQLITE_OK} sl@0: } sl@0: sl@0: do_test rollback-1.7 { sl@0: sqlite3_step $STMT sl@0: } {SQLITE_ROW} sl@0: do_test rollback-1.8 { sl@0: sqlite3_step $STMT sl@0: } {SQLITE_ROW} sl@0: do_test rollback-1.9 { sl@0: sqlite3_finalize $STMT sl@0: } {SQLITE_OK} sl@0: sl@0: finish_test