mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
Remove some unnecessary code and complication from the btree interface. (CVS 909)
FossilOrigin-Name: 35cc7c7d37d9ca486e7f300efe80a78a7f1064e2
This commit is contained in:
18
manifest
18
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)
|
C Remove\ssome\sunnecessary\scode\sand\scomplication\sfrom\sthe\sbtree\sinterface.\s(CVS\s909)
|
||||||
D 2003-04-15T19:22:23
|
D 2003-04-16T01:28:16
|
||||||
F Makefile.in df3a4db41a7450468b5fe934d9dd8f723b631249
|
F Makefile.in df3a4db41a7450468b5fe934d9dd8f723b631249
|
||||||
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
|
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
|
||||||
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
|
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
|
||||||
@ -21,9 +21,9 @@ F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea
|
|||||||
F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
|
F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
|
||||||
F src/attach.c 7ebc7487de43e357a64226f8abef81f2669f2183
|
F src/attach.c 7ebc7487de43e357a64226f8abef81f2669f2183
|
||||||
F src/auth.c f37bfc9451b8c1fa52f34adff474560018892729
|
F src/auth.c f37bfc9451b8c1fa52f34adff474560018892729
|
||||||
F src/btree.c 9949031b6087e9d1b43b359b84c68a491086984f
|
F src/btree.c b9487cceb9ea78af9cbae9def34114902f511736
|
||||||
F src/btree.h 5cb871546bd6fa58396a6f033e2b29b388241e1b
|
F src/btree.h 529c98cb0715c62214544fbbe50b946f99a85540
|
||||||
F src/btree_rb.c c917cdcc401df1075b257a96e8a1e3e46a506805
|
F src/btree_rb.c 7fa4901a65de66522ce31985833f20b98f7baad4
|
||||||
F src/build.c daed1dacdb70e5d4def9df2e34a1cabeeb8467c9
|
F src/build.c daed1dacdb70e5d4def9df2e34a1cabeeb8467c9
|
||||||
F src/copy.c 8699e571994934c78f70761a1458d7b9e9e75073
|
F src/copy.c 8699e571994934c78f70761a1458d7b9e9e75073
|
||||||
F src/delete.c 6021fd293a78ebeb35e8177bd811d752fe090f89
|
F src/delete.c 6021fd293a78ebeb35e8177bd811d752fe090f89
|
||||||
@ -33,7 +33,7 @@ F src/func.c 882c3ed5a02be18cd904715c7ec62947a34a3605
|
|||||||
F src/hash.c 4fc39feb7b7711f6495ee9f2159559bedb043e1f
|
F src/hash.c 4fc39feb7b7711f6495ee9f2159559bedb043e1f
|
||||||
F src/hash.h cd0433998bc1a3759d244e1637fe5a3c13b53bf8
|
F src/hash.h cd0433998bc1a3759d244e1637fe5a3c13b53bf8
|
||||||
F src/insert.c 45d27e3e8447bff4025db2f0dc3bb4e318e602f4
|
F src/insert.c 45d27e3e8447bff4025db2f0dc3bb4e318e602f4
|
||||||
F src/main.c daf5b7c256340fb9aa77df7254865218a47d5a63
|
F src/main.c 9b3e2e1e12d8ab950c1b99fc3805f69018a6e751
|
||||||
F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565
|
F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565
|
||||||
F src/os.c c33ebb320921b8df6d09ea19fe846348df86a0c9
|
F src/os.c c33ebb320921b8df6d09ea19fe846348df86a0c9
|
||||||
F src/os.h aa52f0c9da321ff6134d19f2ca959e18e33615d0
|
F src/os.h aa52f0c9da321ff6134d19f2ca959e18e33615d0
|
||||||
@ -162,7 +162,7 @@ F www/speed.tcl cb4c10a722614aea76d2c51f32ee43400d5951be
|
|||||||
F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
|
F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
|
||||||
F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
|
F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
|
||||||
F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
|
F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
|
||||||
P 93eb6c52aca8de15a88247ec986c36245527ec7b
|
P 0b996959b8d8bc2c82eab9cccc190befd0056505
|
||||||
R 97b4c68da27841d236c7d5fe42a0a220
|
R 9b9a6e33d11cf491ef2a5576ee3b5a64
|
||||||
U drh
|
U drh
|
||||||
Z 2af580d6307d67cd3da5d48cc8031613
|
Z ff418746ff7b6d08e8d28734401a85c5
|
||||||
|
@ -1 +1 @@
|
|||||||
0b996959b8d8bc2c82eab9cccc190befd0056505
|
35cc7c7d37d9ca486e7f300efe80a78a7f1064e2
|
182
src/btree.c
182
src/btree.c
@ -9,7 +9,7 @@
|
|||||||
** May you share freely, never taking more than you give.
|
** 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.
|
** This file implements a external (disk-based) database using BTrees.
|
||||||
** For a detailed discussion of BTrees, refer to
|
** 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
|
** BTree begins on page 2 of the file. (Pages are numbered beginning with
|
||||||
** 1, not 0.) Thus a minimum database contains 2 pages.
|
** 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 "sqliteInt.h"
|
||||||
#include "pager.h"
|
#include "pager.h"
|
||||||
#include "btree.h"
|
#include "btree.h"
|
||||||
@ -389,7 +382,7 @@ struct BtCursor {
|
|||||||
#define SKIP_INVALID 3 /* Calls to Next() and Previous() are invalid */
|
#define SKIP_INVALID 3 /* Calls to Next() and Previous() are invalid */
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
static int sqliteBtreeCloseCursor(BtCursor *pCur);
|
static int fileBtreeCloseCursor(BtCursor *pCur);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Routines for byte swapping.
|
** Routines for byte swapping.
|
||||||
@ -733,9 +726,9 @@ int sqliteBtreeOpen(
|
|||||||
/*
|
/*
|
||||||
** Close an open database and invalidate all cursors.
|
** Close an open database and invalidate all cursors.
|
||||||
*/
|
*/
|
||||||
static int sqliteBtreeClose(Btree *pBt){
|
static int fileBtreeClose(Btree *pBt){
|
||||||
while( pBt->pCursor ){
|
while( pBt->pCursor ){
|
||||||
sqliteBtreeCloseCursor(pBt->pCursor);
|
fileBtreeCloseCursor(pBt->pCursor);
|
||||||
}
|
}
|
||||||
sqlitepager_close(pBt->pPager);
|
sqlitepager_close(pBt->pPager);
|
||||||
sqliteFree(pBt);
|
sqliteFree(pBt);
|
||||||
@ -757,7 +750,7 @@ static int sqliteBtreeClose(Btree *pBt){
|
|||||||
** Synchronous is on by default so database corruption is not
|
** Synchronous is on by default so database corruption is not
|
||||||
** normally a worry.
|
** normally a worry.
|
||||||
*/
|
*/
|
||||||
static int sqliteBtreeSetCacheSize(Btree *pBt, int mxPage){
|
static int fileBtreeSetCacheSize(Btree *pBt, int mxPage){
|
||||||
sqlitepager_set_cachesize(pBt->pPager, mxPage);
|
sqlitepager_set_cachesize(pBt->pPager, mxPage);
|
||||||
return SQLITE_OK;
|
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
|
** 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.
|
** 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);
|
sqlitepager_set_safety_level(pBt->pPager, level);
|
||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
@ -877,7 +870,7 @@ static int newDatabase(Btree *pBt){
|
|||||||
** sqliteBtreeDelete()
|
** sqliteBtreeDelete()
|
||||||
** sqliteBtreeUpdateMeta()
|
** sqliteBtreeUpdateMeta()
|
||||||
*/
|
*/
|
||||||
static int sqliteBtreeBeginTrans(Btree *pBt){
|
static int fileBtreeBeginTrans(Btree *pBt){
|
||||||
int rc;
|
int rc;
|
||||||
if( pBt->inTrans ) return SQLITE_ERROR;
|
if( pBt->inTrans ) return SQLITE_ERROR;
|
||||||
if( pBt->readOnly ) return SQLITE_READONLY;
|
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
|
** This will release the write lock on the database file. If there
|
||||||
** are no active cursors, it also releases the read lock.
|
** are no active cursors, it also releases the read lock.
|
||||||
*/
|
*/
|
||||||
static int sqliteBtreeCommit(Btree *pBt){
|
static int fileBtreeCommit(Btree *pBt){
|
||||||
int rc;
|
int rc;
|
||||||
rc = pBt->readOnly ? SQLITE_OK : sqlitepager_commit(pBt->pPager);
|
rc = pBt->readOnly ? SQLITE_OK : sqlitepager_commit(pBt->pPager);
|
||||||
pBt->inTrans = 0;
|
pBt->inTrans = 0;
|
||||||
@ -924,7 +917,7 @@ static int sqliteBtreeCommit(Btree *pBt){
|
|||||||
** This will release the write lock on the database file. If there
|
** This will release the write lock on the database file. If there
|
||||||
** are no active cursors, it also releases the read lock.
|
** are no active cursors, it also releases the read lock.
|
||||||
*/
|
*/
|
||||||
static int sqliteBtreeRollback(Btree *pBt){
|
static int fileBtreeRollback(Btree *pBt){
|
||||||
int rc;
|
int rc;
|
||||||
BtCursor *pCur;
|
BtCursor *pCur;
|
||||||
if( pBt->inTrans==0 ) return SQLITE_OK;
|
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
|
** 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.
|
** to start a new checkpoint if another checkpoint is already active.
|
||||||
*/
|
*/
|
||||||
static int sqliteBtreeBeginCkpt(Btree *pBt){
|
static int fileBtreeBeginCkpt(Btree *pBt){
|
||||||
int rc;
|
int rc;
|
||||||
if( !pBt->inTrans || pBt->inCkpt ){
|
if( !pBt->inTrans || pBt->inCkpt ){
|
||||||
return pBt->readOnly ? SQLITE_READONLY : SQLITE_ERROR;
|
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
|
** Commit a checkpoint to transaction currently in progress. If no
|
||||||
** checkpoint is active, this is a no-op.
|
** checkpoint is active, this is a no-op.
|
||||||
*/
|
*/
|
||||||
static int sqliteBtreeCommitCkpt(Btree *pBt){
|
static int fileBtreeCommitCkpt(Btree *pBt){
|
||||||
int rc;
|
int rc;
|
||||||
if( pBt->inCkpt && !pBt->readOnly ){
|
if( pBt->inCkpt && !pBt->readOnly ){
|
||||||
rc = sqlitepager_ckpt_commit(pBt->pPager);
|
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
|
** to use a cursor that was open at the beginning of this operation
|
||||||
** will result in an error.
|
** will result in an error.
|
||||||
*/
|
*/
|
||||||
static int sqliteBtreeRollbackCkpt(Btree *pBt){
|
static int fileBtreeRollbackCkpt(Btree *pBt){
|
||||||
int rc;
|
int rc;
|
||||||
BtCursor *pCur;
|
BtCursor *pCur;
|
||||||
if( pBt->inCkpt==0 || pBt->readOnly ) return SQLITE_OK;
|
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
|
** root page of a b-tree. If it is not, then the cursor acquired
|
||||||
** will not work correctly.
|
** 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;
|
int rc;
|
||||||
BtCursor *pCur, *pRing;
|
BtCursor *pCur, *pRing;
|
||||||
|
|
||||||
@ -1097,7 +1090,7 @@ create_cursor_exception:
|
|||||||
** Close a cursor. The read lock on the database file is released
|
** Close a cursor. The read lock on the database file is released
|
||||||
** when the last cursor is closed.
|
** when the last cursor is closed.
|
||||||
*/
|
*/
|
||||||
static int sqliteBtreeCloseCursor(BtCursor *pCur){
|
static int fileBtreeCloseCursor(BtCursor *pCur){
|
||||||
Btree *pBt = pCur->pBt;
|
Btree *pBt = pCur->pBt;
|
||||||
if( pCur->pPrev ){
|
if( pCur->pPrev ){
|
||||||
pCur->pPrev->pNext = pCur->pNext;
|
pCur->pPrev->pNext = pCur->pNext;
|
||||||
@ -1150,7 +1143,7 @@ static void releaseTempCursor(BtCursor *pCur){
|
|||||||
** pointing to an entry (which can happen, for example, if
|
** pointing to an entry (which can happen, for example, if
|
||||||
** the database is empty) then *pSize is set to 0.
|
** 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;
|
Cell *pCell;
|
||||||
MemPage *pPage;
|
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
|
** is raised. The change was made in an effort to boost performance
|
||||||
** by eliminating unneeded tests.
|
** 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;
|
MemPage *pPage;
|
||||||
|
|
||||||
assert( amt>=0 );
|
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
|
** pointing to an entry (which can happen, for example, if
|
||||||
** the database is empty) then *pSize is set to 0.
|
** 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;
|
Cell *pCell;
|
||||||
MemPage *pPage;
|
MemPage *pPage;
|
||||||
|
|
||||||
@ -1284,7 +1277,7 @@ static int sqliteBtreeDataSize(BtCursor *pCur, int *pSize){
|
|||||||
** amount requested if there are not enough bytes in the data
|
** amount requested if there are not enough bytes in the data
|
||||||
** to satisfy the request.
|
** 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;
|
Cell *pCell;
|
||||||
MemPage *pPage;
|
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
|
** keys must be exactly the same length. (The length of the pCur key
|
||||||
** is the actual key length minus nIgnore bytes.)
|
** is the actual key length minus nIgnore bytes.)
|
||||||
*/
|
*/
|
||||||
static int sqliteBtreeKeyCompare(
|
static int fileBtreeKeyCompare(
|
||||||
BtCursor *pCur, /* Pointer to entry to compare against */
|
BtCursor *pCur, /* Pointer to entry to compare against */
|
||||||
const void *pKey, /* Key to compare against entry that pCur points to */
|
const void *pKey, /* Key to compare against entry that pCur points to */
|
||||||
int nKey, /* Number of bytes in pKey */
|
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
|
** on success. Set *pRes to 0 if the cursor actually points to something
|
||||||
** or set *pRes to 1 if the table is empty.
|
** 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;
|
int rc;
|
||||||
if( pCur->pPage==0 ) return SQLITE_ABORT;
|
if( pCur->pPage==0 ) return SQLITE_ABORT;
|
||||||
rc = moveToRoot(pCur);
|
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
|
** on success. Set *pRes to 0 if the cursor actually points to something
|
||||||
** or set *pRes to 1 if the table is empty.
|
** 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;
|
int rc;
|
||||||
if( pCur->pPage==0 ) return SQLITE_ABORT;
|
if( pCur->pPage==0 ) return SQLITE_ABORT;
|
||||||
rc = moveToRoot(pCur);
|
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
|
** *pRes>0 The cursor is left pointing at an entry that
|
||||||
** is larger than pKey.
|
** 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;
|
int rc;
|
||||||
if( pCur->pPage==0 ) return SQLITE_ABORT;
|
if( pCur->pPage==0 ) return SQLITE_ABORT;
|
||||||
pCur->eSkip = SKIP_NONE;
|
pCur->eSkip = SKIP_NONE;
|
||||||
@ -1594,7 +1588,7 @@ static int sqliteBtreeMoveto(BtCursor *pCur, const void *pKey, int nKey, int *pR
|
|||||||
upr = pPage->nCell-1;
|
upr = pPage->nCell-1;
|
||||||
while( lwr<=upr ){
|
while( lwr<=upr ){
|
||||||
pCur->idx = (lwr+upr)/2;
|
pCur->idx = (lwr+upr)/2;
|
||||||
rc = sqliteBtreeKeyCompare(pCur, pKey, nKey, 0, &c);
|
rc = fileBtreeKeyCompare(pCur, pKey, nKey, 0, &c);
|
||||||
if( rc ) return rc;
|
if( rc ) return rc;
|
||||||
if( c==0 ){
|
if( c==0 ){
|
||||||
pCur->iMatch = c;
|
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
|
** was already pointing to the last entry in the database before
|
||||||
** this routine was called, then set *pRes=1.
|
** this routine was called, then set *pRes=1.
|
||||||
*/
|
*/
|
||||||
static int sqliteBtreeNext(BtCursor *pCur, int *pRes){
|
static int fileBtreeNext(BtCursor *pCur, int *pRes){
|
||||||
int rc;
|
int rc;
|
||||||
MemPage *pPage = pCur->pPage;
|
MemPage *pPage = pCur->pPage;
|
||||||
assert( pRes!=0 );
|
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
|
** was already pointing to the first entry in the database before
|
||||||
** this routine was called, then set *pRes=1.
|
** this routine was called, then set *pRes=1.
|
||||||
*/
|
*/
|
||||||
static int sqliteBtreePrevious(BtCursor *pCur, int *pRes){
|
static int fileBtreePrevious(BtCursor *pCur, int *pRes){
|
||||||
int rc;
|
int rc;
|
||||||
Pgno pgno;
|
Pgno pgno;
|
||||||
MemPage *pPage;
|
MemPage *pPage;
|
||||||
@ -2613,7 +2607,7 @@ static int checkReadLocks(BtCursor *pCur){
|
|||||||
** define what database the record should be inserted into. The cursor
|
** define what database the record should be inserted into. The cursor
|
||||||
** is left pointing at the new record.
|
** is left pointing at the new record.
|
||||||
*/
|
*/
|
||||||
static int sqliteBtreeInsert(
|
static int fileBtreeInsert(
|
||||||
BtCursor *pCur, /* Insert data into the table of this cursor */
|
BtCursor *pCur, /* Insert data into the table of this cursor */
|
||||||
const void *pKey, int nKey, /* The key of the new record */
|
const void *pKey, int nKey, /* The key of the new record */
|
||||||
const void *pData, int nData /* The data 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) ){
|
if( checkReadLocks(pCur) ){
|
||||||
return SQLITE_LOCKED; /* The table pCur points to has a read lock */
|
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;
|
if( rc ) return rc;
|
||||||
pPage = pCur->pPage;
|
pPage = pCur->pPage;
|
||||||
assert( pPage->isInit );
|
assert( pPage->isInit );
|
||||||
@ -2681,7 +2675,7 @@ static int sqliteBtreeInsert(
|
|||||||
** sqliteBtreePrevious() will always leave the cursor pointing at the
|
** sqliteBtreePrevious() will always leave the cursor pointing at the
|
||||||
** entry immediately before the one that was deleted.
|
** entry immediately before the one that was deleted.
|
||||||
*/
|
*/
|
||||||
static int sqliteBtreeDelete(BtCursor *pCur){
|
static int fileBtreeDelete(BtCursor *pCur){
|
||||||
MemPage *pPage = pCur->pPage;
|
MemPage *pPage = pCur->pPage;
|
||||||
Cell *pCell;
|
Cell *pCell;
|
||||||
int rc;
|
int rc;
|
||||||
@ -2724,7 +2718,7 @@ static int sqliteBtreeDelete(BtCursor *pCur){
|
|||||||
int szNext;
|
int szNext;
|
||||||
int notUsed;
|
int notUsed;
|
||||||
getTempCursor(pCur, &leafCur);
|
getTempCursor(pCur, &leafCur);
|
||||||
rc = sqliteBtreeNext(&leafCur, ¬Used);
|
rc = fileBtreeNext(&leafCur, ¬Used);
|
||||||
if( rc!=SQLITE_OK ){
|
if( rc!=SQLITE_OK ){
|
||||||
return SQLITE_CORRUPT;
|
return SQLITE_CORRUPT;
|
||||||
}
|
}
|
||||||
@ -2764,11 +2758,12 @@ static int sqliteBtreeDelete(BtCursor *pCur){
|
|||||||
** number for the root page of the new table.
|
** number for the root page of the new table.
|
||||||
**
|
**
|
||||||
** In the current implementation, BTree tables and BTree indices are the
|
** 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
|
** 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.
|
** 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;
|
MemPage *pRoot;
|
||||||
Pgno pgnoRoot;
|
Pgno pgnoRoot;
|
||||||
int rc;
|
int rc;
|
||||||
@ -2788,19 +2783,6 @@ static int sqliteBtreeCreateTable(Btree *pBt, int *piTable){
|
|||||||
return SQLITE_OK;
|
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
|
** Erase the given database page and all its children. Return
|
||||||
** the page to the freelist.
|
** 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.
|
** 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;
|
int rc;
|
||||||
BtCursor *pCur;
|
BtCursor *pCur;
|
||||||
if( !pBt->inTrans ){
|
if( !pBt->inTrans ){
|
||||||
@ -2858,7 +2840,7 @@ static int sqliteBtreeClearTable(Btree *pBt, int iTable){
|
|||||||
}
|
}
|
||||||
rc = clearDatabasePage(pBt, (Pgno)iTable, 0);
|
rc = clearDatabasePage(pBt, (Pgno)iTable, 0);
|
||||||
if( rc ){
|
if( rc ){
|
||||||
sqliteBtreeRollback(pBt);
|
fileBtreeRollback(pBt);
|
||||||
}
|
}
|
||||||
return rc;
|
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
|
** the freelist. Except, the root of the principle table (the one on
|
||||||
** page 2) is never added to the freelist.
|
** page 2) is never added to the freelist.
|
||||||
*/
|
*/
|
||||||
static int sqliteBtreeDropTable(Btree *pBt, int iTable){
|
static int fileBtreeDropTable(Btree *pBt, int iTable){
|
||||||
int rc;
|
int rc;
|
||||||
MemPage *pPage;
|
MemPage *pPage;
|
||||||
BtCursor *pCur;
|
BtCursor *pCur;
|
||||||
@ -2882,7 +2864,7 @@ static int sqliteBtreeDropTable(Btree *pBt, int iTable){
|
|||||||
}
|
}
|
||||||
rc = sqlitepager_get(pBt->pPager, (Pgno)iTable, (void**)&pPage);
|
rc = sqlitepager_get(pBt->pPager, (Pgno)iTable, (void**)&pPage);
|
||||||
if( rc ) return rc;
|
if( rc ) return rc;
|
||||||
rc = sqliteBtreeClearTable(pBt, iTable);
|
rc = fileBtreeClearTable(pBt, iTable);
|
||||||
if( rc ) return rc;
|
if( rc ) return rc;
|
||||||
if( iTable>2 ){
|
if( iTable>2 ){
|
||||||
rc = freePage(pBt, pPage, iTable);
|
rc = freePage(pBt, pPage, iTable);
|
||||||
@ -2995,7 +2977,7 @@ static int copyDatabasePage(
|
|||||||
/*
|
/*
|
||||||
** Read the meta-information out of a database file.
|
** 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;
|
PageOne *pP1;
|
||||||
int rc;
|
int rc;
|
||||||
int i;
|
int i;
|
||||||
@ -3013,7 +2995,7 @@ static int sqliteBtreeGetMeta(Btree *pBt, int *aMeta){
|
|||||||
/*
|
/*
|
||||||
** Write meta-information back into the database.
|
** Write meta-information back into the database.
|
||||||
*/
|
*/
|
||||||
static int sqliteBtreeUpdateMeta(Btree *pBt, int *aMeta){
|
static int fileBtreeUpdateMeta(Btree *pBt, int *aMeta){
|
||||||
PageOne *pP1;
|
PageOne *pP1;
|
||||||
int rc, i;
|
int rc, i;
|
||||||
if( !pBt->inTrans ){
|
if( !pBt->inTrans ){
|
||||||
@ -3039,7 +3021,7 @@ static int sqliteBtreeUpdateMeta(Btree *pBt, int *aMeta){
|
|||||||
** is used for debugging and testing only.
|
** is used for debugging and testing only.
|
||||||
*/
|
*/
|
||||||
#ifdef SQLITE_TEST
|
#ifdef SQLITE_TEST
|
||||||
static int sqliteBtreePageDump(Btree *pBt, int pgno, int recursive){
|
static int fileBtreePageDump(Btree *pBt, int pgno, int recursive){
|
||||||
int rc;
|
int rc;
|
||||||
MemPage *pPage;
|
MemPage *pPage;
|
||||||
int i, j;
|
int i, j;
|
||||||
@ -3100,10 +3082,10 @@ static int sqliteBtreePageDump(Btree *pBt, int pgno, int recursive){
|
|||||||
idx = SWAB16(pBt, pPage->u.hdr.firstCell);
|
idx = SWAB16(pBt, pPage->u.hdr.firstCell);
|
||||||
while( idx>0 && idx<SQLITE_PAGE_SIZE-MIN_CELL_SIZE ){
|
while( idx>0 && idx<SQLITE_PAGE_SIZE-MIN_CELL_SIZE ){
|
||||||
Cell *pCell = (Cell*)&pPage->u.aDisk[idx];
|
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);
|
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);
|
sqlitepager_unref(pPage);
|
||||||
return SQLITE_OK;
|
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.
|
** 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;
|
int cnt, idx;
|
||||||
MemPage *pPage = pCur->pPage;
|
MemPage *pPage = pCur->pPage;
|
||||||
Btree *pBt = pCur->pBt;
|
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
|
** Return the pager associated with a BTree. This routine is used for
|
||||||
** testing and debugging only.
|
** testing and debugging only.
|
||||||
*/
|
*/
|
||||||
static Pager *sqliteBtreePager(Btree *pBt){
|
static Pager *fileBtreePager(Btree *pBt){
|
||||||
return pBt->pPager;
|
return pBt->pPager;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -3438,7 +3420,7 @@ static int checkTreePage(
|
|||||||
** and a pointer to that error message is returned. The calling function
|
** and a pointer to that error message is returned. The calling function
|
||||||
** is responsible for freeing the error message when it is done.
|
** 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 i;
|
||||||
int nRef;
|
int nRef;
|
||||||
IntegrityCk sCheck;
|
IntegrityCk sCheck;
|
||||||
@ -3502,7 +3484,7 @@ char *sqliteBtreeIntegrityCheck(Btree *pBt, int *aRoot, int nRoot){
|
|||||||
/*
|
/*
|
||||||
** Return the full pathname of the underlying database file.
|
** 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 );
|
assert( pBt->pPager!=0 );
|
||||||
return sqlitepager_filename(pBt->pPager);
|
return sqlitepager_filename(pBt->pPager);
|
||||||
}
|
}
|
||||||
@ -3510,7 +3492,7 @@ static const char *sqliteBtreeGetFilename(Btree *pBt){
|
|||||||
/*
|
/*
|
||||||
** Change the name of the underlying database file.
|
** 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);
|
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.
|
** to provide pointers to alternative functions in similar tables.
|
||||||
*/
|
*/
|
||||||
static BtOps sqliteBtreeOps = {
|
static BtOps sqliteBtreeOps = {
|
||||||
sqliteBtreeClose,
|
fileBtreeClose,
|
||||||
sqliteBtreeSetCacheSize,
|
fileBtreeSetCacheSize,
|
||||||
sqliteBtreeSetSafetyLevel,
|
fileBtreeSetSafetyLevel,
|
||||||
sqliteBtreeBeginTrans,
|
fileBtreeBeginTrans,
|
||||||
sqliteBtreeCommit,
|
fileBtreeCommit,
|
||||||
sqliteBtreeRollback,
|
fileBtreeRollback,
|
||||||
sqliteBtreeBeginCkpt,
|
fileBtreeBeginCkpt,
|
||||||
sqliteBtreeCommitCkpt,
|
fileBtreeCommitCkpt,
|
||||||
sqliteBtreeRollbackCkpt,
|
fileBtreeRollbackCkpt,
|
||||||
sqliteBtreeCreateTable,
|
fileBtreeCreateTable,
|
||||||
sqliteBtreeCreateIndex,
|
fileBtreeCreateTable, /* Really sqliteBtreeCreateIndex() */
|
||||||
sqliteBtreeDropTable,
|
fileBtreeDropTable,
|
||||||
sqliteBtreeClearTable,
|
fileBtreeClearTable,
|
||||||
sqliteBtreeCursor,
|
fileBtreeCursor,
|
||||||
sqliteBtreeGetMeta,
|
fileBtreeGetMeta,
|
||||||
sqliteBtreeUpdateMeta,
|
fileBtreeUpdateMeta,
|
||||||
sqliteBtreeIntegrityCheck,
|
fileBtreeIntegrityCheck,
|
||||||
sqliteBtreeGetFilename,
|
fileBtreeGetFilename,
|
||||||
sqliteBtreeChangeFilename,
|
fileBtreeChangeFilename,
|
||||||
#ifdef SQLITE_TEST
|
#ifdef SQLITE_TEST
|
||||||
sqliteBtreePageDump,
|
fileBtreePageDump,
|
||||||
sqliteBtreePager
|
fileBtreePager
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
static BtCursorOps sqliteBtreeCursorOps = {
|
static BtCursorOps sqliteBtreeCursorOps = {
|
||||||
sqliteBtreeMoveto,
|
fileBtreeMoveto,
|
||||||
sqliteBtreeDelete,
|
fileBtreeDelete,
|
||||||
sqliteBtreeInsert,
|
fileBtreeInsert,
|
||||||
sqliteBtreeFirst,
|
fileBtreeFirst,
|
||||||
sqliteBtreeLast,
|
fileBtreeLast,
|
||||||
sqliteBtreeNext,
|
fileBtreeNext,
|
||||||
sqliteBtreePrevious,
|
fileBtreePrevious,
|
||||||
sqliteBtreeKeySize,
|
fileBtreeKeySize,
|
||||||
sqliteBtreeKey,
|
fileBtreeKey,
|
||||||
sqliteBtreeKeyCompare,
|
fileBtreeKeyCompare,
|
||||||
sqliteBtreeDataSize,
|
fileBtreeDataSize,
|
||||||
sqliteBtreeData,
|
fileBtreeData,
|
||||||
sqliteBtreeCloseCursor,
|
fileBtreeCloseCursor,
|
||||||
#ifdef SQLITE_TEST
|
#ifdef SQLITE_TEST
|
||||||
sqliteBtreeCursorDump,
|
fileBtreeCursorDump,
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
10
src/btree.h
10
src/btree.h
@ -13,7 +13,7 @@
|
|||||||
** subsystem. See comments in the source code for a detailed description
|
** subsystem. See comments in the source code for a detailed description
|
||||||
** of what each interface routine does.
|
** 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_
|
#ifndef _BTREE_H_
|
||||||
#define _BTREE_H_
|
#define _BTREE_H_
|
||||||
@ -96,7 +96,6 @@ struct BtCursorOps {
|
|||||||
|
|
||||||
int sqliteBtreeOpen(const char *zFilename, int mode, int nPg, Btree **ppBtree);
|
int sqliteBtreeOpen(const char *zFilename, int mode, int nPg, Btree **ppBtree);
|
||||||
|
|
||||||
#if !defined(SQLITE_NO_BTREE_DEFS)
|
|
||||||
#define btOps(pBt) (*((BtOps **)(pBt)))
|
#define btOps(pBt) (*((BtOps **)(pBt)))
|
||||||
#define btCOps(pCur) (*((BtCursorOps **)(pCur)))
|
#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 sqliteBtreeGetFilename(pBt) (btOps(pBt)->GetFilename(pBt))
|
||||||
#define sqliteBtreeChangeFilename(pBt, zNew)\
|
#define sqliteBtreeChangeFilename(pBt, zNew)\
|
||||||
(btOps(pBt)->ChangeFilename(pBt, zNew))
|
(btOps(pBt)->ChangeFilename(pBt, zNew))
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SQLITE_TEST
|
#ifdef SQLITE_TEST
|
||||||
#if !defined(SQLITE_NO_BTREE_DEFS)
|
|
||||||
#define sqliteBtreePageDump(pBt, pgno, recursive)\
|
#define sqliteBtreePageDump(pBt, pgno, recursive)\
|
||||||
(btOps(pBt)->PageDump(pBt, pgno, recursive))
|
(btOps(pBt)->PageDump(pBt, pgno, recursive))
|
||||||
#define sqliteBtreeCursorDump(pCur, aResult)\
|
#define sqliteBtreeCursorDump(pCur, aResult)\
|
||||||
(btCOps(pCur)->CursorDump(pCur, aResult))
|
(btCOps(pCur)->CursorDump(pCur, aResult))
|
||||||
#define sqliteBtreePager(pBt) (btOps(pBt)->Pager(pBt))
|
#define sqliteBtreePager(pBt) (btOps(pBt)->Pager(pBt))
|
||||||
#endif
|
|
||||||
|
|
||||||
int btree_native_byte_order;
|
int btree_native_byte_order;
|
||||||
#endif
|
#endif /* SQLITE_TEST */
|
||||||
|
|
||||||
|
|
||||||
#endif /* _BTREE_H_ */
|
#endif /* _BTREE_H_ */
|
||||||
|
183
src/btree_rb.c
183
src/btree_rb.c
@ -9,14 +9,13 @@
|
|||||||
** May you share freely, never taking more than you give.
|
** 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
|
** This file implements an in-core database using Red-Black balanced
|
||||||
** binary trees.
|
** binary trees.
|
||||||
**
|
**
|
||||||
** It was contributed to SQLite by anonymous on 2003-Feb-04 23:24:49 UTC.
|
** It was contributed to SQLite by anonymous on 2003-Feb-04 23:24:49 UTC.
|
||||||
*/
|
*/
|
||||||
#define SQLITE_NO_BTREE_DEFS
|
|
||||||
#include "btree.h"
|
#include "btree.h"
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -127,11 +126,11 @@ struct BtRbNode {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
static int sqliteBtreeMoveto(BtCursor* pCur, const void *pKey, int nKey, int *pRes);
|
static int memBtreeMoveto(BtCursor* pCur, const void *pKey, int nKey,int *pRes);
|
||||||
static int sqliteBtreeClearTable(Btree* tree, int n);
|
static int memBtreeClearTable(Btree* tree, int n);
|
||||||
static int sqliteBtreeNext(BtCursor* pCur, int *pRes);
|
static int memBtreeNext(BtCursor* pCur, int *pRes);
|
||||||
static int sqliteBtreeLast(BtCursor* pCur, int *pRes);
|
static int memBtreeLast(BtCursor* pCur, int *pRes);
|
||||||
static int sqliteBtreePrevious(BtCursor* pCur, int *pRes);
|
static int memBtreePrevious(BtCursor* pCur, int *pRes);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The key-compare function for the red-black trees. Returns as follows:
|
* 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.
|
* Create a new table in the supplied Btree. Set *n to the new table number.
|
||||||
* Return SQLITE_OK if the operation is a success.
|
* 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 );
|
assert( tree->eTransState != TRANS_NONE );
|
||||||
|
|
||||||
@ -612,25 +611,15 @@ static int sqliteBtreeCreateTable(Btree* tree, int* n)
|
|||||||
return SQLITE_OK;
|
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.
|
* Delete table n from the supplied Btree.
|
||||||
*/
|
*/
|
||||||
static int sqliteBtreeDropTable(Btree* tree, int n)
|
static int memBtreeDropTable(Btree* tree, int n)
|
||||||
{
|
{
|
||||||
BtRbTree *pTree;
|
BtRbTree *pTree;
|
||||||
assert( tree->eTransState != TRANS_NONE );
|
assert( tree->eTransState != TRANS_NONE );
|
||||||
|
|
||||||
sqliteBtreeClearTable(tree, n);
|
memBtreeClearTable(tree, n);
|
||||||
pTree = sqliteHashFind(&tree->tblHash, 0, n);
|
pTree = sqliteHashFind(&tree->tblHash, 0, n);
|
||||||
assert(pTree);
|
assert(pTree);
|
||||||
sqliteFree(pTree);
|
sqliteFree(pTree);
|
||||||
@ -646,7 +635,7 @@ static int sqliteBtreeDropTable(Btree* tree, int n)
|
|||||||
return SQLITE_OK;
|
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)
|
int nIgnore, int *pRes)
|
||||||
{
|
{
|
||||||
assert(pCur);
|
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.
|
* 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);
|
assert(tree);
|
||||||
*ppCur = sqliteMalloc(sizeof(BtCursor));
|
*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.
|
* 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)
|
const void *pDataInput, int nData)
|
||||||
{
|
{
|
||||||
void * pData;
|
void * pData;
|
||||||
@ -716,7 +705,7 @@ static int sqliteBtreeInsert(BtCursor* pCur, const void *pKey, int nKey,
|
|||||||
*
|
*
|
||||||
* The new node is initially red.
|
* The new node is initially red.
|
||||||
*/
|
*/
|
||||||
sqliteBtreeMoveto( pCur, pKey, nKey, &match);
|
memBtreeMoveto( pCur, pKey, nKey, &match);
|
||||||
if( match ){
|
if( match ){
|
||||||
BtRbNode *pNode = sqliteMalloc(sizeof(BtRbNode));
|
BtRbNode *pNode = sqliteMalloc(sizeof(BtRbNode));
|
||||||
pNode->nKey = nKey;
|
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
|
** *pRes>0 The cursor is left pointing at an entry that
|
||||||
** is larger than pKey.
|
** 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;
|
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
|
** sqliteBtreePrevious() will always leave the cursor pointing at the
|
||||||
** entry immediately before the one that was deleted.
|
** 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 *pZ; /* The one being deleted */
|
||||||
BtRbNode *pChild; /* The child of the spliced out node */
|
BtRbNode *pChild; /* The child of the spliced out node */
|
||||||
@ -880,7 +869,7 @@ static int sqliteBtreeDelete(BtCursor* pCur)
|
|||||||
BtRbNode *pTmp;
|
BtRbNode *pTmp;
|
||||||
int dummy;
|
int dummy;
|
||||||
pCur->eSkip = SKIP_NONE;
|
pCur->eSkip = SKIP_NONE;
|
||||||
sqliteBtreeNext(pCur, &dummy);
|
memBtreeNext(pCur, &dummy);
|
||||||
assert( dummy == 0 );
|
assert( dummy == 0 );
|
||||||
if( pCur->pBtree->eTransState == TRANS_ROLLBACK ){
|
if( pCur->pBtree->eTransState == TRANS_ROLLBACK ){
|
||||||
sqliteFree(pZ->pKey);
|
sqliteFree(pZ->pKey);
|
||||||
@ -897,11 +886,11 @@ static int sqliteBtreeDelete(BtCursor* pCur)
|
|||||||
}else{
|
}else{
|
||||||
int res;
|
int res;
|
||||||
pCur->eSkip = SKIP_NONE;
|
pCur->eSkip = SKIP_NONE;
|
||||||
sqliteBtreeNext(pCur, &res);
|
memBtreeNext(pCur, &res);
|
||||||
pCur->eSkip = SKIP_NEXT;
|
pCur->eSkip = SKIP_NEXT;
|
||||||
if( res ){
|
if( res ){
|
||||||
sqliteBtreeLast(pCur, &res);
|
memBtreeLast(pCur, &res);
|
||||||
sqliteBtreePrevious(pCur, &res);
|
memBtreePrevious(pCur, &res);
|
||||||
pCur->eSkip = SKIP_PREV;
|
pCur->eSkip = SKIP_PREV;
|
||||||
}
|
}
|
||||||
if( pCur->pBtree->eTransState == TRANS_ROLLBACK ){
|
if( pCur->pBtree->eTransState == TRANS_ROLLBACK ){
|
||||||
@ -943,7 +932,7 @@ static int sqliteBtreeDelete(BtCursor* pCur)
|
|||||||
/*
|
/*
|
||||||
* Empty table n of the Btree.
|
* Empty table n of the Btree.
|
||||||
*/
|
*/
|
||||||
static int sqliteBtreeClearTable(Btree* tree, int n)
|
static int memBtreeClearTable(Btree* tree, int n)
|
||||||
{
|
{
|
||||||
BtRbTree *pTree;
|
BtRbTree *pTree;
|
||||||
BtRbNode *pNode;
|
BtRbNode *pNode;
|
||||||
@ -987,7 +976,7 @@ static int sqliteBtreeClearTable(Btree* tree, int n)
|
|||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sqliteBtreeFirst(BtCursor* pCur, int *pRes)
|
static int memBtreeFirst(BtCursor* pCur, int *pRes)
|
||||||
{
|
{
|
||||||
if( pCur->pTree->pHead ){
|
if( pCur->pTree->pHead ){
|
||||||
pCur->pNode = pCur->pTree->pHead;
|
pCur->pNode = pCur->pTree->pHead;
|
||||||
@ -1004,7 +993,7 @@ static int sqliteBtreeFirst(BtCursor* pCur, int *pRes)
|
|||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sqliteBtreeLast(BtCursor* pCur, int *pRes)
|
static int memBtreeLast(BtCursor* pCur, int *pRes)
|
||||||
{
|
{
|
||||||
if( pCur->pTree->pHead ){
|
if( pCur->pTree->pHead ){
|
||||||
pCur->pNode = pCur->pTree->pHead;
|
pCur->pNode = pCur->pTree->pHead;
|
||||||
@ -1021,7 +1010,7 @@ static int sqliteBtreeLast(BtCursor* pCur, int *pRes)
|
|||||||
return SQLITE_OK;
|
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 && pCur->eSkip != SKIP_NEXT ){
|
||||||
if( pCur->pNode->pRight ){
|
if( pCur->pNode->pRight ){
|
||||||
@ -1048,7 +1037,7 @@ static int sqliteBtreeNext(BtCursor* pCur, int *pRes)
|
|||||||
return SQLITE_OK;
|
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 && pCur->eSkip != SKIP_PREV ){
|
||||||
if( pCur->pNode->pLeft ){
|
if( pCur->pNode->pLeft ){
|
||||||
@ -1075,7 +1064,7 @@ static int sqliteBtreePrevious(BtCursor* pCur, int *pRes)
|
|||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sqliteBtreeKeySize(BtCursor* pCur, int *pSize)
|
static int memBtreeKeySize(BtCursor* pCur, int *pSize)
|
||||||
{
|
{
|
||||||
if( pCur->pNode ){
|
if( pCur->pNode ){
|
||||||
*pSize = pCur->pNode->nKey;
|
*pSize = pCur->pNode->nKey;
|
||||||
@ -1085,7 +1074,7 @@ static int sqliteBtreeKeySize(BtCursor* pCur, int *pSize)
|
|||||||
return SQLITE_OK;
|
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 ) return 0;
|
||||||
if( !pCur->pNode->pKey || ((amt + offset) <= pCur->pNode->nKey) ){
|
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);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sqliteBtreeDataSize(BtCursor* pCur, int *pSize)
|
static int memBtreeDataSize(BtCursor* pCur, int *pSize)
|
||||||
{
|
{
|
||||||
if( pCur->pNode ){
|
if( pCur->pNode ){
|
||||||
*pSize = pCur->pNode->nData;
|
*pSize = pCur->pNode->nData;
|
||||||
@ -1108,7 +1097,7 @@ static int sqliteBtreeDataSize(BtCursor* pCur, int *pSize)
|
|||||||
return SQLITE_OK;
|
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( !pCur->pNode ) return 0;
|
||||||
if( (amt + offset) <= pCur->pNode->nData ){
|
if( (amt + offset) <= pCur->pNode->nData ){
|
||||||
@ -1121,19 +1110,19 @@ static int sqliteBtreeData(BtCursor *pCur, int offset, int amt, char *zBuf)
|
|||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sqliteBtreeCloseCursor(BtCursor* pCur)
|
static int memBtreeCloseCursor(BtCursor* pCur)
|
||||||
{
|
{
|
||||||
sqliteFree(pCur);
|
sqliteFree(pCur);
|
||||||
return SQLITE_OK;
|
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 );
|
memcpy( aMeta, tree->aMetaData, sizeof(int) * SQLITE_N_BTREE_META );
|
||||||
return SQLITE_OK;
|
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 );
|
memcpy( tree->aMetaData, aMeta, sizeof(int) * SQLITE_N_BTREE_META );
|
||||||
return SQLITE_OK;
|
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
|
* binary tree. If an error is found, return an explanation of the problem in
|
||||||
* memory obtained from sqliteMalloc(). Parameters aRoot and nRoot are ignored.
|
* 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;
|
char * msg = 0;
|
||||||
HashElem *p;
|
HashElem *p;
|
||||||
@ -1160,28 +1149,28 @@ static char *sqliteBtreeIntegrityCheck(Btree* tree, int* aRoot, int nRoot)
|
|||||||
/*
|
/*
|
||||||
* Close the supplied Btree. Delete everything associated with it.
|
* Close the supplied Btree. Delete everything associated with it.
|
||||||
*/
|
*/
|
||||||
static int sqliteBtreeClose(Btree* tree)
|
static int memBtreeClose(Btree* tree)
|
||||||
{
|
{
|
||||||
HashElem *p;
|
HashElem *p;
|
||||||
for(p=sqliteHashFirst(&tree->tblHash); p; p=sqliteHashNext(p)){
|
for(p=sqliteHashFirst(&tree->tblHash); p; p=sqliteHashNext(p)){
|
||||||
tree->eTransState = TRANS_ROLLBACK;
|
tree->eTransState = TRANS_ROLLBACK;
|
||||||
sqliteBtreeClearTable(tree, sqliteHashKeysize(p));
|
memBtreeClearTable(tree, sqliteHashKeysize(p));
|
||||||
sqliteFree(sqliteHashData(p));
|
sqliteFree(sqliteHashData(p));
|
||||||
}
|
}
|
||||||
sqliteFree(tree);
|
sqliteFree(tree);
|
||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sqliteBtreeSetCacheSize(Btree* tree, int sz)
|
static int memBtreeSetCacheSize(Btree* tree, int sz)
|
||||||
{
|
{
|
||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sqliteBtreeSetSafetyLevel(Btree *pBt, int level){
|
static int memBtreeSetSafetyLevel(Btree *pBt, int level){
|
||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sqliteBtreeBeginTrans(Btree* tree)
|
static int memBtreeBeginTrans(Btree* tree)
|
||||||
{
|
{
|
||||||
if( tree->eTransState != TRANS_NONE )
|
if( tree->eTransState != TRANS_NONE )
|
||||||
return SQLITE_ERROR;
|
return SQLITE_ERROR;
|
||||||
@ -1191,7 +1180,7 @@ static int sqliteBtreeBeginTrans(Btree* tree)
|
|||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sqliteBtreeCommit(Btree* tree)
|
static int memBtreeCommit(Btree* tree)
|
||||||
{
|
{
|
||||||
/* Just delete pTransRollback and pCheckRollback */
|
/* Just delete pTransRollback and pCheckRollback */
|
||||||
BtRollbackOp *pOp, *pTmp;
|
BtRollbackOp *pOp, *pTmp;
|
||||||
@ -1235,7 +1224,7 @@ static void execute_rollback_list(Btree *pBtree, BtRollbackOp *pList)
|
|||||||
assert(cur.pTree);
|
assert(cur.pTree);
|
||||||
cur.iTree = pList->iTab;
|
cur.iTree = pList->iTab;
|
||||||
cur.eSkip = SKIP_NONE;
|
cur.eSkip = SKIP_NONE;
|
||||||
sqliteBtreeInsert( &cur, pList->pKey,
|
memBtreeInsert( &cur, pList->pKey,
|
||||||
pList->nKey, pList->pData, pList->nData );
|
pList->nKey, pList->pData, pList->nData );
|
||||||
break;
|
break;
|
||||||
case ROLLBACK_DELETE:
|
case ROLLBACK_DELETE:
|
||||||
@ -1243,15 +1232,15 @@ static void execute_rollback_list(Btree *pBtree, BtRollbackOp *pList)
|
|||||||
assert(cur.pTree);
|
assert(cur.pTree);
|
||||||
cur.iTree = pList->iTab;
|
cur.iTree = pList->iTab;
|
||||||
cur.eSkip = SKIP_NONE;
|
cur.eSkip = SKIP_NONE;
|
||||||
sqliteBtreeMoveto(&cur, pList->pKey, pList->nKey, &res);
|
memBtreeMoveto(&cur, pList->pKey, pList->nKey, &res);
|
||||||
assert(res == 0);
|
assert(res == 0);
|
||||||
sqliteBtreeDelete( &cur );
|
memBtreeDelete( &cur );
|
||||||
break;
|
break;
|
||||||
case ROLLBACK_CREATE:
|
case ROLLBACK_CREATE:
|
||||||
btreeCreateTable(pBtree, pList->iTab);
|
btreeCreateTable(pBtree, pList->iTab);
|
||||||
break;
|
break;
|
||||||
case ROLLBACK_DROP:
|
case ROLLBACK_DROP:
|
||||||
sqliteBtreeDropTable(pBtree, pList->iTab);
|
memBtreeDropTable(pBtree, pList->iTab);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
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;
|
tree->eTransState = TRANS_ROLLBACK;
|
||||||
execute_rollback_list(tree, tree->pCheckRollback);
|
execute_rollback_list(tree, tree->pCheckRollback);
|
||||||
@ -1276,7 +1265,7 @@ static int sqliteBtreeRollback(Btree* tree)
|
|||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sqliteBtreeBeginCkpt(Btree* tree)
|
static int memBtreeBeginCkpt(Btree* tree)
|
||||||
{
|
{
|
||||||
if( tree->eTransState != TRANS_INTRANSACTION )
|
if( tree->eTransState != TRANS_INTRANSACTION )
|
||||||
return SQLITE_ERROR;
|
return SQLITE_ERROR;
|
||||||
@ -1287,7 +1276,7 @@ static int sqliteBtreeBeginCkpt(Btree* tree)
|
|||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sqliteBtreeCommitCkpt(Btree* tree)
|
static int memBtreeCommitCkpt(Btree* tree)
|
||||||
{
|
{
|
||||||
if( tree->eTransState == TRANS_INCHECKPOINT ){
|
if( tree->eTransState == TRANS_INCHECKPOINT ){
|
||||||
if( tree->pCheckRollback ){
|
if( tree->pCheckRollback ){
|
||||||
@ -1301,7 +1290,7 @@ static int sqliteBtreeCommitCkpt(Btree* tree)
|
|||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sqliteBtreeRollbackCkpt(Btree* tree)
|
static int memBtreeRollbackCkpt(Btree* tree)
|
||||||
{
|
{
|
||||||
if( tree->eTransState != TRANS_INCHECKPOINT ) return SQLITE_OK;
|
if( tree->eTransState != TRANS_INCHECKPOINT ) return SQLITE_OK;
|
||||||
tree->eTransState = TRANS_ROLLBACK;
|
tree->eTransState = TRANS_ROLLBACK;
|
||||||
@ -1314,19 +1303,19 @@ static int sqliteBtreeRollbackCkpt(Btree* tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SQLITE_TEST
|
#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");
|
assert(!"Cannot call sqliteBtreePageDump");
|
||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sqliteBtreeCursorDump(BtCursor* pCur, int* aRes)
|
static int memBtreeCursorDump(BtCursor* pCur, int* aRes)
|
||||||
{
|
{
|
||||||
assert(!"Cannot call sqliteBtreeCursorDump");
|
assert(!"Cannot call sqliteBtreeCursorDump");
|
||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct Pager *sqliteBtreePager(Btree* tree)
|
static struct Pager *memBtreePager(Btree* tree)
|
||||||
{
|
{
|
||||||
assert(!"Cannot call sqliteBtreePager");
|
assert(!"Cannot call sqliteBtreePager");
|
||||||
return SQLITE_OK;
|
return SQLITE_OK;
|
||||||
@ -1336,60 +1325,60 @@ static struct Pager *sqliteBtreePager(Btree* tree)
|
|||||||
/*
|
/*
|
||||||
** Return the full pathname of the underlying database file.
|
** Return the full pathname of the underlying database file.
|
||||||
*/
|
*/
|
||||||
static const char *sqliteBtreeGetFilename(Btree *pBt){
|
static const char *memBtreeGetFilename(Btree *pBt){
|
||||||
return ":memory:";
|
return ":memory:";
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Change the name of the underlying database file.
|
** 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;
|
return SQLITE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BtOps sqliteBtreeOps = {
|
static BtOps sqliteBtreeOps = {
|
||||||
sqliteBtreeClose,
|
memBtreeClose,
|
||||||
sqliteBtreeSetCacheSize,
|
memBtreeSetCacheSize,
|
||||||
sqliteBtreeSetSafetyLevel,
|
memBtreeSetSafetyLevel,
|
||||||
sqliteBtreeBeginTrans,
|
memBtreeBeginTrans,
|
||||||
sqliteBtreeCommit,
|
memBtreeCommit,
|
||||||
sqliteBtreeRollback,
|
memBtreeRollback,
|
||||||
sqliteBtreeBeginCkpt,
|
memBtreeBeginCkpt,
|
||||||
sqliteBtreeCommitCkpt,
|
memBtreeCommitCkpt,
|
||||||
sqliteBtreeRollbackCkpt,
|
memBtreeRollbackCkpt,
|
||||||
sqliteBtreeCreateTable,
|
memBtreeCreateTable,
|
||||||
sqliteBtreeCreateIndex,
|
memBtreeCreateTable,
|
||||||
sqliteBtreeDropTable,
|
memBtreeDropTable,
|
||||||
sqliteBtreeClearTable,
|
memBtreeClearTable,
|
||||||
sqliteBtreeCursor,
|
memBtreeCursor,
|
||||||
sqliteBtreeGetMeta,
|
memBtreeGetMeta,
|
||||||
sqliteBtreeUpdateMeta,
|
memBtreeUpdateMeta,
|
||||||
sqliteBtreeIntegrityCheck,
|
memBtreeIntegrityCheck,
|
||||||
sqliteBtreeGetFilename,
|
memBtreeGetFilename,
|
||||||
sqliteBtreeChangeFilename,
|
memBtreeChangeFilename,
|
||||||
|
|
||||||
#ifdef SQLITE_TEST
|
#ifdef SQLITE_TEST
|
||||||
sqliteBtreePageDump,
|
memBtreePageDump,
|
||||||
sqliteBtreePager
|
memBtreePager
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static BtCursorOps sqliteBtreeCursorOps = {
|
static BtCursorOps sqliteBtreeCursorOps = {
|
||||||
sqliteBtreeMoveto,
|
memBtreeMoveto,
|
||||||
sqliteBtreeDelete,
|
memBtreeDelete,
|
||||||
sqliteBtreeInsert,
|
memBtreeInsert,
|
||||||
sqliteBtreeFirst,
|
memBtreeFirst,
|
||||||
sqliteBtreeLast,
|
memBtreeLast,
|
||||||
sqliteBtreeNext,
|
memBtreeNext,
|
||||||
sqliteBtreePrevious,
|
memBtreePrevious,
|
||||||
sqliteBtreeKeySize,
|
memBtreeKeySize,
|
||||||
sqliteBtreeKey,
|
memBtreeKey,
|
||||||
sqliteBtreeKeyCompare,
|
memBtreeKeyCompare,
|
||||||
sqliteBtreeDataSize,
|
memBtreeDataSize,
|
||||||
sqliteBtreeData,
|
memBtreeData,
|
||||||
sqliteBtreeCloseCursor,
|
memBtreeCloseCursor,
|
||||||
#ifdef SQLITE_TEST
|
#ifdef SQLITE_TEST
|
||||||
sqliteBtreeCursorDump,
|
memBtreeCursorDump,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
** other files are for internal use by SQLite and should not be
|
** other files are for internal use by SQLite and should not be
|
||||||
** accessed by users of the library.
|
** 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 "sqliteInt.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
@ -426,7 +426,7 @@ sqlite *sqlite_open(const char *zFilename, int mode, char **pzErrMsg){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Open the backend database driver */
|
/* 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 ){
|
if( rc!=SQLITE_OK ){
|
||||||
switch( rc ){
|
switch( rc ){
|
||||||
default: {
|
default: {
|
||||||
@ -1065,8 +1065,6 @@ void *sqlite_commit_hook(
|
|||||||
** is for temporary use only and is deleted as soon as the connection
|
** is for temporary use only and is deleted as soon as the connection
|
||||||
** is closed.
|
** is closed.
|
||||||
**
|
**
|
||||||
**
|
|
||||||
**
|
|
||||||
** A temporary database can be either a disk file (that is automatically
|
** 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,
|
** 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
|
** depending on the values of the TEMP_STORE compile-time macro and the
|
||||||
|
Reference in New Issue
Block a user