blob: e82844241580d83369c210d104af4fa34a2cec55 [file] [log] [blame]
drh3e0a3c92008-11-03 21:40:00 +00001# 2008 November 3
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#
12# This file implements regression tests for SQLite library. The
13# focus of this script is the response of COMMIT and ROLLBACK when
14# statements are still pending.
15#
drhad4a4b82008-11-05 16:37:34 +000016# $Id: trans3.test,v 1.2 2008/11/05 16:37:35 drh Exp $
drh3e0a3c92008-11-03 21:40:00 +000017#
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20unset -nocomplain ecode
21
22do_test trans3-1.1 {
23 db eval {
24 CREATE TABLE t1(x);
25 INSERT INTO t1 VALUES(1);
26 INSERT INTO t1 VALUES(2);
27 INSERT INTO t1 VALUES(3);
28 SELECT * FROM t1;
29 }
30} {1 2 3}
31do_test trans3-1.2 {
32 db eval BEGIN
33 db eval {INSERT INTO t1 VALUES(4);}
34 set ::ecode {}
35 set x [catch {
drhad4a4b82008-11-05 16:37:34 +000036 db eval {SELECT * FROM t1 LIMIT 1} {
drh3e0a3c92008-11-03 21:40:00 +000037 if {[catch {db eval COMMIT} errmsg]} {
38 set ::ecode [sqlite3_extended_errcode db]
39 error $errmsg
40 }
41 }
42 } errmsg]
43 lappend x $errmsg
drhad4a4b82008-11-05 16:37:34 +000044} {0 {}}
drh3e0a3c92008-11-03 21:40:00 +000045do_test trans3-1.3 {
46 set ::ecode
drhad4a4b82008-11-05 16:37:34 +000047} {}
48do_test trans3-1.3.1 {
49 sqlite3_get_autocommit db
50} 1
drh3e0a3c92008-11-03 21:40:00 +000051do_test trans3-1.4 {
drh3e0a3c92008-11-03 21:40:00 +000052 db eval {SELECT * FROM t1}
53} {1 2 3 4}
54do_test trans3-1.5 {
drh47b7fc72014-11-11 01:33:57 +000055 db eval {BEGIN; CREATE TABLE xyzzy(abc);}
drh3e0a3c92008-11-03 21:40:00 +000056 db eval {INSERT INTO t1 VALUES(5);}
57 set ::ecode {}
58 set x [catch {
59 db eval {SELECT * FROM t1} {
60 if {[catch {db eval ROLLBACK} errmsg]} {
61 set ::ecode [sqlite3_extended_errcode db]
62 error $errmsg
63 }
64 }
65 } errmsg]
66 lappend x $errmsg
drh21021a52012-02-13 17:01:51 +000067} {1 {abort due to ROLLBACK}}
drh3e0a3c92008-11-03 21:40:00 +000068do_test trans3-1.6 {
69 set ::ecode
drh21021a52012-02-13 17:01:51 +000070} {}
drh3e0a3c92008-11-03 21:40:00 +000071do_test trans3-1.7 {
drh3e0a3c92008-11-03 21:40:00 +000072 db eval {SELECT * FROM t1}
drh21021a52012-02-13 17:01:51 +000073} {1 2 3 4}
drh3e0a3c92008-11-03 21:40:00 +000074unset -nocomplain ecode
75
76finish_test