1a059ad07Sdrh /* 2b19a2bc6Sdrh ** 2001 September 15 3a059ad07Sdrh ** 4b19a2bc6Sdrh ** The author disclaims copyright to this source code. In place of 5b19a2bc6Sdrh ** a legal notice, here is a blessing: 6a059ad07Sdrh ** 7b19a2bc6Sdrh ** May you do good and not evil. 8b19a2bc6Sdrh ** May you find forgiveness for yourself and forgive others. 9b19a2bc6Sdrh ** May you share freely, never taking more than you give. 10a059ad07Sdrh ** 11a059ad07Sdrh ************************************************************************* 12a059ad07Sdrh ** This header file defines the interface that the sqlite B-Tree file 136446c4dcSdrh ** subsystem. See comments in the source code for a detailed description 146446c4dcSdrh ** of what each interface routine does. 15a059ad07Sdrh */ 1643f58d6aSdrh #ifndef SQLITE_BTREE_H 1743f58d6aSdrh #define SQLITE_BTREE_H 18a059ad07Sdrh 194adee20fSdanielk1977 /* TODO: This definition is just included so other modules compile. It 204adee20fSdanielk1977 ** needs to be revisited. 214adee20fSdanielk1977 */ 2291618564Sdrh #define SQLITE_N_BTREE_META 16 234adee20fSdanielk1977 2473509eeeSdrh /* 25951af805Sdanielk1977 ** If defined as non-zero, auto-vacuum is enabled by default. Otherwise 26951af805Sdanielk1977 ** it must be turned on for each database using "PRAGMA auto_vacuum = 1". 27951af805Sdanielk1977 */ 28951af805Sdanielk1977 #ifndef SQLITE_DEFAULT_AUTOVACUUM 29951af805Sdanielk1977 #define SQLITE_DEFAULT_AUTOVACUUM 0 30951af805Sdanielk1977 #endif 31951af805Sdanielk1977 32dddbcdccSdanielk1977 #define BTREE_AUTOVACUUM_NONE 0 /* Do not do auto-vacuum */ 33dddbcdccSdanielk1977 #define BTREE_AUTOVACUUM_FULL 1 /* Do full auto-vacuum */ 34dddbcdccSdanielk1977 #define BTREE_AUTOVACUUM_INCR 2 /* Incremental vacuum */ 35dddbcdccSdanielk1977 36951af805Sdanielk1977 /* 3773509eeeSdrh ** Forward declarations of structure 3873509eeeSdrh */ 39a059ad07Sdrh typedef struct Btree Btree; 40a059ad07Sdrh typedef struct BtCursor BtCursor; 41aef0bf64Sdanielk1977 typedef struct BtShared BtShared; 428eeb4463Sdrh typedef struct BtreePayload BtreePayload; 43b95a8864Spaul 4473509eeeSdrh 4524162fe6Sdanielk1977 int sqlite3BtreeOpen( 463a6d8aecSdan sqlite3_vfs *pVfs, /* VFS to use with this b-tree */ 4790f5ecb3Sdrh const char *zFilename, /* Name of database file to open */ 48aef0bf64Sdanielk1977 sqlite3 *db, /* Associated database connection */ 490d19f7acSdanielk1977 Btree **ppBtree, /* Return open Btree* here */ 5033f4e02aSdrh int flags, /* Flags */ 5133f4e02aSdrh int vfsFlags /* Flags passed through to VFS open */ 5224162fe6Sdanielk1977 ); 533aac2dd7Sdrh 543aac2dd7Sdrh /* The flags parameter to sqlite3BtreeOpen can be the bitwise or of the 553aac2dd7Sdrh ** following values. 567bec505eSdrh ** 577bec505eSdrh ** NOTE: These values must match the corresponding PAGER_ values in 587bec505eSdrh ** pager.h. 5973509eeeSdrh */ 60d4187c71Sdrh #define BTREE_OMIT_JOURNAL 1 /* Do not create or use a rollback journal */ 6133f111dcSdrh #define BTREE_MEMORY 2 /* This is an in-memory DB */ 6233f111dcSdrh #define BTREE_SINGLE 4 /* The file contains at most 1 b-tree */ 6333f111dcSdrh #define BTREE_UNORDERED 8 /* Use of a hash implementation is OK */ 64e53831d6Sdrh 653aac2dd7Sdrh int sqlite3BtreeClose(Btree*); 663aac2dd7Sdrh int sqlite3BtreeSetCacheSize(Btree*,int); 679b0cf34fSdrh int sqlite3BtreeSetSpillSize(Btree*,int); 6818c7e40cSdrh #if SQLITE_MAX_MMAP_SIZE>0 690d0614bdSdrh int sqlite3BtreeSetMmapLimit(Btree*,sqlite3_int64); 7018c7e40cSdrh #endif 7140c3941cSdrh int sqlite3BtreeSetPagerFlags(Btree*,unsigned); 720d19f7acSdanielk1977 int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix); 7390f5ecb3Sdrh int sqlite3BtreeGetPageSize(Btree*); 74e9261dbdSdrh Pgno sqlite3BtreeMaxPageCount(Btree*,Pgno); 75584e8b76Sdrh Pgno sqlite3BtreeLastPage(Btree*); 765b47efa6Sdrh int sqlite3BtreeSecureDelete(Btree*,int); 7745248de3Sdrh int sqlite3BtreeGetRequestedReserve(Btree*); 780094f37eSdan int sqlite3BtreeGetReserveNoMutex(Btree *p); 79951af805Sdanielk1977 int sqlite3BtreeSetAutoVacuum(Btree *, int); 80951af805Sdanielk1977 int sqlite3BtreeGetAutoVacuum(Btree *); 81bb2d9b1bSdrh int sqlite3BtreeBeginTrans(Btree*,int,int*); 82067b92baSdrh int sqlite3BtreeCommitPhaseOne(Btree*, const char*); 8360939d0aSdan int sqlite3BtreeCommitPhaseTwo(Btree*, int); 843aac2dd7Sdrh int sqlite3BtreeCommit(Btree*); 8547b7fc78Sdrh int sqlite3BtreeRollback(Btree*,int,int); 86bd43455cSdanielk1977 int sqlite3BtreeBeginStmt(Btree*,int); 87abc38158Sdrh int sqlite3BtreeCreateTable(Btree*, Pgno*, int flags); 8899744fa4Sdrh int sqlite3BtreeTxnState(Btree*); 890410302eSdanielk1977 int sqlite3BtreeIsInBackup(Btree*); 901e6c58deSshearer 91da184236Sdanielk1977 void *sqlite3BtreeSchema(Btree *, int, void(*)(void *)); 92602b466eSdanielk1977 int sqlite3BtreeSchemaLocked(Btree *pBtree); 932eb22af0Sdrh #ifndef SQLITE_OMIT_SHARED_CACHE 94602b466eSdanielk1977 int sqlite3BtreeLockTable(Btree *pBtree, int iTab, u8 isWriteLock); 952eb22af0Sdrh #endif 961e6c58deSshearer 971e6c58deSshearer /* Savepoints are named, nestable SQL transactions mostly implemented */ 981e6c58deSshearer /* in vdbe.c and pager.c See https://sqlite.org/lang_savepoint.html */ 99fd7f0452Sdanielk1977 int sqlite3BtreeSavepoint(Btree *, int, int); 1003aac2dd7Sdrh 1011e6c58deSshearer /* "Checkpoint" only refers to WAL. See https://sqlite.org/wal.html#ckpt */ 1021e6c58deSshearer #ifndef SQLITE_OMIT_WAL 1031e6c58deSshearer int sqlite3BtreeCheckpoint(Btree*, int, int *, int *); 1041e6c58deSshearer #endif 1051e6c58deSshearer 1064adee20fSdanielk1977 const char *sqlite3BtreeGetFilename(Btree *); 1075865e3d5Sdanielk1977 const char *sqlite3BtreeGetJournalname(Btree *); 1084adee20fSdanielk1977 int sqlite3BtreeCopyFile(Btree *, Btree *); 1094adee20fSdanielk1977 110dddbcdccSdanielk1977 int sqlite3BtreeIncrVacuum(Btree *); 111dddbcdccSdanielk1977 1123aac2dd7Sdrh /* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR 113d4187c71Sdrh ** of the flags shown below. 114d4187c71Sdrh ** 115d4187c71Sdrh ** Every SQLite table must have either BTREE_INTKEY or BTREE_BLOBKEY set. 116d4187c71Sdrh ** With BTREE_INTKEY, the table key is a 64-bit integer and arbitrary data 117d4187c71Sdrh ** is stored in the leaves. (BTREE_INTKEY is used for SQL tables.) With 118d4187c71Sdrh ** BTREE_BLOBKEY, the key is an arbitrary BLOB and no content is stored 119d4187c71Sdrh ** anywhere - the key is the content. (BTREE_BLOBKEY is used for SQL 120d4187c71Sdrh ** indices.) 12173509eeeSdrh */ 1228b18dd4fSdrh #define BTREE_INTKEY 1 /* Table has only 64-bit signed integer keys */ 123d4187c71Sdrh #define BTREE_BLOBKEY 2 /* Table has keys only - no data */ 1243aac2dd7Sdrh 125a0bf2652Sdanielk1977 int sqlite3BtreeDropTable(Btree*, int, int*); 126*2c718873Sdan int sqlite3BtreeClearTable(Btree*, int, i64*); 127079a3072Sdrh int sqlite3BtreeClearTableOfCursor(BtCursor*); 12880231042Sdan int sqlite3BtreeTripAllCursors(Btree*, int, int); 1290d19f7acSdanielk1977 130602b466eSdanielk1977 void sqlite3BtreeGetMeta(Btree *pBtree, int idx, u32 *pValue); 1313aac2dd7Sdrh int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value); 1320d19f7acSdanielk1977 133b483eba0Sdan int sqlite3BtreeNewDb(Btree *p); 134b483eba0Sdan 1350d19f7acSdanielk1977 /* 1360d19f7acSdanielk1977 ** The second parameter to sqlite3BtreeGetMeta or sqlite3BtreeUpdateMeta 1370d19f7acSdanielk1977 ** should be one of the following values. The integer values are assigned 1380d19f7acSdanielk1977 ** to constants so that the offset of the corresponding field in an 1390d19f7acSdanielk1977 ** SQLite database header may be found using the following formula: 1400d19f7acSdanielk1977 ** 1410d19f7acSdanielk1977 ** offset = 36 + (idx * 4) 1420d19f7acSdanielk1977 ** 1430d19f7acSdanielk1977 ** For example, the free-page-count field is located at byte offset 36 of 1440d19f7acSdanielk1977 ** the database file header. The incr-vacuum-flag field is located at 1450d19f7acSdanielk1977 ** byte offset 64 (== 36+4*7). 14691618564Sdrh ** 14791618564Sdrh ** The BTREE_DATA_VERSION value is not really a value stored in the header. 14891618564Sdrh ** It is a read-only number computed by the pager. But we merge it with 14991618564Sdrh ** the header value access routines since its access pattern is the same. 15091618564Sdrh ** Call it a "virtual meta value". 1510d19f7acSdanielk1977 */ 1520d19f7acSdanielk1977 #define BTREE_FREE_PAGE_COUNT 0 1530d19f7acSdanielk1977 #define BTREE_SCHEMA_VERSION 1 1540d19f7acSdanielk1977 #define BTREE_FILE_FORMAT 2 1550d19f7acSdanielk1977 #define BTREE_DEFAULT_CACHE_SIZE 3 1560d19f7acSdanielk1977 #define BTREE_LARGEST_ROOT_PAGE 4 1570d19f7acSdanielk1977 #define BTREE_TEXT_ENCODING 5 1580d19f7acSdanielk1977 #define BTREE_USER_VERSION 6 1590d19f7acSdanielk1977 #define BTREE_INCR_VACUUM 7 1604ee09b4bSdrh #define BTREE_APPLICATION_ID 8 16191618564Sdrh #define BTREE_DATA_VERSION 15 /* A virtual meta-value */ 1623aac2dd7Sdrh 163428c218cSdan /* 1640df57012Sdrh ** Kinds of hints that can be passed into the sqlite3BtreeCursorHint() 1650df57012Sdrh ** interface. 1660df57012Sdrh ** 1670df57012Sdrh ** BTREE_HINT_RANGE (arguments: Expr*, Mem*) 1680df57012Sdrh ** 1690df57012Sdrh ** The first argument is an Expr* (which is guaranteed to be constant for 1700df57012Sdrh ** the lifetime of the cursor) that defines constraints on which rows 1710df57012Sdrh ** might be fetched with this cursor. The Expr* tree may contain 1720df57012Sdrh ** TK_REGISTER nodes that refer to values stored in the array of registers 1730df57012Sdrh ** passed as the second parameter. In other words, if Expr.op==TK_REGISTER 1740df57012Sdrh ** then the value of the node is the value in Mem[pExpr.iTable]. Any 1750df57012Sdrh ** TK_COLUMN node in the expression tree refers to the Expr.iColumn-th 1760df57012Sdrh ** column of the b-tree of the cursor. The Expr tree will not contain 1770df57012Sdrh ** any function calls nor subqueries nor references to b-trees other than 1780df57012Sdrh ** the cursor being hinted. 1790df57012Sdrh ** 1800df57012Sdrh ** The design of the _RANGE hint is aid b-tree implementations that try 1810df57012Sdrh ** to prefetch content from remote machines - to provide those 1820df57012Sdrh ** implementations with limits on what needs to be prefetched and thereby 1830df57012Sdrh ** reduce network bandwidth. 1840403cb30Sdrh ** 1850403cb30Sdrh ** Note that BTREE_HINT_FLAGS with BTREE_BULKLOAD is the only hint used by 1860403cb30Sdrh ** standard SQLite. The other hints are provided for extentions that use 1870403cb30Sdrh ** the SQLite parser and code generator but substitute their own storage 1880403cb30Sdrh ** engine. 1890df57012Sdrh */ 190f7854c73Sdrh #define BTREE_HINT_RANGE 0 /* Range constraints on queries */ 1910df57012Sdrh 1920df57012Sdrh /* 1930df57012Sdrh ** Values that may be OR'd together to form the argument to the 1940df57012Sdrh ** BTREE_HINT_FLAGS hint for sqlite3BtreeCursorHint(): 195e0997b34Sdrh ** 196e0997b34Sdrh ** The BTREE_BULKLOAD flag is set on index cursors when the index is going 197e0997b34Sdrh ** to be filled with content that is already in sorted order. 198e0997b34Sdrh ** 199e0997b34Sdrh ** The BTREE_SEEK_EQ flag is set on cursors that will get OP_SeekGE or 200e0997b34Sdrh ** OP_SeekLE opcodes for a range search, but where the range of entries 201e0997b34Sdrh ** selected will all have the same key. In other words, the cursor will 202e0997b34Sdrh ** be used only for equality key searches. 203e0997b34Sdrh ** 204428c218cSdan */ 205e0997b34Sdrh #define BTREE_BULKLOAD 0x00000001 /* Used to full index in sorted order */ 206e0997b34Sdrh #define BTREE_SEEK_EQ 0x00000002 /* EQ seeks only - no range seeks */ 207428c218cSdan 208fd261ec6Sdan /* 209fd261ec6Sdan ** Flags passed as the third argument to sqlite3BtreeCursor(). 2102b4e9522Sdan ** 2112b4e9522Sdan ** For read-only cursors the wrFlag argument is always zero. For read-write 2129c0c57a4Sdrh ** cursors it may be set to either (BTREE_WRCSR|BTREE_FORDELETE) or just 2139c0c57a4Sdrh ** (BTREE_WRCSR). If the BTREE_FORDELETE bit is set, then the cursor will 2142b4e9522Sdan ** only be used by SQLite for the following: 2152b4e9522Sdan ** 2169c0c57a4Sdrh ** * to seek to and then delete specific entries, and/or 2172b4e9522Sdan ** 2182b4e9522Sdan ** * to read values that will be used to create keys that other 2192b4e9522Sdan ** BTREE_FORDELETE cursors will seek to and delete. 2209c0c57a4Sdrh ** 2219c0c57a4Sdrh ** The BTREE_FORDELETE flag is an optimization hint. It is not used by 2229c0c57a4Sdrh ** by this, the native b-tree engine of SQLite, but it is available to 2239c0c57a4Sdrh ** alternative storage engines that might be substituted in place of this 2249c0c57a4Sdrh ** b-tree system. For alternative storage engines in which a delete of 2259c0c57a4Sdrh ** the main table row automatically deletes corresponding index rows, 2269c0c57a4Sdrh ** the FORDELETE flag hint allows those alternative storage engines to 2279c0c57a4Sdrh ** skip a lot of work. Namely: FORDELETE cursors may treat all SEEK 2289c0c57a4Sdrh ** and DELETE operations as no-ops, and any READ operation against a 2299c0c57a4Sdrh ** FORDELETE cursor may return a null row: 0x01 0x00. 230fd261ec6Sdan */ 231fd261ec6Sdan #define BTREE_WRCSR 0x00000004 /* read-write cursor */ 232fd261ec6Sdan #define BTREE_FORDELETE 0x00000008 /* Cursor is for seek/delete only */ 233fd261ec6Sdan 2343aac2dd7Sdrh int sqlite3BtreeCursor( 2353aac2dd7Sdrh Btree*, /* BTree containing table to open */ 236abc38158Sdrh Pgno iTable, /* Index of root page */ 2373aac2dd7Sdrh int wrFlag, /* 1 for writing. 0 for read-only */ 2381e968a0cSdrh struct KeyInfo*, /* First argument to compare function */ 239cd3e8f7cSdanielk1977 BtCursor *pCursor /* Space to write cursor structure */ 2403aac2dd7Sdrh ); 241fe0cf7a1Sdrh BtCursor *sqlite3BtreeFakeValidCursor(void); 24259020f32Sdrh int sqlite3BtreeCursorSize(void); 243f25a5071Sdrh void sqlite3BtreeCursorZero(BtCursor*); 244f7854c73Sdrh void sqlite3BtreeCursorHintFlags(BtCursor*, unsigned); 245f7854c73Sdrh #ifdef SQLITE_ENABLE_CURSOR_HINTS 2460403cb30Sdrh void sqlite3BtreeCursorHint(BtCursor*, int, ...); 247f7854c73Sdrh #endif 2483aac2dd7Sdrh 249a34b6764Sdrh int sqlite3BtreeCloseCursor(BtCursor*); 25042a410dcSdrh int sqlite3BtreeTableMoveto( 251e63d9991Sdrh BtCursor*, 252e63d9991Sdrh i64 intKey, 253e63d9991Sdrh int bias, 254e63d9991Sdrh int *pRes 255e63d9991Sdrh ); 25642a410dcSdrh int sqlite3BtreeIndexMoveto( 25742a410dcSdrh BtCursor*, 25842a410dcSdrh UnpackedRecord *pUnKey, 25942a410dcSdrh int *pRes 26042a410dcSdrh ); 2616848dad8Sdrh int sqlite3BtreeCursorHasMoved(BtCursor*); 2626848dad8Sdrh int sqlite3BtreeCursorRestore(BtCursor*, int*); 263e807bdbaSdrh int sqlite3BtreeDelete(BtCursor*, u8 flags); 264e807bdbaSdrh 265f91c1318Sdan /* Allowed flags for sqlite3BtreeDelete() and sqlite3BtreeInsert() */ 266e807bdbaSdrh #define BTREE_SAVEPOSITION 0x02 /* Leave cursor pointing at NEXT or PREV */ 267def19e3bSdrh #define BTREE_AUXDELETE 0x04 /* not the primary delete operation */ 268f91c1318Sdan #define BTREE_APPEND 0x08 /* Insert is likely an append */ 2694049ede9Sdan #define BTREE_PREFORMAT 0x80 /* Inserted data is a preformated cell */ 270e807bdbaSdrh 2718eeb4463Sdrh /* An instance of the BtreePayload object describes the content of a single 2728eeb4463Sdrh ** entry in either an index or table btree. 2738eeb4463Sdrh ** 2748eeb4463Sdrh ** Index btrees (used for indexes and also WITHOUT ROWID tables) contain 27589ee2298Sdrh ** an arbitrary key and no data. These btrees have pKey,nKey set to the 27689ee2298Sdrh ** key and the pData,nData,nZero fields are uninitialized. The aMem,nMem 27789ee2298Sdrh ** fields give an array of Mem objects that are a decomposition of the key. 27889ee2298Sdrh ** The nMem field might be zero, indicating that no decomposition is available. 2798eeb4463Sdrh ** 2808eeb4463Sdrh ** Table btrees (used for rowid tables) contain an integer rowid used as 2818eeb4463Sdrh ** the key and passed in the nKey field. The pKey field is zero. 2828eeb4463Sdrh ** pData,nData hold the content of the new entry. nZero extra zero bytes 2838eeb4463Sdrh ** are appended to the end of the content when constructing the entry. 28489ee2298Sdrh ** The aMem,nMem fields are uninitialized for table btrees. 28589ee2298Sdrh ** 28689ee2298Sdrh ** Field usage summary: 28789ee2298Sdrh ** 28889ee2298Sdrh ** Table BTrees Index Btrees 28989ee2298Sdrh ** 29089ee2298Sdrh ** pKey always NULL encoded key 29189ee2298Sdrh ** nKey the ROWID length of pKey 29289ee2298Sdrh ** pData data not used 29389ee2298Sdrh ** aMem not used decomposed key value 29489ee2298Sdrh ** nMem not used entries in aMem 29589ee2298Sdrh ** nData length of pData not used 29689ee2298Sdrh ** nZero extra zeros after pData not used 2978eeb4463Sdrh ** 2988eeb4463Sdrh ** This object is used to pass information into sqlite3BtreeInsert(). The 2998eeb4463Sdrh ** same information used to be passed as five separate parameters. But placing 3008eeb4463Sdrh ** the information into this object helps to keep the interface more 3018eeb4463Sdrh ** organized and understandable, and it also helps the resulting code to 3028eeb4463Sdrh ** run a little faster by using fewer registers for parameter passing. 3038eeb4463Sdrh */ 3048eeb4463Sdrh struct BtreePayload { 3058eeb4463Sdrh const void *pKey; /* Key content for indexes. NULL for tables */ 3068eeb4463Sdrh sqlite3_int64 nKey; /* Size of pKey for indexes. PRIMARY KEY for tabs */ 30789ee2298Sdrh const void *pData; /* Data for tables. */ 3087a6ea93fSdrh sqlite3_value *aMem; /* First of nMem value in the unpacked pKey */ 3099b4eaebcSdrh u16 nMem; /* Number of aMem[] value. Might be zero */ 3108eeb4463Sdrh int nData; /* Size of pData. 0 if none. */ 3118eeb4463Sdrh int nZero; /* Extra zero data appended after pData,nData */ 3128eeb4463Sdrh }; 3138eeb4463Sdrh 3148eeb4463Sdrh int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload, 315f91c1318Sdan int flags, int seekResult); 3163aac2dd7Sdrh int sqlite3BtreeFirst(BtCursor*, int *pRes); 3173aac2dd7Sdrh int sqlite3BtreeLast(BtCursor*, int *pRes); 3182ab792e4Sdrh int sqlite3BtreeNext(BtCursor*, int flags); 319c39e000bSdrh int sqlite3BtreeEof(BtCursor*); 3202ab792e4Sdrh int sqlite3BtreePrevious(BtCursor*, int flags); 321a7c90c42Sdrh i64 sqlite3BtreeIntegerKey(BtCursor*); 3227b14b65dSdrh void sqlite3BtreeCursorPin(BtCursor*); 3237b14b65dSdrh void sqlite3BtreeCursorUnpin(BtCursor*); 324092457b1Sdrh #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC 325092457b1Sdrh i64 sqlite3BtreeOffset(BtCursor*); 326092457b1Sdrh #endif 327cb3cabd0Sdrh int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*); 328a7c90c42Sdrh const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt); 329a7c90c42Sdrh u32 sqlite3BtreePayloadSize(BtCursor*); 33053d30dd3Sdrh sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor*); 331144f9eadSdrh 332abc38158Sdrh char *sqlite3BtreeIntegrityCheck(sqlite3*,Btree*,Pgno*aRoot,int nRoot,int,int*); 333a34b6764Sdrh struct Pager *sqlite3BtreePager(Btree*); 3345e98e838Sdrh i64 sqlite3BtreeRowCountEst(BtCursor*); 335a34b6764Sdrh 3362eb22af0Sdrh #ifndef SQLITE_OMIT_INCRBLOB 337cb3cabd0Sdrh int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, void*); 338dcbb5d3fSdanielk1977 int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*); 3395a500afdSdan void sqlite3BtreeIncrblobCursor(BtCursor *); 3402eb22af0Sdrh #endif 341be51a65dSdanielk1977 void sqlite3BtreeClearCursor(BtCursor *); 342e04dc88bSdan int sqlite3BtreeSetVersion(Btree *pBt, int iVersion); 343e0997b34Sdrh int sqlite3BtreeCursorHasHint(BtCursor*, unsigned int mask); 344781597feSdrh int sqlite3BtreeIsReadonly(Btree *pBt); 345def6889dSdrh int sqlite3HeaderSizeBtree(void); 346e04dc88bSdan 34737ccfcfeSdrh #ifdef SQLITE_DEBUG 34837ccfcfeSdrh sqlite3_uint64 sqlite3BtreeSeekCount(Btree*); 34937ccfcfeSdrh #else 35037ccfcfeSdrh # define sqlite3BtreeSeekCount(X) 0 35137ccfcfeSdrh #endif 35237ccfcfeSdrh 353ea8ffdfeSdrh #ifndef NDEBUG 354ea8ffdfeSdrh int sqlite3BtreeCursorIsValid(BtCursor*); 355ea8ffdfeSdrh #endif 356d6ef5afeSdrh int sqlite3BtreeCursorIsValidNN(BtCursor*); 357ea8ffdfeSdrh 35821f6daa2Sdrh int sqlite3BtreeCount(sqlite3*, BtCursor*, i64*); 359a5533162Sdanielk1977 360a34b6764Sdrh #ifdef SQLITE_TEST 3613e27c026Sdrh int sqlite3BtreeCursorInfo(BtCursor*, int*, int); 362c8629a13Sdrh void sqlite3BtreeCursorList(Btree*); 363b5402fbfSdanielk1977 #endif 364be0072d2Sdrh 365a550f2deSdan #ifndef SQLITE_OMIT_WAL 366cdc1f049Sdan int sqlite3BtreeCheckpoint(Btree*, int, int *, int *); 367a550f2deSdan #endif 368a550f2deSdan 3697aae7358Sdan int sqlite3BtreeTransferRow(BtCursor*, BtCursor*, i64); 370036e0675Sdan 371b1ab8ea7Sdrh /* 372b1ab8ea7Sdrh ** If we are not using shared cache, then there is no need to 373b1ab8ea7Sdrh ** use mutexes to access the BtShared structures. So make the 374b1ab8ea7Sdrh ** Enter and Leave procedures no-ops. 375b1ab8ea7Sdrh */ 376f7590db0Sdanielk1977 #ifndef SQLITE_OMIT_SHARED_CACHE 377b1ab8ea7Sdrh void sqlite3BtreeEnter(Btree*); 378f7590db0Sdanielk1977 void sqlite3BtreeEnterAll(sqlite3*); 37920d876faSdan int sqlite3BtreeSharable(Btree*); 38020d876faSdan void sqlite3BtreeEnterCursor(BtCursor*); 381272989b4Sdan int sqlite3BtreeConnectionCount(Btree*); 382f7590db0Sdanielk1977 #else 383f7590db0Sdanielk1977 # define sqlite3BtreeEnter(X) 384f7590db0Sdanielk1977 # define sqlite3BtreeEnterAll(X) 38520d876faSdan # define sqlite3BtreeSharable(X) 0 38620d876faSdan # define sqlite3BtreeEnterCursor(X) 387272989b4Sdan # define sqlite3BtreeConnectionCount(X) 1 388a6f6d205Sshane #endif 389f7590db0Sdanielk1977 390f7590db0Sdanielk1977 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE 391f7590db0Sdanielk1977 void sqlite3BtreeLeave(Btree*); 392ff0587c6Sdrh void sqlite3BtreeLeaveCursor(BtCursor*); 393b1ab8ea7Sdrh void sqlite3BtreeLeaveAll(sqlite3*); 394a6f6d205Sshane #ifndef NDEBUG 395f7590db0Sdanielk1977 /* These routines are used inside assert() statements only. */ 396f7590db0Sdanielk1977 int sqlite3BtreeHoldsMutex(Btree*); 397f7590db0Sdanielk1977 int sqlite3BtreeHoldsAllMutexes(sqlite3*); 3982120608eSdrh int sqlite3SchemaMutexHeld(sqlite3*,int,Schema*); 399a6f6d205Sshane #endif 400f7590db0Sdanielk1977 #else 401f7590db0Sdanielk1977 402f7590db0Sdanielk1977 # define sqlite3BtreeLeave(X) 403ff0587c6Sdrh # define sqlite3BtreeLeaveCursor(X) 404b1ab8ea7Sdrh # define sqlite3BtreeLeaveAll(X) 405f7590db0Sdanielk1977 406f7590db0Sdanielk1977 # define sqlite3BtreeHoldsMutex(X) 1 407f7590db0Sdanielk1977 # define sqlite3BtreeHoldsAllMutexes(X) 1 408e54e0518Sdrh # define sqlite3SchemaMutexHeld(X,Y,Z) 1 409900b31efSdrh #endif 410900b31efSdrh 411900b31efSdrh 41243f58d6aSdrh #endif /* SQLITE_BTREE_H */ 413