From e6e0832af4da0252eb61ff7b698da1853b6876b2 Mon Sep 17 00:00:00 2001 From: MartinChoo <214582617@qq.com> Date: Sat, 5 Jul 2025 11:05:16 +0800 Subject: [PATCH] Support enable page compress Signed-off-by: MartinChoo <214582617@qq.com> --- patch/0001-History-features-on-OH.patch | 13 +- patch/0002-Enable-and-optimize-ICU.patch | 13 +- patch/0003-Busy-debug-and-log-dump.patch | 13 +- patch/0004-Support-meta-recovery.patch | 13 +- ...ity-report-corruption-and-check-page.patch | 13 +- patch/0006-Support-Binlog.patch | 12 +- patch/0007-DatabaseDebugTool.patch | 12 + patch/0008-Rekey-multi-process.patch | 32 +- ...Allow-enable-checksum-through-PRAGMA.patch | 53 +- ...ExtensionLoading-LoadCustomTokenizer.patch | 22 +- patch/0011-Support-compress-db.patch | 460 ++++++++++++++++++ ...h => 0012-Bugfix-on-current-version.patch} | 51 +- patch/BUILD.gn | 1 + 13 files changed, 593 insertions(+), 115 deletions(-) create mode 100644 patch/0011-Support-compress-db.patch rename patch/{0011-Bug-fixes-on-current-version.patch => 0012-Bugfix-on-current-version.patch} (89%) diff --git a/patch/0001-History-features-on-OH.patch b/patch/0001-History-features-on-OH.patch index d33eeee..b6a9a13 100644 --- a/patch/0001-History-features-on-OH.patch +++ b/patch/0001-History-features-on-OH.patch @@ -1,15 +1,14 @@ -From f71a3aaddebdcba87ad8af804d680397ecc5fa48 Mon Sep 17 00:00:00 2001 -From: wanghaishuo -Date: Mon, 12 May 2025 15:29:53 +0800 -Subject: [PATCH 1/6] History features on OH +From 1355da4b32bfb2e263e03e953d052086cf40ed20 Mon Sep 17 00:00:00 2001 +From: MartinChoo <214582617@qq.com> +Date: Thu, 3 Jul 2025 22:53:07 +0800 +Subject: [PATCH 01/12] History features on OH -Signed-off-by: wanghaishuo --- src/sqlite3.c | 2451 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 2438 insertions(+), 13 deletions(-) diff --git a/src/sqlite3.c b/src/sqlite3.c -index 7fb290f..ad78006 100644 +index 730b247..b132937 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c @@ -2915,6 +2915,11 @@ SQLITE_API int sqlite3_extended_result_codes(sqlite3*, int onoff); @@ -3033,5 +3032,5 @@ index 7fb290f..ad78006 100644 +/************** End hw export the symbols *****************************************/ +#endif /* SQLITE_EXPORT_SYMBOLS */ -- -2.34.1 +2.47.0.windows.2 diff --git a/patch/0002-Enable-and-optimize-ICU.patch b/patch/0002-Enable-and-optimize-ICU.patch index 15c1115..559c32f 100644 --- a/patch/0002-Enable-and-optimize-ICU.patch +++ b/patch/0002-Enable-and-optimize-ICU.patch @@ -1,9 +1,8 @@ -From 57b5e5dc8b3a7f622e9666c20ec2a7f78997bf3c Mon Sep 17 00:00:00 2001 -From: wanghaishuo -Date: Mon, 12 May 2025 15:24:45 +0800 -Subject: [PATCH 2/6] Enable and optimize ICU +From 733de3813ffb596919bcc72fb8f61422cbacf295 Mon Sep 17 00:00:00 2001 +From: MartinChoo <214582617@qq.com> +Date: Thu, 3 Jul 2025 22:53:41 +0800 +Subject: [PATCH 02/12] Enable and optimize ICU -Signed-off-by: wanghaishuo --- src/sqlite3.c | 1013 ++++------------------------------------------ src/sqlite3icu.c | 888 ++++++++++++++++++++++++++++++++++++++++ @@ -11,7 +10,7 @@ Signed-off-by: wanghaishuo create mode 100644 src/sqlite3icu.c diff --git a/src/sqlite3.c b/src/sqlite3.c -index ad78006..8d8b8ae 100644 +index b132937..efc4cd4 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c @@ -2502,6 +2502,7 @@ struct sqlite3_mem_methods { @@ -2020,5 +2019,5 @@ index 0000000..b5944d5 +/************** End of fts3_icu.c ********************************************/ \ No newline at end of file -- -2.34.1 +2.47.0.windows.2 diff --git a/patch/0003-Busy-debug-and-log-dump.patch b/patch/0003-Busy-debug-and-log-dump.patch index 15d6408..2dfa3c7 100644 --- a/patch/0003-Busy-debug-and-log-dump.patch +++ b/patch/0003-Busy-debug-and-log-dump.patch @@ -1,15 +1,14 @@ -From c56ae11e3fe85ab6fa71c9d49ac37a433b01fb4b Mon Sep 17 00:00:00 2001 -From: wanghaishuo -Date: Mon, 12 May 2025 15:31:54 +0800 -Subject: [PATCH 3/6] Busy debug and log dump +From 65e08929709648a1ee5d6b0d3b6383634f8669e3 Mon Sep 17 00:00:00 2001 +From: MartinChoo <214582617@qq.com> +Date: Thu, 3 Jul 2025 22:54:18 +0800 +Subject: [PATCH 03/12] Busy debug and log dump -Signed-off-by: wanghaishuo --- src/sqlite3.c | 745 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 731 insertions(+), 14 deletions(-) diff --git a/src/sqlite3.c b/src/sqlite3.c -index 8d8b8ae..574a76a 100644 +index efc4cd4..6f423a9 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c @@ -879,6 +879,7 @@ SQLITE_API int sqlite3_exec( @@ -1414,5 +1413,5 @@ index 8d8b8ae..574a76a 100644 #ifdef SQLITE_EXPORT_SYMBOLS struct sqlite3_api_routines_hw { -- -2.34.1 +2.47.0.windows.2 diff --git a/patch/0004-Support-meta-recovery.patch b/patch/0004-Support-meta-recovery.patch index d9f6e35..6f6427f 100644 --- a/patch/0004-Support-meta-recovery.patch +++ b/patch/0004-Support-meta-recovery.patch @@ -1,15 +1,14 @@ -From cdf4fb30449a76dc055c92efef0eee7e128ccd56 Mon Sep 17 00:00:00 2001 -From: wanghaishuo -Date: Mon, 12 May 2025 15:33:13 +0800 -Subject: [PATCH 4/6] Support meta recovery +From 45e883bed32094756ff8878964d911cc0cfe9fd3 Mon Sep 17 00:00:00 2001 +From: MartinChoo <214582617@qq.com> +Date: Thu, 3 Jul 2025 22:54:55 +0800 +Subject: [PATCH 04/12] Support meta recovery -Signed-off-by: wanghaishuo --- src/sqlite3.c | 1156 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 1151 insertions(+), 5 deletions(-) diff --git a/src/sqlite3.c b/src/sqlite3.c -index 574a76a..96ed35b 100644 +index 6f423a9..dc09c3c 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c @@ -786,6 +786,7 @@ SQLITE_API int sqlite3_exec( @@ -1290,5 +1289,5 @@ index 574a76a..96ed35b 100644 #include #include -- -2.34.1 +2.47.0.windows.2 diff --git a/patch/0005-Enhance-dfx-ability-report-corruption-and-check-page.patch b/patch/0005-Enhance-dfx-ability-report-corruption-and-check-page.patch index bc8e8da..62075d3 100644 --- a/patch/0005-Enhance-dfx-ability-report-corruption-and-check-page.patch +++ b/patch/0005-Enhance-dfx-ability-report-corruption-and-check-page.patch @@ -1,9 +1,8 @@ -From ee3361c659ae4f46615bdb9f703cb3469c595214 Mon Sep 17 00:00:00 2001 -From: wanghaishuo -Date: Mon, 12 May 2025 15:42:10 +0800 -Subject: [PATCH 5/6] Enhance dfx ability, report corruption and check pages +From 530b32340de30cfde81712585051e5b8b77ba095 Mon Sep 17 00:00:00 2001 +From: MartinChoo <214582617@qq.com> +Date: Thu, 3 Jul 2025 22:55:22 +0800 +Subject: [PATCH 05/12] Enhance dfx ability, report corruption and check pages -Signed-off-by: wanghaishuo --- ext/misc/cksumvfs.c | 916 ++++++++++++++++++++++++++++++++++++++++++++ src/sqlite3.c | 818 ++++++++++++++++++++++++++++++++++----- @@ -933,7 +932,7 @@ index 0000000..6f4c55c +EXPORT_SYMBOLS const sqlite3_api_routines_cksumvfs *sqlite3_export_cksumvfs_symbols = &sqlite3CksumvfsApis; +#endif diff --git a/src/sqlite3.c b/src/sqlite3.c -index 96ed35b..2a4e87f 100644 +index dc09c3c..e7e8b3c 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c @@ -2472,6 +2472,21 @@ struct sqlite3_mem_methods { @@ -2410,5 +2409,5 @@ index 96ed35b..2a4e87f 100644 int (*initialize)(); int (*config)(int,...); -- -2.34.1 +2.47.0.windows.2 diff --git a/patch/0006-Support-Binlog.patch b/patch/0006-Support-Binlog.patch index c64f7d1..b353695 100644 --- a/patch/0006-Support-Binlog.patch +++ b/patch/0006-Support-Binlog.patch @@ -1,14 +1,14 @@ -From 50059cd9ac8a97d4334f6fe042d42708a96b4f9f Mon Sep 17 00:00:00 2001 -From: Liu Hongyang -Date: Wed, 11 Jun 2025 09:32:35 +0800 -Subject: [PATCH] Support-Binlog +From 35341a0e47408e8b99c89c012e966bd255fe5f16 Mon Sep 17 00:00:00 2001 +From: MartinChoo <214582617@qq.com> +Date: Thu, 3 Jul 2025 22:55:59 +0800 +Subject: [PATCH 06/12] Support-Binlog --- src/sqlite3.c | 1493 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 1484 insertions(+), 9 deletions(-) diff --git a/src/sqlite3.c b/src/sqlite3.c -index e7e8b3c..eb89098 100644 +index e7e8b3c..37501f9 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c @@ -2938,7 +2938,9 @@ SQLITE_API sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); @@ -1776,5 +1776,5 @@ index e7e8b3c..eb89098 100644 EXPORT_SYMBOLS const sqlite3_api_routines *sqlite3_export_symbols = &sqlite3Apis; -- -2.25.1 +2.47.0.windows.2 diff --git a/patch/0007-DatabaseDebugTool.patch b/patch/0007-DatabaseDebugTool.patch index daddcc8..9fc0387 100644 --- a/patch/0007-DatabaseDebugTool.patch +++ b/patch/0007-DatabaseDebugTool.patch @@ -1,3 +1,12 @@ +From ea38cd58b2a3704a2ce6e7e6840cdaa72c24b566 Mon Sep 17 00:00:00 2001 +From: MartinChoo <214582617@qq.com> +Date: Thu, 3 Jul 2025 22:56:30 +0800 +Subject: [PATCH 07/12] DatabaseDebugTool + +--- + src/shell.c | 4 ++++ + 1 file changed, 4 insertions(+) + diff --git a/src/shell.c b/src/shell.c index 7fb190e..c1948b1 100644 --- a/src/shell.c @@ -20,3 +29,6 @@ index 7fb190e..c1948b1 100644 /* Do an initial pass through the command-line argument to locate ** the name of the database file, the name of the initialization file, ** the size of the alternative malloc heap, options affecting commands +-- +2.47.0.windows.2 + diff --git a/patch/0008-Rekey-multi-process.patch b/patch/0008-Rekey-multi-process.patch index 2a6c342..397ac2a 100644 --- a/patch/0008-Rekey-multi-process.patch +++ b/patch/0008-Rekey-multi-process.patch @@ -1,17 +1,17 @@ -From fa5b9fefdd1d5b13ad1953690ed93f21f26be9ac Mon Sep 17 00:00:00 2001 -From: ryne3366 -Date: Fri, 6 Jun 2025 19:42:36 +0800 -Subject: [PATCH 1/2] rekey multi process +From c21f5d9abd672d70f46e22ffb6bb3ef48e7f1c6e Mon Sep 17 00:00:00 2001 +From: MartinChoo <214582617@qq.com> +Date: Thu, 3 Jul 2025 22:57:18 +0800 +Subject: [PATCH 08/12] rekey multi process --- src/sqlite3.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 3 deletions(-) diff --git a/src/sqlite3.c b/src/sqlite3.c -index 6530284..b808dc6 100644 +index 37501f9..425d3d7 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c -@@ -15692,6 +15692,7 @@ typedef int VList; +@@ -15689,6 +15689,7 @@ typedef int VList; #define RESERVED_BYTE (PENDING_BYTE+1) #define SHARED_FIRST (PENDING_BYTE+2) #define SHARED_SIZE 510 @@ -19,7 +19,7 @@ index 6530284..b808dc6 100644 /* ** Wrapper around OS specific sqlite3_os_init() function. -@@ -38678,6 +38679,10 @@ struct unixFile { +@@ -38682,6 +38683,10 @@ struct unixFile { #endif }; @@ -30,7 +30,7 @@ index 6530284..b808dc6 100644 /* This variable holds the process id (pid) from when the xRandomness() ** method was called. If xOpen() is called from a different process id, ** indicating that a fork() has occurred, the PRNG will be reset. -@@ -39623,6 +39628,9 @@ struct unixInodeInfo { +@@ -39627,6 +39632,9 @@ struct unixInodeInfo { sqlite3_mutex *pLockMutex; /* Hold this mutex for... */ int nShared; /* Number of SHARED locks held */ int nLock; /* Number of outstanding file locks */ @@ -40,7 +40,7 @@ index 6530284..b808dc6 100644 unsigned char eFileLock; /* One of SHARED_LOCK, RESERVED_LOCK etc. */ unsigned char bProcessLock; /* An exclusive process lock is held */ UnixUnusedFd *pUnused; /* Unused file descriptors to close */ -@@ -61693,6 +61701,9 @@ SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager, sqlite3 *db){ +@@ -61697,6 +61705,9 @@ SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager, sqlite3 *db){ PAGERTRACE(("CLOSE %d\n", PAGERID(pPager))); IOTRACE(("CLOSE %p\n", pPager)) sqlite3OsClose(pPager->jfd); @@ -50,7 +50,7 @@ index 6530284..b808dc6 100644 sqlite3OsClose(pPager->fd); sqlite3PageFree(pTmp); sqlite3PcacheClose(pPager->pPCache); -@@ -255484,6 +255495,54 @@ void sqlite3CodecDetach(void *ctx){ +@@ -255500,6 +255511,54 @@ void sqlite3CodecDetach(void *ctx){ return; } @@ -105,7 +105,7 @@ index 6530284..b808dc6 100644 int sqlite3CodecAttach(sqlite3* db, int nDb, const void *pKey, int nKey){ if(db == NULL){ return SQLITE_ERROR; -@@ -255503,6 +255562,18 @@ int sqlite3CodecAttach(sqlite3* db, int nDb, const void *pKey, int nKey){ +@@ -255519,6 +255578,18 @@ int sqlite3CodecAttach(sqlite3* db, int nDb, const void *pKey, int nKey){ return SQLITE_ERROR; } sqlite3_mutex_enter(db->mutex); @@ -124,7 +124,7 @@ index 6530284..b808dc6 100644 #ifdef SQLITE_CODEC_ATTACH_CHANGED int rc = sqlite3CodecInitContext(ctx, p, pKey, nKey, nDb); #else -@@ -255510,6 +255581,7 @@ int sqlite3CodecAttach(sqlite3* db, int nDb, const void *pKey, int nKey){ +@@ -255526,6 +255597,7 @@ int sqlite3CodecAttach(sqlite3* db, int nDb, const void *pKey, int nKey){ #endif /* SQLITE_CODEC_ATTACH_CHANGED */ if(rc != SQLITE_OK){ sqlite3_free(ctx); @@ -132,7 +132,7 @@ index 6530284..b808dc6 100644 return rc; } sqlite3PagerSetCodec(sqlite3BtreePager(p), sqlite3Codec, NULL, sqlite3CodecDetach, (void *)ctx); -@@ -255518,7 +255590,7 @@ int sqlite3CodecAttach(sqlite3* db, int nDb, const void *pKey, int nKey){ +@@ -255534,7 +255606,7 @@ int sqlite3CodecAttach(sqlite3* db, int nDb, const void *pKey, int nKey){ p->pBt->btsFlags &= ~BTS_PAGESIZE_FIXED; sqlite3BtreeSetPageSize(p, ctx->readCtx->codecConst.cipherPageSize, ctx->readCtx->codecConst.reserveSize, 0); sqlite3BtreeSecureDelete(p, 1); @@ -141,7 +141,7 @@ index 6530284..b808dc6 100644 sqlite3BtreeSetAutoVacuum(p, SQLITE_DEFAULT_AUTOVACUUM); } -@@ -255589,7 +255661,20 @@ int sqlite3_rekey_v2(sqlite3 *db, const char *zDb, const void *pKey, int nKey){ +@@ -255605,7 +255677,20 @@ int sqlite3_rekey_v2(sqlite3 *db, const char *zDb, const void *pKey, int nKey){ return rc; } sqlite3_mutex_enter(db->mutex); @@ -163,7 +163,7 @@ index 6530284..b808dc6 100644 sqlite3PagerPagecount(pPager, &pageCount); // support hmac algo changed by using rekey operation int oldHmacAlgo = ctx->writeCtx->codecConst.hmacAlgo; -@@ -255624,8 +255709,10 @@ int sqlite3_rekey_v2(sqlite3 *db, const char *zDb, const void *pKey, int nKey){ +@@ -255640,8 +255725,10 @@ int sqlite3_rekey_v2(sqlite3 *db, const char *zDb, const void *pKey, int nKey){ } (void)sqlite3BtreeRollback(p, SQLITE_ABORT_ROLLBACK, 0); } @@ -176,5 +176,5 @@ index 6530284..b808dc6 100644 } -- -2.34.1 +2.47.0.windows.2 diff --git a/patch/0009-Allow-enable-checksum-through-PRAGMA.patch b/patch/0009-Allow-enable-checksum-through-PRAGMA.patch index fc422b9..bb63f29 100644 --- a/patch/0009-Allow-enable-checksum-through-PRAGMA.patch +++ b/patch/0009-Allow-enable-checksum-through-PRAGMA.patch @@ -1,9 +1,8 @@ -From 6795a730af198fed664ac8418b36368048c4aa4b Mon Sep 17 00:00:00 2001 +From 1136400a2cdcdbd784cb459cfc6f123f14f3cc58 Mon Sep 17 00:00:00 2001 From: MartinChoo <214582617@qq.com> -Date: Sat, 7 Jun 2025 22:25:48 +0800 -Subject: [PATCH] Allow enable checksum through PRAGMA +Date: Thu, 3 Jul 2025 22:57:51 +0800 +Subject: [PATCH 09/12] Allow enable checksum through PRAGMA -Signed-off-by: MartinChoo <214582617@qq.com> --- ext/misc/cksumvfs.c | 185 ++++++++++++++++++++++++++++++++++++-------- src/sqlite3.c | 175 ++++++++++++++++++++++++++++++++--------- @@ -377,10 +376,10 @@ index 6f4c55c..a23a997 100644 int (*register_cksumvfs)(const char *); int (*unregister_cksumvfs)(); diff --git a/src/sqlite3.c b/src/sqlite3.c -index 3be1113..80d7979 100644 +index 425d3d7..24e3247 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c -@@ -139859,6 +139859,10 @@ static int integrityCheckResultRow(Vdbe *v){ +@@ -139875,6 +139875,10 @@ static int integrityCheckResultRow(Vdbe *v){ return addr; } @@ -391,7 +390,7 @@ index 3be1113..80d7979 100644 /* ** Process a pragma statement. ** -@@ -139981,7 +139985,15 @@ SQLITE_PRIVATE void sqlite3Pragma( +@@ -139997,7 +140001,15 @@ SQLITE_PRIVATE void sqlite3Pragma( /* PragmaMetaDoubleWrie executes internal */ goto pragma_out; } @@ -408,7 +407,7 @@ index 3be1113..80d7979 100644 /* Locate the pragma in the lookup table */ pPragma = pragmaLocate(zLeft); if( pPragma==0 ){ -@@ -184243,16 +184255,12 @@ SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, vo +@@ -184259,16 +184271,12 @@ SQLITE_API int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, vo *(unsigned int*)pArg = sqlite3PagerDataVersion(pPager); rc = SQLITE_OK; }else if( op==SQLITE_FCNTL_RESERVE_BYTES ){ @@ -425,7 +424,7 @@ index 3be1113..80d7979 100644 }else if( op==SQLITE_FCNTL_RESET_CACHE ){ sqlite3BtreeClearCache(pBtree); rc = SQLITE_OK; -@@ -256078,7 +256086,71 @@ export_finish: +@@ -256094,7 +256102,71 @@ export_finish: return; } /************** End file hw_codec.c *****************************************/ @@ -498,7 +497,7 @@ index 3be1113..80d7979 100644 #ifdef SQLITE_META_DWR #define META_DWR_MAX_PAGES 500 #define META_DWR_MAGIC 0x234A86D9 -@@ -256110,7 +256182,7 @@ typedef struct MetaDwrHdr { +@@ -256126,7 +256198,7 @@ typedef struct MetaDwrHdr { Pgno *pages; u32 pageBufSize; u8 hdrValid; @@ -507,7 +506,7 @@ index 3be1113..80d7979 100644 u16 needSync; i64 lastSyncTime; } MetaDwrHdr; -@@ -256124,7 +256196,7 @@ typedef struct MetaDwrHdr { +@@ -256140,7 +256212,7 @@ typedef struct MetaDwrHdr { static int MetaDwrHeaderSimpleCheck(Pager *pPager, MetaDwrHdr *hdr) { #if SQLITE_OS_UNIX if (hdr->checkFileId) { @@ -516,7 +515,7 @@ index 3be1113..80d7979 100644 if (fd == NULL || fd->pInode == NULL || pPager->pVfs == NULL) { return SQLITE_INTERNAL; } -@@ -256134,7 +256206,7 @@ static int MetaDwrHeaderSimpleCheck(Pager *pPager, MetaDwrHdr *hdr) { +@@ -256150,7 +256222,7 @@ static int MetaDwrHeaderSimpleCheck(Pager *pPager, MetaDwrHdr *hdr) { return SQLITE_IOERR_DATA; } } @@ -525,7 +524,7 @@ index 3be1113..80d7979 100644 if (hdr->pageCnt > META_DWR_MAX_PAGES || hdr->version != META_DWR_VERSION || hdr->magic != META_DWR_MAGIC || hdr->checkSum != META_DWR_MAGIC) { sqlite3_log(SQLITE_IOERR_DATA, "Meta dwr file check wrong pageCnt %u, version %u, magic %u, checkSum %u", -@@ -256366,7 +256438,15 @@ static MetaDwrHdr *AllocInitMetaHeaderDwr(Pager *pPager) { +@@ -256382,7 +256454,15 @@ static MetaDwrHdr *AllocInitMetaHeaderDwr(Pager *pPager) { MetaDwrReleaseHdr(hdr); return NULL; } @@ -542,7 +541,7 @@ index 3be1113..80d7979 100644 return hdr; } -@@ -256379,7 +256459,7 @@ static void MetaDwrCloseFile(Pager *pPager) { +@@ -256395,7 +256475,7 @@ static void MetaDwrCloseFile(Pager *pPager) { osMunmap(pPager->metaMapPage, META_DWR_HEADER_PAGE_SIZE); pPager->metaMapPage = NULL; } @@ -551,7 +550,7 @@ index 3be1113..80d7979 100644 if (pPager->metaHdr && pPager->metaHdr->needSync > 0) { (void)sqlite3OsSync(pPager->metaFd, SQLITE_SYNC_NORMAL); } -@@ -256474,10 +256554,10 @@ static void MetaDwrUpdateHeaderDbInfo(BtShared *pBt) { +@@ -256490,10 +256570,10 @@ static void MetaDwrUpdateHeaderDbInfo(BtShared *pBt) { } else { hdr->mxFrameInWal = 0; } @@ -564,7 +563,7 @@ index 3be1113..80d7979 100644 if (fd == NULL || fd->pInode == NULL) { sqlite3_log(SQLITE_WARNING_DUMP, "update meta header invalid fd"); hdr->hdrValid = 0; -@@ -256485,7 +256565,7 @@ static void MetaDwrUpdateHeaderDbInfo(BtShared *pBt) { +@@ -256501,7 +256581,7 @@ static void MetaDwrUpdateHeaderDbInfo(BtShared *pBt) { } hdr->dbFileInode = fd->pInode->fileId.ino; } @@ -573,7 +572,7 @@ index 3be1113..80d7979 100644 hdr->freeListPageNo = sqlite3Get4byte(dbHdrInfo + 4); hdr->freeListPageCnt = sqlite3Get4byte(dbHdrInfo + 8); hdr->schemaCookie = sqlite3Get4byte(dbHdrInfo + 12); -@@ -256581,7 +256661,7 @@ static int MetaDwrWriteOnePage(Btree *pBt, PgHdr *pPage, MetaDwrHdr *hdr, u8 cur +@@ -256597,7 +256677,7 @@ static int MetaDwrWriteOnePage(Btree *pBt, PgHdr *pPage, MetaDwrHdr *hdr, u8 cur return SQLITE_NOMEM; #else pData = pPage->pData; @@ -582,7 +581,7 @@ index 3be1113..80d7979 100644 rc = sqlite3OsWrite(pPager->metaFd, pData, pageSz, ofs); if (rc != SQLITE_OK) { return rc; -@@ -256643,7 +256723,7 @@ static int MetaDwrCheckPerm(sqlite3_vfs *pVfs, u8 openCreate, char *metaPath) { +@@ -256659,7 +256739,7 @@ static int MetaDwrCheckPerm(sqlite3_vfs *pVfs, u8 openCreate, char *metaPath) { if (openCreate) { sqlite3_log(SQLITE_WARNING_DUMP, "Meta double write disabled, sysno %d", errno); } @@ -591,7 +590,7 @@ index 3be1113..80d7979 100644 return rc; } -@@ -256686,7 +256766,7 @@ static int MetaDwrOpenFile(Pager *pPager, u8 openCreate) { +@@ -256702,7 +256782,7 @@ static int MetaDwrOpenFile(Pager *pPager, u8 openCreate) { pPager->metaMapPage = page; } } @@ -600,7 +599,7 @@ index 3be1113..80d7979 100644 pPager->metaFd = metaFd; INIT_META_OUT: sqlite3EndBenignMalloc(); -@@ -256810,7 +256890,7 @@ static int MetaDwrRecoverHeadPage( +@@ -256826,7 +256906,7 @@ static int MetaDwrRecoverHeadPage( goto RELEASE_OUT; } } @@ -609,7 +608,7 @@ index 3be1113..80d7979 100644 rc = SQLITE_NOTADB; for (u32 i = 0; i < hdr->pageCnt; i++) { if (hdr->pages[i] != pgno) { -@@ -257060,15 +257140,24 @@ CHK_RESTORE_OUT: +@@ -257076,15 +257156,24 @@ CHK_RESTORE_OUT: static inline u8 IsConnectionValidForCheck(Pager *pPager) { #if SQLITE_OS_UNIX @@ -642,7 +641,7 @@ index 3be1113..80d7979 100644 #endif } -@@ -257083,7 +257172,7 @@ static int MetaDwrOpenAndCheck(Btree *pBt) +@@ -257099,7 +257188,7 @@ static int MetaDwrOpenAndCheck(Btree *pBt) if (pPager->xCodec) { return SQLITE_OK; } @@ -651,7 +650,7 @@ index 3be1113..80d7979 100644 sqlite3BtreeEnter(pBt); int rc = SQLITE_OK; int openedTransaction = 0; -@@ -257128,7 +257217,7 @@ static void MetaDwrDisable(Btree *pBt) +@@ -257144,7 +257233,7 @@ static void MetaDwrDisable(Btree *pBt) if (pPager->xCodec) { return; } @@ -660,7 +659,7 @@ index 3be1113..80d7979 100644 sqlite3BtreeEnter(pBt); MetaDwrCloseFile(pPager); MetaDwrReleaseHdr(pPager->metaHdr); -@@ -257143,7 +257232,8 @@ static void MetaDwrDisable(Btree *pBt) +@@ -257159,7 +257248,8 @@ static void MetaDwrDisable(Btree *pBt) } sqlite3BtreeLeave(pBt); } @@ -670,7 +669,7 @@ index 3be1113..80d7979 100644 #if SQLITE_OS_UNIX #include #include -@@ -257352,10 +257442,17 @@ static void DumpLocksByWal(Wal *pWal) +@@ -257368,10 +257458,17 @@ static void DumpLocksByWal(Wal *pWal) sqlite3_log(SQLITE_ERROR, "Wal ptr is NULL!"); return; } @@ -690,7 +689,7 @@ index 3be1113..80d7979 100644 } #endif /* #ifndef SQLITE_OMIT_WAL */ -@@ -257365,13 +257462,20 @@ static void DumpLocksByPager(Pager *pPager) +@@ -257381,13 +257478,20 @@ static void DumpLocksByPager(Pager *pPager) sqlite3_log(SQLITE_ERROR, "Pager ptr is NULL!"); return; } @@ -714,7 +713,7 @@ index 3be1113..80d7979 100644 #endif /* #ifndef SQLITE_OMIT_WAL */ } #endif /* SQLITE_OS_UNIX */ -@@ -258307,7 +258411,8 @@ static const sqlite3_api_routines_cksumvfs sqlite3CksumvfsApis = { +@@ -258484,7 +258588,8 @@ static const sqlite3_api_routines_cksumvfs sqlite3CksumvfsApis = { }; EXPORT_SYMBOLS const sqlite3_api_routines_cksumvfs *sqlite3_export_cksumvfs_symbols = &sqlite3CksumvfsApis; diff --git a/patch/0010-EnableExtensionLoading-LoadCustomTokenizer.patch b/patch/0010-EnableExtensionLoading-LoadCustomTokenizer.patch index 571dd7a..8176939 100644 --- a/patch/0010-EnableExtensionLoading-LoadCustomTokenizer.patch +++ b/patch/0010-EnableExtensionLoading-LoadCustomTokenizer.patch @@ -1,5 +1,14 @@ +From 4df2a5e625753f2cb9c211617e91f606fdd6d4c6 Mon Sep 17 00:00:00 2001 +From: MartinChoo <214582617@qq.com> +Date: Thu, 3 Jul 2025 22:58:29 +0800 +Subject: [PATCH 10/12] EnableExtensionLoading-LoadCustomTokenizer + +--- + src/shell.c | 32 ++++++++++++++++++++++++++++++++ + 1 file changed, 32 insertions(+) + diff --git a/src/shell.c b/src/shell.c -index 7fb190e..6dc5087 100644 +index c1948b1..cedf118 100644 --- a/src/shell.c +++ b/src/shell.c @@ -118,6 +118,7 @@ typedef unsigned short int u16; @@ -8,9 +17,9 @@ index 7fb190e..6dc5087 100644 #include +#include #include "sqlite3.h" + #include "sqlite3sym.h" typedef sqlite3_int64 i64; - typedef sqlite3_uint64 u64; -@@ -22189,6 +22190,32 @@ static void open_db(ShellState *p, int openFlags){ +@@ -22190,6 +22191,32 @@ static void open_db(ShellState *p, int openFlags){ } sqlite3_db_config(p->db, SQLITE_DBCONFIG_STMT_SCANSTATUS, (int)0, (int*)0); @@ -43,7 +52,7 @@ index 7fb190e..6dc5087 100644 /* Reflect the use or absence of --unsafe-testing invocation. */ { int testmode_on = ShellHasFlag(p,SHFLG_TestingMode); -@@ -28237,6 +28264,8 @@ static int line_is_complete(char *zSql, int nSql){ +@@ -28238,6 +28265,8 @@ static int line_is_complete(char *zSql, int nSql){ static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){ int rc; char *zErrMsg = 0; @@ -52,7 +61,7 @@ index 7fb190e..6dc5087 100644 open_db(p, 0); if( ShellHasFlag(p,SHFLG_Backslash) ) resolve_backslashes(zSql); -@@ -28244,6 +28273,9 @@ static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){ +@@ -28245,6 +28274,9 @@ static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){ BEGIN_TIMER; rc = shell_exec(p, zSql, &zErrMsg); END_TIMER; @@ -62,3 +71,6 @@ index 7fb190e..6dc5087 100644 if( rc || zErrMsg ){ char zPrefix[100]; const char *zErrorTail; +-- +2.47.0.windows.2 + diff --git a/patch/0011-Support-compress-db.patch b/patch/0011-Support-compress-db.patch new file mode 100644 index 0000000..0dab67f --- /dev/null +++ b/patch/0011-Support-compress-db.patch @@ -0,0 +1,460 @@ +From ddb82896cd11c541d9e9a703a995522b894727ca Mon Sep 17 00:00:00 2001 +From: MartinChoo <214582617@qq.com> +Date: Fri, 4 Jul 2025 10:05:43 +0800 +Subject: [PATCH 11/12] Support compress db + +--- + src/compressvfs.c | 440 ++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 440 insertions(+) + create mode 100644 src/compressvfs.c + +diff --git a/src/compressvfs.c b/src/compressvfs.c +new file mode 100644 +index 0000000..8f93267 +--- /dev/null ++++ b/src/compressvfs.c +@@ -0,0 +1,440 @@ ++/************** Begin file compressvfs.c *********************************************/ ++/* ++** 2025 June 26 ++** ++** The author disclaims copyright to this source code. In place of ++** a legal notice, here is a blessing: ++** ++** May you do good and not evil. ++** May you find forgiveness for yourself and forgive others. ++** May you share freely, never taking more than you give. ++** ++************************************************************************* ++** ++** This file implements a VFS shim that compress each page's data ++** of an SQLite database file. It will Open a OutterDB which used to ++** manager compressed page data and create a vfs_pages table into OutterDB. ++** When read pages's data, the data will be selected from vfs_pages and ++** decompress by compression. ++** ++** COMPILING ++** ++** This extension requires SQLite 3.44.4 or later. It uses the ++** sqlite3_database_file_object() interface which was added in ++** version 3.44.4, so it will not link with an earlier version of ++** SQLite. ++** ++** To build this extension as a separately loaded shared library or ++** DLL, use compiler command-lines similar to the following: ++** ++** (linux) gcc -fPIC -shared compressvfs.c -o sqlitecompressvfs.z.so ++** ++** You may want to add additional compiler options, of course, ++** according to the needs of your project. ++** ++** LOADING ++** ++** To use this extension as a shared library, you first have to ++** open SQLite database connection with compressvfs. ++** It will load autometically when connect to OutterDB. ++** And then compressvfs will be reegistered before open db connection. ++** After first used , all subsequent databse connections that are opened ++** will include this extension. ++** ++** Compressvfs is a VFS Shim. When loaded, "compressvfs" will registered based on ++** default VFS. This is normally what you want. ++** ++** USING ++** ++** Open database connections using the sqlite3_open() with uri "?vfs=compressvfs" or ++** sqlite3_open_v2() interfaces with zVfs parameter. ++** ++** For example: ++** ++** sqlite3 *db; ++** sqlite3_open("file:example.db?vfs=compressvfs", &db); ++** or ++** sqlite3_open_v2("example.db", &db, flag, "compressvfs"); ++** ++** After open databse connections with compressvfs, page data will be auto compressed. ++** And data can be read and written normally. ++** ++*/ ++#ifdef SQLITE_ENABLE_PAGE_COMPRESS ++#include ++SQLITE_EXTENSION_INIT1 ++#include ++#include ++#include ++#include ++#include ++#include "securec.h" ++#ifndef _WIN32 ++#include ++#endif ++ ++// hw export the symbols ++#ifdef SQLITE_EXPORT_SYMBOLS ++#if defined(__GNUC__) ++# define EXPORT_SYMBOLS __attribute__ ((visibility ("default"))) ++#elif defined(_MSC_VER) ++# define EXPORT_SYMBOLS __declspec(dllexport) ++#else ++# define EXPORT_SYMBOLS ++#endif ++#endif ++ ++/* ++** Useful datatype ++*/ ++#ifndef UINT32_TYPE ++# ifdef HAVE_UINT32_T ++# define UINT32_TYPE uint32_t ++# else ++# define UINT32_TYPE unsigned int ++# endif ++#endif ++#ifndef UINT16_TYPE ++# ifdef HAVE_UINT16_T ++# define UINT16_TYPE uint16_t ++# else ++# define UINT16_TYPE unsigned short int ++# endif ++#endif ++#ifndef INT16_TYPE ++# ifdef HAVE_INT16_T ++# define INT16_TYPE int16_t ++# else ++# define INT16_TYPE short int ++# endif ++#endif ++#ifndef UINT8_TYPE ++# ifdef HAVE_UINT8_T ++# define UINT8_TYPE uint8_t ++# else ++# define UINT8_TYPE unsigned char ++# endif ++#endif ++#ifndef INT8_TYPE ++# ifdef HAVE_INT8_T ++# define INT8_TYPE int8_t ++# else ++# define INT8_TYPE signed char ++# endif ++#endif ++#ifndef LONGDOUBLE_TYPE ++# define LONGDOUBLE_TYPE long double ++#endif ++#ifdef SQLITE_INT64_TYPE ++ typedef SQLITE_INT64_TYPE sqlite_int64; ++# ifdef SQLITE_UINT64_TYPE ++ typedef SQLITE_UINT64_TYPE sqlite_uint64; ++# else ++ typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; ++# endif ++#elif defined(_MSC_VER) || defined(__BORLANDC__) ++ typedef __int64 sqlite_int64; ++ typedef unsigned __int64 sqlite_uint64; ++#else ++ typedef long long int sqlite_int64; ++ typedef unsigned long long int sqlite_uint64; ++#endif ++typedef sqlite_int64 sqlite3_int64; ++typedef sqlite_uint64 sqlite3_uint64; ++typedef sqlite_int64 i64; /* 8-byte signed integer */ ++typedef sqlite_uint64 u64; /* 8-byte unsigned integer */ ++typedef UINT32_TYPE u32; /* 4-byte unsigned integer */ ++typedef UINT16_TYPE u16; /* 2-byte unsigned integer */ ++typedef INT16_TYPE i16; /* 2-byte signed integer */ ++typedef UINT8_TYPE u8; /* 1-byte unsigned integer */ ++typedef INT8_TYPE i8; /* 1-byte signed integer */ ++ ++typedef u32 Pgno; ++/* VFS's name */ ++#define COMPRESS_VFS_NAME "compressvfs" ++ ++/* COMPRESSION OPTIONS */ ++#define COMPRESSION_UNDEFINED 0 ++#define COMPRESSION_BROTLI 1 ++#define COMPRESSION_ZSTD 2 ++ ++ ++typedef struct compress_info compress_info; ++struct compress_info{ ++ sqlite3_vfs *pRootVfs; /* Ptr to default VFS */ ++ sqlite3* pDb; /* Ptr to OutterDB */ ++ u8 bOutterDbOpen; /* True to OutterDB is opened */ ++ u8 bSubDbOpen; /* True to SubDB is opened */ ++}; ++ ++/* An open file */ ++typedef struct{ ++ sqlite3_file base; /* IO methods */ ++ compress_info *pInfo; /* Ptr to compress info */ ++ u8 bBegin; /* True to xSync() need commit */ ++ u8 compression; /* Compression options */ ++ int page_size; /* Uncompressed page size */ ++} CompressFile; ++ ++ ++static int compressClose(sqlite3_file *pFile); ++static int compressRead(sqlite3_file *pFile, void *pBuf, int iAmt, sqlite_int64 iOfst); ++static int compressWrite(sqlite3_file *pFile, const void *pBuf, int iAmt, sqlite_int64 iOfst); ++static int compressTruncate(sqlite3_file *pFile, sqlite_int64 size); ++static int compressSync(sqlite3_file *pFile, int flags); ++static int compressFileSize(sqlite3_file *pFile, i64 *pSize); ++static int compressLock(sqlite3_file *pFile, int eFileLock); ++static int compressUnlock(sqlite3_file *pFile, int eFileLock); ++static int compressCheckReservedLock(sqlite3_file *pFile, int *pResOut); ++static int compressFileControl(sqlite3_file *pFile, int op, void *pArg); ++static int compressSectorSize(sqlite3_file *pFile); ++static int compressDeviceCharacteristics(sqlite3_file *pFile); ++static int compressShmMap(sqlite3_file *pFile, int iPg, int pgsz, int fileFlag, void volatile **pp); ++static int compressShmLock(sqlite3_file *pFile, int offset, int n, int flags); ++static void compressShmBarrier(sqlite3_file *pFile); ++static int compressShmUnmap(sqlite3_file *pFile, int deleteFlag); ++static int compressFetch(sqlite3_file *pFile, sqlite_int64 iOfst, int iAmt, void **pp); ++static int compressUnfetch(sqlite3_file *pFile, sqlite_int64 iOfst, void *pPage); ++ ++static sqlite3_vfs compress_vfs = {0}; ++static compress_info compress_vfs_info = {0}; ++static sqlite3_io_methods compress_io_methods = { ++ 3, ++ compressClose, ++ compressRead, ++ compressWrite, ++ compressTruncate, ++ compressSync, ++ compressFileSize, ++ compressLock, ++ compressUnlock, ++ compressCheckReservedLock, ++ compressFileControl, ++ compressSectorSize, ++ compressDeviceCharacteristics, ++ compressShmMap, ++ compressShmLock, ++ compressShmBarrier, ++ compressShmUnmap, ++ compressFetch, ++ compressUnfetch ++}; ++ ++/* ++** Sync a compress file. If need commit a transaction ++** which begin in compressWrite or compressTruncate. ++*/ ++static int compressSync(sqlite3_file *pFile, int flags){ ++ assert( pFile ); ++ return SQLITE_OK; ++} ++ ++/* ++** Check if another file-handle holds a RESERVED lock on a compress file. ++*/ ++static int compressCheckReservedLock(sqlite3_file *pFile, int *pResOut){ ++ assert( pFile ); ++ return SQLITE_OK; ++} ++ ++/* ++** File control method. Use default VFS's xFileControl. ++*/ ++static int compressFileControl(sqlite3_file *pFile, int op, void *pArg){ ++ assert( pFile ); ++ return SQLITE_OK; ++} ++ ++/* ++** Return the sector-size in bytes for a file. Use default VFS's xSectorSize. ++*/ ++static int compressSectorSize(sqlite3_file *pFile){ ++ assert( pFile ); ++ return SQLITE_OK; ++} ++ ++/* ++** Return the device characteristic flags supported by a file. ++** Use default VFS's xDeviceCharacteristics. ++*/ ++static int compressDeviceCharacteristics(sqlite3_file *pFile){ ++ assert( pFile ); ++ return SQLITE_OK; ++} ++ ++/* ++** Lock a compress file.Never lock InnerDB, because it wil not control the database file. ++*/ ++static int compressLock(sqlite3_file *pFile, int eFileLock){ ++ assert( pFile ); ++ return SQLITE_OK; ++} ++ ++/* ++** Unlock a compress file.Never unlock InnerDB, because it wil not control the database file. ++*/ ++static int compressUnlock(sqlite3_file *pFile, int eFileLock){ ++ assert( pFile ); ++ return SQLITE_OK; ++} ++ ++/* ++** Get File's size. Here wil return InnerDB's file size. ++*/ ++static int compressFileSize(sqlite3_file *pFile, i64 *pSize){ ++ assert( pFile ); ++ return SQLITE_OK; ++} ++ ++/* ++** Truncate a compress file by delete from vfs_pages. ++*/ ++static int compressTruncate(sqlite3_file *pFile, sqlite_int64 size){ ++ assert( pFile ); ++ return SQLITE_OK; ++} ++ ++/* ++** Write one page of data to compress file at a time. ++** It will be compressed and insert into vfs_pages in OutterDB. ++*/ ++static int compressWrite(sqlite3_file *pFile, const void *pBuf, int iAmt, sqlite_int64 iOfst){ ++ assert( pFile ); ++ assert( iAmt>0 ); ++ return SQLITE_OK; ++} ++ ++/* ++** Read data from compress file. ++** It will be selected from vfs_pages in OutterDB and return a decompressed buf. ++*/ ++static int compressRead(sqlite3_file *pFile, void *pBuf, int iAmt, sqlite_int64 iOfst){ ++ assert( pFile ); ++ assert( iOfst>=0 ); ++ assert( iAmt>0 ); ++ return SQLITE_OK; ++} ++ ++/* ++** Close compress file. Need sync data and close OutterDB and InnerDB. ++*/ ++static int compressClose(sqlite3_file *pFile){ ++ assert( pFile ); ++ return SQLITE_OK; ++} ++ ++/* ++** Create a shared memory file mapping. Need to rename the shm file, append a tail named "compress." ++*/ ++static int compressShmMap( ++ sqlite3_file *pFile, ++ int iPg, ++ int pgsz, ++ int fileFlag, ++ void volatile **pp ++){ ++ assert( pFile ); ++ return SQLITE_OK; ++} ++ ++/* Perform locking on a shared-memory segment */ ++static int compressShmLock(sqlite3_file *pFile, int offset, int n, int flags){ ++ assert( pFile ); ++ return SQLITE_OK; ++} ++ ++/* Memory barrier operation on shared memory */ ++static void compressShmBarrier(sqlite3_file *pFile){ ++ assert( pFile ); ++ return SQLITE_OK; ++} ++ ++/* Unmap a shared memory segment */ ++static int compressShmUnmap(sqlite3_file *pFile, int deleteFlag){ ++ assert( pFile ); ++ return SQLITE_OK; ++} ++ ++/* Fetch a page of a memory-mapped file */ ++static int compressFetch(sqlite3_file *pFile, sqlite_int64 iOfst, int iAmt, void **pp){ ++ assert( pFile ); ++ return SQLITE_OK; ++} ++ ++/* Release a memory-mapped page */ ++static int compressUnfetch(sqlite3_file *pFile, sqlite_int64 iOfst, void *pPage){ ++ assert( pFile ); ++ return SQLITE_OK; ++} ++ ++/* ++** 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 ++** which used to manager compressed pages's data. ++*/ ++static int compressOpen( ++ sqlite3_vfs *pVfs, ++ const char *zName, ++ sqlite3_file *pFile, ++ int flags, ++ int *pOutFlags ++){ ++ return SQLITE_OK; ++} ++ ++/* ++** Delete compress file. If this file is journal or wal, need to delete the InnerDB's renamed file. ++*/ ++static int compressDelete(sqlite3_vfs *pVfs, const char *zName, int syncDir){ ++ return SQLITE_OK; ++} ++ ++/* ++** Access compress file. If this file is journal or wal need to access the InnerDB's renamed file. ++*/ ++static int compressAccess( ++ sqlite3_vfs *pVfs, ++ const char *zName, ++ int flags, ++ int *pResOut ++){ ++ return SQLITE_OK; ++} ++ ++ ++/* ++** Init compressvfs and register the vfs ++*/ ++EXPORT_SYMBOLS int sqlite3CompressvfsInit(){ ++ // copy default vfs for compressvfs ++ if( sqlite3_vfs_find(COMPRESS_VFS_NAME) ){ ++ return SQLITE_OK; ++ } ++ sqlite3_vfs *default_vfs = sqlite3_vfs_find(0); ++ if( default_vfs==0 ){ ++ sqlite3_log(SQLITE_ERROR, "Default vfs not found!"); ++ return SQLITE_ERROR; ++ } ++ sqlite3_vfs *pVfs = &compress_vfs; ++ compress_info *pInfo = &compress_vfs_info; ++ *pVfs = *default_vfs; ++ pVfs->pNext = 0; ++ pVfs->zName = COMPRESS_VFS_NAME; ++ pVfs->pAppData = pInfo; ++ pVfs->szOsFile = pVfs->szOsFile+sizeof(CompressFile); ++ ++ pVfs->xOpen = compressOpen; ++ pVfs->xDelete = compressDelete; ++ pVfs->xAccess = compressAccess; ++ pInfo->pRootVfs = default_vfs; ++ pInfo->bSubDbOpen = 0; ++ pInfo->bOutterDbOpen = 0; ++ int rc = sqlite3_vfs_register(pVfs, 0); ++ if( rc!=SQLITE_OK ){ ++ sqlite3_log(SQLITE_ERROR, "Compress vfs register error!"); ++ return rc; ++ } ++ return SQLITE_OK; ++} ++ ++#endif /* SQLITE_ENABLE_PAGE_COMPRESS */ +\ No newline at end of file +-- +2.47.0.windows.2 + diff --git a/patch/0011-Bug-fixes-on-current-version.patch b/patch/0012-Bugfix-on-current-version.patch similarity index 89% rename from patch/0011-Bug-fixes-on-current-version.patch rename to patch/0012-Bugfix-on-current-version.patch index 1c5aaf3..a8b8350 100644 --- a/patch/0011-Bug-fixes-on-current-version.patch +++ b/patch/0012-Bugfix-on-current-version.patch @@ -1,18 +1,17 @@ -From 7bb232b30ce94a323c92c93a30df658a02d4d702 Mon Sep 17 00:00:00 2001 +From 52770347b08c1e477d58834668572a1dc882ed69 Mon Sep 17 00:00:00 2001 From: MartinChoo <214582617@qq.com> -Date: Sat, 7 Jun 2025 23:07:45 +0800 -Subject: [PATCH] Bug fixes on current version +Date: Sat, 5 Jul 2025 10:45:06 +0800 +Subject: [PATCH 12/12] Bugfix on current version -Signed-off-by: MartinChoo <214582617@qq.com> --- src/sqlite3.c | 239 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 193 insertions(+), 46 deletions(-) diff --git a/src/sqlite3.c b/src/sqlite3.c -index 80d7979..6ab872e 100644 +index 24e3247..ec7c250 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c -@@ -38786,8 +38786,8 @@ static void enableDbFileDelMonitor(int32_t fd) +@@ -38790,8 +38790,8 @@ static void enableDbFileDelMonitor(int32_t fd) } flags |= HMFS_MONITOR_FL; ret = ioctl(fd, HMFS_IOCTL_HW_SET_FLAGS, &flags); @@ -23,7 +22,7 @@ index 80d7979..6ab872e 100644 } } -@@ -57786,6 +57786,8 @@ static void MetaDwrCheckVacuum(BtShared *pBt); +@@ -57790,6 +57790,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); @@ -32,7 +31,7 @@ index 80d7979..6ab872e 100644 #define META_HEADER_CHANGED 1 #define META_SCHEMA_CHANGED 2 #define META_IN_RECOVERY 1 -@@ -59564,11 +59566,12 @@ static int pager_end_transaction(Pager *pPager, int hasSuper, int bCommit){ +@@ -59568,11 +59570,12 @@ static int pager_end_transaction(Pager *pPager, int hasSuper, int bCommit){ sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize); } #ifdef SQLITE_META_DWR @@ -50,7 +49,7 @@ index 80d7979..6ab872e 100644 } #endif if( pagerUseWal(pPager) ){ -@@ -74672,6 +74675,11 @@ static int lockBtree(BtShared *pBt){ +@@ -74676,6 +74679,11 @@ static int lockBtree(BtShared *pBt){ } if( nPage>nPageFile ){ if( sqlite3WritableSchema(pBt->db)==0 ){ @@ -62,7 +61,7 @@ index 80d7979..6ab872e 100644 rc = SQLITE_CORRUPT_BKPT; goto page1_init_failed; }else{ -@@ -121520,8 +121528,8 @@ static void attachFunc( +@@ -121536,8 +121544,8 @@ static void attachFunc( if( rc==SQLITE_OK ){ extern int sqlite3CodecAttach(sqlite3*, int, const void*, int); extern void sqlite3CodecGetKey(sqlite3*, int, void**, int*); @@ -73,7 +72,7 @@ index 80d7979..6ab872e 100644 int t = sqlite3_value_type(argv[2]); switch( t ){ case SQLITE_INTEGER: -@@ -121538,14 +121546,7 @@ static void attachFunc( +@@ -121554,14 +121562,7 @@ static void attachFunc( break; case SQLITE_NULL: @@ -89,7 +88,7 @@ index 80d7979..6ab872e 100644 break; } } -@@ -183717,10 +183718,12 @@ opendb_out: +@@ -183733,10 +183734,12 @@ opendb_out: db->eOpenState = SQLITE_STATE_SICK; } #ifdef SQLITE_ENABLE_DROPTABLE_CALLBACK @@ -106,7 +105,7 @@ index 80d7979..6ab872e 100644 #endif /* SQLITE_ENABLE_DROPTABLE_CALLBACK */ #ifdef SQLITE_ENABLE_BINLOG sqlite3BinlogReset(db); -@@ -204166,6 +204169,39 @@ static int fts3ExprTermOffsetInit(Fts3Expr *pExpr, int iPhrase, void *ctx){ +@@ -204182,6 +204185,39 @@ static int fts3ExprTermOffsetInit(Fts3Expr *pExpr, int iPhrase, void *ctx){ return rc; } @@ -146,7 +145,7 @@ index 80d7979..6ab872e 100644 /* ** Implementation of offsets() function. */ -@@ -204202,6 +204238,12 @@ SQLITE_PRIVATE void sqlite3Fts3Offsets( +@@ -204218,6 +204254,12 @@ SQLITE_PRIVATE void sqlite3Fts3Offsets( sCtx.iDocid = pCsr->iPrevId; sCtx.pCsr = pCsr; @@ -159,7 +158,7 @@ index 80d7979..6ab872e 100644 /* Loop through the table columns, appending offset information to ** string-buffer res for each column. */ -@@ -254388,7 +254430,20 @@ SQLITE_API int sqlite3_stmt_init( +@@ -254404,7 +254446,20 @@ SQLITE_API int sqlite3_stmt_init( /* Return the source-id for this library */ SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } /************************** End of sqlite3.c ******************************/ @@ -181,7 +180,7 @@ index 80d7979..6ab872e 100644 #ifdef SQLITE_HAS_CODEC /************** Begin file hw_codec_openssl.h *******************************/ #ifndef EXPOSE_INTERNAL_FUNC -@@ -255582,6 +255637,7 @@ int sqlite3CodecAttach(sqlite3* db, int nDb, const void *pKey, int nKey){ +@@ -255598,6 +255653,7 @@ int sqlite3CodecAttach(sqlite3* db, int nDb, const void *pKey, int nKey){ } } #endif @@ -189,7 +188,7 @@ index 80d7979..6ab872e 100644 #ifdef SQLITE_CODEC_ATTACH_CHANGED int rc = sqlite3CodecInitContext(ctx, p, pKey, nKey, nDb); #else -@@ -256176,7 +256232,12 @@ typedef struct MetaDwrHdr { +@@ -256192,7 +256248,12 @@ typedef struct MetaDwrHdr { u32 pageSz; u32 pageCnt; u64 dbFileInode; @@ -203,7 +202,7 @@ index 80d7979..6ab872e 100644 u32 checkSum; u8 *zones; Pgno *pages; -@@ -256539,6 +256600,87 @@ static inline u64 CaculateMetaDwrWriteOffset(int pageSz, u32 idx, u8 zone) { +@@ -256555,6 +256616,87 @@ static inline u64 CaculateMetaDwrWriteOffset(int pageSz, u32 idx, u8 zone) { return META_DWR_HEADER_PAGE_SIZE + pageSz * (idx * 2 + zone); } @@ -291,7 +290,7 @@ index 80d7979..6ab872e 100644 static void MetaDwrUpdateHeaderDbInfo(BtShared *pBt) { MetaDwrHdr *hdr = pBt->pPager->metaHdr; // 28 offset: dbSize, freelist pageNo, freelist pages count, schema cookie -@@ -256759,11 +256901,12 @@ static int MetaDwrOpenFile(Pager *pPager, u8 openCreate) { +@@ -256775,11 +256917,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); @@ -309,7 +308,7 @@ index 80d7979..6ab872e 100644 } } #endif /* SQLITE_OS_UNIX */ -@@ -257137,7 +257280,7 @@ CHK_RESTORE_OUT: +@@ -257153,7 +257296,7 @@ CHK_RESTORE_OUT: return rc; } @@ -318,7 +317,7 @@ index 80d7979..6ab872e 100644 { #if SQLITE_OS_UNIX if (pPager->pVfs == NULL) { -@@ -257151,10 +257294,18 @@ static inline u8 IsConnectionValidForCheck(Pager *pPager) +@@ -257167,10 +257310,18 @@ static inline u8 IsConnectionValidForCheck(Pager *pPager) checkFileId = SQLITE_CHECK_FILE_ID_CKSM; } unixFile *fd = Sqlite3GetUnixFile(pPager->fd, checkFileId); @@ -338,7 +337,7 @@ index 80d7979..6ab872e 100644 return 1; #else return 0; -@@ -257164,7 +257315,7 @@ static inline u8 IsConnectionValidForCheck(Pager *pPager) +@@ -257180,7 +257331,7 @@ static inline u8 IsConnectionValidForCheck(Pager *pPager) static int MetaDwrOpenAndCheck(Btree *pBt) { Pager *pPager = pBt->pBt->pPager; @@ -347,7 +346,7 @@ index 80d7979..6ab872e 100644 return SQLITE_OK; } #ifdef SQLITE_HAS_CODEC -@@ -257209,7 +257360,7 @@ DWR_OPEN_OUT: +@@ -257225,7 +257376,7 @@ DWR_OPEN_OUT: static void MetaDwrDisable(Btree *pBt) { Pager *pPager = pBt->pBt->pPager; @@ -356,7 +355,7 @@ index 80d7979..6ab872e 100644 return; } #ifdef SQLITE_HAS_CODEC -@@ -257235,19 +257386,6 @@ static void MetaDwrDisable(Btree *pBt) +@@ -257251,19 +257402,6 @@ static void MetaDwrDisable(Btree *pBt) #endif /* SQLITE_META_DWR */ #if SQLITE_OS_UNIX @@ -376,7 +375,7 @@ index 80d7979..6ab872e 100644 static void ResetLockStatus(void) { (void)memset(&g_lockStatus, 0, sizeof(g_lockStatus)); -@@ -257351,8 +257489,13 @@ static inline const char *FlockToName(int l_type) +@@ -257367,8 +257505,13 @@ static inline const char *FlockToName(int l_type) static int DumpProcessLocks(int fd, struct flock *lock, const char *lockName, char *dumpBuf, int bufLen) { @@ -391,7 +390,7 @@ index 80d7979..6ab872e 100644 sqlite3_log(SQLITE_ERROR, "[SQLite]Get wal file lock ofs %u failed, errno: %d", lock->l_start, errno); return 0; } -@@ -258422,7 +258565,11 @@ struct sqlite3_api_routines_hw { +@@ -258599,7 +258742,11 @@ struct sqlite3_api_routines_hw { int (*rekey_v2)(sqlite3*,const char*,const void*,int); int (*is_support_binlog)(void); int (*replay_binlog)(sqlite3*, sqlite3*); diff --git a/patch/BUILD.gn b/patch/BUILD.gn index 2abaadd..f3232ac 100644 --- a/patch/BUILD.gn +++ b/patch/BUILD.gn @@ -24,6 +24,7 @@ action("apply_patch") { outputs = [ "$sqlite_dst_dir/ext/misc/cksumvfs.c", "$sqlite_dst_dir/src/shell.c", + "$sqlite_dst_dir/src/compressvfs.c", "$sqlite_dst_dir/src/sqlite3.c", "$sqlite_dst_dir/src/sqlite3icu.c", "$sqlite_dst_dir/include/sqlite3ext.h", -- Gitee