engine/sqlite/src/btree.h
changeset 71 fbd95db6a4e1
parent 69 4a65cc85c4f3
child 72 2e267e7da513
equal deleted inserted replaced
69:4a65cc85c4f3 71:fbd95db6a4e1
     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 1282 2008-11-13 09:31:33Z LarsPson $
       
    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 #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 
       
    38 /*
       
    39 ** Forward declarations of structure
       
    40 */
       
    41 typedef struct Btree Btree;
       
    42 typedef struct BtCursor BtCursor;
       
    43 typedef struct BtShared BtShared;
       
    44 typedef struct BtreeMutexArray BtreeMutexArray;
       
    45 
       
    46 /*
       
    47 ** This structure records all of the Btrees that need to hold
       
    48 ** a mutex before we enter sqlite3VdbeExec().  The Btrees are
       
    49 ** are placed in aBtree[] in order of aBtree[]->pBt.  That way,
       
    50 ** we can always lock and unlock them all quickly.
       
    51 */
       
    52 struct BtreeMutexArray {
       
    53   int nMutex;
       
    54   Btree *aBtree[SQLITE_MAX_ATTACHED+1];
       
    55 };
       
    56 
       
    57 
       
    58 int sqlite3BtreeOpen(
       
    59   const char *zFilename,   /* Name of database file to open */
       
    60   sqlite3 *db,             /* Associated database connection */
       
    61   Btree **,                /* Return open Btree* here */
       
    62   int flags,               /* Flags */
       
    63   int vfsFlags             /* Flags passed through to VFS open */
       
    64 );
       
    65 
       
    66 /* The flags parameter to sqlite3BtreeOpen can be the bitwise or of the
       
    67 ** following values.
       
    68 **
       
    69 ** NOTE:  These values must match the corresponding PAGER_ values in
       
    70 ** pager.h.
       
    71 */
       
    72 #define BTREE_OMIT_JOURNAL  1  /* Do not use journal.  No argument */
       
    73 #define BTREE_NO_READLOCK   2  /* Omit readlocks on readonly files */
       
    74 #define BTREE_MEMORY        4  /* In-memory DB.  No argument */
       
    75 #define BTREE_READONLY      8  /* Open the database in read-only mode */
       
    76 #define BTREE_READWRITE    16  /* Open for both reading and writing */
       
    77 #define BTREE_CREATE       32  /* Create the database if it does not exist */
       
    78 
       
    79 /* Additional values for the 4th argument of sqlite3BtreeOpen that
       
    80 ** are not associated with PAGER_ values.
       
    81 */
       
    82 #define BTREE_PRIVATE      64  /* Never share with other connections */
       
    83 
       
    84 int sqlite3BtreeClose(Btree*);
       
    85 int sqlite3BtreeSetCacheSize(Btree*,int);
       
    86 int sqlite3BtreeSetSafetyLevel(Btree*,int,int);
       
    87 int sqlite3BtreeSyncDisabled(Btree*);
       
    88 int sqlite3BtreeSetPageSize(Btree*,int,int);
       
    89 int sqlite3BtreeGetPageSize(Btree*);
       
    90 int sqlite3BtreeMaxPageCount(Btree*,int);
       
    91 int sqlite3BtreeGetReserve(Btree*);
       
    92 int sqlite3BtreeSetAutoVacuum(Btree *, int);
       
    93 int sqlite3BtreeGetAutoVacuum(Btree *);
       
    94 int sqlite3BtreeBeginTrans(Btree*,int);
       
    95 int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
       
    96 int sqlite3BtreeCommitPhaseTwo(Btree*);
       
    97 int sqlite3BtreeCommit(Btree*);
       
    98 int sqlite3BtreeRollback(Btree*);
       
    99 int sqlite3BtreeBeginStmt(Btree*);
       
   100 int sqlite3BtreeCommitStmt(Btree*);
       
   101 int sqlite3BtreeRollbackStmt(Btree*);
       
   102 int sqlite3BtreeCreateTable(Btree*, int*, int flags);
       
   103 int sqlite3BtreeIsInTrans(Btree*);
       
   104 int sqlite3BtreeIsInStmt(Btree*);
       
   105 int sqlite3BtreeIsInReadTrans(Btree*);
       
   106 void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
       
   107 int sqlite3BtreeSchemaLocked(Btree *);
       
   108 int sqlite3BtreeLockTable(Btree *, int, u8);
       
   109 
       
   110 const char *sqlite3BtreeGetFilename(Btree *);
       
   111 const char *sqlite3BtreeGetDirname(Btree *);
       
   112 const char *sqlite3BtreeGetJournalname(Btree *);
       
   113 int sqlite3BtreeCopyFile(Btree *, Btree *);
       
   114 
       
   115 int sqlite3BtreeIncrVacuum(Btree *);
       
   116 
       
   117 /* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR
       
   118 ** of the following flags:
       
   119 */
       
   120 #define BTREE_INTKEY     1    /* Table has only 64-bit signed integer keys */
       
   121 #define BTREE_ZERODATA   2    /* Table has keys only - no data */
       
   122 #define BTREE_LEAFDATA   4    /* Data stored in leaves only.  Implies INTKEY */
       
   123 
       
   124 int sqlite3BtreeDropTable(Btree*, int, int*);
       
   125 int sqlite3BtreeClearTable(Btree*, int);
       
   126 int sqlite3BtreeGetMeta(Btree*, int idx, u32 *pValue);
       
   127 int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
       
   128 void sqlite3BtreeTripAllCursors(Btree*, int);
       
   129 
       
   130 int sqlite3BtreeCursor(
       
   131   Btree*,                              /* BTree containing table to open */
       
   132   int iTable,                          /* Index of root page */
       
   133   int wrFlag,                          /* 1 for writing.  0 for read-only */
       
   134   int(*)(void*,int,const void*,int,const void*),  /* Key comparison function */
       
   135   void*,                               /* First argument to compare function */
       
   136   BtCursor **ppCursor                  /* Returned cursor */
       
   137 );
       
   138 
       
   139 int sqlite3BtreeCloseCursor(BtCursor*);
       
   140 int sqlite3BtreeMoveto(BtCursor*,const void *pKey,i64 nKey,int bias,int *pRes);
       
   141 int sqlite3BtreeDelete(BtCursor*);
       
   142 int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
       
   143                                   const void *pData, int nData,
       
   144                                   int nZero, int bias);
       
   145 int sqlite3BtreeFirst(BtCursor*, int *pRes);
       
   146 int sqlite3BtreeLast(BtCursor*, int *pRes);
       
   147 int sqlite3BtreeNext(BtCursor*, int *pRes);
       
   148 int sqlite3BtreeEof(BtCursor*);
       
   149 int sqlite3BtreeFlags(BtCursor*);
       
   150 int sqlite3BtreePrevious(BtCursor*, int *pRes);
       
   151 int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
       
   152 int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
       
   153 sqlite3 *sqlite3BtreeCursorDb(const BtCursor*);
       
   154 const void *sqlite3BtreeKeyFetch(BtCursor*, int *pAmt);
       
   155 const void *sqlite3BtreeDataFetch(BtCursor*, int *pAmt);
       
   156 int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
       
   157 int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
       
   158 
       
   159 char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
       
   160 struct Pager *sqlite3BtreePager(Btree*);
       
   161 
       
   162 int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
       
   163 void sqlite3BtreeCacheOverflow(BtCursor *);
       
   164 
       
   165 #ifdef SQLITE_TEST
       
   166 int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
       
   167 void sqlite3BtreeCursorList(Btree*);
       
   168 int sqlite3BtreePageDump(Btree*, int, int recursive);
       
   169 #endif
       
   170 
       
   171 /*
       
   172 ** If we are not using shared cache, then there is no need to
       
   173 ** use mutexes to access the BtShared structures.  So make the
       
   174 ** Enter and Leave procedures no-ops.
       
   175 */
       
   176 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE
       
   177   void sqlite3BtreeEnter(Btree*);
       
   178   void sqlite3BtreeLeave(Btree*);
       
   179   int sqlite3BtreeHoldsMutex(Btree*);
       
   180   void sqlite3BtreeEnterCursor(BtCursor*);
       
   181   void sqlite3BtreeLeaveCursor(BtCursor*);
       
   182   void sqlite3BtreeEnterAll(sqlite3*);
       
   183   void sqlite3BtreeLeaveAll(sqlite3*);
       
   184   int sqlite3BtreeHoldsAllMutexes(sqlite3*);
       
   185   void sqlite3BtreeMutexArrayEnter(BtreeMutexArray*);
       
   186   void sqlite3BtreeMutexArrayLeave(BtreeMutexArray*);
       
   187   void sqlite3BtreeMutexArrayInsert(BtreeMutexArray*, Btree*);
       
   188 #else
       
   189 # define sqlite3BtreeEnter(X)
       
   190 # define sqlite3BtreeLeave(X)
       
   191 # define sqlite3BtreeHoldsMutex(X) 1
       
   192 # define sqlite3BtreeEnterCursor(X)
       
   193 # define sqlite3BtreeLeaveCursor(X)
       
   194 # define sqlite3BtreeEnterAll(X)
       
   195 # define sqlite3BtreeLeaveAll(X)
       
   196 # define sqlite3BtreeHoldsAllMutexes(X) 1
       
   197 # define sqlite3BtreeMutexArrayEnter(X)
       
   198 # define sqlite3BtreeMutexArrayLeave(X)
       
   199 # define sqlite3BtreeMutexArrayInsert(X,Y)
       
   200 #endif
       
   201 
       
   202 
       
   203 #endif /* _BTREE_H_ */