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