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 #***********************************************************************
13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl
16 ifcapable {!pager_pragmas} {
21 if {[atomic_batch_write test.db]} {
26 #-------------------------------------------------------------------------
27 # The tests in this file check that the following two bugs (both now fixed)
30 # jrnlmode2-1.*: Demonstrate bug #3745:
32 # In persistent journal mode, if:
34 # * There is a persistent journal in the file-system, AND
35 # * there exists a connection with a shared lock on the db file,
37 # then a second connection cannot open a read-transaction on the database.
38 # The reason is because while determining that the persistent-journal is
39 # not a hot-journal, SQLite currently grabs an exclusive lock on the
40 # database file. If this fails because another connection has a shared
41 # lock, then SQLITE_BUSY is returned to the user.
43 # jrnlmode2-2.*: Demonstrate bug #3751:
45 # If a connection is opened in SQLITE_OPEN_READONLY mode, the underlying
46 # unix file descriptor on the database file is opened in O_RDONLY mode.
48 # When SQLite queries the database file for the schema in order to compile
49 # the SELECT statement, it sees the empty journal in the file system, it
50 # attempts to obtain an exclusive lock on the database file (this is a
51 # bug). The attempt to obtain an exclusive (write) lock on a read-only file
52 # fails at the OS level. Under unix, fcntl() reports an EBADF - "Bad file
53 # descriptor" - error.
56 do_test jrnlmode2-1.1 {
58 PRAGMA journal_mode = persist;
59 CREATE TABLE t1(a, b);
60 INSERT INTO t1 VALUES(1, 2);
64 do_test jrnlmode2-1.2 {
65 file exists test.db-journal
68 do_test jrnlmode2-1.3 {
70 execsql { SELECT * FROM t1 } db2
73 do_test jrnlmode2-1.4 {
75 INSERT INTO t1 VALUES(3, 4);
81 execsql { PRAGMA lock_status }
82 } {main shared temp closed}
84 do_test jrnlmode2-1.5 {
85 file exists test.db-journal
88 do_test jrnlmode2-1.6 {
89 catchsql { SELECT * FROM t1 } db2
92 do_test jrnlmode2-1.7 {
94 catchsql { SELECT * FROM t1 } db2
99 do_test jrnlmode2-2.1 {
101 execsql { PRAGMA journal_mode = truncate }
102 execsql { INSERT INTO t1 VALUES(5, 6) }
105 do_test jrnlmode2-2.2 {
106 file exists test.db-journal
109 do_test jrnlmode2-2.3 {
110 file size test.db-journal
113 do_test jrnlmode2-2.4 {
114 sqlite3 db2 test.db -readonly 1
115 catchsql { SELECT * FROM t1 } db2
118 do_test jrnlmode2-2.5 {
120 delete_file test.db-journal
122 do_test jrnlmode2-2.6 {
123 sqlite3 db2 test.db -readonly 1
124 catchsql { SELECT * FROM t1 } db2