/ Check-in [bfb3234d]
Login

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

Overview
Comment:Update test3.c to work with the new btree.c API. (CVS 1314)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: bfb3234dc60c9152fdf0a16b887089365443f5ed
User & Date: drh 2004-05-04 17:27:28
Context
2004-05-06
23:37
Add code to convert between the various supported unicode encoding schemes. Untested at this point. (CVS 1315) check-in: 71260ff7 user: danielk1977 tags: trunk
2004-05-04
17:27
Update test3.c to work with the new btree.c API. (CVS 1314) check-in: bfb3234d user: drh tags: trunk
15:00
Added template for the utf.c file containing conversion routines. (CVS 1313) check-in: 89b42c46 user: drh 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.108 2004/05/03 19:49:33 drh Exp $
           12  +** $Id: btree.c,v 1.109 2004/05/04 17:27:28 drh 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.
................................................................................
   262    262     int (*xCompare)(void*,int,const void*,int,const void*); /* Key comp func */
   263    263     void *pArg;               /* First arg to xCompare() */
   264    264     Pgno pgnoRoot;            /* The root page of this tree */
   265    265     MemPage *pPage;           /* Page that contains the entry */
   266    266     int idx;                  /* Index of the entry in pPage->aCell[] */
   267    267     u8 wrFlag;                /* True if writable */
   268    268     u8 eSkip;                 /* Determines if next step operation is a no-op */
   269         -  u8 iMatch;                /* compare result from last sqliteBtreeMoveto() */
          269  +  u8 iMatch;                /* compare result from last sqlite3BtreeMoveto() */
   270    270   };
   271    271   
   272    272   /*
   273    273   ** Legal values for BtCursor.eSkip.
   274    274   */
   275    275   #define SKIP_NONE     0   /* Always step the cursor */
   276         -#define SKIP_NEXT     1   /* The next sqliteBtreeNext() is a no-op */
   277         -#define SKIP_PREV     2   /* The next sqliteBtreePrevious() is a no-op */
          276  +#define SKIP_NEXT     1   /* The next sqlite3BtreeNext() is a no-op */
          277  +#define SKIP_PREV     2   /* The next sqlite3BtreePrevious() is a no-op */
   278    278   #define SKIP_INVALID  3   /* Calls to Next() and Previous() are invalid */
   279    279   
   280    280   /*
   281    281   ** Read or write a two-, four-, and eight-byte big-endian integer values.
   282    282   */
   283    283   static u32 get2byte(unsigned char *p){
   284    284     return (p[0]<<8) | p[1];
................................................................................
   389    389   ** into one big FreeBlk at the end of the page.
   390    390   */
   391    391   static void defragmentPage(MemPage *pPage){
   392    392     int pc, i, n, addr;
   393    393     int start, hdr, size;
   394    394     int leftover;
   395    395     unsigned char *oldPage;
   396         -  unsigned char newPage[SQLITE_PAGE_SIZE];
          396  +  unsigned char newPage[MX_PAGE_SIZE];
   397    397   
   398    398     assert( sqlitepager_iswriteable(pPage->aData) );
   399    399     assert( pPage->pBt!=0 );
   400         -  assert( pPage->pageSize <= SQLITE_PAGE_SIZE );
          400  +  assert( pPage->pageSize <= MX_PAGE_SIZE );
   401    401     oldPage = pPage->aData;
   402    402     hdr = pPage->hdrOffset;
   403    403     addr = 3+hdr;
   404    404     n = 6+hdr;
   405    405     if( !pPage->leaf ){
   406    406       n += 4;
   407    407     }
................................................................................
   825    825   **
   826    826   ** Actually, this routine just sets up the internal data structures
   827    827   ** for accessing the database.  We do not open the database file 
   828    828   ** until the first page is loaded.
   829    829   **
   830    830   ** zFilename is the name of the database file.  If zFilename is NULL
   831    831   ** a new database with a random name is created.  This randomly named
   832         -** database file will be deleted when sqliteBtreeClose() is called.
          832  +** database file will be deleted when sqlite3BtreeClose() is called.
   833    833   */
   834         -int sqliteBtreeOpen(
          834  +int sqlite3BtreeOpen(
   835    835     const char *zFilename,  /* Name of the file containing the BTree database */
   836    836     Btree **ppBtree,        /* Pointer to new Btree object written here */
   837    837     int nCache,             /* Number of cache pages */
   838    838     int flags               /* Options */
   839    839   ){
   840    840     Btree *pBt;
   841    841     int rc, i;
................................................................................
   901    901   ** and the database cannot be corrupted if this program
   902    902   ** crashes.  But if the operating system crashes or there is
   903    903   ** an abrupt power failure when synchronous is off, the database
   904    904   ** could be left in an inconsistent and unrecoverable state.
   905    905   ** Synchronous is on by default so database corruption is not
   906    906   ** normally a worry.
   907    907   */
   908         -int sqilte3BtreeSetCacheSize(Btree *pBt, int mxPage){
          908  +int sqlite3BtreeSetCacheSize(Btree *pBt, int mxPage){
   909    909     sqlitepager_set_cachesize(pBt->pPager, mxPage);
   910    910     return SQLITE_OK;
   911    911   }
   912    912   
   913    913   /*
   914    914   ** Change the way data is synced to disk in order to increase or decrease
   915    915   ** how well the database resists damage due to OS crashes and power
................................................................................
  1006   1006   /*
  1007   1007   ** Attempt to start a new transaction.
  1008   1008   **
  1009   1009   ** A transaction must be started before attempting any changes
  1010   1010   ** to the database.  None of the following routines will work
  1011   1011   ** unless a transaction is started first:
  1012   1012   **
  1013         -**      sqliteBtreeCreateTable()
  1014         -**      sqliteBtreeCreateIndex()
  1015         -**      sqliteBtreeClearTable()
  1016         -**      sqliteBtreeDropTable()
  1017         -**      sqliteBtreeInsert()
  1018         -**      sqliteBtreeDelete()
  1019         -**      sqliteBtreeUpdateMeta()
         1013  +**      sqlite3BtreeCreateTable()
         1014  +**      sqlite3BtreeCreateIndex()
         1015  +**      sqlite3BtreeClearTable()
         1016  +**      sqlite3BtreeDropTable()
         1017  +**      sqlite3BtreeInsert()
         1018  +**      sqlite3BtreeDelete()
         1019  +**      sqlite3BtreeUpdateMeta()
  1020   1020   */
  1021   1021   int sqlite3BtreeBeginTrans(Btree *pBt){
  1022   1022     int rc;
  1023   1023     if( pBt->inTrans ) return SQLITE_ERROR;
  1024   1024     if( pBt->readOnly ) return SQLITE_READONLY;
  1025   1025     if( pBt->pPage1==0 ){
  1026   1026       rc = lockBtree(pBt);
................................................................................
  1184   1184   ** writing to that table.  This is a kind of "read-lock".  When a cursor
  1185   1185   ** is opened with wrFlag==0 it is guaranteed that the table will not
  1186   1186   ** change as long as the cursor is open.  This allows the cursor to
  1187   1187   ** do a sequential scan of the table without having to worry about
  1188   1188   ** entries being inserted or deleted during the scan.  Cursors should
  1189   1189   ** be opened with wrFlag==0 only if this read-lock property is needed.
  1190   1190   ** That is to say, cursors should be opened with wrFlag==0 only if they
  1191         -** intend to use the sqliteBtreeNext() system call.  All other cursors
         1191  +** intend to use the sqlite3BtreeNext() system call.  All other cursors
  1192   1192   ** should be opened with wrFlag==1 even if they never really intend
  1193   1193   ** to write.
  1194   1194   ** 
  1195   1195   ** No checking is done to make sure that page iTable really is the
  1196   1196   ** root page of a b-tree.  If it is not, then the cursor acquired
  1197   1197   ** will not work correctly.
  1198   1198   **
................................................................................
  2949   2949       assert( pPage->leaf );
  2950   2950       pCur->idx++;
  2951   2951     }else{
  2952   2952       assert( pPage->leaf );
  2953   2953     }
  2954   2954     insertCell(pPage, pCur->idx, &newCell, szNew);
  2955   2955     rc = balance(pPage);
  2956         -  /* sqliteBtreePageDump(pCur->pBt, pCur->pgnoRoot, 1); */
         2956  +  /* sqlite3BtreePageDump(pCur->pBt, pCur->pgnoRoot, 1); */
  2957   2957     /* fflush(stdout); */
  2958   2958     moveToRoot(pCur);
  2959   2959     pCur->eSkip = SKIP_INVALID;
  2960   2960     return rc;
  2961   2961   }
  2962   2962   
  2963   2963   /*
................................................................................
  3157   3157     }
  3158   3158     releasePage(pPage);
  3159   3159     return rc;  
  3160   3160   }
  3161   3161   
  3162   3162   
  3163   3163   /*
  3164         -** Read the meta-information out of a database file.
         3164  +** Read the meta-information out of a database file.  Meta[0]
         3165  +** is the number of free pages currently in the database.  Meta[1]
         3166  +** through meta[15] are available for use by higher layers.
  3165   3167   */
  3166   3168   int sqlite3BtreeGetMeta(Btree *pBt, int idx, u32 *pMeta){
  3167   3169     int rc;
  3168   3170     int i;
  3169   3171     unsigned char *pP1;
  3170   3172   
  3171         -  assert( idx>=0 && idx<15 );
         3173  +  assert( idx>=0 && idx<=15 );
  3172   3174     rc = sqlitepager_get(pBt->pPager, 1, (void**)&pP1);
  3173   3175     if( rc ) return rc;
  3174         -  *pMeta = get4byte(&pP1[40 + idx*4]);
         3176  +  *pMeta = get4byte(&pP1[36 + idx*4]);
  3175   3177     sqlitepager_unref(pP1);
  3176   3178     return SQLITE_OK;
  3177   3179   }
  3178   3180   
  3179   3181   /*
  3180         -** Write meta-information back into the database.
         3182  +** Write meta-information back into the database.  Meta[0] is
         3183  +** read-only and may not be written.
  3181   3184   */
  3182   3185   int sqlite3BtreeUpdateMeta(Btree *pBt, int idx, u32 iMeta){
  3183   3186     unsigned char *pP1;
  3184   3187     int rc, i;
  3185         -  assert( idx>=0 && idx<15 );
         3188  +  assert( idx>=1 && idx<=15 );
  3186   3189     if( !pBt->inTrans ){
  3187   3190       return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
  3188   3191     }
  3189   3192     rc = sqlitepager_get(pBt->pPager, 1, (void**)&pP1);
  3190   3193     if( rc ) return rc;
  3191   3194     rc = sqlitepager_write(pP1);
  3192   3195     if( rc ) return rc;
  3193         -  put4byte(&pP1[40 + idx*4], iMeta);
         3196  +  put4byte(&pP1[36 + idx*4], iMeta);
  3194   3197     return SQLITE_OK;
  3195   3198   }
  3196   3199   
  3197   3200   /******************************************************************************
  3198   3201   ** The complete implementation of the BTree subsystem is above this line.
  3199   3202   ** All the code the follows is for testing and troubleshooting the BTree
  3200   3203   ** subsystem.  None of the code that follows is used during normal operation.
................................................................................
  3201   3204   ******************************************************************************/
  3202   3205   
  3203   3206   /*
  3204   3207   ** Print a disassembly of the given page on standard output.  This routine
  3205   3208   ** is used for debugging and testing only.
  3206   3209   */
  3207   3210   #ifdef SQLITE_TEST
  3208         -static int fileBtreePageDump(Btree *pBt, int pgno, int recursive){
         3211  +int sqlite3BtreePageDump(Btree *pBt, int pgno, int recursive){
  3209   3212     int rc;
  3210   3213     MemPage *pPage;
  3211   3214     int i, j;
  3212   3215     int nFree;
  3213   3216     u16 idx;
  3214   3217     int hdrOffset;
  3215   3218     char range[20];

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.23 2003/04/13 18:26:52 paul Exp $
           16  +** $Id: test3.c,v 1.24 2004/05/04 17:27:28 drh Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "pager.h"
    20     20   #include "btree.h"
    21     21   #include "tcl.h"
    22     22   #include <stdlib.h>
    23     23   #include <string.h>
................................................................................
    45     45       case SQLITE_PROTOCOL:   zName = "SQLITE_PROTOCOL";    break;
    46     46       default:                zName = "SQLITE_Unknown";     break;
    47     47     }
    48     48     return zName;
    49     49   }
    50     50   
    51     51   /*
    52         -** Usage:   btree_open FILENAME
           52  +** Usage:   btree_open FILENAME NCACHE FLAGS
    53     53   **
    54     54   ** Open a new database
    55     55   */
    56     56   static int btree_open(
    57     57     void *NotUsed,
    58     58     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
    59     59     int argc,              /* Number of arguments */
    60     60     const char **argv      /* Text of each argument */
    61     61   ){
    62     62     Btree *pBt;
    63         -  int rc;
           63  +  int rc, nCache, flags;
    64     64     char zBuf[100];
    65         -  if( argc!=2 ){
           65  +  if( argc!=4 ){
    66     66       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    67         -       " FILENAME\"", 0);
           67  +       " FILENAME NCACHE FLAGS\"", 0);
    68     68       return TCL_ERROR;
    69     69     }
    70         -  rc = sqliteBtreeFactory(0, argv[1], 0, 1000, &pBt);
           70  +  if( Tcl_GetInt(interp, argv[2], &nCache) ) return TCL_ERROR;
           71  +  if( Tcl_GetInt(interp, argv[3], &flags) ) return TCL_ERROR;
           72  +  rc = sqlite3BtreeOpen(argv[1], &pBt, nCache, flags);
    71     73     if( rc!=SQLITE_OK ){
    72     74       Tcl_AppendResult(interp, errorName(rc), 0);
    73     75       return TCL_ERROR;
    74     76     }
    75     77     sprintf(zBuf,"%p", pBt);
    76     78     if( strncmp(zBuf,"0x",2) ){
    77     79       sprintf(zBuf, "0x%p", pBt);
................................................................................
    95     97     int rc;
    96     98     if( argc!=2 ){
    97     99       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
    98    100          " ID\"", 0);
    99    101       return TCL_ERROR;
   100    102     }
   101    103     if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
   102         -  rc = sqliteBtreeClose(pBt);
          104  +  rc = sqlite3BtreeClose(pBt);
   103    105     if( rc!=SQLITE_OK ){
   104    106       Tcl_AppendResult(interp, errorName(rc), 0);
   105    107       return TCL_ERROR;
   106    108     }
   107    109     return TCL_OK;
   108    110   }
   109    111   
................................................................................
   122    124     int rc;
   123    125     if( argc!=2 ){
   124    126       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   125    127          " ID\"", 0);
   126    128       return TCL_ERROR;
   127    129     }
   128    130     if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
   129         -  rc = sqliteBtreeBeginTrans(pBt);
          131  +  rc = sqlite3BtreeBeginTrans(pBt);
   130    132     if( rc!=SQLITE_OK ){
   131    133       Tcl_AppendResult(interp, errorName(rc), 0);
   132    134       return TCL_ERROR;
   133    135     }
   134    136     return TCL_OK;
   135    137   }
   136    138   
................................................................................
   149    151     int rc;
   150    152     if( argc!=2 ){
   151    153       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   152    154          " ID\"", 0);
   153    155       return TCL_ERROR;
   154    156     }
   155    157     if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
   156         -  rc = sqliteBtreeRollback(pBt);
          158  +  rc = sqlite3BtreeRollback(pBt);
   157    159     if( rc!=SQLITE_OK ){
   158    160       Tcl_AppendResult(interp, errorName(rc), 0);
   159    161       return TCL_ERROR;
   160    162     }
   161    163     return TCL_OK;
   162    164   }
   163    165   
................................................................................
   176    178     int rc;
   177    179     if( argc!=2 ){
   178    180       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   179    181          " ID\"", 0);
   180    182       return TCL_ERROR;
   181    183     }
   182    184     if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
   183         -  rc = sqliteBtreeCommit(pBt);
          185  +  rc = sqlite3BtreeCommit(pBt);
   184    186     if( rc!=SQLITE_OK ){
   185    187       Tcl_AppendResult(interp, errorName(rc), 0);
   186    188       return TCL_ERROR;
   187    189     }
   188    190     return TCL_OK;
   189    191   }
   190    192   
   191    193   /*
   192         -** Usage:   btree_create_table ID
          194  +** Usage:   btree_create_table ID FLAGS
   193    195   **
   194    196   ** Create a new table in the database
   195    197   */
   196    198   static int btree_create_table(
   197    199     void *NotUsed,
   198    200     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   199    201     int argc,              /* Number of arguments */
   200    202     const char **argv      /* Text of each argument */
   201    203   ){
   202    204     Btree *pBt;
   203         -  int rc, iTable;
          205  +  int rc, iTable, flags;
   204    206     char zBuf[30];
   205         -  if( argc!=2 ){
          207  +  if( argc!=3 ){
   206    208       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   207         -       " ID\"", 0);
          209  +       " ID FLAGS\"", 0);
   208    210       return TCL_ERROR;
   209    211     }
   210    212     if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
   211         -  rc = sqliteBtreeCreateTable(pBt, &iTable);
          213  +  if( Tcl_GetInt(interp, argv[2], &flags) ) return TCL_ERROR;
          214  +  rc = sqlite3BtreeCreateTable(pBt, &iTable, flags);
   212    215     if( rc!=SQLITE_OK ){
   213    216       Tcl_AppendResult(interp, errorName(rc), 0);
   214    217       return TCL_ERROR;
   215    218     }
   216    219     sprintf(zBuf, "%d", iTable);
   217    220     Tcl_AppendResult(interp, zBuf, 0);
   218    221     return TCL_OK;
................................................................................
   235    238     if( argc!=3 ){
   236    239       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   237    240          " ID TABLENUM\"", 0);
   238    241       return TCL_ERROR;
   239    242     }
   240    243     if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
   241    244     if( Tcl_GetInt(interp, argv[2], &iTable) ) return TCL_ERROR;
   242         -  rc = sqliteBtreeDropTable(pBt, iTable);
          245  +  rc = sqlite3BtreeDropTable(pBt, iTable);
   243    246     if( rc!=SQLITE_OK ){
   244    247       Tcl_AppendResult(interp, errorName(rc), 0);
   245    248       return TCL_ERROR;
   246    249     }
   247    250     return TCL_OK;
   248    251   }
   249    252   
................................................................................
   264    267     if( argc!=3 ){
   265    268       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   266    269          " ID TABLENUM\"", 0);
   267    270       return TCL_ERROR;
   268    271     }
   269    272     if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
   270    273     if( Tcl_GetInt(interp, argv[2], &iTable) ) return TCL_ERROR;
   271         -  rc = sqliteBtreeClearTable(pBt, iTable);
          274  +  rc = sqlite3BtreeClearTable(pBt, iTable);
   272    275     if( rc!=SQLITE_OK ){
   273    276       Tcl_AppendResult(interp, errorName(rc), 0);
   274    277       return TCL_ERROR;
   275    278     }
   276    279     return TCL_OK;
   277    280   }
          281  +
          282  +#define SQLITE_N_BTREE_META 16
   278    283   
   279    284   /*
   280    285   ** Usage:   btree_get_meta ID
   281    286   **
   282    287   ** Return meta data
   283    288   */
   284    289   static int btree_get_meta(
................................................................................
   286    291     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   287    292     int argc,              /* Number of arguments */
   288    293     const char **argv      /* Text of each argument */
   289    294   ){
   290    295     Btree *pBt;
   291    296     int rc;
   292    297     int i;
   293         -  int aMeta[SQLITE_N_BTREE_META];
   294    298     if( argc!=2 ){
   295    299       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   296    300          " ID\"", 0);
   297    301       return TCL_ERROR;
   298    302     }
   299    303     if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
   300         -  rc = sqliteBtreeGetMeta(pBt, aMeta);
   301         -  if( rc!=SQLITE_OK ){
   302         -    Tcl_AppendResult(interp, errorName(rc), 0);
   303         -    return TCL_ERROR;
   304         -  }
   305    304     for(i=0; i<SQLITE_N_BTREE_META; i++){
   306    305       char zBuf[30];
   307         -    sprintf(zBuf,"%d",aMeta[i]);
          306  +    unsigned int v;
          307  +    rc = sqlite3BtreeGetMeta(pBt, i, &v);
          308  +    if( rc!=SQLITE_OK ){
          309  +      Tcl_AppendResult(interp, errorName(rc), 0);
          310  +      return TCL_ERROR;
          311  +    }
          312  +    sprintf(zBuf,"%d",v);
   308    313       Tcl_AppendElement(interp, zBuf);
   309    314     }
   310    315     return TCL_OK;
   311    316   }
   312    317   
   313    318   /*
   314    319   ** Usage:   btree_update_meta ID METADATA...
................................................................................
   320    325     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   321    326     int argc,              /* Number of arguments */
   322    327     const char **argv      /* Text of each argument */
   323    328   ){
   324    329     Btree *pBt;
   325    330     int rc;
   326    331     int i;
   327         -  int aMeta[SQLITE_N_BTREE_META];
          332  +  int aMeta[SQLITE_N_BTREE_META-1];
   328    333   
   329    334     if( argc!=2+SQLITE_N_BTREE_META ){
   330    335       char zBuf[30];
   331    336       sprintf(zBuf,"%d",SQLITE_N_BTREE_META);
   332    337       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   333    338          " ID METADATA...\" (METADATA is ", zBuf, " integers)", 0);
   334    339       return TCL_ERROR;
   335    340     }
   336    341     if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
   337         -  for(i=0; i<SQLITE_N_BTREE_META; i++){
          342  +  for(i=0; i<SQLITE_N_BTREE_META-1; i++){
   338    343       if( Tcl_GetInt(interp, argv[i+2], &aMeta[i]) ) return TCL_ERROR;
   339    344     }
   340         -  rc = sqliteBtreeUpdateMeta(pBt, aMeta);
   341         -  if( rc!=SQLITE_OK ){
   342         -    Tcl_AppendResult(interp, errorName(rc), 0);
   343         -    return TCL_ERROR;
          345  +  for(i=0; i<SQLITE_N_BTREE_META-1; i++){
          346  +    rc = sqlite3BtreeUpdateMeta(pBt, i+1, aMeta[i]);
          347  +    if( rc!=SQLITE_OK ){
          348  +      Tcl_AppendResult(interp, errorName(rc), 0);
          349  +      return TCL_ERROR;
          350  +    }
   344    351     }
   345    352     return TCL_OK;
   346    353   }
   347    354   
   348    355   /*
   349    356   ** Usage:   btree_page_dump ID PAGENUM
   350    357   **
................................................................................
   363    370     if( argc!=3 ){
   364    371       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   365    372          " ID\"", 0);
   366    373       return TCL_ERROR;
   367    374     }
   368    375     if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
   369    376     if( Tcl_GetInt(interp, argv[2], &iPage) ) return TCL_ERROR;
   370         -  rc = sqliteBtreePageDump(pBt, iPage, 0);
          377  +  rc = sqlite3BtreePageDump(pBt, iPage, 0);
   371    378     if( rc!=SQLITE_OK ){
   372    379       Tcl_AppendResult(interp, errorName(rc), 0);
   373    380       return TCL_ERROR;
   374    381     }
   375    382     return TCL_OK;
   376    383   }
   377    384   
................................................................................
   393    400     if( argc!=3 ){
   394    401       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   395    402          " ID\"", 0);
   396    403       return TCL_ERROR;
   397    404     }
   398    405     if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
   399    406     if( Tcl_GetInt(interp, argv[2], &iPage) ) return TCL_ERROR;
   400         -  rc = sqliteBtreePageDump(pBt, iPage, 1);
          407  +  rc = sqlite3BtreePageDump(pBt, iPage, 1);
   401    408     if( rc!=SQLITE_OK ){
   402    409       Tcl_AppendResult(interp, errorName(rc), 0);
   403    410       return TCL_ERROR;
   404    411     }
   405    412     return TCL_OK;
   406    413   }
   407    414   
................................................................................
   422    429   
   423    430     if( argc!=2 ){
   424    431       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   425    432          " ID\"", 0);
   426    433       return TCL_ERROR;
   427    434     }
   428    435     if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
   429         -  a = sqlitepager_stats(sqliteBtreePager(pBt));
          436  +  a = sqlitepager_stats(sqlite3BtreePager(pBt));
   430    437     for(i=0; i<9; i++){
   431    438       static char *zName[] = {
   432    439         "ref", "page", "max", "size", "state", "err",
   433    440         "hit", "miss", "ovfl",
   434    441       };
   435    442       char zBuf[100];
   436    443       Tcl_AppendElement(interp, zName[i]);
................................................................................
   455    462   
   456    463     if( argc!=2 ){
   457    464       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   458    465          " ID\"", 0);
   459    466       return TCL_ERROR;
   460    467     }
   461    468     if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
   462         -  sqlitepager_refdump(sqliteBtreePager(pBt));
          469  +  sqlitepager_refdump(sqlite3BtreePager(pBt));
   463    470     return TCL_OK;
   464    471   }
   465    472   
   466    473   /*
   467    474   ** Usage:   btree_integrity_check ID ROOT ...
   468    475   **
   469    476   ** Look through every page of the given BTree file to verify correct
................................................................................
   489    496     }
   490    497     if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
   491    498     nRoot = argc-2;
   492    499     aRoot = malloc( sizeof(int)*(argc-2) );
   493    500     for(i=0; i<argc-2; i++){
   494    501       if( Tcl_GetInt(interp, argv[i+2], &aRoot[i]) ) return TCL_ERROR;
   495    502     }
   496         -  zResult = sqliteBtreeIntegrityCheck(pBt, aRoot, nRoot);
          503  +  zResult = sqlite3BtreeIntegrityCheck(pBt, aRoot, nRoot);
   497    504     if( zResult ){
   498    505       Tcl_AppendResult(interp, zResult, 0);
   499    506       sqliteFree(zResult); 
   500    507     }
   501    508     return TCL_OK;
   502    509   }
   503    510   
................................................................................
   523    530       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   524    531          " ID TABLENUM WRITEABLE\"", 0);
   525    532       return TCL_ERROR;
   526    533     }
   527    534     if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
   528    535     if( Tcl_GetInt(interp, argv[2], &iTable) ) return TCL_ERROR;
   529    536     if( Tcl_GetBoolean(interp, argv[3], &wrFlag) ) return TCL_ERROR;
   530         -  rc = sqliteBtreeCursor(pBt, iTable, wrFlag, &pCur);
          537  +  rc = sqlite3BtreeCursor(pBt, iTable, wrFlag, &pCur);
   531    538     if( rc ){
   532    539       Tcl_AppendResult(interp, errorName(rc), 0);
   533    540       return TCL_ERROR;
   534    541     }
   535    542     sprintf(zBuf,"0x%x", (int)pCur);
   536    543     Tcl_AppendResult(interp, zBuf, 0);
   537    544     return SQLITE_OK;
................................................................................
   553    560   
   554    561     if( argc!=2 ){
   555    562       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   556    563          " ID\"", 0);
   557    564       return TCL_ERROR;
   558    565     }
   559    566     if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
   560         -  rc = sqliteBtreeCloseCursor(pCur);
          567  +  rc = sqlite3BtreeCloseCursor(pCur);
   561    568     if( rc ){
   562    569       Tcl_AppendResult(interp, errorName(rc), 0);
   563    570       return TCL_ERROR;
   564    571     }
   565    572     return SQLITE_OK;
   566    573   }
   567    574   
................................................................................
   583    590   
   584    591     if( argc!=3 ){
   585    592       Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
   586    593          " ID KEY\"", 0);
   587    594       return TCL_ERROR;
   588    595     }
   589    596     if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
   590         -  rc = sqliteBtreeMoveto(pCur, argv[2], strlen(argv[2]), &res);  
          597  +  rc = sqlite3BtreeMoveto(pCur, argv[2], strlen(argv[2]), &res);  
   591    598     if( rc ){
   592    599       Tcl_AppendResult(interp, errorName(rc), 0);
   593    600       return TCL_ERROR;
   594    601     }
   595    602     if( res<0 ) res = -1;
   596    603     if( res>0 ) res = 1;
   597    604     sprintf(zBuf,"%d",res);