os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/shared2.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/shared2.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,131 @@
     1.4 +# 2005 January 19
     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 +#
    1.15 +# $Id: shared2.test,v 1.5 2007/08/23 02:47:54 drh Exp $
    1.16 +
    1.17 +set testdir [file dirname $argv0]
    1.18 +source $testdir/tester.tcl
    1.19 +db close
    1.20 +
    1.21 +ifcapable !shared_cache {
    1.22 +  finish_test
    1.23 +  return
    1.24 +}
    1.25 +set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
    1.26 +
    1.27 +# Test that if we delete all rows from a table any read-uncommitted 
    1.28 +# cursors are correctly invalidated. Test on both table and index btrees.
    1.29 +do_test shared2-1.1 {
    1.30 +  sqlite3 db1 test.db
    1.31 +  sqlite3 db2 test.db
    1.32 +
    1.33 +  # Set up some data. Table "numbers" has 64 rows after this block 
    1.34 +  # is executed.
    1.35 +  execsql {
    1.36 +    BEGIN;
    1.37 +    CREATE TABLE numbers(a PRIMARY KEY, b);
    1.38 +    INSERT INTO numbers(oid) VALUES(NULL);
    1.39 +    INSERT INTO numbers(oid) SELECT NULL FROM numbers;
    1.40 +    INSERT INTO numbers(oid) SELECT NULL FROM numbers;
    1.41 +    INSERT INTO numbers(oid) SELECT NULL FROM numbers;
    1.42 +    INSERT INTO numbers(oid) SELECT NULL FROM numbers;
    1.43 +    INSERT INTO numbers(oid) SELECT NULL FROM numbers;
    1.44 +    INSERT INTO numbers(oid) SELECT NULL FROM numbers;
    1.45 +    UPDATE numbers set a = oid, b = 'abcdefghijklmnopqrstuvwxyz0123456789';
    1.46 +    COMMIT;
    1.47 +  } db1
    1.48 +} {}
    1.49 +do_test shared2-1.2 {
    1.50 +  # Put connection 2 in read-uncommitted mode and start a SELECT on table 
    1.51 +  # 'numbers'. Half way through the SELECT, use connection 1 to delete the
    1.52 +  # contents of this table.
    1.53 +  execsql {
    1.54 +    pragma read_uncommitted = 1;
    1.55 +  } db2
    1.56 +  set count [execsql {SELECT count(*) FROM numbers} db2]
    1.57 +  db2 eval {SELECT a FROM numbers ORDER BY oid} {
    1.58 +    if {$a==32} {
    1.59 +      execsql {
    1.60 +        BEGIN;
    1.61 +        DELETE FROM numbers;
    1.62 +      } db1
    1.63 +    }
    1.64 +  }
    1.65 +  list $a $count
    1.66 +} {32 64}
    1.67 +do_test shared2-1.3 {
    1.68 +  # Same test as 1.2, except scan using the index this time.
    1.69 +  execsql {
    1.70 +    ROLLBACK;
    1.71 +  } db1
    1.72 +  set count [execsql {SELECT count(*) FROM numbers} db2]
    1.73 +  db2 eval {SELECT a, b FROM numbers ORDER BY a} {
    1.74 +    if {$a==32} {
    1.75 +      execsql {
    1.76 +        DELETE FROM numbers;
    1.77 +      } db1
    1.78 +    }
    1.79 +  }
    1.80 +  list $a $count
    1.81 +} {32 64}
    1.82 +
    1.83 +#---------------------------------------------------------------------------
    1.84 +# These tests, shared2.2.*, test the outcome when data is added to or 
    1.85 +# removed from a table due to a rollback while a read-uncommitted 
    1.86 +# cursor is scanning it.
    1.87 +#
    1.88 +do_test shared2-2.1 {
    1.89 +  execsql {
    1.90 +    INSERT INTO numbers VALUES(1, 'Medium length text field');
    1.91 +    INSERT INTO numbers VALUES(2, 'Medium length text field');
    1.92 +    INSERT INTO numbers VALUES(3, 'Medium length text field');
    1.93 +    INSERT INTO numbers VALUES(4, 'Medium length text field');
    1.94 +    BEGIN;
    1.95 +    DELETE FROM numbers WHERE (a%2)=0;
    1.96 +  } db1
    1.97 +  set res [list]
    1.98 +  db2 eval {
    1.99 +    SELECT a FROM numbers ORDER BY a;
   1.100 +  } {
   1.101 +    lappend res $a
   1.102 +    if {$a==3} {
   1.103 +      execsql {ROLLBACK} db1
   1.104 +    }
   1.105 +  }
   1.106 +  set res
   1.107 +} {1 3 4}
   1.108 +do_test shared2-2.2 {
   1.109 +  execsql {
   1.110 +    BEGIN;
   1.111 +    INSERT INTO numbers VALUES(5, 'Medium length text field');
   1.112 +    INSERT INTO numbers VALUES(6, 'Medium length text field');
   1.113 +  } db1
   1.114 +  set res [list]
   1.115 +  db2 eval {
   1.116 +    SELECT a FROM numbers ORDER BY a;
   1.117 +  } {
   1.118 +    lappend res $a
   1.119 +    if {$a==5} {
   1.120 +      execsql {ROLLBACK} db1
   1.121 +    }
   1.122 +  }
   1.123 +  set res
   1.124 +} {1 2 3 4 5}
   1.125 +
   1.126 +db1 close
   1.127 +db2 close
   1.128 +
   1.129 +do_test shared2-3.2 {
   1.130 +  sqlite3_enable_shared_cache 1
   1.131 +} {1}
   1.132 +
   1.133 +sqlite3_enable_shared_cache $::enable_shared_cache
   1.134 +finish_test