2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/*
2N/A** 2001 September 15
2N/A**
2N/A** The author disclaims copyright to this source code. In place of
2N/A** a legal notice, here is a blessing:
2N/A**
2N/A** May you do good and not evil.
2N/A** May you find forgiveness for yourself and forgive others.
2N/A** May you share freely, never taking more than you give.
2N/A**
2N/A*************************************************************************
2N/A** This header file defines the interface that the sqlite B-Tree file
2N/A** subsystem. See comments in the source code for a detailed description
2N/A** of what each interface routine does.
2N/A**
2N/A** @(#) $Id: btree.h,v 1.36 2004/02/10 02:57:59 drh Exp $
2N/A*/
2N/A#ifndef _BTREE_H_
2N/A#define _BTREE_H_
2N/A
2N/A/*
2N/A** Forward declarations of structure
2N/A*/
2N/Atypedef struct Btree Btree;
2N/Atypedef struct BtCursor BtCursor;
2N/Atypedef struct BtOps BtOps;
2N/Atypedef struct BtCursorOps BtCursorOps;
2N/A
2N/A
2N/A/*
2N/A** An instance of the following structure contains pointers to all
2N/A** methods against an open BTree. Alternative BTree implementations
2N/A** (examples: file based versus in-memory) can be created by substituting
2N/A** different methods. Users of the BTree cannot tell the difference.
2N/A**
2N/A** In C++ we could do this by defining a virtual base class and then
2N/A** creating subclasses for each different implementation. But this is
2N/A** C not C++ so we have to be a little more explicit.
2N/A*/
2N/Astruct BtOps {
2N/A int (*Close)(Btree*);
2N/A int (*SetCacheSize)(Btree*, int);
2N/A int (*SetSafetyLevel)(Btree*, int);
2N/A int (*BeginTrans)(Btree*);
2N/A int (*Commit)(Btree*);
2N/A int (*Rollback)(Btree*);
2N/A int (*BeginCkpt)(Btree*);
2N/A int (*CommitCkpt)(Btree*);
2N/A int (*RollbackCkpt)(Btree*);
2N/A int (*CreateTable)(Btree*, int*);
2N/A int (*CreateIndex)(Btree*, int*);
2N/A int (*DropTable)(Btree*, int);
2N/A int (*ClearTable)(Btree*, int);
2N/A int (*Cursor)(Btree*, int iTable, int wrFlag, BtCursor **ppCur);
2N/A int (*GetMeta)(Btree*, int*);
2N/A int (*UpdateMeta)(Btree*, int*);
2N/A char *(*IntegrityCheck)(Btree*, int*, int);
2N/A const char *(*GetFilename)(Btree*);
2N/A int (*Copyfile)(Btree*,Btree*);
2N/A struct Pager *(*Pager)(Btree*);
2N/A#ifdef SQLITE_TEST
2N/A int (*PageDump)(Btree*, int, int);
2N/A#endif
2N/A};
2N/A
2N/A/*
2N/A** An instance of this structure defines all of the methods that can
2N/A** be executed against a cursor.
2N/A*/
2N/Astruct BtCursorOps {
2N/A int (*Moveto)(BtCursor*, const void *pKey, int nKey, int *pRes);
2N/A int (*Delete)(BtCursor*);
2N/A int (*Insert)(BtCursor*, const void *pKey, int nKey,
2N/A const void *pData, int nData);
2N/A int (*First)(BtCursor*, int *pRes);
2N/A int (*Last)(BtCursor*, int *pRes);
2N/A int (*Next)(BtCursor*, int *pRes);
2N/A int (*Previous)(BtCursor*, int *pRes);
2N/A int (*KeySize)(BtCursor*, int *pSize);
2N/A int (*Key)(BtCursor*, int offset, int amt, char *zBuf);
2N/A int (*KeyCompare)(BtCursor*, const void *pKey, int nKey,
2N/A int nIgnore, int *pRes);
2N/A int (*DataSize)(BtCursor*, int *pSize);
2N/A int (*Data)(BtCursor*, int offset, int amt, char *zBuf);
2N/A int (*CloseCursor)(BtCursor*);
2N/A#ifdef SQLITE_TEST
2N/A int (*CursorDump)(BtCursor*, int*);
2N/A#endif
2N/A};
2N/A
2N/A/*
2N/A** The number of 4-byte "meta" values contained on the first page of each
2N/A** database file.
2N/A*/
2N/A#define SQLITE_N_BTREE_META 10
2N/A
2N/Aint sqliteBtreeOpen(const char *zFilename, int mode, int nPg, Btree **ppBtree);
2N/Aint sqliteRbtreeOpen(const char *zFilename, int mode, int nPg, Btree **ppBtree);
2N/A
2N/A#define btOps(pBt) (*((BtOps **)(pBt)))
2N/A#define btCOps(pCur) (*((BtCursorOps **)(pCur)))
2N/A
2N/A#define sqliteBtreeClose(pBt) (btOps(pBt)->Close(pBt))
2N/A#define sqliteBtreeSetCacheSize(pBt, sz) (btOps(pBt)->SetCacheSize(pBt, sz))
2N/A#define sqliteBtreeSetSafetyLevel(pBt, sl) (btOps(pBt)->SetSafetyLevel(pBt, sl))
2N/A#define sqliteBtreeBeginTrans(pBt) (btOps(pBt)->BeginTrans(pBt))
2N/A#define sqliteBtreeCommit(pBt) (btOps(pBt)->Commit(pBt))
2N/A#define sqliteBtreeRollback(pBt) (btOps(pBt)->Rollback(pBt))
2N/A#define sqliteBtreeBeginCkpt(pBt) (btOps(pBt)->BeginCkpt(pBt))
2N/A#define sqliteBtreeCommitCkpt(pBt) (btOps(pBt)->CommitCkpt(pBt))
2N/A#define sqliteBtreeRollbackCkpt(pBt) (btOps(pBt)->RollbackCkpt(pBt))
2N/A#define sqliteBtreeCreateTable(pBt,piTable)\
2N/A (btOps(pBt)->CreateTable(pBt,piTable))
2N/A#define sqliteBtreeCreateIndex(pBt, piIndex)\
2N/A (btOps(pBt)->CreateIndex(pBt, piIndex))
2N/A#define sqliteBtreeDropTable(pBt, iTable) (btOps(pBt)->DropTable(pBt, iTable))
2N/A#define sqliteBtreeClearTable(pBt, iTable)\
2N/A (btOps(pBt)->ClearTable(pBt, iTable))
2N/A#define sqliteBtreeCursor(pBt, iTable, wrFlag, ppCur)\
2N/A (btOps(pBt)->Cursor(pBt, iTable, wrFlag, ppCur))
2N/A#define sqliteBtreeMoveto(pCur, pKey, nKey, pRes)\
2N/A (btCOps(pCur)->Moveto(pCur, pKey, nKey, pRes))
2N/A#define sqliteBtreeDelete(pCur) (btCOps(pCur)->Delete(pCur))
2N/A#define sqliteBtreeInsert(pCur, pKey, nKey, pData, nData) \
2N/A (btCOps(pCur)->Insert(pCur, pKey, nKey, pData, nData))
2N/A#define sqliteBtreeFirst(pCur, pRes) (btCOps(pCur)->First(pCur, pRes))
2N/A#define sqliteBtreeLast(pCur, pRes) (btCOps(pCur)->Last(pCur, pRes))
2N/A#define sqliteBtreeNext(pCur, pRes) (btCOps(pCur)->Next(pCur, pRes))
2N/A#define sqliteBtreePrevious(pCur, pRes) (btCOps(pCur)->Previous(pCur, pRes))
2N/A#define sqliteBtreeKeySize(pCur, pSize) (btCOps(pCur)->KeySize(pCur, pSize) )
2N/A#define sqliteBtreeKey(pCur, offset, amt, zBuf)\
2N/A (btCOps(pCur)->Key(pCur, offset, amt, zBuf))
2N/A#define sqliteBtreeKeyCompare(pCur, pKey, nKey, nIgnore, pRes)\
2N/A (btCOps(pCur)->KeyCompare(pCur, pKey, nKey, nIgnore, pRes))
2N/A#define sqliteBtreeDataSize(pCur, pSize) (btCOps(pCur)->DataSize(pCur, pSize))
2N/A#define sqliteBtreeData(pCur, offset, amt, zBuf)\
2N/A (btCOps(pCur)->Data(pCur, offset, amt, zBuf))
2N/A#define sqliteBtreeCloseCursor(pCur) (btCOps(pCur)->CloseCursor(pCur))
2N/A#define sqliteBtreeGetMeta(pBt, aMeta) (btOps(pBt)->GetMeta(pBt, aMeta))
2N/A#define sqliteBtreeUpdateMeta(pBt, aMeta) (btOps(pBt)->UpdateMeta(pBt, aMeta))
2N/A#define sqliteBtreeIntegrityCheck(pBt, aRoot, nRoot)\
2N/A (btOps(pBt)->IntegrityCheck(pBt, aRoot, nRoot))
2N/A#define sqliteBtreeGetFilename(pBt) (btOps(pBt)->GetFilename(pBt))
2N/A#define sqliteBtreeCopyFile(pBt1, pBt2) (btOps(pBt1)->Copyfile(pBt1, pBt2))
2N/A#define sqliteBtreePager(pBt) (btOps(pBt)->Pager(pBt))
2N/A
2N/A#ifdef SQLITE_TEST
2N/A#define sqliteBtreePageDump(pBt, pgno, recursive)\
2N/A (btOps(pBt)->PageDump(pBt, pgno, recursive))
2N/A#define sqliteBtreeCursorDump(pCur, aResult)\
2N/A (btCOps(pCur)->CursorDump(pCur, aResult))
2N/Aint btree_native_byte_order;
2N/A#endif /* SQLITE_TEST */
2N/A
2N/A
2N/A#endif /* _BTREE_H_ */