xref: /sqlite-3.40.0/src/test_btree.c (revision 7617e4a8)
116a9b836Sdrh /*
216a9b836Sdrh ** 2007 May 05
316a9b836Sdrh **
416a9b836Sdrh ** The author disclaims copyright to this source code.  In place of
516a9b836Sdrh ** a legal notice, here is a blessing:
616a9b836Sdrh **
716a9b836Sdrh **    May you do good and not evil.
816a9b836Sdrh **    May you find forgiveness for yourself and forgive others.
916a9b836Sdrh **    May you share freely, never taking more than you give.
1016a9b836Sdrh **
1116a9b836Sdrh *************************************************************************
1216a9b836Sdrh ** Code for testing the btree.c module in SQLite.  This code
1316a9b836Sdrh ** is not included in the SQLite library.  It is used for automated
1416a9b836Sdrh ** testing of the SQLite library.
1516a9b836Sdrh */
1616a9b836Sdrh #include "btreeInt.h"
1752b1dbb5Smistachkin #if defined(INCLUDE_SQLITE_TCL_H)
1852b1dbb5Smistachkin #  include "sqlite_tcl.h"
1952b1dbb5Smistachkin #else
2052b1dbb5Smistachkin #  include "tcl.h"
2152b1dbb5Smistachkin #endif
2216a9b836Sdrh 
2316a9b836Sdrh /*
2416a9b836Sdrh ** Usage: sqlite3_shared_cache_report
2516a9b836Sdrh **
2616a9b836Sdrh ** Return a list of file that are shared and the number of
2716a9b836Sdrh ** references to each file.
2816a9b836Sdrh */
sqlite3BtreeSharedCacheReport(void * clientData,Tcl_Interp * interp,int objc,Tcl_Obj * CONST objv[])29*7617e4a8Smistachkin int SQLITE_TCLAPI sqlite3BtreeSharedCacheReport(
3016a9b836Sdrh   void * clientData,
3116a9b836Sdrh   Tcl_Interp *interp,
3216a9b836Sdrh   int objc,
3316a9b836Sdrh   Tcl_Obj *CONST objv[]
3416a9b836Sdrh ){
3516a9b836Sdrh #ifndef SQLITE_OMIT_SHARED_CACHE
36e53831d6Sdrh   extern BtShared *sqlite3SharedCacheList;
3716a9b836Sdrh   BtShared *pBt;
3816a9b836Sdrh   Tcl_Obj *pRet = Tcl_NewObj();
3978f82d1eSdrh   for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
40d4e0bb0eSdrh     const char *zFile = sqlite3PagerFilename(pBt->pPager, 1);
4116a9b836Sdrh     Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj(zFile, -1));
4216a9b836Sdrh     Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(pBt->nRef));
4316a9b836Sdrh   }
4416a9b836Sdrh   Tcl_SetObjResult(interp, pRet);
4516a9b836Sdrh #endif
4616a9b836Sdrh   return TCL_OK;
4716a9b836Sdrh }
4816a9b836Sdrh 
4916a9b836Sdrh /*
5016a9b836Sdrh ** Print debugging information about all cursors to standard output.
5116a9b836Sdrh */
sqlite3BtreeCursorList(Btree * p)5216a9b836Sdrh void sqlite3BtreeCursorList(Btree *p){
5385e9e22bSdrh #ifdef SQLITE_DEBUG
5416a9b836Sdrh   BtCursor *pCur;
5516a9b836Sdrh   BtShared *pBt = p->pBt;
5616a9b836Sdrh   for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){
5771d5d2cdSdanielk1977     MemPage *pPage = pCur->apPage[pCur->iPage];
58036dbec0Sdrh     char *zMode = (pCur->curFlags & BTCF_WriteFlag) ? "rw" : "ro";
5916a9b836Sdrh     sqlite3DebugPrintf("CURSOR %p rooted at %4d(%s) currently at %d.%d%s\n",
6016a9b836Sdrh        pCur, pCur->pgnoRoot, zMode,
6171d5d2cdSdanielk1977        pPage ? pPage->pgno : 0, pCur->aiIdx[pCur->iPage],
6216a9b836Sdrh        (pCur->eState==CURSOR_VALID) ? "" : " eof"
6316a9b836Sdrh     );
6416a9b836Sdrh   }
6585e9e22bSdrh #endif
6616a9b836Sdrh }
67