Update contrib.
4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
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.
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.
16 ** $Id: test_btree.c,v 1.8 2008/09/29 11:49:48 danielk1977 Exp $
22 ** Usage: sqlite3_shared_cache_report
24 ** Return a list of file that are shared and the number of
25 ** references to each file.
27 int sqlite3BtreeSharedCacheReport(
33 #ifndef SQLITE_OMIT_SHARED_CACHE
34 extern BtShared *sqlite3SharedCacheList;
36 Tcl_Obj *pRet = Tcl_NewObj();
37 for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
38 const char *zFile = sqlite3PagerFilename(pBt->pPager);
39 Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj(zFile, -1));
40 Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(pBt->nRef));
42 Tcl_SetObjResult(interp, pRet);
48 ** Print debugging information about all cursors to standard output.
50 void sqlite3BtreeCursorList(Btree *p){
53 BtShared *pBt = p->pBt;
54 for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){
55 MemPage *pPage = pCur->apPage[pCur->iPage];
56 char *zMode = pCur->wrFlag ? "rw" : "ro";
57 sqlite3DebugPrintf("CURSOR %p rooted at %4d(%s) currently at %d.%d%s\n",
58 pCur, pCur->pgnoRoot, zMode,
59 pPage ? pPage->pgno : 0, pCur->aiIdx[pCur->iPage],
60 (pCur->eState==CURSOR_VALID) ? "" : " eof"
68 ** Fill aResult[] with information about the entry and page that the
69 ** cursor is pointing to.
71 ** aResult[0] = The page number
72 ** aResult[1] = The entry number
73 ** aResult[2] = Total number of entries on this page
74 ** aResult[3] = Cell size (local payload + header)
75 ** aResult[4] = Number of free bytes on this page
76 ** aResult[5] = Number of free blocks on the page
77 ** aResult[6] = Total payload size (local + overflow)
78 ** aResult[7] = Header size in bytes
79 ** aResult[8] = Local payload size
80 ** aResult[9] = Parent page number
81 ** aResult[10]= Page number of the first overflow page
83 ** This routine is used for testing and debugging only.
85 int sqlite3BtreeCursorInfo(BtCursor *pCur, int *aResult, int upCnt){
88 MemPage *pPage = pCur->apPage[pCur->iPage];
92 if( pCur->eState==CURSOR_REQUIRESEEK ){
93 rc = sqlite3BtreeRestoreCursorPosition(pCur);
99 assert( pPage->isInit );
100 sqlite3BtreeGetTempCursor(pCur, &tmpCur);
102 sqlite3BtreeMoveToParent(&tmpCur);
104 pPage = tmpCur.pPage;
105 aResult[0] = sqlite3PagerPagenumber(pPage->pDbPage);
106 assert( aResult[0]==pPage->pgno );
107 aResult[1] = tmpCur.idx;
108 aResult[2] = pPage->nCell;
109 if( tmpCur.idx>=0 && tmpCur.idx<pPage->nCell ){
110 sqlite3BtreeParseCell(tmpCur.pPage, tmpCur.idx, &tmpCur.info);
111 aResult[3] = tmpCur.info.nSize;
112 aResult[6] = tmpCur.info.nData;
113 aResult[7] = tmpCur.info.nHeader;
114 aResult[8] = tmpCur.info.nLocal;
121 aResult[4] = pPage->nFree;
123 idx = get2byte(&pPage->aData[pPage->hdrOffset+1]);
124 while( idx>0 && idx<pPage->pBt->usableSize ){
126 idx = get2byte(&pPage->aData[idx]);
129 if( pPage->pParent==0 || sqlite3BtreeIsRootPage(pPage) ){
132 aResult[9] = pPage->pParent->pgno;
134 if( tmpCur.info.iOverflow ){
135 aResult[10] = get4byte(&tmpCur.info.pCell[tmpCur.info.iOverflow]);
139 sqlite3BtreeReleaseTempCursor(&tmpCur);