3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file implements tests to verify that ticket #4018 has been
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
22 set fd [open tf_main.tcl w]
23 puts $fd [subst -nocommands {
24 sqlite3_test_control_pending_byte 0x0010000
26 set rc [catch { db eval {$sql} } msg]
27 puts -nonewline "[set rc] {[set msg]}"
32 set fd [open "| [info nameofexec] ./tf_main.tcl" r]
40 CREATE TABLE t1(a, b);
46 # The database is locked by connection [db]. Open and close a second
47 # connection to test.db 10000 times. If file-descriptors are not being
48 # reused, then the process will quickly exceed its maximum number of
49 # file descriptors (1024 by default on linux).
51 for {set i 0} {$i < 10000} {incr i} {
57 # Now check that connection [db] is still holding a SHARED lock by
58 # having a second process try to write the db.
60 testsql {INSERT INTO t1 VALUES(3, 4)}
61 } {1 {database is locked}}
63 # Sanity checking. Have [db] release the lock and then retry the
64 # INSERT from the previous test case.
67 testsql {INSERT INTO t1 VALUES(3, 4)}
70 # Check that reusing a file descriptor cannot change a read-only
71 # connection into a read-write connection.
74 execsql {INSERT INTO t1 VALUES(1, 2)} db2
79 SELECT * FROM t1 ORDER BY a;
84 sqlite3 db2 test.db -readonly 1
86 catchsql {INSERT INTO t1 VALUES(5, 6)} db2
87 } {1 {attempt to write a readonly database}}