1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/lock3.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,78 @@
1.4 +# 2001 September 15
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 script is database locks and the operation of the
1.16 +# DEFERRED, IMMEDIATE, and EXCLUSIVE keywords as modifiers to the
1.17 +# BEGIN command.
1.18 +#
1.19 +# $Id: lock3.test,v 1.1 2004/10/05 02:41:43 drh Exp $
1.20 +
1.21 +
1.22 +set testdir [file dirname $argv0]
1.23 +source $testdir/tester.tcl
1.24 +
1.25 +# Establish two connections to the same database. Put some
1.26 +# sample data into the database.
1.27 +#
1.28 +do_test lock3-1.1 {
1.29 + sqlite3 db2 test.db
1.30 + execsql {
1.31 + CREATE TABLE t1(a);
1.32 + INSERT INTO t1 VALUES(1);
1.33 + }
1.34 + execsql {
1.35 + SELECT * FROM t1
1.36 + } db2
1.37 +} 1
1.38 +
1.39 +# Get a deferred lock on the database using one connection. The
1.40 +# other connection should still be able to write.
1.41 +#
1.42 +do_test lock3-2.1 {
1.43 + execsql {BEGIN DEFERRED TRANSACTION}
1.44 + execsql {INSERT INTO t1 VALUES(2)} db2
1.45 + execsql {END TRANSACTION}
1.46 + execsql {SELECT * FROM t1}
1.47 +} {1 2}
1.48 +
1.49 +# Get an immediate lock on the database using one connection. The
1.50 +# other connection should be able to read the database but not write
1.51 +# it.
1.52 +#
1.53 +do_test lock3-3.1 {
1.54 + execsql {BEGIN IMMEDIATE TRANSACTION}
1.55 + catchsql {SELECT * FROM t1} db2
1.56 +} {0 {1 2}}
1.57 +do_test lock3-3.2 {
1.58 + catchsql {INSERT INTO t1 VALUES(3)} db2
1.59 +} {1 {database is locked}}
1.60 +do_test lock3-3.3 {
1.61 + execsql {END TRANSACTION}
1.62 +} {}
1.63 +
1.64 +
1.65 +# Get an exclusive lock on the database using one connection. The
1.66 +# other connection should be unable to read or write the database.
1.67 +#
1.68 +do_test lock3-4.1 {
1.69 + execsql {BEGIN EXCLUSIVE TRANSACTION}
1.70 + catchsql {SELECT * FROM t1} db2
1.71 +} {1 {database is locked}}
1.72 +do_test lock3-4.2 {
1.73 + catchsql {INSERT INTO t1 VALUES(3)} db2
1.74 +} {1 {database is locked}}
1.75 +do_test lock3-4.3 {
1.76 + execsql {END TRANSACTION}
1.77 +} {}
1.78 +
1.79 +catch {db2 close}
1.80 +
1.81 +finish_test