ds@1952: /* ds@1952: ** 2001 September 15 ds@1952: ** ds@1952: ** The author disclaims copyright to this source code. In place of ds@1952: ** a legal notice, here is a blessing: ds@1952: ** ds@1952: ** May you do good and not evil. ds@1952: ** May you find forgiveness for yourself and forgive others. ds@1952: ** May you share freely, never taking more than you give. ds@1952: ** ds@1952: ************************************************************************* ds@1952: ** This header file defines the interface that the sqlite B-Tree file ds@1952: ** subsystem. See comments in the source code for a detailed description ds@1952: ** of what each interface routine does. ds@1952: ** ds@1952: ** @(#) $Id$ ds@1952: */ ds@1952: #ifndef _BTREE_H_ ds@1952: #define _BTREE_H_ ds@1952: ds@1952: /* TODO: This definition is just included so other modules compile. It ds@1952: ** needs to be revisited. ds@1952: */ ds@1952: #define SQLITE_N_BTREE_META 10 ds@1952: ds@1952: /* ds@1952: ** If defined as non-zero, auto-vacuum is enabled by default. Otherwise ds@1952: ** it must be turned on for each database using "PRAGMA auto_vacuum = 1". ds@1952: */ ds@1952: #ifndef SQLITE_DEFAULT_AUTOVACUUM ds@1952: #define SQLITE_DEFAULT_AUTOVACUUM 0 ds@1952: #endif ds@1952: ds@1952: #define BTREE_AUTOVACUUM_NONE 0 /* Do not do auto-vacuum */ ds@1952: #define BTREE_AUTOVACUUM_FULL 1 /* Do full auto-vacuum */ ds@1952: #define BTREE_AUTOVACUUM_INCR 2 /* Incremental vacuum */ ds@1952: ds@1952: /* ds@1952: ** Forward declarations of structure ds@1952: */ ds@1952: typedef struct Btree Btree; ds@1952: typedef struct BtCursor BtCursor; ds@1952: typedef struct BtShared BtShared; ds@1952: typedef struct BtreeMutexArray BtreeMutexArray; ds@1952: ds@1952: /* ds@1952: ** This structure records all of the Btrees that need to hold ds@1952: ** a mutex before we enter sqlite3VdbeExec(). The Btrees are ds@1952: ** are placed in aBtree[] in order of aBtree[]->pBt. That way, ds@1952: ** we can always lock and unlock them all quickly. ds@1952: */ ds@1952: struct BtreeMutexArray { ds@1952: int nMutex; ds@1952: Btree *aBtree[SQLITE_MAX_ATTACHED+1]; ds@1952: }; ds@1952: ds@1952: ds@1952: int sqlite3BtreeOpen( ds@1952: const char *zFilename, /* Name of database file to open */ ds@1952: sqlite3 *db, /* Associated database connection */ ds@1952: Btree **, /* Return open Btree* here */ ds@1952: int flags, /* Flags */ ds@1952: int vfsFlags /* Flags passed through to VFS open */ ds@1952: ); ds@1952: ds@1952: /* The flags parameter to sqlite3BtreeOpen can be the bitwise or of the ds@1952: ** following values. ds@1952: ** ds@1952: ** NOTE: These values must match the corresponding PAGER_ values in ds@1952: ** pager.h. ds@1952: */ ds@1952: #define BTREE_OMIT_JOURNAL 1 /* Do not use journal. No argument */ ds@1952: #define BTREE_NO_READLOCK 2 /* Omit readlocks on readonly files */ ds@1952: #define BTREE_MEMORY 4 /* In-memory DB. No argument */ ds@1952: #define BTREE_READONLY 8 /* Open the database in read-only mode */ ds@1952: #define BTREE_READWRITE 16 /* Open for both reading and writing */ ds@1952: #define BTREE_CREATE 32 /* Create the database if it does not exist */ ds@1952: ds@1952: /* Additional values for the 4th argument of sqlite3BtreeOpen that ds@1952: ** are not associated with PAGER_ values. ds@1952: */ ds@1952: #define BTREE_PRIVATE 64 /* Never share with other connections */ ds@1952: ds@1952: int sqlite3BtreeClose(Btree*); ds@1952: int sqlite3BtreeSetBusyHandler(Btree*,BusyHandler*); ds@1952: int sqlite3BtreeSetCacheSize(Btree*,int); ds@1952: int sqlite3BtreeSetSafetyLevel(Btree*,int,int); ds@1952: int sqlite3BtreeSyncDisabled(Btree*); ds@1952: int sqlite3BtreeSetPageSize(Btree*,int,int); ds@1952: int sqlite3BtreeGetPageSize(Btree*); ds@1952: int sqlite3BtreeMaxPageCount(Btree*,int); ds@1952: int sqlite3BtreeGetReserve(Btree*); ds@1952: int sqlite3BtreeSetAutoVacuum(Btree *, int); ds@1952: int sqlite3BtreeGetAutoVacuum(Btree *); ds@1952: int sqlite3BtreeBeginTrans(Btree*,int); ds@1952: int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster); ds@1952: int sqlite3BtreeCommitPhaseTwo(Btree*); ds@1952: int sqlite3BtreeCommit(Btree*); ds@1952: int sqlite3BtreeRollback(Btree*); ds@1952: int sqlite3BtreeBeginStmt(Btree*); ds@1952: int sqlite3BtreeCommitStmt(Btree*); ds@1952: int sqlite3BtreeRollbackStmt(Btree*); ds@1952: int sqlite3BtreeCreateTable(Btree*, int*, int flags); ds@1952: int sqlite3BtreeIsInTrans(Btree*); ds@1952: int sqlite3BtreeIsInStmt(Btree*); ds@1952: int sqlite3BtreeIsInReadTrans(Btree*); ds@1952: void *sqlite3BtreeSchema(Btree *, int, void(*)(void *)); ds@1952: int sqlite3BtreeSchemaLocked(Btree *); ds@1952: int sqlite3BtreeLockTable(Btree *, int, u8); ds@1952: ds@1952: const char *sqlite3BtreeGetFilename(Btree *); ds@1952: const char *sqlite3BtreeGetDirname(Btree *); ds@1952: const char *sqlite3BtreeGetJournalname(Btree *); ds@1952: int sqlite3BtreeCopyFile(Btree *, Btree *); ds@1952: ds@1952: int sqlite3BtreeIncrVacuum(Btree *); ds@1952: ds@1952: /* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR ds@1952: ** of the following flags: ds@1952: */ ds@1952: #define BTREE_INTKEY 1 /* Table has only 64-bit signed integer keys */ ds@1952: #define BTREE_ZERODATA 2 /* Table has keys only - no data */ ds@1952: #define BTREE_LEAFDATA 4 /* Data stored in leaves only. Implies INTKEY */ ds@1952: ds@1952: int sqlite3BtreeDropTable(Btree*, int, int*); ds@1952: int sqlite3BtreeClearTable(Btree*, int); ds@1952: int sqlite3BtreeGetMeta(Btree*, int idx, u32 *pValue); ds@1952: int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value); ds@1952: void sqlite3BtreeTripAllCursors(Btree*, int); ds@1952: ds@1952: int sqlite3BtreeCursor( ds@1952: Btree*, /* BTree containing table to open */ ds@1952: int iTable, /* Index of root page */ ds@1952: int wrFlag, /* 1 for writing. 0 for read-only */ ds@1952: int(*)(void*,int,const void*,int,const void*), /* Key comparison function */ ds@1952: void*, /* First argument to compare function */ ds@1952: BtCursor **ppCursor /* Returned cursor */ ds@1952: ); ds@1952: ds@1952: int sqlite3BtreeCloseCursor(BtCursor*); ds@1952: int sqlite3BtreeMoveto(BtCursor*,const void *pKey,i64 nKey,int bias,int *pRes); ds@1952: int sqlite3BtreeDelete(BtCursor*); ds@1952: int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey, ds@1952: const void *pData, int nData, ds@1952: int nZero, int bias); ds@1952: int sqlite3BtreeFirst(BtCursor*, int *pRes); ds@1952: int sqlite3BtreeLast(BtCursor*, int *pRes); ds@1952: int sqlite3BtreeNext(BtCursor*, int *pRes); ds@1952: int sqlite3BtreeEof(BtCursor*); ds@1952: int sqlite3BtreeFlags(BtCursor*); ds@1952: int sqlite3BtreePrevious(BtCursor*, int *pRes); ds@1952: int sqlite3BtreeKeySize(BtCursor*, i64 *pSize); ds@1952: int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*); ds@1952: sqlite3 *sqlite3BtreeCursorDb(const BtCursor*); ds@1952: const void *sqlite3BtreeKeyFetch(BtCursor*, int *pAmt); ds@1952: const void *sqlite3BtreeDataFetch(BtCursor*, int *pAmt); ds@1952: int sqlite3BtreeDataSize(BtCursor*, u32 *pSize); ds@1952: int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*); ds@1952: ds@1952: char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*); ds@1952: struct Pager *sqlite3BtreePager(Btree*); ds@1952: ds@1952: int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*); ds@1952: void sqlite3BtreeCacheOverflow(BtCursor *); ds@1952: ds@1952: #ifdef SQLITE_TEST ds@1952: int sqlite3BtreeCursorInfo(BtCursor*, int*, int); ds@1952: void sqlite3BtreeCursorList(Btree*); ds@1952: int sqlite3BtreePageDump(Btree*, int, int recursive); ds@1952: #endif ds@1952: ds@1952: /* ds@1952: ** If we are not using shared cache, then there is no need to ds@1952: ** use mutexes to access the BtShared structures. So make the ds@1952: ** Enter and Leave procedures no-ops. ds@1952: */ ds@1952: #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE ds@1952: void sqlite3BtreeEnter(Btree*); ds@1952: void sqlite3BtreeLeave(Btree*); ds@1952: int sqlite3BtreeHoldsMutex(Btree*); ds@1952: void sqlite3BtreeEnterCursor(BtCursor*); ds@1952: void sqlite3BtreeLeaveCursor(BtCursor*); ds@1952: void sqlite3BtreeEnterAll(sqlite3*); ds@1952: void sqlite3BtreeLeaveAll(sqlite3*); ds@1952: int sqlite3BtreeHoldsAllMutexes(sqlite3*); ds@1952: void sqlite3BtreeMutexArrayEnter(BtreeMutexArray*); ds@1952: void sqlite3BtreeMutexArrayLeave(BtreeMutexArray*); ds@1952: void sqlite3BtreeMutexArrayInsert(BtreeMutexArray*, Btree*); ds@1952: #else ds@1952: # define sqlite3BtreeEnter(X) ds@1952: # define sqlite3BtreeLeave(X) ds@1952: # define sqlite3BtreeHoldsMutex(X) 1 ds@1952: # define sqlite3BtreeEnterCursor(X) ds@1952: # define sqlite3BtreeLeaveCursor(X) ds@1952: # define sqlite3BtreeEnterAll(X) ds@1952: # define sqlite3BtreeLeaveAll(X) ds@1952: # define sqlite3BtreeHoldsAllMutexes(X) 1 ds@1952: # define sqlite3BtreeMutexArrayEnter(X) ds@1952: # define sqlite3BtreeMutexArrayLeave(X) ds@1952: # define sqlite3BtreeMutexArrayInsert(X,Y) ds@1952: #endif ds@1952: ds@1952: ds@1952: #endif /* _BTREE_H_ */