Fossil SCM

Update to the latest SQLite which contains a bug fix in the current-time function on windows.

drh 2010-06-23 15:23 trunk
Commit 34178e2771d036b90c11df7a1c7bd8b5dcfaa795
2 files changed +114 -76 +1 -1
+114 -76
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -636,11 +636,11 @@
636636
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
637637
** [sqlite_version()] and [sqlite_source_id()].
638638
*/
639639
#define SQLITE_VERSION "3.7.0"
640640
#define SQLITE_VERSION_NUMBER 3007000
641
-#define SQLITE_SOURCE_ID "2010-06-21 12:47:41 ee0acef1faffd480fd2136f81fb2b6f6a17b5388"
641
+#define SQLITE_SOURCE_ID "2010-06-23 15:18:12 51ef43b9f7db8fabf73d9c8a76dae6c275e50d58"
642642
643643
/*
644644
** CAPI3REF: Run-Time Library Version Numbers
645645
** KEYWORDS: sqlite3_version, sqlite3_sourceid
646646
**
@@ -7858,10 +7858,14 @@
78587858
SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
78597859
SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*);
78607860
78617861
/* Functions used to truncate the database file. */
78627862
SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
7863
+
7864
+#if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL)
7865
+SQLITE_PRIVATE void *sqlite3PagerCodec(DbPage *);
7866
+#endif
78637867
78647868
/* Functions to support testing and debugging. */
78657869
#if !defined(NDEBUG) || defined(SQLITE_TEST)
78667870
SQLITE_PRIVATE Pgno sqlite3PagerPagenumber(DbPage*);
78677871
SQLITE_PRIVATE int sqlite3PagerIswriteable(DbPage*);
@@ -31136,11 +31140,11 @@
3113631140
GetSystemTimeAsFileTime( &ft );
3113731141
#endif
3113831142
3113931143
*piNow = winFiletimeEpoch +
3114031144
((((sqlite3_int64)ft.dwHighDateTime)*max32BitValue) +
31141
- (sqlite3_int64)ft.dwLowDateTime)/(sqlite3_int64)1000;
31145
+ (sqlite3_int64)ft.dwLowDateTime)/(sqlite3_int64)10000;
3114231146
3114331147
#ifdef SQLITE_TEST
3114431148
if( sqlite3_current_time ){
3114531149
*piNow = 1000*(sqlite3_int64)sqlite3_current_time + unixEpoch;
3114631150
}
@@ -34772,13 +34776,14 @@
3477234776
static void pager_unlock(Pager *pPager){
3477334777
if( !pPager->exclusiveMode ){
3477434778
int rc = SQLITE_OK; /* Return code */
3477534779
int iDc = isOpen(pPager->fd)?sqlite3OsDeviceCharacteristics(pPager->fd):0;
3477634780
34777
- /* Always close the journal file when dropping the database lock.
34778
- ** Otherwise, another connection with journal_mode=delete might
34779
- ** delete the file out from under us.
34781
+ /* If the operating system support deletion of open files, then
34782
+ ** close the journal file when dropping the database lock. Otherwise
34783
+ ** another connection with journal_mode=delete might delete the file
34784
+ ** out from under us.
3478034785
*/
3478134786
assert( (PAGER_JOURNALMODE_MEMORY & 5)!=1 );
3478234787
assert( (PAGER_JOURNALMODE_OFF & 5)!=1 );
3478334788
assert( (PAGER_JOURNALMODE_WAL & 5)!=1 );
3478434789
assert( (PAGER_JOURNALMODE_DELETE & 5)!=1 );
@@ -35346,10 +35351,13 @@
3534635351
int rc; /* Return code */
3534735352
sqlite3_file *pMaster; /* Malloc'd master-journal file descriptor */
3534835353
sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */
3534935354
char *zMasterJournal = 0; /* Contents of master journal file */
3535035355
i64 nMasterJournal; /* Size of master journal file */
35356
+ char *zJournal; /* Pointer to one journal within MJ file */
35357
+ char *zMasterPtr; /* Space to hold MJ filename from a journal file */
35358
+ int nMasterPtr; /* Amount of space allocated to zMasterPtr[] */
3535135359
3535235360
/* Allocate space for both the pJournal and pMaster file descriptors.
3535335361
** If successful, open the master journal file for reading.
3535435362
*/
3535535363
pMaster = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile * 2);
@@ -35360,77 +35368,72 @@
3536035368
const int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MASTER_JOURNAL);
3536135369
rc = sqlite3OsOpen(pVfs, zMaster, pMaster, flags, 0);
3536235370
}
3536335371
if( rc!=SQLITE_OK ) goto delmaster_out;
3536435372
35365
- rc = sqlite3OsFileSize(pMaster, &nMasterJournal);
35366
- if( rc!=SQLITE_OK ) goto delmaster_out;
35367
-
35368
- if( nMasterJournal>0 ){
35369
- char *zJournal;
35370
- char *zMasterPtr = 0;
35371
- int nMasterPtr = pVfs->mxPathname+1;
35372
-
35373
- /* Load the entire master journal file into space obtained from
35374
- ** sqlite3_malloc() and pointed to by zMasterJournal.
35375
- */
35376
- zMasterJournal = sqlite3Malloc((int)nMasterJournal + nMasterPtr + 1);
35377
- if( !zMasterJournal ){
35378
- rc = SQLITE_NOMEM;
35379
- goto delmaster_out;
35380
- }
35381
- zMasterPtr = &zMasterJournal[nMasterJournal+1];
35382
- rc = sqlite3OsRead(pMaster, zMasterJournal, (int)nMasterJournal, 0);
35383
- if( rc!=SQLITE_OK ) goto delmaster_out;
35384
- zMasterJournal[nMasterJournal] = 0;
35385
-
35386
- zJournal = zMasterJournal;
35387
- while( (zJournal-zMasterJournal)<nMasterJournal ){
35388
- int exists;
35389
- rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists);
35390
- if( rc!=SQLITE_OK ){
35391
- goto delmaster_out;
35392
- }
35393
- if( exists ){
35394
- /* One of the journals pointed to by the master journal exists.
35395
- ** Open it and check if it points at the master journal. If
35396
- ** so, return without deleting the master journal file.
35397
- */
35398
- int c;
35399
- int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MAIN_JOURNAL);
35400
- rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0);
35401
- if( rc!=SQLITE_OK ){
35402
- goto delmaster_out;
35403
- }
35404
-
35405
- rc = readMasterJournal(pJournal, zMasterPtr, nMasterPtr);
35406
- sqlite3OsClose(pJournal);
35407
- if( rc!=SQLITE_OK ){
35408
- goto delmaster_out;
35409
- }
35410
-
35411
- c = zMasterPtr[0]!=0 && strcmp(zMasterPtr, zMaster)==0;
35412
- if( c ){
35413
- /* We have a match. Do not delete the master journal file. */
35414
- goto delmaster_out;
35415
- }
35416
- }
35417
- zJournal += (sqlite3Strlen30(zJournal)+1);
35418
- }
35419
- }
35420
-
35373
+ /* Load the entire master journal file into space obtained from
35374
+ ** sqlite3_malloc() and pointed to by zMasterJournal. Also obtain
35375
+ ** sufficient space (in zMasterPtr) to hold the names of master
35376
+ ** journal files extracted from regular rollback-journals.
35377
+ */
35378
+ rc = sqlite3OsFileSize(pMaster, &nMasterJournal);
35379
+ if( rc!=SQLITE_OK ) goto delmaster_out;
35380
+ nMasterPtr = pVfs->mxPathname+1;
35381
+ zMasterJournal = sqlite3Malloc((int)nMasterJournal + nMasterPtr + 1);
35382
+ if( !zMasterJournal ){
35383
+ rc = SQLITE_NOMEM;
35384
+ goto delmaster_out;
35385
+ }
35386
+ zMasterPtr = &zMasterJournal[nMasterJournal+1];
35387
+ rc = sqlite3OsRead(pMaster, zMasterJournal, (int)nMasterJournal, 0);
35388
+ if( rc!=SQLITE_OK ) goto delmaster_out;
35389
+ zMasterJournal[nMasterJournal] = 0;
35390
+
35391
+ zJournal = zMasterJournal;
35392
+ while( (zJournal-zMasterJournal)<nMasterJournal ){
35393
+ int exists;
35394
+ rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists);
35395
+ if( rc!=SQLITE_OK ){
35396
+ goto delmaster_out;
35397
+ }
35398
+ if( exists ){
35399
+ /* One of the journals pointed to by the master journal exists.
35400
+ ** Open it and check if it points at the master journal. If
35401
+ ** so, return without deleting the master journal file.
35402
+ */
35403
+ int c;
35404
+ int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MAIN_JOURNAL);
35405
+ rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0);
35406
+ if( rc!=SQLITE_OK ){
35407
+ goto delmaster_out;
35408
+ }
35409
+
35410
+ rc = readMasterJournal(pJournal, zMasterPtr, nMasterPtr);
35411
+ sqlite3OsClose(pJournal);
35412
+ if( rc!=SQLITE_OK ){
35413
+ goto delmaster_out;
35414
+ }
35415
+
35416
+ c = zMasterPtr[0]!=0 && strcmp(zMasterPtr, zMaster)==0;
35417
+ if( c ){
35418
+ /* We have a match. Do not delete the master journal file. */
35419
+ goto delmaster_out;
35420
+ }
35421
+ }
35422
+ zJournal += (sqlite3Strlen30(zJournal)+1);
35423
+ }
35424
+
35425
+ sqlite3OsClose(pMaster);
3542135426
rc = sqlite3OsDelete(pVfs, zMaster, 0);
3542235427
3542335428
delmaster_out:
35424
- if( zMasterJournal ){
35425
- sqlite3_free(zMasterJournal);
35426
- }
35429
+ sqlite3_free(zMasterJournal);
3542735430
if( pMaster ){
3542835431
sqlite3OsClose(pMaster);
3542935432
assert( !isOpen(pJournal) );
35433
+ sqlite3_free(pMaster);
3543035434
}
35431
- sqlite3_free(pMaster);
3543235435
return rc;
3543335436
}
3543435437
3543535438
3543635439
/*
@@ -36125,11 +36128,11 @@
3612536128
for(ii=0; rc==SQLITE_OK && ii<nJRec && pPager->journalOff<szJ; ii++){
3612636129
rc = pager_playback_one_page(pPager, &pPager->journalOff, pDone, 1, 1);
3612736130
}
3612836131
assert( rc!=SQLITE_DONE );
3612936132
}
36130
- assert( rc!=SQLITE_OK || pPager->journalOff==szJ );
36133
+ assert( rc!=SQLITE_OK || pPager->journalOff>=szJ );
3613136134
3613236135
/* Finally, rollback pages from the sub-journal. Page that were
3613336136
** previously rolled back out of the main journal (and are hence in pDone)
3613436137
** will be skipped. Out-of-range pages are also skipped.
3613536138
*/
@@ -38256,11 +38259,11 @@
3825638259
*/
3825738260
rc = sqlite3PagerBegin(pPager, 0, pPager->subjInMemory);
3825838261
if( rc!=SQLITE_OK ){
3825938262
return rc;
3826038263
}
38261
- if( !isOpen(pPager->jfd)
38264
+ if( pPager->pInJournal==0
3826238265
&& pPager->journalMode!=PAGER_JOURNALMODE_OFF
3826338266
&& !pagerUseWal(pPager)
3826438267
){
3826538268
assert( pPager->useJournal );
3826638269
rc = pager_open_journal(pPager);
@@ -38571,13 +38574,16 @@
3857138574
put32bits(((char*)pPgHdr->pData)+92, change_counter);
3857238575
put32bits(((char*)pPgHdr->pData)+96, SQLITE_VERSION_NUMBER);
3857338576
3857438577
/* If running in direct mode, write the contents of page 1 to the file. */
3857538578
if( DIRECT_MODE ){
38576
- const void *zBuf = pPgHdr->pData;
38579
+ const void *zBuf;
3857738580
assert( pPager->dbFileSize>0 );
38578
- rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
38581
+ CODEC2(pPager, pPgHdr->pData, 1, 6, rc=SQLITE_NOMEM, zBuf);
38582
+ if( rc==SQLITE_OK ){
38583
+ rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
38584
+ }
3857938585
if( rc==SQLITE_OK ){
3858038586
pPager->changeCountDone = 1;
3858138587
}
3858238588
}else{
3858338589
pPager->changeCountDone = 1;
@@ -39647,11 +39653,27 @@
3964739653
sqlite3OsUnlock(pPager->fd, SQLITE_LOCK_SHARED);
3964839654
}
3964939655
}
3965039656
return rc;
3965139657
}
39652
-#endif
39658
+
39659
+#ifdef SQLITE_HAS_CODEC
39660
+/*
39661
+** This function is called by the wal module when writing page content
39662
+** into the log file.
39663
+**
39664
+** This function returns a pointer to a buffer containing the encrypted
39665
+** page content. If a malloc fails, this function may return NULL.
39666
+*/
39667
+SQLITE_PRIVATE void *sqlite3PagerCodec(PgHdr *pPg){
39668
+ void *aData = 0;
39669
+ CODEC2(pPg->pPager, pPg->pData, pPg->pgno, 6, return 0, aData);
39670
+ return aData;
39671
+}
39672
+#endif /* SQLITE_HAS_CODEC */
39673
+
39674
+#endif /* !SQLITE_OMIT_WAL */
3965339675
3965439676
#endif /* SQLITE_OMIT_DISKIO */
3965539677
3965639678
/************** End of pager.c ***********************************************/
3965739679
/************** Begin file wal.c *********************************************/
@@ -41940,23 +41962,30 @@
4194041962
4194141963
/* Write the log file. */
4194241964
for(p=pList; p; p=p->pDirty){
4194341965
u32 nDbsize; /* Db-size field for frame header */
4194441966
i64 iOffset; /* Write offset in log file */
41945
-
41967
+ void *pData;
41968
+
41969
+
4194641970
iOffset = walFrameOffset(++iFrame, szPage);
4194741971
4194841972
/* Populate and write the frame header */
4194941973
nDbsize = (isCommit && p->pDirty==0) ? nTruncate : 0;
41950
- walEncodeFrame(pWal, p->pgno, nDbsize, p->pData, aFrame);
41974
+#if defined(SQLITE_HAS_CODEC)
41975
+ if( (pData = sqlite3PagerCodec(p))==0 ) return SQLITE_NOMEM;
41976
+#else
41977
+ pData = p->pData;
41978
+#endif
41979
+ walEncodeFrame(pWal, p->pgno, nDbsize, pData, aFrame);
4195141980
rc = sqlite3OsWrite(pWal->pWalFd, aFrame, sizeof(aFrame), iOffset);
4195241981
if( rc!=SQLITE_OK ){
4195341982
return rc;
4195441983
}
4195541984
4195641985
/* Write the page data */
41957
- rc = sqlite3OsWrite(pWal->pWalFd, p->pData, szPage, iOffset+sizeof(aFrame));
41986
+ rc = sqlite3OsWrite(pWal->pWalFd, pData, szPage, iOffset+sizeof(aFrame));
4195841987
if( rc!=SQLITE_OK ){
4195941988
return rc;
4196041989
}
4196141990
pLast = p;
4196241991
}
@@ -41969,18 +41998,23 @@
4196941998
assert( isCommit );
4197041999
assert( iSegment>0 );
4197142000
4197242001
iSegment = (((iOffset+iSegment-1)/iSegment) * iSegment);
4197342002
while( iOffset<iSegment ){
41974
- walEncodeFrame(pWal, pLast->pgno, nTruncate, pLast->pData, aFrame);
42003
+ void *pData;
42004
+#if defined(SQLITE_HAS_CODEC)
42005
+ if( (pData = sqlite3PagerCodec(pLast))==0 ) return SQLITE_NOMEM;
42006
+#else
42007
+ pData = pLast->pData;
42008
+#endif
42009
+ walEncodeFrame(pWal, pLast->pgno, nTruncate, pData, aFrame);
4197542010
rc = sqlite3OsWrite(pWal->pWalFd, aFrame, sizeof(aFrame), iOffset);
4197642011
if( rc!=SQLITE_OK ){
4197742012
return rc;
4197842013
}
41979
-
4198042014
iOffset += WAL_FRAME_HDRSIZE;
41981
- rc = sqlite3OsWrite(pWal->pWalFd, pLast->pData, szPage, iOffset);
42015
+ rc = sqlite3OsWrite(pWal->pWalFd, pData, szPage, iOffset);
4198242016
if( rc!=SQLITE_OK ){
4198342017
return rc;
4198442018
}
4198542019
nLast++;
4198642020
iOffset += szPage;
@@ -63351,10 +63385,14 @@
6335163385
*/
6335263386
rc = sqlite3PagerCloseWal(u.cd.pPager);
6335363387
if( rc==SQLITE_OK ){
6335463388
sqlite3PagerSetJournalMode(u.cd.pPager, u.cd.eNew);
6335563389
}
63390
+ }else if( u.cd.eOld==PAGER_JOURNALMODE_MEMORY ){
63391
+ /* Cannot transition directly from MEMORY to WAL. Use mode OFF
63392
+ ** as an intermediate */
63393
+ sqlite3PagerSetJournalMode(u.cd.pPager, PAGER_JOURNALMODE_OFF);
6335663394
}
6335763395
6335863396
/* Open a transaction on the database file. Regardless of the journal
6335963397
** mode, this transaction always uses a rollback journal.
6336063398
*/
6336163399
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -636,11 +636,11 @@
636 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
637 ** [sqlite_version()] and [sqlite_source_id()].
638 */
639 #define SQLITE_VERSION "3.7.0"
640 #define SQLITE_VERSION_NUMBER 3007000
641 #define SQLITE_SOURCE_ID "2010-06-21 12:47:41 ee0acef1faffd480fd2136f81fb2b6f6a17b5388"
642
643 /*
644 ** CAPI3REF: Run-Time Library Version Numbers
645 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
646 **
@@ -7858,10 +7858,14 @@
7858 SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
7859 SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*);
7860
7861 /* Functions used to truncate the database file. */
7862 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
 
 
 
 
7863
7864 /* Functions to support testing and debugging. */
7865 #if !defined(NDEBUG) || defined(SQLITE_TEST)
7866 SQLITE_PRIVATE Pgno sqlite3PagerPagenumber(DbPage*);
7867 SQLITE_PRIVATE int sqlite3PagerIswriteable(DbPage*);
@@ -31136,11 +31140,11 @@
31136 GetSystemTimeAsFileTime( &ft );
31137 #endif
31138
31139 *piNow = winFiletimeEpoch +
31140 ((((sqlite3_int64)ft.dwHighDateTime)*max32BitValue) +
31141 (sqlite3_int64)ft.dwLowDateTime)/(sqlite3_int64)1000;
31142
31143 #ifdef SQLITE_TEST
31144 if( sqlite3_current_time ){
31145 *piNow = 1000*(sqlite3_int64)sqlite3_current_time + unixEpoch;
31146 }
@@ -34772,13 +34776,14 @@
34772 static void pager_unlock(Pager *pPager){
34773 if( !pPager->exclusiveMode ){
34774 int rc = SQLITE_OK; /* Return code */
34775 int iDc = isOpen(pPager->fd)?sqlite3OsDeviceCharacteristics(pPager->fd):0;
34776
34777 /* Always close the journal file when dropping the database lock.
34778 ** Otherwise, another connection with journal_mode=delete might
34779 ** delete the file out from under us.
 
34780 */
34781 assert( (PAGER_JOURNALMODE_MEMORY & 5)!=1 );
34782 assert( (PAGER_JOURNALMODE_OFF & 5)!=1 );
34783 assert( (PAGER_JOURNALMODE_WAL & 5)!=1 );
34784 assert( (PAGER_JOURNALMODE_DELETE & 5)!=1 );
@@ -35346,10 +35351,13 @@
35346 int rc; /* Return code */
35347 sqlite3_file *pMaster; /* Malloc'd master-journal file descriptor */
35348 sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */
35349 char *zMasterJournal = 0; /* Contents of master journal file */
35350 i64 nMasterJournal; /* Size of master journal file */
 
 
 
35351
35352 /* Allocate space for both the pJournal and pMaster file descriptors.
35353 ** If successful, open the master journal file for reading.
35354 */
35355 pMaster = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile * 2);
@@ -35360,77 +35368,72 @@
35360 const int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MASTER_JOURNAL);
35361 rc = sqlite3OsOpen(pVfs, zMaster, pMaster, flags, 0);
35362 }
35363 if( rc!=SQLITE_OK ) goto delmaster_out;
35364
35365 rc = sqlite3OsFileSize(pMaster, &nMasterJournal);
35366 if( rc!=SQLITE_OK ) goto delmaster_out;
35367
35368 if( nMasterJournal>0 ){
35369 char *zJournal;
35370 char *zMasterPtr = 0;
35371 int nMasterPtr = pVfs->mxPathname+1;
35372
35373 /* Load the entire master journal file into space obtained from
35374 ** sqlite3_malloc() and pointed to by zMasterJournal.
35375 */
35376 zMasterJournal = sqlite3Malloc((int)nMasterJournal + nMasterPtr + 1);
35377 if( !zMasterJournal ){
35378 rc = SQLITE_NOMEM;
35379 goto delmaster_out;
35380 }
35381 zMasterPtr = &zMasterJournal[nMasterJournal+1];
35382 rc = sqlite3OsRead(pMaster, zMasterJournal, (int)nMasterJournal, 0);
35383 if( rc!=SQLITE_OK ) goto delmaster_out;
35384 zMasterJournal[nMasterJournal] = 0;
35385
35386 zJournal = zMasterJournal;
35387 while( (zJournal-zMasterJournal)<nMasterJournal ){
35388 int exists;
35389 rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists);
35390 if( rc!=SQLITE_OK ){
35391 goto delmaster_out;
35392 }
35393 if( exists ){
35394 /* One of the journals pointed to by the master journal exists.
35395 ** Open it and check if it points at the master journal. If
35396 ** so, return without deleting the master journal file.
35397 */
35398 int c;
35399 int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MAIN_JOURNAL);
35400 rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0);
35401 if( rc!=SQLITE_OK ){
35402 goto delmaster_out;
35403 }
35404
35405 rc = readMasterJournal(pJournal, zMasterPtr, nMasterPtr);
35406 sqlite3OsClose(pJournal);
35407 if( rc!=SQLITE_OK ){
35408 goto delmaster_out;
35409 }
35410
35411 c = zMasterPtr[0]!=0 && strcmp(zMasterPtr, zMaster)==0;
35412 if( c ){
35413 /* We have a match. Do not delete the master journal file. */
35414 goto delmaster_out;
35415 }
35416 }
35417 zJournal += (sqlite3Strlen30(zJournal)+1);
35418 }
35419 }
35420
35421 rc = sqlite3OsDelete(pVfs, zMaster, 0);
35422
35423 delmaster_out:
35424 if( zMasterJournal ){
35425 sqlite3_free(zMasterJournal);
35426 }
35427 if( pMaster ){
35428 sqlite3OsClose(pMaster);
35429 assert( !isOpen(pJournal) );
 
35430 }
35431 sqlite3_free(pMaster);
35432 return rc;
35433 }
35434
35435
35436 /*
@@ -36125,11 +36128,11 @@
36125 for(ii=0; rc==SQLITE_OK && ii<nJRec && pPager->journalOff<szJ; ii++){
36126 rc = pager_playback_one_page(pPager, &pPager->journalOff, pDone, 1, 1);
36127 }
36128 assert( rc!=SQLITE_DONE );
36129 }
36130 assert( rc!=SQLITE_OK || pPager->journalOff==szJ );
36131
36132 /* Finally, rollback pages from the sub-journal. Page that were
36133 ** previously rolled back out of the main journal (and are hence in pDone)
36134 ** will be skipped. Out-of-range pages are also skipped.
36135 */
@@ -38256,11 +38259,11 @@
38256 */
38257 rc = sqlite3PagerBegin(pPager, 0, pPager->subjInMemory);
38258 if( rc!=SQLITE_OK ){
38259 return rc;
38260 }
38261 if( !isOpen(pPager->jfd)
38262 && pPager->journalMode!=PAGER_JOURNALMODE_OFF
38263 && !pagerUseWal(pPager)
38264 ){
38265 assert( pPager->useJournal );
38266 rc = pager_open_journal(pPager);
@@ -38571,13 +38574,16 @@
38571 put32bits(((char*)pPgHdr->pData)+92, change_counter);
38572 put32bits(((char*)pPgHdr->pData)+96, SQLITE_VERSION_NUMBER);
38573
38574 /* If running in direct mode, write the contents of page 1 to the file. */
38575 if( DIRECT_MODE ){
38576 const void *zBuf = pPgHdr->pData;
38577 assert( pPager->dbFileSize>0 );
38578 rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
 
 
 
38579 if( rc==SQLITE_OK ){
38580 pPager->changeCountDone = 1;
38581 }
38582 }else{
38583 pPager->changeCountDone = 1;
@@ -39647,11 +39653,27 @@
39647 sqlite3OsUnlock(pPager->fd, SQLITE_LOCK_SHARED);
39648 }
39649 }
39650 return rc;
39651 }
39652 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39653
39654 #endif /* SQLITE_OMIT_DISKIO */
39655
39656 /************** End of pager.c ***********************************************/
39657 /************** Begin file wal.c *********************************************/
@@ -41940,23 +41962,30 @@
41940
41941 /* Write the log file. */
41942 for(p=pList; p; p=p->pDirty){
41943 u32 nDbsize; /* Db-size field for frame header */
41944 i64 iOffset; /* Write offset in log file */
41945
 
 
41946 iOffset = walFrameOffset(++iFrame, szPage);
41947
41948 /* Populate and write the frame header */
41949 nDbsize = (isCommit && p->pDirty==0) ? nTruncate : 0;
41950 walEncodeFrame(pWal, p->pgno, nDbsize, p->pData, aFrame);
 
 
 
 
 
41951 rc = sqlite3OsWrite(pWal->pWalFd, aFrame, sizeof(aFrame), iOffset);
41952 if( rc!=SQLITE_OK ){
41953 return rc;
41954 }
41955
41956 /* Write the page data */
41957 rc = sqlite3OsWrite(pWal->pWalFd, p->pData, szPage, iOffset+sizeof(aFrame));
41958 if( rc!=SQLITE_OK ){
41959 return rc;
41960 }
41961 pLast = p;
41962 }
@@ -41969,18 +41998,23 @@
41969 assert( isCommit );
41970 assert( iSegment>0 );
41971
41972 iSegment = (((iOffset+iSegment-1)/iSegment) * iSegment);
41973 while( iOffset<iSegment ){
41974 walEncodeFrame(pWal, pLast->pgno, nTruncate, pLast->pData, aFrame);
 
 
 
 
 
 
41975 rc = sqlite3OsWrite(pWal->pWalFd, aFrame, sizeof(aFrame), iOffset);
41976 if( rc!=SQLITE_OK ){
41977 return rc;
41978 }
41979
41980 iOffset += WAL_FRAME_HDRSIZE;
41981 rc = sqlite3OsWrite(pWal->pWalFd, pLast->pData, szPage, iOffset);
41982 if( rc!=SQLITE_OK ){
41983 return rc;
41984 }
41985 nLast++;
41986 iOffset += szPage;
@@ -63351,10 +63385,14 @@
63351 */
63352 rc = sqlite3PagerCloseWal(u.cd.pPager);
63353 if( rc==SQLITE_OK ){
63354 sqlite3PagerSetJournalMode(u.cd.pPager, u.cd.eNew);
63355 }
 
 
 
 
63356 }
63357
63358 /* Open a transaction on the database file. Regardless of the journal
63359 ** mode, this transaction always uses a rollback journal.
63360 */
63361
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -636,11 +636,11 @@
636 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
637 ** [sqlite_version()] and [sqlite_source_id()].
638 */
639 #define SQLITE_VERSION "3.7.0"
640 #define SQLITE_VERSION_NUMBER 3007000
641 #define SQLITE_SOURCE_ID "2010-06-23 15:18:12 51ef43b9f7db8fabf73d9c8a76dae6c275e50d58"
642
643 /*
644 ** CAPI3REF: Run-Time Library Version Numbers
645 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
646 **
@@ -7858,10 +7858,14 @@
7858 SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
7859 SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager*);
7860
7861 /* Functions used to truncate the database file. */
7862 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager*,Pgno);
7863
7864 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL)
7865 SQLITE_PRIVATE void *sqlite3PagerCodec(DbPage *);
7866 #endif
7867
7868 /* Functions to support testing and debugging. */
7869 #if !defined(NDEBUG) || defined(SQLITE_TEST)
7870 SQLITE_PRIVATE Pgno sqlite3PagerPagenumber(DbPage*);
7871 SQLITE_PRIVATE int sqlite3PagerIswriteable(DbPage*);
@@ -31136,11 +31140,11 @@
31140 GetSystemTimeAsFileTime( &ft );
31141 #endif
31142
31143 *piNow = winFiletimeEpoch +
31144 ((((sqlite3_int64)ft.dwHighDateTime)*max32BitValue) +
31145 (sqlite3_int64)ft.dwLowDateTime)/(sqlite3_int64)10000;
31146
31147 #ifdef SQLITE_TEST
31148 if( sqlite3_current_time ){
31149 *piNow = 1000*(sqlite3_int64)sqlite3_current_time + unixEpoch;
31150 }
@@ -34772,13 +34776,14 @@
34776 static void pager_unlock(Pager *pPager){
34777 if( !pPager->exclusiveMode ){
34778 int rc = SQLITE_OK; /* Return code */
34779 int iDc = isOpen(pPager->fd)?sqlite3OsDeviceCharacteristics(pPager->fd):0;
34780
34781 /* If the operating system support deletion of open files, then
34782 ** close the journal file when dropping the database lock. Otherwise
34783 ** another connection with journal_mode=delete might delete the file
34784 ** out from under us.
34785 */
34786 assert( (PAGER_JOURNALMODE_MEMORY & 5)!=1 );
34787 assert( (PAGER_JOURNALMODE_OFF & 5)!=1 );
34788 assert( (PAGER_JOURNALMODE_WAL & 5)!=1 );
34789 assert( (PAGER_JOURNALMODE_DELETE & 5)!=1 );
@@ -35346,10 +35351,13 @@
35351 int rc; /* Return code */
35352 sqlite3_file *pMaster; /* Malloc'd master-journal file descriptor */
35353 sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */
35354 char *zMasterJournal = 0; /* Contents of master journal file */
35355 i64 nMasterJournal; /* Size of master journal file */
35356 char *zJournal; /* Pointer to one journal within MJ file */
35357 char *zMasterPtr; /* Space to hold MJ filename from a journal file */
35358 int nMasterPtr; /* Amount of space allocated to zMasterPtr[] */
35359
35360 /* Allocate space for both the pJournal and pMaster file descriptors.
35361 ** If successful, open the master journal file for reading.
35362 */
35363 pMaster = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile * 2);
@@ -35360,77 +35368,72 @@
35368 const int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MASTER_JOURNAL);
35369 rc = sqlite3OsOpen(pVfs, zMaster, pMaster, flags, 0);
35370 }
35371 if( rc!=SQLITE_OK ) goto delmaster_out;
35372
35373 /* Load the entire master journal file into space obtained from
35374 ** sqlite3_malloc() and pointed to by zMasterJournal. Also obtain
35375 ** sufficient space (in zMasterPtr) to hold the names of master
35376 ** journal files extracted from regular rollback-journals.
35377 */
35378 rc = sqlite3OsFileSize(pMaster, &nMasterJournal);
35379 if( rc!=SQLITE_OK ) goto delmaster_out;
35380 nMasterPtr = pVfs->mxPathname+1;
35381 zMasterJournal = sqlite3Malloc((int)nMasterJournal + nMasterPtr + 1);
35382 if( !zMasterJournal ){
35383 rc = SQLITE_NOMEM;
35384 goto delmaster_out;
35385 }
35386 zMasterPtr = &zMasterJournal[nMasterJournal+1];
35387 rc = sqlite3OsRead(pMaster, zMasterJournal, (int)nMasterJournal, 0);
35388 if( rc!=SQLITE_OK ) goto delmaster_out;
35389 zMasterJournal[nMasterJournal] = 0;
35390
35391 zJournal = zMasterJournal;
35392 while( (zJournal-zMasterJournal)<nMasterJournal ){
35393 int exists;
35394 rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists);
35395 if( rc!=SQLITE_OK ){
35396 goto delmaster_out;
35397 }
35398 if( exists ){
35399 /* One of the journals pointed to by the master journal exists.
35400 ** Open it and check if it points at the master journal. If
35401 ** so, return without deleting the master journal file.
35402 */
35403 int c;
35404 int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MAIN_JOURNAL);
35405 rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0);
35406 if( rc!=SQLITE_OK ){
35407 goto delmaster_out;
35408 }
35409
35410 rc = readMasterJournal(pJournal, zMasterPtr, nMasterPtr);
35411 sqlite3OsClose(pJournal);
35412 if( rc!=SQLITE_OK ){
35413 goto delmaster_out;
35414 }
35415
35416 c = zMasterPtr[0]!=0 && strcmp(zMasterPtr, zMaster)==0;
35417 if( c ){
35418 /* We have a match. Do not delete the master journal file. */
35419 goto delmaster_out;
35420 }
35421 }
35422 zJournal += (sqlite3Strlen30(zJournal)+1);
35423 }
35424
35425 sqlite3OsClose(pMaster);
 
 
 
35426 rc = sqlite3OsDelete(pVfs, zMaster, 0);
35427
35428 delmaster_out:
35429 sqlite3_free(zMasterJournal);
 
 
35430 if( pMaster ){
35431 sqlite3OsClose(pMaster);
35432 assert( !isOpen(pJournal) );
35433 sqlite3_free(pMaster);
35434 }
 
35435 return rc;
35436 }
35437
35438
35439 /*
@@ -36125,11 +36128,11 @@
36128 for(ii=0; rc==SQLITE_OK && ii<nJRec && pPager->journalOff<szJ; ii++){
36129 rc = pager_playback_one_page(pPager, &pPager->journalOff, pDone, 1, 1);
36130 }
36131 assert( rc!=SQLITE_DONE );
36132 }
36133 assert( rc!=SQLITE_OK || pPager->journalOff>=szJ );
36134
36135 /* Finally, rollback pages from the sub-journal. Page that were
36136 ** previously rolled back out of the main journal (and are hence in pDone)
36137 ** will be skipped. Out-of-range pages are also skipped.
36138 */
@@ -38256,11 +38259,11 @@
38259 */
38260 rc = sqlite3PagerBegin(pPager, 0, pPager->subjInMemory);
38261 if( rc!=SQLITE_OK ){
38262 return rc;
38263 }
38264 if( pPager->pInJournal==0
38265 && pPager->journalMode!=PAGER_JOURNALMODE_OFF
38266 && !pagerUseWal(pPager)
38267 ){
38268 assert( pPager->useJournal );
38269 rc = pager_open_journal(pPager);
@@ -38571,13 +38574,16 @@
38574 put32bits(((char*)pPgHdr->pData)+92, change_counter);
38575 put32bits(((char*)pPgHdr->pData)+96, SQLITE_VERSION_NUMBER);
38576
38577 /* If running in direct mode, write the contents of page 1 to the file. */
38578 if( DIRECT_MODE ){
38579 const void *zBuf;
38580 assert( pPager->dbFileSize>0 );
38581 CODEC2(pPager, pPgHdr->pData, 1, 6, rc=SQLITE_NOMEM, zBuf);
38582 if( rc==SQLITE_OK ){
38583 rc = sqlite3OsWrite(pPager->fd, zBuf, pPager->pageSize, 0);
38584 }
38585 if( rc==SQLITE_OK ){
38586 pPager->changeCountDone = 1;
38587 }
38588 }else{
38589 pPager->changeCountDone = 1;
@@ -39647,11 +39653,27 @@
39653 sqlite3OsUnlock(pPager->fd, SQLITE_LOCK_SHARED);
39654 }
39655 }
39656 return rc;
39657 }
39658
39659 #ifdef SQLITE_HAS_CODEC
39660 /*
39661 ** This function is called by the wal module when writing page content
39662 ** into the log file.
39663 **
39664 ** This function returns a pointer to a buffer containing the encrypted
39665 ** page content. If a malloc fails, this function may return NULL.
39666 */
39667 SQLITE_PRIVATE void *sqlite3PagerCodec(PgHdr *pPg){
39668 void *aData = 0;
39669 CODEC2(pPg->pPager, pPg->pData, pPg->pgno, 6, return 0, aData);
39670 return aData;
39671 }
39672 #endif /* SQLITE_HAS_CODEC */
39673
39674 #endif /* !SQLITE_OMIT_WAL */
39675
39676 #endif /* SQLITE_OMIT_DISKIO */
39677
39678 /************** End of pager.c ***********************************************/
39679 /************** Begin file wal.c *********************************************/
@@ -41940,23 +41962,30 @@
41962
41963 /* Write the log file. */
41964 for(p=pList; p; p=p->pDirty){
41965 u32 nDbsize; /* Db-size field for frame header */
41966 i64 iOffset; /* Write offset in log file */
41967 void *pData;
41968
41969
41970 iOffset = walFrameOffset(++iFrame, szPage);
41971
41972 /* Populate and write the frame header */
41973 nDbsize = (isCommit && p->pDirty==0) ? nTruncate : 0;
41974 #if defined(SQLITE_HAS_CODEC)
41975 if( (pData = sqlite3PagerCodec(p))==0 ) return SQLITE_NOMEM;
41976 #else
41977 pData = p->pData;
41978 #endif
41979 walEncodeFrame(pWal, p->pgno, nDbsize, pData, aFrame);
41980 rc = sqlite3OsWrite(pWal->pWalFd, aFrame, sizeof(aFrame), iOffset);
41981 if( rc!=SQLITE_OK ){
41982 return rc;
41983 }
41984
41985 /* Write the page data */
41986 rc = sqlite3OsWrite(pWal->pWalFd, pData, szPage, iOffset+sizeof(aFrame));
41987 if( rc!=SQLITE_OK ){
41988 return rc;
41989 }
41990 pLast = p;
41991 }
@@ -41969,18 +41998,23 @@
41998 assert( isCommit );
41999 assert( iSegment>0 );
42000
42001 iSegment = (((iOffset+iSegment-1)/iSegment) * iSegment);
42002 while( iOffset<iSegment ){
42003 void *pData;
42004 #if defined(SQLITE_HAS_CODEC)
42005 if( (pData = sqlite3PagerCodec(pLast))==0 ) return SQLITE_NOMEM;
42006 #else
42007 pData = pLast->pData;
42008 #endif
42009 walEncodeFrame(pWal, pLast->pgno, nTruncate, pData, aFrame);
42010 rc = sqlite3OsWrite(pWal->pWalFd, aFrame, sizeof(aFrame), iOffset);
42011 if( rc!=SQLITE_OK ){
42012 return rc;
42013 }
 
42014 iOffset += WAL_FRAME_HDRSIZE;
42015 rc = sqlite3OsWrite(pWal->pWalFd, pData, szPage, iOffset);
42016 if( rc!=SQLITE_OK ){
42017 return rc;
42018 }
42019 nLast++;
42020 iOffset += szPage;
@@ -63351,10 +63385,14 @@
63385 */
63386 rc = sqlite3PagerCloseWal(u.cd.pPager);
63387 if( rc==SQLITE_OK ){
63388 sqlite3PagerSetJournalMode(u.cd.pPager, u.cd.eNew);
63389 }
63390 }else if( u.cd.eOld==PAGER_JOURNALMODE_MEMORY ){
63391 /* Cannot transition directly from MEMORY to WAL. Use mode OFF
63392 ** as an intermediate */
63393 sqlite3PagerSetJournalMode(u.cd.pPager, PAGER_JOURNALMODE_OFF);
63394 }
63395
63396 /* Open a transaction on the database file. Regardless of the journal
63397 ** mode, this transaction always uses a rollback journal.
63398 */
63399
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.7.0"
111111
#define SQLITE_VERSION_NUMBER 3007000
112
-#define SQLITE_SOURCE_ID "2010-06-21 12:47:41 ee0acef1faffd480fd2136f81fb2b6f6a17b5388"
112
+#define SQLITE_SOURCE_ID "2010-06-23 15:18:12 51ef43b9f7db8fabf73d9c8a76dae6c275e50d58"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
118118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.0"
111 #define SQLITE_VERSION_NUMBER 3007000
112 #define SQLITE_SOURCE_ID "2010-06-21 12:47:41 ee0acef1faffd480fd2136f81fb2b6f6a17b5388"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.0"
111 #define SQLITE_VERSION_NUMBER 3007000
112 #define SQLITE_SOURCE_ID "2010-06-23 15:18:12 51ef43b9f7db8fabf73d9c8a76dae6c275e50d58"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button