OLD | NEW |
(Empty) | |
| 1 # 2001 September 15 |
| 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 # This file implements regression tests for SQLite library. The |
| 12 # focus of this script is database locks and the operation of the |
| 13 # DEFERRED, IMMEDIATE, and EXCLUSIVE keywords as modifiers to the |
| 14 # BEGIN command. |
| 15 # |
| 16 # $Id: lock3.test,v 1.4 2009/03/28 15:04:24 drh Exp $ |
| 17 |
| 18 |
| 19 set testdir [file dirname $argv0] |
| 20 source $testdir/tester.tcl |
| 21 |
| 22 # Establish two connections to the same database. Put some |
| 23 # sample data into the database. |
| 24 # |
| 25 do_test lock3-1.1 { |
| 26 file mkdir tempdir/t1/t2/t3 |
| 27 sqlite3 db2 ./tempdir/t1//t2/./t3//./../..//./../../tempdir/..//test.db// |
| 28 execsql { |
| 29 CREATE TABLE t1(a); |
| 30 INSERT INTO t1 VALUES(1); |
| 31 } |
| 32 execsql { |
| 33 SELECT * FROM t1 |
| 34 } db2 |
| 35 } 1 |
| 36 |
| 37 # Get a deferred lock on the database using one connection. The |
| 38 # other connection should still be able to write. |
| 39 # |
| 40 do_test lock3-2.1 { |
| 41 execsql {BEGIN DEFERRED TRANSACTION} |
| 42 execsql {INSERT INTO t1 VALUES(2)} db2 |
| 43 execsql {END TRANSACTION} |
| 44 execsql {SELECT * FROM t1} |
| 45 } {1 2} |
| 46 |
| 47 # Get an immediate lock on the database using one connection. The |
| 48 # other connection should be able to read the database but not write |
| 49 # it. |
| 50 # |
| 51 do_test lock3-3.1 { |
| 52 execsql {BEGIN IMMEDIATE TRANSACTION} |
| 53 catchsql {SELECT * FROM t1} db2 |
| 54 } {0 {1 2}} |
| 55 do_test lock3-3.2 { |
| 56 catchsql {INSERT INTO t1 VALUES(3)} db2 |
| 57 } {1 {database is locked}} |
| 58 do_test lock3-3.3 { |
| 59 execsql {END TRANSACTION} |
| 60 } {} |
| 61 |
| 62 |
| 63 # Get an exclusive lock on the database using one connection. The |
| 64 # other connection should be unable to read or write the database. |
| 65 # |
| 66 do_test lock3-4.1 { |
| 67 execsql {BEGIN EXCLUSIVE TRANSACTION} |
| 68 catchsql {SELECT * FROM t1} db2 |
| 69 } {1 {database is locked}} |
| 70 do_test lock3-4.2 { |
| 71 catchsql {INSERT INTO t1 VALUES(3)} db2 |
| 72 } {1 {database is locked}} |
| 73 do_test lock3-4.3 { |
| 74 execsql {END TRANSACTION} |
| 75 } {} |
| 76 |
| 77 catch {db2 close} |
| 78 |
| 79 finish_test |
OLD | NEW |