Annotation of embedaddon/php/ext/sqlite/libsqlite/src/btree.h, revision 1.1
1.1 ! misho 1: /*
! 2: ** 2001 September 15
! 3: **
! 4: ** The author disclaims copyright to this source code. In place of
! 5: ** a legal notice, here is a blessing:
! 6: **
! 7: ** May you do good and not evil.
! 8: ** May you find forgiveness for yourself and forgive others.
! 9: ** May you share freely, never taking more than you give.
! 10: **
! 11: *************************************************************************
! 12: ** This header file defines the interface that the sqlite B-Tree file
! 13: ** subsystem. See comments in the source code for a detailed description
! 14: ** of what each interface routine does.
! 15: **
! 16: ** @(#) $Id: btree.h 195361 2005-09-07 15:11:33Z iliaa $
! 17: */
! 18: #ifndef _BTREE_H_
! 19: #define _BTREE_H_
! 20:
! 21: /*
! 22: ** Forward declarations of structure
! 23: */
! 24: typedef struct Btree Btree;
! 25: typedef struct BtCursor BtCursor;
! 26: typedef struct BtOps BtOps;
! 27: typedef struct BtCursorOps BtCursorOps;
! 28:
! 29:
! 30: /*
! 31: ** An instance of the following structure contains pointers to all
! 32: ** methods against an open BTree. Alternative BTree implementations
! 33: ** (examples: file based versus in-memory) can be created by substituting
! 34: ** different methods. Users of the BTree cannot tell the difference.
! 35: **
! 36: ** In C++ we could do this by defining a virtual base class and then
! 37: ** creating subclasses for each different implementation. But this is
! 38: ** C not C++ so we have to be a little more explicit.
! 39: */
! 40: struct BtOps {
! 41: int (*Close)(Btree*);
! 42: int (*SetCacheSize)(Btree*, int);
! 43: int (*SetSafetyLevel)(Btree*, int);
! 44: int (*BeginTrans)(Btree*);
! 45: int (*Commit)(Btree*);
! 46: int (*Rollback)(Btree*);
! 47: int (*BeginCkpt)(Btree*);
! 48: int (*CommitCkpt)(Btree*);
! 49: int (*RollbackCkpt)(Btree*);
! 50: int (*CreateTable)(Btree*, int*);
! 51: int (*CreateIndex)(Btree*, int*);
! 52: int (*DropTable)(Btree*, int);
! 53: int (*ClearTable)(Btree*, int);
! 54: int (*Cursor)(Btree*, int iTable, int wrFlag, BtCursor **ppCur);
! 55: int (*GetMeta)(Btree*, int*);
! 56: int (*UpdateMeta)(Btree*, int*);
! 57: char *(*IntegrityCheck)(Btree*, int*, int);
! 58: const char *(*GetFilename)(Btree*);
! 59: int (*Copyfile)(Btree*,Btree*);
! 60: struct Pager *(*Pager)(Btree*);
! 61: #ifdef SQLITE_TEST
! 62: int (*PageDump)(Btree*, int, int);
! 63: #endif
! 64: };
! 65:
! 66: /*
! 67: ** An instance of this structure defines all of the methods that can
! 68: ** be executed against a cursor.
! 69: */
! 70: struct BtCursorOps {
! 71: int (*Moveto)(BtCursor*, const void *pKey, int nKey, int *pRes);
! 72: int (*Delete)(BtCursor*);
! 73: int (*Insert)(BtCursor*, const void *pKey, int nKey,
! 74: const void *pData, int nData);
! 75: int (*First)(BtCursor*, int *pRes);
! 76: int (*Last)(BtCursor*, int *pRes);
! 77: int (*Next)(BtCursor*, int *pRes);
! 78: int (*Previous)(BtCursor*, int *pRes);
! 79: int (*KeySize)(BtCursor*, int *pSize);
! 80: int (*Key)(BtCursor*, int offset, int amt, char *zBuf);
! 81: int (*KeyCompare)(BtCursor*, const void *pKey, int nKey,
! 82: int nIgnore, int *pRes);
! 83: int (*DataSize)(BtCursor*, int *pSize);
! 84: int (*Data)(BtCursor*, int offset, int amt, char *zBuf);
! 85: int (*CloseCursor)(BtCursor*);
! 86: #ifdef SQLITE_TEST
! 87: int (*CursorDump)(BtCursor*, int*);
! 88: #endif
! 89: };
! 90:
! 91: /*
! 92: ** The number of 4-byte "meta" values contained on the first page of each
! 93: ** database file.
! 94: */
! 95: #define SQLITE_N_BTREE_META 10
! 96:
! 97: int sqliteBtreeOpen(const char *zFilename, int mode, int nPg, Btree **ppBtree);
! 98: int sqliteRbtreeOpen(const char *zFilename, int mode, int nPg, Btree **ppBtree);
! 99:
! 100: #define btOps(pBt) (*((BtOps **)(pBt)))
! 101: #define btCOps(pCur) (*((BtCursorOps **)(pCur)))
! 102:
! 103: #define sqliteBtreeClose(pBt) (btOps(pBt)->Close(pBt))
! 104: #define sqliteBtreeSetCacheSize(pBt, sz) (btOps(pBt)->SetCacheSize(pBt, sz))
! 105: #define sqliteBtreeSetSafetyLevel(pBt, sl) (btOps(pBt)->SetSafetyLevel(pBt, sl))
! 106: #define sqliteBtreeBeginTrans(pBt) (btOps(pBt)->BeginTrans(pBt))
! 107: #define sqliteBtreeCommit(pBt) (btOps(pBt)->Commit(pBt))
! 108: #define sqliteBtreeRollback(pBt) (btOps(pBt)->Rollback(pBt))
! 109: #define sqliteBtreeBeginCkpt(pBt) (btOps(pBt)->BeginCkpt(pBt))
! 110: #define sqliteBtreeCommitCkpt(pBt) (btOps(pBt)->CommitCkpt(pBt))
! 111: #define sqliteBtreeRollbackCkpt(pBt) (btOps(pBt)->RollbackCkpt(pBt))
! 112: #define sqliteBtreeCreateTable(pBt,piTable)\
! 113: (btOps(pBt)->CreateTable(pBt,piTable))
! 114: #define sqliteBtreeCreateIndex(pBt, piIndex)\
! 115: (btOps(pBt)->CreateIndex(pBt, piIndex))
! 116: #define sqliteBtreeDropTable(pBt, iTable) (btOps(pBt)->DropTable(pBt, iTable))
! 117: #define sqliteBtreeClearTable(pBt, iTable)\
! 118: (btOps(pBt)->ClearTable(pBt, iTable))
! 119: #define sqliteBtreeCursor(pBt, iTable, wrFlag, ppCur)\
! 120: (btOps(pBt)->Cursor(pBt, iTable, wrFlag, ppCur))
! 121: #define sqliteBtreeMoveto(pCur, pKey, nKey, pRes)\
! 122: (btCOps(pCur)->Moveto(pCur, pKey, nKey, pRes))
! 123: #define sqliteBtreeDelete(pCur) (btCOps(pCur)->Delete(pCur))
! 124: #define sqliteBtreeInsert(pCur, pKey, nKey, pData, nData) \
! 125: (btCOps(pCur)->Insert(pCur, pKey, nKey, pData, nData))
! 126: #define sqliteBtreeFirst(pCur, pRes) (btCOps(pCur)->First(pCur, pRes))
! 127: #define sqliteBtreeLast(pCur, pRes) (btCOps(pCur)->Last(pCur, pRes))
! 128: #define sqliteBtreeNext(pCur, pRes) (btCOps(pCur)->Next(pCur, pRes))
! 129: #define sqliteBtreePrevious(pCur, pRes) (btCOps(pCur)->Previous(pCur, pRes))
! 130: #define sqliteBtreeKeySize(pCur, pSize) (btCOps(pCur)->KeySize(pCur, pSize) )
! 131: #define sqliteBtreeKey(pCur, offset, amt, zBuf)\
! 132: (btCOps(pCur)->Key(pCur, offset, amt, zBuf))
! 133: #define sqliteBtreeKeyCompare(pCur, pKey, nKey, nIgnore, pRes)\
! 134: (btCOps(pCur)->KeyCompare(pCur, pKey, nKey, nIgnore, pRes))
! 135: #define sqliteBtreeDataSize(pCur, pSize) (btCOps(pCur)->DataSize(pCur, pSize))
! 136: #define sqliteBtreeData(pCur, offset, amt, zBuf)\
! 137: (btCOps(pCur)->Data(pCur, offset, amt, zBuf))
! 138: #define sqliteBtreeCloseCursor(pCur) (btCOps(pCur)->CloseCursor(pCur))
! 139: #define sqliteBtreeGetMeta(pBt, aMeta) (btOps(pBt)->GetMeta(pBt, aMeta))
! 140: #define sqliteBtreeUpdateMeta(pBt, aMeta) (btOps(pBt)->UpdateMeta(pBt, aMeta))
! 141: #define sqliteBtreeIntegrityCheck(pBt, aRoot, nRoot)\
! 142: (btOps(pBt)->IntegrityCheck(pBt, aRoot, nRoot))
! 143: #define sqliteBtreeGetFilename(pBt) (btOps(pBt)->GetFilename(pBt))
! 144: #define sqliteBtreeCopyFile(pBt1, pBt2) (btOps(pBt1)->Copyfile(pBt1, pBt2))
! 145: #define sqliteBtreePager(pBt) (btOps(pBt)->Pager(pBt))
! 146:
! 147: #ifdef SQLITE_TEST
! 148: #define sqliteBtreePageDump(pBt, pgno, recursive)\
! 149: (btOps(pBt)->PageDump(pBt, pgno, recursive))
! 150: #define sqliteBtreeCursorDump(pCur, aResult)\
! 151: (btCOps(pCur)->CursorDump(pCur, aResult))
! 152: int btree_native_byte_order;
! 153: #endif /* SQLITE_TEST */
! 154:
! 155:
! 156: #endif /* _BTREE_H_ */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>