diff --git a/patch/0001-History-features-on-OH.patch b/patch/0001-History-features-on-OH.patch index 84d4bc3123bf9154b7f17d916b163e9fb101152d..773dbbb5480e56598e54636dcc12eae37a2bd04b 100644 --- a/patch/0001-History-features-on-OH.patch +++ b/patch/0001-History-features-on-OH.patch @@ -2397,7 +2397,7 @@ index 730b247..b132937 100644 + if(sqlite3CodecCheckHmac(keyCtx, pgno, inputBuffer.bufferSize + keyCtx->codecConst.initVectorSize, input, input + inputBuffer.bufferSize + keyCtx->codecConst.initVectorSize)){ + sqlite3_log(SQLITE_ERROR, "codec: check hmac error at page %d, hmac %d, kdf %d, pageSize %d, iter %d.", + pgno, keyCtx->codecConst.hmacAlgo, keyCtx->codecConst.kdfAlgo, keyCtx->codecConst.cipherPageSize, keyCtx->iter); -+ return pgno == 1 ? SQLITE_NOTADB : SQLITE_CORRUPT; ++ return pgno == 1 ? SQLITE_NOTADB : SQLITE_ERROR; + } + unsigned char *initVector = input + inputBuffer.bufferSize; + void *cipherCtx = opensslGetCtx(keyCtx->codecConst.cipher, CODEC_OPERATION_DECRYPT, keyCtx->key, initVector); diff --git a/patch/0012-Bugfix-on-current-version.patch b/patch/0012-Bugfix-on-current-version.patch index 351906634d7da316f655b5cd2edae9bd7e2a008e..4284a6f55e976976da535aa852813e01eab53425 100644 --- a/patch/0012-Bugfix-on-current-version.patch +++ b/patch/0012-Bugfix-on-current-version.patch @@ -1,13 +1,13 @@ -From c5761b4ffbe2376f9f7ee1c67f139ecd214dd364 Mon Sep 17 00:00:00 2001 +From 61984da0804f6d602bde57125322482d0ce1f0ba Mon Sep 17 00:00:00 2001 From: MartinChoo <214582617@qq.com> Date: Thu, 14 Aug 2025 19:51:56 +0800 Subject: [PATCH] Bugfix on current version --- ext/misc/cksumvfs.c | 11 +- - src/compressvfs.c | 270 ++++++++++++++++++++++++------------ - src/sqlite3.c | 327 ++++++++++++++++++++++++++++++++++++-------- - 3 files changed, 458 insertions(+), 150 deletions(-) + src/compressvfs.c | 271 +++++++++++++++++++++++----------- + src/sqlite3.c | 349 ++++++++++++++++++++++++++++++++++++-------- + 3 files changed, 481 insertions(+), 150 deletions(-) diff --git a/ext/misc/cksumvfs.c b/ext/misc/cksumvfs.c index 27b1028..e89edcd 100644 @@ -53,7 +53,7 @@ index 27b1028..e89edcd 100644 ((u8*)zBuf)[iAmt-CKSUMVFS_RESERVED_SIZE]=CKSUMVFS_MAGIC_NUM; ((u8*)zBuf)[iAmt-CKSUMVFS_RESERVED_SIZE+1]=p->verifyCksm ? CKSUMVFS_CALC_CHECKSUM : CKSUMVFS_WITHOUT_CHECKSUM; diff --git a/src/compressvfs.c b/src/compressvfs.c -index f2fe169..5f5ec20 100644 +index f2fe169..64a1421 100644 --- a/src/compressvfs.c +++ b/src/compressvfs.c @@ -151,6 +151,7 @@ typedef INT8_TYPE i8; /* 1-byte signed integer */ @@ -377,7 +377,7 @@ index f2fe169..5f5ec20 100644 } return rc; } -@@ -888,6 +926,39 @@ static int compressUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage +@@ -888,6 +926,40 @@ static int compressUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage return SQLITE_OK; } @@ -409,6 +409,7 @@ index f2fe169..5f5ec20 100644 + if( rc!=SQLITE_OK ){ + sqlite3_log(rc, "Compress vfs lock file open wrong, path:%s, flag(%d)", lockPath, flags); + sqlite3_free(pLockFd); ++ return rc; + } + *pFile = pLockFd; + return rc; @@ -417,7 +418,7 @@ index f2fe169..5f5ec20 100644 /* ** Open a compress file.If this file is not a journal or wal file, ** it will open a OutterDB and create vfs_pages and vfs_compression table -@@ -902,87 +973,114 @@ static int compressOpen( +@@ -902,87 +974,114 @@ static int compressOpen( ){ sqlite3_file *pSubFile = ORIGFILE(pFile); CompressFile *pCompress = (CompressFile *)pFile; @@ -562,7 +563,7 @@ index f2fe169..5f5ec20 100644 } diff --git a/src/sqlite3.c b/src/sqlite3.c -index 0cdb348..399c6b1 100644 +index 692520d..ff0f0b4 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c @@ -5363,7 +5363,7 @@ SQLITE_API int sqlite3_set_droptable_handle(sqlite3*, void (*xFunc)(sqlite3*,con @@ -620,7 +621,44 @@ index 0cdb348..399c6b1 100644 } } -@@ -57976,6 +57984,8 @@ static void MetaDwrCheckVacuum(BtShared *pBt); +@@ -42226,6 +42234,24 @@ static int openDirectory(const char *zFilename, int *pFd){ + return unixLogError(SQLITE_CANTOPEN_BKPT, "openDirectory", zDirname); + } + ++#ifdef LOG_DUMP ++static int unixCurrentTimeInt64(sqlite3_vfs *NotUsed, sqlite3_int64 *piNow); ++static int dirSyncTimeCostAlert(int fd, int fullSync, int dataOnly) ++{ ++ sqlite3_int64 startTimeMs = 0; ++ sqlite3_int64 endTimeMs = 0; ++ // unixCurrentTimeInt64 always return OK ++ (void)unixCurrentTimeInt64(0, &startTimeMs); ++ int rc = full_fsync(fd, 0, 0); ++ (void)unixCurrentTimeInt64(0, &endTimeMs); ++ // 1500 ms ++ if (unlikely(endTimeMs >= (startTimeMs + 1500))) { ++ sqlite3_log(SQLITE_WARNING_DUMP, "[SQLite]Dir sync takes %lld ms", endTimeMs - startTimeMs); ++ } ++ return rc; ++} ++#endif ++ + /* + ** Make sure all writes to a particular file are committed to disk. + ** +@@ -42277,7 +42303,11 @@ static int unixSync(sqlite3_file *id, int flags){ + HAVE_FULLFSYNC, isFullsync)); + rc = osOpenDirectory(pFile->zPath, &dirfd); + if( rc==SQLITE_OK ){ ++#ifndef LOG_DUMP + full_fsync(dirfd, 0, 0); ++#else ++ dirSyncTimeCostAlert(dirfd, 0, 0); ++#endif + robust_close(pFile, dirfd, __LINE__); + }else{ + assert( rc==SQLITE_CANTOPEN ); +@@ -57976,6 +58006,8 @@ static void MetaDwrCheckVacuum(BtShared *pBt); static int MetaDwrRecoverAndBeginTran(Btree *pBt, int wrflag, int *pSchemaVersion); static int MetaDwrOpenAndCheck(Btree *pBt); static void MetaDwrDisable(Btree *pBt); @@ -629,7 +667,7 @@ index 0cdb348..399c6b1 100644 #define META_HEADER_CHANGED 1 #define META_SCHEMA_CHANGED 2 #define META_IN_RECOVERY 1 -@@ -58253,6 +58263,9 @@ struct Pager { +@@ -58253,6 +58285,9 @@ struct Pager { void *metaMapPage; int (*xGetMethod)(Pager*,Pgno,DbPage**,int); /* Routine to fetch a patch */ #endif @@ -639,7 +677,7 @@ index 0cdb348..399c6b1 100644 }; /* -@@ -59754,11 +59767,12 @@ static int pager_end_transaction(Pager *pPager, int hasSuper, int bCommit){ +@@ -59754,11 +59789,12 @@ static int pager_end_transaction(Pager *pPager, int hasSuper, int bCommit){ sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize); } #ifdef SQLITE_META_DWR @@ -657,7 +695,7 @@ index 0cdb348..399c6b1 100644 } #endif if( pagerUseWal(pPager) ){ -@@ -62547,7 +62561,8 @@ SQLITE_PRIVATE int sqlite3PagerOpen( +@@ -62547,7 +62583,8 @@ SQLITE_PRIVATE int sqlite3PagerOpen( ** specific formatting and order of the various filenames, so if the format ** changes here, be sure to change it there as well. ** @@ -667,7 +705,7 @@ index 0cdb348..399c6b1 100644 ** So the final layout in memory is as follows: ** ** Pager object (sizeof(Pager) bytes) -@@ -62561,13 +62576,16 @@ SQLITE_PRIVATE int sqlite3PagerOpen( +@@ -62561,13 +62598,16 @@ SQLITE_PRIVATE int sqlite3PagerOpen( ** URI query parameters (nUriByte bytes) ** Journal filename (nPathname+16+1 bytes) ** WAL filename (nPathname+12+1 bytes) @@ -684,7 +722,7 @@ index 0cdb348..399c6b1 100644 } #endif assert( SQLITE_PTRSIZE==sizeof(Pager*) ); -@@ -62583,6 +62601,9 @@ SQLITE_PRIVATE int sqlite3PagerOpen( +@@ -62583,6 +62623,9 @@ SQLITE_PRIVATE int sqlite3PagerOpen( nPathname + 8 + fileExtSz + 1 + /* Journal filename */ #ifndef SQLITE_OMIT_WAL nPathname + 4 + fileExtSz + 1 + /* WAL filename */ @@ -694,7 +732,7 @@ index 0cdb348..399c6b1 100644 #endif 3 /* Terminator */ ); -@@ -62651,6 +62672,19 @@ SQLITE_PRIVATE int sqlite3PagerOpen( +@@ -62651,6 +62694,19 @@ SQLITE_PRIVATE int sqlite3PagerOpen( pPager->zWal = 0; } #endif @@ -714,7 +752,7 @@ index 0cdb348..399c6b1 100644 (void)pPtr; /* Suppress warning about unused pPtr value */ if( nPathname ) sqlite3DbFree(0, zPathname); -@@ -73773,7 +73807,13 @@ static void zeroPage(MemPage *pPage, int flags){ +@@ -73773,7 +73829,13 @@ static void zeroPage(MemPage *pPage, int flags){ data[hdr+7] = 0; put2byte(&data[hdr+5], pBt->usableSize); pPage->nFree = (u16)(pBt->usableSize - first); @@ -729,7 +767,7 @@ index 0cdb348..399c6b1 100644 pPage->cellOffset = first; pPage->aDataEnd = &data[pBt->pageSize]; pPage->aCellIdx = &data[first]; -@@ -73982,7 +74022,9 @@ static void pageReinit(DbPage *pData){ +@@ -73982,7 +74044,9 @@ static void pageReinit(DbPage *pData){ ** But no harm is done by this. And it is very important that ** btreeInitPage() be called on every btree page so we make ** the call for every page that comes in for re-initializing. */ @@ -740,7 +778,7 @@ index 0cdb348..399c6b1 100644 } } } -@@ -74898,6 +74940,11 @@ static int lockBtree(BtShared *pBt){ +@@ -74898,6 +74962,11 @@ static int lockBtree(BtShared *pBt){ } if( nPage>nPageFile ){ if( sqlite3WritableSchema(pBt->db)==0 ){ @@ -752,7 +790,7 @@ index 0cdb348..399c6b1 100644 rc = SQLITE_CORRUPT_BKPT; goto page1_init_failed; }else{ -@@ -92357,8 +92404,9 @@ SQLITE_API int sqlite3_set_droptable_handle(sqlite3 *db, void (*xFunc)(sqlite3*, +@@ -92357,8 +92426,9 @@ SQLITE_API int sqlite3_set_droptable_handle(sqlite3 *db, void (*xFunc)(sqlite3*, #endif /* SQLITE_ENABLE_DROPTABLE_CALLBACK */ #ifdef SQLITE_ENABLE_BINLOG @@ -763,7 +801,7 @@ index 0cdb348..399c6b1 100644 return SQLITE_ERROR; } -@@ -116854,7 +116902,9 @@ static void findOrCreateAggInfoColumn( +@@ -116854,7 +116924,9 @@ static void findOrCreateAggInfoColumn( ){ struct AggInfo_col *pCol; int k; @@ -773,7 +811,7 @@ index 0cdb348..399c6b1 100644 assert( pAggInfo->iFirstReg==0 ); pCol = pAggInfo->aCol; for(k=0; knColumn; k++, pCol++){ -@@ -116872,6 +116922,10 @@ static void findOrCreateAggInfoColumn( +@@ -116872,6 +116944,10 @@ static void findOrCreateAggInfoColumn( assert( pParse->db->mallocFailed ); return; } @@ -784,7 +822,7 @@ index 0cdb348..399c6b1 100644 pCol = &pAggInfo->aCol[k]; assert( ExprUseYTab(pExpr) ); pCol->pTab = pExpr->y.pTab; -@@ -116905,6 +116959,7 @@ fix_up_expr: +@@ -116905,6 +116981,7 @@ fix_up_expr: if( pExpr->op==TK_COLUMN ){ pExpr->op = TK_AGG_COLUMN; } @@ -792,7 +830,7 @@ index 0cdb348..399c6b1 100644 pExpr->iAgg = (i16)k; } -@@ -116988,13 +117043,19 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){ +@@ -116988,13 +117065,19 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){ ** function that is already in the pAggInfo structure */ struct AggInfo_func *pItem = pAggInfo->aFunc; @@ -813,7 +851,7 @@ index 0cdb348..399c6b1 100644 /* pExpr is original. Make a new entry in pAggInfo->aFunc[] */ u8 enc = ENC(pParse->db); -@@ -117046,6 +117107,7 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){ +@@ -117046,6 +117129,7 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){ */ assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) ); ExprSetVVAProperty(pExpr, EP_NoReduce); @@ -821,7 +859,7 @@ index 0cdb348..399c6b1 100644 pExpr->iAgg = (i16)i; pExpr->pAggInfo = pAggInfo; return WRC_Prune; -@@ -121758,8 +121820,8 @@ static void attachFunc( +@@ -121758,8 +121842,8 @@ static void attachFunc( if( rc==SQLITE_OK ){ extern int sqlite3CodecAttach(sqlite3*, int, const void*, int); extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*); @@ -832,7 +870,7 @@ index 0cdb348..399c6b1 100644 int t = sqlite3_value_type(argv[2]); switch( t ){ case SQLITE_INTEGER: -@@ -121776,14 +121838,7 @@ static void attachFunc( +@@ -121776,14 +121860,7 @@ static void attachFunc( break; case SQLITE_NULL: @@ -848,7 +886,7 @@ index 0cdb348..399c6b1 100644 break; } } -@@ -184151,10 +184206,12 @@ opendb_out: +@@ -184151,10 +184228,12 @@ opendb_out: db->eOpenState = SQLITE_STATE_SICK; } #ifdef SQLITE_ENABLE_DROPTABLE_CALLBACK @@ -865,7 +903,7 @@ index 0cdb348..399c6b1 100644 #endif /* SQLITE_ENABLE_DROPTABLE_CALLBACK */ #ifdef SQLITE_ENABLE_BINLOG sqlite3BinlogReset(db); -@@ -204600,6 +204657,39 @@ static int fts3ExprTermOffsetInit(Fts3Expr *pExpr, int iPhrase, void *ctx){ +@@ -204600,6 +204679,39 @@ static int fts3ExprTermOffsetInit(Fts3Expr *pExpr, int iPhrase, void *ctx){ return rc; } @@ -905,7 +943,7 @@ index 0cdb348..399c6b1 100644 /* ** Implementation of offsets() function. */ -@@ -204636,6 +204726,12 @@ SQLITE_PRIVATE void sqlite3Fts3Offsets( +@@ -204636,6 +204748,12 @@ SQLITE_PRIVATE void sqlite3Fts3Offsets( sCtx.iDocid = pCsr->iPrevId; sCtx.pCsr = pCsr; @@ -918,7 +956,7 @@ index 0cdb348..399c6b1 100644 /* Loop through the table columns, appending offset information to ** string-buffer res for each column. */ -@@ -254823,6 +254919,21 @@ SQLITE_API int sqlite3_stmt_init( +@@ -254823,6 +254941,21 @@ SQLITE_API int sqlite3_stmt_init( SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } /************************** End of sqlite3.c ******************************/ @@ -940,7 +978,7 @@ index 0cdb348..399c6b1 100644 #ifdef SQLITE_CKSUMVFS_STATIC extern sqlite3_file *cksmvfsGetOrigFile(sqlite3_file *file); #else -@@ -255984,8 +256095,12 @@ void sqlite3CodecDetach(void *ctx){ +@@ -255984,8 +256117,12 @@ void sqlite3CodecDetach(void *ctx){ #if SQLITE_OS_UNIX static int CodecFileLock(Pager *pPager, short lockType) { @@ -955,7 +993,7 @@ index 0cdb348..399c6b1 100644 unixInodeInfo *pInode = pFile->pInode; if (pInode == NULL) { sqlite3_log(SQLITE_IOERR_RDLOCK, "Codec file lock %d go wrong", lockType); -@@ -256060,6 +256175,7 @@ int sqlite3CodecAttach(sqlite3* db, int nDb, const void *pKey, int nKey){ +@@ -256060,6 +256197,7 @@ int sqlite3CodecAttach(sqlite3* db, int nDb, const void *pKey, int nKey){ } } #endif @@ -963,7 +1001,7 @@ index 0cdb348..399c6b1 100644 #ifdef SQLITE_CODEC_ATTACH_CHANGED int rc = sqlite3CodecInitContext(ctx, p, pKey, nKey, nDb); #else -@@ -256636,7 +256752,12 @@ typedef struct MetaDwrHdr { +@@ -256636,7 +256774,12 @@ typedef struct MetaDwrHdr { u32 pageSz; u32 pageCnt; u64 dbFileInode; @@ -977,7 +1015,7 @@ index 0cdb348..399c6b1 100644 u32 checkSum; u8 *zones; Pgno *pages; -@@ -256991,6 +257112,88 @@ static inline u64 CaculateMetaDwrWriteOffset(int pageSz, u32 idx, u8 zone) { +@@ -256991,6 +257134,88 @@ static inline u64 CaculateMetaDwrWriteOffset(int pageSz, u32 idx, u8 zone) { return META_DWR_HEADER_PAGE_SIZE + pageSz * (idx * 2 + zone); } @@ -1066,7 +1104,7 @@ index 0cdb348..399c6b1 100644 static void MetaDwrUpdateHeaderDbInfo(BtShared *pBt) { MetaDwrHdr *hdr = pBt->pPager->metaHdr; // 28 offset: dbSize, freelist pageNo, freelist pages count, schema cookie -@@ -257146,7 +257349,10 @@ static int MetaDwrRestoreAllPages(Btree *pBt, const ScanPages *metaPages, MetaDw +@@ -257146,7 +257371,10 @@ static int MetaDwrRestoreAllPages(Btree *pBt, const ScanPages *metaPages, MetaDw return rc; } } @@ -1078,7 +1116,7 @@ index 0cdb348..399c6b1 100644 MetaDwrUpdateHeaderDbInfo(pBt->pBt); return rc; } -@@ -257211,11 +257417,12 @@ static int MetaDwrOpenFile(Pager *pPager, u8 openCreate) { +@@ -257211,11 +257439,12 @@ static int MetaDwrOpenFile(Pager *pPager, u8 openCreate) { if (pPager->metaMapPage == NULL) { sqlite3_int64 sz = META_DWR_HEADER_PAGE_SIZE; sqlite3OsFileControlHint(metaFd, SQLITE_FCNTL_CHUNK_SIZE, &sz); @@ -1096,7 +1134,7 @@ index 0cdb348..399c6b1 100644 } } #endif /* SQLITE_OS_UNIX */ -@@ -257589,7 +257796,7 @@ CHK_RESTORE_OUT: +@@ -257589,7 +257818,7 @@ CHK_RESTORE_OUT: return rc; } @@ -1105,7 +1143,7 @@ index 0cdb348..399c6b1 100644 { #if SQLITE_OS_UNIX u8 checkFileId = Sqlite3GetCheckFileId(pPager->pVfs); -@@ -257597,10 +257804,18 @@ static inline u8 IsConnectionValidForCheck(Pager *pPager) +@@ -257597,10 +257826,18 @@ static inline u8 IsConnectionValidForCheck(Pager *pPager) return 0; } unixFile *fd = Sqlite3GetUnixFile(pPager->fd, checkFileId); @@ -1125,7 +1163,7 @@ index 0cdb348..399c6b1 100644 return 1; #else return 0; -@@ -257610,7 +257825,7 @@ static inline u8 IsConnectionValidForCheck(Pager *pPager) +@@ -257610,7 +257847,7 @@ static inline u8 IsConnectionValidForCheck(Pager *pPager) static int MetaDwrOpenAndCheck(Btree *pBt) { Pager *pPager = pBt->pBt->pPager; @@ -1134,7 +1172,7 @@ index 0cdb348..399c6b1 100644 return SQLITE_OK; } #ifdef SQLITE_HAS_CODEC -@@ -257655,7 +257870,7 @@ DWR_OPEN_OUT: +@@ -257655,7 +257892,7 @@ DWR_OPEN_OUT: static void MetaDwrDisable(Btree *pBt) { Pager *pPager = pBt->pBt->pPager; @@ -1143,7 +1181,7 @@ index 0cdb348..399c6b1 100644 return; } #ifdef SQLITE_HAS_CODEC -@@ -257681,19 +257896,6 @@ static void MetaDwrDisable(Btree *pBt) +@@ -257681,19 +257918,6 @@ static void MetaDwrDisable(Btree *pBt) #endif /* SQLITE_META_DWR */ #if SQLITE_OS_UNIX @@ -1163,7 +1201,7 @@ index 0cdb348..399c6b1 100644 static void ResetLockStatus(void) { (void)memset(&g_lockStatus, 0, sizeof(g_lockStatus)); -@@ -257797,8 +257999,13 @@ static inline const char *FlockToName(int l_type) +@@ -257797,8 +258021,13 @@ static inline const char *FlockToName(int l_type) static int DumpProcessLocks(int fd, struct flock *lock, const char *lockName, char *dumpBuf, int bufLen) { @@ -1178,7 +1216,7 @@ index 0cdb348..399c6b1 100644 sqlite3_log(SQLITE_ERROR, "[SQLite]Get wal file lock ofs %u failed, errno: %d", lock->l_start, errno); return 0; } -@@ -259039,9 +259246,13 @@ struct sqlite3_api_routines_extra { +@@ -259053,9 +259282,13 @@ struct sqlite3_api_routines_extra { int (*key_v2)(sqlite3*,const char*,const void*,int); int (*rekey)(sqlite3*,const void*,int); int (*rekey_v2)(sqlite3*,const char*,const void*,int); @@ -1194,5 +1232,5 @@ index 0cdb348..399c6b1 100644 int (*compressdb_backup)(sqlite3*, const char*); #else -- -2.47.0.windows.2 +2.34.1