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
21 set fd [open tf_main.tcl w]
22 puts $fd [subst -nocommands {
23 sqlite3_test_control_pending_byte 0x0010000
25 set rc [catch { db eval {$sql} } msg]
26 puts -nonewline "[set rc] {[set msg]}"
31 set fd [open "| [info nameofexec] ./tf_main.tcl" r]
39 CREATE TABLE t1(a, b);
45 # The database is locked by connection [db]. Open and close a second
46 # connection to test.db 10000 times. If file-descriptors are not being
47 # reused, then the process will quickly exceed its maximum number of
48 # file descriptors (1024 by default on linux).
50 for {set i 0} {$i < 10000} {incr i} {
56 # Now check that connection [db] is still holding a SHARED lock by
57 # having a second process try to write the db.
59 testsql {INSERT INTO t1 VALUES(3, 4)}
60 } {1 {database is locked}}
62 # Sanity checking. Have [db] release the lock and then retry the
63 # INSERT from the previous test case.
66 testsql {INSERT INTO t1 VALUES(3, 4)}
69 # Check that reusing a file descriptor cannot change a read-only
70 # connection into a read-write connection.
73 execsql {INSERT INTO t1 VALUES(1, 2)} db2
78 SELECT * FROM t1 ORDER BY a;
83 sqlite3 db2 test.db -readonly 1
85 catchsql {INSERT INTO t1 VALUES(5, 6)} db2
86 } {1 {attempt to write a readonly database}}