drh | a059ad0 | 2001-04-17 20:09:11 +0000 | [diff] [blame] | 1 | /* |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 2 | ** 2001 September 15 |
drh | a059ad0 | 2001-04-17 20:09:11 +0000 | [diff] [blame] | 3 | ** |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 4 | ** The author disclaims copyright to this source code. In place of |
| 5 | ** a legal notice, here is a blessing: |
drh | a059ad0 | 2001-04-17 20:09:11 +0000 | [diff] [blame] | 6 | ** |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 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. |
drh | a059ad0 | 2001-04-17 20:09:11 +0000 | [diff] [blame] | 10 | ** |
| 11 | ************************************************************************* |
| 12 | ** This header file defines the interface that the sqlite B-Tree file |
drh | 6446c4d | 2001-12-15 14:22:18 +0000 | [diff] [blame] | 13 | ** subsystem. See comments in the source code for a detailed description |
| 14 | ** of what each interface routine does. |
drh | a059ad0 | 2001-04-17 20:09:11 +0000 | [diff] [blame] | 15 | ** |
danielk1977 | 2dec970 | 2007-05-02 16:48:37 +0000 | [diff] [blame^] | 16 | ** @(#) $Id: btree.h,v 1.78 2007/05/02 16:48:37 danielk1977 Exp $ |
drh | a059ad0 | 2001-04-17 20:09:11 +0000 | [diff] [blame] | 17 | */ |
drh | be0072d | 2001-09-13 14:46:09 +0000 | [diff] [blame] | 18 | #ifndef _BTREE_H_ |
| 19 | #define _BTREE_H_ |
drh | a059ad0 | 2001-04-17 20:09:11 +0000 | [diff] [blame] | 20 | |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 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 | |
drh | 73509ee | 2003-04-06 20:44:45 +0000 | [diff] [blame] | 26 | /* |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 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 | |
danielk1977 | dddbcdc | 2007-04-26 14:42:34 +0000 | [diff] [blame] | 34 | #define BTREE_AUTOVACUUM_NONE 0 /* Do not do auto-vacuum */ |
| 35 | #define BTREE_AUTOVACUUM_FULL 1 /* Do full auto-vacuum */ |
| 36 | #define BTREE_AUTOVACUUM_INCR 2 /* Incremental vacuum */ |
| 37 | |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 38 | /* |
drh | 73509ee | 2003-04-06 20:44:45 +0000 | [diff] [blame] | 39 | ** Forward declarations of structure |
| 40 | */ |
drh | a059ad0 | 2001-04-17 20:09:11 +0000 | [diff] [blame] | 41 | typedef struct Btree Btree; |
| 42 | typedef struct BtCursor BtCursor; |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 43 | typedef struct BtShared BtShared; |
paul | b95a886 | 2003-04-01 21:16:41 +0000 | [diff] [blame] | 44 | |
drh | 73509ee | 2003-04-06 20:44:45 +0000 | [diff] [blame] | 45 | |
danielk1977 | 24162fe | 2004-06-04 06:22:00 +0000 | [diff] [blame] | 46 | int sqlite3BtreeOpen( |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 47 | const char *zFilename, /* Name of database file to open */ |
danielk1977 | aef0bf6 | 2005-12-30 16:28:01 +0000 | [diff] [blame] | 48 | sqlite3 *db, /* Associated database connection */ |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 49 | Btree **, /* Return open Btree* here */ |
| 50 | int flags /* Flags */ |
danielk1977 | 24162fe | 2004-06-04 06:22:00 +0000 | [diff] [blame] | 51 | ); |
drh | 3aac2dd | 2004-04-26 14:10:20 +0000 | [diff] [blame] | 52 | |
| 53 | /* The flags parameter to sqlite3BtreeOpen can be the bitwise or of the |
| 54 | ** following values. |
drh | 7bec505 | 2005-02-06 02:45:41 +0000 | [diff] [blame] | 55 | ** |
| 56 | ** NOTE: These values must match the corresponding PAGER_ values in |
| 57 | ** pager.h. |
drh | 73509ee | 2003-04-06 20:44:45 +0000 | [diff] [blame] | 58 | */ |
drh | 3aac2dd | 2004-04-26 14:10:20 +0000 | [diff] [blame] | 59 | #define BTREE_OMIT_JOURNAL 1 /* Do not use journal. No argument */ |
drh | 7bec505 | 2005-02-06 02:45:41 +0000 | [diff] [blame] | 60 | #define BTREE_NO_READLOCK 2 /* Omit readlocks on readonly files */ |
| 61 | #define BTREE_MEMORY 4 /* In-memory DB. No argument */ |
drh | 73509ee | 2003-04-06 20:44:45 +0000 | [diff] [blame] | 62 | |
drh | 3aac2dd | 2004-04-26 14:10:20 +0000 | [diff] [blame] | 63 | int sqlite3BtreeClose(Btree*); |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 64 | int sqlite3BtreeSetBusyHandler(Btree*,BusyHandler*); |
drh | 3aac2dd | 2004-04-26 14:10:20 +0000 | [diff] [blame] | 65 | int sqlite3BtreeSetCacheSize(Btree*,int); |
drh | ac530b1 | 2006-02-11 01:25:50 +0000 | [diff] [blame] | 66 | int sqlite3BtreeSetSafetyLevel(Btree*,int,int); |
drh | 2c8997b | 2005-08-27 16:36:48 +0000 | [diff] [blame] | 67 | int sqlite3BtreeSyncDisabled(Btree*); |
drh | 90f5ecb | 2004-07-22 01:19:35 +0000 | [diff] [blame] | 68 | int sqlite3BtreeSetPageSize(Btree*,int,int); |
| 69 | int sqlite3BtreeGetPageSize(Btree*); |
drh | 2011d5f | 2004-07-22 02:40:37 +0000 | [diff] [blame] | 70 | int sqlite3BtreeGetReserve(Btree*); |
danielk1977 | 951af80 | 2004-11-05 15:45:09 +0000 | [diff] [blame] | 71 | int sqlite3BtreeSetAutoVacuum(Btree *, int); |
| 72 | int sqlite3BtreeGetAutoVacuum(Btree *); |
danielk1977 | 40b38dc | 2004-06-26 08:38:24 +0000 | [diff] [blame] | 73 | int sqlite3BtreeBeginTrans(Btree*,int); |
drh | 80e35f4 | 2007-03-30 14:06:34 +0000 | [diff] [blame] | 74 | int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster); |
| 75 | int sqlite3BtreeCommitPhaseTwo(Btree*); |
drh | 3aac2dd | 2004-04-26 14:10:20 +0000 | [diff] [blame] | 76 | int sqlite3BtreeCommit(Btree*); |
| 77 | int sqlite3BtreeRollback(Btree*); |
| 78 | int sqlite3BtreeBeginStmt(Btree*); |
| 79 | int sqlite3BtreeCommitStmt(Btree*); |
| 80 | int sqlite3BtreeRollbackStmt(Btree*); |
| 81 | int sqlite3BtreeCreateTable(Btree*, int*, int flags); |
danielk1977 | 1d850a7 | 2004-05-31 08:26:49 +0000 | [diff] [blame] | 82 | int sqlite3BtreeIsInTrans(Btree*); |
| 83 | int sqlite3BtreeIsInStmt(Btree*); |
danielk1977 | 2372c2b | 2006-06-27 16:34:56 +0000 | [diff] [blame] | 84 | int sqlite3BtreeIsInReadTrans(Btree*); |
danielk1977 | da18423 | 2006-01-05 11:34:32 +0000 | [diff] [blame] | 85 | void *sqlite3BtreeSchema(Btree *, int, void(*)(void *)); |
danielk1977 | c87d34d | 2006-01-06 13:00:28 +0000 | [diff] [blame] | 86 | int sqlite3BtreeSchemaLocked(Btree *); |
danielk1977 | c00da10 | 2006-01-07 13:21:04 +0000 | [diff] [blame] | 87 | int sqlite3BtreeLockTable(Btree *, int, u8); |
drh | 3aac2dd | 2004-04-26 14:10:20 +0000 | [diff] [blame] | 88 | |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 89 | const char *sqlite3BtreeGetFilename(Btree *); |
danielk1977 | 5865e3d | 2004-06-14 06:03:57 +0000 | [diff] [blame] | 90 | const char *sqlite3BtreeGetDirname(Btree *); |
| 91 | const char *sqlite3BtreeGetJournalname(Btree *); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 92 | int sqlite3BtreeCopyFile(Btree *, Btree *); |
| 93 | |
danielk1977 | dddbcdc | 2007-04-26 14:42:34 +0000 | [diff] [blame] | 94 | int sqlite3BtreeIncrVacuum(Btree *); |
| 95 | |
drh | 3aac2dd | 2004-04-26 14:10:20 +0000 | [diff] [blame] | 96 | /* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR |
| 97 | ** of the following flags: |
drh | 73509ee | 2003-04-06 20:44:45 +0000 | [diff] [blame] | 98 | */ |
drh | 8b18dd4 | 2004-05-12 19:18:15 +0000 | [diff] [blame] | 99 | #define BTREE_INTKEY 1 /* Table has only 64-bit signed integer keys */ |
| 100 | #define BTREE_ZERODATA 2 /* Table has keys only - no data */ |
| 101 | #define BTREE_LEAFDATA 4 /* Data stored in leaves only. Implies INTKEY */ |
drh | 73509ee | 2003-04-06 20:44:45 +0000 | [diff] [blame] | 102 | |
danielk1977 | a0bf265 | 2004-11-04 14:30:04 +0000 | [diff] [blame] | 103 | int sqlite3BtreeDropTable(Btree*, int, int*); |
drh | 3aac2dd | 2004-04-26 14:10:20 +0000 | [diff] [blame] | 104 | int sqlite3BtreeClearTable(Btree*, int); |
| 105 | int sqlite3BtreeGetMeta(Btree*, int idx, u32 *pValue); |
| 106 | int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value); |
paul | b95a886 | 2003-04-01 21:16:41 +0000 | [diff] [blame] | 107 | |
drh | 3aac2dd | 2004-04-26 14:10:20 +0000 | [diff] [blame] | 108 | int sqlite3BtreeCursor( |
| 109 | Btree*, /* BTree containing table to open */ |
| 110 | int iTable, /* Index of root page */ |
| 111 | int wrFlag, /* 1 for writing. 0 for read-only */ |
| 112 | int(*)(void*,int,const void*,int,const void*), /* Key comparison function */ |
| 113 | void*, /* First argument to compare function */ |
| 114 | BtCursor **ppCursor /* Returned cursor */ |
| 115 | ); |
paul | b95a886 | 2003-04-01 21:16:41 +0000 | [diff] [blame] | 116 | |
danielk1977 | bf3b721 | 2004-05-18 10:06:24 +0000 | [diff] [blame] | 117 | void sqlite3BtreeSetCompare( |
| 118 | BtCursor *, |
| 119 | int(*)(void*,int,const void*,int,const void*), |
| 120 | void* |
| 121 | ); |
| 122 | |
drh | a34b676 | 2004-05-07 13:30:42 +0000 | [diff] [blame] | 123 | int sqlite3BtreeCloseCursor(BtCursor*); |
drh | e4d9081 | 2007-03-29 05:51:49 +0000 | [diff] [blame] | 124 | int sqlite3BtreeMoveto(BtCursor*,const void *pKey,i64 nKey,int bias,int *pRes); |
drh | 3aac2dd | 2004-04-26 14:10:20 +0000 | [diff] [blame] | 125 | int sqlite3BtreeDelete(BtCursor*); |
drh | 4a1c380 | 2004-05-12 15:15:47 +0000 | [diff] [blame] | 126 | int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey, |
drh | b026e05 | 2007-05-02 01:34:31 +0000 | [diff] [blame] | 127 | const void *pData, int nData, |
| 128 | int nZero, int bias); |
drh | 3aac2dd | 2004-04-26 14:10:20 +0000 | [diff] [blame] | 129 | int sqlite3BtreeFirst(BtCursor*, int *pRes); |
| 130 | int sqlite3BtreeLast(BtCursor*, int *pRes); |
| 131 | int sqlite3BtreeNext(BtCursor*, int *pRes); |
drh | c39e000 | 2004-05-07 23:50:57 +0000 | [diff] [blame] | 132 | int sqlite3BtreeEof(BtCursor*); |
drh | f328bc8 | 2004-05-10 23:29:49 +0000 | [diff] [blame] | 133 | int sqlite3BtreeFlags(BtCursor*); |
drh | 3aac2dd | 2004-04-26 14:10:20 +0000 | [diff] [blame] | 134 | int sqlite3BtreePrevious(BtCursor*, int *pRes); |
drh | 4a1c380 | 2004-05-12 15:15:47 +0000 | [diff] [blame] | 135 | int sqlite3BtreeKeySize(BtCursor*, i64 *pSize); |
drh | 3aac2dd | 2004-04-26 14:10:20 +0000 | [diff] [blame] | 136 | int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*); |
drh | e51c44f | 2004-05-30 20:46:09 +0000 | [diff] [blame] | 137 | const void *sqlite3BtreeKeyFetch(BtCursor*, int *pAmt); |
| 138 | const void *sqlite3BtreeDataFetch(BtCursor*, int *pAmt); |
drh | 3aac2dd | 2004-04-26 14:10:20 +0000 | [diff] [blame] | 139 | int sqlite3BtreeDataSize(BtCursor*, u32 *pSize); |
| 140 | int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*); |
drh | 144f9ea | 2003-04-16 01:28:16 +0000 | [diff] [blame] | 141 | |
drh | 1dcdbc0 | 2007-01-27 02:24:54 +0000 | [diff] [blame] | 142 | char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*); |
drh | a34b676 | 2004-05-07 13:30:42 +0000 | [diff] [blame] | 143 | struct Pager *sqlite3BtreePager(Btree*); |
| 144 | |
danielk1977 | b4e9af9 | 2007-05-01 17:49:49 +0000 | [diff] [blame] | 145 | int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, const void*); |
danielk1977 | 2dec970 | 2007-05-02 16:48:37 +0000 | [diff] [blame^] | 146 | void sqlite3BtreeCacheOverflow(BtCursor *); |
drh | f328bc8 | 2004-05-10 23:29:49 +0000 | [diff] [blame] | 147 | |
drh | a34b676 | 2004-05-07 13:30:42 +0000 | [diff] [blame] | 148 | #ifdef SQLITE_TEST |
drh | 3e27c02 | 2004-07-23 00:01:38 +0000 | [diff] [blame] | 149 | int sqlite3BtreeCursorInfo(BtCursor*, int*, int); |
drh | c8629a1 | 2004-05-08 20:07:40 +0000 | [diff] [blame] | 150 | void sqlite3BtreeCursorList(Btree*); |
drh | a34b676 | 2004-05-07 13:30:42 +0000 | [diff] [blame] | 151 | #endif |
| 152 | |
danielk1977 | b5402fb | 2005-01-12 07:15:04 +0000 | [diff] [blame] | 153 | #ifdef SQLITE_DEBUG |
| 154 | int sqlite3BtreePageDump(Btree*, int, int recursive); |
| 155 | #else |
| 156 | #define sqlite3BtreePageDump(X,Y,Z) SQLITE_OK |
| 157 | #endif |
drh | be0072d | 2001-09-13 14:46:09 +0000 | [diff] [blame] | 158 | |
| 159 | #endif /* _BTREE_H_ */ |