test_btree.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. ** 2007 May 05
  3. **
  4. ** The author disclaims copyright to this source code. In place of
  5. ** a legal notice, here is a blessing:
  6. **
  7. ** May you do good and not evil.
  8. ** May you find forgiveness for yourself and forgive others.
  9. ** May you share freely, never taking more than you give.
  10. **
  11. *************************************************************************
  12. ** Code for testing the btree.c module in SQLite. This code
  13. ** is not included in the SQLite library. It is used for automated
  14. ** testing of the SQLite library.
  15. */
  16. #include "btreeInt.h"
  17. #include <tcl.h>
  18. /*
  19. ** Usage: sqlite3_shared_cache_report
  20. **
  21. ** Return a list of file that are shared and the number of
  22. ** references to each file.
  23. */
  24. int sqlite3BtreeSharedCacheReport(
  25. void * clientData,
  26. Tcl_Interp *interp,
  27. int objc,
  28. Tcl_Obj *CONST objv[]
  29. ){
  30. #ifndef SQLITE_OMIT_SHARED_CACHE
  31. extern BtShared *sqlite3SharedCacheList;
  32. BtShared *pBt;
  33. Tcl_Obj *pRet = Tcl_NewObj();
  34. for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
  35. const char *zFile = sqlite3PagerFilename(pBt->pPager, 1);
  36. Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj(zFile, -1));
  37. Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(pBt->nRef));
  38. }
  39. Tcl_SetObjResult(interp, pRet);
  40. #endif
  41. return TCL_OK;
  42. }
  43. /*
  44. ** Print debugging information about all cursors to standard output.
  45. */
  46. void sqlite3BtreeCursorList(Btree *p){
  47. #ifdef SQLITE_DEBUG
  48. BtCursor *pCur;
  49. BtShared *pBt = p->pBt;
  50. for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){
  51. MemPage *pPage = pCur->apPage[pCur->iPage];
  52. char *zMode = pCur->wrFlag ? "rw" : "ro";
  53. sqlite3DebugPrintf("CURSOR %p rooted at %4d(%s) currently at %d.%d%s\n",
  54. pCur, pCur->pgnoRoot, zMode,
  55. pPage ? pPage->pgno : 0, pCur->aiIdx[pCur->iPage],
  56. (pCur->eState==CURSOR_VALID) ? "" : " eof"
  57. );
  58. }
  59. #endif
  60. }