blob: 03b8b207c9834268bf685662f4857f3a04eb5960 [file] [log] [blame]
drh16a9b832007-05-05 18:39:25 +00001/*
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.
drh16a9b832007-05-05 18:39:25 +000015*/
16#include "btreeInt.h"
mistachkin52b1dbb2016-07-28 14:37:04 +000017#if defined(INCLUDE_SQLITE_TCL_H)
18# include "sqlite_tcl.h"
19#else
20# include "tcl.h"
21#endif
drh16a9b832007-05-05 18:39:25 +000022
23/*
drh16a9b832007-05-05 18:39:25 +000024** Usage: sqlite3_shared_cache_report
25**
26** Return a list of file that are shared and the number of
27** references to each file.
28*/
mistachkin7617e4a2016-07-28 17:11:20 +000029int SQLITE_TCLAPI sqlite3BtreeSharedCacheReport(
drh16a9b832007-05-05 18:39:25 +000030 void * clientData,
31 Tcl_Interp *interp,
32 int objc,
33 Tcl_Obj *CONST objv[]
34){
35#ifndef SQLITE_OMIT_SHARED_CACHE
drhe53831d2007-08-17 01:14:38 +000036 extern BtShared *sqlite3SharedCacheList;
37 BtShared *pBt;
38 Tcl_Obj *pRet = Tcl_NewObj();
drh78f82d12008-09-02 00:52:52 +000039 for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
drhd4e0bb02012-05-27 01:19:04 +000040 const char *zFile = sqlite3PagerFilename(pBt->pPager, 1);
drhe53831d2007-08-17 01:14:38 +000041 Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj(zFile, -1));
42 Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(pBt->nRef));
drh16a9b832007-05-05 18:39:25 +000043 }
drhe53831d2007-08-17 01:14:38 +000044 Tcl_SetObjResult(interp, pRet);
drh16a9b832007-05-05 18:39:25 +000045#endif
46 return TCL_OK;
47}
48
49/*
50** Print debugging information about all cursors to standard output.
51*/
52void sqlite3BtreeCursorList(Btree *p){
drh85e9e222008-07-15 00:27:34 +000053#ifdef SQLITE_DEBUG
drh16a9b832007-05-05 18:39:25 +000054 BtCursor *pCur;
55 BtShared *pBt = p->pBt;
56 for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){
danielk197771d5d2c2008-09-29 11:49:47 +000057 MemPage *pPage = pCur->apPage[pCur->iPage];
drh036dbec2014-03-11 23:40:44 +000058 char *zMode = (pCur->curFlags & BTCF_WriteFlag) ? "rw" : "ro";
drh16a9b832007-05-05 18:39:25 +000059 sqlite3DebugPrintf("CURSOR %p rooted at %4d(%s) currently at %d.%d%s\n",
60 pCur, pCur->pgnoRoot, zMode,
danielk197771d5d2c2008-09-29 11:49:47 +000061 pPage ? pPage->pgno : 0, pCur->aiIdx[pCur->iPage],
drh16a9b832007-05-05 18:39:25 +000062 (pCur->eState==CURSOR_VALID) ? "" : " eof"
63 );
64 }
drh85e9e222008-07-15 00:27:34 +000065#endif
drh16a9b832007-05-05 18:39:25 +000066}