Annotation of embedaddon/sqlite3/src/btree.h, revision 1.1.1.1

1.1       misho       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: #ifndef _BTREE_H_
                     17: #define _BTREE_H_
                     18: 
                     19: /* TODO: This definition is just included so other modules compile. It
                     20: ** needs to be revisited.
                     21: */
                     22: #define SQLITE_N_BTREE_META 10
                     23: 
                     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: 
                     32: #define BTREE_AUTOVACUUM_NONE 0        /* Do not do auto-vacuum */
                     33: #define BTREE_AUTOVACUUM_FULL 1        /* Do full auto-vacuum */
                     34: #define BTREE_AUTOVACUUM_INCR 2        /* Incremental vacuum */
                     35: 
                     36: /*
                     37: ** Forward declarations of structure
                     38: */
                     39: typedef struct Btree Btree;
                     40: typedef struct BtCursor BtCursor;
                     41: typedef struct BtShared BtShared;
                     42: 
                     43: 
                     44: int sqlite3BtreeOpen(
                     45:   sqlite3_vfs *pVfs,       /* VFS to use with this b-tree */
                     46:   const char *zFilename,   /* Name of database file to open */
                     47:   sqlite3 *db,             /* Associated database connection */
                     48:   Btree **ppBtree,         /* Return open Btree* here */
                     49:   int flags,               /* Flags */
                     50:   int vfsFlags             /* Flags passed through to VFS open */
                     51: );
                     52: 
                     53: /* The flags parameter to sqlite3BtreeOpen can be the bitwise or of the
                     54: ** following values.
                     55: **
                     56: ** NOTE:  These values must match the corresponding PAGER_ values in
                     57: ** pager.h.
                     58: */
                     59: #define BTREE_OMIT_JOURNAL  1  /* Do not create or use a rollback journal */
                     60: #define BTREE_NO_READLOCK   2  /* Omit readlocks on readonly files */
                     61: #define BTREE_MEMORY        4  /* This is an in-memory DB */
                     62: #define BTREE_SINGLE        8  /* The file contains at most 1 b-tree */
                     63: #define BTREE_UNORDERED    16  /* Use of a hash implementation is OK */
                     64: 
                     65: int sqlite3BtreeClose(Btree*);
                     66: int sqlite3BtreeSetCacheSize(Btree*,int);
                     67: int sqlite3BtreeSetSafetyLevel(Btree*,int,int,int);
                     68: int sqlite3BtreeSyncDisabled(Btree*);
                     69: int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
                     70: int sqlite3BtreeGetPageSize(Btree*);
                     71: int sqlite3BtreeMaxPageCount(Btree*,int);
                     72: u32 sqlite3BtreeLastPage(Btree*);
                     73: int sqlite3BtreeSecureDelete(Btree*,int);
                     74: int sqlite3BtreeGetReserve(Btree*);
                     75: int sqlite3BtreeSetAutoVacuum(Btree *, int);
                     76: int sqlite3BtreeGetAutoVacuum(Btree *);
                     77: int sqlite3BtreeBeginTrans(Btree*,int);
                     78: int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
                     79: int sqlite3BtreeCommitPhaseTwo(Btree*, int);
                     80: int sqlite3BtreeCommit(Btree*);
                     81: int sqlite3BtreeRollback(Btree*);
                     82: int sqlite3BtreeBeginStmt(Btree*,int);
                     83: int sqlite3BtreeCreateTable(Btree*, int*, int flags);
                     84: int sqlite3BtreeIsInTrans(Btree*);
                     85: int sqlite3BtreeIsInReadTrans(Btree*);
                     86: int sqlite3BtreeIsInBackup(Btree*);
                     87: void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
                     88: int sqlite3BtreeSchemaLocked(Btree *pBtree);
                     89: int sqlite3BtreeLockTable(Btree *pBtree, int iTab, u8 isWriteLock);
                     90: int sqlite3BtreeSavepoint(Btree *, int, int);
                     91: 
                     92: const char *sqlite3BtreeGetFilename(Btree *);
                     93: const char *sqlite3BtreeGetJournalname(Btree *);
                     94: int sqlite3BtreeCopyFile(Btree *, Btree *);
                     95: 
                     96: int sqlite3BtreeIncrVacuum(Btree *);
                     97: 
                     98: /* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR
                     99: ** of the flags shown below.
                    100: **
                    101: ** Every SQLite table must have either BTREE_INTKEY or BTREE_BLOBKEY set.
                    102: ** With BTREE_INTKEY, the table key is a 64-bit integer and arbitrary data
                    103: ** is stored in the leaves.  (BTREE_INTKEY is used for SQL tables.)  With
                    104: ** BTREE_BLOBKEY, the key is an arbitrary BLOB and no content is stored
                    105: ** anywhere - the key is the content.  (BTREE_BLOBKEY is used for SQL
                    106: ** indices.)
                    107: */
                    108: #define BTREE_INTKEY     1    /* Table has only 64-bit signed integer keys */
                    109: #define BTREE_BLOBKEY    2    /* Table has keys only - no data */
                    110: 
                    111: int sqlite3BtreeDropTable(Btree*, int, int*);
                    112: int sqlite3BtreeClearTable(Btree*, int, int*);
                    113: void sqlite3BtreeTripAllCursors(Btree*, int);
                    114: 
                    115: void sqlite3BtreeGetMeta(Btree *pBtree, int idx, u32 *pValue);
                    116: int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
                    117: 
                    118: /*
                    119: ** The second parameter to sqlite3BtreeGetMeta or sqlite3BtreeUpdateMeta
                    120: ** should be one of the following values. The integer values are assigned 
                    121: ** to constants so that the offset of the corresponding field in an
                    122: ** SQLite database header may be found using the following formula:
                    123: **
                    124: **   offset = 36 + (idx * 4)
                    125: **
                    126: ** For example, the free-page-count field is located at byte offset 36 of
                    127: ** the database file header. The incr-vacuum-flag field is located at
                    128: ** byte offset 64 (== 36+4*7).
                    129: */
                    130: #define BTREE_FREE_PAGE_COUNT     0
                    131: #define BTREE_SCHEMA_VERSION      1
                    132: #define BTREE_FILE_FORMAT         2
                    133: #define BTREE_DEFAULT_CACHE_SIZE  3
                    134: #define BTREE_LARGEST_ROOT_PAGE   4
                    135: #define BTREE_TEXT_ENCODING       5
                    136: #define BTREE_USER_VERSION        6
                    137: #define BTREE_INCR_VACUUM         7
                    138: 
                    139: int sqlite3BtreeCursor(
                    140:   Btree*,                              /* BTree containing table to open */
                    141:   int iTable,                          /* Index of root page */
                    142:   int wrFlag,                          /* 1 for writing.  0 for read-only */
                    143:   struct KeyInfo*,                     /* First argument to compare function */
                    144:   BtCursor *pCursor                    /* Space to write cursor structure */
                    145: );
                    146: int sqlite3BtreeCursorSize(void);
                    147: void sqlite3BtreeCursorZero(BtCursor*);
                    148: 
                    149: int sqlite3BtreeCloseCursor(BtCursor*);
                    150: int sqlite3BtreeMovetoUnpacked(
                    151:   BtCursor*,
                    152:   UnpackedRecord *pUnKey,
                    153:   i64 intKey,
                    154:   int bias,
                    155:   int *pRes
                    156: );
                    157: int sqlite3BtreeCursorHasMoved(BtCursor*, int*);
                    158: int sqlite3BtreeDelete(BtCursor*);
                    159: int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
                    160:                                   const void *pData, int nData,
                    161:                                   int nZero, int bias, int seekResult);
                    162: int sqlite3BtreeFirst(BtCursor*, int *pRes);
                    163: int sqlite3BtreeLast(BtCursor*, int *pRes);
                    164: int sqlite3BtreeNext(BtCursor*, int *pRes);
                    165: int sqlite3BtreeEof(BtCursor*);
                    166: int sqlite3BtreePrevious(BtCursor*, int *pRes);
                    167: int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
                    168: int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
                    169: const void *sqlite3BtreeKeyFetch(BtCursor*, int *pAmt);
                    170: const void *sqlite3BtreeDataFetch(BtCursor*, int *pAmt);
                    171: int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
                    172: int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
                    173: void sqlite3BtreeSetCachedRowid(BtCursor*, sqlite3_int64);
                    174: sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor*);
                    175: 
                    176: char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
                    177: struct Pager *sqlite3BtreePager(Btree*);
                    178: 
                    179: int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
                    180: void sqlite3BtreeCacheOverflow(BtCursor *);
                    181: void sqlite3BtreeClearCursor(BtCursor *);
                    182: 
                    183: int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
                    184: 
                    185: #ifndef NDEBUG
                    186: int sqlite3BtreeCursorIsValid(BtCursor*);
                    187: #endif
                    188: 
                    189: #ifndef SQLITE_OMIT_BTREECOUNT
                    190: int sqlite3BtreeCount(BtCursor *, i64 *);
                    191: #endif
                    192: 
                    193: #ifdef SQLITE_TEST
                    194: int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
                    195: void sqlite3BtreeCursorList(Btree*);
                    196: #endif
                    197: 
                    198: #ifndef SQLITE_OMIT_WAL
                    199:   int sqlite3BtreeCheckpoint(Btree*, int, int *, int *);
                    200: #endif
                    201: 
                    202: /*
                    203: ** If we are not using shared cache, then there is no need to
                    204: ** use mutexes to access the BtShared structures.  So make the
                    205: ** Enter and Leave procedures no-ops.
                    206: */
                    207: #ifndef SQLITE_OMIT_SHARED_CACHE
                    208:   void sqlite3BtreeEnter(Btree*);
                    209:   void sqlite3BtreeEnterAll(sqlite3*);
                    210: #else
                    211: # define sqlite3BtreeEnter(X) 
                    212: # define sqlite3BtreeEnterAll(X)
                    213: #endif
                    214: 
                    215: #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE
                    216:   int sqlite3BtreeSharable(Btree*);
                    217:   void sqlite3BtreeLeave(Btree*);
                    218:   void sqlite3BtreeEnterCursor(BtCursor*);
                    219:   void sqlite3BtreeLeaveCursor(BtCursor*);
                    220:   void sqlite3BtreeLeaveAll(sqlite3*);
                    221: #ifndef NDEBUG
                    222:   /* These routines are used inside assert() statements only. */
                    223:   int sqlite3BtreeHoldsMutex(Btree*);
                    224:   int sqlite3BtreeHoldsAllMutexes(sqlite3*);
                    225:   int sqlite3SchemaMutexHeld(sqlite3*,int,Schema*);
                    226: #endif
                    227: #else
                    228: 
                    229: # define sqlite3BtreeSharable(X) 0
                    230: # define sqlite3BtreeLeave(X)
                    231: # define sqlite3BtreeEnterCursor(X)
                    232: # define sqlite3BtreeLeaveCursor(X)
                    233: # define sqlite3BtreeLeaveAll(X)
                    234: 
                    235: # define sqlite3BtreeHoldsMutex(X) 1
                    236: # define sqlite3BtreeHoldsAllMutexes(X) 1
                    237: # define sqlite3SchemaMutexHeld(X,Y,Z) 1
                    238: #endif
                    239: 
                    240: 
                    241: #endif /* _BTREE_H_ */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>