1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/SRC/test_btree.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,142 @@
1.4 +/*
1.5 +** 2007 May 05
1.6 +**
1.7 +** The author disclaims copyright to this source code. In place of
1.8 +** a legal notice, here is a blessing:
1.9 +**
1.10 +** May you do good and not evil.
1.11 +** May you find forgiveness for yourself and forgive others.
1.12 +** May you share freely, never taking more than you give.
1.13 +**
1.14 +*************************************************************************
1.15 +** Code for testing the btree.c module in SQLite. This code
1.16 +** is not included in the SQLite library. It is used for automated
1.17 +** testing of the SQLite library.
1.18 +**
1.19 +** $Id: test_btree.c,v 1.8 2008/09/29 11:49:48 danielk1977 Exp $
1.20 +*/
1.21 +#include "btreeInt.h"
1.22 +#include "tcl.h"
1.23 +
1.24 +/*
1.25 +** Usage: sqlite3_shared_cache_report
1.26 +**
1.27 +** Return a list of file that are shared and the number of
1.28 +** references to each file.
1.29 +*/
1.30 +int sqlite3BtreeSharedCacheReport(
1.31 + void * clientData,
1.32 + Tcl_Interp *interp,
1.33 + int objc,
1.34 + Tcl_Obj *CONST objv[]
1.35 +){
1.36 +#ifndef SQLITE_OMIT_SHARED_CACHE
1.37 + extern BtShared *sqlite3SharedCacheList;
1.38 + BtShared *pBt;
1.39 + Tcl_Obj *pRet = Tcl_NewObj();
1.40 + for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
1.41 + const char *zFile = sqlite3PagerFilename(pBt->pPager);
1.42 + Tcl_ListObjAppendElement(interp, pRet, Tcl_NewStringObj(zFile, -1));
1.43 + Tcl_ListObjAppendElement(interp, pRet, Tcl_NewIntObj(pBt->nRef));
1.44 + }
1.45 + Tcl_SetObjResult(interp, pRet);
1.46 +#endif
1.47 + return TCL_OK;
1.48 +}
1.49 +
1.50 +/*
1.51 +** Print debugging information about all cursors to standard output.
1.52 +*/
1.53 +void sqlite3BtreeCursorList(Btree *p){
1.54 +#ifdef SQLITE_DEBUG
1.55 + BtCursor *pCur;
1.56 + BtShared *pBt = p->pBt;
1.57 + for(pCur=pBt->pCursor; pCur; pCur=pCur->pNext){
1.58 + MemPage *pPage = pCur->apPage[pCur->iPage];
1.59 + char *zMode = pCur->wrFlag ? "rw" : "ro";
1.60 + sqlite3DebugPrintf("CURSOR %p rooted at %4d(%s) currently at %d.%d%s\n",
1.61 + pCur, pCur->pgnoRoot, zMode,
1.62 + pPage ? pPage->pgno : 0, pCur->aiIdx[pCur->iPage],
1.63 + (pCur->eState==CURSOR_VALID) ? "" : " eof"
1.64 + );
1.65 + }
1.66 +#endif
1.67 +}
1.68 +
1.69 +
1.70 +/*
1.71 +** Fill aResult[] with information about the entry and page that the
1.72 +** cursor is pointing to.
1.73 +**
1.74 +** aResult[0] = The page number
1.75 +** aResult[1] = The entry number
1.76 +** aResult[2] = Total number of entries on this page
1.77 +** aResult[3] = Cell size (local payload + header)
1.78 +** aResult[4] = Number of free bytes on this page
1.79 +** aResult[5] = Number of free blocks on the page
1.80 +** aResult[6] = Total payload size (local + overflow)
1.81 +** aResult[7] = Header size in bytes
1.82 +** aResult[8] = Local payload size
1.83 +** aResult[9] = Parent page number
1.84 +** aResult[10]= Page number of the first overflow page
1.85 +**
1.86 +** This routine is used for testing and debugging only.
1.87 +*/
1.88 +int sqlite3BtreeCursorInfo(BtCursor *pCur, int *aResult, int upCnt){
1.89 +#if 0
1.90 + int cnt, idx;
1.91 + MemPage *pPage = pCur->apPage[pCur->iPage];
1.92 + BtCursor tmpCur;
1.93 + int rc;
1.94 +
1.95 + if( pCur->eState==CURSOR_REQUIRESEEK ){
1.96 + rc = sqlite3BtreeRestoreCursorPosition(pCur);
1.97 + if( rc!=SQLITE_OK ){
1.98 + return rc;
1.99 + }
1.100 + }
1.101 +
1.102 + assert( pPage->isInit );
1.103 + sqlite3BtreeGetTempCursor(pCur, &tmpCur);
1.104 + while( upCnt-- ){
1.105 + sqlite3BtreeMoveToParent(&tmpCur);
1.106 + }
1.107 + pPage = tmpCur.pPage;
1.108 + aResult[0] = sqlite3PagerPagenumber(pPage->pDbPage);
1.109 + assert( aResult[0]==pPage->pgno );
1.110 + aResult[1] = tmpCur.idx;
1.111 + aResult[2] = pPage->nCell;
1.112 + if( tmpCur.idx>=0 && tmpCur.idx<pPage->nCell ){
1.113 + sqlite3BtreeParseCell(tmpCur.pPage, tmpCur.idx, &tmpCur.info);
1.114 + aResult[3] = tmpCur.info.nSize;
1.115 + aResult[6] = tmpCur.info.nData;
1.116 + aResult[7] = tmpCur.info.nHeader;
1.117 + aResult[8] = tmpCur.info.nLocal;
1.118 + }else{
1.119 + aResult[3] = 0;
1.120 + aResult[6] = 0;
1.121 + aResult[7] = 0;
1.122 + aResult[8] = 0;
1.123 + }
1.124 + aResult[4] = pPage->nFree;
1.125 + cnt = 0;
1.126 + idx = get2byte(&pPage->aData[pPage->hdrOffset+1]);
1.127 + while( idx>0 && idx<pPage->pBt->usableSize ){
1.128 + cnt++;
1.129 + idx = get2byte(&pPage->aData[idx]);
1.130 + }
1.131 + aResult[5] = cnt;
1.132 + if( pPage->pParent==0 || sqlite3BtreeIsRootPage(pPage) ){
1.133 + aResult[9] = 0;
1.134 + }else{
1.135 + aResult[9] = pPage->pParent->pgno;
1.136 + }
1.137 + if( tmpCur.info.iOverflow ){
1.138 + aResult[10] = get4byte(&tmpCur.info.pCell[tmpCur.info.iOverflow]);
1.139 + }else{
1.140 + aResult[10] = 0;
1.141 + }
1.142 + sqlite3BtreeReleaseTempCursor(&tmpCur);
1.143 +#endif
1.144 + return SQLITE_OK;
1.145 +}