vdbeInt.h
上传用户:sunhongbo
上传日期:2022-01-25
资源大小:3010k
文件大小:19k
- /*
- ** 2003 September 6
- **
- ** The author disclaims copyright to this source code. In place of
- ** a legal notice, here is a blessing:
- **
- ** May you do good and not evil.
- ** May you find forgiveness for yourself and forgive others.
- ** May you share freely, never taking more than you give.
- **
- *************************************************************************
- ** This is the header file for information that is private to the
- ** VDBE. This information used to all be at the top of the single
- ** source code file "vdbe.c". When that file became too big (over
- ** 6000 lines long) it was split up into several smaller files and
- ** this header information was factored out.
- */
- #ifndef _VDBEINT_H_
- #define _VDBEINT_H_
- /*
- ** intToKey() and keyToInt() used to transform the rowid. But with
- ** the latest versions of the design they are no-ops.
- */
- #define keyToInt(X) (X)
- #define intToKey(X) (X)
- /*
- ** SQL is translated into a sequence of instructions to be
- ** executed by a virtual machine. Each instruction is an instance
- ** of the following structure.
- */
- typedef struct VdbeOp Op;
- /*
- ** Boolean values
- */
- typedef unsigned char Bool;
- /*
- ** A cursor is a pointer into a single BTree within a database file.
- ** The cursor can seek to a BTree entry with a particular key, or
- ** loop over all entries of the Btree. You can also insert new BTree
- ** entries or retrieve the key or data from the entry that the cursor
- ** is currently pointing to.
- **
- ** Every cursor that the virtual machine has open is represented by an
- ** instance of the following structure.
- **
- ** If the Cursor.isTriggerRow flag is set it means that this cursor is
- ** really a single row that represents the NEW or OLD pseudo-table of
- ** a row trigger. The data for the row is stored in Cursor.pData and
- ** the rowid is in Cursor.iKey.
- */
- struct Cursor {
- BtCursor *pCursor; /* The cursor structure of the backend */
- int iDb; /* Index of cursor database in db->aDb[] (or -1) */
- i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
- i64 nextRowid; /* Next rowid returned by OP_NewRowid */
- Bool zeroed; /* True if zeroed out and ready for reuse */
- Bool rowidIsValid; /* True if lastRowid is valid */
- Bool atFirst; /* True if pointing to first entry */
- Bool useRandomRowid; /* Generate new record numbers semi-randomly */
- Bool nullRow; /* True if pointing to a row with no data */
- Bool nextRowidValid; /* True if the nextRowid field is valid */
- Bool pseudoTable; /* This is a NEW or OLD pseudo-tables of a trigger */
- Bool ephemPseudoTable;
- Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
- Bool isTable; /* True if a table requiring integer keys */
- Bool isIndex; /* True if an index containing keys only - no data */
- u8 bogusIncrKey; /* Something for pIncrKey to point to if pKeyInfo==0 */
- i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
- Btree *pBt; /* Separate file holding temporary table */
- int nData; /* Number of bytes in pData */
- char *pData; /* Data for a NEW or OLD pseudo-table */
- i64 iKey; /* Key for the NEW or OLD pseudo-table row */
- u8 *pIncrKey; /* Pointer to pKeyInfo->incrKey */
- KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
- int nField; /* Number of fields in the header */
- i64 seqCount; /* Sequence counter */
- sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
- const sqlite3_module *pModule; /* Module for cursor pVtabCursor */
- /* Cached information about the header for the data record that the
- ** cursor is currently pointing to. Only valid if cacheValid is true.
- ** aRow might point to (ephemeral) data for the current row, or it might
- ** be NULL.
- */
- int cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
- int payloadSize; /* Total number of bytes in the record */
- u32 *aType; /* Type values for all entries in the record */
- u32 *aOffset; /* Cached offsets to the start of each columns data */
- u8 *aRow; /* Data for the current row, if all on one page */
- };
- typedef struct Cursor Cursor;
- /*
- ** A value for Cursor.cacheValid that means the cache is always invalid.
- */
- #define CACHE_STALE 0
- /*
- ** Internally, the vdbe manipulates nearly all SQL values as Mem
- ** structures. Each Mem struct may cache multiple representations (string,
- ** integer etc.) of the same value. A value (and therefore Mem structure)
- ** has the following properties:
- **
- ** Each value has a manifest type. The manifest type of the value stored
- ** in a Mem struct is returned by the MemType(Mem*) macro. The type is
- ** one of SQLITE_NULL, SQLITE_INTEGER, SQLITE_REAL, SQLITE_TEXT or
- ** SQLITE_BLOB.
- */
- struct Mem {
- union {
- i64 i; /* Integer value. Or FuncDef* when flags==MEM_Agg */
- FuncDef *pDef; /* Used only when flags==MEM_Agg */
- } u;
- double r; /* Real value */
- sqlite3 *db; /* The associated database connection */
- char *z; /* String or BLOB value */
- int n; /* Number of characters in string value, excluding ' ' */
- u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
- u8 type; /* One of SQLITE_NULL, SQLITE_TEXT, SQLITE_INTEGER, etc */
- u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
- void (*xDel)(void *); /* If not null, call this function to delete Mem.z */
- char *zMalloc; /* Dynamic buffer allocated by sqlite3_malloc() */
- };
- /* One or more of the following flags are set to indicate the validOK
- ** representations of the value stored in the Mem struct.
- **
- ** If the MEM_Null flag is set, then the value is an SQL NULL value.
- ** No other flags may be set in this case.
- **
- ** If the MEM_Str flag is set then Mem.z points at a string representation.
- ** Usually this is encoded in the same unicode encoding as the main
- ** database (see below for exceptions). If the MEM_Term flag is also
- ** set, then the string is nul terminated. The MEM_Int and MEM_Real
- ** flags may coexist with the MEM_Str flag.
- **
- ** Multiple of these values can appear in Mem.flags. But only one
- ** at a time can appear in Mem.type.
- */
- #define MEM_Null 0x0001 /* Value is NULL */
- #define MEM_Str 0x0002 /* Value is a string */
- #define MEM_Int 0x0004 /* Value is an integer */
- #define MEM_Real 0x0008 /* Value is a real number */
- #define MEM_Blob 0x0010 /* Value is a BLOB */
- #define MemSetTypeFlag(p, f)
- ((p)->flags = ((p)->flags&~(MEM_Int|MEM_Real|MEM_Null|MEM_Blob|MEM_Str))|f)
- /* Whenever Mem contains a valid string or blob representation, one of
- ** the following flags must be set to determine the memory management
- ** policy for Mem.z. The MEM_Term flag tells us whether or not the
- ** string is