os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/rollback.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/rollback.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,82 @@
     1.4 +# 2004 June 30
     1.5 +#
     1.6 +# The author disclaims copyright to this source code.  In place of
     1.7 +# a legal notice, here is a blessing:
     1.8 +#
     1.9 +#    May you do good and not evil.
    1.10 +#    May you find forgiveness for yourself and forgive others.
    1.11 +#    May you share freely, never taking more than you give.
    1.12 +#
    1.13 +#***********************************************************************
    1.14 +# This file implements regression tests for SQLite library.  The
    1.15 +# focus of this file is verifying that a rollback in one statement
    1.16 +# caused by an ON CONFLICT ROLLBACK clause aborts any other pending
    1.17 +# statements.
    1.18 +#
    1.19 +# $Id: rollback.test,v 1.6 2007/09/12 17:01:45 danielk1977 Exp $
    1.20 +
    1.21 +set testdir [file dirname $argv0]
    1.22 +source $testdir/tester.tcl
    1.23 +
    1.24 +set DB [sqlite3_connection_pointer db]
    1.25 +
    1.26 +do_test rollback-1.1 {
    1.27 +  execsql {
    1.28 +    CREATE TABLE t1(a);
    1.29 +    INSERT INTO t1 VALUES(1);
    1.30 +    INSERT INTO t1 VALUES(2);
    1.31 +    INSERT INTO t1 VALUES(3);
    1.32 +    INSERT INTO t1 VALUES(4);
    1.33 +    SELECT * FROM t1;
    1.34 +  }
    1.35 +} {1 2 3 4}
    1.36 +
    1.37 +ifcapable conflict {
    1.38 +  do_test rollback-1.2 {
    1.39 +    execsql {
    1.40 +      CREATE TABLE t3(a unique on conflict rollback);
    1.41 +      INSERT INTO t3 SELECT a FROM t1;
    1.42 +      BEGIN;
    1.43 +      INSERT INTO t1 SELECT * FROM t1;
    1.44 +    }
    1.45 +  } {}
    1.46 +}
    1.47 +do_test rollback-1.3 {
    1.48 +  set STMT [sqlite3_prepare $DB "SELECT a FROM t1" -1 TAIL]
    1.49 +  sqlite3_step $STMT
    1.50 +} {SQLITE_ROW}
    1.51 +
    1.52 +ifcapable conflict {
    1.53 +  # This causes a ROLLBACK, which deletes the table out from underneath the
    1.54 +  # SELECT statement.
    1.55 +  #
    1.56 +  do_test rollback-1.4 {
    1.57 +    catchsql {
    1.58 +      INSERT INTO t3 SELECT a FROM t1;
    1.59 +    }
    1.60 +  } {1 {column a is not unique}}
    1.61 +  
    1.62 +  # Try to continue with the SELECT statement
    1.63 +  #
    1.64 +  do_test rollback-1.5 {
    1.65 +    sqlite3_step $STMT
    1.66 +  } {SQLITE_ERROR}
    1.67 +
    1.68 +  # Restart the SELECT statement
    1.69 +  #
    1.70 +  do_test rollback-1.6 { sqlite3_reset $STMT } {SQLITE_ABORT}
    1.71 +} else {
    1.72 +  do_test rollback-1.6 { sqlite3_reset $STMT } {SQLITE_OK}
    1.73 +}
    1.74 +
    1.75 +do_test rollback-1.7 {
    1.76 +  sqlite3_step $STMT
    1.77 +} {SQLITE_ROW}
    1.78 +do_test rollback-1.8 {
    1.79 +  sqlite3_step $STMT
    1.80 +} {SQLITE_ROW}
    1.81 +do_test rollback-1.9 {
    1.82 +  sqlite3_finalize $STMT
    1.83 +} {SQLITE_OK}
    1.84 +
    1.85 +finish_test