File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / sqlite3 / test / sharedlock.test
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 17:04:16 2012 UTC (12 years, 10 months ago) by misho
Branches: sqlite3, MAIN
CVS tags: v3_7_10, HEAD
sqlite3

    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.1.1 2012/02/21 17:04:16 misho 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: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>