btree.h

Go to the documentation of this file.
00001 /*
00002 ** 2001 September 15
00003 **
00004 ** The author disclaims copyright to this source code.  In place of
00005 ** a legal notice, here is a blessing:
00006 **
00007 **    May you do good and not evil.
00008 **    May you find forgiveness for yourself and forgive others.
00009 **    May you share freely, never taking more than you give.
00010 **
00011 *************************************************************************
00012 ** This header file defines the interface that the sqlite B-Tree file
00013 ** subsystem.  See comments in the source code for a detailed description
00014 ** of what each interface routine does.
00015 **
00016 ** @(#) $Id: btree.h,v 1.105 2008/10/27 13:59:34 danielk1977 Exp $
00017 */
00018 #ifndef _BTREE_H_
00019 #define _BTREE_H_
00020 
00021 /* TODO: This definition is just included so other modules compile. It
00022 ** needs to be revisited.
00023 */
00024 #define SQLITE_N_BTREE_META 10
00025 
00026 /*
00027 ** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
00028 ** it must be turned on for each database using "PRAGMA auto_vacuum = 1".
00029 */
00030 #ifndef SQLITE_DEFAULT_AUTOVACUUM
00031   #define SQLITE_DEFAULT_AUTOVACUUM 0
00032 #endif
00033 
00034 #define BTREE_AUTOVACUUM_NONE 0        /* Do not do auto-vacuum */
00035 #define BTREE_AUTOVACUUM_FULL 1        /* Do full auto-vacuum */
00036 #define BTREE_AUTOVACUUM_INCR 2        /* Incremental vacuum */
00037 
00038 /*
00039 ** Forward declarations of structure
00040 */
00041 typedef struct Btree Btree;
00042 typedef struct BtCursor BtCursor;
00043 typedef struct BtShared BtShared;
00044 typedef struct BtreeMutexArray BtreeMutexArray;
00045 
00046 /*
00047 ** This structure records all of the Btrees that need to hold
00048 ** a mutex before we enter sqlite3VdbeExec().  The Btrees are
00049 ** are placed in aBtree[] in order of aBtree[]->pBt.  That way,
00050 ** we can always lock and unlock them all quickly.
00051 */
00052 struct BtreeMutexArray {
00053   int nMutex;
00054   Btree *aBtree[SQLITE_MAX_ATTACHED+1];
00055 };
00056 
00057 
00058 int sqlite3BtreeOpen(
00059   const char *zFilename,   /* Name of database file to open */
00060   sqlite3 *db,             /* Associated database connection */
00061   Btree **,                /* Return open Btree* here */
00062   int flags,               /* Flags */
00063   int vfsFlags             /* Flags passed through to VFS open */
00064 );
00065 
00066 /* The flags parameter to sqlite3BtreeOpen can be the bitwise or of the
00067 ** following values.
00068 **
00069 ** NOTE:  These values must match the corresponding PAGER_ values in
00070 ** pager.h.
00071 */
00072 #define BTREE_OMIT_JOURNAL  1  /* Do not use journal.  No argument */
00073 #define BTREE_NO_READLOCK   2  /* Omit readlocks on readonly files */
00074 #define BTREE_MEMORY        4  /* In-memory DB.  No argument */
00075 #define BTREE_READONLY      8  /* Open the database in read-only mode */
00076 #define BTREE_READWRITE    16  /* Open for both reading and writing */
00077 #define BTREE_CREATE       32  /* Create the database if it does not exist */
00078 
00079 int sqlite3BtreeClose(Btree*);
00080 int sqlite3BtreeSetCacheSize(Btree*,int);
00081 int sqlite3BtreeSetSafetyLevel(Btree*,int,int);
00082 int sqlite3BtreeSyncDisabled(Btree*);
00083 int sqlite3BtreeSetPageSize(Btree*,int,int);
00084 int sqlite3BtreeGetPageSize(Btree*);
00085 int sqlite3BtreeMaxPageCount(Btree*,int);
00086 int sqlite3BtreeGetReserve(Btree*);
00087 int sqlite3BtreeSetAutoVacuum(Btree *, int);
00088 int sqlite3BtreeGetAutoVacuum(Btree *);
00089 int sqlite3BtreeBeginTrans(Btree*,int);
00090 int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
00091 int sqlite3BtreeCommitPhaseTwo(Btree*);
00092 int sqlite3BtreeCommit(Btree*);
00093 int sqlite3BtreeRollback(Btree*);
00094 int sqlite3BtreeBeginStmt(Btree*);
00095 int sqlite3BtreeCommitStmt(Btree*);
00096 int sqlite3BtreeRollbackStmt(Btree*);
00097 int sqlite3BtreeCreateTable(Btree*, int*, int flags);
00098 int sqlite3BtreeIsInTrans(Btree*);
00099 int sqlite3BtreeIsInStmt(Btree*);
00100 int sqlite3BtreeIsInReadTrans(Btree*);
00101 void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
00102 int sqlite3BtreeSchemaLocked(Btree *);
00103 int sqlite3BtreeLockTable(Btree *, int, u8);
00104 
00105 const char *sqlite3BtreeGetFilename(Btree *);
00106 const char *sqlite3BtreeGetDirname(Btree *);
00107 const char *sqlite3BtreeGetJournalname(Btree *);
00108 int sqlite3BtreeCopyFile(Btree *, Btree *);
00109 
00110 int sqlite3BtreeIncrVacuum(Btree *);
00111 
00112 /* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR
00113 ** of the following flags:
00114 */
00115 #define BTREE_INTKEY     1    /* Table has only 64-bit signed integer keys */
00116 #define BTREE_ZERODATA   2    /* Table has keys only - no data */
00117 #define BTREE_LEAFDATA   4    /* Data stored in leaves only.  Implies INTKEY */
00118 
00119 int sqlite3BtreeDropTable(Btree*, int, int*);
00120 int sqlite3BtreeClearTable(Btree*, int, int*);
00121 int sqlite3BtreeGetMeta(Btree*, int idx, u32 *pValue);
00122 int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
00123 void sqlite3BtreeTripAllCursors(Btree*, int);
00124 
00125 int sqlite3BtreeCursor(
00126   Btree*,                              /* BTree containing table to open */
00127   int iTable,                          /* Index of root page */
00128   int wrFlag,                          /* 1 for writing.  0 for read-only */
00129   struct KeyInfo*,                     /* First argument to compare function */
00130   BtCursor *pCursor                    /* Space to write cursor structure */
00131 );
00132 int sqlite3BtreeCursorSize(void);
00133 
00134 int sqlite3BtreeCloseCursor(BtCursor*);
00135 int sqlite3BtreeMoveto(
00136   BtCursor*,
00137   const void *pKey,
00138   i64 nKey,
00139   int bias,
00140   int *pRes
00141 );
00142 int sqlite3BtreeMovetoUnpacked(
00143   BtCursor*,
00144   UnpackedRecord *pUnKey,
00145   i64 intKey,
00146   int bias,
00147   int *pRes
00148 );
00149 int sqlite3BtreeCursorHasMoved(BtCursor*, int*);
00150 int sqlite3BtreeDelete(BtCursor*);
00151 int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
00152                                   const void *pData, int nData,
00153                                   int nZero, int bias);
00154 int sqlite3BtreeFirst(BtCursor*, int *pRes);
00155 int sqlite3BtreeLast(BtCursor*, int *pRes);
00156 int sqlite3BtreeNext(BtCursor*, int *pRes);
00157 int sqlite3BtreeEof(BtCursor*);
00158 int sqlite3BtreeFlags(BtCursor*);
00159 int sqlite3BtreePrevious(BtCursor*, int *pRes);
00160 int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
00161 int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
00162 sqlite3 *sqlite3BtreeCursorDb(const BtCursor*);
00163 const void *sqlite3BtreeKeyFetch(BtCursor*, int *pAmt);
00164 const void *sqlite3BtreeDataFetch(BtCursor*, int *pAmt);
00165 int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
00166 int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
00167 
00168 char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
00169 struct Pager *sqlite3BtreePager(Btree*);
00170 
00171 int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
00172 void sqlite3BtreeCacheOverflow(BtCursor *);
00173 void sqlite3BtreeClearCursor(BtCursor *);
00174 
00175 #ifdef SQLITE_TEST
00176 int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
00177 void sqlite3BtreeCursorList(Btree*);
00178 #endif
00179 
00180 /*
00181 ** If we are not using shared cache, then there is no need to
00182 ** use mutexes to access the BtShared structures.  So make the
00183 ** Enter and Leave procedures no-ops.
00184 */
00185 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE
00186   void sqlite3BtreeEnter(Btree*);
00187   void sqlite3BtreeLeave(Btree*);
00188 #ifndef NDEBUG
00189   /* This routine is used inside assert() statements only. */
00190   int sqlite3BtreeHoldsMutex(Btree*);
00191 #endif
00192   void sqlite3BtreeEnterCursor(BtCursor*);
00193   void sqlite3BtreeLeaveCursor(BtCursor*);
00194   void sqlite3BtreeEnterAll(sqlite3*);
00195   void sqlite3BtreeLeaveAll(sqlite3*);
00196 #ifndef NDEBUG
00197   /* This routine is used inside assert() statements only. */
00198   int sqlite3BtreeHoldsAllMutexes(sqlite3*);
00199 #endif
00200   void sqlite3BtreeMutexArrayEnter(BtreeMutexArray*);
00201   void sqlite3BtreeMutexArrayLeave(BtreeMutexArray*);
00202   void sqlite3BtreeMutexArrayInsert(BtreeMutexArray*, Btree*);
00203 #else
00204 # define sqlite3BtreeEnter(X)
00205 # define sqlite3BtreeLeave(X)
00206 #ifndef NDEBUG
00207   /* This routine is used inside assert() statements only. */
00208 # define sqlite3BtreeHoldsMutex(X) 1
00209 #endif
00210 # define sqlite3BtreeEnterCursor(X)
00211 # define sqlite3BtreeLeaveCursor(X)
00212 # define sqlite3BtreeEnterAll(X)
00213 # define sqlite3BtreeLeaveAll(X)
00214 #ifndef NDEBUG
00215   /* This routine is used inside assert() statements only. */
00216 # define sqlite3BtreeHoldsAllMutexes(X) 1
00217 #endif
00218 # define sqlite3BtreeMutexArrayEnter(X)
00219 # define sqlite3BtreeMutexArrayLeave(X)
00220 # define sqlite3BtreeMutexArrayInsert(X,Y)
00221 #endif
00222 
00223 
00224 #endif /* _BTREE_H_ */

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:52 2011 by Doxygen 1.6.1