Index: src/pager.c ================================================================== --- src/pager.c +++ src/pager.c @@ -16,11 +16,11 @@ ** is separate from the database file. The pager also implements file ** locking to prevent two processes from writing the same database ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.448 2008/05/15 11:08:08 danielk1977 Exp $ +** @(#) $Id: pager.c,v 1.449 2008/05/20 07:05:09 danielk1977 Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" #include #include @@ -4686,32 +4686,34 @@ ** transaction the m-j name will have already been written. */ if( !pPager->setMaster ){ rc = pager_incr_changecounter(pPager, 0); if( rc!=SQLITE_OK ) goto sync_exit; + if( pPager->journalMode!=PAGER_JOURNALMODE_OFF ){ #ifndef SQLITE_OMIT_AUTOVACUUM - if( nTrunc!=0 ){ - /* If this transaction has made the database smaller, then all pages - ** being discarded by the truncation must be written to the journal - ** file. - */ - Pgno i; - int iSkip = PAGER_MJ_PGNO(pPager); - for( i=nTrunc+1; i<=pPager->origDbSize; i++ ){ - if( !sqlite3BitvecTest(pPager->pInJournal, i) && i!=iSkip ){ - rc = sqlite3PagerGet(pPager, i, &pPg); - if( rc!=SQLITE_OK ) goto sync_exit; - rc = sqlite3PagerWrite(pPg); - sqlite3PagerUnref(pPg); - if( rc!=SQLITE_OK ) goto sync_exit; - } - } - } + if( nTrunc!=0 ){ + /* If this transaction has made the database smaller, then all pages + ** being discarded by the truncation must be written to the journal + ** file. + */ + Pgno i; + int iSkip = PAGER_MJ_PGNO(pPager); + for( i=nTrunc+1; i<=pPager->origDbSize; i++ ){ + if( !sqlite3BitvecTest(pPager->pInJournal, i) && i!=iSkip ){ + rc = sqlite3PagerGet(pPager, i, &pPg); + if( rc!=SQLITE_OK ) goto sync_exit; + rc = sqlite3PagerWrite(pPg); + sqlite3PagerUnref(pPg); + if( rc!=SQLITE_OK ) goto sync_exit; + } + } + } #endif - rc = writeMasterJournal(pPager, zMaster); - if( rc!=SQLITE_OK ) goto sync_exit; - rc = syncJournal(pPager); + rc = writeMasterJournal(pPager, zMaster); + if( rc!=SQLITE_OK ) goto sync_exit; + rc = syncJournal(pPager); + } } if( rc!=SQLITE_OK ) goto sync_exit; #ifndef SQLITE_OMIT_AUTOVACUUM if( nTrunc!=0 ){ Index: test/jrnlmode.test ================================================================== --- test/jrnlmode.test +++ test/jrnlmode.test @@ -9,11 +9,11 @@ # #*********************************************************************** # This file implements regression tests for SQLite library. The focus # of these tests is the journal mode pragma. # -# $Id: jrnlmode.test,v 1.2 2008/05/07 19:11:03 danielk1977 Exp $ +# $Id: jrnlmode.test,v 1.3 2008/05/20 07:05:09 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl ifcapable {!pager_pragmas} { @@ -189,11 +189,66 @@ execsql { SELECT * FROM def; } } {4 5 6} +#---------------------------------------------------------------------- +# Test caes jrnlmode-3.X verify that ticket #3127 has been fixed. +# + db close + file delete -force test2.db + file delete -force test.db + sqlite3 db test.db + + do_test jrnlmode-3.1 { + execsql { + CREATE TABLE x(n INTEGER); + ATTACH 'test2.db' AS a; + create table a.x ( n integer ); + insert into a.x values(1); + insert into a.x values (2); + insert into a.x values (3); + insert into a.x values (4); + } + } {} + + do_test jrnlmode-3.2 { + execsql { PRAGMA journal_mode=off; } + execsql { + BEGIN IMMEDIATE; + INSERT OR IGNORE INTO main.x SELECT * FROM a.x; + COMMIT; + } + } {} } +ifcapable autovacuum&&pragma { + db close + file delete -force test.db + sqlite3 db test.db + do_test jrnlmode-4.1 { + execsql { + PRAGMA cache_size = 1; + PRAGMA auto_vacuum = 1; + CREATE TABLE abc(a, b, c); + } + execsql { PRAGMA page_count } + } {3} + + do_test jrnlmode-4.2 { + execsql { PRAGMA journal_mode = off } + } {off} + + do_test jrnlmode-4.3 { + execsql { INSERT INTO abc VALUES(1, 2, randomblob(2000)) } + } {} + # This will attempt to truncate the database file. Check that this + # is not a problem when journal_mode=off. + do_test jrnlmode-4.4 { + execsql { DELETE FROM abc } + } {} + integrity_check jrnlmode-4.5 +} finish_test