Fossil SCM

Update the built-in SQLite to the latest beta of version 3.7.0.

drh 2010-07-06 20:51 trunk
Commit 8733f07f0ab39bf00ef8e17b87d1db37da367757
2 files changed +95 -89 +12 -6
+95 -89
--- 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-07-03 13:59:01 3b20ad03be55613d922d81aec5313327bf4098b9"
641
+#define SQLITE_SOURCE_ID "2010-07-06 20:37:10 5621862b0e2fc945ded51f5926a6b4c9f07d0ab7"
642642
643643
/*
644644
** CAPI3REF: Run-Time Library Version Numbers
645645
** KEYWORDS: sqlite3_version, sqlite3_sourceid
646646
**
@@ -1359,20 +1359,27 @@
13591359
** is also passed as a parameter to both methods. If the output buffer
13601360
** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
13611361
** handled as a fatal error by SQLite, vfs implementations should endeavor
13621362
** to prevent this by setting mxPathname to a sufficiently large value.
13631363
**
1364
-** The xRandomness(), xSleep(), and xCurrentTime() interfaces
1365
-** are not strictly a part of the filesystem, but they are
1364
+** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
1365
+** interfaces are not strictly a part of the filesystem, but they are
13661366
** included in the VFS structure for completeness.
13671367
** The xRandomness() function attempts to return nBytes bytes
13681368
** of good-quality randomness into zOut. The return value is
13691369
** the actual number of bytes of randomness obtained.
13701370
** The xSleep() method causes the calling thread to sleep for at
13711371
** least the number of microseconds given. The xCurrentTime()
1372
-** method returns a Julian Day Number for the current date and time.
1373
-**
1372
+** method returns a Julian Day Number for the current date and time as
1373
+** a floating point value.
1374
+** The xCurrentTimeInt64() method returns, as an integer, the Julian
1375
+** Day Number multipled by 86400000 (the number of milliseconds in
1376
+** a 24-hour day).
1377
+** ^SQLite will use the xCurrentTimeInt64() method to get the current
1378
+** date and time if that method is available (if iVersion is 2 or
1379
+** greater and the function pointer is not NULL) and will fall back
1380
+** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
13741381
*/
13751382
typedef struct sqlite3_vfs sqlite3_vfs;
13761383
struct sqlite3_vfs {
13771384
int iVersion; /* Structure version number (currently 2) */
13781385
int szOsFile; /* Size of subclassed sqlite3_file */
@@ -1395,11 +1402,10 @@
13951402
int (*xGetLastError)(sqlite3_vfs*, int, char *);
13961403
/*
13971404
** The methods above are in version 1 of the sqlite_vfs object
13981405
** definition. Those that follow are added in version 2 or later
13991406
*/
1400
- int (*xRename)(sqlite3_vfs*, const char *zOld, const char *zNew, int dirSync);
14011407
int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
14021408
/*
14031409
** The methods above are in versions 1 and 2 of the sqlite_vfs object.
14041410
** New fields may be appended in figure versions. The iVersion
14051411
** value will increment whenever this happens.
@@ -28503,11 +28509,10 @@
2850328509
unixDlClose, /* xDlClose */ \
2850428510
unixRandomness, /* xRandomness */ \
2850528511
unixSleep, /* xSleep */ \
2850628512
unixCurrentTime, /* xCurrentTime */ \
2850728513
unixGetLastError, /* xGetLastError */ \
28508
- 0, /* xRename */ \
2850928514
unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \
2851028515
}
2851128516
2851228517
/*
2851328518
** All default VFSes for unix are contained in the following array.
@@ -29497,11 +29502,15 @@
2949729502
SimulateDiskfullError(return SQLITE_FULL);
2949829503
OSTRACE(("WRITE %d lock=%d\n", pFile->h, pFile->locktype));
2949929504
rc = SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
2950029505
if( rc==INVALID_SET_FILE_POINTER && (error=GetLastError())!=NO_ERROR ){
2950129506
pFile->lastErrno = error;
29502
- return SQLITE_FULL;
29507
+ if( pFile->lastErrno==ERROR_HANDLE_DISK_FULL ){
29508
+ return SQLITE_FULL;
29509
+ }else{
29510
+ return SQLITE_IOERR_WRITE;
29511
+ }
2950329512
}
2950429513
assert( amt>0 );
2950529514
while(
2950629515
amt>0
2950729516
&& (rc = WriteFile(pFile->h, pBuf, amt, &wrote, 0))!=0
@@ -29510,11 +29519,15 @@
2951029519
amt -= wrote;
2951129520
pBuf = &((char*)pBuf)[wrote];
2951229521
}
2951329522
if( !rc || amt>(int)wrote ){
2951429523
pFile->lastErrno = GetLastError();
29515
- return SQLITE_FULL;
29524
+ if( pFile->lastErrno==ERROR_HANDLE_DISK_FULL ){
29525
+ return SQLITE_FULL;
29526
+ }else{
29527
+ return SQLITE_IOERR_WRITE;
29528
+ }
2951629529
}
2951729530
return SQLITE_OK;
2951829531
}
2951929532
2952029533
/*
@@ -30844,11 +30857,21 @@
3084430857
UNUSED_PARAMETER(pVfs);
3084530858
if( zConverted==0 ){
3084630859
return SQLITE_NOMEM;
3084730860
}
3084830861
if( isNT() ){
30849
- attr = GetFileAttributesW((WCHAR*)zConverted);
30862
+ WIN32_FILE_ATTRIBUTE_DATA sAttrData;
30863
+ memset(&sAttrData, 0, sizeof(sAttrData));
30864
+ attr = GetFileAttributesExW((WCHAR*)zConverted,
30865
+ GetFileExInfoStandard, &sAttrData);
30866
+ /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file
30867
+ ** as if it does not exist.
30868
+ */
30869
+ if( flags==SQLITE_ACCESS_EXISTS && attr!=INVALID_FILE_ATTRIBUTES
30870
+ && sAttrData.nFileSizeHigh==0 && sAttrData.nFileSizeLow==0 ){
30871
+ attr = INVALID_FILE_ATTRIBUTES;
30872
+ }
3085030873
/* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
3085130874
** Since the ASCII version of these Windows API do not exist for WINCE,
3085230875
** it's important to not reference them for WINCE builds.
3085330876
*/
3085430877
#if SQLITE_OS_WINCE==0
@@ -31244,11 +31267,10 @@
3124431267
winDlClose, /* xDlClose */
3124531268
winRandomness, /* xRandomness */
3124631269
winSleep, /* xSleep */
3124731270
winCurrentTime, /* xCurrentTime */
3124831271
winGetLastError, /* xGetLastError */
31249
- 0, /* xRename */
3125031272
winCurrentTimeInt64, /* xCurrentTimeInt64 */
3125131273
};
3125231274
3125331275
sqlite3_vfs_register(&winVfs, 1);
3125431276
return SQLITE_OK;
@@ -33981,10 +34003,11 @@
3398134003
char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */
3398234004
PCache *pPCache; /* Pointer to page cache object */
3398334005
sqlite3_backup *pBackup; /* Pointer to list of ongoing backup processes */
3398434006
#ifndef SQLITE_OMIT_WAL
3398534007
Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */
34008
+ char *zWal; /* File name for write-ahead log */
3398634009
#endif
3398734010
};
3398834011
3398934012
/*
3399034013
** The following global variables hold counters used for
@@ -35091,10 +35114,25 @@
3509135114
i -= 200;
3509235115
}
3509335116
return cksum;
3509435117
}
3509535118
35119
+/*
35120
+** Report the current page size and number of reserved bytes back
35121
+** to the codec.
35122
+*/
35123
+#ifdef SQLITE_HAS_CODEC
35124
+static void pagerReportSize(Pager *pPager){
35125
+ if( pPager->xCodecSizeChng ){
35126
+ pPager->xCodecSizeChng(pPager->pCodec, pPager->pageSize,
35127
+ (int)pPager->nReserve);
35128
+ }
35129
+}
35130
+#else
35131
+# define pagerReportSize(X) /* No-op if we do not support a codec */
35132
+#endif
35133
+
3509635134
/*
3509735135
** Read a single page from either the journal file (if isMainJrnl==1) or
3509835136
** from the sub-journal (if isMainJrnl==0) and playback that page.
3509935137
** The page begins at offset *pOffset into the file. The *pOffset
3510035138
** value is increased to the start of the next page in the journal.
@@ -35183,15 +35221,24 @@
3518335221
if( !isSavepnt && pager_cksum(pPager, (u8*)aData)!=cksum ){
3518435222
return SQLITE_DONE;
3518535223
}
3518635224
}
3518735225
35226
+ /* If this page has already been played by before during the current
35227
+ ** rollback, then don't bother to play it back again.
35228
+ */
3518835229
if( pDone && (rc = sqlite3BitvecSet(pDone, pgno))!=SQLITE_OK ){
3518935230
return rc;
3519035231
}
35191
-
3519235232
assert( pPager->state==PAGER_RESERVED || pPager->state>=PAGER_EXCLUSIVE );
35233
+
35234
+ /* When playing back page 1, restore the nReserve setting
35235
+ */
35236
+ if( pgno==1 && pPager->nReserve!=((u8*)aData)[20] ){
35237
+ pPager->nReserve = ((u8*)aData)[20];
35238
+ pagerReportSize(pPager);
35239
+ }
3519335240
3519435241
/* If the pager is in RESERVED state, then there must be a copy of this
3519535242
** page in the pager cache. In this case just update the pager cache,
3519635243
** not the database file. The page is left marked dirty in this case.
3519735244
**
@@ -35987,42 +36034,10 @@
3598736034
pPager->state = PAGER_SHARED;
3598836035
3598936036
return rc;
3599036037
}
3599136038
35992
-/*
35993
-** Check for the existence of or delete the *-wal file that corresponds to
35994
-** the database opened by pPager.
35995
-**
35996
-** When pExists!=NULL, set *pExists to 1 if the *-wal file exists, or 0
35997
-** if the *-wal file does not exist.
35998
-**
35999
-** When pExists==NULL, delete the *-wal file if it exists, or the do
36000
-** nothing if the *-wal file does not exist.
36001
-**
36002
-** Return SQLITE_OK on success. If on an IO or OOM error occurs, return
36003
-** an SQLite error code.
36004
-*/
36005
-static int pagerCheckForOrDeleteWAL(Pager *pPager, int *pExists){
36006
- int rc; /* Return code */
36007
- char *zWal; /* Name of the WAL file */
36008
-
36009
- assert( !pPager->tempFile );
36010
- zWal = sqlite3_mprintf("%s-wal", pPager->zFilename);
36011
- if( !zWal ){
36012
- rc = SQLITE_NOMEM;
36013
- }else{
36014
- if( pExists ){
36015
- rc = sqlite3OsAccess(pPager->pVfs, zWal, SQLITE_ACCESS_EXISTS, pExists);
36016
- }else{
36017
- rc = sqlite3OsDelete(pPager->pVfs, zWal, 0);
36018
- }
36019
- sqlite3_free(zWal);
36020
- }
36021
- return rc;
36022
-}
36023
-
3602436039
/*
3602536040
** Check if the *-wal file that corresponds to the database opened by pPager
3602636041
** exists if the database is not empy, or verify that the *-wal file does
3602736042
** not exist (by deleting it) if the database file is empty.
3602836043
**
@@ -36048,14 +36063,16 @@
3604836063
int nPage; /* Size of the database file */
3604936064
assert( pPager->state>=SHARED_LOCK );
3605036065
rc = sqlite3PagerPagecount(pPager, &nPage);
3605136066
if( rc ) return rc;
3605236067
if( nPage==0 ){
36053
- rc = pagerCheckForOrDeleteWAL(pPager, 0);
36068
+ rc = sqlite3OsDelete(pPager->pVfs, pPager->zWal, 0);
3605436069
isWal = 0;
3605536070
}else{
36056
- rc = pagerCheckForOrDeleteWAL(pPager, &isWal);
36071
+ rc = sqlite3OsAccess(
36072
+ pPager->pVfs, pPager->zWal, SQLITE_ACCESS_EXISTS, &isWal
36073
+ );
3605736074
}
3605836075
if( rc==SQLITE_OK ){
3605936076
if( isWal ){
3606036077
pager_reset(pPager);
3606136078
rc = sqlite3PagerOpenWal(pPager, 0);
@@ -36325,25 +36342,10 @@
3632536342
){
3632636343
pPager->xBusyHandler = xBusyHandler;
3632736344
pPager->pBusyHandlerArg = pBusyHandlerArg;
3632836345
}
3632936346
36330
-/*
36331
-** Report the current page size and number of reserved bytes back
36332
-** to the codec.
36333
-*/
36334
-#ifdef SQLITE_HAS_CODEC
36335
-static void pagerReportSize(Pager *pPager){
36336
- if( pPager->xCodecSizeChng ){
36337
- pPager->xCodecSizeChng(pPager->pCodec, pPager->pageSize,
36338
- (int)pPager->nReserve);
36339
- }
36340
-}
36341
-#else
36342
-# define pagerReportSize(X) /* No-op if we do not support a codec */
36343
-#endif
36344
-
3634536347
/*
3634636348
** Change the page size used by the Pager object. The new page size
3634736349
** is passed in *pPageSize.
3634836350
**
3634936351
** If the pager is in the error state when this function is called, it
@@ -36479,19 +36481,10 @@
3647936481
/* This routine is only called by btree immediately after creating
3648036482
** the Pager object. There has not been an opportunity to transition
3648136483
** to WAL mode yet.
3648236484
*/
3648336485
assert( !pagerUseWal(pPager) );
36484
-#if 0
36485
- if( pagerUseWal(pPager) ){
36486
- int isInWal = 0;
36487
- rc = sqlite3WalRead(pPager->pWal, 1, &isInWal, N, pDest);
36488
- if( rc!=SQLITE_OK || isInWal ){
36489
- return rc;
36490
- }
36491
- }
36492
-#endif
3649336486
3649436487
if( isOpen(pPager->fd) ){
3649536488
IOTRACE(("DBHDR %p 0 %d\n", pPager, N))
3649636489
rc = sqlite3OsRead(pPager->fd, pDest, N, 0);
3649736490
if( rc==SQLITE_IOERR_SHORT_READ ){
@@ -37339,10 +37332,13 @@
3733937332
ROUND8(pcacheSize) + /* PCache object */
3734037333
ROUND8(pVfs->szOsFile) + /* The main db file */
3734137334
journalFileSize * 2 + /* The two journal files */
3734237335
nPathname + 1 + /* zFilename */
3734337336
nPathname + 8 + 1 /* zJournal */
37337
+#ifndef SQLITE_OMIT_WAL
37338
+ + nPathname + 4 + 1 /* zWal */
37339
+#endif
3734437340
);
3734537341
assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
3734637342
if( !pPtr ){
3734737343
sqlite3_free(zPathname);
3734837344
return SQLITE_NOMEM;
@@ -37359,11 +37355,20 @@
3735937355
if( zPathname ){
3736037356
pPager->zJournal = (char*)(pPtr += nPathname + 1);
3736137357
memcpy(pPager->zFilename, zPathname, nPathname);
3736237358
memcpy(pPager->zJournal, zPathname, nPathname);
3736337359
memcpy(&pPager->zJournal[nPathname], "-journal", 8);
37364
- if( pPager->zFilename[0]==0 ) pPager->zJournal[0] = 0;
37360
+ if( pPager->zFilename[0]==0 ){
37361
+ pPager->zJournal[0] = 0;
37362
+ }
37363
+#ifndef SQLITE_OMIT_WAL
37364
+ else{
37365
+ pPager->zWal = &pPager->zJournal[nPathname+8+1];
37366
+ memcpy(pPager->zWal, zPathname, nPathname);
37367
+ memcpy(&pPager->zWal[nPathname], "-wal", 4);
37368
+ }
37369
+#endif
3736537370
sqlite3_free(zPathname);
3736637371
}
3736737372
pPager->pVfs = pVfs;
3736837373
pPager->vfsFlags = vfsFlags;
3736937374
@@ -39651,12 +39656,11 @@
3965139656
3965239657
/* Open the connection to the log file. If this operation fails,
3965339658
** (e.g. due to malloc() failure), unlock the database file and
3965439659
** return an error code.
3965539660
*/
39656
- rc = sqlite3WalOpen(pPager->pVfs, pPager->fd,
39657
- pPager->zFilename, &pPager->pWal);
39661
+ rc = sqlite3WalOpen(pPager->pVfs, pPager->fd, pPager->zWal, &pPager->pWal);
3965839662
if( rc==SQLITE_OK ){
3965939663
pPager->journalMode = PAGER_JOURNALMODE_WAL;
3966039664
}
3966139665
}else{
3966239666
*pisOpen = 1;
@@ -39685,15 +39689,17 @@
3968539689
*/
3968639690
if( !pPager->pWal ){
3968739691
int logexists = 0;
3968839692
rc = sqlite3OsLock(pPager->fd, SQLITE_LOCK_SHARED);
3968939693
if( rc==SQLITE_OK ){
39690
- rc = pagerCheckForOrDeleteWAL(pPager, &logexists);
39694
+ rc = sqlite3OsAccess(
39695
+ pPager->pVfs, pPager->zWal, SQLITE_ACCESS_EXISTS, &logexists
39696
+ );
3969139697
}
3969239698
if( rc==SQLITE_OK && logexists ){
3969339699
rc = sqlite3WalOpen(pPager->pVfs, pPager->fd,
39694
- pPager->zFilename, &pPager->pWal);
39700
+ pPager->zWal, &pPager->pWal);
3969539701
}
3969639702
}
3969739703
3969839704
/* Checkpoint and close the log. Because an EXCLUSIVE lock is held on
3969939705
** the database file, the log and log-summary files will be deleted.
@@ -40152,11 +40158,11 @@
4015240158
u8 exclusiveMode; /* Non-zero if connection is in exclusive mode */
4015340159
u8 isWIndexOpen; /* True if ShmOpen() called on pDbFd */
4015440160
u8 writeLock; /* True if in a write transaction */
4015540161
u8 ckptLock; /* True if holding a checkpoint lock */
4015640162
WalIndexHdr hdr; /* Wal-index header for current transaction */
40157
- char *zWalName; /* Name of WAL file */
40163
+ const char *zWalName; /* Name of WAL file */
4015840164
u32 nCkpt; /* Checkpoint sequence counter in the wal-header */
4015940165
#ifdef SQLITE_DEBUG
4016040166
u8 lockError; /* True if a locking error has occurred */
4016140167
#endif
4016240168
};
@@ -40907,12 +40913,13 @@
4090740913
pWal->isWIndexOpen = 0;
4090840914
}
4090940915
}
4091040916
4091140917
/*
40912
-** Open a connection to the WAL file associated with database zDbName.
40913
-** The database file must already be opened on connection pDbFd.
40918
+** Open a connection to the WAL file zWalName. The database file must
40919
+** already be opened on connection pDbFd. The buffer that zWalName points
40920
+** to must remain valid for the lifetime of the returned Wal* handle.
4091440921
**
4091540922
** A SHARED lock should be held on the database file when this function
4091640923
** is called. The purpose of this SHARED lock is to prevent any other
4091740924
** client from unlinking the WAL or wal-index file. If another process
4091840925
** were to do this just after this client opened one of these files, the
@@ -40923,20 +40930,18 @@
4092340930
** an SQLite error code is returned and *ppWal is left unmodified.
4092440931
*/
4092540932
SQLITE_PRIVATE int sqlite3WalOpen(
4092640933
sqlite3_vfs *pVfs, /* vfs module to open wal and wal-index */
4092740934
sqlite3_file *pDbFd, /* The open database file */
40928
- const char *zDbName, /* Name of the database file */
40935
+ const char *zWalName, /* Name of the WAL file */
4092940936
Wal **ppWal /* OUT: Allocated Wal handle */
4093040937
){
4093140938
int rc; /* Return Code */
4093240939
Wal *pRet; /* Object to allocate and return */
4093340940
int flags; /* Flags passed to OsOpen() */
40934
- char *zWal; /* Name of write-ahead log file */
40935
- int nWal; /* Length of zWal in bytes */
4093640941
40937
- assert( zDbName && zDbName[0] );
40942
+ assert( zWalName && zWalName[0] );
4093840943
assert( pDbFd );
4093940944
4094040945
/* In the amalgamation, the os_unix.c and os_win.c source files come before
4094140946
** this source file. Verify that the #defines of the locking byte offsets
4094240947
** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value.
@@ -40949,30 +40954,28 @@
4094940954
#endif
4095040955
4095140956
4095240957
/* Allocate an instance of struct Wal to return. */
4095340958
*ppWal = 0;
40954
- nWal = sqlite3Strlen30(zDbName) + 5;
40955
- pRet = (Wal*)sqlite3MallocZero(sizeof(Wal) + pVfs->szOsFile + nWal);
40959
+ pRet = (Wal*)sqlite3MallocZero(sizeof(Wal) + pVfs->szOsFile);
4095640960
if( !pRet ){
4095740961
return SQLITE_NOMEM;
4095840962
}
4095940963
4096040964
pRet->pVfs = pVfs;
4096140965
pRet->pWalFd = (sqlite3_file *)&pRet[1];
4096240966
pRet->pDbFd = pDbFd;
4096340967
pRet->readLock = -1;
4096440968
sqlite3_randomness(8, &pRet->hdr.aSalt);
40965
- pRet->zWalName = zWal = pVfs->szOsFile + (char*)pRet->pWalFd;
40966
- sqlite3_snprintf(nWal, zWal, "%s-wal", zDbName);
40969
+ pRet->zWalName = zWalName;
4096740970
rc = sqlite3OsShmOpen(pDbFd);
4096840971
4096940972
/* Open file handle on the write-ahead log file. */
4097040973
if( rc==SQLITE_OK ){
4097140974
pRet->isWIndexOpen = 1;
4097240975
flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_MAIN_JOURNAL);
40973
- rc = sqlite3OsOpen(pVfs, zWal, pRet->pWalFd, flags, &flags);
40976
+ rc = sqlite3OsOpen(pVfs, zWalName, pRet->pWalFd, flags, &flags);
4097440977
}
4097540978
4097640979
if( rc!=SQLITE_OK ){
4097740980
walIndexClose(pRet, 0);
4097840981
sqlite3OsClose(pRet->pWalFd);
@@ -84648,25 +84651,28 @@
8464884651
** or executed. All the parser does is build the internal data
8464984652
** structures that describe the table, index, or view.
8465084653
*/
8465184654
int rc;
8465284655
sqlite3_stmt *pStmt;
84656
+ TESTONLY(int rcp); /* Return code from sqlite3_prepare() */
8465384657
8465484658
assert( db->init.busy );
8465584659
db->init.iDb = iDb;
8465684660
db->init.newTnum = atoi(argv[1]);
8465784661
db->init.orphanTrigger = 0;
84658
- rc = sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
84662
+ TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
84663
+ rc = db->errCode;
84664
+ assert( (rc&0xFF)==(rcp&0xFF) );
8465984665
db->init.iDb = 0;
8466084666
if( SQLITE_OK!=rc ){
8466184667
if( db->init.orphanTrigger ){
8466284668
assert( iDb==1 );
8466384669
}else{
8466484670
pData->rc = rc;
8466584671
if( rc==SQLITE_NOMEM ){
8466684672
db->mallocFailed = 1;
84667
- }else if( rc!=SQLITE_INTERRUPT && rc!=SQLITE_LOCKED ){
84673
+ }else if( rc!=SQLITE_INTERRUPT && (rc&0xFF)!=SQLITE_LOCKED ){
8466884674
corruptSchema(pData, argv[0], sqlite3_errmsg(db));
8466984675
}
8467084676
}
8467184677
}
8467284678
sqlite3_finalize(pStmt);
8467384679
--- 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-07-03 13:59:01 3b20ad03be55613d922d81aec5313327bf4098b9"
642
643 /*
644 ** CAPI3REF: Run-Time Library Version Numbers
645 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
646 **
@@ -1359,20 +1359,27 @@
1359 ** is also passed as a parameter to both methods. If the output buffer
1360 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
1361 ** handled as a fatal error by SQLite, vfs implementations should endeavor
1362 ** to prevent this by setting mxPathname to a sufficiently large value.
1363 **
1364 ** The xRandomness(), xSleep(), and xCurrentTime() interfaces
1365 ** are not strictly a part of the filesystem, but they are
1366 ** included in the VFS structure for completeness.
1367 ** The xRandomness() function attempts to return nBytes bytes
1368 ** of good-quality randomness into zOut. The return value is
1369 ** the actual number of bytes of randomness obtained.
1370 ** The xSleep() method causes the calling thread to sleep for at
1371 ** least the number of microseconds given. The xCurrentTime()
1372 ** method returns a Julian Day Number for the current date and time.
1373 **
 
 
 
 
 
 
 
1374 */
1375 typedef struct sqlite3_vfs sqlite3_vfs;
1376 struct sqlite3_vfs {
1377 int iVersion; /* Structure version number (currently 2) */
1378 int szOsFile; /* Size of subclassed sqlite3_file */
@@ -1395,11 +1402,10 @@
1395 int (*xGetLastError)(sqlite3_vfs*, int, char *);
1396 /*
1397 ** The methods above are in version 1 of the sqlite_vfs object
1398 ** definition. Those that follow are added in version 2 or later
1399 */
1400 int (*xRename)(sqlite3_vfs*, const char *zOld, const char *zNew, int dirSync);
1401 int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
1402 /*
1403 ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
1404 ** New fields may be appended in figure versions. The iVersion
1405 ** value will increment whenever this happens.
@@ -28503,11 +28509,10 @@
28503 unixDlClose, /* xDlClose */ \
28504 unixRandomness, /* xRandomness */ \
28505 unixSleep, /* xSleep */ \
28506 unixCurrentTime, /* xCurrentTime */ \
28507 unixGetLastError, /* xGetLastError */ \
28508 0, /* xRename */ \
28509 unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \
28510 }
28511
28512 /*
28513 ** All default VFSes for unix are contained in the following array.
@@ -29497,11 +29502,15 @@
29497 SimulateDiskfullError(return SQLITE_FULL);
29498 OSTRACE(("WRITE %d lock=%d\n", pFile->h, pFile->locktype));
29499 rc = SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
29500 if( rc==INVALID_SET_FILE_POINTER && (error=GetLastError())!=NO_ERROR ){
29501 pFile->lastErrno = error;
29502 return SQLITE_FULL;
 
 
 
 
29503 }
29504 assert( amt>0 );
29505 while(
29506 amt>0
29507 && (rc = WriteFile(pFile->h, pBuf, amt, &wrote, 0))!=0
@@ -29510,11 +29519,15 @@
29510 amt -= wrote;
29511 pBuf = &((char*)pBuf)[wrote];
29512 }
29513 if( !rc || amt>(int)wrote ){
29514 pFile->lastErrno = GetLastError();
29515 return SQLITE_FULL;
 
 
 
 
29516 }
29517 return SQLITE_OK;
29518 }
29519
29520 /*
@@ -30844,11 +30857,21 @@
30844 UNUSED_PARAMETER(pVfs);
30845 if( zConverted==0 ){
30846 return SQLITE_NOMEM;
30847 }
30848 if( isNT() ){
30849 attr = GetFileAttributesW((WCHAR*)zConverted);
 
 
 
 
 
 
 
 
 
 
30850 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
30851 ** Since the ASCII version of these Windows API do not exist for WINCE,
30852 ** it's important to not reference them for WINCE builds.
30853 */
30854 #if SQLITE_OS_WINCE==0
@@ -31244,11 +31267,10 @@
31244 winDlClose, /* xDlClose */
31245 winRandomness, /* xRandomness */
31246 winSleep, /* xSleep */
31247 winCurrentTime, /* xCurrentTime */
31248 winGetLastError, /* xGetLastError */
31249 0, /* xRename */
31250 winCurrentTimeInt64, /* xCurrentTimeInt64 */
31251 };
31252
31253 sqlite3_vfs_register(&winVfs, 1);
31254 return SQLITE_OK;
@@ -33981,10 +34003,11 @@
33981 char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */
33982 PCache *pPCache; /* Pointer to page cache object */
33983 sqlite3_backup *pBackup; /* Pointer to list of ongoing backup processes */
33984 #ifndef SQLITE_OMIT_WAL
33985 Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */
 
33986 #endif
33987 };
33988
33989 /*
33990 ** The following global variables hold counters used for
@@ -35091,10 +35114,25 @@
35091 i -= 200;
35092 }
35093 return cksum;
35094 }
35095
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35096 /*
35097 ** Read a single page from either the journal file (if isMainJrnl==1) or
35098 ** from the sub-journal (if isMainJrnl==0) and playback that page.
35099 ** The page begins at offset *pOffset into the file. The *pOffset
35100 ** value is increased to the start of the next page in the journal.
@@ -35183,15 +35221,24 @@
35183 if( !isSavepnt && pager_cksum(pPager, (u8*)aData)!=cksum ){
35184 return SQLITE_DONE;
35185 }
35186 }
35187
 
 
 
35188 if( pDone && (rc = sqlite3BitvecSet(pDone, pgno))!=SQLITE_OK ){
35189 return rc;
35190 }
35191
35192 assert( pPager->state==PAGER_RESERVED || pPager->state>=PAGER_EXCLUSIVE );
 
 
 
 
 
 
 
35193
35194 /* If the pager is in RESERVED state, then there must be a copy of this
35195 ** page in the pager cache. In this case just update the pager cache,
35196 ** not the database file. The page is left marked dirty in this case.
35197 **
@@ -35987,42 +36034,10 @@
35987 pPager->state = PAGER_SHARED;
35988
35989 return rc;
35990 }
35991
35992 /*
35993 ** Check for the existence of or delete the *-wal file that corresponds to
35994 ** the database opened by pPager.
35995 **
35996 ** When pExists!=NULL, set *pExists to 1 if the *-wal file exists, or 0
35997 ** if the *-wal file does not exist.
35998 **
35999 ** When pExists==NULL, delete the *-wal file if it exists, or the do
36000 ** nothing if the *-wal file does not exist.
36001 **
36002 ** Return SQLITE_OK on success. If on an IO or OOM error occurs, return
36003 ** an SQLite error code.
36004 */
36005 static int pagerCheckForOrDeleteWAL(Pager *pPager, int *pExists){
36006 int rc; /* Return code */
36007 char *zWal; /* Name of the WAL file */
36008
36009 assert( !pPager->tempFile );
36010 zWal = sqlite3_mprintf("%s-wal", pPager->zFilename);
36011 if( !zWal ){
36012 rc = SQLITE_NOMEM;
36013 }else{
36014 if( pExists ){
36015 rc = sqlite3OsAccess(pPager->pVfs, zWal, SQLITE_ACCESS_EXISTS, pExists);
36016 }else{
36017 rc = sqlite3OsDelete(pPager->pVfs, zWal, 0);
36018 }
36019 sqlite3_free(zWal);
36020 }
36021 return rc;
36022 }
36023
36024 /*
36025 ** Check if the *-wal file that corresponds to the database opened by pPager
36026 ** exists if the database is not empy, or verify that the *-wal file does
36027 ** not exist (by deleting it) if the database file is empty.
36028 **
@@ -36048,14 +36063,16 @@
36048 int nPage; /* Size of the database file */
36049 assert( pPager->state>=SHARED_LOCK );
36050 rc = sqlite3PagerPagecount(pPager, &nPage);
36051 if( rc ) return rc;
36052 if( nPage==0 ){
36053 rc = pagerCheckForOrDeleteWAL(pPager, 0);
36054 isWal = 0;
36055 }else{
36056 rc = pagerCheckForOrDeleteWAL(pPager, &isWal);
 
 
36057 }
36058 if( rc==SQLITE_OK ){
36059 if( isWal ){
36060 pager_reset(pPager);
36061 rc = sqlite3PagerOpenWal(pPager, 0);
@@ -36325,25 +36342,10 @@
36325 ){
36326 pPager->xBusyHandler = xBusyHandler;
36327 pPager->pBusyHandlerArg = pBusyHandlerArg;
36328 }
36329
36330 /*
36331 ** Report the current page size and number of reserved bytes back
36332 ** to the codec.
36333 */
36334 #ifdef SQLITE_HAS_CODEC
36335 static void pagerReportSize(Pager *pPager){
36336 if( pPager->xCodecSizeChng ){
36337 pPager->xCodecSizeChng(pPager->pCodec, pPager->pageSize,
36338 (int)pPager->nReserve);
36339 }
36340 }
36341 #else
36342 # define pagerReportSize(X) /* No-op if we do not support a codec */
36343 #endif
36344
36345 /*
36346 ** Change the page size used by the Pager object. The new page size
36347 ** is passed in *pPageSize.
36348 **
36349 ** If the pager is in the error state when this function is called, it
@@ -36479,19 +36481,10 @@
36479 /* This routine is only called by btree immediately after creating
36480 ** the Pager object. There has not been an opportunity to transition
36481 ** to WAL mode yet.
36482 */
36483 assert( !pagerUseWal(pPager) );
36484 #if 0
36485 if( pagerUseWal(pPager) ){
36486 int isInWal = 0;
36487 rc = sqlite3WalRead(pPager->pWal, 1, &isInWal, N, pDest);
36488 if( rc!=SQLITE_OK || isInWal ){
36489 return rc;
36490 }
36491 }
36492 #endif
36493
36494 if( isOpen(pPager->fd) ){
36495 IOTRACE(("DBHDR %p 0 %d\n", pPager, N))
36496 rc = sqlite3OsRead(pPager->fd, pDest, N, 0);
36497 if( rc==SQLITE_IOERR_SHORT_READ ){
@@ -37339,10 +37332,13 @@
37339 ROUND8(pcacheSize) + /* PCache object */
37340 ROUND8(pVfs->szOsFile) + /* The main db file */
37341 journalFileSize * 2 + /* The two journal files */
37342 nPathname + 1 + /* zFilename */
37343 nPathname + 8 + 1 /* zJournal */
 
 
 
37344 );
37345 assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
37346 if( !pPtr ){
37347 sqlite3_free(zPathname);
37348 return SQLITE_NOMEM;
@@ -37359,11 +37355,20 @@
37359 if( zPathname ){
37360 pPager->zJournal = (char*)(pPtr += nPathname + 1);
37361 memcpy(pPager->zFilename, zPathname, nPathname);
37362 memcpy(pPager->zJournal, zPathname, nPathname);
37363 memcpy(&pPager->zJournal[nPathname], "-journal", 8);
37364 if( pPager->zFilename[0]==0 ) pPager->zJournal[0] = 0;
 
 
 
 
 
 
 
 
 
37365 sqlite3_free(zPathname);
37366 }
37367 pPager->pVfs = pVfs;
37368 pPager->vfsFlags = vfsFlags;
37369
@@ -39651,12 +39656,11 @@
39651
39652 /* Open the connection to the log file. If this operation fails,
39653 ** (e.g. due to malloc() failure), unlock the database file and
39654 ** return an error code.
39655 */
39656 rc = sqlite3WalOpen(pPager->pVfs, pPager->fd,
39657 pPager->zFilename, &pPager->pWal);
39658 if( rc==SQLITE_OK ){
39659 pPager->journalMode = PAGER_JOURNALMODE_WAL;
39660 }
39661 }else{
39662 *pisOpen = 1;
@@ -39685,15 +39689,17 @@
39685 */
39686 if( !pPager->pWal ){
39687 int logexists = 0;
39688 rc = sqlite3OsLock(pPager->fd, SQLITE_LOCK_SHARED);
39689 if( rc==SQLITE_OK ){
39690 rc = pagerCheckForOrDeleteWAL(pPager, &logexists);
 
 
39691 }
39692 if( rc==SQLITE_OK && logexists ){
39693 rc = sqlite3WalOpen(pPager->pVfs, pPager->fd,
39694 pPager->zFilename, &pPager->pWal);
39695 }
39696 }
39697
39698 /* Checkpoint and close the log. Because an EXCLUSIVE lock is held on
39699 ** the database file, the log and log-summary files will be deleted.
@@ -40152,11 +40158,11 @@
40152 u8 exclusiveMode; /* Non-zero if connection is in exclusive mode */
40153 u8 isWIndexOpen; /* True if ShmOpen() called on pDbFd */
40154 u8 writeLock; /* True if in a write transaction */
40155 u8 ckptLock; /* True if holding a checkpoint lock */
40156 WalIndexHdr hdr; /* Wal-index header for current transaction */
40157 char *zWalName; /* Name of WAL file */
40158 u32 nCkpt; /* Checkpoint sequence counter in the wal-header */
40159 #ifdef SQLITE_DEBUG
40160 u8 lockError; /* True if a locking error has occurred */
40161 #endif
40162 };
@@ -40907,12 +40913,13 @@
40907 pWal->isWIndexOpen = 0;
40908 }
40909 }
40910
40911 /*
40912 ** Open a connection to the WAL file associated with database zDbName.
40913 ** The database file must already be opened on connection pDbFd.
 
40914 **
40915 ** A SHARED lock should be held on the database file when this function
40916 ** is called. The purpose of this SHARED lock is to prevent any other
40917 ** client from unlinking the WAL or wal-index file. If another process
40918 ** were to do this just after this client opened one of these files, the
@@ -40923,20 +40930,18 @@
40923 ** an SQLite error code is returned and *ppWal is left unmodified.
40924 */
40925 SQLITE_PRIVATE int sqlite3WalOpen(
40926 sqlite3_vfs *pVfs, /* vfs module to open wal and wal-index */
40927 sqlite3_file *pDbFd, /* The open database file */
40928 const char *zDbName, /* Name of the database file */
40929 Wal **ppWal /* OUT: Allocated Wal handle */
40930 ){
40931 int rc; /* Return Code */
40932 Wal *pRet; /* Object to allocate and return */
40933 int flags; /* Flags passed to OsOpen() */
40934 char *zWal; /* Name of write-ahead log file */
40935 int nWal; /* Length of zWal in bytes */
40936
40937 assert( zDbName && zDbName[0] );
40938 assert( pDbFd );
40939
40940 /* In the amalgamation, the os_unix.c and os_win.c source files come before
40941 ** this source file. Verify that the #defines of the locking byte offsets
40942 ** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value.
@@ -40949,30 +40954,28 @@
40949 #endif
40950
40951
40952 /* Allocate an instance of struct Wal to return. */
40953 *ppWal = 0;
40954 nWal = sqlite3Strlen30(zDbName) + 5;
40955 pRet = (Wal*)sqlite3MallocZero(sizeof(Wal) + pVfs->szOsFile + nWal);
40956 if( !pRet ){
40957 return SQLITE_NOMEM;
40958 }
40959
40960 pRet->pVfs = pVfs;
40961 pRet->pWalFd = (sqlite3_file *)&pRet[1];
40962 pRet->pDbFd = pDbFd;
40963 pRet->readLock = -1;
40964 sqlite3_randomness(8, &pRet->hdr.aSalt);
40965 pRet->zWalName = zWal = pVfs->szOsFile + (char*)pRet->pWalFd;
40966 sqlite3_snprintf(nWal, zWal, "%s-wal", zDbName);
40967 rc = sqlite3OsShmOpen(pDbFd);
40968
40969 /* Open file handle on the write-ahead log file. */
40970 if( rc==SQLITE_OK ){
40971 pRet->isWIndexOpen = 1;
40972 flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_MAIN_JOURNAL);
40973 rc = sqlite3OsOpen(pVfs, zWal, pRet->pWalFd, flags, &flags);
40974 }
40975
40976 if( rc!=SQLITE_OK ){
40977 walIndexClose(pRet, 0);
40978 sqlite3OsClose(pRet->pWalFd);
@@ -84648,25 +84651,28 @@
84648 ** or executed. All the parser does is build the internal data
84649 ** structures that describe the table, index, or view.
84650 */
84651 int rc;
84652 sqlite3_stmt *pStmt;
 
84653
84654 assert( db->init.busy );
84655 db->init.iDb = iDb;
84656 db->init.newTnum = atoi(argv[1]);
84657 db->init.orphanTrigger = 0;
84658 rc = sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
 
 
84659 db->init.iDb = 0;
84660 if( SQLITE_OK!=rc ){
84661 if( db->init.orphanTrigger ){
84662 assert( iDb==1 );
84663 }else{
84664 pData->rc = rc;
84665 if( rc==SQLITE_NOMEM ){
84666 db->mallocFailed = 1;
84667 }else if( rc!=SQLITE_INTERRUPT && rc!=SQLITE_LOCKED ){
84668 corruptSchema(pData, argv[0], sqlite3_errmsg(db));
84669 }
84670 }
84671 }
84672 sqlite3_finalize(pStmt);
84673
--- 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-07-06 20:37:10 5621862b0e2fc945ded51f5926a6b4c9f07d0ab7"
642
643 /*
644 ** CAPI3REF: Run-Time Library Version Numbers
645 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
646 **
@@ -1359,20 +1359,27 @@
1359 ** is also passed as a parameter to both methods. If the output buffer
1360 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
1361 ** handled as a fatal error by SQLite, vfs implementations should endeavor
1362 ** to prevent this by setting mxPathname to a sufficiently large value.
1363 **
1364 ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
1365 ** interfaces are not strictly a part of the filesystem, but they are
1366 ** included in the VFS structure for completeness.
1367 ** The xRandomness() function attempts to return nBytes bytes
1368 ** of good-quality randomness into zOut. The return value is
1369 ** the actual number of bytes of randomness obtained.
1370 ** The xSleep() method causes the calling thread to sleep for at
1371 ** least the number of microseconds given. The xCurrentTime()
1372 ** method returns a Julian Day Number for the current date and time as
1373 ** a floating point value.
1374 ** The xCurrentTimeInt64() method returns, as an integer, the Julian
1375 ** Day Number multipled by 86400000 (the number of milliseconds in
1376 ** a 24-hour day).
1377 ** ^SQLite will use the xCurrentTimeInt64() method to get the current
1378 ** date and time if that method is available (if iVersion is 2 or
1379 ** greater and the function pointer is not NULL) and will fall back
1380 ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
1381 */
1382 typedef struct sqlite3_vfs sqlite3_vfs;
1383 struct sqlite3_vfs {
1384 int iVersion; /* Structure version number (currently 2) */
1385 int szOsFile; /* Size of subclassed sqlite3_file */
@@ -1395,11 +1402,10 @@
1402 int (*xGetLastError)(sqlite3_vfs*, int, char *);
1403 /*
1404 ** The methods above are in version 1 of the sqlite_vfs object
1405 ** definition. Those that follow are added in version 2 or later
1406 */
 
1407 int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
1408 /*
1409 ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
1410 ** New fields may be appended in figure versions. The iVersion
1411 ** value will increment whenever this happens.
@@ -28503,11 +28509,10 @@
28509 unixDlClose, /* xDlClose */ \
28510 unixRandomness, /* xRandomness */ \
28511 unixSleep, /* xSleep */ \
28512 unixCurrentTime, /* xCurrentTime */ \
28513 unixGetLastError, /* xGetLastError */ \
 
28514 unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \
28515 }
28516
28517 /*
28518 ** All default VFSes for unix are contained in the following array.
@@ -29497,11 +29502,15 @@
29502 SimulateDiskfullError(return SQLITE_FULL);
29503 OSTRACE(("WRITE %d lock=%d\n", pFile->h, pFile->locktype));
29504 rc = SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
29505 if( rc==INVALID_SET_FILE_POINTER && (error=GetLastError())!=NO_ERROR ){
29506 pFile->lastErrno = error;
29507 if( pFile->lastErrno==ERROR_HANDLE_DISK_FULL ){
29508 return SQLITE_FULL;
29509 }else{
29510 return SQLITE_IOERR_WRITE;
29511 }
29512 }
29513 assert( amt>0 );
29514 while(
29515 amt>0
29516 && (rc = WriteFile(pFile->h, pBuf, amt, &wrote, 0))!=0
@@ -29510,11 +29519,15 @@
29519 amt -= wrote;
29520 pBuf = &((char*)pBuf)[wrote];
29521 }
29522 if( !rc || amt>(int)wrote ){
29523 pFile->lastErrno = GetLastError();
29524 if( pFile->lastErrno==ERROR_HANDLE_DISK_FULL ){
29525 return SQLITE_FULL;
29526 }else{
29527 return SQLITE_IOERR_WRITE;
29528 }
29529 }
29530 return SQLITE_OK;
29531 }
29532
29533 /*
@@ -30844,11 +30857,21 @@
30857 UNUSED_PARAMETER(pVfs);
30858 if( zConverted==0 ){
30859 return SQLITE_NOMEM;
30860 }
30861 if( isNT() ){
30862 WIN32_FILE_ATTRIBUTE_DATA sAttrData;
30863 memset(&sAttrData, 0, sizeof(sAttrData));
30864 attr = GetFileAttributesExW((WCHAR*)zConverted,
30865 GetFileExInfoStandard, &sAttrData);
30866 /* For an SQLITE_ACCESS_EXISTS query, treat a zero-length file
30867 ** as if it does not exist.
30868 */
30869 if( flags==SQLITE_ACCESS_EXISTS && attr!=INVALID_FILE_ATTRIBUTES
30870 && sAttrData.nFileSizeHigh==0 && sAttrData.nFileSizeLow==0 ){
30871 attr = INVALID_FILE_ATTRIBUTES;
30872 }
30873 /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed.
30874 ** Since the ASCII version of these Windows API do not exist for WINCE,
30875 ** it's important to not reference them for WINCE builds.
30876 */
30877 #if SQLITE_OS_WINCE==0
@@ -31244,11 +31267,10 @@
31267 winDlClose, /* xDlClose */
31268 winRandomness, /* xRandomness */
31269 winSleep, /* xSleep */
31270 winCurrentTime, /* xCurrentTime */
31271 winGetLastError, /* xGetLastError */
 
31272 winCurrentTimeInt64, /* xCurrentTimeInt64 */
31273 };
31274
31275 sqlite3_vfs_register(&winVfs, 1);
31276 return SQLITE_OK;
@@ -33981,10 +34003,11 @@
34003 char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */
34004 PCache *pPCache; /* Pointer to page cache object */
34005 sqlite3_backup *pBackup; /* Pointer to list of ongoing backup processes */
34006 #ifndef SQLITE_OMIT_WAL
34007 Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */
34008 char *zWal; /* File name for write-ahead log */
34009 #endif
34010 };
34011
34012 /*
34013 ** The following global variables hold counters used for
@@ -35091,10 +35114,25 @@
35114 i -= 200;
35115 }
35116 return cksum;
35117 }
35118
35119 /*
35120 ** Report the current page size and number of reserved bytes back
35121 ** to the codec.
35122 */
35123 #ifdef SQLITE_HAS_CODEC
35124 static void pagerReportSize(Pager *pPager){
35125 if( pPager->xCodecSizeChng ){
35126 pPager->xCodecSizeChng(pPager->pCodec, pPager->pageSize,
35127 (int)pPager->nReserve);
35128 }
35129 }
35130 #else
35131 # define pagerReportSize(X) /* No-op if we do not support a codec */
35132 #endif
35133
35134 /*
35135 ** Read a single page from either the journal file (if isMainJrnl==1) or
35136 ** from the sub-journal (if isMainJrnl==0) and playback that page.
35137 ** The page begins at offset *pOffset into the file. The *pOffset
35138 ** value is increased to the start of the next page in the journal.
@@ -35183,15 +35221,24 @@
35221 if( !isSavepnt && pager_cksum(pPager, (u8*)aData)!=cksum ){
35222 return SQLITE_DONE;
35223 }
35224 }
35225
35226 /* If this page has already been played by before during the current
35227 ** rollback, then don't bother to play it back again.
35228 */
35229 if( pDone && (rc = sqlite3BitvecSet(pDone, pgno))!=SQLITE_OK ){
35230 return rc;
35231 }
 
35232 assert( pPager->state==PAGER_RESERVED || pPager->state>=PAGER_EXCLUSIVE );
35233
35234 /* When playing back page 1, restore the nReserve setting
35235 */
35236 if( pgno==1 && pPager->nReserve!=((u8*)aData)[20] ){
35237 pPager->nReserve = ((u8*)aData)[20];
35238 pagerReportSize(pPager);
35239 }
35240
35241 /* If the pager is in RESERVED state, then there must be a copy of this
35242 ** page in the pager cache. In this case just update the pager cache,
35243 ** not the database file. The page is left marked dirty in this case.
35244 **
@@ -35987,42 +36034,10 @@
36034 pPager->state = PAGER_SHARED;
36035
36036 return rc;
36037 }
36038
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36039 /*
36040 ** Check if the *-wal file that corresponds to the database opened by pPager
36041 ** exists if the database is not empy, or verify that the *-wal file does
36042 ** not exist (by deleting it) if the database file is empty.
36043 **
@@ -36048,14 +36063,16 @@
36063 int nPage; /* Size of the database file */
36064 assert( pPager->state>=SHARED_LOCK );
36065 rc = sqlite3PagerPagecount(pPager, &nPage);
36066 if( rc ) return rc;
36067 if( nPage==0 ){
36068 rc = sqlite3OsDelete(pPager->pVfs, pPager->zWal, 0);
36069 isWal = 0;
36070 }else{
36071 rc = sqlite3OsAccess(
36072 pPager->pVfs, pPager->zWal, SQLITE_ACCESS_EXISTS, &isWal
36073 );
36074 }
36075 if( rc==SQLITE_OK ){
36076 if( isWal ){
36077 pager_reset(pPager);
36078 rc = sqlite3PagerOpenWal(pPager, 0);
@@ -36325,25 +36342,10 @@
36342 ){
36343 pPager->xBusyHandler = xBusyHandler;
36344 pPager->pBusyHandlerArg = pBusyHandlerArg;
36345 }
36346
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36347 /*
36348 ** Change the page size used by the Pager object. The new page size
36349 ** is passed in *pPageSize.
36350 **
36351 ** If the pager is in the error state when this function is called, it
@@ -36479,19 +36481,10 @@
36481 /* This routine is only called by btree immediately after creating
36482 ** the Pager object. There has not been an opportunity to transition
36483 ** to WAL mode yet.
36484 */
36485 assert( !pagerUseWal(pPager) );
 
 
 
 
 
 
 
 
 
36486
36487 if( isOpen(pPager->fd) ){
36488 IOTRACE(("DBHDR %p 0 %d\n", pPager, N))
36489 rc = sqlite3OsRead(pPager->fd, pDest, N, 0);
36490 if( rc==SQLITE_IOERR_SHORT_READ ){
@@ -37339,10 +37332,13 @@
37332 ROUND8(pcacheSize) + /* PCache object */
37333 ROUND8(pVfs->szOsFile) + /* The main db file */
37334 journalFileSize * 2 + /* The two journal files */
37335 nPathname + 1 + /* zFilename */
37336 nPathname + 8 + 1 /* zJournal */
37337 #ifndef SQLITE_OMIT_WAL
37338 + nPathname + 4 + 1 /* zWal */
37339 #endif
37340 );
37341 assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
37342 if( !pPtr ){
37343 sqlite3_free(zPathname);
37344 return SQLITE_NOMEM;
@@ -37359,11 +37355,20 @@
37355 if( zPathname ){
37356 pPager->zJournal = (char*)(pPtr += nPathname + 1);
37357 memcpy(pPager->zFilename, zPathname, nPathname);
37358 memcpy(pPager->zJournal, zPathname, nPathname);
37359 memcpy(&pPager->zJournal[nPathname], "-journal", 8);
37360 if( pPager->zFilename[0]==0 ){
37361 pPager->zJournal[0] = 0;
37362 }
37363 #ifndef SQLITE_OMIT_WAL
37364 else{
37365 pPager->zWal = &pPager->zJournal[nPathname+8+1];
37366 memcpy(pPager->zWal, zPathname, nPathname);
37367 memcpy(&pPager->zWal[nPathname], "-wal", 4);
37368 }
37369 #endif
37370 sqlite3_free(zPathname);
37371 }
37372 pPager->pVfs = pVfs;
37373 pPager->vfsFlags = vfsFlags;
37374
@@ -39651,12 +39656,11 @@
39656
39657 /* Open the connection to the log file. If this operation fails,
39658 ** (e.g. due to malloc() failure), unlock the database file and
39659 ** return an error code.
39660 */
39661 rc = sqlite3WalOpen(pPager->pVfs, pPager->fd, pPager->zWal, &pPager->pWal);
 
39662 if( rc==SQLITE_OK ){
39663 pPager->journalMode = PAGER_JOURNALMODE_WAL;
39664 }
39665 }else{
39666 *pisOpen = 1;
@@ -39685,15 +39689,17 @@
39689 */
39690 if( !pPager->pWal ){
39691 int logexists = 0;
39692 rc = sqlite3OsLock(pPager->fd, SQLITE_LOCK_SHARED);
39693 if( rc==SQLITE_OK ){
39694 rc = sqlite3OsAccess(
39695 pPager->pVfs, pPager->zWal, SQLITE_ACCESS_EXISTS, &logexists
39696 );
39697 }
39698 if( rc==SQLITE_OK && logexists ){
39699 rc = sqlite3WalOpen(pPager->pVfs, pPager->fd,
39700 pPager->zWal, &pPager->pWal);
39701 }
39702 }
39703
39704 /* Checkpoint and close the log. Because an EXCLUSIVE lock is held on
39705 ** the database file, the log and log-summary files will be deleted.
@@ -40152,11 +40158,11 @@
40158 u8 exclusiveMode; /* Non-zero if connection is in exclusive mode */
40159 u8 isWIndexOpen; /* True if ShmOpen() called on pDbFd */
40160 u8 writeLock; /* True if in a write transaction */
40161 u8 ckptLock; /* True if holding a checkpoint lock */
40162 WalIndexHdr hdr; /* Wal-index header for current transaction */
40163 const char *zWalName; /* Name of WAL file */
40164 u32 nCkpt; /* Checkpoint sequence counter in the wal-header */
40165 #ifdef SQLITE_DEBUG
40166 u8 lockError; /* True if a locking error has occurred */
40167 #endif
40168 };
@@ -40907,12 +40913,13 @@
40913 pWal->isWIndexOpen = 0;
40914 }
40915 }
40916
40917 /*
40918 ** Open a connection to the WAL file zWalName. The database file must
40919 ** already be opened on connection pDbFd. The buffer that zWalName points
40920 ** to must remain valid for the lifetime of the returned Wal* handle.
40921 **
40922 ** A SHARED lock should be held on the database file when this function
40923 ** is called. The purpose of this SHARED lock is to prevent any other
40924 ** client from unlinking the WAL or wal-index file. If another process
40925 ** were to do this just after this client opened one of these files, the
@@ -40923,20 +40930,18 @@
40930 ** an SQLite error code is returned and *ppWal is left unmodified.
40931 */
40932 SQLITE_PRIVATE int sqlite3WalOpen(
40933 sqlite3_vfs *pVfs, /* vfs module to open wal and wal-index */
40934 sqlite3_file *pDbFd, /* The open database file */
40935 const char *zWalName, /* Name of the WAL file */
40936 Wal **ppWal /* OUT: Allocated Wal handle */
40937 ){
40938 int rc; /* Return Code */
40939 Wal *pRet; /* Object to allocate and return */
40940 int flags; /* Flags passed to OsOpen() */
 
 
40941
40942 assert( zWalName && zWalName[0] );
40943 assert( pDbFd );
40944
40945 /* In the amalgamation, the os_unix.c and os_win.c source files come before
40946 ** this source file. Verify that the #defines of the locking byte offsets
40947 ** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value.
@@ -40949,30 +40954,28 @@
40954 #endif
40955
40956
40957 /* Allocate an instance of struct Wal to return. */
40958 *ppWal = 0;
40959 pRet = (Wal*)sqlite3MallocZero(sizeof(Wal) + pVfs->szOsFile);
 
40960 if( !pRet ){
40961 return SQLITE_NOMEM;
40962 }
40963
40964 pRet->pVfs = pVfs;
40965 pRet->pWalFd = (sqlite3_file *)&pRet[1];
40966 pRet->pDbFd = pDbFd;
40967 pRet->readLock = -1;
40968 sqlite3_randomness(8, &pRet->hdr.aSalt);
40969 pRet->zWalName = zWalName;
 
40970 rc = sqlite3OsShmOpen(pDbFd);
40971
40972 /* Open file handle on the write-ahead log file. */
40973 if( rc==SQLITE_OK ){
40974 pRet->isWIndexOpen = 1;
40975 flags = (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_MAIN_JOURNAL);
40976 rc = sqlite3OsOpen(pVfs, zWalName, pRet->pWalFd, flags, &flags);
40977 }
40978
40979 if( rc!=SQLITE_OK ){
40980 walIndexClose(pRet, 0);
40981 sqlite3OsClose(pRet->pWalFd);
@@ -84648,25 +84651,28 @@
84651 ** or executed. All the parser does is build the internal data
84652 ** structures that describe the table, index, or view.
84653 */
84654 int rc;
84655 sqlite3_stmt *pStmt;
84656 TESTONLY(int rcp); /* Return code from sqlite3_prepare() */
84657
84658 assert( db->init.busy );
84659 db->init.iDb = iDb;
84660 db->init.newTnum = atoi(argv[1]);
84661 db->init.orphanTrigger = 0;
84662 TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
84663 rc = db->errCode;
84664 assert( (rc&0xFF)==(rcp&0xFF) );
84665 db->init.iDb = 0;
84666 if( SQLITE_OK!=rc ){
84667 if( db->init.orphanTrigger ){
84668 assert( iDb==1 );
84669 }else{
84670 pData->rc = rc;
84671 if( rc==SQLITE_NOMEM ){
84672 db->mallocFailed = 1;
84673 }else if( rc!=SQLITE_INTERRUPT && (rc&0xFF)!=SQLITE_LOCKED ){
84674 corruptSchema(pData, argv[0], sqlite3_errmsg(db));
84675 }
84676 }
84677 }
84678 sqlite3_finalize(pStmt);
84679
+12 -6
--- 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-07-03 13:59:01 3b20ad03be55613d922d81aec5313327bf4098b9"
112
+#define SQLITE_SOURCE_ID "2010-07-06 20:37:10 5621862b0e2fc945ded51f5926a6b4c9f07d0ab7"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -830,20 +830,27 @@
830830
** is also passed as a parameter to both methods. If the output buffer
831831
** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
832832
** handled as a fatal error by SQLite, vfs implementations should endeavor
833833
** to prevent this by setting mxPathname to a sufficiently large value.
834834
**
835
-** The xRandomness(), xSleep(), and xCurrentTime() interfaces
836
-** are not strictly a part of the filesystem, but they are
835
+** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
836
+** interfaces are not strictly a part of the filesystem, but they are
837837
** included in the VFS structure for completeness.
838838
** The xRandomness() function attempts to return nBytes bytes
839839
** of good-quality randomness into zOut. The return value is
840840
** the actual number of bytes of randomness obtained.
841841
** The xSleep() method causes the calling thread to sleep for at
842842
** least the number of microseconds given. The xCurrentTime()
843
-** method returns a Julian Day Number for the current date and time.
844
-**
843
+** method returns a Julian Day Number for the current date and time as
844
+** a floating point value.
845
+** The xCurrentTimeInt64() method returns, as an integer, the Julian
846
+** Day Number multipled by 86400000 (the number of milliseconds in
847
+** a 24-hour day).
848
+** ^SQLite will use the xCurrentTimeInt64() method to get the current
849
+** date and time if that method is available (if iVersion is 2 or
850
+** greater and the function pointer is not NULL) and will fall back
851
+** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
845852
*/
846853
typedef struct sqlite3_vfs sqlite3_vfs;
847854
struct sqlite3_vfs {
848855
int iVersion; /* Structure version number (currently 2) */
849856
int szOsFile; /* Size of subclassed sqlite3_file */
@@ -866,11 +873,10 @@
866873
int (*xGetLastError)(sqlite3_vfs*, int, char *);
867874
/*
868875
** The methods above are in version 1 of the sqlite_vfs object
869876
** definition. Those that follow are added in version 2 or later
870877
*/
871
- int (*xRename)(sqlite3_vfs*, const char *zOld, const char *zNew, int dirSync);
872878
int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
873879
/*
874880
** The methods above are in versions 1 and 2 of the sqlite_vfs object.
875881
** New fields may be appended in figure versions. The iVersion
876882
** value will increment whenever this happens.
877883
--- 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-07-03 13:59:01 3b20ad03be55613d922d81aec5313327bf4098b9"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -830,20 +830,27 @@
830 ** is also passed as a parameter to both methods. If the output buffer
831 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
832 ** handled as a fatal error by SQLite, vfs implementations should endeavor
833 ** to prevent this by setting mxPathname to a sufficiently large value.
834 **
835 ** The xRandomness(), xSleep(), and xCurrentTime() interfaces
836 ** are not strictly a part of the filesystem, but they are
837 ** included in the VFS structure for completeness.
838 ** The xRandomness() function attempts to return nBytes bytes
839 ** of good-quality randomness into zOut. The return value is
840 ** the actual number of bytes of randomness obtained.
841 ** The xSleep() method causes the calling thread to sleep for at
842 ** least the number of microseconds given. The xCurrentTime()
843 ** method returns a Julian Day Number for the current date and time.
844 **
 
 
 
 
 
 
 
845 */
846 typedef struct sqlite3_vfs sqlite3_vfs;
847 struct sqlite3_vfs {
848 int iVersion; /* Structure version number (currently 2) */
849 int szOsFile; /* Size of subclassed sqlite3_file */
@@ -866,11 +873,10 @@
866 int (*xGetLastError)(sqlite3_vfs*, int, char *);
867 /*
868 ** The methods above are in version 1 of the sqlite_vfs object
869 ** definition. Those that follow are added in version 2 or later
870 */
871 int (*xRename)(sqlite3_vfs*, const char *zOld, const char *zNew, int dirSync);
872 int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
873 /*
874 ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
875 ** New fields may be appended in figure versions. The iVersion
876 ** value will increment whenever this happens.
877
--- 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-07-06 20:37:10 5621862b0e2fc945ded51f5926a6b4c9f07d0ab7"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -830,20 +830,27 @@
830 ** is also passed as a parameter to both methods. If the output buffer
831 ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is
832 ** handled as a fatal error by SQLite, vfs implementations should endeavor
833 ** to prevent this by setting mxPathname to a sufficiently large value.
834 **
835 ** The xRandomness(), xSleep(), xCurrentTime(), and xCurrentTimeInt64()
836 ** interfaces are not strictly a part of the filesystem, but they are
837 ** included in the VFS structure for completeness.
838 ** The xRandomness() function attempts to return nBytes bytes
839 ** of good-quality randomness into zOut. The return value is
840 ** the actual number of bytes of randomness obtained.
841 ** The xSleep() method causes the calling thread to sleep for at
842 ** least the number of microseconds given. The xCurrentTime()
843 ** method returns a Julian Day Number for the current date and time as
844 ** a floating point value.
845 ** The xCurrentTimeInt64() method returns, as an integer, the Julian
846 ** Day Number multipled by 86400000 (the number of milliseconds in
847 ** a 24-hour day).
848 ** ^SQLite will use the xCurrentTimeInt64() method to get the current
849 ** date and time if that method is available (if iVersion is 2 or
850 ** greater and the function pointer is not NULL) and will fall back
851 ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
852 */
853 typedef struct sqlite3_vfs sqlite3_vfs;
854 struct sqlite3_vfs {
855 int iVersion; /* Structure version number (currently 2) */
856 int szOsFile; /* Size of subclassed sqlite3_file */
@@ -866,11 +873,10 @@
873 int (*xGetLastError)(sqlite3_vfs*, int, char *);
874 /*
875 ** The methods above are in version 1 of the sqlite_vfs object
876 ** definition. Those that follow are added in version 2 or later
877 */
 
878 int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*);
879 /*
880 ** The methods above are in versions 1 and 2 of the sqlite_vfs object.
881 ** New fields may be appended in figure versions. The iVersion
882 ** value will increment whenever this happens.
883

Keyboard Shortcuts

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