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