/ Check-in [1d96ce8c]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Restore (btree_set_cache_size) to test3.c. This is used on unix for the tcl "crash tests". Make some functions no longer used outside of btree.c static. (CVS 6869)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:1d96ce8c76e007ca29e7971a6c72b6387fe0fb93
User & Date: danielk1977 2009-07-09 05:07:38
Context
2009-07-09
08:27
In btree.c, have setSharedCacheLock() assume that the b-tree is sharable instead of checking to see if it is. The caller has already performed this check. (CVS 6870) check-in: 3190eefd user: danielk1977 tags: trunk
05:07
Restore (btree_set_cache_size) to test3.c. This is used on unix for the tcl "crash tests". Make some functions no longer used outside of btree.c static. (CVS 6869) check-in: 1d96ce8c user: danielk1977 tags: trunk
03:20
removed the test function sqlite3BtreeFlags() (test code only); (CVS 6868) check-in: 579ba6c8 user: shane tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12         -** $Id: btree.c,v 1.668 2009/07/09 03:20:46 shane Exp $
           12  +** $Id: btree.c,v 1.669 2009/07/09 05:07:38 danielk1977 Exp $
    13     13   **
    14     14   ** This file implements a external (disk-based) database using BTrees.
    15     15   ** See the header comment on "btreeInt.h" for additional information.
    16     16   ** Including a description of file format and an overview of operation.
    17     17   */
    18     18   #include "btreeInt.h"
    19     19   
................................................................................
   642    642   /*
   643    643   ** Restore the cursor to the position it was in (or as close to as possible)
   644    644   ** when saveCursorPosition() was called. Note that this call deletes the 
   645    645   ** saved position info stored by saveCursorPosition(), so there can be
   646    646   ** at most one effective restoreCursorPosition() call after each 
   647    647   ** saveCursorPosition().
   648    648   */
   649         -int sqlite3BtreeRestoreCursorPosition(BtCursor *pCur){
          649  +static int btreeRestoreCursorPosition(BtCursor *pCur){
   650    650     int rc;
   651    651     assert( cursorHoldsMutex(pCur) );
   652    652     assert( pCur->eState>=CURSOR_REQUIRESEEK );
   653    653     if( pCur->eState==CURSOR_FAULT ){
   654    654       return pCur->skip;
   655    655     }
   656    656     pCur->eState = CURSOR_INVALID;
................................................................................
   661    661       assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID );
   662    662     }
   663    663     return rc;
   664    664   }
   665    665   
   666    666   #define restoreCursorPosition(p) \
   667    667     (p->eState>=CURSOR_REQUIRESEEK ? \
   668         -         sqlite3BtreeRestoreCursorPosition(p) : \
          668  +         btreeRestoreCursorPosition(p) : \
   669    669            SQLITE_OK)
   670    670   
   671    671   /*
   672    672   ** Determine whether or not a cursor has moved from the position it
   673    673   ** was last placed at.  Cursors can move when the row they are pointing
   674    674   ** at is deleted out from under them.
   675    675   **
................................................................................
   828    828       }
   829    829     }
   830    830     return findCell(pPage, iCell);
   831    831   }
   832    832   
   833    833   /*
   834    834   ** Parse a cell content block and fill in the CellInfo structure.  There
   835         -** are two versions of this function.  sqlite3BtreeParseCell() takes a 
   836         -** cell index as the second argument and sqlite3BtreeParseCellPtr() 
          835  +** are two versions of this function.  btreeParseCell() takes a 
          836  +** cell index as the second argument and btreeParseCellPtr() 
   837    837   ** takes a pointer to the body of the cell as its second argument.
   838    838   **
   839    839   ** Within this file, the parseCell() macro can be called instead of
   840         -** sqlite3BtreeParseCellPtr(). Using some compilers, this will be faster.
          840  +** btreeParseCellPtr(). Using some compilers, this will be faster.
   841    841   */
   842         -void sqlite3BtreeParseCellPtr(
          842  +static void btreeParseCellPtr(
   843    843     MemPage *pPage,         /* Page containing the cell */
   844    844     u8 *pCell,              /* Pointer to the cell text. */
   845    845     CellInfo *pInfo         /* Fill in this structure */
   846    846   ){
   847    847     u16 n;                  /* Number bytes in cell content header */
   848    848     u32 nPayload;           /* Number of bytes of cell payload */
   849    849   
................................................................................
   907    907         pInfo->nLocal = (u16)minLocal;
   908    908       }
   909    909       pInfo->iOverflow = (u16)(pInfo->nLocal + n);
   910    910       pInfo->nSize = pInfo->iOverflow + 4;
   911    911     }
   912    912   }
   913    913   #define parseCell(pPage, iCell, pInfo) \
   914         -  sqlite3BtreeParseCellPtr((pPage), findCell((pPage), (iCell)), (pInfo))
   915         -void sqlite3BtreeParseCell(
          914  +  btreeParseCellPtr((pPage), findCell((pPage), (iCell)), (pInfo))
          915  +static void btreeParseCell(
   916    916     MemPage *pPage,         /* Page containing the cell */
   917    917     int iCell,              /* The cell index.  First cell is 0 */
   918    918     CellInfo *pInfo         /* Fill in this structure */
   919    919   ){
   920    920     parseCell(pPage, iCell, pInfo);
   921    921   }
   922    922   
................................................................................
   932    932   
   933    933   #ifdef SQLITE_DEBUG
   934    934     /* The value returned by this function should always be the same as
   935    935     ** the (CellInfo.nSize) value found by doing a full parse of the
   936    936     ** cell. If SQLITE_DEBUG is defined, an assert() at the bottom of
   937    937     ** this function verifies that this invariant is not violated. */
   938    938     CellInfo debuginfo;
   939         -  sqlite3BtreeParseCellPtr(pPage, pCell, &debuginfo);
          939  +  btreeParseCellPtr(pPage, pCell, &debuginfo);
   940    940   #endif
   941    941   
   942    942     if( pPage->intKey ){
   943    943       u8 *pEnd;
   944    944       if( pPage->hasData ){
   945    945         pIter += getVarint32(pIter, nSize);
   946    946       }else{
................................................................................
   989    989   ** If the cell pCell, part of page pPage contains a pointer
   990    990   ** to an overflow page, insert an entry into the pointer-map
   991    991   ** for the overflow page.
   992    992   */
   993    993   static int ptrmapPutOvflPtr(MemPage *pPage, u8 *pCell){
   994    994     CellInfo info;
   995    995     assert( pCell!=0 );
   996         -  sqlite3BtreeParseCellPtr(pPage, pCell, &info);
          996  +  btreeParseCellPtr(pPage, pCell, &info);
   997    997     assert( (info.nData+(pPage->intKey?0:info.nKey))==info.nPayload );
   998    998     if( info.iOverflow ){
   999    999       Pgno ovfl = get4byte(&pCell[info.iOverflow]);
  1000   1000       return ptrmapPut(pPage->pBt, ovfl, PTRMAP_OVERFLOW1, pPage->pgno);
  1001   1001     }
  1002   1002     return SQLITE_OK;
  1003   1003   }
................................................................................
  1045   1045     for(i=0; i<nCell; i++){
  1046   1046       u8 *pAddr;     /* The i-th cell pointer */
  1047   1047       pAddr = &data[cellOffset + i*2];
  1048   1048       pc = get2byte(pAddr);
  1049   1049       testcase( pc==iCellFirst );
  1050   1050       testcase( pc==iCellLast );
  1051   1051   #if !defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK)
  1052         -    /* These conditions have already been verified in sqlite3BtreeInitPage()
         1052  +    /* These conditions have already been verified in btreeInitPage()
  1053   1053       ** if SQLITE_ENABLE_OVERSIZE_CELL_CHECK is defined 
  1054   1054       */
  1055   1055       if( pc<iCellFirst || pc>iCellLast ){
  1056   1056         return SQLITE_CORRUPT_BKPT;
  1057   1057       }
  1058   1058   #endif
  1059   1059       assert( pc>=iCellFirst && pc<=iCellLast );
................................................................................
  1201   1201   #ifdef SQLITE_SECURE_DELETE
  1202   1202     /* Overwrite deleted information with zeros when the SECURE_DELETE 
  1203   1203     ** option is enabled at compile-time */
  1204   1204     memset(&data[start], 0, size);
  1205   1205   #endif
  1206   1206   
  1207   1207     /* Add the space back into the linked list of freeblocks.  Note that
  1208         -  ** even though the freeblock list was checked by sqlite3BtreeInitPage(),
  1209         -  ** sqlite3BtreeInitPage() did not detect overlapping cells or
         1208  +  ** even though the freeblock list was checked by btreeInitPage(),
         1209  +  ** btreeInitPage() did not detect overlapping cells or
  1210   1210     ** freeblocks that overlapped cells.   Nor does it detect when the
  1211   1211     ** cell content area exceeds the value in the page header.  If these
  1212   1212     ** situations arise, then subsequent insert operations might corrupt
  1213   1213     ** the freelist.  So we do need to check for corruption while scanning
  1214   1214     ** the freelist.
  1215   1215     */
  1216   1216     hdr = pPage->hdrOffset;
................................................................................
  1309   1309   **
  1310   1310   ** Return SQLITE_OK on success.  If we see that the page does
  1311   1311   ** not contain a well-formed database page, then return 
  1312   1312   ** SQLITE_CORRUPT.  Note that a return of SQLITE_OK does not
  1313   1313   ** guarantee that the page is well-formed.  It only shows that
  1314   1314   ** we failed to detect any corruption.
  1315   1315   */
  1316         -int sqlite3BtreeInitPage(MemPage *pPage){
         1316  +static int btreeInitPage(MemPage *pPage){
  1317   1317   
  1318   1318     assert( pPage->pBt!=0 );
  1319   1319     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  1320   1320     assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
  1321   1321     assert( pPage == sqlite3PagerGetExtra(pPage->pDbPage) );
  1322   1322     assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) );
  1323   1323   
................................................................................
  1472   1472   ** If the noContent flag is set, it means that we do not care about
  1473   1473   ** the content of the page at this time.  So do not go to the disk
  1474   1474   ** to fetch the content.  Just fill in the content with zeros for now.
  1475   1475   ** If in the future we call sqlite3PagerWrite() on this page, that
  1476   1476   ** means we have started to be concerned about content and the disk
  1477   1477   ** read should occur at that point.
  1478   1478   */
  1479         -int sqlite3BtreeGetPage(
         1479  +static int btreeGetPage(
  1480   1480     BtShared *pBt,       /* The btree */
  1481   1481     Pgno pgno,           /* Number of the page to fetch */
  1482   1482     MemPage **ppPage,    /* Return the page in this parameter */
  1483   1483     int noContent        /* Do not load page content if true */
  1484   1484   ){
  1485   1485     int rc;
  1486   1486     DbPage *pDbPage;
................................................................................
  1519   1519     assert( rc==SQLITE_OK || nPage==-1 );
  1520   1520     return (Pgno)nPage;
  1521   1521   }
  1522   1522   
  1523   1523   /*
  1524   1524   ** Get a page from the pager and initialize it.  This routine
  1525   1525   ** is just a convenience wrapper around separate calls to
  1526         -** sqlite3BtreeGetPage() and sqlite3BtreeInitPage().
         1526  +** btreeGetPage() and btreeInitPage().
  1527   1527   */
  1528   1528   static int getAndInitPage(
  1529   1529     BtShared *pBt,          /* The database file */
  1530   1530     Pgno pgno,           /* Number of the page to get */
  1531   1531     MemPage **ppPage     /* Write the page pointer here */
  1532   1532   ){
  1533   1533     int rc;
................................................................................
  1549   1549       rc = SQLITE_OK;
  1550   1550     }else{
  1551   1551       /* Page not in cache.  Acquire it. */
  1552   1552       testcase( pgno==pagerPagecount(pBt) );
  1553   1553       if( pgno>pagerPagecount(pBt) ){
  1554   1554         return SQLITE_CORRUPT_BKPT; 
  1555   1555       }
  1556         -    rc = sqlite3BtreeGetPage(pBt, pgno, ppPage, 0);
         1556  +    rc = btreeGetPage(pBt, pgno, ppPage, 0);
  1557   1557       if( rc ) return rc;
  1558   1558       pPage = *ppPage;
  1559   1559     }
  1560   1560     if( !pPage->isInit ){
  1561         -    rc = sqlite3BtreeInitPage(pPage);
         1561  +    rc = btreeInitPage(pPage);
  1562   1562     }
  1563   1563     if( rc!=SQLITE_OK ){
  1564   1564       releasePage(pPage);
  1565   1565       *ppPage = 0;
  1566   1566     }
  1567   1567     return rc;
  1568   1568   }
  1569   1569   
  1570   1570   /*
  1571   1571   ** Release a MemPage.  This should be called once for each prior
  1572         -** call to sqlite3BtreeGetPage.
         1572  +** call to btreeGetPage.
  1573   1573   */
  1574   1574   static void releasePage(MemPage *pPage){
  1575   1575     if( pPage ){
  1576   1576       assert( pPage->nOverflow==0 || sqlite3PagerPageRefcount(pPage->pDbPage)>1 );
  1577   1577       assert( pPage->aData );
  1578   1578       assert( pPage->pBt );
  1579   1579       assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
................................................................................
  1597   1597     assert( sqlite3PagerPageRefcount(pData)>0 );
  1598   1598     if( pPage->isInit ){
  1599   1599       assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  1600   1600       pPage->isInit = 0;
  1601   1601       if( sqlite3PagerPageRefcount(pData)>1 ){
  1602   1602         /* pPage might not be a btree page;  it might be an overflow page
  1603   1603         ** or ptrmap page or a free page.  In those cases, the following
  1604         -      ** call to sqlite3BtreeInitPage() will likely return SQLITE_CORRUPT.
         1604  +      ** call to btreeInitPage() will likely return SQLITE_CORRUPT.
  1605   1605         ** But no harm is done by this.  And it is very important that
  1606         -      ** sqlite3BtreeInitPage() be called on every btree page so we make
         1606  +      ** btreeInitPage() be called on every btree page so we make
  1607   1607         ** the call for every page that comes in for re-initing. */
  1608         -      sqlite3BtreeInitPage(pPage);
         1608  +      btreeInitPage(pPage);
  1609   1609       }
  1610   1610     }
  1611   1611   }
  1612   1612   
  1613   1613   /*
  1614   1614   ** Invoke the busy handler for a btree.
  1615   1615   */
................................................................................
  2184   2184   static int lockBtree(BtShared *pBt){
  2185   2185     int rc;
  2186   2186     MemPage *pPage1;
  2187   2187     int nPage;
  2188   2188   
  2189   2189     assert( sqlite3_mutex_held(pBt->mutex) );
  2190   2190     assert( pBt->pPage1==0 );
  2191         -  rc = sqlite3BtreeGetPage(pBt, 1, &pPage1, 0);
         2191  +  rc = btreeGetPage(pBt, 1, &pPage1, 0);
  2192   2192     if( rc!=SQLITE_OK ) return rc;
  2193   2193   
  2194   2194     /* Do some checking to help insure the file we opened really is
  2195   2195     ** a valid database file. 
  2196   2196     */
  2197   2197     rc = sqlite3PagerPagecount(pBt->pPager, &nPage);
  2198   2198     if( rc!=SQLITE_OK ){
................................................................................
  2510   2510     int nCell;                         /* Number of cells in page pPage */
  2511   2511     int rc;                            /* Return code */
  2512   2512     BtShared *pBt = pPage->pBt;
  2513   2513     u8 isInitOrig = pPage->isInit;
  2514   2514     Pgno pgno = pPage->pgno;
  2515   2515   
  2516   2516     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  2517         -  rc = sqlite3BtreeInitPage(pPage);
         2517  +  rc = btreeInitPage(pPage);
  2518   2518     if( rc!=SQLITE_OK ){
  2519   2519       goto set_child_ptrmaps_out;
  2520   2520     }
  2521   2521     nCell = pPage->nCell;
  2522   2522   
  2523   2523     for(i=0; i<nCell; i++){
  2524   2524       u8 *pCell = findCell(pPage, i);
................................................................................
  2569   2569       }
  2570   2570       put4byte(pPage->aData, iTo);
  2571   2571     }else{
  2572   2572       u8 isInitOrig = pPage->isInit;
  2573   2573       int i;
  2574   2574       int nCell;
  2575   2575   
  2576         -    sqlite3BtreeInitPage(pPage);
         2576  +    btreeInitPage(pPage);
  2577   2577       nCell = pPage->nCell;
  2578   2578   
  2579   2579       for(i=0; i<nCell; i++){
  2580   2580         u8 *pCell = findCell(pPage, i);
  2581   2581         if( eType==PTRMAP_OVERFLOW1 ){
  2582   2582           CellInfo info;
  2583         -        sqlite3BtreeParseCellPtr(pPage, pCell, &info);
         2583  +        btreeParseCellPtr(pPage, pCell, &info);
  2584   2584           if( info.iOverflow ){
  2585   2585             if( iFrom==get4byte(&pCell[info.iOverflow]) ){
  2586   2586               put4byte(&pCell[info.iOverflow], iTo);
  2587   2587               break;
  2588   2588             }
  2589   2589           }
  2590   2590         }else{
................................................................................
  2664   2664     }
  2665   2665   
  2666   2666     /* Fix the database pointer on page iPtrPage that pointed at iDbPage so
  2667   2667     ** that it points at iFreePage. Also fix the pointer map entry for
  2668   2668     ** iPtrPage.
  2669   2669     */
  2670   2670     if( eType!=PTRMAP_ROOTPAGE ){
  2671         -    rc = sqlite3BtreeGetPage(pBt, iPtrPage, &pPtrPage, 0);
         2671  +    rc = btreeGetPage(pBt, iPtrPage, &pPtrPage, 0);
  2672   2672       if( rc!=SQLITE_OK ){
  2673   2673         return rc;
  2674   2674       }
  2675   2675       rc = sqlite3PagerWrite(pPtrPage->pDbPage);
  2676   2676       if( rc!=SQLITE_OK ){
  2677   2677         releasePage(pPtrPage);
  2678   2678         return rc;
................................................................................
  2744   2744           assert( iFreePg==iLastPg );
  2745   2745           releasePage(pFreePg);
  2746   2746         }
  2747   2747       } else {
  2748   2748         Pgno iFreePg;             /* Index of free page to move pLastPg to */
  2749   2749         MemPage *pLastPg;
  2750   2750   
  2751         -      rc = sqlite3BtreeGetPage(pBt, iLastPg, &pLastPg, 0);
         2751  +      rc = btreeGetPage(pBt, iLastPg, &pLastPg, 0);
  2752   2752         if( rc!=SQLITE_OK ){
  2753   2753           return rc;
  2754   2754         }
  2755   2755   
  2756   2756         /* If nFin is zero, this loop runs exactly once and page pLastPg
  2757   2757         ** is swapped with the first free page pulled off the free list.
  2758   2758         **
................................................................................
  2783   2783     }
  2784   2784   
  2785   2785     if( nFin==0 ){
  2786   2786       iLastPg--;
  2787   2787       while( iLastPg==PENDING_BYTE_PAGE(pBt)||PTRMAP_ISPAGE(pBt, iLastPg) ){
  2788   2788         if( PTRMAP_ISPAGE(pBt, iLastPg) ){
  2789   2789           MemPage *pPg;
  2790         -        int rc = sqlite3BtreeGetPage(pBt, iLastPg, &pPg, 0);
         2790  +        int rc = btreeGetPage(pBt, iLastPg, &pPg, 0);
  2791   2791           if( rc!=SQLITE_OK ){
  2792   2792             return rc;
  2793   2793           }
  2794   2794           rc = sqlite3PagerWrite(pPg->pDbPage);
  2795   2795           releasePage(pPg);
  2796   2796           if( rc!=SQLITE_OK ){
  2797   2797             return rc;
................................................................................
  3128   3128       assert( TRANS_WRITE==pBt->inTransaction );
  3129   3129       rc2 = sqlite3PagerRollback(pBt->pPager);
  3130   3130       if( rc2!=SQLITE_OK ){
  3131   3131         rc = rc2;
  3132   3132       }
  3133   3133   
  3134   3134       /* The rollback may have destroyed the pPage1->aData value.  So
  3135         -    ** call sqlite3BtreeGetPage() on page 1 again to make
         3135  +    ** call btreeGetPage() on page 1 again to make
  3136   3136       ** sure pPage1->aData is set correctly. */
  3137         -    if( sqlite3BtreeGetPage(pBt, 1, &pPage1, 0)==SQLITE_OK ){
         3137  +    if( btreeGetPage(pBt, 1, &pPage1, 0)==SQLITE_OK ){
  3138   3138         releasePage(pPage1);
  3139   3139       }
  3140   3140       assert( countWriteCursors(pBt)==0 );
  3141   3141       pBt->inTransaction = TRANS_READ;
  3142   3142     }
  3143   3143   
  3144   3144     btreeEndTransaction(p);
................................................................................
  3380   3380     }
  3381   3381     return SQLITE_OK;
  3382   3382   }
  3383   3383   
  3384   3384   /*
  3385   3385   ** Make sure the BtCursor* given in the argument has a valid
  3386   3386   ** BtCursor.info structure.  If it is not already valid, call
  3387         -** sqlite3BtreeParseCell() to fill it in.
         3387  +** btreeParseCell() to fill it in.
  3388   3388   **
  3389   3389   ** BtCursor.info is a cache of the information in the current cell.
  3390         -** Using this cache reduces the number of calls to sqlite3BtreeParseCell().
         3390  +** Using this cache reduces the number of calls to btreeParseCell().
  3391   3391   **
  3392   3392   ** 2007-06-25:  There is a bug in some versions of MSVC that cause the
  3393   3393   ** compiler to crash when getCellInfo() is implemented as a macro.
  3394   3394   ** But there is a measureable speed advantage to using the macro on gcc
  3395   3395   ** (when less compiler optimizations like -Os or -O0 are used and the
  3396   3396   ** compiler is not doing agressive inlining.)  So we use a real function
  3397   3397   ** for MSVC and a macro for everything else.  Ticket #2457.
  3398   3398   */
  3399   3399   #ifndef NDEBUG
  3400   3400     static void assertCellInfo(BtCursor *pCur){
  3401   3401       CellInfo info;
  3402   3402       int iPage = pCur->iPage;
  3403   3403       memset(&info, 0, sizeof(info));
  3404         -    sqlite3BtreeParseCell(pCur->apPage[iPage], pCur->aiIdx[iPage], &info);
         3404  +    btreeParseCell(pCur->apPage[iPage], pCur->aiIdx[iPage], &info);
  3405   3405       assert( memcmp(&info, &pCur->info, sizeof(info))==0 );
  3406   3406     }
  3407   3407   #else
  3408   3408     #define assertCellInfo(x)
  3409   3409   #endif
  3410   3410   #ifdef _MSC_VER
  3411   3411     /* Use a real function in MSVC to work around bugs in that compiler. */
  3412   3412     static void getCellInfo(BtCursor *pCur){
  3413   3413       if( pCur->info.nSize==0 ){
  3414   3414         int iPage = pCur->iPage;
  3415         -      sqlite3BtreeParseCell(pCur->apPage[iPage],pCur->aiIdx[iPage],&pCur->info);
         3415  +      btreeParseCell(pCur->apPage[iPage],pCur->aiIdx[iPage],&pCur->info);
  3416   3416         pCur->validNKey = 1;
  3417   3417       }else{
  3418   3418         assertCellInfo(pCur);
  3419   3419       }
  3420   3420     }
  3421   3421   #else /* if not _MSC_VER */
  3422   3422     /* Use a macro in all other compilers so that the function is inlined */
  3423   3423   #define getCellInfo(pCur)                                                      \
  3424   3424     if( pCur->info.nSize==0 ){                                                   \
  3425   3425       int iPage = pCur->iPage;                                                   \
  3426         -    sqlite3BtreeParseCell(pCur->apPage[iPage],pCur->aiIdx[iPage],&pCur->info); \
         3426  +    btreeParseCell(pCur->apPage[iPage],pCur->aiIdx[iPage],&pCur->info); \
  3427   3427       pCur->validNKey = 1;                                                       \
  3428   3428     }else{                                                                       \
  3429   3429       assertCellInfo(pCur);                                                      \
  3430   3430     }
  3431   3431   #endif /* _MSC_VER */
  3432   3432   
  3433   3433   /*
................................................................................
  3535   3535           rc = SQLITE_DONE;
  3536   3536         }
  3537   3537       }
  3538   3538     }
  3539   3539   #endif
  3540   3540   
  3541   3541     if( rc==SQLITE_OK ){
  3542         -    rc = sqlite3BtreeGetPage(pBt, ovfl, &pPage, 0);
         3542  +    rc = btreeGetPage(pBt, ovfl, &pPage, 0);
  3543   3543       assert(rc==SQLITE_OK || pPage==0);
  3544   3544       if( next==0 && rc==SQLITE_OK ){
  3545   3545         next = get4byte(pPage->aData);
  3546   3546       }
  3547   3547     }
  3548   3548   
  3549   3549     *pPgnoNext = next;
................................................................................
  3948   3948   ** Move the cursor up to the parent page.
  3949   3949   **
  3950   3950   ** pCur->idx is set to the cell index that contains the pointer
  3951   3951   ** to the page we are coming from.  If we are coming from the
  3952   3952   ** right-most child page then pCur->idx is set to one more than
  3953   3953   ** the largest cell index.
  3954   3954   */
  3955         -void sqlite3BtreeMoveToParent(BtCursor *pCur){
         3955  +static void moveToParent(BtCursor *pCur){
  3956   3956     assert( cursorHoldsMutex(pCur) );
  3957   3957     assert( pCur->eState==CURSOR_VALID );
  3958   3958     assert( pCur->iPage>0 );
  3959   3959     assert( pCur->apPage[pCur->iPage] );
  3960   3960     assertParentIndex(
  3961   3961       pCur->apPage[pCur->iPage-1], 
  3962   3962       pCur->aiIdx[pCur->iPage-1], 
................................................................................
  4280   4280           }else{
  4281   4281             /* The record flows over onto one or more overflow pages. In
  4282   4282             ** this case the whole cell needs to be parsed, a buffer allocated
  4283   4283             ** and accessPayload() used to retrieve the record into the
  4284   4284             ** buffer before VdbeRecordCompare() can be called. */
  4285   4285             void *pCellKey;
  4286   4286             u8 * const pCellBody = pCell - pPage->childPtrSize;
  4287         -          sqlite3BtreeParseCellPtr(pPage, pCellBody, &pCur->info);
         4287  +          btreeParseCellPtr(pPage, pCellBody, &pCur->info);
  4288   4288             nCell = (int)pCur->info.nKey;
  4289   4289             pCellKey = sqlite3Malloc( nCell );
  4290   4290             if( pCellKey==0 ){
  4291   4291               rc = SQLITE_NOMEM;
  4292   4292               goto moveto_finish;
  4293   4293             }
  4294   4294             rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0, 0);
................................................................................
  4404   4404       }
  4405   4405       do{
  4406   4406         if( pCur->iPage==0 ){
  4407   4407           *pRes = 1;
  4408   4408           pCur->eState = CURSOR_INVALID;
  4409   4409           return SQLITE_OK;
  4410   4410         }
  4411         -      sqlite3BtreeMoveToParent(pCur);
         4411  +      moveToParent(pCur);
  4412   4412         pPage = pCur->apPage[pCur->iPage];
  4413   4413       }while( pCur->aiIdx[pCur->iPage]>=pPage->nCell );
  4414   4414       *pRes = 0;
  4415   4415       if( pPage->intKey ){
  4416   4416         rc = sqlite3BtreeNext(pCur, pRes);
  4417   4417       }else{
  4418   4418         rc = SQLITE_OK;
................................................................................
  4467   4467     }else{
  4468   4468       while( pCur->aiIdx[pCur->iPage]==0 ){
  4469   4469         if( pCur->iPage==0 ){
  4470   4470           pCur->eState = CURSOR_INVALID;
  4471   4471           *pRes = 1;
  4472   4472           return SQLITE_OK;
  4473   4473         }
  4474         -      sqlite3BtreeMoveToParent(pCur);
         4474  +      moveToParent(pCur);
  4475   4475       }
  4476   4476       pCur->info.nSize = 0;
  4477   4477       pCur->validNKey = 0;
  4478   4478   
  4479   4479       pCur->aiIdx[pCur->iPage]--;
  4480   4480       pPage = pCur->apPage[pCur->iPage];
  4481   4481       if( pPage->intKey && !pPage->leaf ){
................................................................................
  4573   4573         }else{
  4574   4574           iTrunk = get4byte(&pPage1->aData[32]);
  4575   4575         }
  4576   4576         testcase( iTrunk==mxPage );
  4577   4577         if( iTrunk>mxPage ){
  4578   4578           rc = SQLITE_CORRUPT_BKPT;
  4579   4579         }else{
  4580         -        rc = sqlite3BtreeGetPage(pBt, iTrunk, &pTrunk, 0);
         4580  +        rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0);
  4581   4581         }
  4582   4582         if( rc ){
  4583   4583           pTrunk = 0;
  4584   4584           goto end_allocate_page;
  4585   4585         }
  4586   4586   
  4587   4587         k = get4byte(&pTrunk->aData[4]);
................................................................................
  4630   4630             MemPage *pNewTrunk;
  4631   4631             Pgno iNewTrunk = get4byte(&pTrunk->aData[8]);
  4632   4632             if( iNewTrunk>mxPage ){ 
  4633   4633               rc = SQLITE_CORRUPT_BKPT;
  4634   4634               goto end_allocate_page;
  4635   4635             }
  4636   4636             testcase( iNewTrunk==mxPage );
  4637         -          rc = sqlite3BtreeGetPage(pBt, iNewTrunk, &pNewTrunk, 0);
         4637  +          rc = btreeGetPage(pBt, iNewTrunk, &pNewTrunk, 0);
  4638   4638             if( rc!=SQLITE_OK ){
  4639   4639               goto end_allocate_page;
  4640   4640             }
  4641   4641             rc = sqlite3PagerWrite(pNewTrunk->pDbPage);
  4642   4642             if( rc!=SQLITE_OK ){
  4643   4643               releasePage(pNewTrunk);
  4644   4644               goto end_allocate_page;
................................................................................
  4703   4703                    *pPgno, closest+1, k, pTrunk->pgno, n-1));
  4704   4704             if( closest<k-1 ){
  4705   4705               memcpy(&aData[8+closest*4], &aData[4+k*4], 4);
  4706   4706             }
  4707   4707             put4byte(&aData[4], k-1);
  4708   4708             assert( sqlite3PagerIswriteable(pTrunk->pDbPage) );
  4709   4709             noContent = !btreeGetHasContent(pBt, *pPgno);
  4710         -          rc = sqlite3BtreeGetPage(pBt, *pPgno, ppPage, noContent);
         4710  +          rc = btreeGetPage(pBt, *pPgno, ppPage, noContent);
  4711   4711             if( rc==SQLITE_OK ){
  4712   4712               rc = sqlite3PagerWrite((*ppPage)->pDbPage);
  4713   4713               if( rc!=SQLITE_OK ){
  4714   4714                 releasePage(*ppPage);
  4715   4715               }
  4716   4716             }
  4717   4717             searchList = 0;
................................................................................
  4735   4735         /* If *pPgno refers to a pointer-map page, allocate two new pages
  4736   4736         ** at the end of the file instead of one. The first allocated page
  4737   4737         ** becomes a new pointer-map page, the second is used by the caller.
  4738   4738         */
  4739   4739         MemPage *pPg = 0;
  4740   4740         TRACE(("ALLOCATE: %d from end of file (pointer-map page)\n", *pPgno));
  4741   4741         assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
  4742         -      rc = sqlite3BtreeGetPage(pBt, *pPgno, &pPg, 0);
         4742  +      rc = btreeGetPage(pBt, *pPgno, &pPg, 0);
  4743   4743         if( rc==SQLITE_OK ){
  4744   4744           rc = sqlite3PagerWrite(pPg->pDbPage);
  4745   4745           releasePage(pPg);
  4746   4746         }
  4747   4747         if( rc ) return rc;
  4748   4748         (*pPgno)++;
  4749   4749         if( *pPgno==PENDING_BYTE_PAGE(pBt) ){ (*pPgno)++; }
  4750   4750       }
  4751   4751   #endif
  4752   4752   
  4753   4753       assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
  4754         -    rc = sqlite3BtreeGetPage(pBt, *pPgno, ppPage, 0);
         4754  +    rc = btreeGetPage(pBt, *pPgno, ppPage, 0);
  4755   4755       if( rc ) return rc;
  4756   4756       rc = sqlite3PagerWrite((*ppPage)->pDbPage);
  4757   4757       if( rc!=SQLITE_OK ){
  4758   4758         releasePage(*ppPage);
  4759   4759       }
  4760   4760       TRACE(("ALLOCATE: %d from end of file\n", *pPgno));
  4761   4761     }
................................................................................
  4814   4814     nFree = get4byte(&pPage1->aData[36]);
  4815   4815     put4byte(&pPage1->aData[36], nFree+1);
  4816   4816   
  4817   4817   #ifdef SQLITE_SECURE_DELETE
  4818   4818     /* If the SQLITE_SECURE_DELETE compile-time option is enabled, then
  4819   4819     ** always fully overwrite deleted information with zeros.
  4820   4820     */
  4821         -  if( (!pPage && (rc = sqlite3BtreeGetPage(pBt, iPage, &pPage, 0)))
         4821  +  if( (!pPage && (rc = btreeGetPage(pBt, iPage, &pPage, 0)))
  4822   4822      ||            (rc = sqlite3PagerWrite(pPage->pDbPage))
  4823   4823     ){
  4824   4824       goto freepage_out;
  4825   4825     }
  4826   4826     memset(pPage->aData, 0, pPage->pBt->pageSize);
  4827   4827   #endif
  4828   4828   
................................................................................
  4841   4841     ** first trunk page in the current free-list. This block tests if it
  4842   4842     ** is possible to add the page as a new free-list leaf.
  4843   4843     */
  4844   4844     if( nFree!=0 ){
  4845   4845       int nLeaf;                /* Initial number of leaf cells on trunk page */
  4846   4846   
  4847   4847       iTrunk = get4byte(&pPage1->aData[32]);
  4848         -    rc = sqlite3BtreeGetPage(pBt, iTrunk, &pTrunk, 0);
         4848  +    rc = btreeGetPage(pBt, iTrunk, &pTrunk, 0);
  4849   4849       if( rc!=SQLITE_OK ){
  4850   4850         goto freepage_out;
  4851   4851       }
  4852   4852   
  4853   4853       nLeaf = get4byte(&pTrunk->aData[4]);
  4854   4854       if( nLeaf<0 ){
  4855   4855         rc = SQLITE_CORRUPT_BKPT;
................................................................................
  4888   4888   
  4889   4889     /* If control flows to this point, then it was not possible to add the
  4890   4890     ** the page being freed as a leaf page of the first trunk in the free-list.
  4891   4891     ** Possibly because the free-list is empty, or possibly because the 
  4892   4892     ** first trunk in the free-list is full. Either way, the page being freed
  4893   4893     ** will become the new first trunk page in the free-list.
  4894   4894     */
  4895         -  if(   ((!pPage) && (0 != (rc = sqlite3BtreeGetPage(pBt, iPage, &pPage, 0))))
         4895  +  if(   ((!pPage) && (0 != (rc = btreeGetPage(pBt, iPage, &pPage, 0))))
  4896   4896        || (0 != (rc = sqlite3PagerWrite(pPage->pDbPage)))
  4897   4897     ){
  4898   4898       goto freepage_out;
  4899   4899     }
  4900   4900     put4byte(pPage->aData, iTrunk);
  4901   4901     put4byte(&pPage->aData[4], 0);
  4902   4902     put4byte(&pPage1->aData[32], iPage);
................................................................................
  4922   4922     CellInfo info;
  4923   4923     Pgno ovflPgno;
  4924   4924     int rc;
  4925   4925     int nOvfl;
  4926   4926     u16 ovflPageSize;
  4927   4927   
  4928   4928     assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  4929         -  sqlite3BtreeParseCellPtr(pPage, pCell, &info);
         4929  +  btreeParseCellPtr(pPage, pCell, &info);
  4930   4930     if( info.iOverflow==0 ){
  4931   4931       return SQLITE_OK;  /* No overflow pages. Return without doing anything */
  4932   4932     }
  4933   4933     ovflPgno = get4byte(&pCell[info.iOverflow]);
  4934   4934     assert( pBt->usableSize > 4 );
  4935   4935     ovflPageSize = pBt->usableSize - 4;
  4936   4936     nOvfl = (info.nPayload - info.nLocal + ovflPageSize - 1)/ovflPageSize;
................................................................................
  5005   5005     }
  5006   5006     if( pPage->hasData ){
  5007   5007       nHeader += putVarint(&pCell[nHeader], nData+nZero);
  5008   5008     }else{
  5009   5009       nData = nZero = 0;
  5010   5010     }
  5011   5011     nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey);
  5012         -  sqlite3BtreeParseCellPtr(pPage, pCell, &info);
         5012  +  btreeParseCellPtr(pPage, pCell, &info);
  5013   5013     assert( info.nHeader==nHeader );
  5014   5014     assert( info.nKey==nKey );
  5015   5015     assert( info.nData==(u32)(nData+nZero) );
  5016   5016     
  5017   5017     /* Fill in the payload */
  5018   5018     nPayload = nData + nZero;
  5019   5019     if( pPage->intKey ){
................................................................................
  5428   5428       assert( pPage->isInit );
  5429   5429   
  5430   5430       for(j=0; j<pPage->nCell; j++){
  5431   5431         CellInfo info;
  5432   5432         u8 *z;
  5433   5433        
  5434   5434         z = findCell(pPage, j);
  5435         -      sqlite3BtreeParseCellPtr(pPage, z, &info);
         5435  +      btreeParseCellPtr(pPage, z, &info);
  5436   5436         if( info.iOverflow ){
  5437   5437           Pgno ovfl = get4byte(&z[info.iOverflow]);
  5438   5438           ptrmapGet(pBt, ovfl, &e, &n);
  5439   5439           assert( n==pPage->pgno && e==PTRMAP_OVERFLOW1 );
  5440   5440         }
  5441   5441         if( !pPage->leaf ){
  5442   5442           Pgno child = get4byte(z);
................................................................................
  5461   5461   ** parent page stored in the pointer map is page pTo. If pFrom contained
  5462   5462   ** any cells with overflow page pointers, then the corresponding pointer
  5463   5463   ** map entries are also updated so that the parent page is page pTo.
  5464   5464   **
  5465   5465   ** If pFrom is currently carrying any overflow cells (entries in the
  5466   5466   ** MemPage.aOvfl[] array), they are not copied to pTo. 
  5467   5467   **
  5468         -** Before returning, page pTo is reinitialized using sqlite3BtreeInitPage().
         5468  +** Before returning, page pTo is reinitialized using btreeInitPage().
  5469   5469   **
  5470   5470   ** The performance of this function is not critical. It is only used by 
  5471   5471   ** the balance_shallower() and balance_deeper() procedures, neither of
  5472   5472   ** which are called often under normal circumstances.
  5473   5473   */
  5474   5474   static int copyNodeContent(MemPage *pFrom, MemPage *pTo){
  5475   5475     BtShared * const pBt = pFrom->pBt;
................................................................................
  5489   5489     memcpy(&aTo[iData], &aFrom[iData], pBt->usableSize-iData);
  5490   5490     memcpy(&aTo[iToHdr], &aFrom[iFromHdr], pFrom->cellOffset + 2*pFrom->nCell);
  5491   5491   
  5492   5492     /* Reinitialize page pTo so that the contents of the MemPage structure
  5493   5493     ** match the new data. The initialization of pTo "cannot" fail, as the
  5494   5494     ** data copied from pFrom is known to be valid.  */
  5495   5495     pTo->isInit = 0;
  5496         -  TESTONLY(rc = ) sqlite3BtreeInitPage(pTo);
         5496  +  TESTONLY(rc = ) btreeInitPage(pTo);
  5497   5497     assert( rc==SQLITE_OK );
  5498   5498   
  5499   5499     /* If this is an auto-vacuum database, update the pointer-map entries
  5500   5500     ** for any b-tree or overflow pages that pTo now contains the pointers to. */
  5501   5501     if( ISAUTOVACUUM ){
  5502   5502       rc = setChildPtrmaps(pTo);
  5503   5503     }
................................................................................
  5952   5952           /* If the tree is a leaf-data tree, and the siblings are leaves, 
  5953   5953           ** then there is no divider cell in apCell[]. Instead, the divider 
  5954   5954           ** cell consists of the integer key for the right-most cell of 
  5955   5955           ** the sibling-page assembled above only.
  5956   5956           */
  5957   5957           CellInfo info;
  5958   5958           j--;
  5959         -        sqlite3BtreeParseCellPtr(pNew, apCell[j], &info);
         5959  +        btreeParseCellPtr(pNew, apCell[j], &info);
  5960   5960           pCell = pTemp;
  5961   5961           sz = 4 + putVarint(&pCell[4], info.nKey);
  5962   5962           pTemp = 0;
  5963   5963         }else{
  5964   5964           pCell -= 4;
  5965   5965           /* Obscure case for non-leaf-data trees: If the cell at pCell was
  5966   5966           ** previously stored on a leaf node, and its reported size was 4
  5967   5967           ** bytes, then it may actually be smaller than this 
  5968         -        ** (see sqlite3BtreeParseCellPtr(), 4 bytes is the minimum size of
         5968  +        ** (see btreeParseCellPtr(), 4 bytes is the minimum size of
  5969   5969           ** any cell). But it is important to pass the correct size to 
  5970   5970           ** insertCell(), so reparse the cell now.
  5971   5971           **
  5972   5972           ** Note that this can never happen in an SQLite data file, as all
  5973   5973           ** cells are at least 4 bytes. It only happens in b-trees used
  5974   5974           ** to evaluate "IN (SELECT ...)" and similar clauses.
  5975   5975           */
................................................................................
  6672   6672         */
  6673   6673         u8 eType;
  6674   6674         Pgno iPtrPage;
  6675   6675   
  6676   6676         releasePage(pPageMove);
  6677   6677   
  6678   6678         /* Move the page currently at pgnoRoot to pgnoMove. */
  6679         -      rc = sqlite3BtreeGetPage(pBt, pgnoRoot, &pRoot, 0);
         6679  +      rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0);
  6680   6680         if( rc!=SQLITE_OK ){
  6681   6681           return rc;
  6682   6682         }
  6683   6683         rc = ptrmapGet(pBt, pgnoRoot, &eType, &iPtrPage);
  6684   6684         if( eType==PTRMAP_ROOTPAGE || eType==PTRMAP_FREEPAGE ){
  6685   6685           rc = SQLITE_CORRUPT_BKPT;
  6686   6686         }
................................................................................
  6693   6693         rc = relocatePage(pBt, pRoot, eType, iPtrPage, pgnoMove, 0);
  6694   6694         releasePage(pRoot);
  6695   6695   
  6696   6696         /* Obtain the page at pgnoRoot */
  6697   6697         if( rc!=SQLITE_OK ){
  6698   6698           return rc;
  6699   6699         }
  6700         -      rc = sqlite3BtreeGetPage(pBt, pgnoRoot, &pRoot, 0);
         6700  +      rc = btreeGetPage(pBt, pgnoRoot, &pRoot, 0);
  6701   6701         if( rc!=SQLITE_OK ){
  6702   6702           return rc;
  6703   6703         }
  6704   6704         rc = sqlite3PagerWrite(pRoot->pDbPage);
  6705   6705         if( rc!=SQLITE_OK ){
  6706   6706           releasePage(pRoot);
  6707   6707           return rc;
................................................................................
  6856   6856     ** occur.
  6857   6857     */
  6858   6858     if( pBt->pCursor ){
  6859   6859       sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db);
  6860   6860       return SQLITE_LOCKED_SHAREDCACHE;
  6861   6861     }
  6862   6862   
  6863         -  rc = sqlite3BtreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
         6863  +  rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
  6864   6864     if( rc ) return rc;
  6865   6865     rc = sqlite3BtreeClearTable(p, iTable, 0);
  6866   6866     if( rc ){
  6867   6867       releasePage(pPage);
  6868   6868       return rc;
  6869   6869     }
  6870   6870   
................................................................................
  6891   6891         }else{
  6892   6892           /* The table being dropped does not have the largest root-page
  6893   6893           ** number in the database. So move the page that does into the 
  6894   6894           ** gap left by the deleted root-page.
  6895   6895           */
  6896   6896           MemPage *pMove;
  6897   6897           releasePage(pPage);
  6898         -        rc = sqlite3BtreeGetPage(pBt, maxRootPgno, &pMove, 0);
         6898  +        rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
  6899   6899           if( rc!=SQLITE_OK ){
  6900   6900             return rc;
  6901   6901           }
  6902   6902           rc = relocatePage(pBt, pMove, PTRMAP_ROOTPAGE, 0, iTable, 0);
  6903   6903           releasePage(pMove);
  6904   6904           if( rc!=SQLITE_OK ){
  6905   6905             return rc;
  6906   6906           }
  6907         -        rc = sqlite3BtreeGetPage(pBt, maxRootPgno, &pMove, 0);
         6907  +        rc = btreeGetPage(pBt, maxRootPgno, &pMove, 0);
  6908   6908           if( rc!=SQLITE_OK ){
  6909   6909             return rc;
  6910   6910           }
  6911   6911           rc = freePage(pMove);
  6912   6912           releasePage(pMove);
  6913   6913           if( rc!=SQLITE_OK ){
  6914   6914             return rc;
................................................................................
  7056   7056       if( pPage->leaf ){
  7057   7057         do {
  7058   7058           if( pCur->iPage==0 ){
  7059   7059             /* All pages of the b-tree have been visited. Return successfully. */
  7060   7060             *pnEntry = nEntry;
  7061   7061             return SQLITE_OK;
  7062   7062           }
  7063         -        sqlite3BtreeMoveToParent(pCur);
         7063  +        moveToParent(pCur);
  7064   7064         }while ( pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell );
  7065   7065   
  7066   7066         pCur->aiIdx[pCur->iPage]++;
  7067   7067         pPage = pCur->apPage[pCur->iPage];
  7068   7068       }
  7069   7069   
  7070   7070       /* Descend to the child node of the cell that the cursor currently 
................................................................................
  7283   7283   
  7284   7284     /* Check that the page exists
  7285   7285     */
  7286   7286     pBt = pCheck->pBt;
  7287   7287     usableSize = pBt->usableSize;
  7288   7288     if( iPage==0 ) return 0;
  7289   7289     if( checkRef(pCheck, iPage, zParentContext) ) return 0;
  7290         -  if( (rc = sqlite3BtreeGetPage(pBt, (Pgno)iPage, &pPage, 0))!=0 ){
         7290  +  if( (rc = btreeGetPage(pBt, (Pgno)iPage, &pPage, 0))!=0 ){
  7291   7291       if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ) pCheck->mallocFailed = 1;
  7292   7292       checkAppendMsg(pCheck, zContext,
  7293   7293          "unable to get the page. error code=%d", rc);
  7294   7294       return 0;
  7295   7295     }
  7296         -  if( (rc = sqlite3BtreeInitPage(pPage))!=0 ){
         7296  +  if( (rc = btreeInitPage(pPage))!=0 ){
  7297   7297       assert( rc==SQLITE_CORRUPT );  /* The only possible error from InitPage */
  7298   7298       checkAppendMsg(pCheck, zContext, 
  7299         -                   "sqlite3BtreeInitPage() returns error code %d", rc);
         7299  +                   "btreeInitPage() returns error code %d", rc);
  7300   7300       releasePage(pPage);
  7301   7301       return 0;
  7302   7302     }
  7303   7303   
  7304   7304     /* Check out all the cells.
  7305   7305     */
  7306   7306     depth = 0;
................................................................................
  7310   7310       CellInfo info;
  7311   7311   
  7312   7312       /* Check payload overflow pages
  7313   7313       */
  7314   7314       sqlite3_snprintf(sizeof(zContext), zContext,
  7315   7315                "On tree page %d cell %d: ", iPage, i);
  7316   7316       pCell = findCell(pPage,i);
  7317         -    sqlite3BtreeParseCellPtr(pPage, pCell, &info);
         7317  +    btreeParseCellPtr(pPage, pCell, &info);
  7318   7318       sz = info.nData;
  7319   7319       if( !pPage->intKey ) sz += (int)info.nKey;
  7320   7320       assert( sz==info.nPayload );
  7321   7321       if( (sz>info.nLocal) 
  7322   7322        && (&pCell[info.iOverflow]<=&pPage->aData[pBt->usableSize])
  7323   7323       ){
  7324   7324         int nPage = (sz - info.nLocal + usableSize - 5)/(usableSize - 4);

Changes to src/btree.h.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This header file defines the interface that the sqlite B-Tree file
    13     13   ** subsystem.  See comments in the source code for a detailed description
    14     14   ** of what each interface routine does.
    15     15   **
    16         -** @(#) $Id: btree.h,v 1.118 2009/07/06 18:56:13 danielk1977 Exp $
           16  +** @(#) $Id: btree.h,v 1.119 2009/07/09 05:07:38 danielk1977 Exp $
    17     17   */
    18     18   #ifndef _BTREE_H_
    19     19   #define _BTREE_H_
    20     20   
    21     21   /* TODO: This definition is just included so other modules compile. It
    22     22   ** needs to be revisited.
    23     23   */
................................................................................
   164    164   int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
   165    165                                     const void *pData, int nData,
   166    166                                     int nZero, int bias, int seekResult);
   167    167   int sqlite3BtreeFirst(BtCursor*, int *pRes);
   168    168   int sqlite3BtreeLast(BtCursor*, int *pRes);
   169    169   int sqlite3BtreeNext(BtCursor*, int *pRes);
   170    170   int sqlite3BtreeEof(BtCursor*);
   171         -int sqlite3BtreeFlags(BtCursor*);
   172    171   int sqlite3BtreePrevious(BtCursor*, int *pRes);
   173    172   int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
   174    173   int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
   175    174   const void *sqlite3BtreeKeyFetch(BtCursor*, int *pAmt);
   176    175   const void *sqlite3BtreeDataFetch(BtCursor*, int *pAmt);
   177    176   int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
   178    177   int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);

Changes to src/btreeInt.h.

     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12         -** $Id: btreeInt.h,v 1.50 2009/07/02 07:47:33 danielk1977 Exp $
           12  +** $Id: btreeInt.h,v 1.51 2009/07/09 05:07:38 danielk1977 Exp $
    13     13   **
    14     14   ** This file implements a external (disk-based) database using BTrees.
    15     15   ** For a detailed discussion of BTrees, refer to
    16     16   **
    17     17   **     Donald E. Knuth, THE ART OF COMPUTER PROGRAMMING, Volume 3:
    18     18   **     "Sorting And Searching", pages 473-480. Addison-Wesley
    19     19   **     Publishing Company, Reading, Massachusetts.
................................................................................
   635    635   ** Read or write a two- and four-byte big-endian integer values.
   636    636   */
   637    637   #define get2byte(x)   ((x)[0]<<8 | (x)[1])
   638    638   #define put2byte(p,v) ((p)[0] = (u8)((v)>>8), (p)[1] = (u8)(v))
   639    639   #define get4byte sqlite3Get4byte
   640    640   #define put4byte sqlite3Put4byte
   641    641   
   642         -/*
   643         -** Internal routines that should be accessed by the btree layer only.
   644         -*/
   645         -int sqlite3BtreeGetPage(BtShared*, Pgno, MemPage**, int);
   646         -int sqlite3BtreeInitPage(MemPage *pPage);
   647         -void sqlite3BtreeParseCellPtr(MemPage*, u8*, CellInfo*);
   648         -void sqlite3BtreeParseCell(MemPage*, int, CellInfo*);
   649         -int sqlite3BtreeRestoreCursorPosition(BtCursor *pCur);
   650         -void sqlite3BtreeMoveToParent(BtCursor *pCur);
   651         -
   652         -#ifdef SQLITE_TEST
   653         -void sqlite3BtreeGetTempCursor(BtCursor *pCur, BtCursor *pTempCur);
   654         -void sqlite3BtreeReleaseTempCursor(BtCursor *pCur);
   655         -#endif

Changes to src/test3.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Code for testing the btree.c module in SQLite.  This code
    13     13   ** is not included in the SQLite library.  It is used for automated
    14     14   ** testing of the SQLite library.
    15     15   **
    16         -** $Id: test3.c,v 1.110 2009/07/09 03:20:46 shane Exp $
           16  +** $Id: test3.c,v 1.111 2009/07/09 05:07:38 danielk1977 Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "btreeInt.h"
    20     20   #include "tcl.h"
    21     21   #include <stdlib.h>
    22     22   #include <string.h>
    23     23   
................................................................................
   404    404     if( argc!=2 ){
   405    405       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   406    406          " ID\"", 0);
   407    407       return TCL_ERROR;
   408    408     }
   409    409     pCur = sqlite3TestTextToPtr(argv[1]);
   410    410     sqlite3BtreeEnter(pCur->pBtree);
   411         -  if (pCur->eState>=CURSOR_REQUIRESEEK) sqlite3BtreeRestoreCursorPosition(pCur);
          411  +
          412  +  /* The cursor may be in "require-seek" state. If this is the case, the
          413  +  ** call to BtreeDataSize() will fix it. */
          414  +  sqlite3BtreeDataSize(pCur, (u32*)&n2);
   412    415     if( pCur->apPage[pCur->iPage]->intKey ){
   413    416       n1 = 0;
   414    417     }else{
   415    418       sqlite3BtreeKeySize(pCur, (i64*)&n1);
   416    419     }
   417         -  sqlite3BtreeDataSize(pCur, (u32*)&n2);
   418    420     sqlite3BtreeLeave(pCur->pBtree);
   419    421     sqlite3_snprintf(sizeof(zBuf),zBuf, "%d", (int)(n1+n2));
   420    422     Tcl_AppendResult(interp, zBuf, 0);
   421    423     return SQLITE_OK;
   422    424   }
   423    425   
   424    426   /*
................................................................................
   574    576     res = sqlite3PagerIsMemdb(sqlite3BtreePager(pBt));
   575    577     sqlite3BtreeLeave(pBt);
   576    578     sqlite3_mutex_leave(pBt->db->mutex);
   577    579     Tcl_SetObjResult(interp, Tcl_NewBooleanObj(res));
   578    580     return SQLITE_OK;
   579    581   }
   580    582   
          583  +/*
          584  +** usage:   btree_set_cache_size ID NCACHE
          585  +**
          586  +** Set the size of the cache used by btree $ID.
          587  +*/
          588  +static int btree_set_cache_size(
          589  +  void *NotUsed,
          590  +  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
          591  +  int argc,              /* Number of arguments */
          592  +  const char **argv      /* Text of each argument */
          593  +){
          594  +  int nCache;
          595  +  Btree *pBt;
          596  +  
          597  +  if( argc!=3 ){
          598  +    Tcl_AppendResult(
          599  +        interp, "wrong # args: should be \"", argv[0], " BT NCACHE\"", 0);
          600  +    return TCL_ERROR;
          601  +  }
          602  +  pBt = sqlite3TestTextToPtr(argv[1]);
          603  +  if( Tcl_GetInt(interp, argv[2], &nCache) ) return TCL_ERROR;
          604  +
          605  +  sqlite3_mutex_enter(pBt->db->mutex);
          606  +  sqlite3BtreeEnter(pBt);
          607  +  sqlite3BtreeSetCacheSize(pBt, nCache);
          608  +  sqlite3BtreeLeave(pBt);
          609  +  sqlite3_mutex_leave(pBt->db->mutex);
          610  +  return TCL_OK;
          611  +}      
          612  +
          613  +
   581    614   
   582    615   /*
   583    616   ** Register commands with the TCL interpreter.
   584    617   */
   585    618   int Sqlitetest3_Init(Tcl_Interp *interp){
   586    619     static struct {
   587    620        char *zName;
................................................................................
   595    628        { "btree_close_cursor",       (Tcl_CmdProc*)btree_close_cursor       },
   596    629        { "btree_next",               (Tcl_CmdProc*)btree_next               },
   597    630        { "btree_eof",                (Tcl_CmdProc*)btree_eof                },
   598    631        { "btree_payload_size",       (Tcl_CmdProc*)btree_payload_size       },
   599    632        { "btree_first",              (Tcl_CmdProc*)btree_first              },
   600    633        { "btree_varint_test",        (Tcl_CmdProc*)btree_varint_test        },
   601    634        { "btree_from_db",            (Tcl_CmdProc*)btree_from_db            },
   602         -     { "btree_ismemdb",            (Tcl_CmdProc*)btree_ismemdb            }
          635  +     { "btree_ismemdb",            (Tcl_CmdProc*)btree_ismemdb            },
          636  +     { "btree_set_cache_size",     (Tcl_CmdProc*)btree_set_cache_size     }
   603    637     };
   604    638     int i;
   605    639   
   606    640     for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
   607    641       Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
   608    642     }
   609    643   
   610    644     return TCL_OK;
   611    645   }