diff --git a/manifest b/manifest index 29110b4ff3..a2be0318d0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Allow\sthe\sdatabase\sname\sin\sa\sDETACH\sstatement\sto\sbe\squoted.\nTicket\s#1151.\s(CVS\s2386) -D 2005-03-15T02:04:12 +C When\screating\sa\snew\sdatabase,\sdelete\sany\spreexisting\sjournal\sthat\smight\sbe\nleft\sover\sfrom\sa\sprior\sdatabase\swith\sthe\ssame\sname.\s\sTicket\s#1152.\s(CVS\s2387) +D 2005-03-15T17:09:30 F Makefile.in 5c00d0037104de2a50ac7647a5f12769795957a3 F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7 F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1 @@ -52,7 +52,7 @@ F src/os_unix.c d4823c6b3dd86e8cbb6a8f9d2fd6c4b3e722f8ee F src/os_unix.h 40b2fd1d02cfa45d6c3dea25316fd019cf9fcb0c F src/os_win.c bddeae1c3299be0fbe47077dd4e98b786a067f71 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b -F src/pager.c 2e795b3d85303b03daa1e18727a6aaa215a50980 +F src/pager.c 26a642c1238615bdea53d458ab6a4df7ca070a08 F src/pager.h 70d496f372163abb6340f474288c4bb9ea962cf7 F src/parse.y 0b6135268a7a29db35335d5b71b5a8791e02f91e F src/pragma.c 4b20dbc0f4b97f412dc511853d3d0c2e0d4adedc @@ -144,6 +144,7 @@ F test/join.test e08471279574487cac0d17fa1ea66aca15c4de7f F test/join2.test f2171c265e57ee298a27e57e7051d22962f9f324 F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0 F test/join4.test cc6cafe85e11aacacd0abcd247a46bed251308f8 +F test/journal1.test ffc86f485293ece87005d00c6da1640554af7e22 F test/lastinsert.test b6a1db3e1ce2d3f0d6afe99d445084f543b6feaa F test/laststmtchanges.test 07cbdabc52407c29e40abc25050f2434f044a6b1 F test/limit.test 270b076f31c5c32f7187de5727e74da4de43e477 @@ -274,7 +275,7 @@ F www/tclsqlite.tcl e73f8f8e5f20e8277619433f7970060ab01088fc F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0 F www/whentouse.tcl 3e522a06ad41992023c80ca29a048ae2331ca5bd -P 644c6398e52481e5dda87671e1c196b26b1e4990 -R c7a0fd10b1d2a373374c7ed8ae164835 +P 24e887735256499e58dabe90463524d9e6eb08ce +R 76fc7bf07ced1da0a2aa6b133619eb70 U drh -Z 2ee8d8f83569ed719ed59eea247ccc2d +Z 568a4e730d583509fc67f9b125ab2918 diff --git a/manifest.uuid b/manifest.uuid index bc59624ad5..ed94e11f12 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -24e887735256499e58dabe90463524d9e6eb08ce \ No newline at end of file +856e2ec9688affbfe496cf184f460b18408e3dc0 \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index bfe2939b5b..19c9eb5326 100644 --- a/src/pager.c +++ b/src/pager.c @@ -18,7 +18,7 @@ ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.193 2005/03/14 02:01:50 drh Exp $ +** @(#) $Id: pager.c,v 1.194 2005/03/15 17:09:30 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -2178,6 +2178,26 @@ static PgHdr *pager_get_all_dirty_pages(Pager *pPager){ return pList; } +/* +** Return TRUE if there is a hot journal on the given pager. +** A hot journal is one that needs to be played back. +** +** If the current size of the database file is 0 but a journal file +** exists, that is probably an old journal left over from a prior +** database with the same name. Just delete the journal. +*/ +static int hasHotJournal(Pager *pPager){ + if( !pPager->useJournal ) return 0; + if( !sqlite3OsFileExists(pPager->zJournal) ) return 0; + if( sqlite3OsCheckReservedLock(&pPager->fd) ) return 0; + if( sqlite3pager_pagecount(pPager)==0 ){ + sqlite3OsDelete(pPager->zJournal); + return 0; + }else{ + return 1; + } +} + /* ** Acquire a page. ** @@ -2203,7 +2223,7 @@ static PgHdr *pager_get_all_dirty_pages(Pager *pPager){ */ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){ PgHdr *pPg; - int rc, n; + int rc; /* The maximum page number is 2^31. Return SQLITE_CORRUPT if a page ** number greater than this, or zero, is requested. @@ -2234,10 +2254,7 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){ /* If a journal file exists, and there is no RESERVED lock on the ** database file, then it either needs to be played back or deleted. */ - if( pPager->useJournal && - sqlite3OsFileExists(pPager->zJournal) && - !sqlite3OsCheckReservedLock(&pPager->fd) - ){ + if( hasHotJournal(pPager) ){ int rc; /* Get an EXCLUSIVE lock on the database file. At this point it is @@ -2415,13 +2432,12 @@ int sqlite3pager_get(Pager *pPager, Pgno pgno, void **ppPage){ if( pPager->nExtra>0 ){ memset(PGHDR_TO_EXTRA(pPg, pPager), 0, pPager->nExtra); } - n = sqlite3pager_pagecount(pPager); if( pPager->errMask!=0 ){ sqlite3pager_unref(PGHDR_TO_DATA(pPg)); rc = pager_errcode(pPager); return rc; } - if( n<(int)pgno ){ + if( sqlite3pager_pagecount(pPager)<(int)pgno ){ memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize); }else{ int rc; diff --git a/test/journal1.test b/test/journal1.test new file mode 100644 index 0000000000..fbcdc0abe4 --- /dev/null +++ b/test/journal1.test @@ -0,0 +1,59 @@ +# 2005 March 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests to make sure that leftover journals from +# prior databases do not try to rollback into new databases. +# +# $Id: journal1.test,v 1.1 2005/03/15 17:09:30 drh Exp $ + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Create a smaple database +# +do_test journal1-1.1 { + execsql { + CREATE TABLE t1(a,b); + INSERT INTO t1 VALUES(1,randstr(10,400)); + INSERT INTO t1 VALUES(2,randstr(10,400)); + INSERT INTO t1 SELECT a+2, a||b FROM t1; + INSERT INTO t1 SELECT a+4, a||b FROM t1; + SELECT count(*) FROM t1; + } +} 8 + +# Make changes to the database and save the journal file. +# Then delete the database. Replace the the journal file +# and try to create a new database with the same name. The +# old journal should not attempt to rollback into the new +# database. +# +do_test journal1-1.2 { + execsql { + BEGIN; + DELETE FROM t1; + } + file copy -force test.db-journal test.db-journal-bu + execsql { + ROLLBACK; + } + db close + file delete test.db + file copy test.db-journal-bu test.db-journal + sqlite3 db test.db + catchsql { + SELECT * FROM sqlite_master + } +} {0 {}} + +finish_test