1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/lock5.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,176 @@
1.4 +# 2008 June 28
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.
1.16 +#
1.17 +# $Id: lock5.test,v 1.3 2008/09/24 09:12:47 danielk1977 Exp $
1.18 +
1.19 +set testdir [file dirname $argv0]
1.20 +source $testdir/tester.tcl
1.21 +
1.22 +# This file is only run if using the unix backend compiled with the
1.23 +# SQLITE_ENABLE_LOCKING_STYLE macro.
1.24 +db close
1.25 +if {[catch {sqlite3 db test.db -vfs unix-none} msg]} {
1.26 + finish_test
1.27 + return
1.28 +}
1.29 +db close
1.30 +
1.31 +do_test lock5-dotfile.1 {
1.32 + sqlite3 db test.db -vfs unix-dotfile
1.33 + execsql {
1.34 + BEGIN;
1.35 + CREATE TABLE t1(a, b);
1.36 + }
1.37 +} {}
1.38 +
1.39 +do_test lock5-dotfile.2 {
1.40 + file exists test.db.lock
1.41 +} {1}
1.42 +
1.43 +do_test lock5-dotfile.3 {
1.44 + execsql COMMIT
1.45 + file exists test.db.lock
1.46 +} {0}
1.47 +
1.48 +do_test lock5-dotfile.4 {
1.49 + sqlite3 db2 test.db -vfs unix-dotfile
1.50 + execsql {
1.51 + INSERT INTO t1 VALUES('a', 'b');
1.52 + SELECT * FROM t1;
1.53 + } db2
1.54 +} {a b}
1.55 +
1.56 +do_test lock5-dotfile.5 {
1.57 + execsql {
1.58 + BEGIN;
1.59 + SELECT * FROM t1;
1.60 + } db2
1.61 +} {a b}
1.62 +
1.63 +do_test lock5-dotfile.6 {
1.64 + file exists test.db.lock
1.65 +} {1}
1.66 +
1.67 +do_test lock5-dotfile.7 {
1.68 + catchsql { SELECT * FROM t1; }
1.69 +} {1 {database is locked}}
1.70 +
1.71 +do_test lock5-dotfile.8 {
1.72 + execsql {
1.73 + SELECT * FROM t1;
1.74 + ROLLBACK;
1.75 + } db2
1.76 +} {a b}
1.77 +
1.78 +do_test lock5-dotfile.9 {
1.79 + catchsql { SELECT * FROM t1; }
1.80 +} {0 {a b}}
1.81 +
1.82 +do_test lock5-dotfile.10 {
1.83 + file exists test.db.lock
1.84 +} {0}
1.85 +
1.86 +do_test lock5-dotfile.X {
1.87 + db2 close
1.88 + execsql {BEGIN EXCLUSIVE}
1.89 + db close
1.90 + file exists test.db.lock
1.91 +} {0}
1.92 +
1.93 +#####################################################################
1.94 +
1.95 +file delete -force test.db
1.96 +
1.97 +do_test lock5-flock.1 {
1.98 + sqlite3 db test.db -vfs unix-flock
1.99 + execsql {
1.100 + CREATE TABLE t1(a, b);
1.101 + BEGIN;
1.102 + INSERT INTO t1 VALUES(1, 2);
1.103 + }
1.104 +} {}
1.105 +
1.106 +# Make sure we are not accidentally using the dotfile locking scheme.
1.107 +do_test lock5-flock.2 {
1.108 + file exists test.db.lock
1.109 +} {0}
1.110 +
1.111 +do_test lock5-flock.3 {
1.112 + sqlite3 db2 test.db -vfs unix-flock
1.113 + catchsql { SELECT * FROM t1 } db2
1.114 +} {1 {database is locked}}
1.115 +
1.116 +do_test lock5-flock.4 {
1.117 + execsql COMMIT
1.118 + catchsql { SELECT * FROM t1 } db2
1.119 +} {0 {1 2}}
1.120 +
1.121 +do_test lock5-flock.5 {
1.122 + execsql BEGIN
1.123 + catchsql { SELECT * FROM t1 } db2
1.124 +} {0 {1 2}}
1.125 +
1.126 +do_test lock5-flock.6 {
1.127 + execsql {SELECT * FROM t1}
1.128 + catchsql { SELECT * FROM t1 } db2
1.129 +} {1 {database is locked}}
1.130 +
1.131 +do_test lock5-flock.7 {
1.132 + db close
1.133 + catchsql { SELECT * FROM t1 } db2
1.134 +} {0 {1 2}}
1.135 +
1.136 +do_test lock5-flock.8 {
1.137 + db2 close
1.138 +} {}
1.139 +
1.140 +#####################################################################
1.141 +
1.142 +do_test lock5-none.1 {
1.143 + sqlite3 db test.db -vfs unix-none
1.144 + sqlite3 db2 test.db -vfs unix-none
1.145 + execsql {
1.146 + BEGIN;
1.147 + INSERT INTO t1 VALUES(3, 4);
1.148 + }
1.149 +} {}
1.150 +do_test lock5-none.2 {
1.151 + execsql { SELECT * FROM t1 }
1.152 +} {1 2 3 4}
1.153 +do_test lock5-flock.3 {
1.154 + execsql { SELECT * FROM t1 } db2
1.155 +} {1 2}
1.156 +do_test lock5-none.4 {
1.157 + execsql {
1.158 + BEGIN;
1.159 + SELECT * FROM t1;
1.160 + } db2
1.161 +} {1 2}
1.162 +do_test lock5-none.5 {
1.163 + execsql COMMIT
1.164 + execsql {SELECT * FROM t1} db2
1.165 +} {1 2}
1.166 +
1.167 +ifcapable memorymanage {
1.168 + do_test lock5-none.6 {
1.169 + sqlite3_release_memory 1000000
1.170 + execsql {SELECT * FROM t1} db2
1.171 + } {1 2 3 4}
1.172 +}
1.173 +
1.174 +do_test lock5-flock.X {
1.175 + db close
1.176 + db2 close
1.177 +} {}
1.178 +
1.179 +finish_test