mirror of
https://github.com/sqlite/sqlite.git
synced 2026-10-23 21:49:02 +03:00
This allows the sqlite3_step() to return SQLITE_BUSY if the commit is blocked by a lock. Ticket #885. (CVS 1928) FossilOrigin-Name: d1b29156558f1c576002cdb2544dffaa693da39b
91 lines
2.0 KiB
Plaintext
91 lines
2.0 KiB
Plaintext
# 2004 September 2
|
|
#
|
|
# 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 testing the callback-free C/C++ API and in
|
|
# particular the behavior of sqlite3_step() when trying to commit
|
|
# with lock contention.
|
|
#
|
|
# $Id: capi3b.test,v 1.1 2004/09/02 14:57:09 drh Exp $
|
|
#
|
|
|
|
set testdir [file dirname $argv0]
|
|
source $testdir/tester.tcl
|
|
|
|
|
|
db close
|
|
set DB [sqlite3 db test.db]
|
|
set DB2 [sqlite3 db2 test.db]
|
|
|
|
# Create some data in the database
|
|
#
|
|
do_test capi3b-1.1 {
|
|
execsql {
|
|
CREATE TABLE t1(x);
|
|
INSERT INTO t1 VALUES(1);
|
|
INSERT INTO t1 VALUES(2);
|
|
SELECT * FROM t1
|
|
}
|
|
} {1 2}
|
|
|
|
# Make sure the second database connection can see the data
|
|
#
|
|
do_test capi3b-1.2 {
|
|
execsql {
|
|
SELECT * FROM t1
|
|
} db2
|
|
} {1 2}
|
|
|
|
# First database connection acquires a shared lock
|
|
#
|
|
do_test capi3b-1.3 {
|
|
execsql {
|
|
BEGIN;
|
|
SELECT * FROM t1;
|
|
}
|
|
} {1 2}
|
|
|
|
# Second database connection tries to write. The sqlite3_step()
|
|
# function returns SQLITE_BUSY because it cannot commit.
|
|
#
|
|
do_test capi3b-1.4 {
|
|
set VM [sqlite3_prepare $DB2 {INSERT INTO t1 VALUES(3)} -1 TAIL]
|
|
sqlite3_step $VM
|
|
} SQLITE_BUSY
|
|
|
|
# The sqlite3_step call can be repeated multiple times.
|
|
#
|
|
do_test capi3b-1.5.1 {
|
|
sqlite3_step $VM
|
|
} SQLITE_BUSY
|
|
do_test capi3b-1.5.2 {
|
|
sqlite3_step $VM
|
|
} SQLITE_BUSY
|
|
|
|
# The first connection closes its transaction. This allows the second
|
|
# connections sqlite3_step to succeed.
|
|
#
|
|
do_test capi3b-1.6 {
|
|
execsql COMMIT
|
|
sqlite3_step $VM
|
|
} SQLITE_DONE
|
|
do_test capi3b-1.7 {
|
|
sqlite3_finalize $VM
|
|
} SQLITE_OK
|
|
do_test capi3b-1.8 {
|
|
execsql {SELECT * FROM t1} db2
|
|
} {1 2 3}
|
|
do_test capi3b-1.9 {
|
|
execsql {SELECT * FROM t1}
|
|
} {1 2 3}
|
|
|
|
catch {db2 close}
|
|
finish_test
|