Fossil SCM
Update the built-in SQLite to the latest beta of version 3.7.0.
Commit
8733f07f0ab39bf00ef8e17b87d1db37da367757
Parent
710a8ba9938a9fb…
2 files changed
+95
-89
+12
-6
+95
-89
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -636,11 +636,11 @@ | ||
| 636 | 636 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 637 | 637 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 638 | 638 | */ |
| 639 | 639 | #define SQLITE_VERSION "3.7.0" |
| 640 | 640 | #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" | |
| 642 | 642 | |
| 643 | 643 | /* |
| 644 | 644 | ** CAPI3REF: Run-Time Library Version Numbers |
| 645 | 645 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 646 | 646 | ** |
| @@ -1359,20 +1359,27 @@ | ||
| 1359 | 1359 | ** is also passed as a parameter to both methods. If the output buffer |
| 1360 | 1360 | ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is |
| 1361 | 1361 | ** handled as a fatal error by SQLite, vfs implementations should endeavor |
| 1362 | 1362 | ** to prevent this by setting mxPathname to a sufficiently large value. |
| 1363 | 1363 | ** |
| 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 | |
| 1366 | 1366 | ** included in the VFS structure for completeness. |
| 1367 | 1367 | ** The xRandomness() function attempts to return nBytes bytes |
| 1368 | 1368 | ** of good-quality randomness into zOut. The return value is |
| 1369 | 1369 | ** the actual number of bytes of randomness obtained. |
| 1370 | 1370 | ** The xSleep() method causes the calling thread to sleep for at |
| 1371 | 1371 | ** 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. | |
| 1374 | 1381 | */ |
| 1375 | 1382 | typedef struct sqlite3_vfs sqlite3_vfs; |
| 1376 | 1383 | struct sqlite3_vfs { |
| 1377 | 1384 | int iVersion; /* Structure version number (currently 2) */ |
| 1378 | 1385 | int szOsFile; /* Size of subclassed sqlite3_file */ |
| @@ -1395,11 +1402,10 @@ | ||
| 1395 | 1402 | int (*xGetLastError)(sqlite3_vfs*, int, char *); |
| 1396 | 1403 | /* |
| 1397 | 1404 | ** The methods above are in version 1 of the sqlite_vfs object |
| 1398 | 1405 | ** definition. Those that follow are added in version 2 or later |
| 1399 | 1406 | */ |
| 1400 | - int (*xRename)(sqlite3_vfs*, const char *zOld, const char *zNew, int dirSync); | |
| 1401 | 1407 | int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*); |
| 1402 | 1408 | /* |
| 1403 | 1409 | ** The methods above are in versions 1 and 2 of the sqlite_vfs object. |
| 1404 | 1410 | ** New fields may be appended in figure versions. The iVersion |
| 1405 | 1411 | ** value will increment whenever this happens. |
| @@ -28503,11 +28509,10 @@ | ||
| 28503 | 28509 | unixDlClose, /* xDlClose */ \ |
| 28504 | 28510 | unixRandomness, /* xRandomness */ \ |
| 28505 | 28511 | unixSleep, /* xSleep */ \ |
| 28506 | 28512 | unixCurrentTime, /* xCurrentTime */ \ |
| 28507 | 28513 | unixGetLastError, /* xGetLastError */ \ |
| 28508 | - 0, /* xRename */ \ | |
| 28509 | 28514 | unixCurrentTimeInt64, /* xCurrentTimeInt64 */ \ |
| 28510 | 28515 | } |
| 28511 | 28516 | |
| 28512 | 28517 | /* |
| 28513 | 28518 | ** All default VFSes for unix are contained in the following array. |
| @@ -29497,11 +29502,15 @@ | ||
| 29497 | 29502 | SimulateDiskfullError(return SQLITE_FULL); |
| 29498 | 29503 | OSTRACE(("WRITE %d lock=%d\n", pFile->h, pFile->locktype)); |
| 29499 | 29504 | rc = SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN); |
| 29500 | 29505 | if( rc==INVALID_SET_FILE_POINTER && (error=GetLastError())!=NO_ERROR ){ |
| 29501 | 29506 | 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 | + } | |
| 29503 | 29512 | } |
| 29504 | 29513 | assert( amt>0 ); |
| 29505 | 29514 | while( |
| 29506 | 29515 | amt>0 |
| 29507 | 29516 | && (rc = WriteFile(pFile->h, pBuf, amt, &wrote, 0))!=0 |
| @@ -29510,11 +29519,15 @@ | ||
| 29510 | 29519 | amt -= wrote; |
| 29511 | 29520 | pBuf = &((char*)pBuf)[wrote]; |
| 29512 | 29521 | } |
| 29513 | 29522 | if( !rc || amt>(int)wrote ){ |
| 29514 | 29523 | 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 | + } | |
| 29516 | 29529 | } |
| 29517 | 29530 | return SQLITE_OK; |
| 29518 | 29531 | } |
| 29519 | 29532 | |
| 29520 | 29533 | /* |
| @@ -30844,11 +30857,21 @@ | ||
| 30844 | 30857 | UNUSED_PARAMETER(pVfs); |
| 30845 | 30858 | if( zConverted==0 ){ |
| 30846 | 30859 | return SQLITE_NOMEM; |
| 30847 | 30860 | } |
| 30848 | 30861 | 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 | + } | |
| 30850 | 30873 | /* isNT() is 1 if SQLITE_OS_WINCE==1, so this else is never executed. |
| 30851 | 30874 | ** Since the ASCII version of these Windows API do not exist for WINCE, |
| 30852 | 30875 | ** it's important to not reference them for WINCE builds. |
| 30853 | 30876 | */ |
| 30854 | 30877 | #if SQLITE_OS_WINCE==0 |
| @@ -31244,11 +31267,10 @@ | ||
| 31244 | 31267 | winDlClose, /* xDlClose */ |
| 31245 | 31268 | winRandomness, /* xRandomness */ |
| 31246 | 31269 | winSleep, /* xSleep */ |
| 31247 | 31270 | winCurrentTime, /* xCurrentTime */ |
| 31248 | 31271 | winGetLastError, /* xGetLastError */ |
| 31249 | - 0, /* xRename */ | |
| 31250 | 31272 | winCurrentTimeInt64, /* xCurrentTimeInt64 */ |
| 31251 | 31273 | }; |
| 31252 | 31274 | |
| 31253 | 31275 | sqlite3_vfs_register(&winVfs, 1); |
| 31254 | 31276 | return SQLITE_OK; |
| @@ -33981,10 +34003,11 @@ | ||
| 33981 | 34003 | char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */ |
| 33982 | 34004 | PCache *pPCache; /* Pointer to page cache object */ |
| 33983 | 34005 | sqlite3_backup *pBackup; /* Pointer to list of ongoing backup processes */ |
| 33984 | 34006 | #ifndef SQLITE_OMIT_WAL |
| 33985 | 34007 | Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */ |
| 34008 | + char *zWal; /* File name for write-ahead log */ | |
| 33986 | 34009 | #endif |
| 33987 | 34010 | }; |
| 33988 | 34011 | |
| 33989 | 34012 | /* |
| 33990 | 34013 | ** The following global variables hold counters used for |
| @@ -35091,10 +35114,25 @@ | ||
| 35091 | 35114 | i -= 200; |
| 35092 | 35115 | } |
| 35093 | 35116 | return cksum; |
| 35094 | 35117 | } |
| 35095 | 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 | + | |
| 35096 | 35134 | /* |
| 35097 | 35135 | ** Read a single page from either the journal file (if isMainJrnl==1) or |
| 35098 | 35136 | ** from the sub-journal (if isMainJrnl==0) and playback that page. |
| 35099 | 35137 | ** The page begins at offset *pOffset into the file. The *pOffset |
| 35100 | 35138 | ** value is increased to the start of the next page in the journal. |
| @@ -35183,15 +35221,24 @@ | ||
| 35183 | 35221 | if( !isSavepnt && pager_cksum(pPager, (u8*)aData)!=cksum ){ |
| 35184 | 35222 | return SQLITE_DONE; |
| 35185 | 35223 | } |
| 35186 | 35224 | } |
| 35187 | 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 | + */ | |
| 35188 | 35229 | if( pDone && (rc = sqlite3BitvecSet(pDone, pgno))!=SQLITE_OK ){ |
| 35189 | 35230 | return rc; |
| 35190 | 35231 | } |
| 35191 | - | |
| 35192 | 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 | + } | |
| 35193 | 35240 | |
| 35194 | 35241 | /* If the pager is in RESERVED state, then there must be a copy of this |
| 35195 | 35242 | ** page in the pager cache. In this case just update the pager cache, |
| 35196 | 35243 | ** not the database file. The page is left marked dirty in this case. |
| 35197 | 35244 | ** |
| @@ -35987,42 +36034,10 @@ | ||
| 35987 | 36034 | pPager->state = PAGER_SHARED; |
| 35988 | 36035 | |
| 35989 | 36036 | return rc; |
| 35990 | 36037 | } |
| 35991 | 36038 | |
| 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 | 36039 | /* |
| 36025 | 36040 | ** Check if the *-wal file that corresponds to the database opened by pPager |
| 36026 | 36041 | ** exists if the database is not empy, or verify that the *-wal file does |
| 36027 | 36042 | ** not exist (by deleting it) if the database file is empty. |
| 36028 | 36043 | ** |
| @@ -36048,14 +36063,16 @@ | ||
| 36048 | 36063 | int nPage; /* Size of the database file */ |
| 36049 | 36064 | assert( pPager->state>=SHARED_LOCK ); |
| 36050 | 36065 | rc = sqlite3PagerPagecount(pPager, &nPage); |
| 36051 | 36066 | if( rc ) return rc; |
| 36052 | 36067 | if( nPage==0 ){ |
| 36053 | - rc = pagerCheckForOrDeleteWAL(pPager, 0); | |
| 36068 | + rc = sqlite3OsDelete(pPager->pVfs, pPager->zWal, 0); | |
| 36054 | 36069 | isWal = 0; |
| 36055 | 36070 | }else{ |
| 36056 | - rc = pagerCheckForOrDeleteWAL(pPager, &isWal); | |
| 36071 | + rc = sqlite3OsAccess( | |
| 36072 | + pPager->pVfs, pPager->zWal, SQLITE_ACCESS_EXISTS, &isWal | |
| 36073 | + ); | |
| 36057 | 36074 | } |
| 36058 | 36075 | if( rc==SQLITE_OK ){ |
| 36059 | 36076 | if( isWal ){ |
| 36060 | 36077 | pager_reset(pPager); |
| 36061 | 36078 | rc = sqlite3PagerOpenWal(pPager, 0); |
| @@ -36325,25 +36342,10 @@ | ||
| 36325 | 36342 | ){ |
| 36326 | 36343 | pPager->xBusyHandler = xBusyHandler; |
| 36327 | 36344 | pPager->pBusyHandlerArg = pBusyHandlerArg; |
| 36328 | 36345 | } |
| 36329 | 36346 | |
| 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 | 36347 | /* |
| 36346 | 36348 | ** Change the page size used by the Pager object. The new page size |
| 36347 | 36349 | ** is passed in *pPageSize. |
| 36348 | 36350 | ** |
| 36349 | 36351 | ** If the pager is in the error state when this function is called, it |
| @@ -36479,19 +36481,10 @@ | ||
| 36479 | 36481 | /* This routine is only called by btree immediately after creating |
| 36480 | 36482 | ** the Pager object. There has not been an opportunity to transition |
| 36481 | 36483 | ** to WAL mode yet. |
| 36482 | 36484 | */ |
| 36483 | 36485 | 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 | 36486 | |
| 36494 | 36487 | if( isOpen(pPager->fd) ){ |
| 36495 | 36488 | IOTRACE(("DBHDR %p 0 %d\n", pPager, N)) |
| 36496 | 36489 | rc = sqlite3OsRead(pPager->fd, pDest, N, 0); |
| 36497 | 36490 | if( rc==SQLITE_IOERR_SHORT_READ ){ |
| @@ -37339,10 +37332,13 @@ | ||
| 37339 | 37332 | ROUND8(pcacheSize) + /* PCache object */ |
| 37340 | 37333 | ROUND8(pVfs->szOsFile) + /* The main db file */ |
| 37341 | 37334 | journalFileSize * 2 + /* The two journal files */ |
| 37342 | 37335 | nPathname + 1 + /* zFilename */ |
| 37343 | 37336 | nPathname + 8 + 1 /* zJournal */ |
| 37337 | +#ifndef SQLITE_OMIT_WAL | |
| 37338 | + + nPathname + 4 + 1 /* zWal */ | |
| 37339 | +#endif | |
| 37344 | 37340 | ); |
| 37345 | 37341 | assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) ); |
| 37346 | 37342 | if( !pPtr ){ |
| 37347 | 37343 | sqlite3_free(zPathname); |
| 37348 | 37344 | return SQLITE_NOMEM; |
| @@ -37359,11 +37355,20 @@ | ||
| 37359 | 37355 | if( zPathname ){ |
| 37360 | 37356 | pPager->zJournal = (char*)(pPtr += nPathname + 1); |
| 37361 | 37357 | memcpy(pPager->zFilename, zPathname, nPathname); |
| 37362 | 37358 | memcpy(pPager->zJournal, zPathname, nPathname); |
| 37363 | 37359 | 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 | |
| 37365 | 37370 | sqlite3_free(zPathname); |
| 37366 | 37371 | } |
| 37367 | 37372 | pPager->pVfs = pVfs; |
| 37368 | 37373 | pPager->vfsFlags = vfsFlags; |
| 37369 | 37374 | |
| @@ -39651,12 +39656,11 @@ | ||
| 39651 | 39656 | |
| 39652 | 39657 | /* Open the connection to the log file. If this operation fails, |
| 39653 | 39658 | ** (e.g. due to malloc() failure), unlock the database file and |
| 39654 | 39659 | ** return an error code. |
| 39655 | 39660 | */ |
| 39656 | - rc = sqlite3WalOpen(pPager->pVfs, pPager->fd, | |
| 39657 | - pPager->zFilename, &pPager->pWal); | |
| 39661 | + rc = sqlite3WalOpen(pPager->pVfs, pPager->fd, pPager->zWal, &pPager->pWal); | |
| 39658 | 39662 | if( rc==SQLITE_OK ){ |
| 39659 | 39663 | pPager->journalMode = PAGER_JOURNALMODE_WAL; |
| 39660 | 39664 | } |
| 39661 | 39665 | }else{ |
| 39662 | 39666 | *pisOpen = 1; |
| @@ -39685,15 +39689,17 @@ | ||
| 39685 | 39689 | */ |
| 39686 | 39690 | if( !pPager->pWal ){ |
| 39687 | 39691 | int logexists = 0; |
| 39688 | 39692 | rc = sqlite3OsLock(pPager->fd, SQLITE_LOCK_SHARED); |
| 39689 | 39693 | if( rc==SQLITE_OK ){ |
| 39690 | - rc = pagerCheckForOrDeleteWAL(pPager, &logexists); | |
| 39694 | + rc = sqlite3OsAccess( | |
| 39695 | + pPager->pVfs, pPager->zWal, SQLITE_ACCESS_EXISTS, &logexists | |
| 39696 | + ); | |
| 39691 | 39697 | } |
| 39692 | 39698 | if( rc==SQLITE_OK && logexists ){ |
| 39693 | 39699 | rc = sqlite3WalOpen(pPager->pVfs, pPager->fd, |
| 39694 | - pPager->zFilename, &pPager->pWal); | |
| 39700 | + pPager->zWal, &pPager->pWal); | |
| 39695 | 39701 | } |
| 39696 | 39702 | } |
| 39697 | 39703 | |
| 39698 | 39704 | /* Checkpoint and close the log. Because an EXCLUSIVE lock is held on |
| 39699 | 39705 | ** the database file, the log and log-summary files will be deleted. |
| @@ -40152,11 +40158,11 @@ | ||
| 40152 | 40158 | u8 exclusiveMode; /* Non-zero if connection is in exclusive mode */ |
| 40153 | 40159 | u8 isWIndexOpen; /* True if ShmOpen() called on pDbFd */ |
| 40154 | 40160 | u8 writeLock; /* True if in a write transaction */ |
| 40155 | 40161 | u8 ckptLock; /* True if holding a checkpoint lock */ |
| 40156 | 40162 | WalIndexHdr hdr; /* Wal-index header for current transaction */ |
| 40157 | - char *zWalName; /* Name of WAL file */ | |
| 40163 | + const char *zWalName; /* Name of WAL file */ | |
| 40158 | 40164 | u32 nCkpt; /* Checkpoint sequence counter in the wal-header */ |
| 40159 | 40165 | #ifdef SQLITE_DEBUG |
| 40160 | 40166 | u8 lockError; /* True if a locking error has occurred */ |
| 40161 | 40167 | #endif |
| 40162 | 40168 | }; |
| @@ -40907,12 +40913,13 @@ | ||
| 40907 | 40913 | pWal->isWIndexOpen = 0; |
| 40908 | 40914 | } |
| 40909 | 40915 | } |
| 40910 | 40916 | |
| 40911 | 40917 | /* |
| 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. | |
| 40914 | 40921 | ** |
| 40915 | 40922 | ** A SHARED lock should be held on the database file when this function |
| 40916 | 40923 | ** is called. The purpose of this SHARED lock is to prevent any other |
| 40917 | 40924 | ** client from unlinking the WAL or wal-index file. If another process |
| 40918 | 40925 | ** were to do this just after this client opened one of these files, the |
| @@ -40923,20 +40930,18 @@ | ||
| 40923 | 40930 | ** an SQLite error code is returned and *ppWal is left unmodified. |
| 40924 | 40931 | */ |
| 40925 | 40932 | SQLITE_PRIVATE int sqlite3WalOpen( |
| 40926 | 40933 | sqlite3_vfs *pVfs, /* vfs module to open wal and wal-index */ |
| 40927 | 40934 | 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 */ | |
| 40929 | 40936 | Wal **ppWal /* OUT: Allocated Wal handle */ |
| 40930 | 40937 | ){ |
| 40931 | 40938 | int rc; /* Return Code */ |
| 40932 | 40939 | Wal *pRet; /* Object to allocate and return */ |
| 40933 | 40940 | int flags; /* Flags passed to OsOpen() */ |
| 40934 | - char *zWal; /* Name of write-ahead log file */ | |
| 40935 | - int nWal; /* Length of zWal in bytes */ | |
| 40936 | 40941 | |
| 40937 | - assert( zDbName && zDbName[0] ); | |
| 40942 | + assert( zWalName && zWalName[0] ); | |
| 40938 | 40943 | assert( pDbFd ); |
| 40939 | 40944 | |
| 40940 | 40945 | /* In the amalgamation, the os_unix.c and os_win.c source files come before |
| 40941 | 40946 | ** this source file. Verify that the #defines of the locking byte offsets |
| 40942 | 40947 | ** in os_unix.c and os_win.c agree with the WALINDEX_LOCK_OFFSET value. |
| @@ -40949,30 +40954,28 @@ | ||
| 40949 | 40954 | #endif |
| 40950 | 40955 | |
| 40951 | 40956 | |
| 40952 | 40957 | /* Allocate an instance of struct Wal to return. */ |
| 40953 | 40958 | *ppWal = 0; |
| 40954 | - nWal = sqlite3Strlen30(zDbName) + 5; | |
| 40955 | - pRet = (Wal*)sqlite3MallocZero(sizeof(Wal) + pVfs->szOsFile + nWal); | |
| 40959 | + pRet = (Wal*)sqlite3MallocZero(sizeof(Wal) + pVfs->szOsFile); | |
| 40956 | 40960 | if( !pRet ){ |
| 40957 | 40961 | return SQLITE_NOMEM; |
| 40958 | 40962 | } |
| 40959 | 40963 | |
| 40960 | 40964 | pRet->pVfs = pVfs; |
| 40961 | 40965 | pRet->pWalFd = (sqlite3_file *)&pRet[1]; |
| 40962 | 40966 | pRet->pDbFd = pDbFd; |
| 40963 | 40967 | pRet->readLock = -1; |
| 40964 | 40968 | 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; | |
| 40967 | 40970 | rc = sqlite3OsShmOpen(pDbFd); |
| 40968 | 40971 | |
| 40969 | 40972 | /* Open file handle on the write-ahead log file. */ |
| 40970 | 40973 | if( rc==SQLITE_OK ){ |
| 40971 | 40974 | pRet->isWIndexOpen = 1; |
| 40972 | 40975 | 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); | |
| 40974 | 40977 | } |
| 40975 | 40978 | |
| 40976 | 40979 | if( rc!=SQLITE_OK ){ |
| 40977 | 40980 | walIndexClose(pRet, 0); |
| 40978 | 40981 | sqlite3OsClose(pRet->pWalFd); |
| @@ -84648,25 +84651,28 @@ | ||
| 84648 | 84651 | ** or executed. All the parser does is build the internal data |
| 84649 | 84652 | ** structures that describe the table, index, or view. |
| 84650 | 84653 | */ |
| 84651 | 84654 | int rc; |
| 84652 | 84655 | sqlite3_stmt *pStmt; |
| 84656 | + TESTONLY(int rcp); /* Return code from sqlite3_prepare() */ | |
| 84653 | 84657 | |
| 84654 | 84658 | assert( db->init.busy ); |
| 84655 | 84659 | db->init.iDb = iDb; |
| 84656 | 84660 | db->init.newTnum = atoi(argv[1]); |
| 84657 | 84661 | 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) ); | |
| 84659 | 84665 | db->init.iDb = 0; |
| 84660 | 84666 | if( SQLITE_OK!=rc ){ |
| 84661 | 84667 | if( db->init.orphanTrigger ){ |
| 84662 | 84668 | assert( iDb==1 ); |
| 84663 | 84669 | }else{ |
| 84664 | 84670 | pData->rc = rc; |
| 84665 | 84671 | if( rc==SQLITE_NOMEM ){ |
| 84666 | 84672 | db->mallocFailed = 1; |
| 84667 | - }else if( rc!=SQLITE_INTERRUPT && rc!=SQLITE_LOCKED ){ | |
| 84673 | + }else if( rc!=SQLITE_INTERRUPT && (rc&0xFF)!=SQLITE_LOCKED ){ | |
| 84668 | 84674 | corruptSchema(pData, argv[0], sqlite3_errmsg(db)); |
| 84669 | 84675 | } |
| 84670 | 84676 | } |
| 84671 | 84677 | } |
| 84672 | 84678 | sqlite3_finalize(pStmt); |
| 84673 | 84679 |
| --- 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 @@ | ||
| 107 | 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | 109 | */ |
| 110 | 110 | #define SQLITE_VERSION "3.7.0" |
| 111 | 111 | #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" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| @@ -830,20 +830,27 @@ | ||
| 830 | 830 | ** is also passed as a parameter to both methods. If the output buffer |
| 831 | 831 | ** is not large enough, [SQLITE_CANTOPEN] should be returned. Since this is |
| 832 | 832 | ** handled as a fatal error by SQLite, vfs implementations should endeavor |
| 833 | 833 | ** to prevent this by setting mxPathname to a sufficiently large value. |
| 834 | 834 | ** |
| 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 | |
| 837 | 837 | ** included in the VFS structure for completeness. |
| 838 | 838 | ** The xRandomness() function attempts to return nBytes bytes |
| 839 | 839 | ** of good-quality randomness into zOut. The return value is |
| 840 | 840 | ** the actual number of bytes of randomness obtained. |
| 841 | 841 | ** The xSleep() method causes the calling thread to sleep for at |
| 842 | 842 | ** 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. | |
| 845 | 852 | */ |
| 846 | 853 | typedef struct sqlite3_vfs sqlite3_vfs; |
| 847 | 854 | struct sqlite3_vfs { |
| 848 | 855 | int iVersion; /* Structure version number (currently 2) */ |
| 849 | 856 | int szOsFile; /* Size of subclassed sqlite3_file */ |
| @@ -866,11 +873,10 @@ | ||
| 866 | 873 | int (*xGetLastError)(sqlite3_vfs*, int, char *); |
| 867 | 874 | /* |
| 868 | 875 | ** The methods above are in version 1 of the sqlite_vfs object |
| 869 | 876 | ** definition. Those that follow are added in version 2 or later |
| 870 | 877 | */ |
| 871 | - int (*xRename)(sqlite3_vfs*, const char *zOld, const char *zNew, int dirSync); | |
| 872 | 878 | int (*xCurrentTimeInt64)(sqlite3_vfs*, sqlite3_int64*); |
| 873 | 879 | /* |
| 874 | 880 | ** The methods above are in versions 1 and 2 of the sqlite_vfs object. |
| 875 | 881 | ** New fields may be appended in figure versions. The iVersion |
| 876 | 882 | ** value will increment whenever this happens. |
| 877 | 883 |
| --- 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 |