drh | 16a9b83 | 2007-05-05 18:39:25 +0000 | [diff] [blame] | 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. |
drh | 16a9b83 | 2007-05-05 18:39:25 +0000 | [diff] [blame] | 15 | */ |
| 16 | #include "btreeInt.h" |
mistachkin | 52b1dbb | 2016-07-28 14:37:04 +0000 | [diff] [blame] | 17 | #if defined(INCLUDE_SQLITE_TCL_H) |
| 18 | # include "sqlite_tcl.h" |
| 19 | #else |
| 20 | # include "tcl.h" |
| 21 | #endif |
drh | 16a9b83 | 2007-05-05 18:39:25 +0000 | [diff] [blame] | 22 | |
| 23 | /* |
drh | 16a9b83 | 2007-05-05 18:39:25 +0000 | [diff] [blame] | 24 | ** 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 | */ |
mistachkin | 7617e4a | 2016-07-28 17:11:20 +0000 | [diff] [blame] | 29 | int SQLITE_TCLAPI sqlite3BtreeSharedCacheReport( |
drh | 16a9b83 | 2007-05-05 18:39:25 +0000 | [diff] [blame] | 30 | void * clientData, |
| 31 | Tcl_Interp *interp, |
| 32 | int objc, |
| 33 | Tcl_Obj *CONST objv[] |
| 34 | ){ |
| 35 | #ifndef SQLITE_OMIT_SHARED_CACHE |
drh | e53831d | 2007-08-17 01:14:38 +0000 | [diff] [blame] | 36 | extern BtShared *sqlite3SharedCacheList; |
| 37 | BtShared *pBt; |
| 38 | Tcl_Obj *pRet = Tcl_NewObj(); |
drh | 78f82d1 | 2008-09-02 00:52:52 +0000 | [diff] [blame] | 39 | for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){ |
drh | d4e0bb0 | 2012-05-27 01:19:04 +0000 | [diff] [blame] | 40 | const char *zFile = sqlite3PagerFilename(pBt->pPager, 1); |
drh | e53831d | 2007-08-17 01:14:38 +0000 | [diff] [blame] | 41 | Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj(zFile, -1)); |
| 42 | Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(pBt->nRef)); |
drh | 16a9b83 | 2007-05-05 18:39:25 +0000 | [diff] [blame] | 43 | } |
drh | e53831d | 2007-08-17 01:14:38 +0000 | [diff] [blame] | 44 | Tcl_SetObjResult(interp, pRet); |
drh | 16a9b83 | 2007-05-05 18:39:25 +0000 | [diff] [blame] | 45 | #endif |
| 46 | return TCL_OK; |
| 47 | } |
| 48 | |
| 49 | /* |
| 50 | ** Print debugging information about all cursors to standard output. |
| 51 | */ |
| 52 | void sqlite3BtreeCursorList(Btree *p){ |
drh | 85e9e22 | 2008-07-15 00:27:34 +0000 | [diff] [blame] | 53 | #ifdef SQLITE_DEBUG |
drh | 16a9b83 | 2007-05-05 18:39:25 +0000 | [diff] [blame] | 54 | BtCursor *pCur; |
| 55 | BtShared *pBt = p->pBt; |
| 56 | for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){ |
danielk1977 | 71d5d2c | 2008-09-29 11:49:47 +0000 | [diff] [blame] | 57 | MemPage *pPage = pCur->apPage[pCur->iPage]; |
drh | 036dbec | 2014-03-11 23:40:44 +0000 | [diff] [blame] | 58 | char *zMode = (pCur->curFlags & BTCF_WriteFlag) ? "rw" : "ro"; |
drh | 16a9b83 | 2007-05-05 18:39:25 +0000 | [diff] [blame] | 59 | sqlite3DebugPrintf("CURSOR %p rooted at %4d(%s) currently at %d.%d%s\n", |
| 60 | pCur, pCur->pgnoRoot, zMode, |
danielk1977 | 71d5d2c | 2008-09-29 11:49:47 +0000 | [diff] [blame] | 61 | pPage ? pPage->pgno : 0, pCur->aiIdx[pCur->iPage], |
drh | 16a9b83 | 2007-05-05 18:39:25 +0000 | [diff] [blame] | 62 | (pCur->eState==CURSOR_VALID) ? "" : " eof" |
| 63 | ); |
| 64 | } |
drh | 85e9e22 | 2008-07-15 00:27:34 +0000 | [diff] [blame] | 65 | #endif |
drh | 16a9b83 | 2007-05-05 18:39:25 +0000 | [diff] [blame] | 66 | } |