Home | History | Annotate | Download | only in test
      1 # 2009 July 2
      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 # $Id: sharedlock.test,v 1.1 2009/07/02 17:21:58 danielk1977 Exp $
     13 
     14 set testdir [file dirname $argv0]
     15 source $testdir/tester.tcl
     16 db close
     17 
     18 ifcapable !shared_cache {
     19   finish_test
     20   return
     21 }
     22 
     23 set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
     24 sqlite3 db  test.db
     25 sqlite3 db2 test.db
     26 
     27 do_test sharedlock-1.1 {
     28   execsql {
     29     CREATE TABLE t1(a, b);
     30     INSERT INTO t1 VALUES(1, 'one');
     31     INSERT INTO t1 VALUES(2, 'two');
     32   }
     33 } {}
     34 
     35 do_test sharedlock-1.2 {
     36   set res [list]
     37   db eval { SELECT * FROM t1 ORDER BY rowid } {
     38     lappend res $a $b
     39     if {$a == 1} { catch { db  eval "INSERT INTO t1 VALUES(3, 'three')" } }
     40 
     41     # This should fail. Connection [db] has a read-lock on t1, which should
     42     # prevent connection [db2] from obtaining the write-lock it needs to
     43     # modify t1. At one point there was a bug causing the previous INSERT
     44     # to drop the read-lock belonging to [db].
     45     if {$a == 2} { catch { db2 eval "INSERT INTO t1 VALUES(4, 'four')"  } }
     46   }
     47   set res
     48 } {1 one 2 two 3 three}
     49 
     50 db close
     51 db2 close
     52 
     53 sqlite3_enable_shared_cache $::enable_shared_cache
     54 finish_test
     55 
     56