btree.h 7.5 KB

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