Change the journal_mode pragma so that it always returns the current
journal mode, even on a failed attempt to change the journal mode. Allow the journal mode to be changed as long as there is not a pending transaction. Ticket #3811. (CVS 6526) FossilOrigin-Name: 419e320ae51639794335d19699f8e1189e524e7d
This commit is contained in:
+82
-2
@@ -9,7 +9,11 @@
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# $Id: jrnlmode3.test,v 1.4 2009/04/20 13:32:33 drh Exp $
|
||||
# Test cases inspired by ticket #3811. Tests to make sure that
|
||||
# the journal_mode can only be changed at appropriate times and that
|
||||
# all reported changes are effective.
|
||||
#
|
||||
# $Id: jrnlmode3.test,v 1.5 2009/04/20 17:43:03 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -19,7 +23,6 @@ ifcapable {!pager_pragmas} {
|
||||
return
|
||||
}
|
||||
|
||||
# Ticket #3811
|
||||
#
|
||||
# Verify that journal_mode=OFF works as long as it occurs before the first
|
||||
# transaction, even if locking_mode=EXCLUSIVE is enabled. The behavior if
|
||||
@@ -66,5 +69,82 @@ do_test jrnlmode3-2.2 {
|
||||
}
|
||||
} {1 2}
|
||||
|
||||
# Test cases to verify that we can move from any journal_mode
|
||||
# to any other, as long as we are not in a transaction. Verify
|
||||
# that we cannot change journal_mode while a transaction is active.
|
||||
#
|
||||
set all_journal_modes {delete persist truncate memory off}
|
||||
set cnt 0
|
||||
foreach fromjmode $all_journal_modes {
|
||||
foreach tojmode $all_journal_modes {
|
||||
|
||||
# Skip the no-change cases
|
||||
if {$fromjmode==$tojmode} continue
|
||||
incr cnt
|
||||
|
||||
# Start with a fresh database connection an empty database file.
|
||||
#
|
||||
db close
|
||||
file delete -force test.db test.db-journal
|
||||
sqlite3 db test.db
|
||||
|
||||
# Initialize the journal mode.
|
||||
#
|
||||
do_test jrnlmode3-3.$cnt.1-($fromjmode-to-$tojmode) {
|
||||
db eval "PRAGMA journal_mode = $fromjmode;"
|
||||
} $fromjmode
|
||||
|
||||
# Verify that the initial journal mode takes.
|
||||
#
|
||||
do_test jrnlmode3-3.$cnt.2 {
|
||||
db eval {PRAGMA main.journal_mode}
|
||||
} $fromjmode
|
||||
|
||||
# Start a transaction and try to change the journal mode within
|
||||
# the transaction. This should fail.
|
||||
#
|
||||
do_test jrnlmode3-3.$cnt.3 {
|
||||
db eval {
|
||||
CREATE TABLE t1(x);
|
||||
BEGIN;
|
||||
INSERT INTO t1 VALUES($cnt);
|
||||
}
|
||||
db eval "PRAGMA journal_mode=$tojmode"
|
||||
} $fromjmode
|
||||
|
||||
# Rollback the transaction. Verify that the rollback occurred
|
||||
# if journal_mode!=OFF.
|
||||
#
|
||||
do_test jrnlmode3-3.$cnt.4 {
|
||||
db eval {
|
||||
ROLLBACK;
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} [expr {$fromjmode=="off"?$cnt:""}]
|
||||
|
||||
# Now change the journal mode again. This time the new mode
|
||||
# should take.
|
||||
#
|
||||
do_test jrnlmode3-3.$cnt.5 {
|
||||
db eval "PRAGMA journal_mode=$tojmode"
|
||||
} $tojmode
|
||||
|
||||
# Do a the transaction. Verify that the rollback occurred
|
||||
# if journal_mode!=OFF.
|
||||
#
|
||||
do_test jrnlmode3-3.$cnt.6 {
|
||||
db eval {
|
||||
DROP TABLE IF EXISTS t1;
|
||||
CREATE TABLE t1(x);
|
||||
BEGIN;
|
||||
INSERT INTO t1 VALUES(1);
|
||||
}
|
||||
db eval ROLLBACK
|
||||
db eval {
|
||||
SELECT * FROM t1;
|
||||
}
|
||||
} [expr {$tojmode=="off"?"1":""}]
|
||||
}
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
Reference in New Issue
Block a user