Merge branch 'prerelease' of github.com:sqlcipher/sqlcipher into prerelease
[sqlcipher.git] / src / btree.h
blobace0f8cd217770a2f66b2eb871bbc5fdc6fc2b68
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.
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.
16 #ifndef _BTREE_H_
17 #define _BTREE_H_
19 /* TODO: This definition is just included so other modules compile. It
20 ** needs to be revisited.
22 #define SQLITE_N_BTREE_META 10
25 ** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
26 ** it must be turned on for each database using "PRAGMA auto_vacuum = 1".
28 #ifndef SQLITE_DEFAULT_AUTOVACUUM
29 #define SQLITE_DEFAULT_AUTOVACUUM 0
30 #endif
32 #define BTREE_AUTOVACUUM_NONE 0 /* Do not do auto-vacuum */
33 #define BTREE_AUTOVACUUM_FULL 1 /* Do full auto-vacuum */
34 #define BTREE_AUTOVACUUM_INCR 2 /* Incremental vacuum */
37 ** Forward declarations of structure
39 typedef struct Btree Btree;
40 typedef struct BtCursor BtCursor;
41 typedef struct BtShared BtShared;
44 int sqlite3BtreeOpen(
45 sqlite3_vfs *pVfs, /* VFS to use with this b-tree */
46 const char *zFilename, /* Name of database file to open */
47 sqlite3 *db, /* Associated database connection */
48 Btree **ppBtree, /* Return open Btree* here */
49 int flags, /* Flags */
50 int vfsFlags /* Flags passed through to VFS open */
53 /* The flags parameter to sqlite3BtreeOpen can be the bitwise or of the
54 ** following values.
56 ** NOTE: These values must match the corresponding PAGER_ values in
57 ** pager.h.
59 #define BTREE_OMIT_JOURNAL 1 /* Do not create or use a rollback journal */
60 #define BTREE_MEMORY 2 /* This is an in-memory DB */
61 #define BTREE_SINGLE 4 /* The file contains at most 1 b-tree */
62 #define BTREE_UNORDERED 8 /* Use of a hash implementation is OK */
64 int sqlite3BtreeClose(Btree*);
65 int sqlite3BtreeSetCacheSize(Btree*,int);
66 int sqlite3BtreeSetMmapLimit(Btree*,sqlite3_int64);
67 int sqlite3BtreeSetSafetyLevel(Btree*,int,int,int);
68 int sqlite3BtreeSyncDisabled(Btree*);
69 int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
70 int sqlite3BtreeGetPageSize(Btree*);
71 int sqlite3BtreeMaxPageCount(Btree*,int);
72 u32 sqlite3BtreeLastPage(Btree*);
73 int sqlite3BtreeSecureDelete(Btree*,int);
74 int sqlite3BtreeGetReserve(Btree*);
75 #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_DEBUG)
76 int sqlite3BtreeGetReserveNoMutex(Btree *p);
77 #endif
78 int sqlite3BtreeSetAutoVacuum(Btree *, int);
79 int sqlite3BtreeGetAutoVacuum(Btree *);
80 int sqlite3BtreeBeginTrans(Btree*,int);
81 int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
82 int sqlite3BtreeCommitPhaseTwo(Btree*, int);
83 int sqlite3BtreeCommit(Btree*);
84 int sqlite3BtreeRollback(Btree*,int);
85 int sqlite3BtreeBeginStmt(Btree*,int);
86 int sqlite3BtreeCreateTable(Btree*, int*, int flags);
87 int sqlite3BtreeIsInTrans(Btree*);
88 int sqlite3BtreeIsInReadTrans(Btree*);
89 int sqlite3BtreeIsInBackup(Btree*);
90 void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
91 int sqlite3BtreeSchemaLocked(Btree *pBtree);
92 int sqlite3BtreeLockTable(Btree *pBtree, int iTab, u8 isWriteLock);
93 int sqlite3BtreeSavepoint(Btree *, int, int);
95 const char *sqlite3BtreeGetFilename(Btree *);
96 const char *sqlite3BtreeGetJournalname(Btree *);
97 int sqlite3BtreeCopyFile(Btree *, Btree *);
99 int sqlite3BtreeIncrVacuum(Btree *);
101 /* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR
102 ** of the flags shown below.
104 ** Every SQLite table must have either BTREE_INTKEY or BTREE_BLOBKEY set.
105 ** With BTREE_INTKEY, the table key is a 64-bit integer and arbitrary data
106 ** is stored in the leaves. (BTREE_INTKEY is used for SQL tables.) With
107 ** BTREE_BLOBKEY, the key is an arbitrary BLOB and no content is stored
108 ** anywhere - the key is the content. (BTREE_BLOBKEY is used for SQL
109 ** indices.)
111 #define BTREE_INTKEY 1 /* Table has only 64-bit signed integer keys */
112 #define BTREE_BLOBKEY 2 /* Table has keys only - no data */
114 int sqlite3BtreeDropTable(Btree*, int, int*);
115 int sqlite3BtreeClearTable(Btree*, int, int*);
116 void sqlite3BtreeTripAllCursors(Btree*, int);
118 void sqlite3BtreeGetMeta(Btree *pBtree, int idx, u32 *pValue);
119 int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
121 int sqlite3BtreeNewDb(Btree *p);
124 ** The second parameter to sqlite3BtreeGetMeta or sqlite3BtreeUpdateMeta
125 ** should be one of the following values. The integer values are assigned
126 ** to constants so that the offset of the corresponding field in an
127 ** SQLite database header may be found using the following formula:
129 ** offset = 36 + (idx * 4)
131 ** For example, the free-page-count field is located at byte offset 36 of
132 ** the database file header. The incr-vacuum-flag field is located at
133 ** byte offset 64 (== 36+4*7).
135 #define BTREE_FREE_PAGE_COUNT 0
136 #define BTREE_SCHEMA_VERSION 1
137 #define BTREE_FILE_FORMAT 2
138 #define BTREE_DEFAULT_CACHE_SIZE 3
139 #define BTREE_LARGEST_ROOT_PAGE 4
140 #define BTREE_TEXT_ENCODING 5
141 #define BTREE_USER_VERSION 6
142 #define BTREE_INCR_VACUUM 7
143 #define BTREE_APPLICATION_ID 8
146 ** Values that may be OR'd together to form the second argument of an
147 ** sqlite3BtreeCursorHints() call.
149 #define BTREE_BULKLOAD 0x00000001
151 int sqlite3BtreeCursor(
152 Btree*, /* BTree containing table to open */
153 int iTable, /* Index of root page */
154 int wrFlag, /* 1 for writing. 0 for read-only */
155 struct KeyInfo*, /* First argument to compare function */
156 BtCursor *pCursor /* Space to write cursor structure */
158 int sqlite3BtreeCursorSize(void);
159 void sqlite3BtreeCursorZero(BtCursor*);
161 int sqlite3BtreeCloseCursor(BtCursor*);
162 int sqlite3BtreeMovetoUnpacked(
163 BtCursor*,
164 UnpackedRecord *pUnKey,
165 i64 intKey,
166 int bias,
167 int *pRes
169 int sqlite3BtreeCursorHasMoved(BtCursor*, int*);
170 int sqlite3BtreeDelete(BtCursor*);
171 int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
172 const void *pData, int nData,
173 int nZero, int bias, int seekResult);
174 int sqlite3BtreeFirst(BtCursor*, int *pRes);
175 int sqlite3BtreeLast(BtCursor*, int *pRes);
176 int sqlite3BtreeNext(BtCursor*, int *pRes);
177 int sqlite3BtreeEof(BtCursor*);
178 int sqlite3BtreePrevious(BtCursor*, int *pRes);
179 int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
180 int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
181 const void *sqlite3BtreeKeyFetch(BtCursor*, int *pAmt);
182 const void *sqlite3BtreeDataFetch(BtCursor*, int *pAmt);
183 int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
184 int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
185 void sqlite3BtreeSetCachedRowid(BtCursor*, sqlite3_int64);
186 sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor*);
188 char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
189 struct Pager *sqlite3BtreePager(Btree*);
191 int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
192 void sqlite3BtreeCacheOverflow(BtCursor *);
193 void sqlite3BtreeClearCursor(BtCursor *);
194 int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
195 void sqlite3BtreeCursorHints(BtCursor *, unsigned int mask);
197 #ifndef NDEBUG
198 int sqlite3BtreeCursorIsValid(BtCursor*);
199 #endif
201 #ifndef SQLITE_OMIT_BTREECOUNT
202 int sqlite3BtreeCount(BtCursor *, i64 *);
203 #endif
205 #ifdef SQLITE_TEST
206 int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
207 void sqlite3BtreeCursorList(Btree*);
208 #endif
210 #ifndef SQLITE_OMIT_WAL
211 int sqlite3BtreeCheckpoint(Btree*, int, int *, int *);
212 #endif
215 ** If we are not using shared cache, then there is no need to
216 ** use mutexes to access the BtShared structures. So make the
217 ** Enter and Leave procedures no-ops.
219 #ifndef SQLITE_OMIT_SHARED_CACHE
220 void sqlite3BtreeEnter(Btree*);
221 void sqlite3BtreeEnterAll(sqlite3*);
222 #else
223 # define sqlite3BtreeEnter(X)
224 # define sqlite3BtreeEnterAll(X)
225 #endif
227 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE
228 int sqlite3BtreeSharable(Btree*);
229 void sqlite3BtreeLeave(Btree*);
230 void sqlite3BtreeEnterCursor(BtCursor*);
231 void sqlite3BtreeLeaveCursor(BtCursor*);
232 void sqlite3BtreeLeaveAll(sqlite3*);
233 #ifndef NDEBUG
234 /* These routines are used inside assert() statements only. */
235 int sqlite3BtreeHoldsMutex(Btree*);
236 int sqlite3BtreeHoldsAllMutexes(sqlite3*);
237 int sqlite3SchemaMutexHeld(sqlite3*,int,Schema*);
238 #endif
239 #else
241 # define sqlite3BtreeSharable(X) 0
242 # define sqlite3BtreeLeave(X)
243 # define sqlite3BtreeEnterCursor(X)
244 # define sqlite3BtreeLeaveCursor(X)
245 # define sqlite3BtreeLeaveAll(X)
247 # define sqlite3BtreeHoldsMutex(X) 1
248 # define sqlite3BtreeHoldsAllMutexes(X) 1
249 # define sqlite3SchemaMutexHeld(X,Y,Z) 1
250 #endif
253 #endif /* _BTREE_H_ */