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 #***********************************************************************
12 # Test cases inspired by ticket #3811. Tests to make sure that
13 # the journal_mode can only be changed at appropriate times and that
14 # all reported changes are effective.
16 # $Id: jrnlmode3.test,v 1.5 2009/04/20 17:43:03 drh Exp $
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
21 ifcapable {!pager_pragmas} {
27 # Verify that journal_mode=OFF works as long as it occurs before the first
28 # transaction, even if locking_mode=EXCLUSIVE is enabled. The behavior if
29 # journal_mode is changed after the first transaction is undefined and hence
32 do_test jrnlmode3-1.1 {
34 PRAGMA journal_mode=OFF;
35 PRAGMA locking_mode=EXCLUSIVE;
37 INSERT INTO t1 VALUES(1);
41 do_test jrnlmode3-1.2 {
44 INSERT INTO t1 VALUES(2);
51 forcedelete test.db test.db-journal
54 do_test jrnlmode3-2.1 {
56 PRAGMA locking_mode=EXCLUSIVE;
57 PRAGMA journal_mode=OFF;
59 INSERT INTO t1 VALUES(1);
63 do_test jrnlmode3-2.2 {
66 INSERT INTO t1 VALUES(2);
72 # Test cases to verify that we can move from any journal_mode
73 # to any other, as long as we are not in a transaction. Verify
74 # that we cannot change journal_mode while a transaction is active.
76 set all_journal_modes {delete persist truncate memory off}
78 foreach fromjmode $all_journal_modes {
79 foreach tojmode $all_journal_modes {
81 # Skip the no-change cases
82 if {$fromjmode==$tojmode} continue
85 # Start with a fresh database connection an empty database file.
88 forcedelete test.db test.db-journal
91 # Initialize the journal mode.
93 do_test jrnlmode3-3.$cnt.1-($fromjmode-to-$tojmode) {
94 db eval "PRAGMA journal_mode = $fromjmode;"
97 # Verify that the initial journal mode takes.
99 do_test jrnlmode3-3.$cnt.2 {
100 db eval {PRAGMA main.journal_mode}
103 # Start a transaction and try to change the journal mode within
104 # the transaction. This should fail.
106 do_test jrnlmode3-3.$cnt.3 {
110 INSERT INTO t1 VALUES($cnt);
112 db eval "PRAGMA journal_mode=$tojmode"
115 # Rollback the transaction.
117 do_test jrnlmode3-3.$cnt.4 {
124 # Now change the journal mode again. This time the new mode
127 do_test jrnlmode3-3.$cnt.5 {
128 db eval "PRAGMA journal_mode=$tojmode"
131 # Do a the transaction. Verify that the rollback occurred
132 # if journal_mode!=OFF.
134 do_test jrnlmode3-3.$cnt.6 {
136 DROP TABLE IF EXISTS t1;
139 INSERT INTO t1 VALUES(1);