1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Update test3.c to work with the new btree.c API. (CVS 1314)

FossilOrigin-Name: bfb3234dc60c9152fdf0a16b887089365443f5ed
This commit is contained in:
drh
2004-05-04 17:27:28 +00:00
parent a5d14fe7c5
commit 23e11cab7d
4 changed files with 81 additions and 71 deletions

View File

@@ -1,5 +1,5 @@
C Added\stemplate\sfor\sthe\sutf.c\sfile\scontaining\sconversion\sroutines.\s(CVS\s1313)
D 2004-05-04T15:00:47
C Update\stest3.c\sto\swork\swith\sthe\snew\sbtree.c\sAPI.\s(CVS\s1314)
D 2004-05-04T17:27:28
F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -23,7 +23,7 @@ F sqlite.def fc4f5734786fe4743cfe2aa98eb2da4b089edb5f
F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
F src/attach.c b01db0d3211f673d8e670abf7eaad04591d40d14
F src/auth.c 4fa3b05bd19445d1c474d6751c4a508d6ea0abe1
F src/btree.c 4ec7a8e12bcc977361fca283e9cbb6bc02f34325
F src/btree.c 54f5f2d0004ca0a2c36d863632f6b5a84fd04095
F src/btree.h 858659c6605ae07a2a0fb3d176b25573d30f27c5
F src/btree_rb.c 99feb3ff835106d018a483a1ce403e5cf9c718bc
F src/build.c 76fbca30081decd6615dee34b48c927ed5063752
@@ -54,7 +54,7 @@ F src/table.c d845cb101b5afc1f7fea083c99e3d2fa7998d895
F src/tclsqlite.c e816201db3ea6ba857a0351547be1d4b7286e95d
F src/test1.c 9aa62b89d420e6763b5e7ae89a47f6cf87370477
F src/test2.c 9d611c45e1b07039a2bd95f5ea73178362b23229
F src/test3.c 30985ebdfaf3ee1462a9b0652d3efbdc8d9798f5
F src/test3.c 7d06add423e4a90ec1a2e8d02006f82081109558
F src/test4.c 6e3e31acfaf21d66420fc35fda5b17dc0000cc8d
F src/tokenize.c 6676b946fd8825b67ab52140af4fdc57a70bda48
F src/trigger.c a9927b57c865b6f3df3fb5e40c9824d722660ded
@@ -189,7 +189,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
P fdc629dbbf974024215969e0bd3def4597258812
R 862d1dd5fd20c7467c3bdf6faef3043d
P 89b42c468f437003f74a1785370e75b2585fa9e2
R a73f1cc52bfc16883d27a39f1dbd6caa
U drh
Z b159d386ddf509db1096e77212da2220
Z 27226ab3419af317804aa8669b342fd3

View File

@@ -1 +1 @@
89b42c468f437003f74a1785370e75b2585fa9e2
bfb3234dc60c9152fdf0a16b887089365443f5ed

View File

@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btree.c,v 1.108 2004/05/03 19:49:33 drh Exp $
** $Id: btree.c,v 1.109 2004/05/04 17:27:28 drh Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
@@ -266,15 +266,15 @@ struct BtCursor {
int idx; /* Index of the entry in pPage->aCell[] */
u8 wrFlag; /* True if writable */
u8 eSkip; /* Determines if next step operation is a no-op */
u8 iMatch; /* compare result from last sqliteBtreeMoveto() */
u8 iMatch; /* compare result from last sqlite3BtreeMoveto() */
};
/*
** Legal values for BtCursor.eSkip.
*/
#define SKIP_NONE 0 /* Always step the cursor */
#define SKIP_NEXT 1 /* The next sqliteBtreeNext() is a no-op */
#define SKIP_PREV 2 /* The next sqliteBtreePrevious() is a no-op */
#define SKIP_NEXT 1 /* The next sqlite3BtreeNext() is a no-op */
#define SKIP_PREV 2 /* The next sqlite3BtreePrevious() is a no-op */
#define SKIP_INVALID 3 /* Calls to Next() and Previous() are invalid */
/*
@@ -393,11 +393,11 @@ static void defragmentPage(MemPage *pPage){
int start, hdr, size;
int leftover;
unsigned char *oldPage;
unsigned char newPage[SQLITE_PAGE_SIZE];
unsigned char newPage[MX_PAGE_SIZE];
assert( sqlitepager_iswriteable(pPage->aData) );
assert( pPage->pBt!=0 );
assert( pPage->pageSize <= SQLITE_PAGE_SIZE );
assert( pPage->pageSize <= MX_PAGE_SIZE );
oldPage = pPage->aData;
hdr = pPage->hdrOffset;
addr = 3+hdr;
@@ -829,9 +829,9 @@ static void pageDestructor(void *pData){
**
** zFilename is the name of the database file. If zFilename is NULL
** a new database with a random name is created. This randomly named
** database file will be deleted when sqliteBtreeClose() is called.
** database file will be deleted when sqlite3BtreeClose() is called.
*/
int sqliteBtreeOpen(
int sqlite3BtreeOpen(
const char *zFilename, /* Name of the file containing the BTree database */
Btree **ppBtree, /* Pointer to new Btree object written here */
int nCache, /* Number of cache pages */
@@ -905,7 +905,7 @@ int sqlite3BtreeClose(Btree *pBt){
** Synchronous is on by default so database corruption is not
** normally a worry.
*/
int sqilte3BtreeSetCacheSize(Btree *pBt, int mxPage){
int sqlite3BtreeSetCacheSize(Btree *pBt, int mxPage){
sqlitepager_set_cachesize(pBt->pPager, mxPage);
return SQLITE_OK;
}
@@ -1010,13 +1010,13 @@ static int newDatabase(Btree *pBt){
** to the database. None of the following routines will work
** unless a transaction is started first:
**
** sqliteBtreeCreateTable()
** sqliteBtreeCreateIndex()
** sqliteBtreeClearTable()
** sqliteBtreeDropTable()
** sqliteBtreeInsert()
** sqliteBtreeDelete()
** sqliteBtreeUpdateMeta()
** sqlite3BtreeCreateTable()
** sqlite3BtreeCreateIndex()
** sqlite3BtreeClearTable()
** sqlite3BtreeDropTable()
** sqlite3BtreeInsert()
** sqlite3BtreeDelete()
** sqlite3BtreeUpdateMeta()
*/
int sqlite3BtreeBeginTrans(Btree *pBt){
int rc;
@@ -1188,7 +1188,7 @@ static int dfltCompare(
** entries being inserted or deleted during the scan. Cursors should
** be opened with wrFlag==0 only if this read-lock property is needed.
** That is to say, cursors should be opened with wrFlag==0 only if they
** intend to use the sqliteBtreeNext() system call. All other cursors
** intend to use the sqlite3BtreeNext() system call. All other cursors
** should be opened with wrFlag==1 even if they never really intend
** to write.
**
@@ -2953,7 +2953,7 @@ int sqlite3BtreeInsert(
}
insertCell(pPage, pCur->idx, &newCell, szNew);
rc = balance(pPage);
/* sqliteBtreePageDump(pCur->pBt, pCur->pgnoRoot, 1); */
/* sqlite3BtreePageDump(pCur->pBt, pCur->pgnoRoot, 1); */
/* fflush(stdout); */
moveToRoot(pCur);
pCur->eSkip = SKIP_INVALID;
@@ -3161,28 +3161,31 @@ int sqlite3BtreeDropTable(Btree *pBt, int iTable){
/*
** Read the meta-information out of a database file.
** Read the meta-information out of a database file. Meta[0]
** is the number of free pages currently in the database. Meta[1]
** through meta[15] are available for use by higher layers.
*/
int sqlite3BtreeGetMeta(Btree *pBt, int idx, u32 *pMeta){
int rc;
int i;
unsigned char *pP1;
assert( idx>=0 && idx<15 );
assert( idx>=0 && idx<=15 );
rc = sqlitepager_get(pBt->pPager, 1, (void**)&pP1);
if( rc ) return rc;
*pMeta = get4byte(&pP1[40 + idx*4]);
*pMeta = get4byte(&pP1[36 + idx*4]);
sqlitepager_unref(pP1);
return SQLITE_OK;
}
/*
** Write meta-information back into the database.
** Write meta-information back into the database. Meta[0] is
** read-only and may not be written.
*/
int sqlite3BtreeUpdateMeta(Btree *pBt, int idx, u32 iMeta){
unsigned char *pP1;
int rc, i;
assert( idx>=0 && idx<15 );
assert( idx>=1 && idx<=15 );
if( !pBt->inTrans ){
return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
}
@@ -3190,7 +3193,7 @@ int sqlite3BtreeUpdateMeta(Btree *pBt, int idx, u32 iMeta){
if( rc ) return rc;
rc = sqlitepager_write(pP1);
if( rc ) return rc;
put4byte(&pP1[40 + idx*4], iMeta);
put4byte(&pP1[36 + idx*4], iMeta);
return SQLITE_OK;
}
@@ -3205,7 +3208,7 @@ int sqlite3BtreeUpdateMeta(Btree *pBt, int idx, u32 iMeta){
** is used for debugging and testing only.
*/
#ifdef SQLITE_TEST
static int fileBtreePageDump(Btree *pBt, int pgno, int recursive){
int sqlite3BtreePageDump(Btree *pBt, int pgno, int recursive){
int rc;
MemPage *pPage;
int i, j;

View File

@@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test3.c,v 1.23 2003/04/13 18:26:52 paul Exp $
** $Id: test3.c,v 1.24 2004/05/04 17:27:28 drh Exp $
*/
#include "sqliteInt.h"
#include "pager.h"
@@ -49,7 +49,7 @@ static char *errorName(int rc){
}
/*
** Usage: btree_open FILENAME
** Usage: btree_open FILENAME NCACHE FLAGS
**
** Open a new database
*/
@@ -60,14 +60,16 @@ static int btree_open(
const char **argv /* Text of each argument */
){
Btree *pBt;
int rc;
int rc, nCache, flags;
char zBuf[100];
if( argc!=2 ){
if( argc!=4 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" FILENAME\"", 0);
" FILENAME NCACHE FLAGS\"", 0);
return TCL_ERROR;
}
rc = sqliteBtreeFactory(0, argv[1], 0, 1000, &pBt);
if( Tcl_GetInt(interp, argv[2], &nCache) ) return TCL_ERROR;
if( Tcl_GetInt(interp, argv[3], &flags) ) return TCL_ERROR;
rc = sqlite3BtreeOpen(argv[1], &pBt, nCache, flags);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
@@ -99,7 +101,7 @@ static int btree_close(
return TCL_ERROR;
}
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
rc = sqliteBtreeClose(pBt);
rc = sqlite3BtreeClose(pBt);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
@@ -126,7 +128,7 @@ static int btree_begin_transaction(
return TCL_ERROR;
}
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
rc = sqliteBtreeBeginTrans(pBt);
rc = sqlite3BtreeBeginTrans(pBt);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
@@ -153,7 +155,7 @@ static int btree_rollback(
return TCL_ERROR;
}
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
rc = sqliteBtreeRollback(pBt);
rc = sqlite3BtreeRollback(pBt);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
@@ -180,7 +182,7 @@ static int btree_commit(
return TCL_ERROR;
}
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
rc = sqliteBtreeCommit(pBt);
rc = sqlite3BtreeCommit(pBt);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
@@ -189,7 +191,7 @@ static int btree_commit(
}
/*
** Usage: btree_create_table ID
** Usage: btree_create_table ID FLAGS
**
** Create a new table in the database
*/
@@ -200,15 +202,16 @@ static int btree_create_table(
const char **argv /* Text of each argument */
){
Btree *pBt;
int rc, iTable;
int rc, iTable, flags;
char zBuf[30];
if( argc!=2 ){
if( argc!=3 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" ID\"", 0);
" ID FLAGS\"", 0);
return TCL_ERROR;
}
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
rc = sqliteBtreeCreateTable(pBt, &iTable);
if( Tcl_GetInt(interp, argv[2], &flags) ) return TCL_ERROR;
rc = sqlite3BtreeCreateTable(pBt, &iTable, flags);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
@@ -239,7 +242,7 @@ static int btree_drop_table(
}
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
if( Tcl_GetInt(interp, argv[2], &iTable) ) return TCL_ERROR;
rc = sqliteBtreeDropTable(pBt, iTable);
rc = sqlite3BtreeDropTable(pBt, iTable);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
@@ -268,7 +271,7 @@ static int btree_clear_table(
}
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
if( Tcl_GetInt(interp, argv[2], &iTable) ) return TCL_ERROR;
rc = sqliteBtreeClearTable(pBt, iTable);
rc = sqlite3BtreeClearTable(pBt, iTable);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
@@ -276,6 +279,8 @@ static int btree_clear_table(
return TCL_OK;
}
#define SQLITE_N_BTREE_META 16
/*
** Usage: btree_get_meta ID
**
@@ -290,21 +295,21 @@ static int btree_get_meta(
Btree *pBt;
int rc;
int i;
int aMeta[SQLITE_N_BTREE_META];
if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" ID\"", 0);
return TCL_ERROR;
}
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
rc = sqliteBtreeGetMeta(pBt, aMeta);
for(i=0; i<SQLITE_N_BTREE_META; i++){
char zBuf[30];
unsigned int v;
rc = sqlite3BtreeGetMeta(pBt, i, &v);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
}
for(i=0; i<SQLITE_N_BTREE_META; i++){
char zBuf[30];
sprintf(zBuf,"%d",aMeta[i]);
sprintf(zBuf,"%d",v);
Tcl_AppendElement(interp, zBuf);
}
return TCL_OK;
@@ -324,7 +329,7 @@ static int btree_update_meta(
Btree *pBt;
int rc;
int i;
int aMeta[SQLITE_N_BTREE_META];
int aMeta[SQLITE_N_BTREE_META-1];
if( argc!=2+SQLITE_N_BTREE_META ){
char zBuf[30];
@@ -334,14 +339,16 @@ static int btree_update_meta(
return TCL_ERROR;
}
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
for(i=0; i<SQLITE_N_BTREE_META; i++){
for(i=0; i<SQLITE_N_BTREE_META-1; i++){
if( Tcl_GetInt(interp, argv[i+2], &aMeta[i]) ) return TCL_ERROR;
}
rc = sqliteBtreeUpdateMeta(pBt, aMeta);
for(i=0; i<SQLITE_N_BTREE_META-1; i++){
rc = sqlite3BtreeUpdateMeta(pBt, i+1, aMeta[i]);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
}
}
return TCL_OK;
}
@@ -367,7 +374,7 @@ static int btree_page_dump(
}
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
if( Tcl_GetInt(interp, argv[2], &iPage) ) return TCL_ERROR;
rc = sqliteBtreePageDump(pBt, iPage, 0);
rc = sqlite3BtreePageDump(pBt, iPage, 0);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
@@ -397,7 +404,7 @@ static int btree_tree_dump(
}
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
if( Tcl_GetInt(interp, argv[2], &iPage) ) return TCL_ERROR;
rc = sqliteBtreePageDump(pBt, iPage, 1);
rc = sqlite3BtreePageDump(pBt, iPage, 1);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
@@ -426,7 +433,7 @@ static int btree_pager_stats(
return TCL_ERROR;
}
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
a = sqlitepager_stats(sqliteBtreePager(pBt));
a = sqlitepager_stats(sqlite3BtreePager(pBt));
for(i=0; i<9; i++){
static char *zName[] = {
"ref", "page", "max", "size", "state", "err",
@@ -459,7 +466,7 @@ static int btree_pager_ref_dump(
return TCL_ERROR;
}
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
sqlitepager_refdump(sqliteBtreePager(pBt));
sqlitepager_refdump(sqlite3BtreePager(pBt));
return TCL_OK;
}
@@ -493,7 +500,7 @@ static int btree_integrity_check(
for(i=0; i<argc-2; i++){
if( Tcl_GetInt(interp, argv[i+2], &aRoot[i]) ) return TCL_ERROR;
}
zResult = sqliteBtreeIntegrityCheck(pBt, aRoot, nRoot);
zResult = sqlite3BtreeIntegrityCheck(pBt, aRoot, nRoot);
if( zResult ){
Tcl_AppendResult(interp, zResult, 0);
sqliteFree(zResult);
@@ -527,7 +534,7 @@ static int btree_cursor(
if( Tcl_GetInt(interp, argv[1], (int*)&pBt) ) return TCL_ERROR;
if( Tcl_GetInt(interp, argv[2], &iTable) ) return TCL_ERROR;
if( Tcl_GetBoolean(interp, argv[3], &wrFlag) ) return TCL_ERROR;
rc = sqliteBtreeCursor(pBt, iTable, wrFlag, &pCur);
rc = sqlite3BtreeCursor(pBt, iTable, wrFlag, &pCur);
if( rc ){
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
@@ -557,7 +564,7 @@ static int btree_close_cursor(
return TCL_ERROR;
}
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
rc = sqliteBtreeCloseCursor(pCur);
rc = sqlite3BtreeCloseCursor(pCur);
if( rc ){
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;
@@ -587,7 +594,7 @@ static int btree_move_to(
return TCL_ERROR;
}
if( Tcl_GetInt(interp, argv[1], (int*)&pCur) ) return TCL_ERROR;
rc = sqliteBtreeMoveto(pCur, argv[2], strlen(argv[2]), &res);
rc = sqlite3BtreeMoveto(pCur, argv[2], strlen(argv[2]), &res);
if( rc ){
Tcl_AppendResult(interp, errorName(rc), 0);
return TCL_ERROR;