diff --git a/manifest b/manifest index a7e02bb3d3..69ed628e2a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Get\striggers\sworking\son\stables\swith\sINTEGER\sPRIMARY\sKEYs.\s\sTicket\s#291.\nThis\smay\salso\sfix\s#159.\s\sStill\sneed\sto\sadd\stests\sso\sboth\sbugs\sremain\sopen\nfor\sthe\stime\sbeing.\s(CVS\s908) -D 2003-04-15T19:22:23 +C Remove\ssome\sunnecessary\scode\sand\scomplication\sfrom\sthe\sbtree\sinterface.\s(CVS\s909) +D 2003-04-16T01:28:16 F Makefile.in df3a4db41a7450468b5fe934d9dd8f723b631249 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -21,9 +21,9 @@ F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2 F src/attach.c 7ebc7487de43e357a64226f8abef81f2669f2183 F src/auth.c f37bfc9451b8c1fa52f34adff474560018892729 -F src/btree.c 9949031b6087e9d1b43b359b84c68a491086984f -F src/btree.h 5cb871546bd6fa58396a6f033e2b29b388241e1b -F src/btree_rb.c c917cdcc401df1075b257a96e8a1e3e46a506805 +F src/btree.c b9487cceb9ea78af9cbae9def34114902f511736 +F src/btree.h 529c98cb0715c62214544fbbe50b946f99a85540 +F src/btree_rb.c 7fa4901a65de66522ce31985833f20b98f7baad4 F src/build.c daed1dacdb70e5d4def9df2e34a1cabeeb8467c9 F src/copy.c 8699e571994934c78f70761a1458d7b9e9e75073 F src/delete.c 6021fd293a78ebeb35e8177bd811d752fe090f89 @@ -33,7 +33,7 @@ F src/func.c 882c3ed5a02be18cd904715c7ec62947a34a3605 F src/hash.c 4fc39feb7b7711f6495ee9f2159559bedb043e1f F src/hash.h cd0433998bc1a3759d244e1637fe5a3c13b53bf8 F src/insert.c 45d27e3e8447bff4025db2f0dc3bb4e318e602f4 -F src/main.c daf5b7c256340fb9aa77df7254865218a47d5a63 +F src/main.c 9b3e2e1e12d8ab950c1b99fc3805f69018a6e751 F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565 F src/os.c c33ebb320921b8df6d09ea19fe846348df86a0c9 F src/os.h aa52f0c9da321ff6134d19f2ca959e18e33615d0 @@ -162,7 +162,7 @@ F www/speed.tcl cb4c10a722614aea76d2c51f32ee43400d5951be F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218 -P 93eb6c52aca8de15a88247ec986c36245527ec7b -R 97b4c68da27841d236c7d5fe42a0a220 +P 0b996959b8d8bc2c82eab9cccc190befd0056505 +R 9b9a6e33d11cf491ef2a5576ee3b5a64 U drh -Z 2af580d6307d67cd3da5d48cc8031613 +Z ff418746ff7b6d08e8d28734401a85c5 diff --git a/manifest.uuid b/manifest.uuid index 9cd5dc56c6..78eff36361 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0b996959b8d8bc2c82eab9cccc190befd0056505 \ No newline at end of file +35cc7c7d37d9ca486e7f300efe80a78a7f1064e2 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index dca1be3746..d308d2c7a2 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.88 2003/04/13 18:26:51 paul Exp $ +** $Id: btree.c,v 1.89 2003/04/16 01:28:16 drh Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** For a detailed discussion of BTrees, refer to @@ -49,13 +49,6 @@ ** BTree begins on page 2 of the file. (Pages are numbered beginning with ** 1, not 0.) Thus a minimum database contains 2 pages. */ - -/* We don't want the btree function macros as they clash with the functions -** defined in this file. This may be fixed in future by renaming the macros -** or the functions defined here, or both. -*/ -#define SQLITE_NO_BTREE_DEFS - #include "sqliteInt.h" #include "pager.h" #include "btree.h" @@ -389,7 +382,7 @@ struct BtCursor { #define SKIP_INVALID 3 /* Calls to Next() and Previous() are invalid */ /* Forward declarations */ -static int sqliteBtreeCloseCursor(BtCursor *pCur); +static int fileBtreeCloseCursor(BtCursor *pCur); /* ** Routines for byte swapping. @@ -733,9 +726,9 @@ int sqliteBtreeOpen( /* ** Close an open database and invalidate all cursors. */ -static int sqliteBtreeClose(Btree *pBt){ +static int fileBtreeClose(Btree *pBt){ while( pBt->pCursor ){ - sqliteBtreeCloseCursor(pBt->pCursor); + fileBtreeCloseCursor(pBt->pCursor); } sqlitepager_close(pBt->pPager); sqliteFree(pBt); @@ -757,7 +750,7 @@ static int sqliteBtreeClose(Btree *pBt){ ** Synchronous is on by default so database corruption is not ** normally a worry. */ -static int sqliteBtreeSetCacheSize(Btree *pBt, int mxPage){ +static int fileBtreeSetCacheSize(Btree *pBt, int mxPage){ sqlitepager_set_cachesize(pBt->pPager, mxPage); return SQLITE_OK; } @@ -770,7 +763,7 @@ static int sqliteBtreeSetCacheSize(Btree *pBt, int mxPage){ ** is a very low but non-zero probability of damage. Level 3 reduces the ** probability of damage to near zero but with a write performance reduction. */ -static int sqliteBtreeSetSafetyLevel(Btree *pBt, int level){ +static int fileBtreeSetSafetyLevel(Btree *pBt, int level){ sqlitepager_set_safety_level(pBt->pPager, level); return SQLITE_OK; } @@ -877,7 +870,7 @@ static int newDatabase(Btree *pBt){ ** sqliteBtreeDelete() ** sqliteBtreeUpdateMeta() */ -static int sqliteBtreeBeginTrans(Btree *pBt){ +static int fileBtreeBeginTrans(Btree *pBt){ int rc; if( pBt->inTrans ) return SQLITE_ERROR; if( pBt->readOnly ) return SQLITE_READONLY; @@ -906,7 +899,7 @@ static int sqliteBtreeBeginTrans(Btree *pBt){ ** This will release the write lock on the database file. If there ** are no active cursors, it also releases the read lock. */ -static int sqliteBtreeCommit(Btree *pBt){ +static int fileBtreeCommit(Btree *pBt){ int rc; rc = pBt->readOnly ? SQLITE_OK : sqlitepager_commit(pBt->pPager); pBt->inTrans = 0; @@ -924,7 +917,7 @@ static int sqliteBtreeCommit(Btree *pBt){ ** This will release the write lock on the database file. If there ** are no active cursors, it also releases the read lock. */ -static int sqliteBtreeRollback(Btree *pBt){ +static int fileBtreeRollback(Btree *pBt){ int rc; BtCursor *pCur; if( pBt->inTrans==0 ) return SQLITE_OK; @@ -951,7 +944,7 @@ static int sqliteBtreeRollback(Btree *pBt){ ** Only one checkpoint may be active at a time. It is an error to try ** to start a new checkpoint if another checkpoint is already active. */ -static int sqliteBtreeBeginCkpt(Btree *pBt){ +static int fileBtreeBeginCkpt(Btree *pBt){ int rc; if( !pBt->inTrans || pBt->inCkpt ){ return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR; @@ -966,7 +959,7 @@ static int sqliteBtreeBeginCkpt(Btree *pBt){ ** Commit a checkpoint to transaction currently in progress. If no ** checkpoint is active, this is a no-op. */ -static int sqliteBtreeCommitCkpt(Btree *pBt){ +static int fileBtreeCommitCkpt(Btree *pBt){ int rc; if( pBt->inCkpt && !pBt->readOnly ){ rc = sqlitepager_ckpt_commit(pBt->pPager); @@ -985,7 +978,7 @@ static int sqliteBtreeCommitCkpt(Btree *pBt){ ** to use a cursor that was open at the beginning of this operation ** will result in an error. */ -static int sqliteBtreeRollbackCkpt(Btree *pBt){ +static int fileBtreeRollbackCkpt(Btree *pBt){ int rc; BtCursor *pCur; if( pBt->inCkpt==0 || pBt->readOnly ) return SQLITE_OK; @@ -1036,7 +1029,7 @@ static int sqliteBtreeRollbackCkpt(Btree *pBt){ ** root page of a b-tree. If it is not, then the cursor acquired ** will not work correctly. */ -static int sqliteBtreeCursor(Btree *pBt, int iTable, int wrFlag, BtCursor **ppCur){ +static int fileBtreeCursor(Btree *pBt, int iTable, int wrFlag, BtCursor **ppCur){ int rc; BtCursor *pCur, *pRing; @@ -1097,7 +1090,7 @@ create_cursor_exception: ** Close a cursor. The read lock on the database file is released ** when the last cursor is closed. */ -static int sqliteBtreeCloseCursor(BtCursor *pCur){ +static int fileBtreeCloseCursor(BtCursor *pCur){ Btree *pBt = pCur->pBt; if( pCur->pPrev ){ pCur->pPrev->pNext = pCur->pNext; @@ -1150,7 +1143,7 @@ static void releaseTempCursor(BtCursor *pCur){ ** pointing to an entry (which can happen, for example, if ** the database is empty) then *pSize is set to 0. */ -static int sqliteBtreeKeySize(BtCursor *pCur, int *pSize){ +static int fileBtreeKeySize(BtCursor *pCur, int *pSize){ Cell *pCell; MemPage *pPage; @@ -1239,7 +1232,7 @@ static int getPayload(BtCursor *pCur, int offset, int amt, char *zBuf){ ** is raised. The change was made in an effort to boost performance ** by eliminating unneeded tests. */ -static int sqliteBtreeKey(BtCursor *pCur, int offset, int amt, char *zBuf){ +static int fileBtreeKey(BtCursor *pCur, int offset, int amt, char *zBuf){ MemPage *pPage; assert( amt>=0 ); @@ -1261,7 +1254,7 @@ static int sqliteBtreeKey(BtCursor *pCur, int offset, int amt, char *zBuf){ ** pointing to an entry (which can happen, for example, if ** the database is empty) then *pSize is set to 0. */ -static int sqliteBtreeDataSize(BtCursor *pCur, int *pSize){ +static int fileBtreeDataSize(BtCursor *pCur, int *pSize){ Cell *pCell; MemPage *pPage; @@ -1284,7 +1277,7 @@ static int sqliteBtreeDataSize(BtCursor *pCur, int *pSize){ ** amount requested if there are not enough bytes in the data ** to satisfy the request. */ -static int sqliteBtreeData(BtCursor *pCur, int offset, int amt, char *zBuf){ +static int fileBtreeData(BtCursor *pCur, int offset, int amt, char *zBuf){ Cell *pCell; MemPage *pPage; @@ -1322,7 +1315,7 @@ static int sqliteBtreeData(BtCursor *pCur, int offset, int amt, char *zBuf){ ** keys must be exactly the same length. (The length of the pCur key ** is the actual key length minus nIgnore bytes.) */ -static int sqliteBtreeKeyCompare( +static int fileBtreeKeyCompare( BtCursor *pCur, /* Pointer to entry to compare against */ const void *pKey, /* Key to compare against entry that pCur points to */ int nKey, /* Number of bytes in pKey */ @@ -1521,7 +1514,7 @@ static int moveToRightmost(BtCursor *pCur){ ** on success. Set *pRes to 0 if the cursor actually points to something ** or set *pRes to 1 if the table is empty. */ -static int sqliteBtreeFirst(BtCursor *pCur, int *pRes){ +static int fileBtreeFirst(BtCursor *pCur, int *pRes){ int rc; if( pCur->pPage==0 ) return SQLITE_ABORT; rc = moveToRoot(pCur); @@ -1540,7 +1533,7 @@ static int sqliteBtreeFirst(BtCursor *pCur, int *pRes){ ** on success. Set *pRes to 0 if the cursor actually points to something ** or set *pRes to 1 if the table is empty. */ -static int sqliteBtreeLast(BtCursor *pCur, int *pRes){ +static int fileBtreeLast(BtCursor *pCur, int *pRes){ int rc; if( pCur->pPage==0 ) return SQLITE_ABORT; rc = moveToRoot(pCur); @@ -1579,7 +1572,8 @@ static int sqliteBtreeLast(BtCursor *pCur, int *pRes){ ** *pRes>0 The cursor is left pointing at an entry that ** is larger than pKey. */ -static int sqliteBtreeMoveto(BtCursor *pCur, const void *pKey, int nKey, int *pRes){ +static +int fileBtreeMoveto(BtCursor *pCur, const void *pKey, int nKey, int *pRes){ int rc; if( pCur->pPage==0 ) return SQLITE_ABORT; pCur->eSkip = SKIP_NONE; @@ -1594,7 +1588,7 @@ static int sqliteBtreeMoveto(BtCursor *pCur, const void *pKey, int nKey, int *pR upr = pPage->nCell-1; while( lwr<=upr ){ pCur->idx = (lwr+upr)/2; - rc = sqliteBtreeKeyCompare(pCur, pKey, nKey, 0, &c); + rc = fileBtreeKeyCompare(pCur, pKey, nKey, 0, &c); if( rc ) return rc; if( c==0 ){ pCur->iMatch = c; @@ -1632,7 +1626,7 @@ static int sqliteBtreeMoveto(BtCursor *pCur, const void *pKey, int nKey, int *pR ** was already pointing to the last entry in the database before ** this routine was called, then set *pRes=1. */ -static int sqliteBtreeNext(BtCursor *pCur, int *pRes){ +static int fileBtreeNext(BtCursor *pCur, int *pRes){ int rc; MemPage *pPage = pCur->pPage; assert( pRes!=0 ); @@ -1687,7 +1681,7 @@ static int sqliteBtreeNext(BtCursor *pCur, int *pRes){ ** was already pointing to the first entry in the database before ** this routine was called, then set *pRes=1. */ -static int sqliteBtreePrevious(BtCursor *pCur, int *pRes){ +static int fileBtreePrevious(BtCursor *pCur, int *pRes){ int rc; Pgno pgno; MemPage *pPage; @@ -2613,7 +2607,7 @@ static int checkReadLocks(BtCursor *pCur){ ** define what database the record should be inserted into. The cursor ** is left pointing at the new record. */ -static int sqliteBtreeInsert( +static int fileBtreeInsert( BtCursor *pCur, /* Insert data into the table of this cursor */ const void *pKey, int nKey, /* The key of the new record */ const void *pData, int nData /* The data of the new record */ @@ -2639,7 +2633,7 @@ static int sqliteBtreeInsert( if( checkReadLocks(pCur) ){ return SQLITE_LOCKED; /* The table pCur points to has a read lock */ } - rc = sqliteBtreeMoveto(pCur, pKey, nKey, &loc); + rc = fileBtreeMoveto(pCur, pKey, nKey, &loc); if( rc ) return rc; pPage = pCur->pPage; assert( pPage->isInit ); @@ -2681,7 +2675,7 @@ static int sqliteBtreeInsert( ** sqliteBtreePrevious() will always leave the cursor pointing at the ** entry immediately before the one that was deleted. */ -static int sqliteBtreeDelete(BtCursor *pCur){ +static int fileBtreeDelete(BtCursor *pCur){ MemPage *pPage = pCur->pPage; Cell *pCell; int rc; @@ -2724,7 +2718,7 @@ static int sqliteBtreeDelete(BtCursor *pCur){ int szNext; int notUsed; getTempCursor(pCur, &leafCur); - rc = sqliteBtreeNext(&leafCur, ¬Used); + rc = fileBtreeNext(&leafCur, ¬Used); if( rc!=SQLITE_OK ){ return SQLITE_CORRUPT; } @@ -2764,11 +2758,12 @@ static int sqliteBtreeDelete(BtCursor *pCur){ ** number for the root page of the new table. ** ** In the current implementation, BTree tables and BTree indices are the -** the same. But in the future, we may change this so that BTree tables +** the same. In the future, we may change this so that BTree tables ** are restricted to having a 4-byte integer key and arbitrary data and ** BTree indices are restricted to having an arbitrary key and no data. +** But for now, this routine also serves to create indices. */ -static int sqliteBtreeCreateTable(Btree *pBt, int *piTable){ +static int fileBtreeCreateTable(Btree *pBt, int *piTable){ MemPage *pRoot; Pgno pgnoRoot; int rc; @@ -2788,19 +2783,6 @@ static int sqliteBtreeCreateTable(Btree *pBt, int *piTable){ return SQLITE_OK; } -/* -** Create a new BTree index. Write into *piTable the page -** number for the root page of the new index. -** -** In the current implementation, BTree tables and BTree indices are the -** the same. But in the future, we may change this so that BTree tables -** are restricted to having a 4-byte integer key and arbitrary data and -** BTree indices are restricted to having an arbitrary key and no data. -*/ -static int sqliteBtreeCreateIndex(Btree *pBt, int *piIndex){ - return sqliteBtreeCreateTable(pBt, piIndex); -} - /* ** Erase the given database page and all its children. Return ** the page to the freelist. @@ -2844,7 +2826,7 @@ static int clearDatabasePage(Btree *pBt, Pgno pgno, int freePageFlag){ /* ** Delete all information from a single table in the database. */ -static int sqliteBtreeClearTable(Btree *pBt, int iTable){ +static int fileBtreeClearTable(Btree *pBt, int iTable){ int rc; BtCursor *pCur; if( !pBt->inTrans ){ @@ -2858,7 +2840,7 @@ static int sqliteBtreeClearTable(Btree *pBt, int iTable){ } rc = clearDatabasePage(pBt, (Pgno)iTable, 0); if( rc ){ - sqliteBtreeRollback(pBt); + fileBtreeRollback(pBt); } return rc; } @@ -2868,7 +2850,7 @@ static int sqliteBtreeClearTable(Btree *pBt, int iTable){ ** the freelist. Except, the root of the principle table (the one on ** page 2) is never added to the freelist. */ -static int sqliteBtreeDropTable(Btree *pBt, int iTable){ +static int fileBtreeDropTable(Btree *pBt, int iTable){ int rc; MemPage *pPage; BtCursor *pCur; @@ -2882,7 +2864,7 @@ static int sqliteBtreeDropTable(Btree *pBt, int iTable){ } rc = sqlitepager_get(pBt->pPager, (Pgno)iTable, (void**)&pPage); if( rc ) return rc; - rc = sqliteBtreeClearTable(pBt, iTable); + rc = fileBtreeClearTable(pBt, iTable); if( rc ) return rc; if( iTable>2 ){ rc = freePage(pBt, pPage, iTable); @@ -2995,7 +2977,7 @@ static int copyDatabasePage( /* ** Read the meta-information out of a database file. */ -static int sqliteBtreeGetMeta(Btree *pBt, int *aMeta){ +static int fileBtreeGetMeta(Btree *pBt, int *aMeta){ PageOne *pP1; int rc; int i; @@ -3013,7 +2995,7 @@ static int sqliteBtreeGetMeta(Btree *pBt, int *aMeta){ /* ** Write meta-information back into the database. */ -static int sqliteBtreeUpdateMeta(Btree *pBt, int *aMeta){ +static int fileBtreeUpdateMeta(Btree *pBt, int *aMeta){ PageOne *pP1; int rc, i; if( !pBt->inTrans ){ @@ -3039,7 +3021,7 @@ static int sqliteBtreeUpdateMeta(Btree *pBt, int *aMeta){ ** is used for debugging and testing only. */ #ifdef SQLITE_TEST -static int sqliteBtreePageDump(Btree *pBt, int pgno, int recursive){ +static int fileBtreePageDump(Btree *pBt, int pgno, int recursive){ int rc; MemPage *pPage; int i, j; @@ -3100,10 +3082,10 @@ static int sqliteBtreePageDump(Btree *pBt, int pgno, int recursive){ idx = SWAB16(pBt, pPage->u.hdr.firstCell); while( idx>0 && idxu.aDisk[idx]; - sqliteBtreePageDump(pBt, SWAB32(pBt, pCell->h.leftChild), 1); + fileBtreePageDump(pBt, SWAB32(pBt, pCell->h.leftChild), 1); idx = SWAB16(pBt, pCell->h.iNext); } - sqliteBtreePageDump(pBt, SWAB32(pBt, pPage->u.hdr.rightChild), 1); + fileBtreePageDump(pBt, SWAB32(pBt, pPage->u.hdr.rightChild), 1); } sqlitepager_unref(pPage); return SQLITE_OK; @@ -3126,7 +3108,7 @@ static int sqliteBtreePageDump(Btree *pBt, int pgno, int recursive){ ** ** This routine is used for testing and debugging only. */ -static int sqliteBtreeCursorDump(BtCursor *pCur, int *aResult){ +static int fileBtreeCursorDump(BtCursor *pCur, int *aResult){ int cnt, idx; MemPage *pPage = pCur->pPage; Btree *pBt = pCur->pBt; @@ -3158,7 +3140,7 @@ static int sqliteBtreeCursorDump(BtCursor *pCur, int *aResult){ ** Return the pager associated with a BTree. This routine is used for ** testing and debugging only. */ -static Pager *sqliteBtreePager(Btree *pBt){ +static Pager *fileBtreePager(Btree *pBt){ return pBt->pPager; } #endif @@ -3438,7 +3420,7 @@ static int checkTreePage( ** and a pointer to that error message is returned. The calling function ** is responsible for freeing the error message when it is done. */ -char *sqliteBtreeIntegrityCheck(Btree *pBt, int *aRoot, int nRoot){ +char *fileBtreeIntegrityCheck(Btree *pBt, int *aRoot, int nRoot){ int i; int nRef; IntegrityCk sCheck; @@ -3502,7 +3484,7 @@ char *sqliteBtreeIntegrityCheck(Btree *pBt, int *aRoot, int nRoot){ /* ** Return the full pathname of the underlying database file. */ -static const char *sqliteBtreeGetFilename(Btree *pBt){ +static const char *fileBtreeGetFilename(Btree *pBt){ assert( pBt->pPager!=0 ); return sqlitepager_filename(pBt->pPager); } @@ -3510,7 +3492,7 @@ static const char *sqliteBtreeGetFilename(Btree *pBt){ /* ** Change the name of the underlying database file. */ -static int sqliteBtreeChangeFilename(Btree *pBt, const char *zNew){ +static int fileBtreeChangeFilename(Btree *pBt, const char *zNew){ return sqlitepager_rename(pBt->pPager, zNew); } @@ -3521,45 +3503,45 @@ static int sqliteBtreeChangeFilename(Btree *pBt, const char *zNew){ ** to provide pointers to alternative functions in similar tables. */ static BtOps sqliteBtreeOps = { - sqliteBtreeClose, - sqliteBtreeSetCacheSize, - sqliteBtreeSetSafetyLevel, - sqliteBtreeBeginTrans, - sqliteBtreeCommit, - sqliteBtreeRollback, - sqliteBtreeBeginCkpt, - sqliteBtreeCommitCkpt, - sqliteBtreeRollbackCkpt, - sqliteBtreeCreateTable, - sqliteBtreeCreateIndex, - sqliteBtreeDropTable, - sqliteBtreeClearTable, - sqliteBtreeCursor, - sqliteBtreeGetMeta, - sqliteBtreeUpdateMeta, - sqliteBtreeIntegrityCheck, - sqliteBtreeGetFilename, - sqliteBtreeChangeFilename, + fileBtreeClose, + fileBtreeSetCacheSize, + fileBtreeSetSafetyLevel, + fileBtreeBeginTrans, + fileBtreeCommit, + fileBtreeRollback, + fileBtreeBeginCkpt, + fileBtreeCommitCkpt, + fileBtreeRollbackCkpt, + fileBtreeCreateTable, + fileBtreeCreateTable, /* Really sqliteBtreeCreateIndex() */ + fileBtreeDropTable, + fileBtreeClearTable, + fileBtreeCursor, + fileBtreeGetMeta, + fileBtreeUpdateMeta, + fileBtreeIntegrityCheck, + fileBtreeGetFilename, + fileBtreeChangeFilename, #ifdef SQLITE_TEST - sqliteBtreePageDump, - sqliteBtreePager + fileBtreePageDump, + fileBtreePager #endif }; static BtCursorOps sqliteBtreeCursorOps = { - sqliteBtreeMoveto, - sqliteBtreeDelete, - sqliteBtreeInsert, - sqliteBtreeFirst, - sqliteBtreeLast, - sqliteBtreeNext, - sqliteBtreePrevious, - sqliteBtreeKeySize, - sqliteBtreeKey, - sqliteBtreeKeyCompare, - sqliteBtreeDataSize, - sqliteBtreeData, - sqliteBtreeCloseCursor, + fileBtreeMoveto, + fileBtreeDelete, + fileBtreeInsert, + fileBtreeFirst, + fileBtreeLast, + fileBtreeNext, + fileBtreePrevious, + fileBtreeKeySize, + fileBtreeKey, + fileBtreeKeyCompare, + fileBtreeDataSize, + fileBtreeData, + fileBtreeCloseCursor, #ifdef SQLITE_TEST - sqliteBtreeCursorDump, + fileBtreeCursorDump, #endif }; diff --git a/src/btree.h b/src/btree.h index 98ea3345ad..c7eae121af 100644 --- a/src/btree.h +++ b/src/btree.h @@ -13,7 +13,7 @@ ** subsystem. See comments in the source code for a detailed description ** of what each interface routine does. ** -** @(#) $Id: btree.h,v 1.30 2003/04/06 20:44:45 drh Exp $ +** @(#) $Id: btree.h,v 1.31 2003/04/16 01:28:16 drh Exp $ */ #ifndef _BTREE_H_ #define _BTREE_H_ @@ -96,7 +96,6 @@ struct BtCursorOps { int sqliteBtreeOpen(const char *zFilename, int mode, int nPg, Btree **ppBtree); -#if !defined(SQLITE_NO_BTREE_DEFS) #define btOps(pBt) (*((BtOps **)(pBt))) #define btCOps(pCur) (*((BtCursorOps **)(pCur))) @@ -143,18 +142,15 @@ int sqliteBtreeOpen(const char *zFilename, int mode, int nPg, Btree **ppBtree); #define sqliteBtreeGetFilename(pBt) (btOps(pBt)->GetFilename(pBt)) #define sqliteBtreeChangeFilename(pBt, zNew)\ (btOps(pBt)->ChangeFilename(pBt, zNew)) -#endif #ifdef SQLITE_TEST -#if !defined(SQLITE_NO_BTREE_DEFS) #define sqliteBtreePageDump(pBt, pgno, recursive)\ (btOps(pBt)->PageDump(pBt, pgno, recursive)) #define sqliteBtreeCursorDump(pCur, aResult)\ (btCOps(pCur)->CursorDump(pCur, aResult)) #define sqliteBtreePager(pBt) (btOps(pBt)->Pager(pBt)) -#endif - int btree_native_byte_order; -#endif +#endif /* SQLITE_TEST */ + #endif /* _BTREE_H_ */ diff --git a/src/btree_rb.c b/src/btree_rb.c index d0242142e8..de11f9bbfa 100644 --- a/src/btree_rb.c +++ b/src/btree_rb.c @@ -9,14 +9,13 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree_rb.c,v 1.2 2003/04/15 19:22:23 drh Exp $ +** $Id: btree_rb.c,v 1.3 2003/04/16 01:28:16 drh Exp $ ** ** This file implements an in-core database using Red-Black balanced ** binary trees. ** ** It was contributed to SQLite by anonymous on 2003-Feb-04 23:24:49 UTC. */ -#define SQLITE_NO_BTREE_DEFS #include "btree.h" #include "sqliteInt.h" #include @@ -127,11 +126,11 @@ struct BtRbNode { }; /* Forward declarations */ -static int sqliteBtreeMoveto(BtCursor* pCur, const void *pKey, int nKey, int *pRes); -static int sqliteBtreeClearTable(Btree* tree, int n); -static int sqliteBtreeNext(BtCursor* pCur, int *pRes); -static int sqliteBtreeLast(BtCursor* pCur, int *pRes); -static int sqliteBtreePrevious(BtCursor* pCur, int *pRes); +static int memBtreeMoveto(BtCursor* pCur, const void *pKey, int nKey,int *pRes); +static int memBtreeClearTable(Btree* tree, int n); +static int memBtreeNext(BtCursor* pCur, int *pRes); +static int memBtreeLast(BtCursor* pCur, int *pRes); +static int memBtreePrevious(BtCursor* pCur, int *pRes); /* * The key-compare function for the red-black trees. Returns as follows: @@ -593,7 +592,7 @@ int sqliteRBtreeOpen(const char *zFilename, int mode, int nPg, Btree **ppBtree) * Create a new table in the supplied Btree. Set *n to the new table number. * Return SQLITE_OK if the operation is a success. */ -static int sqliteBtreeCreateTable(Btree* tree, int* n) +static int memBtreeCreateTable(Btree* tree, int* n) { assert( tree->eTransState != TRANS_NONE ); @@ -612,25 +611,15 @@ static int sqliteBtreeCreateTable(Btree* tree, int* n) return SQLITE_OK; } -/* - * This is currently an alias for sqliteBtreeCreateTable(). There is a note in - * btree.c suggesting that one day indices and tables may be optimized - * differently. - */ -static int sqliteBtreeCreateIndex(Btree* tree, int* n) -{ - return sqliteBtreeCreateTable(tree, n); -} - /* * Delete table n from the supplied Btree. */ -static int sqliteBtreeDropTable(Btree* tree, int n) +static int memBtreeDropTable(Btree* tree, int n) { BtRbTree *pTree; assert( tree->eTransState != TRANS_NONE ); - sqliteBtreeClearTable(tree, n); + memBtreeClearTable(tree, n); pTree = sqliteHashFind(&tree->tblHash, 0, n); assert(pTree); sqliteFree(pTree); @@ -646,7 +635,7 @@ static int sqliteBtreeDropTable(Btree* tree, int n) return SQLITE_OK; } -static int sqliteBtreeKeyCompare(BtCursor* pCur, const void *pKey, int nKey, +static int memBtreeKeyCompare(BtCursor* pCur, const void *pKey, int nKey, int nIgnore, int *pRes) { assert(pCur); @@ -670,7 +659,7 @@ static int sqliteBtreeKeyCompare(BtCursor* pCur, const void *pKey, int nKey, * * Note that BtCursor.eSkip and BtCursor.pNode both initialize to 0. */ -static int sqliteBtreeCursor(Btree* tree, int iTable, int wrFlag, BtCursor **ppCur) +static int memBtreeCursor(Btree* tree, int iTable, int wrFlag, BtCursor **ppCur) { assert(tree); *ppCur = sqliteMalloc(sizeof(BtCursor)); @@ -691,7 +680,7 @@ static int sqliteBtreeCursor(Btree* tree, int iTable, int wrFlag, BtCursor **ppC * * If the key exists already in the tree, just replace the data. */ -static int sqliteBtreeInsert(BtCursor* pCur, const void *pKey, int nKey, +static int memBtreeInsert(BtCursor* pCur, const void *pKey, int nKey, const void *pDataInput, int nData) { void * pData; @@ -716,7 +705,7 @@ static int sqliteBtreeInsert(BtCursor* pCur, const void *pKey, int nKey, * * The new node is initially red. */ - sqliteBtreeMoveto( pCur, pKey, nKey, &match); + memBtreeMoveto( pCur, pKey, nKey, &match); if( match ){ BtRbNode *pNode = sqliteMalloc(sizeof(BtRbNode)); pNode->nKey = nKey; @@ -800,7 +789,7 @@ static int sqliteBtreeInsert(BtCursor* pCur, const void *pKey, int nKey, ** *pRes>0 The cursor is left pointing at an entry that ** is larger than pKey. */ -static int sqliteBtreeMoveto(BtCursor* pCur, const void *pKey, int nKey, int *pRes) +static int memBtreeMoveto(BtCursor* pCur, const void *pKey, int nKey, int *pRes) { BtRbNode *pTmp = 0; @@ -844,7 +833,7 @@ static int sqliteBtreeMoveto(BtCursor* pCur, const void *pKey, int nKey, int *pR ** sqliteBtreePrevious() will always leave the cursor pointing at the ** entry immediately before the one that was deleted. */ -static int sqliteBtreeDelete(BtCursor* pCur) +static int memBtreeDelete(BtCursor* pCur) { BtRbNode *pZ; /* The one being deleted */ BtRbNode *pChild; /* The child of the spliced out node */ @@ -880,7 +869,7 @@ static int sqliteBtreeDelete(BtCursor* pCur) BtRbNode *pTmp; int dummy; pCur->eSkip = SKIP_NONE; - sqliteBtreeNext(pCur, &dummy); + memBtreeNext(pCur, &dummy); assert( dummy == 0 ); if( pCur->pBtree->eTransState == TRANS_ROLLBACK ){ sqliteFree(pZ->pKey); @@ -897,11 +886,11 @@ static int sqliteBtreeDelete(BtCursor* pCur) }else{ int res; pCur->eSkip = SKIP_NONE; - sqliteBtreeNext(pCur, &res); + memBtreeNext(pCur, &res); pCur->eSkip = SKIP_NEXT; if( res ){ - sqliteBtreeLast(pCur, &res); - sqliteBtreePrevious(pCur, &res); + memBtreeLast(pCur, &res); + memBtreePrevious(pCur, &res); pCur->eSkip = SKIP_PREV; } if( pCur->pBtree->eTransState == TRANS_ROLLBACK ){ @@ -943,7 +932,7 @@ static int sqliteBtreeDelete(BtCursor* pCur) /* * Empty table n of the Btree. */ -static int sqliteBtreeClearTable(Btree* tree, int n) +static int memBtreeClearTable(Btree* tree, int n) { BtRbTree *pTree; BtRbNode *pNode; @@ -987,7 +976,7 @@ static int sqliteBtreeClearTable(Btree* tree, int n) return SQLITE_OK; } -static int sqliteBtreeFirst(BtCursor* pCur, int *pRes) +static int memBtreeFirst(BtCursor* pCur, int *pRes) { if( pCur->pTree->pHead ){ pCur->pNode = pCur->pTree->pHead; @@ -1004,7 +993,7 @@ static int sqliteBtreeFirst(BtCursor* pCur, int *pRes) return SQLITE_OK; } -static int sqliteBtreeLast(BtCursor* pCur, int *pRes) +static int memBtreeLast(BtCursor* pCur, int *pRes) { if( pCur->pTree->pHead ){ pCur->pNode = pCur->pTree->pHead; @@ -1021,7 +1010,7 @@ static int sqliteBtreeLast(BtCursor* pCur, int *pRes) return SQLITE_OK; } -static int sqliteBtreeNext(BtCursor* pCur, int *pRes) +static int memBtreeNext(BtCursor* pCur, int *pRes) { if( pCur->pNode && pCur->eSkip != SKIP_NEXT ){ if( pCur->pNode->pRight ){ @@ -1048,7 +1037,7 @@ static int sqliteBtreeNext(BtCursor* pCur, int *pRes) return SQLITE_OK; } -static int sqliteBtreePrevious(BtCursor* pCur, int *pRes) +static int memBtreePrevious(BtCursor* pCur, int *pRes) { if( pCur->pNode && pCur->eSkip != SKIP_PREV ){ if( pCur->pNode->pLeft ){ @@ -1075,7 +1064,7 @@ static int sqliteBtreePrevious(BtCursor* pCur, int *pRes) return SQLITE_OK; } -static int sqliteBtreeKeySize(BtCursor* pCur, int *pSize) +static int memBtreeKeySize(BtCursor* pCur, int *pSize) { if( pCur->pNode ){ *pSize = pCur->pNode->nKey; @@ -1085,7 +1074,7 @@ static int sqliteBtreeKeySize(BtCursor* pCur, int *pSize) return SQLITE_OK; } -static int sqliteBtreeKey(BtCursor* pCur, int offset, int amt, char *zBuf) +static int memBtreeKey(BtCursor* pCur, int offset, int amt, char *zBuf) { if( !pCur->pNode ) return 0; if( !pCur->pNode->pKey || ((amt + offset) <= pCur->pNode->nKey) ){ @@ -1098,7 +1087,7 @@ static int sqliteBtreeKey(BtCursor* pCur, int offset, int amt, char *zBuf) assert(0); } -static int sqliteBtreeDataSize(BtCursor* pCur, int *pSize) +static int memBtreeDataSize(BtCursor* pCur, int *pSize) { if( pCur->pNode ){ *pSize = pCur->pNode->nData; @@ -1108,7 +1097,7 @@ static int sqliteBtreeDataSize(BtCursor* pCur, int *pSize) return SQLITE_OK; } -static int sqliteBtreeData(BtCursor *pCur, int offset, int amt, char *zBuf) +static int memBtreeData(BtCursor *pCur, int offset, int amt, char *zBuf) { if( !pCur->pNode ) return 0; if( (amt + offset) <= pCur->pNode->nData ){ @@ -1121,19 +1110,19 @@ static int sqliteBtreeData(BtCursor *pCur, int offset, int amt, char *zBuf) assert(0); } -static int sqliteBtreeCloseCursor(BtCursor* pCur) +static int memBtreeCloseCursor(BtCursor* pCur) { sqliteFree(pCur); return SQLITE_OK; } -static int sqliteBtreeGetMeta(Btree* tree, int* aMeta) +static int memBtreeGetMeta(Btree* tree, int* aMeta) { memcpy( aMeta, tree->aMetaData, sizeof(int) * SQLITE_N_BTREE_META ); return SQLITE_OK; } -static int sqliteBtreeUpdateMeta(Btree* tree, int* aMeta) +static int memBtreeUpdateMeta(Btree* tree, int* aMeta) { memcpy( tree->aMetaData, aMeta, sizeof(int) * SQLITE_N_BTREE_META ); return SQLITE_OK; @@ -1144,7 +1133,7 @@ static int sqliteBtreeUpdateMeta(Btree* tree, int* aMeta) * binary tree. If an error is found, return an explanation of the problem in * memory obtained from sqliteMalloc(). Parameters aRoot and nRoot are ignored. */ -static char *sqliteBtreeIntegrityCheck(Btree* tree, int* aRoot, int nRoot) +static char *memBtreeIntegrityCheck(Btree* tree, int* aRoot, int nRoot) { char * msg = 0; HashElem *p; @@ -1160,28 +1149,28 @@ static char *sqliteBtreeIntegrityCheck(Btree* tree, int* aRoot, int nRoot) /* * Close the supplied Btree. Delete everything associated with it. */ -static int sqliteBtreeClose(Btree* tree) +static int memBtreeClose(Btree* tree) { HashElem *p; for(p=sqliteHashFirst(&tree->tblHash); p; p=sqliteHashNext(p)){ tree->eTransState = TRANS_ROLLBACK; - sqliteBtreeClearTable(tree, sqliteHashKeysize(p)); + memBtreeClearTable(tree, sqliteHashKeysize(p)); sqliteFree(sqliteHashData(p)); } sqliteFree(tree); return SQLITE_OK; } -static int sqliteBtreeSetCacheSize(Btree* tree, int sz) +static int memBtreeSetCacheSize(Btree* tree, int sz) { return SQLITE_OK; } -static int sqliteBtreeSetSafetyLevel(Btree *pBt, int level){ +static int memBtreeSetSafetyLevel(Btree *pBt, int level){ return SQLITE_OK; } -static int sqliteBtreeBeginTrans(Btree* tree) +static int memBtreeBeginTrans(Btree* tree) { if( tree->eTransState != TRANS_NONE ) return SQLITE_ERROR; @@ -1191,7 +1180,7 @@ static int sqliteBtreeBeginTrans(Btree* tree) return SQLITE_OK; } -static int sqliteBtreeCommit(Btree* tree) +static int memBtreeCommit(Btree* tree) { /* Just delete pTransRollback and pCheckRollback */ BtRollbackOp *pOp, *pTmp; @@ -1235,7 +1224,7 @@ static void execute_rollback_list(Btree *pBtree, BtRollbackOp *pList) assert(cur.pTree); cur.iTree = pList->iTab; cur.eSkip = SKIP_NONE; - sqliteBtreeInsert( &cur, pList->pKey, + memBtreeInsert( &cur, pList->pKey, pList->nKey, pList->pData, pList->nData ); break; case ROLLBACK_DELETE: @@ -1243,15 +1232,15 @@ static void execute_rollback_list(Btree *pBtree, BtRollbackOp *pList) assert(cur.pTree); cur.iTree = pList->iTab; cur.eSkip = SKIP_NONE; - sqliteBtreeMoveto(&cur, pList->pKey, pList->nKey, &res); + memBtreeMoveto(&cur, pList->pKey, pList->nKey, &res); assert(res == 0); - sqliteBtreeDelete( &cur ); + memBtreeDelete( &cur ); break; case ROLLBACK_CREATE: btreeCreateTable(pBtree, pList->iTab); break; case ROLLBACK_DROP: - sqliteBtreeDropTable(pBtree, pList->iTab); + memBtreeDropTable(pBtree, pList->iTab); break; default: assert(0); @@ -1264,7 +1253,7 @@ static void execute_rollback_list(Btree *pBtree, BtRollbackOp *pList) } } -static int sqliteBtreeRollback(Btree* tree) +static int memBtreeRollback(Btree* tree) { tree->eTransState = TRANS_ROLLBACK; execute_rollback_list(tree, tree->pCheckRollback); @@ -1276,7 +1265,7 @@ static int sqliteBtreeRollback(Btree* tree) return SQLITE_OK; } -static int sqliteBtreeBeginCkpt(Btree* tree) +static int memBtreeBeginCkpt(Btree* tree) { if( tree->eTransState != TRANS_INTRANSACTION ) return SQLITE_ERROR; @@ -1287,7 +1276,7 @@ static int sqliteBtreeBeginCkpt(Btree* tree) return SQLITE_OK; } -static int sqliteBtreeCommitCkpt(Btree* tree) +static int memBtreeCommitCkpt(Btree* tree) { if( tree->eTransState == TRANS_INCHECKPOINT ){ if( tree->pCheckRollback ){ @@ -1301,7 +1290,7 @@ static int sqliteBtreeCommitCkpt(Btree* tree) return SQLITE_OK; } -static int sqliteBtreeRollbackCkpt(Btree* tree) +static int memBtreeRollbackCkpt(Btree* tree) { if( tree->eTransState != TRANS_INCHECKPOINT ) return SQLITE_OK; tree->eTransState = TRANS_ROLLBACK; @@ -1314,19 +1303,19 @@ static int sqliteBtreeRollbackCkpt(Btree* tree) } #ifdef SQLITE_TEST -static int sqliteBtreePageDump(Btree* tree, int pgno, int rec) +static int memBtreePageDump(Btree* tree, int pgno, int rec) { assert(!"Cannot call sqliteBtreePageDump"); return SQLITE_OK; } -static int sqliteBtreeCursorDump(BtCursor* pCur, int* aRes) +static int memBtreeCursorDump(BtCursor* pCur, int* aRes) { assert(!"Cannot call sqliteBtreeCursorDump"); return SQLITE_OK; } -static struct Pager *sqliteBtreePager(Btree* tree) +static struct Pager *memBtreePager(Btree* tree) { assert(!"Cannot call sqliteBtreePager"); return SQLITE_OK; @@ -1336,60 +1325,60 @@ static struct Pager *sqliteBtreePager(Btree* tree) /* ** Return the full pathname of the underlying database file. */ -static const char *sqliteBtreeGetFilename(Btree *pBt){ +static const char *memBtreeGetFilename(Btree *pBt){ return ":memory:"; } /* ** Change the name of the underlying database file. */ -static int sqliteBtreeChangeFilename(Btree *pBt, const char *zNew){ +static int memBtreeChangeFilename(Btree *pBt, const char *zNew){ return SQLITE_OK; } static BtOps sqliteBtreeOps = { - sqliteBtreeClose, - sqliteBtreeSetCacheSize, - sqliteBtreeSetSafetyLevel, - sqliteBtreeBeginTrans, - sqliteBtreeCommit, - sqliteBtreeRollback, - sqliteBtreeBeginCkpt, - sqliteBtreeCommitCkpt, - sqliteBtreeRollbackCkpt, - sqliteBtreeCreateTable, - sqliteBtreeCreateIndex, - sqliteBtreeDropTable, - sqliteBtreeClearTable, - sqliteBtreeCursor, - sqliteBtreeGetMeta, - sqliteBtreeUpdateMeta, - sqliteBtreeIntegrityCheck, - sqliteBtreeGetFilename, - sqliteBtreeChangeFilename, + memBtreeClose, + memBtreeSetCacheSize, + memBtreeSetSafetyLevel, + memBtreeBeginTrans, + memBtreeCommit, + memBtreeRollback, + memBtreeBeginCkpt, + memBtreeCommitCkpt, + memBtreeRollbackCkpt, + memBtreeCreateTable, + memBtreeCreateTable, + memBtreeDropTable, + memBtreeClearTable, + memBtreeCursor, + memBtreeGetMeta, + memBtreeUpdateMeta, + memBtreeIntegrityCheck, + memBtreeGetFilename, + memBtreeChangeFilename, #ifdef SQLITE_TEST - sqliteBtreePageDump, - sqliteBtreePager + memBtreePageDump, + memBtreePager #endif }; static BtCursorOps sqliteBtreeCursorOps = { - sqliteBtreeMoveto, - sqliteBtreeDelete, - sqliteBtreeInsert, - sqliteBtreeFirst, - sqliteBtreeLast, - sqliteBtreeNext, - sqliteBtreePrevious, - sqliteBtreeKeySize, - sqliteBtreeKey, - sqliteBtreeKeyCompare, - sqliteBtreeDataSize, - sqliteBtreeData, - sqliteBtreeCloseCursor, + memBtreeMoveto, + memBtreeDelete, + memBtreeInsert, + memBtreeFirst, + memBtreeLast, + memBtreeNext, + memBtreePrevious, + memBtreeKeySize, + memBtreeKey, + memBtreeKeyCompare, + memBtreeDataSize, + memBtreeData, + memBtreeCloseCursor, #ifdef SQLITE_TEST - sqliteBtreeCursorDump, + memBtreeCursorDump, #endif }; diff --git a/src/main.c b/src/main.c index 9eb5fb3654..e5db2b4fb6 100644 --- a/src/main.c +++ b/src/main.c @@ -14,7 +14,7 @@ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.123 2003/04/15 01:19:48 drh Exp $ +** $Id: main.c,v 1.124 2003/04/16 01:28:16 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -426,7 +426,7 @@ sqlite *sqlite_open(const char *zFilename, int mode, char **pzErrMsg){ } /* Open the backend database driver */ - rc = sqliteBtreeOpen(zFilename, 0, MAX_PAGES, &db->aDb[0].pBt); + rc = sqliteBtreeFactory(db, zFilename, 0, MAX_PAGES, &db->aDb[0].pBt); if( rc!=SQLITE_OK ){ switch( rc ){ default: { @@ -1065,8 +1065,6 @@ void *sqlite_commit_hook( ** is for temporary use only and is deleted as soon as the connection ** is closed. ** -** -** ** A temporary database can be either a disk file (that is automatically ** deleted when the file is closed) or a set of red-black trees held in memory, ** depending on the values of the TEMP_STORE compile-time macro and the