Update mojo sdk to rev 1dc8a9a5db73d3718d99917fadf31f5fb2ebad4f
[chromium-blink-merge.git] / third_party / sqlite / sqlite-src-3080704 / src / btree.h
blobfabedd9a530c83ee7ad743ec591a949d4d640a1c
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 #if SQLITE_MAX_MMAP_SIZE>0
67 int sqlite3BtreeSetMmapLimit(Btree*,sqlite3_int64);
68 #endif
69 int sqlite3BtreeSetPagerFlags(Btree*,unsigned);
70 int sqlite3BtreeSyncDisabled(Btree*);
71 int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
72 int sqlite3BtreeGetPageSize(Btree*);
73 int sqlite3BtreeMaxPageCount(Btree*,int);
74 u32 sqlite3BtreeLastPage(Btree*);
75 int sqlite3BtreeSecureDelete(Btree*,int);
76 int sqlite3BtreeGetReserve(Btree*);
77 #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_DEBUG)
78 int sqlite3BtreeGetReserveNoMutex(Btree *p);
79 #endif
80 int sqlite3BtreeSetAutoVacuum(Btree *, int);
81 int sqlite3BtreeGetAutoVacuum(Btree *);
82 int sqlite3BtreeBeginTrans(Btree*,int);
83 int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
84 int sqlite3BtreeCommitPhaseTwo(Btree*, int);
85 int sqlite3BtreeCommit(Btree*);
86 int sqlite3BtreeRollback(Btree*,int,int);
87 int sqlite3BtreeBeginStmt(Btree*,int);
88 int sqlite3BtreeCreateTable(Btree*, int*, int flags);
89 int sqlite3BtreeIsInTrans(Btree*);
90 int sqlite3BtreeIsInReadTrans(Btree*);
91 int sqlite3BtreeIsInBackup(Btree*);
92 void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
93 int sqlite3BtreeSchemaLocked(Btree *pBtree);
94 int sqlite3BtreeLockTable(Btree *pBtree, int iTab, u8 isWriteLock);
95 int sqlite3BtreeSavepoint(Btree *, int, int);
97 const char *sqlite3BtreeGetFilename(Btree *);
98 const char *sqlite3BtreeGetJournalname(Btree *);
99 int sqlite3BtreeCopyFile(Btree *, Btree *);
101 int sqlite3BtreeIncrVacuum(Btree *);
103 /* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR
104 ** of the flags shown below.
106 ** Every SQLite table must have either BTREE_INTKEY or BTREE_BLOBKEY set.
107 ** With BTREE_INTKEY, the table key is a 64-bit integer and arbitrary data
108 ** is stored in the leaves. (BTREE_INTKEY is used for SQL tables.) With
109 ** BTREE_BLOBKEY, the key is an arbitrary BLOB and no content is stored
110 ** anywhere - the key is the content. (BTREE_BLOBKEY is used for SQL
111 ** indices.)
113 #define BTREE_INTKEY 1 /* Table has only 64-bit signed integer keys */
114 #define BTREE_BLOBKEY 2 /* Table has keys only - no data */
116 int sqlite3BtreeDropTable(Btree*, int, int*);
117 int sqlite3BtreeClearTable(Btree*, int, int*);
118 int sqlite3BtreeClearTableOfCursor(BtCursor*);
119 int sqlite3BtreeTripAllCursors(Btree*, int, int);
121 void sqlite3BtreeGetMeta(Btree *pBtree, int idx, u32 *pValue);
122 int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
124 int sqlite3BtreeNewDb(Btree *p);
127 ** The second parameter to sqlite3BtreeGetMeta or sqlite3BtreeUpdateMeta
128 ** should be one of the following values. The integer values are assigned
129 ** to constants so that the offset of the corresponding field in an
130 ** SQLite database header may be found using the following formula:
132 ** offset = 36 + (idx * 4)
134 ** For example, the free-page-count field is located at byte offset 36 of
135 ** the database file header. The incr-vacuum-flag field is located at
136 ** byte offset 64 (== 36+4*7).
138 #define BTREE_FREE_PAGE_COUNT 0
139 #define BTREE_SCHEMA_VERSION 1
140 #define BTREE_FILE_FORMAT 2
141 #define BTREE_DEFAULT_CACHE_SIZE 3
142 #define BTREE_LARGEST_ROOT_PAGE 4
143 #define BTREE_TEXT_ENCODING 5
144 #define BTREE_USER_VERSION 6
145 #define BTREE_INCR_VACUUM 7
146 #define BTREE_APPLICATION_ID 8
149 ** Values that may be OR'd together to form the second argument of an
150 ** sqlite3BtreeCursorHints() call.
152 #define BTREE_BULKLOAD 0x00000001
154 int sqlite3BtreeCursor(
155 Btree*, /* BTree containing table to open */
156 int iTable, /* Index of root page */
157 int wrFlag, /* 1 for writing. 0 for read-only */
158 struct KeyInfo*, /* First argument to compare function */
159 BtCursor *pCursor /* Space to write cursor structure */
161 int sqlite3BtreeCursorSize(void);
162 void sqlite3BtreeCursorZero(BtCursor*);
164 int sqlite3BtreeCloseCursor(BtCursor*);
165 int sqlite3BtreeMovetoUnpacked(
166 BtCursor*,
167 UnpackedRecord *pUnKey,
168 i64 intKey,
169 int bias,
170 int *pRes
172 int sqlite3BtreeCursorHasMoved(BtCursor*);
173 int sqlite3BtreeCursorRestore(BtCursor*, int*);
174 int sqlite3BtreeDelete(BtCursor*);
175 int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
176 const void *pData, int nData,
177 int nZero, int bias, int seekResult);
178 int sqlite3BtreeFirst(BtCursor*, int *pRes);
179 int sqlite3BtreeLast(BtCursor*, int *pRes);
180 int sqlite3BtreeNext(BtCursor*, int *pRes);
181 int sqlite3BtreeEof(BtCursor*);
182 int sqlite3BtreePrevious(BtCursor*, int *pRes);
183 int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
184 int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
185 const void *sqlite3BtreeKeyFetch(BtCursor*, u32 *pAmt);
186 const void *sqlite3BtreeDataFetch(BtCursor*, u32 *pAmt);
187 int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
188 int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
190 char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
191 struct Pager *sqlite3BtreePager(Btree*);
193 int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
194 void sqlite3BtreeIncrblobCursor(BtCursor *);
195 void sqlite3BtreeClearCursor(BtCursor *);
196 int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
197 void sqlite3BtreeCursorHints(BtCursor *, unsigned int mask);
198 int sqlite3BtreeIsReadonly(Btree *pBt);
200 #ifndef NDEBUG
201 int sqlite3BtreeCursorIsValid(BtCursor*);
202 #endif
204 #ifndef SQLITE_OMIT_BTREECOUNT
205 int sqlite3BtreeCount(BtCursor *, i64 *);
206 #endif
208 #ifdef SQLITE_TEST
209 int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
210 void sqlite3BtreeCursorList(Btree*);
211 #endif
213 #ifndef SQLITE_OMIT_WAL
214 int sqlite3BtreeCheckpoint(Btree*, int, int *, int *);
215 #endif
218 ** If we are not using shared cache, then there is no need to
219 ** use mutexes to access the BtShared structures. So make the
220 ** Enter and Leave procedures no-ops.
222 #ifndef SQLITE_OMIT_SHARED_CACHE
223 void sqlite3BtreeEnter(Btree*);
224 void sqlite3BtreeEnterAll(sqlite3*);
225 #else
226 # define sqlite3BtreeEnter(X)
227 # define sqlite3BtreeEnterAll(X)
228 #endif
230 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE
231 int sqlite3BtreeSharable(Btree*);
232 void sqlite3BtreeLeave(Btree*);
233 void sqlite3BtreeEnterCursor(BtCursor*);
234 void sqlite3BtreeLeaveCursor(BtCursor*);
235 void sqlite3BtreeLeaveAll(sqlite3*);
236 #ifndef NDEBUG
237 /* These routines are used inside assert() statements only. */
238 int sqlite3BtreeHoldsMutex(Btree*);
239 int sqlite3BtreeHoldsAllMutexes(sqlite3*);
240 int sqlite3SchemaMutexHeld(sqlite3*,int,Schema*);
241 #endif
242 #else
244 # define sqlite3BtreeSharable(X) 0
245 # define sqlite3BtreeLeave(X)
246 # define sqlite3BtreeEnterCursor(X)
247 # define sqlite3BtreeLeaveCursor(X)
248 # define sqlite3BtreeLeaveAll(X)
250 # define sqlite3BtreeHoldsMutex(X) 1
251 # define sqlite3BtreeHoldsAllMutexes(X) 1
252 # define sqlite3SchemaMutexHeld(X,Y,Z) 1
253 #endif
256 #endif /* _BTREE_H_ */