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,v 1.63 2005/03/21 04:04:03 danielk1977 Exp $ 17 */ 18 #ifndef _BTREE_H_ 19 #define _BTREE_H_ 20 21 /* TODO: This definition is just included so other modules compile. It 22 ** needs to be revisited. 23 */ 24 #define SQLITE_N_BTREE_META 10 25 26 /* 27 ** If defined as non-zero, auto-vacuum is enabled by default. Otherwise 28 ** it must be turned on for each database using "PRAGMA auto_vacuum = 1". 29 */ 30 #ifndef SQLITE_DEFAULT_AUTOVACUUM 31 #define SQLITE_DEFAULT_AUTOVACUUM 0 32 #endif 33 34 /* 35 ** Forward declarations of structure 36 */ 37 typedef struct Btree Btree; 38 typedef struct BtCursor BtCursor; 39 40 41 int sqlite3BtreeOpen( 42 const char *zFilename, /* Name of database file to open */ 43 Btree **, /* Return open Btree* here */ 44 int flags /* Flags */ 45 ); 46 47 /* The flags parameter to sqlite3BtreeOpen can be the bitwise or of the 48 ** following values. 49 ** 50 ** NOTE: These values must match the corresponding PAGER_ values in 51 ** pager.h. 52 */ 53 #define BTREE_OMIT_JOURNAL 1 /* Do not use journal. No argument */ 54 #define BTREE_NO_READLOCK 2 /* Omit readlocks on readonly files */ 55 #define BTREE_MEMORY 4 /* In-memory DB. No argument */ 56 57 int sqlite3BtreeClose(Btree*); 58 int sqlite3BtreeSetBusyHandler(Btree*,BusyHandler*); 59 int sqlite3BtreeSetCacheSize(Btree*,int); 60 int sqlite3BtreeSetSafetyLevel(Btree*,int); 61 int sqlite3BtreeSetPageSize(Btree*,int,int); 62 int sqlite3BtreeGetPageSize(Btree*); 63 int sqlite3BtreeGetReserve(Btree*); 64 int sqlite3BtreeSetAutoVacuum(Btree *, int); 65 int sqlite3BtreeGetAutoVacuum(Btree *); 66 int sqlite3BtreeBeginTrans(Btree*,int); 67 int sqlite3BtreeCommit(Btree*); 68 int sqlite3BtreeRollback(Btree*); 69 int sqlite3BtreeBeginStmt(Btree*); 70 int sqlite3BtreeCommitStmt(Btree*); 71 int sqlite3BtreeRollbackStmt(Btree*); 72 int sqlite3BtreeCreateTable(Btree*, int*, int flags); 73 int sqlite3BtreeIsInTrans(Btree*); 74 int sqlite3BtreeIsInStmt(Btree*); 75 int sqlite3BtreeSync(Btree*, const char *zMaster); 76 int sqlite3BtreeReset(Btree *); 77 78 const char *sqlite3BtreeGetFilename(Btree *); 79 const char *sqlite3BtreeGetDirname(Btree *); 80 const char *sqlite3BtreeGetJournalname(Btree *); 81 int sqlite3BtreeCopyFile(Btree *, Btree *); 82 83 /* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR 84 ** of the following flags: 85 */ 86 #define BTREE_INTKEY 1 /* Table has only 64-bit signed integer keys */ 87 #define BTREE_ZERODATA 2 /* Table has keys only - no data */ 88 #define BTREE_LEAFDATA 4 /* Data stored in leaves only. Implies INTKEY */ 89 90 int sqlite3BtreeDropTable(Btree*, int, int*); 91 int sqlite3BtreeClearTable(Btree*, int); 92 int sqlite3BtreeGetMeta(Btree*, int idx, u32 *pValue); 93 int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value); 94 95 int sqlite3BtreeCursor( 96 Btree*, /* BTree containing table to open */ 97 int iTable, /* Index of root page */ 98 int wrFlag, /* 1 for writing. 0 for read-only */ 99 int(*)(void*,int,const void*,int,const void*), /* Key comparison function */ 100 void*, /* First argument to compare function */ 101 BtCursor **ppCursor /* Returned cursor */ 102 ); 103 104 void sqlite3BtreeSetCompare( 105 BtCursor *, 106 int(*)(void*,int,const void*,int,const void*), 107 void* 108 ); 109 110 int sqlite3BtreeCloseCursor(BtCursor*); 111 int sqlite3BtreeMoveto(BtCursor*, const void *pKey, i64 nKey, int *pRes); 112 int sqlite3BtreeDelete(BtCursor*); 113 int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey, 114 const void *pData, int nData); 115 int sqlite3BtreeFirst(BtCursor*, int *pRes); 116 int sqlite3BtreeLast(BtCursor*, int *pRes); 117 int sqlite3BtreeNext(BtCursor*, int *pRes); 118 int sqlite3BtreeEof(BtCursor*); 119 int sqlite3BtreeFlags(BtCursor*); 120 int sqlite3BtreePrevious(BtCursor*, int *pRes); 121 int sqlite3BtreeKeySize(BtCursor*, i64 *pSize); 122 int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*); 123 const void *sqlite3BtreeKeyFetch(BtCursor*, int *pAmt); 124 const void *sqlite3BtreeDataFetch(BtCursor*, int *pAmt); 125 int sqlite3BtreeDataSize(BtCursor*, u32 *pSize); 126 int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*); 127 128 char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot); 129 struct Pager *sqlite3BtreePager(Btree*); 130 131 132 #ifdef SQLITE_TEST 133 int sqlite3BtreeCursorInfo(BtCursor*, int*, int); 134 void sqlite3BtreeCursorList(Btree*); 135 #endif 136 137 #ifdef SQLITE_DEBUG 138 int sqlite3BtreePageDump(Btree*, int, int recursive); 139 #else 140 #define sqlite3BtreePageDump(X,Y,Z) SQLITE_OK 141 #endif 142 143 #endif /* _BTREE_H_ */ 144