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