CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
jrnlmode2.test129 linesDownload Raw Back to test
1# 2009 March 242#3# The author disclaims copyright to this source code.  In place of4# 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.tcl15 16ifcapable {!pager_pragmas} {17  finish_test18  return19}20 21if {[atomic_batch_write test.db]} {22  finish_test23  return24}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, AND35#       * 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 is39#     not a hot-journal, SQLite currently grabs an exclusive lock on the40#     database file. If this fails because another connection has a shared41#     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 underlying46#     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 compile49#     the SELECT statement, it sees the empty journal in the file system, it50#     attempts to obtain an exclusive lock on the database file (this is a51#     bug). The attempt to obtain an exclusive (write) lock on a read-only file52#     fails at the OS level. Under unix, fcntl() reports an EBADF - "Bad file53#     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-journal66} {1}67 68do_test jrnlmode2-1.3 {69  sqlite3 db2 test.db70  execsql { SELECT * FROM t1 } db271} {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-journal86} {1}87 88do_test jrnlmode2-1.6 {89  catchsql { SELECT * FROM t1 } db290} {0 {1 2 3 4}}91 92do_test jrnlmode2-1.7 {93  execsql { COMMIT }94  catchsql { SELECT * FROM t1 } db295} {0 {1 2 3 4}}96 97 98 99do_test jrnlmode2-2.1 {100  db2 close101  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-journal107} {1}108 109do_test jrnlmode2-2.3 {110  file size test.db-journal111} {0}112 113do_test jrnlmode2-2.4 {114  sqlite3 db2 test.db -readonly 1115  catchsql { SELECT * FROM t1 } db2116} {0 {1 2 3 4 5 6}}117 118do_test jrnlmode2-2.5 {119  db close120  delete_file test.db-journal121} {}122do_test jrnlmode2-2.6 {123  sqlite3 db2 test.db -readonly 1124  catchsql { SELECT * FROM t1 } db2125} {0 {1 2 3 4 5 6}}126 127catch { db2 close }128finish_test129