Index: src/btree.c ================================================================== --- src/btree.c +++ src/btree.c @@ -753,10 +753,30 @@ assert( cursorHoldsMutex(pCur) ); sqlite3_free(pCur->pKey); pCur->pKey = 0; pCur->eState = CURSOR_INVALID; } + +/* +** This is a debugging routine designed to reveal the file (database or +** wal file) that the page would be read from if it were reread at the +** current time. It returns the name of the file. +*/ +static const char *btreePageOriginFile(MemPage *pPage){ + return sqlite3PagerOrigin(pPage->pDbPage, 0); +} + +/* +** This is a debugging routine designed to reveal the byte offset that +** the page would be read from (from either the database or wal file) if it +** were reread at the current time. The byte offset is returned. +*/ +static i64 btreePageOriginOffset(MemPage *pPage){ + i64 iOffset = 0; + sqlite3PagerOrigin(pPage->pDbPage, &iOffset); + return iOffset; +} /* ** In this version of BtreeMoveto, pKey is a packed index record ** such as is generated by the OP_MakeRecord opcode. Unpack the ** record and then call BtreeMovetoUnpacked() to do the work. Index: src/pager.c ================================================================== --- src/pager.c +++ src/pager.c @@ -7599,7 +7599,34 @@ int sqlite3PagerWalFramesize(Pager *pPager){ assert( pPager->eState>=PAGER_READER ); return sqlite3WalFramesize(pPager->pWal); } #endif + +/* +** Return the name of the file (wal file or database file) that page +** pPg would be read from if it were reread at this point. Also set +** output parameter (*piOffset) to the offset within said file. +*/ +const char *sqlite3PagerOrigin(DbPage *pPg, i64 *piOffset){ + Pager *pPager = pPg->pPager; + Pgno pgno = pPg->pgno; + + assert( pPager->eState>=PAGER_READER ); + assert( assert_pager_state(pPager) ); + assert( pPager->hasHeldSharedLock==1 ); + + if( pagerUseWal(pPager) ){ + u32 iFrame = 0; + int rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame); + if( rc!=SQLITE_OK ) return 0; + if( iFrame ){ + if( piOffset ) *piOffset = (i64)(iFrame-1) * (pPager->pageSize + 24) + 32; + return (const char*)pPager->zWal; + } + } + + if( piOffset ) *piOffset = (i64)pPager->pageSize * (i64)(pgno-1); + return (const char*)pPager->zFilename; +} #endif /* SQLITE_OMIT_DISKIO */ Index: src/pager.h ================================================================== --- src/pager.h +++ src/pager.h @@ -234,7 +234,9 @@ void enable_simulated_io_errors(void); #else # define disable_simulated_io_errors() # define enable_simulated_io_errors() #endif + +const char *sqlite3PagerOrigin(DbPage *pPg, i64 *piOffset); #endif /* SQLITE_PAGER_H */