Fossil SCM

Update to the latest version of SQLite with WAL support.

drh 2010-06-21 15:08 trunk
Commit ed1037e22592b5d9106ec5e47e4c0713c464b96c
2 files changed +120 -79 +13 -12
+120 -79
--- 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-16 12:30:11 ad3209572d0e6afe5c8b52313e334509661045e2"
641
+#define SQLITE_SOURCE_ID "2010-06-21 12:47:41 ee0acef1faffd480fd2136f81fb2b6f6a17b5388"
642642
643643
/*
644644
** CAPI3REF: Run-Time Library Version Numbers
645645
** KEYWORDS: sqlite3_version, sqlite3_sourceid
646646
**
@@ -1029,21 +1029,22 @@
10291029
** first then the size of the file is extended, never the other
10301030
** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
10311031
** information is written to disk in the same order as calls
10321032
** to xWrite().
10331033
*/
1034
-#define SQLITE_IOCAP_ATOMIC 0x00000001
1035
-#define SQLITE_IOCAP_ATOMIC512 0x00000002
1036
-#define SQLITE_IOCAP_ATOMIC1K 0x00000004
1037
-#define SQLITE_IOCAP_ATOMIC2K 0x00000008
1038
-#define SQLITE_IOCAP_ATOMIC4K 0x00000010
1039
-#define SQLITE_IOCAP_ATOMIC8K 0x00000020
1040
-#define SQLITE_IOCAP_ATOMIC16K 0x00000040
1041
-#define SQLITE_IOCAP_ATOMIC32K 0x00000080
1042
-#define SQLITE_IOCAP_ATOMIC64K 0x00000100
1043
-#define SQLITE_IOCAP_SAFE_APPEND 0x00000200
1044
-#define SQLITE_IOCAP_SEQUENTIAL 0x00000400
1034
+#define SQLITE_IOCAP_ATOMIC 0x00000001
1035
+#define SQLITE_IOCAP_ATOMIC512 0x00000002
1036
+#define SQLITE_IOCAP_ATOMIC1K 0x00000004
1037
+#define SQLITE_IOCAP_ATOMIC2K 0x00000008
1038
+#define SQLITE_IOCAP_ATOMIC4K 0x00000010
1039
+#define SQLITE_IOCAP_ATOMIC8K 0x00000020
1040
+#define SQLITE_IOCAP_ATOMIC16K 0x00000040
1041
+#define SQLITE_IOCAP_ATOMIC32K 0x00000080
1042
+#define SQLITE_IOCAP_ATOMIC64K 0x00000100
1043
+#define SQLITE_IOCAP_SAFE_APPEND 0x00000200
1044
+#define SQLITE_IOCAP_SEQUENTIAL 0x00000400
1045
+#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800
10451046
10461047
/*
10471048
** CAPI3REF: File Locking Levels
10481049
**
10491050
** SQLite uses one of these integer values as the second
@@ -25680,23 +25681,25 @@
2568025681
p->pInode->pShmNode = 0;
2568125682
sqlite3_free(p);
2568225683
}
2568325684
}
2568425685
25685
-/* Forward reference */
25686
-static const char *unixTempFileDir(int);
25687
-
2568825686
/*
25689
-** Open a shared-memory area. This particular implementation uses
25690
-** mmapped files.
25687
+** Open a shared-memory area associated with open database file fd.
25688
+** This particular implementation uses mmapped files.
2569125689
**
25692
-** zName is a filename used to identify the shared-memory area. The
25693
-** implementation does not (and perhaps should not) use this name
25694
-** directly, but rather use it as a template for finding an appropriate
25695
-** name for the shared-memory storage. In this implementation, the
25696
-** string "-index" is appended to zName and used as the name of the
25697
-** mmapped file.
25690
+** The file used to implement shared-memory is in the same directory
25691
+** as the open database file and has the same name as the open database
25692
+** file with the "-shm" suffix added. For example, if the database file
25693
+** is "/home/user1/config.db" then the file that is created and mmapped
25694
+** for shared memory will be called "/home/user1/config.db-shm". We
25695
+** experimented with using files in /dev/tmp or an some other tmpfs mount.
25696
+** But if a file in a different directory from the database file is used,
25697
+** then differing access permissions or a chroot() might cause two different
25698
+** processes on the same database to end up using different files for
25699
+** shared memory - meaning that their memory would not really be shared -
25700
+** resulting in database corruption.
2569825701
**
2569925702
** When opening a new shared-memory file, if no other instances of that
2570025703
** file are currently open, in this process or in other processes, then
2570125704
** the file must be truncated to zero length or have its header cleared.
2570225705
*/
@@ -25706,12 +25709,12 @@
2570625709
struct unixShm *p = 0; /* The connection to be opened */
2570725710
struct unixShmNode *pShmNode = 0; /* The underlying mmapped file */
2570825711
int rc; /* Result code */
2570925712
struct unixFile *pDbFd; /* Underlying database file */
2571025713
unixInodeInfo *pInode; /* The inode of fd */
25711
- const char *zTempDir; /* Directory for temporary files */
25712
- int nTempDir; /* Size of the zTempDir string */
25714
+ char *zShmFilename; /* Name of the file used for SHM */
25715
+ int nShmFilename; /* Size of the SHM filename in bytes */
2571325716
2571425717
/* Allocate space for the new sqlite3_shm object.
2571525718
*/
2571625719
p = sqlite3_malloc( sizeof(*p) );
2571725720
if( p==0 ) return SQLITE_NOMEM;
@@ -25724,37 +25727,29 @@
2572425727
*/
2572525728
unixEnterMutex();
2572625729
pInode = pDbFd->pInode;
2572725730
pShmNode = pInode->pShmNode;
2572825731
if( pShmNode==0 ){
25729
- zTempDir = unixTempFileDir(1);
25730
- if( zTempDir==0 ){
25731
- unixLeaveMutex();
25732
- sqlite3_free(p);
25733
- return SQLITE_CANTOPEN_NOTEMPDIR;
25734
- }
25735
- nTempDir = strlen(zTempDir);
25736
- pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nTempDir + 50 );
25732
+ nShmFilename = 5 + (int)strlen(pDbFd->zPath);
25733
+ pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename );
2573725734
if( pShmNode==0 ){
2573825735
rc = SQLITE_NOMEM;
2573925736
goto shm_open_err;
2574025737
}
2574125738
memset(pShmNode, 0, sizeof(*pShmNode));
25742
- pShmNode->zFilename = (char*)&pShmNode[1];
25743
- sqlite3_snprintf(nTempDir+50, pShmNode->zFilename,
25744
- "%s/sqlite-wi-%x-%x", zTempDir,
25745
- (u32)pInode->fileId.dev, (u32)pInode->fileId.ino);
25739
+ zShmFilename = pShmNode->zFilename = (char*)&pShmNode[1];
25740
+ sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", pDbFd->zPath);
2574625741
pShmNode->h = -1;
2574725742
pDbFd->pInode->pShmNode = pShmNode;
2574825743
pShmNode->pInode = pDbFd->pInode;
2574925744
pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
2575025745
if( pShmNode->mutex==0 ){
2575125746
rc = SQLITE_NOMEM;
2575225747
goto shm_open_err;
2575325748
}
2575425749
25755
- pShmNode->h = open(pShmNode->zFilename, O_RDWR|O_CREAT, 0664);
25750
+ pShmNode->h = open(zShmFilename, O_RDWR|O_CREAT, 0664);
2575625751
if( pShmNode->h<0 ){
2575725752
rc = SQLITE_CANTOPEN_BKPT;
2575825753
goto shm_open_err;
2575925754
}
2576025755
@@ -26563,11 +26558,11 @@
2656326558
2656426559
/*
2656526560
** Return the name of a directory in which to put temporary files.
2656626561
** If no suitable temporary file directory can be found, return NULL.
2656726562
*/
26568
-static const char *unixTempFileDir(int allowShm){
26563
+static const char *unixTempFileDir(void){
2656926564
static const char *azDirs[] = {
2657026565
0,
2657126566
0,
2657226567
"/var/tmp",
2657326568
"/usr/tmp",
@@ -26578,23 +26573,15 @@
2657826573
struct stat buf;
2657926574
const char *zDir = 0;
2658026575
2658126576
azDirs[0] = sqlite3_temp_directory;
2658226577
if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
26583
-
26584
- if( allowShm ){
26585
- zDir = "/dev/shm";
26586
- i = 2; /* Skip the app-defined temp locations for shared-memory */
26587
- }else{
26588
- zDir = azDirs[0];
26589
- i = 1;
26590
- }
26591
- for(; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
26578
+ for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
2659226579
if( zDir==0 ) continue;
2659326580
if( stat(zDir, &buf) ) continue;
2659426581
if( !S_ISDIR(buf.st_mode) ) continue;
26595
- if( !allowShm && access(zDir, 07) ) continue;
26582
+ if( access(zDir, 07) ) continue;
2659626583
break;
2659726584
}
2659826585
return zDir;
2659926586
}
2660026587
@@ -26615,11 +26602,11 @@
2661526602
** using the io-error infrastructure to test that SQLite handles this
2661626603
** function failing.
2661726604
*/
2661826605
SimulateIOError( return SQLITE_IOERR );
2661926606
26620
- zDir = unixTempFileDir(0);
26607
+ zDir = unixTempFileDir();
2662126608
if( zDir==0 ) zDir = ".";
2662226609
2662326610
/* Check that the output buffer is large enough for the temporary file
2662426611
** name. If it is not, return SQLITE_ERROR.
2662526612
*/
@@ -27024,10 +27011,16 @@
2702427011
2702527012
default:
2702627013
assert(!"Invalid flags argument");
2702727014
}
2702827015
*pResOut = (access(zPath, amode)==0);
27016
+ if( flags==SQLITE_ACCESS_EXISTS && *pResOut ){
27017
+ struct stat buf;
27018
+ if( 0==stat(zPath, &buf) && buf.st_size==0 ){
27019
+ *pResOut = 0;
27020
+ }
27021
+ }
2702927022
return SQLITE_OK;
2703027023
}
2703127024
2703227025
2703327026
/*
@@ -29906,11 +29899,11 @@
2990629899
/*
2990729900
** Return a vector of device characteristics.
2990829901
*/
2990929902
static int winDeviceCharacteristics(sqlite3_file *id){
2991029903
UNUSED_PARAMETER(id);
29911
- return 0;
29904
+ return SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN;
2991229905
}
2991329906
2991429907
/****************************************************************************
2991529908
********************************* Shared Memory *****************************
2991629909
**
@@ -34777,16 +34770,28 @@
3477734770
** treated as a hot-journal and rolled back.
3477834771
*/
3477934772
static void pager_unlock(Pager *pPager){
3478034773
if( !pPager->exclusiveMode ){
3478134774
int rc = SQLITE_OK; /* Return code */
34775
+ int iDc = isOpen(pPager->fd)?sqlite3OsDeviceCharacteristics(pPager->fd):0;
3478234776
3478334777
/* Always close the journal file when dropping the database lock.
3478434778
** Otherwise, another connection with journal_mode=delete might
3478534779
** delete the file out from under us.
3478634780
*/
34787
- sqlite3OsClose(pPager->jfd);
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 );
34785
+ assert( (PAGER_JOURNALMODE_TRUNCATE & 5)==1 );
34786
+ assert( (PAGER_JOURNALMODE_PERSIST & 5)==1 );
34787
+ if( 0==(iDc & SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN)
34788
+ || 1!=(pPager->journalMode & 5)
34789
+ ){
34790
+ sqlite3OsClose(pPager->jfd);
34791
+ }
34792
+
3478834793
sqlite3BitvecDestroy(pPager->pInJournal);
3478934794
pPager->pInJournal = 0;
3479034795
releaseAllSavepoints(pPager);
3479134796
3479234797
/* If the file is unlocked, somebody else might change it. The
@@ -36673,10 +36678,11 @@
3667336678
}
3667436679
sqlite3EndBenignMalloc();
3667536680
enable_simulated_io_errors();
3667636681
PAGERTRACE(("CLOSE %d\n", PAGERID(pPager)));
3667736682
IOTRACE(("CLOSE %p\n", pPager))
36683
+ sqlite3OsClose(pPager->jfd);
3667836684
sqlite3OsClose(pPager->fd);
3667936685
sqlite3PageFree(pTmp);
3668036686
sqlite3PcacheClose(pPager->pPCache);
3668136687
3668236688
#ifdef SQLITE_HAS_CODEC
@@ -37466,21 +37472,26 @@
3746637472
** to determine whether or not a hot-journal file exists, the IO error
3746737473
** code is returned and the value of *pExists is undefined.
3746837474
*/
3746937475
static int hasHotJournal(Pager *pPager, int *pExists){
3747037476
sqlite3_vfs * const pVfs = pPager->pVfs;
37471
- int rc; /* Return code */
37472
- int exists; /* True if a journal file is present */
37477
+ int rc = SQLITE_OK; /* Return code */
37478
+ int exists = 1; /* True if a journal file is present */
37479
+ int jrnlOpen = !!isOpen(pPager->jfd);
3747337480
3747437481
assert( pPager!=0 );
3747537482
assert( pPager->useJournal );
3747637483
assert( isOpen(pPager->fd) );
37477
- assert( !isOpen(pPager->jfd) );
3747837484
assert( pPager->state <= PAGER_SHARED );
37485
+ assert( jrnlOpen==0 || ( sqlite3OsDeviceCharacteristics(pPager->jfd) &
37486
+ SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
37487
+ ));
3747937488
3748037489
*pExists = 0;
37481
- rc = sqlite3OsAccess(pVfs, pPager->zJournal, SQLITE_ACCESS_EXISTS, &exists);
37490
+ if( !jrnlOpen ){
37491
+ rc = sqlite3OsAccess(pVfs, pPager->zJournal, SQLITE_ACCESS_EXISTS, &exists);
37492
+ }
3748237493
if( rc==SQLITE_OK && exists ){
3748337494
int locked; /* True if some process holds a RESERVED lock */
3748437495
3748537496
/* Race condition here: Another process might have been holding the
3748637497
** the RESERVED lock and have a journal open at the sqlite3OsAccess()
@@ -37514,19 +37525,23 @@
3751437525
** or greater lock on the database file. Now check that there is
3751537526
** at least one non-zero bytes at the start of the journal file.
3751637527
** If there is, then we consider this journal to be hot. If not,
3751737528
** it can be ignored.
3751837529
*/
37519
- int f = SQLITE_OPEN_READONLY|SQLITE_OPEN_MAIN_JOURNAL;
37520
- rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, f, &f);
37530
+ if( !jrnlOpen ){
37531
+ int f = SQLITE_OPEN_READONLY|SQLITE_OPEN_MAIN_JOURNAL;
37532
+ rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, f, &f);
37533
+ }
3752137534
if( rc==SQLITE_OK ){
3752237535
u8 first = 0;
3752337536
rc = sqlite3OsRead(pPager->jfd, (void *)&first, 1, 0);
3752437537
if( rc==SQLITE_IOERR_SHORT_READ ){
3752537538
rc = SQLITE_OK;
3752637539
}
37527
- sqlite3OsClose(pPager->jfd);
37540
+ if( !jrnlOpen ){
37541
+ sqlite3OsClose(pPager->jfd);
37542
+ }
3752837543
*pExists = (first!=0);
3752937544
}else if( rc==SQLITE_CANTOPEN ){
3753037545
/* If we cannot open the rollback journal file in order to see if
3753137546
** its has a zero header, that might be due to an I/O error, or
3753237547
** it might be due to the race condition described above and in
@@ -39437,21 +39452,49 @@
3943739452
3943839453
/* Change the journal mode. */
3943939454
pPager->journalMode = (u8)eMode;
3944039455
3944139456
/* When transistioning from TRUNCATE or PERSIST to any other journal
39442
- ** mode (and we are not in locking_mode=EXCLUSIVE) then delete the
39443
- ** journal file.
39457
+ ** mode except WAL (and we are not in locking_mode=EXCLUSIVE) then
39458
+ ** delete the journal file.
3944439459
*/
3944539460
assert( (PAGER_JOURNALMODE_TRUNCATE & 5)==1 );
3944639461
assert( (PAGER_JOURNALMODE_PERSIST & 5)==1 );
39447
- assert( (PAGER_JOURNALMODE_DELETE & 5)!=1 );
39448
- assert( (PAGER_JOURNALMODE_MEMORY & 5)!=1 );
39449
- assert( (PAGER_JOURNALMODE_OFF & 5)!=1 );
39450
- assert( (PAGER_JOURNALMODE_WAL & 5)!=1 );
39451
- if( (eOld & 5)==1 && (eMode & 5)!=1 && !pPager->exclusiveMode ){
39452
- sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0);
39462
+ assert( (PAGER_JOURNALMODE_DELETE & 5)==0 );
39463
+ assert( (PAGER_JOURNALMODE_MEMORY & 5)==4 );
39464
+ assert( (PAGER_JOURNALMODE_OFF & 5)==0 );
39465
+ assert( (PAGER_JOURNALMODE_WAL & 5)==5 );
39466
+
39467
+ assert( isOpen(pPager->fd) || pPager->exclusiveMode );
39468
+ if( !pPager->exclusiveMode && (eOld & 5)==1 && (eMode & 1)==0 ){
39469
+
39470
+ /* In this case we would like to delete the journal file. If it is
39471
+ ** not possible, then that is not a problem. Deleting the journal file
39472
+ ** here is an optimization only.
39473
+ **
39474
+ ** Before deleting the journal file, obtain a RESERVED lock on the
39475
+ ** database file. This ensures that the journal file is not deleted
39476
+ ** while it is in use by some other client.
39477
+ */
39478
+ int rc = SQLITE_OK;
39479
+ int state = pPager->state;
39480
+ if( state<PAGER_SHARED ){
39481
+ rc = sqlite3PagerSharedLock(pPager);
39482
+ }
39483
+ if( pPager->state==PAGER_SHARED ){
39484
+ assert( rc==SQLITE_OK );
39485
+ rc = sqlite3OsLock(pPager->fd, RESERVED_LOCK);
39486
+ }
39487
+ if( rc==SQLITE_OK ){
39488
+ sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0);
39489
+ }
39490
+ if( rc==SQLITE_OK && state==PAGER_SHARED ){
39491
+ sqlite3OsUnlock(pPager->fd, SHARED_LOCK);
39492
+ }else if( state==PAGER_UNLOCK ){
39493
+ pager_unlock(pPager);
39494
+ }
39495
+ assert( state==pPager->state );
3945339496
}
3945439497
}
3945539498
3945639499
/* Return the new journal mode */
3945739500
return (int)pPager->journalMode;
@@ -63307,36 +63350,30 @@
6330763350
** after a successful return.
6330863351
*/
6330963352
rc = sqlite3PagerCloseWal(u.cd.pPager);
6331063353
if( rc==SQLITE_OK ){
6331163354
sqlite3PagerSetJournalMode(u.cd.pPager, u.cd.eNew);
63312
- }else if( rc==SQLITE_BUSY && pOp->p5==0 ){
63313
- goto abort_due_to_error;
6331463355
}
63315
- }else{
63316
- sqlite3PagerSetJournalMode(u.cd.pPager, PAGER_JOURNALMODE_DELETE);
63317
- rc = SQLITE_OK;
6331863356
}
6331963357
6332063358
/* Open a transaction on the database file. Regardless of the journal
6332163359
** mode, this transaction always uses a rollback journal.
6332263360
*/
6332363361
assert( sqlite3BtreeIsInTrans(u.cd.pBt)==0 );
6332463362
if( rc==SQLITE_OK ){
63325
- rc = sqlite3BtreeSetVersion(u.cd.pBt,
63326
- (u.cd.eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
63327
- if( rc==SQLITE_BUSY && pOp->p5==0 ) goto abort_due_to_error;
63328
- }
63329
- if( rc==SQLITE_BUSY ){
63330
- u.cd.eNew = u.cd.eOld;
63331
- rc = SQLITE_OK;
63363
+ rc = sqlite3BtreeSetVersion(u.cd.pBt, (u.cd.eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
6333263364
}
6333363365
}
6333463366
}
6333563367
#endif /* ifndef SQLITE_OMIT_WAL */
6333663368
63369
+ if( rc ){
63370
+ if( rc==SQLITE_BUSY && pOp->p5!=0 ) rc = SQLITE_OK;
63371
+ u.cd.eNew = u.cd.eOld;
63372
+ }
6333763373
u.cd.eNew = sqlite3PagerSetJournalMode(u.cd.pPager, u.cd.eNew);
63374
+
6333863375
pOut = &aMem[pOp->p2];
6333963376
pOut->flags = MEM_Str|MEM_Static|MEM_Term;
6334063377
pOut->z = (char *)sqlite3JournalModename(u.cd.eNew);
6334163378
pOut->n = sqlite3Strlen30(pOut->z);
6334263379
pOut->enc = SQLITE_UTF8;
@@ -64146,14 +64183,18 @@
6414664183
6414764184
/* Make sure a mutex is held on the table to be accessed */
6414864185
sqlite3VdbeUsesBtree(v, iDb);
6414964186
6415064187
/* Configure the OP_TableLock instruction */
64188
+#ifdef SQLITE_OMIT_SHARED_CACHE
64189
+ sqlite3VdbeChangeToNoop(v, 2, 1);
64190
+#else
6415164191
sqlite3VdbeChangeP1(v, 2, iDb);
6415264192
sqlite3VdbeChangeP2(v, 2, pTab->tnum);
6415364193
sqlite3VdbeChangeP3(v, 2, flags);
6415464194
sqlite3VdbeChangeP4(v, 2, pTab->zName, P4_TRANSIENT);
64195
+#endif
6415564196
6415664197
/* Remove either the OP_OpenWrite or OpenRead. Set the P2
6415764198
** parameter of the other to pTab->tnum. */
6415864199
sqlite3VdbeChangeToNoop(v, 4 - flags, 1);
6415964200
sqlite3VdbeChangeP2(v, 3 + flags, pTab->tnum);
6416064201
--- 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-16 12:30:11 ad3209572d0e6afe5c8b52313e334509661045e2"
642
643 /*
644 ** CAPI3REF: Run-Time Library Version Numbers
645 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
646 **
@@ -1029,21 +1029,22 @@
1029 ** first then the size of the file is extended, never the other
1030 ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
1031 ** information is written to disk in the same order as calls
1032 ** to xWrite().
1033 */
1034 #define SQLITE_IOCAP_ATOMIC 0x00000001
1035 #define SQLITE_IOCAP_ATOMIC512 0x00000002
1036 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
1037 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
1038 #define SQLITE_IOCAP_ATOMIC4K 0x00000010
1039 #define SQLITE_IOCAP_ATOMIC8K 0x00000020
1040 #define SQLITE_IOCAP_ATOMIC16K 0x00000040
1041 #define SQLITE_IOCAP_ATOMIC32K 0x00000080
1042 #define SQLITE_IOCAP_ATOMIC64K 0x00000100
1043 #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
1044 #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
 
1045
1046 /*
1047 ** CAPI3REF: File Locking Levels
1048 **
1049 ** SQLite uses one of these integer values as the second
@@ -25680,23 +25681,25 @@
25680 p->pInode->pShmNode = 0;
25681 sqlite3_free(p);
25682 }
25683 }
25684
25685 /* Forward reference */
25686 static const char *unixTempFileDir(int);
25687
25688 /*
25689 ** Open a shared-memory area. This particular implementation uses
25690 ** mmapped files.
25691 **
25692 ** zName is a filename used to identify the shared-memory area. The
25693 ** implementation does not (and perhaps should not) use this name
25694 ** directly, but rather use it as a template for finding an appropriate
25695 ** name for the shared-memory storage. In this implementation, the
25696 ** string "-index" is appended to zName and used as the name of the
25697 ** mmapped file.
 
 
 
 
 
25698 **
25699 ** When opening a new shared-memory file, if no other instances of that
25700 ** file are currently open, in this process or in other processes, then
25701 ** the file must be truncated to zero length or have its header cleared.
25702 */
@@ -25706,12 +25709,12 @@
25706 struct unixShm *p = 0; /* The connection to be opened */
25707 struct unixShmNode *pShmNode = 0; /* The underlying mmapped file */
25708 int rc; /* Result code */
25709 struct unixFile *pDbFd; /* Underlying database file */
25710 unixInodeInfo *pInode; /* The inode of fd */
25711 const char *zTempDir; /* Directory for temporary files */
25712 int nTempDir; /* Size of the zTempDir string */
25713
25714 /* Allocate space for the new sqlite3_shm object.
25715 */
25716 p = sqlite3_malloc( sizeof(*p) );
25717 if( p==0 ) return SQLITE_NOMEM;
@@ -25724,37 +25727,29 @@
25724 */
25725 unixEnterMutex();
25726 pInode = pDbFd->pInode;
25727 pShmNode = pInode->pShmNode;
25728 if( pShmNode==0 ){
25729 zTempDir = unixTempFileDir(1);
25730 if( zTempDir==0 ){
25731 unixLeaveMutex();
25732 sqlite3_free(p);
25733 return SQLITE_CANTOPEN_NOTEMPDIR;
25734 }
25735 nTempDir = strlen(zTempDir);
25736 pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nTempDir + 50 );
25737 if( pShmNode==0 ){
25738 rc = SQLITE_NOMEM;
25739 goto shm_open_err;
25740 }
25741 memset(pShmNode, 0, sizeof(*pShmNode));
25742 pShmNode->zFilename = (char*)&pShmNode[1];
25743 sqlite3_snprintf(nTempDir+50, pShmNode->zFilename,
25744 "%s/sqlite-wi-%x-%x", zTempDir,
25745 (u32)pInode->fileId.dev, (u32)pInode->fileId.ino);
25746 pShmNode->h = -1;
25747 pDbFd->pInode->pShmNode = pShmNode;
25748 pShmNode->pInode = pDbFd->pInode;
25749 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
25750 if( pShmNode->mutex==0 ){
25751 rc = SQLITE_NOMEM;
25752 goto shm_open_err;
25753 }
25754
25755 pShmNode->h = open(pShmNode->zFilename, O_RDWR|O_CREAT, 0664);
25756 if( pShmNode->h<0 ){
25757 rc = SQLITE_CANTOPEN_BKPT;
25758 goto shm_open_err;
25759 }
25760
@@ -26563,11 +26558,11 @@
26563
26564 /*
26565 ** Return the name of a directory in which to put temporary files.
26566 ** If no suitable temporary file directory can be found, return NULL.
26567 */
26568 static const char *unixTempFileDir(int allowShm){
26569 static const char *azDirs[] = {
26570 0,
26571 0,
26572 "/var/tmp",
26573 "/usr/tmp",
@@ -26578,23 +26573,15 @@
26578 struct stat buf;
26579 const char *zDir = 0;
26580
26581 azDirs[0] = sqlite3_temp_directory;
26582 if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
26583
26584 if( allowShm ){
26585 zDir = "/dev/shm";
26586 i = 2; /* Skip the app-defined temp locations for shared-memory */
26587 }else{
26588 zDir = azDirs[0];
26589 i = 1;
26590 }
26591 for(; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
26592 if( zDir==0 ) continue;
26593 if( stat(zDir, &buf) ) continue;
26594 if( !S_ISDIR(buf.st_mode) ) continue;
26595 if( !allowShm && access(zDir, 07) ) continue;
26596 break;
26597 }
26598 return zDir;
26599 }
26600
@@ -26615,11 +26602,11 @@
26615 ** using the io-error infrastructure to test that SQLite handles this
26616 ** function failing.
26617 */
26618 SimulateIOError( return SQLITE_IOERR );
26619
26620 zDir = unixTempFileDir(0);
26621 if( zDir==0 ) zDir = ".";
26622
26623 /* Check that the output buffer is large enough for the temporary file
26624 ** name. If it is not, return SQLITE_ERROR.
26625 */
@@ -27024,10 +27011,16 @@
27024
27025 default:
27026 assert(!"Invalid flags argument");
27027 }
27028 *pResOut = (access(zPath, amode)==0);
 
 
 
 
 
 
27029 return SQLITE_OK;
27030 }
27031
27032
27033 /*
@@ -29906,11 +29899,11 @@
29906 /*
29907 ** Return a vector of device characteristics.
29908 */
29909 static int winDeviceCharacteristics(sqlite3_file *id){
29910 UNUSED_PARAMETER(id);
29911 return 0;
29912 }
29913
29914 /****************************************************************************
29915 ********************************* Shared Memory *****************************
29916 **
@@ -34777,16 +34770,28 @@
34777 ** treated as a hot-journal and rolled back.
34778 */
34779 static void pager_unlock(Pager *pPager){
34780 if( !pPager->exclusiveMode ){
34781 int rc = SQLITE_OK; /* Return code */
 
34782
34783 /* Always close the journal file when dropping the database lock.
34784 ** Otherwise, another connection with journal_mode=delete might
34785 ** delete the file out from under us.
34786 */
34787 sqlite3OsClose(pPager->jfd);
 
 
 
 
 
 
 
 
 
 
 
34788 sqlite3BitvecDestroy(pPager->pInJournal);
34789 pPager->pInJournal = 0;
34790 releaseAllSavepoints(pPager);
34791
34792 /* If the file is unlocked, somebody else might change it. The
@@ -36673,10 +36678,11 @@
36673 }
36674 sqlite3EndBenignMalloc();
36675 enable_simulated_io_errors();
36676 PAGERTRACE(("CLOSE %d\n", PAGERID(pPager)));
36677 IOTRACE(("CLOSE %p\n", pPager))
 
36678 sqlite3OsClose(pPager->fd);
36679 sqlite3PageFree(pTmp);
36680 sqlite3PcacheClose(pPager->pPCache);
36681
36682 #ifdef SQLITE_HAS_CODEC
@@ -37466,21 +37472,26 @@
37466 ** to determine whether or not a hot-journal file exists, the IO error
37467 ** code is returned and the value of *pExists is undefined.
37468 */
37469 static int hasHotJournal(Pager *pPager, int *pExists){
37470 sqlite3_vfs * const pVfs = pPager->pVfs;
37471 int rc; /* Return code */
37472 int exists; /* True if a journal file is present */
 
37473
37474 assert( pPager!=0 );
37475 assert( pPager->useJournal );
37476 assert( isOpen(pPager->fd) );
37477 assert( !isOpen(pPager->jfd) );
37478 assert( pPager->state <= PAGER_SHARED );
 
 
 
37479
37480 *pExists = 0;
37481 rc = sqlite3OsAccess(pVfs, pPager->zJournal, SQLITE_ACCESS_EXISTS, &exists);
 
 
37482 if( rc==SQLITE_OK && exists ){
37483 int locked; /* True if some process holds a RESERVED lock */
37484
37485 /* Race condition here: Another process might have been holding the
37486 ** the RESERVED lock and have a journal open at the sqlite3OsAccess()
@@ -37514,19 +37525,23 @@
37514 ** or greater lock on the database file. Now check that there is
37515 ** at least one non-zero bytes at the start of the journal file.
37516 ** If there is, then we consider this journal to be hot. If not,
37517 ** it can be ignored.
37518 */
37519 int f = SQLITE_OPEN_READONLY|SQLITE_OPEN_MAIN_JOURNAL;
37520 rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, f, &f);
 
 
37521 if( rc==SQLITE_OK ){
37522 u8 first = 0;
37523 rc = sqlite3OsRead(pPager->jfd, (void *)&first, 1, 0);
37524 if( rc==SQLITE_IOERR_SHORT_READ ){
37525 rc = SQLITE_OK;
37526 }
37527 sqlite3OsClose(pPager->jfd);
 
 
37528 *pExists = (first!=0);
37529 }else if( rc==SQLITE_CANTOPEN ){
37530 /* If we cannot open the rollback journal file in order to see if
37531 ** its has a zero header, that might be due to an I/O error, or
37532 ** it might be due to the race condition described above and in
@@ -39437,21 +39452,49 @@
39437
39438 /* Change the journal mode. */
39439 pPager->journalMode = (u8)eMode;
39440
39441 /* When transistioning from TRUNCATE or PERSIST to any other journal
39442 ** mode (and we are not in locking_mode=EXCLUSIVE) then delete the
39443 ** journal file.
39444 */
39445 assert( (PAGER_JOURNALMODE_TRUNCATE & 5)==1 );
39446 assert( (PAGER_JOURNALMODE_PERSIST & 5)==1 );
39447 assert( (PAGER_JOURNALMODE_DELETE & 5)!=1 );
39448 assert( (PAGER_JOURNALMODE_MEMORY & 5)!=1 );
39449 assert( (PAGER_JOURNALMODE_OFF & 5)!=1 );
39450 assert( (PAGER_JOURNALMODE_WAL & 5)!=1 );
39451 if( (eOld & 5)==1 && (eMode & 5)!=1 && !pPager->exclusiveMode ){
39452 sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39453 }
39454 }
39455
39456 /* Return the new journal mode */
39457 return (int)pPager->journalMode;
@@ -63307,36 +63350,30 @@
63307 ** after a successful return.
63308 */
63309 rc = sqlite3PagerCloseWal(u.cd.pPager);
63310 if( rc==SQLITE_OK ){
63311 sqlite3PagerSetJournalMode(u.cd.pPager, u.cd.eNew);
63312 }else if( rc==SQLITE_BUSY && pOp->p5==0 ){
63313 goto abort_due_to_error;
63314 }
63315 }else{
63316 sqlite3PagerSetJournalMode(u.cd.pPager, PAGER_JOURNALMODE_DELETE);
63317 rc = SQLITE_OK;
63318 }
63319
63320 /* Open a transaction on the database file. Regardless of the journal
63321 ** mode, this transaction always uses a rollback journal.
63322 */
63323 assert( sqlite3BtreeIsInTrans(u.cd.pBt)==0 );
63324 if( rc==SQLITE_OK ){
63325 rc = sqlite3BtreeSetVersion(u.cd.pBt,
63326 (u.cd.eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
63327 if( rc==SQLITE_BUSY && pOp->p5==0 ) goto abort_due_to_error;
63328 }
63329 if( rc==SQLITE_BUSY ){
63330 u.cd.eNew = u.cd.eOld;
63331 rc = SQLITE_OK;
63332 }
63333 }
63334 }
63335 #endif /* ifndef SQLITE_OMIT_WAL */
63336
 
 
 
 
63337 u.cd.eNew = sqlite3PagerSetJournalMode(u.cd.pPager, u.cd.eNew);
 
63338 pOut = &aMem[pOp->p2];
63339 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
63340 pOut->z = (char *)sqlite3JournalModename(u.cd.eNew);
63341 pOut->n = sqlite3Strlen30(pOut->z);
63342 pOut->enc = SQLITE_UTF8;
@@ -64146,14 +64183,18 @@
64146
64147 /* Make sure a mutex is held on the table to be accessed */
64148 sqlite3VdbeUsesBtree(v, iDb);
64149
64150 /* Configure the OP_TableLock instruction */
 
 
 
64151 sqlite3VdbeChangeP1(v, 2, iDb);
64152 sqlite3VdbeChangeP2(v, 2, pTab->tnum);
64153 sqlite3VdbeChangeP3(v, 2, flags);
64154 sqlite3VdbeChangeP4(v, 2, pTab->zName, P4_TRANSIENT);
 
64155
64156 /* Remove either the OP_OpenWrite or OpenRead. Set the P2
64157 ** parameter of the other to pTab->tnum. */
64158 sqlite3VdbeChangeToNoop(v, 4 - flags, 1);
64159 sqlite3VdbeChangeP2(v, 3 + flags, pTab->tnum);
64160
--- 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 **
@@ -1029,21 +1029,22 @@
1029 ** first then the size of the file is extended, never the other
1030 ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
1031 ** information is written to disk in the same order as calls
1032 ** to xWrite().
1033 */
1034 #define SQLITE_IOCAP_ATOMIC 0x00000001
1035 #define SQLITE_IOCAP_ATOMIC512 0x00000002
1036 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
1037 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
1038 #define SQLITE_IOCAP_ATOMIC4K 0x00000010
1039 #define SQLITE_IOCAP_ATOMIC8K 0x00000020
1040 #define SQLITE_IOCAP_ATOMIC16K 0x00000040
1041 #define SQLITE_IOCAP_ATOMIC32K 0x00000080
1042 #define SQLITE_IOCAP_ATOMIC64K 0x00000100
1043 #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
1044 #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
1045 #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800
1046
1047 /*
1048 ** CAPI3REF: File Locking Levels
1049 **
1050 ** SQLite uses one of these integer values as the second
@@ -25680,23 +25681,25 @@
25681 p->pInode->pShmNode = 0;
25682 sqlite3_free(p);
25683 }
25684 }
25685
 
 
 
25686 /*
25687 ** Open a shared-memory area associated with open database file fd.
25688 ** This particular implementation uses mmapped files.
25689 **
25690 ** The file used to implement shared-memory is in the same directory
25691 ** as the open database file and has the same name as the open database
25692 ** file with the "-shm" suffix added. For example, if the database file
25693 ** is "/home/user1/config.db" then the file that is created and mmapped
25694 ** for shared memory will be called "/home/user1/config.db-shm". We
25695 ** experimented with using files in /dev/tmp or an some other tmpfs mount.
25696 ** But if a file in a different directory from the database file is used,
25697 ** then differing access permissions or a chroot() might cause two different
25698 ** processes on the same database to end up using different files for
25699 ** shared memory - meaning that their memory would not really be shared -
25700 ** resulting in database corruption.
25701 **
25702 ** When opening a new shared-memory file, if no other instances of that
25703 ** file are currently open, in this process or in other processes, then
25704 ** the file must be truncated to zero length or have its header cleared.
25705 */
@@ -25706,12 +25709,12 @@
25709 struct unixShm *p = 0; /* The connection to be opened */
25710 struct unixShmNode *pShmNode = 0; /* The underlying mmapped file */
25711 int rc; /* Result code */
25712 struct unixFile *pDbFd; /* Underlying database file */
25713 unixInodeInfo *pInode; /* The inode of fd */
25714 char *zShmFilename; /* Name of the file used for SHM */
25715 int nShmFilename; /* Size of the SHM filename in bytes */
25716
25717 /* Allocate space for the new sqlite3_shm object.
25718 */
25719 p = sqlite3_malloc( sizeof(*p) );
25720 if( p==0 ) return SQLITE_NOMEM;
@@ -25724,37 +25727,29 @@
25727 */
25728 unixEnterMutex();
25729 pInode = pDbFd->pInode;
25730 pShmNode = pInode->pShmNode;
25731 if( pShmNode==0 ){
25732 nShmFilename = 5 + (int)strlen(pDbFd->zPath);
25733 pShmNode = sqlite3_malloc( sizeof(*pShmNode) + nShmFilename );
 
 
 
 
 
 
25734 if( pShmNode==0 ){
25735 rc = SQLITE_NOMEM;
25736 goto shm_open_err;
25737 }
25738 memset(pShmNode, 0, sizeof(*pShmNode));
25739 zShmFilename = pShmNode->zFilename = (char*)&pShmNode[1];
25740 sqlite3_snprintf(nShmFilename, zShmFilename, "%s-shm", pDbFd->zPath);
 
 
25741 pShmNode->h = -1;
25742 pDbFd->pInode->pShmNode = pShmNode;
25743 pShmNode->pInode = pDbFd->pInode;
25744 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
25745 if( pShmNode->mutex==0 ){
25746 rc = SQLITE_NOMEM;
25747 goto shm_open_err;
25748 }
25749
25750 pShmNode->h = open(zShmFilename, O_RDWR|O_CREAT, 0664);
25751 if( pShmNode->h<0 ){
25752 rc = SQLITE_CANTOPEN_BKPT;
25753 goto shm_open_err;
25754 }
25755
@@ -26563,11 +26558,11 @@
26558
26559 /*
26560 ** Return the name of a directory in which to put temporary files.
26561 ** If no suitable temporary file directory can be found, return NULL.
26562 */
26563 static const char *unixTempFileDir(void){
26564 static const char *azDirs[] = {
26565 0,
26566 0,
26567 "/var/tmp",
26568 "/usr/tmp",
@@ -26578,23 +26573,15 @@
26573 struct stat buf;
26574 const char *zDir = 0;
26575
26576 azDirs[0] = sqlite3_temp_directory;
26577 if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
26578 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
 
 
 
 
 
 
 
 
26579 if( zDir==0 ) continue;
26580 if( stat(zDir, &buf) ) continue;
26581 if( !S_ISDIR(buf.st_mode) ) continue;
26582 if( access(zDir, 07) ) continue;
26583 break;
26584 }
26585 return zDir;
26586 }
26587
@@ -26615,11 +26602,11 @@
26602 ** using the io-error infrastructure to test that SQLite handles this
26603 ** function failing.
26604 */
26605 SimulateIOError( return SQLITE_IOERR );
26606
26607 zDir = unixTempFileDir();
26608 if( zDir==0 ) zDir = ".";
26609
26610 /* Check that the output buffer is large enough for the temporary file
26611 ** name. If it is not, return SQLITE_ERROR.
26612 */
@@ -27024,10 +27011,16 @@
27011
27012 default:
27013 assert(!"Invalid flags argument");
27014 }
27015 *pResOut = (access(zPath, amode)==0);
27016 if( flags==SQLITE_ACCESS_EXISTS && *pResOut ){
27017 struct stat buf;
27018 if( 0==stat(zPath, &buf) && buf.st_size==0 ){
27019 *pResOut = 0;
27020 }
27021 }
27022 return SQLITE_OK;
27023 }
27024
27025
27026 /*
@@ -29906,11 +29899,11 @@
29899 /*
29900 ** Return a vector of device characteristics.
29901 */
29902 static int winDeviceCharacteristics(sqlite3_file *id){
29903 UNUSED_PARAMETER(id);
29904 return SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN;
29905 }
29906
29907 /****************************************************************************
29908 ********************************* Shared Memory *****************************
29909 **
@@ -34777,16 +34770,28 @@
34770 ** treated as a hot-journal and rolled back.
34771 */
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 );
34785 assert( (PAGER_JOURNALMODE_TRUNCATE & 5)==1 );
34786 assert( (PAGER_JOURNALMODE_PERSIST & 5)==1 );
34787 if( 0==(iDc & SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN)
34788 || 1!=(pPager->journalMode & 5)
34789 ){
34790 sqlite3OsClose(pPager->jfd);
34791 }
34792
34793 sqlite3BitvecDestroy(pPager->pInJournal);
34794 pPager->pInJournal = 0;
34795 releaseAllSavepoints(pPager);
34796
34797 /* If the file is unlocked, somebody else might change it. The
@@ -36673,10 +36678,11 @@
36678 }
36679 sqlite3EndBenignMalloc();
36680 enable_simulated_io_errors();
36681 PAGERTRACE(("CLOSE %d\n", PAGERID(pPager)));
36682 IOTRACE(("CLOSE %p\n", pPager))
36683 sqlite3OsClose(pPager->jfd);
36684 sqlite3OsClose(pPager->fd);
36685 sqlite3PageFree(pTmp);
36686 sqlite3PcacheClose(pPager->pPCache);
36687
36688 #ifdef SQLITE_HAS_CODEC
@@ -37466,21 +37472,26 @@
37472 ** to determine whether or not a hot-journal file exists, the IO error
37473 ** code is returned and the value of *pExists is undefined.
37474 */
37475 static int hasHotJournal(Pager *pPager, int *pExists){
37476 sqlite3_vfs * const pVfs = pPager->pVfs;
37477 int rc = SQLITE_OK; /* Return code */
37478 int exists = 1; /* True if a journal file is present */
37479 int jrnlOpen = !!isOpen(pPager->jfd);
37480
37481 assert( pPager!=0 );
37482 assert( pPager->useJournal );
37483 assert( isOpen(pPager->fd) );
 
37484 assert( pPager->state <= PAGER_SHARED );
37485 assert( jrnlOpen==0 || ( sqlite3OsDeviceCharacteristics(pPager->jfd) &
37486 SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
37487 ));
37488
37489 *pExists = 0;
37490 if( !jrnlOpen ){
37491 rc = sqlite3OsAccess(pVfs, pPager->zJournal, SQLITE_ACCESS_EXISTS, &exists);
37492 }
37493 if( rc==SQLITE_OK && exists ){
37494 int locked; /* True if some process holds a RESERVED lock */
37495
37496 /* Race condition here: Another process might have been holding the
37497 ** the RESERVED lock and have a journal open at the sqlite3OsAccess()
@@ -37514,19 +37525,23 @@
37525 ** or greater lock on the database file. Now check that there is
37526 ** at least one non-zero bytes at the start of the journal file.
37527 ** If there is, then we consider this journal to be hot. If not,
37528 ** it can be ignored.
37529 */
37530 if( !jrnlOpen ){
37531 int f = SQLITE_OPEN_READONLY|SQLITE_OPEN_MAIN_JOURNAL;
37532 rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, f, &f);
37533 }
37534 if( rc==SQLITE_OK ){
37535 u8 first = 0;
37536 rc = sqlite3OsRead(pPager->jfd, (void *)&first, 1, 0);
37537 if( rc==SQLITE_IOERR_SHORT_READ ){
37538 rc = SQLITE_OK;
37539 }
37540 if( !jrnlOpen ){
37541 sqlite3OsClose(pPager->jfd);
37542 }
37543 *pExists = (first!=0);
37544 }else if( rc==SQLITE_CANTOPEN ){
37545 /* If we cannot open the rollback journal file in order to see if
37546 ** its has a zero header, that might be due to an I/O error, or
37547 ** it might be due to the race condition described above and in
@@ -39437,21 +39452,49 @@
39452
39453 /* Change the journal mode. */
39454 pPager->journalMode = (u8)eMode;
39455
39456 /* When transistioning from TRUNCATE or PERSIST to any other journal
39457 ** mode except WAL (and we are not in locking_mode=EXCLUSIVE) then
39458 ** delete the journal file.
39459 */
39460 assert( (PAGER_JOURNALMODE_TRUNCATE & 5)==1 );
39461 assert( (PAGER_JOURNALMODE_PERSIST & 5)==1 );
39462 assert( (PAGER_JOURNALMODE_DELETE & 5)==0 );
39463 assert( (PAGER_JOURNALMODE_MEMORY & 5)==4 );
39464 assert( (PAGER_JOURNALMODE_OFF & 5)==0 );
39465 assert( (PAGER_JOURNALMODE_WAL & 5)==5 );
39466
39467 assert( isOpen(pPager->fd) || pPager->exclusiveMode );
39468 if( !pPager->exclusiveMode && (eOld & 5)==1 && (eMode & 1)==0 ){
39469
39470 /* In this case we would like to delete the journal file. If it is
39471 ** not possible, then that is not a problem. Deleting the journal file
39472 ** here is an optimization only.
39473 **
39474 ** Before deleting the journal file, obtain a RESERVED lock on the
39475 ** database file. This ensures that the journal file is not deleted
39476 ** while it is in use by some other client.
39477 */
39478 int rc = SQLITE_OK;
39479 int state = pPager->state;
39480 if( state<PAGER_SHARED ){
39481 rc = sqlite3PagerSharedLock(pPager);
39482 }
39483 if( pPager->state==PAGER_SHARED ){
39484 assert( rc==SQLITE_OK );
39485 rc = sqlite3OsLock(pPager->fd, RESERVED_LOCK);
39486 }
39487 if( rc==SQLITE_OK ){
39488 sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0);
39489 }
39490 if( rc==SQLITE_OK && state==PAGER_SHARED ){
39491 sqlite3OsUnlock(pPager->fd, SHARED_LOCK);
39492 }else if( state==PAGER_UNLOCK ){
39493 pager_unlock(pPager);
39494 }
39495 assert( state==pPager->state );
39496 }
39497 }
39498
39499 /* Return the new journal mode */
39500 return (int)pPager->journalMode;
@@ -63307,36 +63350,30 @@
63350 ** after a successful return.
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 assert( sqlite3BtreeIsInTrans(u.cd.pBt)==0 );
63362 if( rc==SQLITE_OK ){
63363 rc = sqlite3BtreeSetVersion(u.cd.pBt, (u.cd.eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
 
 
 
 
 
 
63364 }
63365 }
63366 }
63367 #endif /* ifndef SQLITE_OMIT_WAL */
63368
63369 if( rc ){
63370 if( rc==SQLITE_BUSY && pOp->p5!=0 ) rc = SQLITE_OK;
63371 u.cd.eNew = u.cd.eOld;
63372 }
63373 u.cd.eNew = sqlite3PagerSetJournalMode(u.cd.pPager, u.cd.eNew);
63374
63375 pOut = &aMem[pOp->p2];
63376 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
63377 pOut->z = (char *)sqlite3JournalModename(u.cd.eNew);
63378 pOut->n = sqlite3Strlen30(pOut->z);
63379 pOut->enc = SQLITE_UTF8;
@@ -64146,14 +64183,18 @@
64183
64184 /* Make sure a mutex is held on the table to be accessed */
64185 sqlite3VdbeUsesBtree(v, iDb);
64186
64187 /* Configure the OP_TableLock instruction */
64188 #ifdef SQLITE_OMIT_SHARED_CACHE
64189 sqlite3VdbeChangeToNoop(v, 2, 1);
64190 #else
64191 sqlite3VdbeChangeP1(v, 2, iDb);
64192 sqlite3VdbeChangeP2(v, 2, pTab->tnum);
64193 sqlite3VdbeChangeP3(v, 2, flags);
64194 sqlite3VdbeChangeP4(v, 2, pTab->zName, P4_TRANSIENT);
64195 #endif
64196
64197 /* Remove either the OP_OpenWrite or OpenRead. Set the P2
64198 ** parameter of the other to pTab->tnum. */
64199 sqlite3VdbeChangeToNoop(v, 4 - flags, 1);
64200 sqlite3VdbeChangeP2(v, 3 + flags, pTab->tnum);
64201
+13 -12
--- 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-16 12:30:11 ad3209572d0e6afe5c8b52313e334509661045e2"
112
+#define SQLITE_SOURCE_ID "2010-06-21 12:47:41 ee0acef1faffd480fd2136f81fb2b6f6a17b5388"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -500,21 +500,22 @@
500500
** first then the size of the file is extended, never the other
501501
** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
502502
** information is written to disk in the same order as calls
503503
** to xWrite().
504504
*/
505
-#define SQLITE_IOCAP_ATOMIC 0x00000001
506
-#define SQLITE_IOCAP_ATOMIC512 0x00000002
507
-#define SQLITE_IOCAP_ATOMIC1K 0x00000004
508
-#define SQLITE_IOCAP_ATOMIC2K 0x00000008
509
-#define SQLITE_IOCAP_ATOMIC4K 0x00000010
510
-#define SQLITE_IOCAP_ATOMIC8K 0x00000020
511
-#define SQLITE_IOCAP_ATOMIC16K 0x00000040
512
-#define SQLITE_IOCAP_ATOMIC32K 0x00000080
513
-#define SQLITE_IOCAP_ATOMIC64K 0x00000100
514
-#define SQLITE_IOCAP_SAFE_APPEND 0x00000200
515
-#define SQLITE_IOCAP_SEQUENTIAL 0x00000400
505
+#define SQLITE_IOCAP_ATOMIC 0x00000001
506
+#define SQLITE_IOCAP_ATOMIC512 0x00000002
507
+#define SQLITE_IOCAP_ATOMIC1K 0x00000004
508
+#define SQLITE_IOCAP_ATOMIC2K 0x00000008
509
+#define SQLITE_IOCAP_ATOMIC4K 0x00000010
510
+#define SQLITE_IOCAP_ATOMIC8K 0x00000020
511
+#define SQLITE_IOCAP_ATOMIC16K 0x00000040
512
+#define SQLITE_IOCAP_ATOMIC32K 0x00000080
513
+#define SQLITE_IOCAP_ATOMIC64K 0x00000100
514
+#define SQLITE_IOCAP_SAFE_APPEND 0x00000200
515
+#define SQLITE_IOCAP_SEQUENTIAL 0x00000400
516
+#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800
516517
517518
/*
518519
** CAPI3REF: File Locking Levels
519520
**
520521
** SQLite uses one of these integer values as the second
521522
--- 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-16 12:30:11 ad3209572d0e6afe5c8b52313e334509661045e2"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -500,21 +500,22 @@
500 ** first then the size of the file is extended, never the other
501 ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
502 ** information is written to disk in the same order as calls
503 ** to xWrite().
504 */
505 #define SQLITE_IOCAP_ATOMIC 0x00000001
506 #define SQLITE_IOCAP_ATOMIC512 0x00000002
507 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
508 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
509 #define SQLITE_IOCAP_ATOMIC4K 0x00000010
510 #define SQLITE_IOCAP_ATOMIC8K 0x00000020
511 #define SQLITE_IOCAP_ATOMIC16K 0x00000040
512 #define SQLITE_IOCAP_ATOMIC32K 0x00000080
513 #define SQLITE_IOCAP_ATOMIC64K 0x00000100
514 #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
515 #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
 
516
517 /*
518 ** CAPI3REF: File Locking Levels
519 **
520 ** SQLite uses one of these integer values as the second
521
--- 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 **
@@ -500,21 +500,22 @@
500 ** first then the size of the file is extended, never the other
501 ** way around. The SQLITE_IOCAP_SEQUENTIAL property means that
502 ** information is written to disk in the same order as calls
503 ** to xWrite().
504 */
505 #define SQLITE_IOCAP_ATOMIC 0x00000001
506 #define SQLITE_IOCAP_ATOMIC512 0x00000002
507 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
508 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
509 #define SQLITE_IOCAP_ATOMIC4K 0x00000010
510 #define SQLITE_IOCAP_ATOMIC8K 0x00000020
511 #define SQLITE_IOCAP_ATOMIC16K 0x00000040
512 #define SQLITE_IOCAP_ATOMIC32K 0x00000080
513 #define SQLITE_IOCAP_ATOMIC64K 0x00000100
514 #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
515 #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
516 #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800
517
518 /*
519 ** CAPI3REF: File Locking Levels
520 **
521 ** SQLite uses one of these integer values as the second
522

Keyboard Shortcuts

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