2008-07-30 13:15:43 +00:00
|
|
|
# 2008 June 28
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
# This file implements regression tests for SQLite library. The
|
|
|
|
# focus of this script is database locks.
|
|
|
|
#
|
2009-02-20 20:33:35 +00:00
|
|
|
# $Id: lock5.test,v 1.6 2008/12/04 12:34:16 drh Exp $
|
2008-07-30 13:15:43 +00:00
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
|
|
|
|
|
|
|
# This file is only run if using the unix backend compiled with the
|
|
|
|
# SQLITE_ENABLE_LOCKING_STYLE macro.
|
|
|
|
db close
|
|
|
|
if {[catch {sqlite3 db test.db -vfs unix-none} msg]} {
|
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
|
|
|
db close
|
2011-12-26 19:52:17 +00:00
|
|
|
forcedelete test.db.lock
|
2009-02-20 20:33:35 +00:00
|
|
|
|
|
|
|
ifcapable lock_proxy_pragmas {
|
|
|
|
set ::using_proxy 0
|
|
|
|
foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {
|
|
|
|
set ::using_proxy $value
|
|
|
|
}
|
|
|
|
# Disable the proxy locking for these tests
|
|
|
|
set env(SQLITE_FORCE_PROXY_LOCKING) "0"
|
|
|
|
}
|
|
|
|
|
2008-07-30 13:15:43 +00:00
|
|
|
|
|
|
|
do_test lock5-dotfile.1 {
|
|
|
|
sqlite3 db test.db -vfs unix-dotfile
|
|
|
|
execsql {
|
|
|
|
BEGIN;
|
|
|
|
CREATE TABLE t1(a, b);
|
|
|
|
}
|
|
|
|
} {}
|
|
|
|
|
|
|
|
do_test lock5-dotfile.2 {
|
|
|
|
file exists test.db.lock
|
|
|
|
} {1}
|
|
|
|
|
|
|
|
do_test lock5-dotfile.3 {
|
|
|
|
execsql COMMIT
|
|
|
|
file exists test.db.lock
|
|
|
|
} {0}
|
|
|
|
|
|
|
|
do_test lock5-dotfile.4 {
|
|
|
|
sqlite3 db2 test.db -vfs unix-dotfile
|
|
|
|
execsql {
|
|
|
|
INSERT INTO t1 VALUES('a', 'b');
|
|
|
|
SELECT * FROM t1;
|
|
|
|
} db2
|
|
|
|
} {a b}
|
|
|
|
|
|
|
|
do_test lock5-dotfile.5 {
|
|
|
|
execsql {
|
|
|
|
BEGIN;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
} db2
|
|
|
|
} {a b}
|
|
|
|
|
|
|
|
do_test lock5-dotfile.6 {
|
|
|
|
file exists test.db.lock
|
|
|
|
} {1}
|
|
|
|
|
|
|
|
do_test lock5-dotfile.7 {
|
|
|
|
catchsql { SELECT * FROM t1; }
|
|
|
|
} {1 {database is locked}}
|
|
|
|
|
|
|
|
do_test lock5-dotfile.8 {
|
|
|
|
execsql {
|
|
|
|
SELECT * FROM t1;
|
|
|
|
ROLLBACK;
|
|
|
|
} db2
|
|
|
|
} {a b}
|
|
|
|
|
|
|
|
do_test lock5-dotfile.9 {
|
|
|
|
catchsql { SELECT * FROM t1; }
|
|
|
|
} {0 {a b}}
|
|
|
|
|
|
|
|
do_test lock5-dotfile.10 {
|
|
|
|
file exists test.db.lock
|
|
|
|
} {0}
|
|
|
|
|
|
|
|
do_test lock5-dotfile.X {
|
|
|
|
db2 close
|
|
|
|
execsql {BEGIN EXCLUSIVE}
|
|
|
|
db close
|
|
|
|
file exists test.db.lock
|
|
|
|
} {0}
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
|
2011-12-26 19:52:17 +00:00
|
|
|
forcedelete test.db
|
2009-02-20 20:33:35 +00:00
|
|
|
if {[catch {sqlite3 db test.db -vfs unix-flock} msg]} {
|
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
2008-07-30 13:15:43 +00:00
|
|
|
|
|
|
|
do_test lock5-flock.1 {
|
|
|
|
sqlite3 db test.db -vfs unix-flock
|
|
|
|
execsql {
|
|
|
|
CREATE TABLE t1(a, b);
|
|
|
|
BEGIN;
|
|
|
|
INSERT INTO t1 VALUES(1, 2);
|
|
|
|
}
|
|
|
|
} {}
|
|
|
|
|
|
|
|
# Make sure we are not accidentally using the dotfile locking scheme.
|
|
|
|
do_test lock5-flock.2 {
|
|
|
|
file exists test.db.lock
|
|
|
|
} {0}
|
|
|
|
|
|
|
|
do_test lock5-flock.3 {
|
2010-07-22 13:16:22 +00:00
|
|
|
catch { sqlite3 db2 test.db -vfs unix-flock }
|
2008-07-30 13:15:43 +00:00
|
|
|
catchsql { SELECT * FROM t1 } db2
|
|
|
|
} {1 {database is locked}}
|
|
|
|
|
|
|
|
do_test lock5-flock.4 {
|
|
|
|
execsql COMMIT
|
|
|
|
catchsql { SELECT * FROM t1 } db2
|
|
|
|
} {0 {1 2}}
|
|
|
|
|
|
|
|
do_test lock5-flock.5 {
|
|
|
|
execsql BEGIN
|
|
|
|
catchsql { SELECT * FROM t1 } db2
|
|
|
|
} {0 {1 2}}
|
|
|
|
|
|
|
|
do_test lock5-flock.6 {
|
|
|
|
execsql {SELECT * FROM t1}
|
|
|
|
catchsql { SELECT * FROM t1 } db2
|
|
|
|
} {1 {database is locked}}
|
|
|
|
|
|
|
|
do_test lock5-flock.7 {
|
|
|
|
db close
|
|
|
|
catchsql { SELECT * FROM t1 } db2
|
|
|
|
} {0 {1 2}}
|
|
|
|
|
|
|
|
do_test lock5-flock.8 {
|
|
|
|
db2 close
|
|
|
|
} {}
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
|
|
|
|
do_test lock5-none.1 {
|
|
|
|
sqlite3 db test.db -vfs unix-none
|
|
|
|
sqlite3 db2 test.db -vfs unix-none
|
|
|
|
execsql {
|
|
|
|
BEGIN;
|
|
|
|
INSERT INTO t1 VALUES(3, 4);
|
|
|
|
}
|
|
|
|
} {}
|
|
|
|
do_test lock5-none.2 {
|
|
|
|
execsql { SELECT * FROM t1 }
|
|
|
|
} {1 2 3 4}
|
|
|
|
do_test lock5-flock.3 {
|
|
|
|
execsql { SELECT * FROM t1 } db2
|
|
|
|
} {1 2}
|
|
|
|
do_test lock5-none.4 {
|
|
|
|
execsql {
|
|
|
|
BEGIN;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
} db2
|
|
|
|
} {1 2}
|
|
|
|
do_test lock5-none.5 {
|
|
|
|
execsql COMMIT
|
|
|
|
execsql {SELECT * FROM t1} db2
|
|
|
|
} {1 2}
|
|
|
|
|
|
|
|
ifcapable memorymanage {
|
|
|
|
do_test lock5-none.6 {
|
|
|
|
sqlite3_release_memory 1000000
|
|
|
|
execsql {SELECT * FROM t1} db2
|
|
|
|
} {1 2 3 4}
|
|
|
|
}
|
|
|
|
|
|
|
|
do_test lock5-flock.X {
|
|
|
|
db close
|
|
|
|
db2 close
|
|
|
|
} {}
|
|
|
|
|
2009-02-20 20:33:35 +00:00
|
|
|
ifcapable lock_proxy_pragmas {
|
|
|
|
set env(SQLITE_FORCE_PROXY_LOCKING) $::using_proxy
|
|
|
|
}
|
|
|
|
|
2008-07-30 13:15:43 +00:00
|
|
|
finish_test
|