CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
lock3.test80 linesDownload Raw Back to test
1# 2001 September 152#3# The author disclaims copyright to this source code.  In place of4# 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.  The12# focus of this script is database locks and the operation of the13# DEFERRED, IMMEDIATE, and EXCLUSIVE keywords as modifiers to the14# BEGIN command.15#16# $Id: lock3.test,v 1.4 2009/03/28 15:04:24 drh Exp $17 18 19set testdir [file dirname $argv0]20source $testdir/tester.tcl21 22# Establish two connections to the same database.  Put some23# sample data into the database.24#25do_test lock3-1.1 {26  file mkdir tempdir/t1/t2/t327  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 t134  } db235} 136 37# Get a deferred lock on the database using one connection.  The38# other connection should still be able to write.39#40do_test lock3-2.1 {41  execsql {BEGIN DEFERRED TRANSACTION}42  execsql {INSERT INTO t1 VALUES(2)} db243  execsql {END TRANSACTION}44  execsql {SELECT * FROM t1}45} {1 2}46 47# Get an immediate lock on the database using one connection.  The48# other connection should be able to read the database but not write49# it.50#51do_test lock3-3.1 {52  execsql {BEGIN IMMEDIATE TRANSACTION}53  catchsql {SELECT * FROM t1} db254} {0 {1 2}}55do_test lock3-3.2 {56  catchsql {INSERT INTO t1 VALUES(3)} db257} {1 {database is locked}}58do_test lock3-3.3 {59  execsql {END TRANSACTION}60} {}61 62 63# Get an exclusive lock on the database using one connection.  The64# other connection should be unable to read or write the database.65#66do_test lock3-4.1 {67  execsql {BEGIN EXCLUSIVE TRANSACTION}68  catchsql {SELECT * FROM t1} db269} {1 {database is locked}}70do_test lock3-4.2 {71  catchsql {INSERT INTO t1 VALUES(3)} db272} {1 {database is locked}}73do_test lock3-4.3 {74  execsql {END TRANSACTION}75} {}76 77catch {db2 close}78 79finish_test80