From b15d3a0a8c61a230ecaedd9689f7f430772cad74 Mon Sep 17 00:00:00 2001 From: bluhuang Date: Tue, 8 Apr 2025 15:44:32 +0800 Subject: [PATCH] Subject: [PATCH] Enable and optimize ICU, add icu config Signed-off-by: bluhuang --- include/sqlite3.h | 2 +- patch/0004-Enable-and-optimize-ICU.patch | 93 ++++---- ...ort-corruption-when-runtime-decteted.patch | 208 +++++++++--------- 3 files changed, 145 insertions(+), 158 deletions(-) diff --git a/include/sqlite3.h b/include/sqlite3.h index 3b1a37a..4e6b0be 100644 --- a/include/sqlite3.h +++ b/include/sqlite3.h @@ -612,6 +612,7 @@ SQLITE_API int sqlite3_exec( #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ +#define SQLITE_OPEN_ICU_ENABLE 0x00100000 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */ #define SQLITE_OPEN_EXRESCODE 0x02000000 /* Extended result codes */ @@ -2207,7 +2208,6 @@ struct sqlite3_mem_methods { #define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */ #define SQLITE_CONFIG_ROWID_IN_VIEW 30 /* int* */ #define SQLITE_CONFIG_CORRUPTION 31 /* xCorruption */ -#define SQLITE_CONFIG_ENABLE_ICU 32 /* boolean */ /* ** CAPI3REF: Database Connection Configuration Options diff --git a/patch/0004-Enable-and-optimize-ICU.patch b/patch/0004-Enable-and-optimize-ICU.patch index fbfdd4b..1d0b4f4 100644 --- a/patch/0004-Enable-and-optimize-ICU.patch +++ b/patch/0004-Enable-and-optimize-ICU.patch @@ -1,27 +1,23 @@ -From 5526b966d88575fd479dfe69af0c70c4ac43de14 Mon Sep 17 00:00:00 2001 -From: MartinChoo <214582617@qq.com> -Date: Tue, 25 Feb 2025 17:02:54 +0800 -Subject: [PATCH] Enable and optimize ICU +commit 4dfd9ac2b16ca0ebedebb6b29e108a1e8bccf9bd +Author: bluhuang +Date: Tue Apr 8 15:38:30 2025 +0800 -Signed-off-by: MartinChoo <214582617@qq.com> ---- - src/sqlite3.c | 1065 ++++------------------------------------------ - src/sqlite3icu.c | 925 ++++++++++++++++++++++++++++++++++++++++ - 2 files changed, 1009 insertions(+), 981 deletions(-) - create mode 100644 src/sqlite3icu.c + Subject: [PATCH] Enable and optimize ICU, add icu config + + Signed-off-by: bluhuang diff --git a/src/sqlite3.c b/src/sqlite3.c -index 17d0d25..f348f3c 100644 +index 17d0d25..fd7b3d5 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c -@@ -2506,6 +2506,7 @@ struct sqlite3_mem_methods { - #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */ - #define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */ - #define SQLITE_CONFIG_ROWID_IN_VIEW 30 /* int* */ -+#define SQLITE_CONFIG_ENABLE_ICU 31 /* boolean */ +@@ -927,6 +927,7 @@ SQLITE_API int sqlite3_exec( + #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */ + #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */ + #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */ ++#define SQLITE_OPEN_ICU_ENABLE 0x00100000 /* Ok for sqlite3_open_v2() */ + #define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */ + #define SQLITE_OPEN_EXRESCODE 0x02000000 /* Extended result codes */ - /* - ** CAPI3REF: Database Connection Configuration Options @@ -3283,6 +3284,17 @@ SQLITE_API int sqlite3_get_table( ); SQLITE_API void sqlite3_free_table(char **result); @@ -40,7 +36,17 @@ index 17d0d25..f348f3c 100644 /* ** CAPI3REF: Formatted String Printing Functions ** -@@ -181005,6 +181017,7 @@ SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db); +@@ -17876,6 +17888,9 @@ struct sqlite3 { + #if defined(SQLITE_HAS_CODEC) && defined(SQLITE_CODEC_ATTACH_CHANGED) + CodecParameter codecParm; + #endif /* defined(SQLITE_HAS_CODEC) && defined(SQLITE_CODEC_ATTACH_CHANGED) */ ++#if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS) ++ u32 icuEnable; ++#endif + }; + + /* +@@ -181005,6 +181020,7 @@ SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db); /************** End of rtree.h ***********************************************/ /************** Continuing where we left off in main.c ***********************/ #endif @@ -48,7 +54,7 @@ index 17d0d25..f348f3c 100644 #if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS) /************** Include sqliteicu.h in the middle of main.c ******************/ /************** Begin file sqliteicu.h ***************************************/ -@@ -181029,13 +181042,54 @@ SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db); +@@ -181029,13 +181045,53 @@ SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db); extern "C" { #endif /* __cplusplus */ @@ -68,7 +74,6 @@ index 17d0d25..f348f3c 100644 +typedef int (*sqlite3IcuInit_ptr)(sqlite3 *db); +static sqlite3Fts3IcuTokenizerModule_ptr tokenModulePtr = NULL; +static sqlite3IcuInit_ptr icuInitPtr = NULL; -+static u32 icuEnable = 0u; +static u32 icuInit = 0u; +static void *g_library = NULL; + @@ -96,7 +101,7 @@ index 17d0d25..f348f3c 100644 + +SQLITE_PRIVATE int sqlite3IcuInitInner(sqlite3 *db) +{ -+ if( !icuEnable ){ ++ if( !db->icuEnable ){ + return SQLITE_OK; + } + return icuInitPtr(db); @@ -104,7 +109,7 @@ index 17d0d25..f348f3c 100644 /************** Continuing where we left off in main.c ***********************/ #endif -@@ -181075,7 +181129,7 @@ static int (*const sqlite3BuiltinExtensions[])(sqlite3*) = { +@@ -181075,7 +181131,7 @@ static int (*const sqlite3BuiltinExtensions[])(sqlite3*) = { sqlite3Fts5Init, #endif #if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS) @@ -113,27 +118,15 @@ index 17d0d25..f348f3c 100644 #endif #ifdef SQLITE_ENABLE_RTREE sqlite3RtreeInit, -@@ -181467,6 +181521,19 @@ SQLITE_API int sqlite3_shutdown(void){ +@@ -181467,6 +181523,7 @@ SQLITE_API int sqlite3_shutdown(void){ SQLITE_API int sqlite3_config(int op, ...){ va_list ap; int rc = SQLITE_OK; + va_start(ap, op); -+ -+#if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS) -+ if( op==SQLITE_CONFIG_ENABLE_ICU ){ -+ int iVal = va_arg(ap, int); -+ if( iVal==0 ){ -+ icuEnable = 0u; -+ }else{ -+ icuEnable = 1u; -+ } -+ return rc; -+ } -+#endif /* SQLITE_ENABLE_ICU */ /* sqlite3_config() normally returns SQLITE_MISUSE if it is invoked while ** the SQLite library is in use. Except, a few selected opcodes -@@ -181484,7 +181551,6 @@ SQLITE_API int sqlite3_config(int op, ...){ +@@ -181484,7 +181541,6 @@ SQLITE_API int sqlite3_config(int op, ...){ testcase( op==SQLITE_CONFIG_PCACHE_HDRSZ ); } @@ -141,12 +134,13 @@ index 17d0d25..f348f3c 100644 switch( op ){ /* Mutex configuration options are only available in a threadsafe -@@ -184609,6 +184675,12 @@ static int openDatabase( +@@ -184609,6 +184665,13 @@ static int openDatabase( sqlite3RegisterPerConnectionBuiltinFunctions(db); rc = sqlite3_errcode(db); +#if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS) -+ if( icuEnable ){ ++ db->icuEnable = flags & SQLITE_OPEN_ICU_ENABLE; ++ if (db->icuEnable) { + rc = sqlite3IcuModuleInit(); + if( rc!=SQLITE_OK ) return rc; + } @@ -154,7 +148,7 @@ index 17d0d25..f348f3c 100644 /* Load compiled-in extensions */ for(i=0; rc==SQLITE_OK && iicuEnable ){ + if( tokenModulePtr!=NULL ){ + tokenModulePtr(&pIcu); + }else{ @@ -295,16 +289,16 @@ index 17d0d25..f348f3c 100644 #endif #ifndef SQLITE_DISABLE_FTS3_UNICODE -@@ -191633,7 +191601,7 @@ SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){ +@@ -191633,7 +191592,7 @@ SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db){ || sqlite3Fts3HashInsert(&pHash->hash, "unicode61", 10, (void *)pUnicode) #endif #ifdef SQLITE_ENABLE_ICU - || (pIcu && sqlite3Fts3HashInsert(&pHash->hash, "icu", 4, (void *)pIcu)) -+ || (icuEnable && pIcu && sqlite3Fts3HashInsert(&pHash->hash, "icu", 4, (void *)pIcu)) ++ || (db->icuEnable && pIcu && sqlite3Fts3HashInsert(&pHash->hash, "icu", 4, (void *)pIcu)) #endif ){ rc = SQLITE_NOMEM; -@@ -217955,862 +217923,6 @@ SQLITE_API int sqlite3_rtree_init( +@@ -217955,862 +217914,6 @@ SQLITE_API int sqlite3_rtree_init( #endif /************** End of rtree.c ***********************************************/ @@ -1167,7 +1161,7 @@ index 17d0d25..f348f3c 100644 /************** Begin file sqlite3rbu.c **************************************/ /* ** 2014 August 30 -@@ -261916,15 +261028,6 @@ static void DumpLocksByPager(Pager *pPager) +@@ -261916,15 +261019,6 @@ static void DumpLocksByPager(Pager *pPager) // hw export the symbols #ifdef SQLITE_EXPORT_SYMBOLS @@ -1185,7 +1179,7 @@ index 17d0d25..f348f3c 100644 int (*config)(int,...); diff --git a/src/sqlite3icu.c b/src/sqlite3icu.c new file mode 100644 -index 0000000..75aa78c +index 0000000..288cff8 --- /dev/null +++ b/src/sqlite3icu.c @@ -0,0 +1,925 @@ @@ -2114,6 +2108,3 @@ index 0000000..75aa78c +#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */ + +/************** End of fts3_icu.c ********************************************/ --- -2.47.0.windows.2 - diff --git a/patch/0005-Report-corruption-when-runtime-decteted.patch b/patch/0005-Report-corruption-when-runtime-decteted.patch index 2af605a..1ba3a6d 100644 --- a/patch/0005-Report-corruption-when-runtime-decteted.patch +++ b/patch/0005-Report-corruption-when-runtime-decteted.patch @@ -1,18 +1,19 @@ -From 0fdc896d7434be7ad9a3947aaca13d5ce760547d Mon Sep 17 00:00:00 2001 -From: MartinChoo <214582617@qq.com> -Date: Tue, 25 Feb 2025 22:16:42 +0800 -Subject: [PATCH] Report corruption when runtime detected +commit 4c766b25b23090ca8d145376dbfd283f179d1719 +Author: bluhuang +Date: Tue Apr 8 15:54:07 2025 +0800 -Signed-off-by: MartinChoo <214582617@qq.com> ---- - src/sqlite3.c | 717 ++++++++++++++++++++++++++++++++++++++++++-------- - 1 file changed, 605 insertions(+), 112 deletions(-) + From 0fdc896d7434be7ad9a3947aaca13d5ce760547d Mon Sep 17 00:00:00 2001 + From: MartinChoo <214582617@qq.com> + Date: Tue, 25 Feb 2025 22:16:42 +0800 + Subject: [PATCH] Report corruption when runtime detected + + Signed-off-by: MartinChoo <214582617@qq.com> diff --git a/src/sqlite3.c b/src/sqlite3.c -index f348f3c..0666938 100644 +index fd7b3d5..5d9e646 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c -@@ -2474,6 +2474,21 @@ struct sqlite3_mem_methods { +@@ -2475,6 +2475,21 @@ struct sqlite3_mem_methods { ** is compiled without -DSQLITE_ALLOW_ROWID_IN_VIEW (which is the usual and ** recommended case) then the integer is always filled with zero, regardless ** if its initial value. @@ -34,17 +35,15 @@ index f348f3c..0666938 100644 ** */ #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */ -@@ -2506,7 +2521,8 @@ struct sqlite3_mem_methods { +@@ -2507,6 +2522,7 @@ struct sqlite3_mem_methods { #define SQLITE_CONFIG_SORTERREF_SIZE 28 /* int nByte */ #define SQLITE_CONFIG_MEMDB_MAXSIZE 29 /* sqlite3_int64 */ #define SQLITE_CONFIG_ROWID_IN_VIEW 30 /* int* */ --#define SQLITE_CONFIG_ENABLE_ICU 31 /* boolean */ +#define SQLITE_CONFIG_CORRUPTION 31 /* xCorruption */ -+#define SQLITE_CONFIG_ENABLE_ICU 32 /* boolean */ /* ** CAPI3REF: Database Connection Configuration Options -@@ -20360,6 +20376,8 @@ struct Sqlite3Config { +@@ -20363,6 +20379,8 @@ struct Sqlite3Config { int iOnceResetThreshold; /* When to reset OP_Once counters */ u32 szSorterRef; /* Min size in bytes to use sorter-refs */ unsigned int iPrngSeed; /* Alternative fixed seed for the PRNG */ @@ -53,7 +52,7 @@ index f348f3c..0666938 100644 /* vvvv--- must be last ---vvv */ #ifdef SQLITE_DEBUG sqlite3_int64 aTune[SQLITE_NTUNE]; /* Tuning parameters */ -@@ -20627,6 +20645,57 @@ SQLITE_PRIVATE Window *sqlite3WindowAssemble(Parse*, Window*, ExprList*, ExprLis +@@ -20630,6 +20648,57 @@ SQLITE_PRIVATE Window *sqlite3WindowAssemble(Parse*, Window*, ExprList*, ExprLis } \ } @@ -111,7 +110,7 @@ index f348f3c..0666938 100644 /* ** The SQLITE_*_BKPT macros are substitutes for the error codes with ** the same name but without the _BKPT suffix. These macros invoke -@@ -20635,10 +20704,11 @@ SQLITE_PRIVATE Window *sqlite3WindowAssemble(Parse*, Window*, ExprList*, ExprLis +@@ -20638,10 +20707,11 @@ SQLITE_PRIVATE Window *sqlite3WindowAssemble(Parse*, Window*, ExprList*, ExprLis ** to set a debugger breakpoint. */ SQLITE_PRIVATE int sqlite3ReportError(int iErr, int lineno, const char *zType); @@ -125,7 +124,7 @@ index f348f3c..0666938 100644 #define SQLITE_MISUSE_BKPT sqlite3MisuseError(__LINE__) #define SQLITE_CANTOPEN_BKPT sqlite3CantopenError(__LINE__) #ifdef SQLITE_DEBUG -@@ -20650,12 +20720,13 @@ SQLITE_PRIVATE int sqlite3IoerrnomemError(int); +@@ -20653,12 +20723,13 @@ SQLITE_PRIVATE int sqlite3IoerrnomemError(int); # define SQLITE_NOMEM_BKPT SQLITE_NOMEM # define SQLITE_IOERR_NOMEM_BKPT SQLITE_IOERR_NOMEM #endif @@ -142,7 +141,7 @@ index f348f3c..0666938 100644 /* ** FTS3 and FTS4 both require virtual table support -@@ -23111,6 +23182,8 @@ SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = { +@@ -23114,6 +23185,8 @@ SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = { 0x7ffffffe, /* iOnceResetThreshold */ SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */ 0, /* iPrngSeed */ @@ -151,7 +150,7 @@ index f348f3c..0666938 100644 #ifdef SQLITE_DEBUG {0,0,0,0,0,0}, /* aTune */ #endif -@@ -60758,7 +60831,7 @@ static int readDbPage(PgHdr *pPg){ +@@ -60761,7 +60834,7 @@ static int readDbPage(PgHdr *pPg){ assert( isOpen(pPager->fd) ); if( pagerUseWal(pPager) ){ @@ -160,7 +159,7 @@ index f348f3c..0666938 100644 if( rc ) return rc; } if( iFrame ){ -@@ -63281,7 +63354,12 @@ static int getPageNormal( +@@ -63284,7 +63357,12 @@ static int getPageNormal( assert( assert_pager_state(pPager) ); assert( pPager->hasHeldSharedLock==1 ); @@ -174,7 +173,7 @@ index f348f3c..0666938 100644 pBase = sqlite3PcacheFetch(pPager->pPCache, pgno, 3); if( pBase==0 ){ pPg = 0; -@@ -63313,7 +63391,11 @@ static int getPageNormal( +@@ -63316,7 +63394,11 @@ static int getPageNormal( ** (2) Never try to fetch the locking page */ if( pgno==PAGER_SJ_PGNO(pPager) ){ @@ -187,7 +186,7 @@ index f348f3c..0666938 100644 goto pager_acquire_err; } -@@ -63399,7 +63481,10 @@ static int getPageMMap( +@@ -63402,7 +63484,10 @@ static int getPageMMap( ** test in the previous statement, and avoid testing pgno==0 in the ** common case where pgno is large. */ if( pgno<=1 && pgno==0 ){ @@ -199,7 +198,7 @@ index f348f3c..0666938 100644 } assert( pPager->eState>=PAGER_READER ); assert( assert_pager_state(pPager) ); -@@ -65010,7 +65095,11 @@ SQLITE_PRIVATE int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, i +@@ -65013,7 +65098,11 @@ SQLITE_PRIVATE int sqlite3PagerMovepage(Pager *pPager, DbPage *pPg, Pgno pgno, i if( pPgOld ){ if( NEVER(pPgOld->nRef>1) ){ sqlite3PagerUnrefNotNull(pPgOld); @@ -212,7 +211,7 @@ index f348f3c..0666938 100644 } pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC); if( pPager->tempFile ){ -@@ -66940,7 +67029,13 @@ static int walIndexAppend(Wal *pWal, u32 iFrame, u32 iPage){ +@@ -66943,7 +67032,13 @@ static int walIndexAppend(Wal *pWal, u32 iFrame, u32 iPage){ /* Write the aPgno[] array entry and the hash-table slot. */ nCollide = idx; for(iKey=walHash(iPage); sLoc.aHash[iKey]; iKey=walNextHash(iKey)){ @@ -227,7 +226,7 @@ index f348f3c..0666938 100644 } sLoc.aPgno[idx-1] = iPage; AtomicStore(&sLoc.aHash[iKey], (ht_slot)idx); -@@ -67889,7 +67984,13 @@ static int walCheckpoint( +@@ -67892,7 +67987,13 @@ static int walCheckpoint( ** database plus the amount of data in the wal file, plus the ** maximum size of the pending-byte page (65536 bytes), then ** must be corruption somewhere. */ @@ -242,7 +241,7 @@ index f348f3c..0666938 100644 }else{ sqlite3OsFileControlHint(pWal->pDbFd, SQLITE_FCNTL_SIZE_HINT,&nReq); } -@@ -69201,7 +69302,11 @@ static int walFindFrame( +@@ -69204,7 +69305,11 @@ static int walFindFrame( } if( (nCollide--)==0 ){ *piRead = 0; @@ -255,7 +254,7 @@ index f348f3c..0666938 100644 } iKey = walNextHash(iKey); } -@@ -70005,7 +70110,12 @@ SQLITE_PRIVATE int sqlite3WalCheckpoint( +@@ -70008,7 +70113,12 @@ SQLITE_PRIVATE int sqlite3WalCheckpoint( /* Copy data from the log to the database file. */ if( rc==SQLITE_OK ){ if( pWal->hdr.mxFrame && walPagesize(pWal)!=nBuf ){ @@ -269,7 +268,7 @@ index f348f3c..0666938 100644 }else{ rc = walCheckpoint(pWal, db, eMode2, xBusy2, pBusyArg, sync_flags,zBuf); } -@@ -71469,7 +71579,7 @@ static int checkDbHeaderValid(sqlite3 *db, int iDbpage, u8 *zBuf){ +@@ -71472,7 +71582,7 @@ static int checkDbHeaderValid(sqlite3 *db, int iDbpage, u8 *zBuf){ ** with the page number and filename associated with the (MemPage*). */ #ifdef SQLITE_DEBUG @@ -278,7 +277,7 @@ index f348f3c..0666938 100644 char *zMsg; sqlite3BeginBenignMalloc(); zMsg = sqlite3_mprintf("database corruption page %u of %s", -@@ -71480,11 +71590,11 @@ int corruptPageError(int lineno, MemPage *p){ +@@ -71483,11 +71593,11 @@ int corruptPageError(int lineno, MemPage *p){ sqlite3ReportError(SQLITE_CORRUPT, lineno, zMsg); } sqlite3_free(zMsg); @@ -293,7 +292,7 @@ index f348f3c..0666938 100644 #endif /* Default value for SHARED_LOCK_TRACE macro if shared-cache is disabled -@@ -72210,7 +72320,12 @@ static int btreeMoveto( +@@ -72213,7 +72323,12 @@ static int btreeMoveto( if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT; sqlite3VdbeRecordUnpack(pKeyInfo, (int)nKey, pKey, pIdxKey); if( pIdxKey->nField==0 || pIdxKey->nField>pKeyInfo->nAllField ){ @@ -307,7 +306,7 @@ index f348f3c..0666938 100644 }else{ rc = sqlite3BtreeIndexMoveto(pCur, pIdxKey, pRes); } -@@ -72407,7 +72522,7 @@ static void ptrmapPut(BtShared *pBt, Pgno key, u8 eType, Pgno parent, int *pRC){ +@@ -72410,7 +72525,7 @@ static void ptrmapPut(BtShared *pBt, Pgno key, u8 eType, Pgno parent, int *pRC){ assert( 0==PTRMAP_ISPAGE(pBt, PENDING_BYTE_PAGE(pBt)) ); assert( pBt->autoVacuum ); @@ -316,7 +315,7 @@ index f348f3c..0666938 100644 *pRC = SQLITE_CORRUPT_BKPT; return; } -@@ -72421,12 +72536,24 @@ static void ptrmapPut(BtShared *pBt, Pgno key, u8 eType, Pgno parent, int *pRC){ +@@ -72424,12 +72539,24 @@ static void ptrmapPut(BtShared *pBt, Pgno key, u8 eType, Pgno parent, int *pRC){ /* The first byte of the extra data is the MemPage.isInit byte. ** If that byte is set, it means this page is also being used ** as a btree page. */ @@ -343,7 +342,7 @@ index f348f3c..0666938 100644 goto ptrmap_exit; } assert( offset <= (int)pBt->usableSize-5 ); -@@ -72471,7 +72598,12 @@ static int ptrmapGet(BtShared *pBt, Pgno key, u8 *pEType, Pgno *pPgno){ +@@ -72474,7 +72601,12 @@ static int ptrmapGet(BtShared *pBt, Pgno key, u8 *pEType, Pgno *pPgno){ offset = PTRMAP_PTROFFSET(iPtrmap, key); if( offset<0 ){ sqlite3PagerUnref(pDbPage); @@ -357,7 +356,7 @@ index f348f3c..0666938 100644 } assert( offset <= (int)pBt->usableSize-5 ); assert( pEType!=0 ); -@@ -72479,7 +72611,15 @@ static int ptrmapGet(BtShared *pBt, Pgno key, u8 *pEType, Pgno *pPgno){ +@@ -72482,7 +72614,15 @@ static int ptrmapGet(BtShared *pBt, Pgno key, u8 *pEType, Pgno *pPgno){ if( pPgno ) *pPgno = get4byte(&pPtrmap[offset+1]); sqlite3PagerUnref(pDbPage); @@ -374,7 +373,7 @@ index f348f3c..0666938 100644 return SQLITE_OK; } -@@ -72919,7 +73059,14 @@ static void ptrmapPutOvflPtr(MemPage *pPage, MemPage *pSrc, u8 *pCell,int *pRC){ +@@ -72922,7 +73062,14 @@ static void ptrmapPutOvflPtr(MemPage *pPage, MemPage *pSrc, u8 *pCell,int *pRC){ Pgno ovfl; if( SQLITE_OVERFLOW(pSrc->aDataEnd, pCell, pCell+info.nLocal) ){ testcase( pSrc!=pPage ); @@ -390,7 +389,7 @@ index f348f3c..0666938 100644 return; } ovfl = get4byte(&pCell[info.nSize-4]); -@@ -72977,10 +73124,29 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){ +@@ -72980,10 +73127,29 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){ ** reconstruct the entire page. */ if( (int)data[hdr+7]<=nMaxFrag ){ int iFree = get2byte(&data[hdr+1]); @@ -422,7 +421,7 @@ index f348f3c..0666938 100644 if( 0==iFree2 || (data[iFree2]==0 && data[iFree2+1]==0) ){ u8 *pEnd = &data[cellOffset + nCell*2]; u8 *pAddr; -@@ -72988,16 +73154,51 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){ +@@ -72991,16 +73157,51 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){ int sz = get2byte(&data[iFree+2]); int top = get2byte(&data[hdr+5]); if( top>=iFree ){ @@ -478,7 +477,7 @@ index f348f3c..0666938 100644 } cbrk = top+sz; -@@ -73030,13 +73231,24 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){ +@@ -73033,13 +73234,24 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){ ** if PRAGMA cell_size_check=ON. */ if( pc>iCellLast ){ @@ -505,7 +504,7 @@ index f348f3c..0666938 100644 } assert( cbrk+size<=usableSize && cbrk>=iCellStart ); testcase( cbrk+size==usableSize ); -@@ -73050,7 +73262,13 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){ +@@ -73053,7 +73265,13 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){ defragment_out: assert( pPage->nFree>=0 ); if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){ @@ -520,7 +519,7 @@ index f348f3c..0666938 100644 } assert( cbrk>=iCellFirst ); put2byte(&data[hdr+5], cbrk); -@@ -73075,7 +73293,7 @@ defragment_out: +@@ -73078,7 +73296,7 @@ defragment_out: ** will be ignored if adding the extra space to the fragmentation count ** causes the fragmentation count to exceed 60. */ @@ -529,7 +528,7 @@ index f348f3c..0666938 100644 const int hdr = pPg->hdrOffset; /* Offset to page header */ u8 * const aData = pPg->aData; /* Page data */ int iAddr = hdr + 1; /* Address of ptr to pc */ -@@ -73107,7 +73325,15 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){ +@@ -73110,7 +73328,15 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){ return &aData[pc]; }else if( x+pc > maxPC ){ /* This slot extends off the end of the usable part of the page */ @@ -546,7 +545,7 @@ index f348f3c..0666938 100644 return 0; }else{ /* The slot remains on the free-list. Reduce its size to account -@@ -73122,14 +73348,25 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){ +@@ -73125,14 +73351,25 @@ static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){ if( pc<=iAddr ){ if( pc ){ /* The next slot in the chain comes before the current slot */ @@ -574,7 +573,7 @@ index f348f3c..0666938 100644 } return 0; } -@@ -73177,10 +73414,16 @@ static SQLITE_INLINE int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ +@@ -73180,10 +73417,16 @@ static SQLITE_INLINE int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ if( top==0 && pPage->pBt->usableSize==65536 ){ top = 65536; }else{ @@ -593,7 +592,7 @@ index f348f3c..0666938 100644 } /* If there is enough space between gap and top for one more cell pointer, -@@ -73197,7 +73440,11 @@ static SQLITE_INLINE int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ +@@ -73200,7 +73443,11 @@ static SQLITE_INLINE int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ assert( pSpace+nByte<=data+pPage->pBt->usableSize ); *pIdx = g2 = (int)(pSpace-data); if( g2<=gap ){ @@ -606,7 +605,7 @@ index f348f3c..0666938 100644 }else{ return SQLITE_OK; } -@@ -73276,12 +73523,23 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ +@@ -73279,12 +73526,23 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ while( (iFreeBlk = get2byte(&data[iPtr]))iPtr || iFreeBlk==0 || CORRUPT_DB ); -@@ -73293,10 +73551,24 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ +@@ -73296,10 +73554,24 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ */ if( iFreeBlk && iEnd+3>=iFreeBlk ){ nFrag = iFreeBlk - iEnd; @@ -659,7 +658,7 @@ index f348f3c..0666938 100644 } iSize = iEnd - iStart; iFreeBlk = get2byte(&data[iFreeBlk]); -@@ -73309,13 +73581,27 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ +@@ -73312,13 +73584,27 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ if( iPtr>hdr+1 ){ int iPtrEnd = iPtr + get2byte(&data[iPtr+2]); if( iPtrEnd+3>=iStart ){ @@ -689,7 +688,7 @@ index f348f3c..0666938 100644 data[hdr+7] -= nFrag; } pTmp = &data[hdr+5]; -@@ -73329,8 +73615,21 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ +@@ -73332,8 +73618,21 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ /* The new freeblock is at the beginning of the cell content area, ** so just extend the cell content area rather than create another ** freelist entry */ @@ -713,7 +712,7 @@ index f348f3c..0666938 100644 put2byte(&data[hdr+1], iFreeBlk); put2byte(&data[hdr+5], iEnd); }else{ -@@ -73391,7 +73690,13 @@ static int decodeFlags(MemPage *pPage, int flagByte){ +@@ -73394,7 +73693,13 @@ static int decodeFlags(MemPage *pPage, int flagByte){ pPage->pgno, flagByte, pPage->isInit, pPage->intKey, pPage->intKeyLeaf, pPage->leaf, pPage->childPtrSize, pPage->cellOffset, pPage->nCell, pPage->hdrOffset, pPage->minLocal, pPage->maxLocal, g_lastCkptTime); #endif /* LOG_DUMP */ @@ -728,7 +727,7 @@ index f348f3c..0666938 100644 } }else{ pPage->childPtrSize = 4; -@@ -73422,7 +73727,13 @@ static int decodeFlags(MemPage *pPage, int flagByte){ +@@ -73425,7 +73730,13 @@ static int decodeFlags(MemPage *pPage, int flagByte){ pPage->pgno, flagByte, pPage->isInit, pPage->intKey, pPage->intKeyLeaf, pPage->leaf, pPage->childPtrSize, pPage->cellOffset, pPage->nCell, pPage->hdrOffset, pPage->minLocal, pPage->maxLocal, g_lastCkptTime); #endif /* LOG_DUMP */ @@ -743,7 +742,7 @@ index f348f3c..0666938 100644 } } return SQLITE_OK; -@@ -73473,12 +73784,20 @@ static int btreeComputeFreeSpace(MemPage *pPage){ +@@ -73476,12 +73787,20 @@ static int btreeComputeFreeSpace(MemPage *pPage){ /* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will ** always be at least one cell before the first freeblock. */ @@ -766,7 +765,7 @@ index f348f3c..0666938 100644 } next = get2byte(&data[pc]); size = get2byte(&data[pc+2]); -@@ -73488,11 +73807,19 @@ static int btreeComputeFreeSpace(MemPage *pPage){ +@@ -73491,11 +73810,19 @@ static int btreeComputeFreeSpace(MemPage *pPage){ } if( next>0 ){ /* Freeblock not in ascending order */ @@ -788,7 +787,7 @@ index f348f3c..0666938 100644 } } -@@ -73504,7 +73831,13 @@ static int btreeComputeFreeSpace(MemPage *pPage){ +@@ -73507,7 +73834,13 @@ static int btreeComputeFreeSpace(MemPage *pPage){ ** area, according to the page header, lies within the page. */ if( nFree>usableSize || nFreenFree = (u16)(nFree - iCellFirst); return SQLITE_OK; -@@ -73535,12 +73868,20 @@ static SQLITE_NOINLINE int btreeCellSizeCheck(MemPage *pPage){ +@@ -73538,12 +73871,20 @@ static SQLITE_NOINLINE int btreeCellSizeCheck(MemPage *pPage){ testcase( pc==iCellFirst ); testcase( pc==iCellLast ); if( pciCellLast ){ @@ -826,7 +825,7 @@ index f348f3c..0666938 100644 } } return SQLITE_OK; -@@ -73572,7 +73913,7 @@ static int btreeInitPage(MemPage *pPage){ +@@ -73575,7 +73916,7 @@ static int btreeInitPage(MemPage *pPage){ /* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating ** the b-tree page type. */ if( decodeFlags(pPage, data[0]) ){ @@ -835,7 +834,7 @@ index f348f3c..0666938 100644 } assert( pBt->pageSize>=512 && pBt->pageSize<=65536 ); pPage->maskPage = (u16)(pBt->pageSize - 1); -@@ -73586,7 +73927,12 @@ static int btreeInitPage(MemPage *pPage){ +@@ -73589,7 +73930,12 @@ static int btreeInitPage(MemPage *pPage){ pPage->nCell = get2byte(&data[3]); if( pPage->nCell>MX_CELL(pBt) ){ /* To many cells for a single page. The page must be corrupt */ @@ -849,7 +848,7 @@ index f348f3c..0666938 100644 } testcase( pPage->nCell==MX_CELL(pBt) ); /* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only -@@ -73729,7 +74075,11 @@ static int getAndInitPage( +@@ -73732,7 +74078,11 @@ static int getAndInitPage( if( pgno>btreePagecount(pBt) ){ *ppPage = 0; @@ -862,7 +861,7 @@ index f348f3c..0666938 100644 } rc = sqlite3PagerGet(pBt->pPager, pgno, (DbPage**)&pDbPage, bReadOnly); if( rc ){ -@@ -75199,7 +75549,12 @@ static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){ +@@ -75202,7 +75552,12 @@ static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){ if( eType==PTRMAP_OVERFLOW2 ){ /* The pointer is always the first 4 bytes of the page in this case. */ if( get4byte(pPage->aData)!=iFrom ){ @@ -876,7 +875,7 @@ index f348f3c..0666938 100644 } put4byte(pPage->aData, iTo); }else{ -@@ -75218,7 +75573,13 @@ static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){ +@@ -75221,7 +75576,13 @@ static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){ pPage->xParseCell(pPage, pCell, &info); if( info.nLocal pPage->aData+pPage->pBt->usableSize ){ @@ -891,7 +890,7 @@ index f348f3c..0666938 100644 } if( iFrom==get4byte(pCell+info.nSize-4) ){ put4byte(pCell+info.nSize-4, iTo); -@@ -75227,7 +75588,13 @@ static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){ +@@ -75230,7 +75591,13 @@ static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){ } }else{ if( pCell+4 > pPage->aData+pPage->pBt->usableSize ){ @@ -906,7 +905,7 @@ index f348f3c..0666938 100644 } if( get4byte(pCell)==iFrom ){ put4byte(pCell, iTo); -@@ -75239,7 +75606,11 @@ static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){ +@@ -75242,7 +75609,11 @@ static int modifyPagePointer(MemPage *pPage, Pgno iFrom, Pgno iTo, u8 eType){ if( i==nCell ){ if( eType!=PTRMAP_BTREE || get4byte(&pPage->aData[pPage->hdrOffset+8])!=iFrom ){ @@ -919,7 +918,7 @@ index f348f3c..0666938 100644 } put4byte(&pPage->aData[pPage->hdrOffset+8], iTo); } -@@ -75372,7 +75743,11 @@ static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg, int bCommit){ +@@ -75375,7 +75746,11 @@ static int incrVacuumStep(BtShared *pBt, Pgno nFin, Pgno iLastPg, int bCommit){ return rc; } if( eType==PTRMAP_ROOTPAGE ){ @@ -932,7 +931,7 @@ index f348f3c..0666938 100644 } if( eType==PTRMAP_FREEPAGE ){ -@@ -76448,7 +76823,12 @@ static int accessPayload( +@@ -76451,7 +76826,12 @@ static int accessPayload( assert( eOp==0 || eOp==1 ); assert( pCur->eState==CURSOR_VALID ); if( pCur->ix>=pPage->nCell ){ @@ -946,7 +945,7 @@ index f348f3c..0666938 100644 } assert( cursorHoldsMutex(pCur) ); -@@ -76463,7 +76843,12 @@ static int accessPayload( +@@ -76466,7 +76846,12 @@ static int accessPayload( ** &aPayload[pCur->info.nLocal] > &pPage->aData[pBt->usableSize] ** but is recast into its current form to avoid integer overflow problems */ @@ -960,7 +959,7 @@ index f348f3c..0666938 100644 } /* Check if data must be read/written to/from the btree page itself. */ -@@ -76534,7 +76919,16 @@ static int accessPayload( +@@ -76537,7 +76922,16 @@ static int accessPayload( assert( rc==SQLITE_OK && amt>0 ); while( nextPage ){ /* If required, populate the overflow page-list cache. */ @@ -978,7 +977,7 @@ index f348f3c..0666938 100644 assert( pCur->aOverflow[iIdx]==0 || pCur->aOverflow[iIdx]==nextPage || CORRUPT_DB ); -@@ -76618,7 +77012,11 @@ static int accessPayload( +@@ -76621,7 +77015,11 @@ static int accessPayload( if( rc==SQLITE_OK && amt>0 ){ /* Overflow chain ends prematurely */ @@ -991,7 +990,7 @@ index f348f3c..0666938 100644 } return rc; } -@@ -76770,7 +77168,7 @@ static int moveToChild(BtCursor *pCur, u32 newPgno){ +@@ -76773,7 +77171,7 @@ static int moveToChild(BtCursor *pCur, u32 newPgno){ && (pCur->pPage->nCell<1 || pCur->pPage->intKey!=pCur->curIntKey) ){ releasePage(pCur->pPage); @@ -1000,7 +999,7 @@ index f348f3c..0666938 100644 } if( rc ){ pCur->pPage = pCur->apPage[--pCur->iPage]; -@@ -76905,7 +77303,12 @@ static int moveToRoot(BtCursor *pCur){ +@@ -76908,7 +77306,12 @@ static int moveToRoot(BtCursor *pCur){ ** (or the freelist). */ assert( pRoot->intKey==1 || pRoot->intKey==0 ); if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){ @@ -1014,7 +1013,7 @@ index f348f3c..0666938 100644 } skip_init: -@@ -77166,7 +77569,11 @@ SQLITE_PRIVATE int sqlite3BtreeTableMoveto( +@@ -77169,7 +77572,11 @@ SQLITE_PRIVATE int sqlite3BtreeTableMoveto( if( pPage->intKeyLeaf ){ while( 0x80 <= *(pCell++) ){ if( pCell>=pPage->aDataEnd ){ @@ -1027,7 +1026,7 @@ index f348f3c..0666938 100644 } } } -@@ -77449,7 +77856,12 @@ bypass_moveto_root: +@@ -77452,7 +77859,12 @@ bypass_moveto_root: testcase( nCell==1 ); /* Invalid key size: 0x80 0x80 0x01 */ testcase( nCell==2 ); /* Minimum legal index key size */ if( nCell<2 || nCell/pCur->pBt->usableSize>pCur->pBt->nPage ){ @@ -1041,7 +1040,7 @@ index f348f3c..0666938 100644 goto moveto_index_finish; } pCellKey = sqlite3Malloc( nCell+nOverrun ); -@@ -77523,7 +77935,7 @@ bypass_moveto_root: +@@ -77526,7 +77938,7 @@ bypass_moveto_root: && (pCur->pPage->nCell<1 || pCur->pPage->intKey!=pCur->curIntKey) ){ releasePage(pCur->pPage); @@ -1050,7 +1049,7 @@ index f348f3c..0666938 100644 } if( rc ){ pCur->pPage = pCur->apPage[--pCur->iPage]; -@@ -77807,7 +78219,13 @@ static int allocateBtreePage( +@@ -77810,7 +78222,13 @@ static int allocateBtreePage( n = get4byte(&pPage1->aData[36]); testcase( n==mxPage-1 ); if( n>=mxPage ){ @@ -1065,7 +1064,7 @@ index f348f3c..0666938 100644 } if( n>0 ){ /* There are pages on the freelist. Reuse one of those pages. */ -@@ -77863,7 +78281,12 @@ static int allocateBtreePage( +@@ -77866,7 +78284,12 @@ static int allocateBtreePage( } testcase( iTrunk==mxPage ); if( iTrunk>mxPage || nSearch++ > n ){ @@ -1079,7 +1078,7 @@ index f348f3c..0666938 100644 }else{ rc = btreeGetUnusedPage(pBt, iTrunk, &pTrunk, 0); } -@@ -77892,7 +78315,14 @@ static int allocateBtreePage( +@@ -77895,7 +78318,14 @@ static int allocateBtreePage( TRACE(("ALLOCATE: %u trunk - %u free pages left\n", *pPgno, n-1)); }else if( k>(u32)(pBt->usableSize/4 - 2) ){ /* Value of k is out of range. Database corruption */ @@ -1095,7 +1094,7 @@ index f348f3c..0666938 100644 goto end_allocate_page; #ifndef SQLITE_OMIT_AUTOVACUUM }else if( searchList -@@ -77926,7 +78356,14 @@ static int allocateBtreePage( +@@ -77929,7 +78359,14 @@ static int allocateBtreePage( MemPage *pNewTrunk; Pgno iNewTrunk = get4byte(&pTrunk->aData[8]); if( iNewTrunk>mxPage ){ @@ -1111,7 +1110,7 @@ index f348f3c..0666938 100644 goto end_allocate_page; } testcase( iNewTrunk==mxPage ); -@@ -77991,7 +78428,14 @@ static int allocateBtreePage( +@@ -77994,7 +78431,14 @@ static int allocateBtreePage( iPage = get4byte(&aData[8+closest*4]); testcase( iPage==mxPage ); if( iPage>mxPage || iPage<2 ){ @@ -1127,7 +1126,7 @@ index f348f3c..0666938 100644 goto end_allocate_page; } testcase( iPage==mxPage ); -@@ -78176,7 +78620,14 @@ static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){ +@@ -78179,7 +78623,14 @@ static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){ nLeaf = get4byte(&pTrunk->aData[4]); assert( pBt->usableSize>32 ); if( nLeaf > (u32)pBt->usableSize/4 - 2 ){ @@ -1143,7 +1142,7 @@ index f348f3c..0666938 100644 goto freepage_out; } if( nLeaf < (u32)pBt->usableSize/4 - 8 ){ -@@ -78265,7 +78716,12 @@ static SQLITE_NOINLINE int clearCellOverflow( +@@ -78268,7 +78719,12 @@ static SQLITE_NOINLINE int clearCellOverflow( testcase( pCell + (pInfo->nSize-1) == pPage->aDataEnd ); if( pCell + pInfo->nSize > pPage->aDataEnd ){ /* Cell extends past end of page */ @@ -1157,7 +1156,7 @@ index f348f3c..0666938 100644 } ovflPgno = get4byte(pCell + pInfo->nSize - 4); pBt = pPage->pBt; -@@ -78282,7 +78738,14 @@ static SQLITE_NOINLINE int clearCellOverflow( +@@ -78285,7 +78741,14 @@ static SQLITE_NOINLINE int clearCellOverflow( /* 0 is not a legal page number and page 1 cannot be an ** overflow page. Therefore if ovflPgno<2 or past the end of the ** file the database must be corrupt. */ @@ -1173,7 +1172,7 @@ index f348f3c..0666938 100644 } if( nOvfl ){ rc = getOverflowPage(pBt, ovflPgno, &pOvfl, &iNext); -@@ -78558,7 +79021,12 @@ static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){ +@@ -78561,7 +79024,12 @@ static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){ testcase( pc==(u32)get2byte(&data[hdr+5]) ); testcase( pc+sz==pPage->pBt->usableSize ); if( pc+sz > pPage->pBt->usableSize ){ @@ -1187,7 +1186,7 @@ index f348f3c..0666938 100644 return; } rc = freeSpace(pPage, pc, sz); -@@ -79700,7 +80168,7 @@ static int balance_nonroot( +@@ -79703,7 +80171,7 @@ static int balance_nonroot( ** table-interior, index-leaf, or index-interior). */ if( pOld->aData[0]!=apOld[0]->aData[0] ){ @@ -1196,7 +1195,7 @@ index f348f3c..0666938 100644 goto balance_cleanup; } -@@ -79724,7 +80192,7 @@ static int balance_nonroot( +@@ -79727,7 +80195,7 @@ static int balance_nonroot( memset(&b.szCell[b.nCell], 0, sizeof(b.szCell[0])*(limit+pOld->nOverflow)); if( pOld->nOverflow>0 ){ if( NEVER(limitaiOvfl[0]) ){ @@ -1205,7 +1204,7 @@ index f348f3c..0666938 100644 goto balance_cleanup; } limit = pOld->aiOvfl[0]; -@@ -80367,7 +80835,7 @@ static int anotherValidCursor(BtCursor *pCur){ +@@ -80370,7 +80838,7 @@ static int anotherValidCursor(BtCursor *pCur){ && pOther->eState==CURSOR_VALID && pOther->pPage==pCur->pPage ){ @@ -1214,7 +1213,7 @@ index f348f3c..0666938 100644 } } return SQLITE_OK; -@@ -80427,7 +80895,7 @@ static int balance(BtCursor *pCur){ +@@ -80430,7 +80898,7 @@ static int balance(BtCursor *pCur){ /* The page being written is not a root page, and there is currently ** more than one reference to it. This only happens if the page is one ** of its own ancestor pages. Corruption. */ @@ -1223,7 +1222,7 @@ index f348f3c..0666938 100644 }else{ MemPage * const pParent = pCur->apPage[iPage-1]; int const iIdx = pCur->aiIdx[iPage-1]; -@@ -80591,7 +81059,7 @@ static SQLITE_NOINLINE int btreeOverwriteOverflowCell( +@@ -80594,7 +81062,7 @@ static SQLITE_NOINLINE int btreeOverwriteOverflowCell( rc = btreeGetPage(pBt, ovflPgno, &pPage, 0); if( rc ) return rc; if( sqlite3PagerPageRefcount(pPage->pDbPage)!=1 || pPage->isInit ){ @@ -1232,7 +1231,7 @@ index f348f3c..0666938 100644 }else{ if( iOffset+ovflPageSize<(u32)nTotal ){ ovflPgno = get4byte(pPage->aData); -@@ -80619,7 +81087,14 @@ static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX){ +@@ -80622,7 +81090,14 @@ static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX){ if( pCur->info.pPayload + pCur->info.nLocal > pPage->aDataEnd || pCur->info.pPayload < pPage->aData + pPage->cellOffset ){ @@ -1248,7 +1247,7 @@ index f348f3c..0666938 100644 } if( pCur->info.nLocal==nTotal ){ /* The entire cell is local */ -@@ -80700,7 +81175,7 @@ SQLITE_PRIVATE int sqlite3BtreeInsert( +@@ -80703,7 +81178,7 @@ SQLITE_PRIVATE int sqlite3BtreeInsert( ** Which can only happen if the SQLITE_NoSchemaError flag was set when ** the schema was loaded. This cannot be asserted though, as a user might ** set the flag, load the schema, and then unset the flag. */ @@ -1257,7 +1256,7 @@ index f348f3c..0666938 100644 } } -@@ -80823,7 +81298,7 @@ SQLITE_PRIVATE int sqlite3BtreeInsert( +@@ -80826,7 +81301,7 @@ SQLITE_PRIVATE int sqlite3BtreeInsert( if( pPage->nFree<0 ){ if( NEVER(pCur->eState>CURSOR_INVALID) ){ /* ^^^^^--- due to the moveToRoot() call above */ @@ -1266,7 +1265,7 @@ index f348f3c..0666938 100644 }else{ rc = btreeComputeFreeSpace(pPage); } -@@ -80865,7 +81340,7 @@ SQLITE_PRIVATE int sqlite3BtreeInsert( +@@ -80868,7 +81343,7 @@ SQLITE_PRIVATE int sqlite3BtreeInsert( CellInfo info; assert( idx>=0 ); if( idx>=pPage->nCell ){ @@ -1275,7 +1274,7 @@ index f348f3c..0666938 100644 } rc = sqlite3PagerWrite(pPage->pDbPage); if( rc ){ -@@ -80892,10 +81367,10 @@ SQLITE_PRIVATE int sqlite3BtreeInsert( +@@ -80895,10 +81370,10 @@ SQLITE_PRIVATE int sqlite3BtreeInsert( ** necessary to add the PTRMAP_OVERFLOW1 pointer-map entry. */ assert( rc==SQLITE_OK ); /* clearCell never fails when nLocal==nPayload */ if( oldCell < pPage->aData+pPage->hdrOffset+10 ){ @@ -1288,7 +1287,7 @@ index f348f3c..0666938 100644 } memcpy(oldCell, newCell, szNew); return SQLITE_OK; -@@ -80997,7 +81472,7 @@ SQLITE_PRIVATE int sqlite3BtreeTransferRow(BtCursor *pDest, BtCursor *pSrc, i64 +@@ -81000,7 +81475,7 @@ SQLITE_PRIVATE int sqlite3BtreeTransferRow(BtCursor *pDest, BtCursor *pSrc, i64 nIn = pSrc->info.nLocal; aIn = pSrc->info.pPayload; if( aIn+nIn>pSrc->pPage->aDataEnd ){ @@ -1297,7 +1296,7 @@ index f348f3c..0666938 100644 } nRem = pSrc->info.nPayload; if( nIn==nRem && nInpPage->maxLocal ){ -@@ -81022,7 +81497,7 @@ SQLITE_PRIVATE int sqlite3BtreeTransferRow(BtCursor *pDest, BtCursor *pSrc, i64 +@@ -81025,7 +81500,7 @@ SQLITE_PRIVATE int sqlite3BtreeTransferRow(BtCursor *pDest, BtCursor *pSrc, i64 if( nRem>nIn ){ if( aIn+nIn+4>pSrc->pPage->aDataEnd ){ @@ -1306,7 +1305,7 @@ index f348f3c..0666938 100644 } ovflIn = get4byte(&pSrc->info.pPayload[nIn]); } -@@ -81118,7 +81593,7 @@ SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){ +@@ -81121,7 +81596,7 @@ SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){ assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID ); if( rc || pCur->eState!=CURSOR_VALID ) return rc; }else{ @@ -1315,7 +1314,7 @@ index f348f3c..0666938 100644 } } assert( pCur->eState==CURSOR_VALID ); -@@ -81127,14 +81602,14 @@ SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){ +@@ -81130,14 +81605,14 @@ SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){ iCellIdx = pCur->ix; pPage = pCur->pPage; if( pPage->nCell<=iCellIdx ){ @@ -1333,7 +1332,7 @@ index f348f3c..0666938 100644 } /* If the BTREE_SAVEPOSITION bit is on, then the cursor position must -@@ -81225,7 +81700,7 @@ SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){ +@@ -81228,7 +81703,7 @@ SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){ n = pCur->pPage->pgno; } pCell = findCell(pLeaf, pLeaf->nCell-1); @@ -1342,7 +1341,7 @@ index f348f3c..0666938 100644 nCell = pLeaf->xCellSize(pLeaf, pCell); assert( MX_CELL_SIZE(pBt) >= nCell ); pTmp = pBt->pTmpSpace; -@@ -81341,7 +81816,7 @@ static int btreeCreateTable(Btree *p, Pgno *piTable, int createTabFlags){ +@@ -81344,7 +81819,7 @@ static int btreeCreateTable(Btree *p, Pgno *piTable, int createTabFlags){ */ sqlite3BtreeGetMeta(p, BTREE_LARGEST_ROOT_PAGE, &pgnoRoot); if( pgnoRoot>btreePagecount(pBt) ){ @@ -1351,7 +1350,7 @@ index f348f3c..0666938 100644 } pgnoRoot++; -@@ -81389,7 +81864,7 @@ static int btreeCreateTable(Btree *p, Pgno *piTable, int createTabFlags){ +@@ -81392,7 +81867,7 @@ static int btreeCreateTable(Btree *p, Pgno *piTable, int createTabFlags){ } rc = ptrmapGet(pBt, pgnoRoot, &eType, &iPtrPage); if( eType==PTRMAP_ROOTPAGE || eType==PTRMAP_FREEPAGE ){ @@ -1360,7 +1359,7 @@ index f348f3c..0666938 100644 } if( rc!=SQLITE_OK ){ releasePage(pRoot); -@@ -81479,14 +81954,14 @@ static int clearDatabasePage( +@@ -81482,14 +81957,14 @@ static int clearDatabasePage( assert( sqlite3_mutex_held(pBt->mutex) ); if( pgno>btreePagecount(pBt) ){ @@ -1377,7 +1376,7 @@ index f348f3c..0666938 100644 goto cleardatabasepage_out; } hdr = pPage->hdrOffset; -@@ -81590,7 +82065,7 @@ static int btreeDropTable(Btree *p, Pgno iTable, int *piMoved){ +@@ -81593,7 +82068,7 @@ static int btreeDropTable(Btree *p, Pgno iTable, int *piMoved){ assert( p->inTrans==TRANS_WRITE ); assert( iTable>=2 ); if( iTable>btreePagecount(pBt) ){ @@ -1386,7 +1385,7 @@ index f348f3c..0666938 100644 } rc = sqlite3BtreeClearTable(p, iTable, 0); -@@ -85920,7 +86395,7 @@ static int growOpArray(Vdbe *v, int nOp){ +@@ -85923,7 +86398,7 @@ static int growOpArray(Vdbe *v, int nOp){ ** ** Other useful labels for breakpoints include: ** test_trace_breakpoint(pc,pOp) @@ -1395,7 +1394,7 @@ index f348f3c..0666938 100644 ** sqlite3MisuseError(lineno) ** sqlite3CantopenError(lineno) */ -@@ -94157,7 +94632,7 @@ SQLITE_API int sqlite3_found_count = 0; +@@ -94160,7 +94635,7 @@ SQLITE_API int sqlite3_found_count = 0; ** ** Other useful labels for breakpoints include: ** test_addop_breakpoint(pc,pOp) @@ -1404,7 +1403,7 @@ index f348f3c..0666938 100644 ** sqlite3MisuseError(lineno) ** sqlite3CantopenError(lineno) */ -@@ -181855,6 +182330,12 @@ SQLITE_API int sqlite3_config(int op, ...){ +@@ -181845,6 +182320,12 @@ SQLITE_API int sqlite3_config(int op, ...){ #endif break; } @@ -1417,7 +1416,7 @@ index f348f3c..0666938 100644 default: { rc = SQLITE_ERROR; -@@ -185037,9 +185518,21 @@ SQLITE_PRIVATE int sqlite3ReportError(int iErr, int lineno, const char *zType){ +@@ -185028,9 +185509,21 @@ SQLITE_PRIVATE int sqlite3ReportError(int iErr, int lineno, const char *zType){ zType, lineno, 20+sqlite3_sourceid()); return iErr; } @@ -1441,6 +1440,3 @@ index f348f3c..0666938 100644 } SQLITE_PRIVATE int sqlite3MisuseError(int lineno){ testcase( sqlite3GlobalConfig.xLog!=0 ); --- -2.47.0.windows.2 - -- Gitee