xref: /sqlite-3.40.0/test/trans3.test (revision 85fabf14)
13e0a3c9dSdrh# 2008 November 3
23e0a3c9dSdrh#
33e0a3c9dSdrh# The author disclaims copyright to this source code.  In place of
43e0a3c9dSdrh# a legal notice, here is a blessing:
53e0a3c9dSdrh#
63e0a3c9dSdrh#    May you do good and not evil.
73e0a3c9dSdrh#    May you find forgiveness for yourself and forgive others.
83e0a3c9dSdrh#    May you share freely, never taking more than you give.
93e0a3c9dSdrh#
103e0a3c9dSdrh#***********************************************************************
113e0a3c9dSdrh#
123e0a3c9dSdrh# This file implements regression tests for SQLite library.  The
133e0a3c9dSdrh# focus of this script is the response of COMMIT and ROLLBACK when
143e0a3c9dSdrh# statements are still pending.
153e0a3c9dSdrh#
16ad4a4b80Sdrh# $Id: trans3.test,v 1.2 2008/11/05 16:37:35 drh Exp $
173e0a3c9dSdrh#
183e0a3c9dSdrhset testdir [file dirname $argv0]
193e0a3c9dSdrhsource $testdir/tester.tcl
203e0a3c9dSdrhunset -nocomplain ecode
213e0a3c9dSdrh
223e0a3c9dSdrhdo_test trans3-1.1 {
233e0a3c9dSdrh  db eval {
243e0a3c9dSdrh    CREATE TABLE t1(x);
253e0a3c9dSdrh    INSERT INTO t1 VALUES(1);
263e0a3c9dSdrh    INSERT INTO t1 VALUES(2);
273e0a3c9dSdrh    INSERT INTO t1 VALUES(3);
283e0a3c9dSdrh    SELECT * FROM t1;
293e0a3c9dSdrh  }
303e0a3c9dSdrh} {1 2 3}
313e0a3c9dSdrhdo_test trans3-1.2 {
323e0a3c9dSdrh  db eval BEGIN
333e0a3c9dSdrh  db eval {INSERT INTO t1 VALUES(4);}
343e0a3c9dSdrh  set ::ecode {}
353e0a3c9dSdrh  set x [catch {
36ad4a4b80Sdrh     db eval {SELECT * FROM t1 LIMIT 1} {
373e0a3c9dSdrh        if {[catch {db eval COMMIT} errmsg]} {
383e0a3c9dSdrh           set ::ecode [sqlite3_extended_errcode db]
393e0a3c9dSdrh           error $errmsg
403e0a3c9dSdrh        }
413e0a3c9dSdrh     }
423e0a3c9dSdrh  } errmsg]
433e0a3c9dSdrh  lappend x $errmsg
44ad4a4b80Sdrh} {0 {}}
453e0a3c9dSdrhdo_test trans3-1.3 {
463e0a3c9dSdrh  set ::ecode
47ad4a4b80Sdrh} {}
48ad4a4b80Sdrhdo_test trans3-1.3.1 {
49ad4a4b80Sdrh  sqlite3_get_autocommit db
50ad4a4b80Sdrh} 1
513e0a3c9dSdrhdo_test trans3-1.4 {
523e0a3c9dSdrh  db eval {SELECT * FROM t1}
533e0a3c9dSdrh} {1 2 3 4}
543e0a3c9dSdrhdo_test trans3-1.5 {
55*85fabf14Sdrh  db eval {BEGIN; CREATE TABLE xyzzy(abc);}
563e0a3c9dSdrh  db eval {INSERT INTO t1 VALUES(5);}
573e0a3c9dSdrh  set ::ecode {}
583e0a3c9dSdrh  set x [catch {
593e0a3c9dSdrh     db eval {SELECT * FROM t1} {
603e0a3c9dSdrh        if {[catch {db eval ROLLBACK} errmsg]} {
613e0a3c9dSdrh           set ::ecode [sqlite3_extended_errcode db]
623e0a3c9dSdrh           error $errmsg
633e0a3c9dSdrh        }
643e0a3c9dSdrh     }
653e0a3c9dSdrh  } errmsg]
663e0a3c9dSdrh  lappend x $errmsg
6721021a5cSdrh} {1 {abort due to ROLLBACK}}
683e0a3c9dSdrhdo_test trans3-1.6 {
693e0a3c9dSdrh  set ::ecode
7021021a5cSdrh} {}
713e0a3c9dSdrhdo_test trans3-1.7 {
723e0a3c9dSdrh  db eval {SELECT * FROM t1}
7321021a5cSdrh} {1 2 3 4}
743e0a3c9dSdrhunset -nocomplain ecode
753e0a3c9dSdrh
763e0a3c9dSdrhfinish_test
77