-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
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
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
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
-0b996959b8d8bc2c82eab9cccc190befd0056505
\ No newline at end of file
+35cc7c7d37d9ca486e7f300efe80a78a7f1064e2
\ No newline at end of file
** 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
** 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"
#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.
/*
** 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);
** 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;
}
** 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;
}
** 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;
** 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;
** 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;
** 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;
** 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);
** 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;
** 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;
** 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;
** 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;
** 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 );
** 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;
** 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;
** 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 */
** 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);
** 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);
** *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;
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;
** 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 );
** 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;
** 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 */
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 );
** 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;
int szNext;
int notUsed;
getTempCursor(pCur, &leafCur);
- rc = sqliteBtreeNext(&leafCur, ¬Used);
+ rc = fileBtreeNext(&leafCur, ¬Used);
if( rc!=SQLITE_OK ){
return SQLITE_CORRUPT;
}
** 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;
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.
/*
** 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 ){
}
rc = clearDatabasePage(pBt, (Pgno)iTable, 0);
if( rc ){
- sqliteBtreeRollback(pBt);
+ fileBtreeRollback(pBt);
}
return rc;
}
** 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;
}
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);
/*
** 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;
/*
** 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 ){
** 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;
idx = SWAB16(pBt, pPage->u.hdr.firstCell);
while( idx>0 && idx<SQLITE_PAGE_SIZE-MIN_CELL_SIZE ){
Cell *pCell = (Cell*)&pPage->u.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;
**
** 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;
** 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
** 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;
/*
** 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);
}
/*
** 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);
}
** 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
};
** 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_
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)))
#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_ */
** 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 <assert.h>
};
/* 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:
* 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 );
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);
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);
*
* 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));
*
* 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;
*
* 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;
** *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;
** 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 */
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);
}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 ){
/*
* Empty table n of the Btree.
*/
-static int sqliteBtreeClearTable(Btree* tree, int n)
+static int memBtreeClearTable(Btree* tree, int n)
{
BtRbTree *pTree;
BtRbNode *pNode;
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;
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;
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 ){
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 ){
return SQLITE_OK;
}
-static int sqliteBtreeKeySize(BtCursor* pCur, int *pSize)
+static int memBtreeKeySize(BtCursor* pCur, int *pSize)
{
if( pCur->pNode ){
*pSize = pCur->pNode->nKey;
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) ){
assert(0);
}
-static int sqliteBtreeDataSize(BtCursor* pCur, int *pSize)
+static int memBtreeDataSize(BtCursor* pCur, int *pSize)
{
if( pCur->pNode ){
*pSize = pCur->pNode->nData;
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 ){
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;
* 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;
/*
* 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;
return SQLITE_OK;
}
-static int sqliteBtreeCommit(Btree* tree)
+static int memBtreeCommit(Btree* tree)
{
/* Just delete pTransRollback and pCheckRollback */
BtRollbackOp *pOp, *pTmp;
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:
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);
}
}
-static int sqliteBtreeRollback(Btree* tree)
+static int memBtreeRollback(Btree* tree)
{
tree->eTransState = TRANS_ROLLBACK;
execute_rollback_list(tree, tree->pCheckRollback);
return SQLITE_OK;
}
-static int sqliteBtreeBeginCkpt(Btree* tree)
+static int memBtreeBeginCkpt(Btree* tree)
{
if( tree->eTransState != TRANS_INTRANSACTION )
return SQLITE_ERROR;
return SQLITE_OK;
}
-static int sqliteBtreeCommitCkpt(Btree* tree)
+static int memBtreeCommitCkpt(Btree* tree)
{
if( tree->eTransState == TRANS_INCHECKPOINT ){
if( tree->pCheckRollback ){
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;
}
#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;
/*
** 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
};
** 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"
}
/* 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: {
** 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