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