| | @@ -452,11 +452,11 @@ |
| 452 | 452 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 453 | 453 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 454 | 454 | */ |
| 455 | 455 | #define SQLITE_VERSION "3.40.0" |
| 456 | 456 | #define SQLITE_VERSION_NUMBER 3040000 |
| 457 | | -#define SQLITE_SOURCE_ID "2022-11-04 16:39:39 0e5597ce5353dea2cdb092b166b57ba1d60f8115eb468349f2b2869803691a2c" |
| 457 | +#define SQLITE_SOURCE_ID "2022-11-07 18:36:02 3645585f37631d60cefab1d55cdb1ee060aae87317b9b158a01329ca8a4d3e1e" |
| 458 | 458 | |
| 459 | 459 | /* |
| 460 | 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | 462 | ** |
| | @@ -6178,13 +6178,14 @@ |
| 6178 | 6178 | ** application-defined function to be a text string in an encoding |
| 6179 | 6179 | ** specified by the fifth (and last) parameter, which must be one |
| 6180 | 6180 | ** of [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]. |
| 6181 | 6181 | ** ^SQLite takes the text result from the application from |
| 6182 | 6182 | ** the 2nd parameter of the sqlite3_result_text* interfaces. |
| 6183 | | -** ^If the 3rd parameter to the sqlite3_result_text* interfaces |
| 6184 | | -** is negative, then SQLite takes result text from the 2nd parameter |
| 6185 | | -** through the first zero character. |
| 6183 | +** ^If the 3rd parameter to any of the sqlite3_result_text* interfaces |
| 6184 | +** other than sqlite3_result_text64() is negative, then SQLite computes |
| 6185 | +** the string length itself by searching the 2nd parameter for the first |
| 6186 | +** zero character. |
| 6186 | 6187 | ** ^If the 3rd parameter to the sqlite3_result_text* interfaces |
| 6187 | 6188 | ** is non-negative, then as many bytes (not characters) of the text |
| 6188 | 6189 | ** pointed to by the 2nd parameter are taken as the application-defined |
| 6189 | 6190 | ** function result. If the 3rd parameter is non-negative, then it |
| 6190 | 6191 | ** must be the byte offset into the string where the NUL terminator would |
| | @@ -49485,13 +49486,14 @@ |
| 49485 | 49486 | } |
| 49486 | 49487 | return 0; |
| 49487 | 49488 | } |
| 49488 | 49489 | |
| 49489 | 49490 | /* |
| 49490 | | -** If sqlite3_temp_directory is not, take the mutex and return true. |
| 49491 | +** If sqlite3_temp_directory is defined, take the mutex and return true. |
| 49491 | 49492 | ** |
| 49492 | | -** If sqlite3_temp_directory is NULL, omit the mutex and return false. |
| 49493 | +** If sqlite3_temp_directory is NULL (undefined), omit the mutex and |
| 49494 | +** return false. |
| 49493 | 49495 | */ |
| 49494 | 49496 | static int winTempDirDefined(void){ |
| 49495 | 49497 | sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR)); |
| 49496 | 49498 | if( sqlite3_temp_directory!=0 ) return 1; |
| 49497 | 49499 | sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_TEMPDIR)); |
| | @@ -74325,12 +74327,12 @@ |
| 74325 | 74327 | |
| 74326 | 74328 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 74327 | 74329 | assert( eMode==BTALLOC_ANY || (nearby>0 && IfNotOmitAV(pBt->autoVacuum)) ); |
| 74328 | 74330 | pPage1 = pBt->pPage1; |
| 74329 | 74331 | mxPage = btreePagecount(pBt); |
| 74330 | | - /* EVIDENCE-OF: R-05119-02637 The 4-byte big-endian integer at offset 36 |
| 74331 | | - ** stores stores the total number of pages on the freelist. */ |
| 74332 | + /* EVIDENCE-OF: R-21003-45125 The 4-byte big-endian integer at offset 36 |
| 74333 | + ** stores the total number of pages on the freelist. */ |
| 74332 | 74334 | n = get4byte(&pPage1->aData[36]); |
| 74333 | 74335 | testcase( n==mxPage-1 ); |
| 74334 | 74336 | if( n>=mxPage ){ |
| 74335 | 74337 | return SQLITE_CORRUPT_BKPT; |
| 74336 | 74338 | } |
| | @@ -140949,12 +140951,12 @@ |
| 140949 | 140951 | |
| 140950 | 140952 | /* Jump to the this point in order to terminate the query. |
| 140951 | 140953 | */ |
| 140952 | 140954 | sqlite3VdbeResolveLabel(v, labelEnd); |
| 140953 | 140955 | |
| 140954 | | - /* Reassemble the compound query so that it will be freed correctly |
| 140955 | | - ** by the calling function */ |
| 140956 | + /* Make arrangements to free the 2nd and subsequent arms of the compound |
| 140957 | + ** after the parse has finished */ |
| 140956 | 140958 | if( pSplit->pPrior ){ |
| 140957 | 140959 | sqlite3ParserAddCleanup(pParse, |
| 140958 | 140960 | (void(*)(sqlite3*,void*))sqlite3SelectDelete, pSplit->pPrior); |
| 140959 | 140961 | } |
| 140960 | 140962 | pSplit->pPrior = pPrior; |
| | @@ -207732,10 +207734,38 @@ |
| 207732 | 207734 | #define SQLITE_RBU_STATE_CHECKPOINT 3 |
| 207733 | 207735 | #define SQLITE_RBU_STATE_DONE 4 |
| 207734 | 207736 | #define SQLITE_RBU_STATE_ERROR 5 |
| 207735 | 207737 | |
| 207736 | 207738 | SQLITE_API int sqlite3rbu_state(sqlite3rbu *pRbu); |
| 207739 | + |
| 207740 | +/* |
| 207741 | +** As part of applying an RBU update or performing an RBU vacuum operation, |
| 207742 | +** the system must at one point move the *-oal file to the equivalent *-wal |
| 207743 | +** path. Normally, it does this by invoking POSIX function rename(2) directly. |
| 207744 | +** Except on WINCE platforms, where it uses win32 API MoveFileW(). This |
| 207745 | +** function may be used to register a callback that the RBU module will invoke |
| 207746 | +** instead of one of these APIs. |
| 207747 | +** |
| 207748 | +** If a callback is registered with an RBU handle, it invokes it instead |
| 207749 | +** of rename(2) when it needs to move a file within the file-system. The |
| 207750 | +** first argument passed to the xRename() callback is a copy of the second |
| 207751 | +** argument (pArg) passed to this function. The second is the full path |
| 207752 | +** to the file to move and the third the full path to which it should be |
| 207753 | +** moved. The callback function should return SQLITE_OK to indicate |
| 207754 | +** success. If an error occurs, it should return an SQLite error code. |
| 207755 | +** In this case the RBU operation will be abandoned and the error returned |
| 207756 | +** to the RBU user. |
| 207757 | +** |
| 207758 | +** Passing a NULL pointer in place of the xRename argument to this function |
| 207759 | +** restores the default behaviour. |
| 207760 | +*/ |
| 207761 | +SQLITE_API void sqlite3rbu_rename_handler( |
| 207762 | + sqlite3rbu *pRbu, |
| 207763 | + void *pArg, |
| 207764 | + int (*xRename)(void *pArg, const char *zOld, const char *zNew) |
| 207765 | +); |
| 207766 | + |
| 207737 | 207767 | |
| 207738 | 207768 | /* |
| 207739 | 207769 | ** Create an RBU VFS named zName that accesses the underlying file-system |
| 207740 | 207770 | ** via existing VFS zParent. Or, if the zParent parameter is passed NULL, |
| 207741 | 207771 | ** then the new RBU VFS uses the default system VFS to access the file-system. |
| | @@ -208100,10 +208130,12 @@ |
| 208100 | 208130 | const char *zVfsName; /* Name of automatically created rbu vfs */ |
| 208101 | 208131 | rbu_file *pTargetFd; /* File handle open on target db */ |
| 208102 | 208132 | int nPagePerSector; /* Pages per sector for pTargetFd */ |
| 208103 | 208133 | i64 iOalSz; |
| 208104 | 208134 | i64 nPhaseOneStep; |
| 208135 | + void *pRenameArg; |
| 208136 | + int (*xRename)(void*, const char*, const char*); |
| 208105 | 208137 | |
| 208106 | 208138 | /* The following state variables are used as part of the incremental |
| 208107 | 208139 | ** checkpoint stage (eStage==RBU_STAGE_CKPT). See comments surrounding |
| 208108 | 208140 | ** function rbuSetupCheckpoint() for details. */ |
| 208109 | 208141 | u32 iMaxFrame; /* Largest iWalFrame value in aFrame[] */ |
| | @@ -210948,36 +210980,11 @@ |
| 210948 | 210980 | assert( p->rc==SQLITE_OK ); |
| 210949 | 210981 | p->rc = rbuLockDatabase(dbMain); |
| 210950 | 210982 | } |
| 210951 | 210983 | |
| 210952 | 210984 | if( p->rc==SQLITE_OK ){ |
| 210953 | | -#if defined(_WIN32_WCE) |
| 210954 | | - { |
| 210955 | | - LPWSTR zWideOal; |
| 210956 | | - LPWSTR zWideWal; |
| 210957 | | - |
| 210958 | | - zWideOal = rbuWinUtf8ToUnicode(zOal); |
| 210959 | | - if( zWideOal ){ |
| 210960 | | - zWideWal = rbuWinUtf8ToUnicode(zWal); |
| 210961 | | - if( zWideWal ){ |
| 210962 | | - if( MoveFileW(zWideOal, zWideWal) ){ |
| 210963 | | - p->rc = SQLITE_OK; |
| 210964 | | - }else{ |
| 210965 | | - p->rc = SQLITE_IOERR; |
| 210966 | | - } |
| 210967 | | - sqlite3_free(zWideWal); |
| 210968 | | - }else{ |
| 210969 | | - p->rc = SQLITE_IOERR_NOMEM; |
| 210970 | | - } |
| 210971 | | - sqlite3_free(zWideOal); |
| 210972 | | - }else{ |
| 210973 | | - p->rc = SQLITE_IOERR_NOMEM; |
| 210974 | | - } |
| 210975 | | - } |
| 210976 | | -#else |
| 210977 | | - p->rc = rename(zOal, zWal) ? SQLITE_IOERR : SQLITE_OK; |
| 210978 | | -#endif |
| 210985 | + p->rc = p->xRename(p->pRenameArg, zOal, zWal); |
| 210979 | 210986 | } |
| 210980 | 210987 | |
| 210981 | 210988 | if( p->rc!=SQLITE_OK |
| 210982 | 210989 | || rbuIsVacuum(p) |
| 210983 | 210990 | || rbuExclusiveCheckpoint(dbMain)==0 |
| | @@ -211712,10 +211719,11 @@ |
| 211712 | 211719 | if( p ){ |
| 211713 | 211720 | RbuState *pState = 0; |
| 211714 | 211721 | |
| 211715 | 211722 | /* Create the custom VFS. */ |
| 211716 | 211723 | memset(p, 0, sizeof(sqlite3rbu)); |
| 211724 | + sqlite3rbu_rename_handler(p, 0, 0); |
| 211717 | 211725 | rbuCreateVfs(p); |
| 211718 | 211726 | |
| 211719 | 211727 | /* Open the target, RBU and state databases */ |
| 211720 | 211728 | if( p->rc==SQLITE_OK ){ |
| 211721 | 211729 | char *pCsr = (char*)&p[1]; |
| | @@ -212102,10 +212110,58 @@ |
| 212102 | 212110 | } |
| 212103 | 212111 | |
| 212104 | 212112 | p->rc = rc; |
| 212105 | 212113 | return rc; |
| 212106 | 212114 | } |
| 212115 | + |
| 212116 | +/* |
| 212117 | +** Default xRename callback for RBU. |
| 212118 | +*/ |
| 212119 | +static int xDefaultRename(void *pArg, const char *zOld, const char *zNew){ |
| 212120 | + int rc = SQLITE_OK; |
| 212121 | +#if defined(_WIN32_WCE) |
| 212122 | + { |
| 212123 | + LPWSTR zWideOld; |
| 212124 | + LPWSTR zWideNew; |
| 212125 | + |
| 212126 | + zWideOld = rbuWinUtf8ToUnicode(zOld); |
| 212127 | + if( zWideOld ){ |
| 212128 | + zWideNew = rbuWinUtf8ToUnicode(zNew); |
| 212129 | + if( zWideNew ){ |
| 212130 | + if( MoveFileW(zWideOld, zWideNew) ){ |
| 212131 | + rc = SQLITE_OK; |
| 212132 | + }else{ |
| 212133 | + rc = SQLITE_IOERR; |
| 212134 | + } |
| 212135 | + sqlite3_free(zWideNew); |
| 212136 | + }else{ |
| 212137 | + rc = SQLITE_IOERR_NOMEM; |
| 212138 | + } |
| 212139 | + sqlite3_free(zWideOld); |
| 212140 | + }else{ |
| 212141 | + rc = SQLITE_IOERR_NOMEM; |
| 212142 | + } |
| 212143 | + } |
| 212144 | +#else |
| 212145 | + rc = rename(zOld, zNew) ? SQLITE_IOERR : SQLITE_OK; |
| 212146 | +#endif |
| 212147 | + return rc; |
| 212148 | +} |
| 212149 | + |
| 212150 | +SQLITE_API void sqlite3rbu_rename_handler( |
| 212151 | + sqlite3rbu *pRbu, |
| 212152 | + void *pArg, |
| 212153 | + int (*xRename)(void *pArg, const char *zOld, const char *zNew) |
| 212154 | +){ |
| 212155 | + if( xRename ){ |
| 212156 | + pRbu->xRename = xRename; |
| 212157 | + pRbu->pRenameArg = pArg; |
| 212158 | + }else{ |
| 212159 | + pRbu->xRename = xDefaultRename; |
| 212160 | + pRbu->pRenameArg = 0; |
| 212161 | + } |
| 212162 | +} |
| 212107 | 212163 | |
| 212108 | 212164 | /************************************************************************** |
| 212109 | 212165 | ** Beginning of RBU VFS shim methods. The VFS shim modifies the behaviour |
| 212110 | 212166 | ** of a standard VFS in the following ways: |
| 212111 | 212167 | ** |
| | @@ -238472,11 +238528,11 @@ |
| 238472 | 238528 | int nArg, /* Number of args */ |
| 238473 | 238529 | sqlite3_value **apUnused /* Function arguments */ |
| 238474 | 238530 | ){ |
| 238475 | 238531 | assert( nArg==0 ); |
| 238476 | 238532 | UNUSED_PARAM2(nArg, apUnused); |
| 238477 | | - sqlite3_result_text(pCtx, "fts5: 2022-11-04 16:39:39 0e5597ce5353dea2cdb092b166b57ba1d60f8115eb468349f2b2869803691a2c", -1, SQLITE_TRANSIENT); |
| 238533 | + sqlite3_result_text(pCtx, "fts5: 2022-11-07 18:36:02 3645585f37631d60cefab1d55cdb1ee060aae87317b9b158a01329ca8a4d3e1e", -1, SQLITE_TRANSIENT); |
| 238478 | 238534 | } |
| 238479 | 238535 | |
| 238480 | 238536 | /* |
| 238481 | 238537 | ** Return true if zName is the extension on one of the shadow tables used |
| 238482 | 238538 | ** by this module. |
| 238483 | 238539 | |