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