interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / jrnlmode2.test

128 lines · 3213 bytes Raw Blame History
1# 2009 March 24
2#
3# The author disclaims copyright to this source code. In place of
4# 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#
12
13set testdir [file dirname $argv0]
14source $testdir/tester.tcl
15
16ifcapable {!pager_pragmas} {
17 finish_test
18 return
19}
20
21if {[atomic_batch_write test.db]} {
22 finish_test
23 return
24}
25
26#-------------------------------------------------------------------------
27# The tests in this file check that the following two bugs (both now fixed)
28# do not reappear.
29#
30# jrnlmode2-1.*: Demonstrate bug #3745:
31#
32# In persistent journal mode, if:
33#
34# * There is a persistent journal in the file-system, AND
35# * there exists a connection with a shared lock on the db file,
36#
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.
42#
43# jrnlmode2-2.*: Demonstrate bug #3751:
44#
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.
47#
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.
54#
55
56do_test jrnlmode2-1.1 {
57 execsql {
58 PRAGMA journal_mode = persist;
59 CREATE TABLE t1(a, b);
60 INSERT INTO t1 VALUES(1, 2);
61 }
62} {persist}
63
64do_test jrnlmode2-1.2 {
65 file exists test.db-journal
66} {1}
67
68do_test jrnlmode2-1.3 {
69 sqlite3 db2 test.db
70 execsql { SELECT * FROM t1 } db2
71} {1 2}
72
73do_test jrnlmode2-1.4 {
74 execsql {
75 INSERT INTO t1 VALUES(3, 4);
76 }
77 execsql {
78 BEGIN;
79 SELECT * FROM t1;
80 }
81 execsql { PRAGMA lock_status }
82} {main shared temp closed}
83
84do_test jrnlmode2-1.5 {
85 file exists test.db-journal
86} {1}
87
88do_test jrnlmode2-1.6 {
89 catchsql { SELECT * FROM t1 } db2
90} {0 {1 2 3 4}}
91
92do_test jrnlmode2-1.7 {
93 execsql { COMMIT }
94 catchsql { SELECT * FROM t1 } db2
95} {0 {1 2 3 4}}
96
97
98
99do_test jrnlmode2-2.1 {
100 db2 close
101 execsql { PRAGMA journal_mode = truncate }
102 execsql { INSERT INTO t1 VALUES(5, 6) }
103} {}
104
105do_test jrnlmode2-2.2 {
106 file exists test.db-journal
107} {1}
108
109do_test jrnlmode2-2.3 {
110 file size test.db-journal
111} {0}
112
113do_test jrnlmode2-2.4 {
114 sqlite3 db2 test.db -readonly 1
115 catchsql { SELECT * FROM t1 } db2
116} {0 {1 2 3 4 5 6}}
117
118do_test jrnlmode2-2.5 {
119 db close
120 delete_file test.db-journal
121} {}
122do_test jrnlmode2-2.6 {
123 sqlite3 db2 test.db -readonly 1
124 catchsql { SELECT * FROM t1 } db2
125} {0 {1 2 3 4 5 6}}
126
127catch { db2 close }
128finish_test