Team Ai
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
vdbeInt.h751 linesDownload Raw Back to src
1/*2** 2003 September 63**4** The author disclaims copyright to this source code.  In place of5** 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 is the header file for information that is private to the13** VDBE.  This information used to all be at the top of the single14** source code file "vdbe.c".  When that file became too big (over15** 6000 lines long) it was split up into several smaller files and16** this header information was factored out.17*/18#ifndef SQLITE_VDBEINT_H19#define SQLITE_VDBEINT_H20 21/*22** The maximum number of times that a statement will try to reparse23** itself before giving up and returning SQLITE_SCHEMA.24*/25#ifndef SQLITE_MAX_SCHEMA_RETRY26# define SQLITE_MAX_SCHEMA_RETRY 5027#endif28 29/*30** VDBE_DISPLAY_P4 is true or false depending on whether or not the31** "explain" P4 display logic is enabled.32*/33#if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) \34     || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG) \35     || defined(SQLITE_ENABLE_BYTECODE_VTAB)36# define VDBE_DISPLAY_P4 137#else38# define VDBE_DISPLAY_P4 039#endif40 41/*42** SQL is translated into a sequence of instructions to be43** executed by a virtual machine.  Each instruction is an instance44** of the following structure.45*/46typedef struct VdbeOp Op;47 48/*49** Boolean values50*/51typedef unsigned Bool;52 53/* Opaque type used by code in vdbesort.c */54typedef struct VdbeSorter VdbeSorter;55 56/* Elements of the linked list at Vdbe.pAuxData */57typedef struct AuxData AuxData;58 59/* A cache of large TEXT or BLOB values in a VdbeCursor */60typedef struct VdbeTxtBlbCache VdbeTxtBlbCache;61 62/* Types of VDBE cursors */63#define CURTYPE_BTREE       064#define CURTYPE_SORTER      165#define CURTYPE_VTAB        266#define CURTYPE_PSEUDO      367 68/*69** A VdbeCursor is an superclass (a wrapper) for various cursor objects:70**71**      * A b-tree cursor72**          -  In the main database or in an ephemeral database73**          -  On either an index or a table74**      * A sorter75**      * A virtual table76**      * A one-row "pseudotable" stored in a single register77*/78typedef struct VdbeCursor VdbeCursor;79struct VdbeCursor {80  u8 eCurType;            /* One of the CURTYPE_* values above */81  i8 iDb;                 /* Index of cursor database in db->aDb[] */82  u8 nullRow;             /* True if pointing to a row with no data */83  u8 deferredMoveto;      /* A call to sqlite3BtreeMoveto() is needed */84  u8 isTable;             /* True for rowid tables.  False for indexes */85#ifdef SQLITE_DEBUG86  u8 seekOp;              /* Most recent seek operation on this cursor */87  u8 wrFlag;              /* The wrFlag argument to sqlite3BtreeCursor() */88#endif89  Bool isEphemeral:1;     /* True for an ephemeral table */90  Bool useRandomRowid:1;  /* Generate new record numbers semi-randomly */91  Bool isOrdered:1;       /* True if the table is not BTREE_UNORDERED */92  Bool noReuse:1;         /* OpenEphemeral may not reuse this cursor */93  Bool colCache:1;        /* pCache pointer is initialized and non-NULL */94  u16 seekHit;            /* See the OP_SeekHit and OP_IfNoHope opcodes */95  union {                 /* pBtx for isEphermeral.  pAltMap otherwise */96    Btree *pBtx;            /* Separate file holding temporary table */97    u32 *aAltMap;           /* Mapping from table to index column numbers */98  } ub;99  i64 seqCount;           /* Sequence counter */100 101  /* Cached OP_Column parse information is only valid if cacheStatus matches102  ** Vdbe.cacheCtr.  Vdbe.cacheCtr will never take on the value of103  ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that104  ** the cache is out of date. */105  u32 cacheStatus;        /* Cache is valid if this matches Vdbe.cacheCtr */106  int seekResult;         /* Result of previous sqlite3BtreeMoveto() or 0107                          ** if there have been no prior seeks on the cursor. */108  /* seekResult does not distinguish between "no seeks have ever occurred109  ** on this cursor" and "the most recent seek was an exact match".110  ** For CURTYPE_PSEUDO, seekResult is the register holding the record */111 112  /* When a new VdbeCursor is allocated, only the fields above are zeroed.113  ** The fields that follow are uninitialized, and must be individually114  ** initialized prior to first use. */115  VdbeCursor *pAltCursor; /* Associated index cursor from which to read */116  union {117    BtCursor *pCursor;          /* CURTYPE_BTREE or _PSEUDO.  Btree cursor */118    sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB.              Vtab cursor */119    VdbeSorter *pSorter;        /* CURTYPE_SORTER.            Sorter object */120  } uc;121  KeyInfo *pKeyInfo;      /* Info about index keys needed by index cursors */122  u32 iHdrOffset;         /* Offset to next unparsed byte of the header */123  Pgno pgnoRoot;          /* Root page of the open btree cursor */124  i16 nField;             /* Number of fields in the header */125  u16 nHdrParsed;         /* Number of header fields parsed so far */126  i64 movetoTarget;       /* Argument to the deferred sqlite3BtreeMoveto() */127  u32 *aOffset;           /* Pointer to aType[nField] */128  const u8 *aRow;         /* Data for the current row, if all on one page */129  u32 payloadSize;        /* Total number of bytes in the record */130  u32 szRow;              /* Byte available in aRow */131#ifdef SQLITE_ENABLE_COLUMN_USED_MASK132  u64 maskUsed;           /* Mask of columns used by this cursor */133#endif134  VdbeTxtBlbCache *pCache; /* Cache of large TEXT or BLOB values */135 136  /* Space is allocated for aType to hold at least 2*nField+1 entries:137  ** nField slots for aType[] and nField+1 array slots for aOffset[] */138  u32 aType[FLEXARRAY];    /* Type values record decode.  MUST BE LAST */139};140 141/*142** The size (in bytes) of a VdbeCursor object that has an nField value of N143** or less.  The value of SZ_VDBECURSOR(n) is guaranteed to be a multiple144** of 8.145*/146#define SZ_VDBECURSOR(N) \147    (ROUND8(offsetof(VdbeCursor,aType)) + ((N)+1)*sizeof(u64))148 149/* Return true if P is a null-only cursor150*/151#define IsNullCursor(P) \152  ((P)->eCurType==CURTYPE_PSEUDO && (P)->nullRow && (P)->seekResult==0)153 154/*155** A value for VdbeCursor.cacheStatus that means the cache is always invalid.156*/157#define CACHE_STALE 0158 159/*160** Large TEXT or BLOB values can be slow to load, so we want to avoid161** loading them more than once.  For that reason, large TEXT and BLOB values162** can be stored in a cache defined by this object, and attached to the163** VdbeCursor using the pCache field.164*/165struct VdbeTxtBlbCache {166  char *pCValue;        /* A RCStr buffer to hold the value */167  i64 iOffset;          /* File offset of the row being cached */168  int iCol;             /* Column for which the cache is valid */169  u32 cacheStatus;      /* Vdbe.cacheCtr value */170  u32 colCacheCtr;      /* Column cache counter */171};172 173/*174** When a sub-program is executed (OP_Program), a structure of this type175** is allocated to store the current value of the program counter, as176** well as the current memory cell array and various other frame specific177** values stored in the Vdbe struct. When the sub-program is finished,178** these values are copied back to the Vdbe from the VdbeFrame structure,179** restoring the state of the VM to as it was before the sub-program180** began executing.181**182** The memory for a VdbeFrame object is allocated and managed by a memory183** cell in the parent (calling) frame. When the memory cell is deleted or184** overwritten, the VdbeFrame object is not freed immediately. Instead, it185** is linked into the Vdbe.pDelFrame list. The contents of the Vdbe.pDelFrame186** list is deleted when the VM is reset in VdbeHalt(). The reason for doing187** this instead of deleting the VdbeFrame immediately is to avoid recursive188** calls to sqlite3VdbeMemRelease() when the memory cells belonging to the189** child frame are released.190**191** The currently executing frame is stored in Vdbe.pFrame. Vdbe.pFrame is192** set to NULL if the currently executing frame is the main program.193*/194typedef struct VdbeFrame VdbeFrame;195struct VdbeFrame {196  Vdbe *v;                /* VM this frame belongs to */197  VdbeFrame *pParent;     /* Parent of this frame, or NULL if parent is main */198  Op *aOp;                /* Program instructions for parent frame */199  Mem *aMem;              /* Array of memory cells for parent frame */200  VdbeCursor **apCsr;     /* Array of Vdbe cursors for parent frame */201  u8 *aOnce;              /* Bitmask used by OP_Once */202  void *token;            /* Copy of SubProgram.token */203  i64 lastRowid;          /* Last insert rowid (sqlite3.lastRowid) */204  AuxData *pAuxData;      /* Linked list of auxdata allocations */205#if SQLITE_DEBUG206  u32 iFrameMagic;        /* magic number for sanity checking */207#endif208  int nCursor;            /* Number of entries in apCsr */209  int pc;                 /* Program Counter in parent (calling) frame */210  int nOp;                /* Size of aOp array */211  int nMem;               /* Number of entries in aMem */212  int nChildMem;          /* Number of memory cells for child frame */213  int nChildCsr;          /* Number of cursors for child frame */214  i64 nChange;            /* Statement changes (Vdbe.nChange)     */215  i64 nDbChange;          /* Value of db->nChange */216};217 218/* Magic number for sanity checking on VdbeFrame objects */219#define SQLITE_FRAME_MAGIC 0x879fb71e220 221/*222** Return a pointer to the array of registers allocated for use223** by a VdbeFrame.224*/225#define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])226 227/*228** Internally, the vdbe manipulates nearly all SQL values as Mem229** structures. Each Mem struct may cache multiple representations (string,230** integer etc.) of the same value.231*/232struct sqlite3_value {233  union MemValue {234    double r;           /* Real value used when MEM_Real is set in flags */235    i64 i;              /* Integer value used when MEM_Int is set in flags */236    int nZero;          /* Extra zero bytes when MEM_Zero and MEM_Blob set */237    const char *zPType; /* Pointer type when MEM_Term|MEM_Subtype|MEM_Null */238    FuncDef *pDef;      /* Used only when flags==MEM_Agg */239  } u;240  char *z;            /* String or BLOB value */241  int n;              /* Number of characters in string value, excluding '\0' */242  u16 flags;          /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */243  u8  enc;            /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */244  u8  eSubtype;       /* Subtype for this value */245  /* ShallowCopy only needs to copy the information above */246  sqlite3 *db;        /* The associated database connection */247  int szMalloc;       /* Size of the zMalloc allocation */248  u32 uTemp;          /* Transient storage for serial_type in OP_MakeRecord */249  char *zMalloc;      /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */250  void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */251#ifdef SQLITE_DEBUG252  Mem *pScopyFrom;    /* This Mem is a shallow copy of pScopyFrom */253  u16 mScopyFlags;    /* flags value immediately after the shallow copy */254  u8  bScopy;         /* The pScopyFrom of some other Mem *might* point here */255#endif256};257 258/*259** Size of struct Mem not including the Mem.zMalloc member or anything that260** follows.261*/262#define MEMCELLSIZE offsetof(Mem,db)263 264/* One or more of the following flags are set to indicate the265** representations of the value stored in the Mem struct.266**267**  *  MEM_Null                An SQL NULL value268**269**  *  MEM_Null|MEM_Zero       An SQL NULL with the virtual table270**                             UPDATE no-change flag set271**272**  *  MEM_Null|MEM_Term|      An SQL NULL, but also contains a273**        MEM_Subtype          pointer accessible using274**                             sqlite3_value_pointer().275**276**  *  MEM_Null|MEM_Cleared    Special SQL NULL that compares non-equal277**                             to other NULLs even using the IS operator.278**279**  *  MEM_Str                 A string, stored in Mem.z with280**                             length Mem.n.  Zero-terminated if281**                             MEM_Term is set.  This flag is282**                             incompatible with MEM_Blob and283**                             MEM_Null, but can appear with MEM_Int,284**                             MEM_Real, and MEM_IntReal.285**286**  *  MEM_Blob                A blob, stored in Mem.z length Mem.n.287**                             Incompatible with MEM_Str, MEM_Null,288**                             MEM_Int, MEM_Real, and MEM_IntReal.289**290**  *  MEM_Blob|MEM_Zero       A blob in Mem.z of length Mem.n plus291**                             Mem.u.nZero extra 0x00 bytes at the end.292**293**  *  MEM_Int                 Integer stored in Mem.u.i.294**295**  *  MEM_Real                Real stored in Mem.u.r.296**297**  *  MEM_IntReal             Real stored as an integer in Mem.u.i.298**299** If the MEM_Null flag is set, then the value is an SQL NULL value.300** For a pointer type created using sqlite3_bind_pointer() or301** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set.302**303** If the MEM_Str flag is set then Mem.z points at a string representation.304** Usually this is encoded in the same unicode encoding as the main305** database (see below for exceptions). If the MEM_Term flag is also306** set, then the string is nul terminated. The MEM_Int and MEM_Real307** flags may coexist with the MEM_Str flag.308*/309#define MEM_Undefined 0x0000   /* Value is undefined */310#define MEM_Null      0x0001   /* Value is NULL (or a pointer) */311#define MEM_Str       0x0002   /* Value is a string */312#define MEM_Int       0x0004   /* Value is an integer */313#define MEM_Real      0x0008   /* Value is a real number */314#define MEM_Blob      0x0010   /* Value is a BLOB */315#define MEM_IntReal   0x0020   /* MEM_Int that stringifies like MEM_Real */316#define MEM_AffMask   0x003f   /* Mask of affinity bits */317 318/* Extra bits that modify the meanings of the core datatypes above319*/320#define MEM_FromBind  0x0040   /* Value originates from sqlite3_bind() */321 /*                   0x0080   // Available */322#define MEM_Cleared   0x0100   /* NULL set by OP_Null, not from data */323#define MEM_Term      0x0200   /* String in Mem.z is zero terminated */324#define MEM_Zero      0x0400   /* Mem.i contains count of 0s appended to blob */325#define MEM_Subtype   0x0800   /* Mem.eSubtype is valid */326#define MEM_TypeMask  0x0dbf   /* Mask of type bits */327 328/* Bits that determine the storage for Mem.z for a string or blob or329** aggregate accumulator.330*/331#define MEM_Dyn       0x1000   /* Need to call Mem.xDel() on Mem.z */332#define MEM_Static    0x2000   /* Mem.z points to a static string */333#define MEM_Ephem     0x4000   /* Mem.z points to an ephemeral string */334#define MEM_Agg       0x8000   /* Mem.z points to an agg function context */335 336/* Return TRUE if Mem X contains dynamically allocated content - anything337** that needs to be deallocated to avoid a leak.338*/339#define VdbeMemDynamic(X)  \340  (((X)->flags&(MEM_Agg|MEM_Dyn))!=0)341 342/*343** Clear any existing type flags from a Mem and replace them with f344*/345#define MemSetTypeFlag(p, f) \346   ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)347 348/*349** True if Mem X is a NULL-nochng type.350*/351#define MemNullNochng(X) \352  (((X)->flags&MEM_TypeMask)==(MEM_Null|MEM_Zero) \353    && (X)->n==0 && (X)->u.nZero==0)354 355/*356** Return true if a memory cell has been initialized and is valid.357** is for use inside assert() statements only.358**359** A Memory cell is initialized if at least one of the360** MEM_Null, MEM_Str, MEM_Int, MEM_Real, MEM_Blob, or MEM_IntReal bits361** is set.  It is "undefined" if all those bits are zero.362*/363#ifdef SQLITE_DEBUG364#define memIsValid(M)  ((M)->flags & MEM_AffMask)!=0365#endif366 367/*368** Each auxiliary data pointer stored by a user defined function369** implementation calling sqlite3_set_auxdata() is stored in an instance370** of this structure. All such structures associated with a single VM371** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed372** when the VM is halted (if not before).373*/374struct AuxData {375  int iAuxOp;                     /* Instruction number of OP_Function opcode */376  int iAuxArg;                    /* Index of function argument. */377  void *pAux;                     /* Aux data pointer */378  void (*xDeleteAux)(void*);      /* Destructor for the aux data */379  AuxData *pNextAux;              /* Next element in list */380};381 382/*383** The "context" argument for an installable function.  A pointer to an384** instance of this structure is the first argument to the routines used385** implement the SQL functions.386**387** There is a typedef for this structure in sqlite.h.  So all routines,388** even the public interface to SQLite, can use a pointer to this structure.389** But this file is the only place where the internal details of this390** structure are known.391**392** This structure is defined inside of vdbeInt.h because it uses substructures393** (Mem) which are only defined there.394*/395struct sqlite3_context {396  Mem *pOut;              /* The return value is stored here */397  FuncDef *pFunc;         /* Pointer to function information */398  Mem *pMem;              /* Memory cell used to store aggregate context */399  Vdbe *pVdbe;            /* The VM that owns this context */400  int iOp;                /* Instruction number of OP_Function */401  int isError;            /* Error code returned by the function. */402  u8 enc;                 /* Encoding to use for results */403  u8 skipFlag;            /* Skip accumulator loading if true */404  u16 argc;               /* Number of arguments */405  sqlite3_value *argv[FLEXARRAY]; /* Argument set */406};407 408/*409** The size (in bytes) of an sqlite3_context object that holds N410** argv[] arguments.411*/412#define SZ_CONTEXT(N)  \413   (offsetof(sqlite3_context,argv)+(N)*sizeof(sqlite3_value*))414 415 416/* The ScanStatus object holds a single value for the417** sqlite3_stmt_scanstatus() interface.418**419** aAddrRange[]:420**   This array is used by ScanStatus elements associated with EQP421**   notes that make an SQLITE_SCANSTAT_NCYCLE value available. It is422**   an array of up to 3 ranges of VM addresses for which the Vdbe.anCycle[]423**   values should be summed to calculate the NCYCLE value. Each pair of424**   integer addresses is a start and end address (both inclusive) for a range425**   instructions. A start value of 0 indicates an empty range.426*/427typedef struct ScanStatus ScanStatus;428struct ScanStatus {429  int addrExplain;                /* OP_Explain for loop */430  int aAddrRange[6];431  int addrLoop;                   /* Address of "loops" counter */432  int addrVisit;                  /* Address of "rows visited" counter */433  int iSelectID;                  /* The "Select-ID" for this loop */434  LogEst nEst;                    /* Estimated output rows per loop */435  char *zName;                    /* Name of table or index */436};437 438/* The DblquoteStr object holds the text of a double-quoted439** string for a prepared statement.  A linked list of these objects440** is constructed during statement parsing and is held on Vdbe.pDblStr.441** When computing a normalized SQL statement for an SQL statement, that442** list is consulted for each double-quoted identifier to see if the443** identifier should really be a string literal.444*/445typedef struct DblquoteStr DblquoteStr;446struct DblquoteStr {447  DblquoteStr *pNextStr;   /* Next string literal in the list */448  char z[8];               /* Dequoted value for the string */449};450 451/*452** An instance of the virtual machine.  This structure contains the complete453** state of the virtual machine.454**455** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()456** is really a pointer to an instance of this structure.457*/458struct Vdbe {459  sqlite3 *db;            /* The database connection that owns this statement */460  Vdbe **ppVPrev,*pVNext; /* Linked list of VDBEs with the same Vdbe.db */461  Parse *pParse;          /* Parsing context used to create this Vdbe */462  ynVar nVar;             /* Number of entries in aVar[] */463  int nMem;               /* Number of memory locations currently allocated */464  int nCursor;            /* Number of slots in apCsr[] */465  u32 cacheCtr;           /* VdbeCursor row cache generation counter */466  int pc;                 /* The program counter */467  int rc;                 /* Value to return */468  i64 nChange;            /* Number of db changes made since last reset */469  int iStatement;         /* Statement number (or 0 if has no opened stmt) */470  i64 iCurrentTime;       /* Value of julianday('now') for this statement */471  i64 nFkConstraint;      /* Number of imm. FK constraints this VM */472  i64 nStmtDefCons;       /* Number of def. constraints when stmt started */473  i64 nStmtDefImmCons;    /* Number of def. imm constraints when stmt started */474  Mem *aMem;              /* The memory locations */475  Mem **apArg;            /* Arguments xUpdate and xFilter vtab methods */476  VdbeCursor **apCsr;     /* One element of this array for each open cursor */477  Mem *aVar;              /* Values for the OP_Variable opcode. */478 479  /* When allocating a new Vdbe object, all of the fields below should be480  ** initialized to zero or NULL */481 482  Op *aOp;                /* Space to hold the virtual machine's program */483  int nOp;                /* Number of instructions in the program */484  int nOpAlloc;           /* Slots allocated for aOp[] */485  Mem *aColName;          /* Column names to return */486  Mem *pResultRow;        /* Current output row */487  char *zErrMsg;          /* Error message written here */488  VList *pVList;          /* Name of variables */489#ifndef SQLITE_OMIT_TRACE490  i64 startTime;          /* Time when query started - used for profiling */491#endif492#ifdef SQLITE_DEBUG493  int rcApp;              /* errcode set by sqlite3_result_error_code() */494  u32 nWrite;             /* Number of write operations that have occurred */495  int napArg;             /* Size of the apArg[] array */496#endif497  u16 nResColumn;         /* Number of columns in one row of the result set */498  u16 nResAlloc;          /* Column slots allocated to aColName[] */499  u8 errorAction;         /* Recovery action to do in case of an error */500  u8 minWriteFileFormat;  /* Minimum file format for writable database files */501  u8 prepFlags;           /* SQLITE_PREPARE_* flags */502  u8 eVdbeState;          /* On of the VDBE_*_STATE values */503  bft expired:2;          /* 1: recompile VM immediately  2: when convenient */504  bft explain:2;          /* 0: normal, 1: EXPLAIN, 2: EXPLAIN QUERY PLAN */505  bft changeCntOn:1;      /* True to update the change-counter */506  bft usesStmtJournal:1;  /* True if uses a statement journal */507  bft readOnly:1;         /* True for statements that do not write */508  bft bIsReader:1;        /* True for statements that read */509  bft haveEqpOps:1;       /* Bytecode supports EXPLAIN QUERY PLAN */510  yDbMask btreeMask;      /* Bitmask of db->aDb[] entries referenced */511  yDbMask lockMask;       /* Subset of btreeMask that requires a lock */512  u32 aCounter[9];        /* Counters used by sqlite3_stmt_status() */513  char *zSql;             /* Text of the SQL statement that generated this */514#ifdef SQLITE_ENABLE_NORMALIZE515  char *zNormSql;         /* Normalization of the associated SQL statement */516  DblquoteStr *pDblStr;   /* List of double-quoted string literals */517#endif518  void *pFree;            /* Free this when deleting the vdbe */519  VdbeFrame *pFrame;      /* Parent frame */520  VdbeFrame *pDelFrame;   /* List of frame objects to free on VM reset */521  int nFrame;             /* Number of frames in pFrame list */522  u32 expmask;            /* Binding to these vars invalidates VM */523  SubProgram *pProgram;   /* Linked list of all sub-programs used by VM */524  AuxData *pAuxData;      /* Linked list of auxdata allocations */525#ifdef SQLITE_ENABLE_STMT_SCANSTATUS526  int nScan;              /* Entries in aScan[] */527  ScanStatus *aScan;      /* Scan definitions for sqlite3_stmt_scanstatus() */528#endif529};530 531/*532** The following are allowed values for Vdbe.eVdbeState533*/534#define VDBE_INIT_STATE     0   /* Prepared statement under construction */535#define VDBE_READY_STATE    1   /* Ready to run but not yet started */536#define VDBE_RUN_STATE      2   /* Run in progress */537#define VDBE_HALT_STATE     3   /* Finished.  Need reset() or finalize() */538 539/*540** Structure used to store the context required by the541** sqlite3_preupdate_*() API functions.542*/543struct PreUpdate {544  Vdbe *v;545  VdbeCursor *pCsr;               /* Cursor to read old values from */546  int op;                         /* One of SQLITE_INSERT, UPDATE, DELETE */547  u8 *aRecord;                    /* old.* database record */548  KeyInfo *pKeyinfo;              /* Key information */549  UnpackedRecord *pUnpacked;      /* Unpacked version of aRecord[] */550  UnpackedRecord *pNewUnpacked;   /* Unpacked version of new.* record */551  int iNewReg;                    /* Register for new.* values */552  int iBlobWrite;                 /* Value returned by preupdate_blobwrite() */553  i64 iKey1;                      /* First key value passed to hook */554  i64 iKey2;                      /* Second key value passed to hook */555  Mem oldipk;                     /* Memory cell holding "old" IPK value */556  Mem *aNew;                      /* Array of new.* values */557  Table *pTab;                    /* Schema object being updated */558  Index *pPk;                     /* PK index if pTab is WITHOUT ROWID */559  sqlite3_value **apDflt;         /* Array of default values, if required */560  struct {561    u8 keyinfoSpace[SZ_KEYINFO_0];  /* Space to hold pKeyinfo[0] content */562  } uKey;563};564 565/*566** An instance of this object is used to pass an vector of values into567** OP_VFilter, the xFilter method of a virtual table.  The vector is the568** set of values on the right-hand side of an IN constraint.569**570** The value as passed into xFilter is an sqlite3_value with a "pointer"571** type, such as is generated by sqlite3_result_pointer() and read by572** sqlite3_value_pointer.  Such values have MEM_Term|MEM_Subtype|MEM_Null573** and a subtype of 'p'.  The sqlite3_vtab_in_first() and _next() interfaces574** know how to use this object to step through all the values in the575** right operand of the IN constraint.576*/577typedef struct ValueList ValueList;578struct ValueList {579  BtCursor *pCsr;          /* An ephemeral table holding all values */580  sqlite3_value *pOut;     /* Register to hold each decoded output value */581};582 583/* Size of content associated with serial types that fit into a584** single-byte varint.585*/586#ifndef SQLITE_AMALGAMATION587extern const u8 sqlite3SmallTypeSizes[];588#endif589 590/*591** Function prototypes592*/593void sqlite3VdbeError(Vdbe*, const char *, ...);594void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);595void sqlite3VdbeFreeCursorNN(Vdbe*,VdbeCursor*);596void sqliteVdbePopStack(Vdbe*,int);597int SQLITE_NOINLINE sqlite3VdbeHandleMovedCursor(VdbeCursor *p);598int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*);599int sqlite3VdbeCursorRestore(VdbeCursor*);600u32 sqlite3VdbeSerialTypeLen(u32);601u8 sqlite3VdbeOneByteSerialTypeLen(u8);602#ifdef SQLITE_MIXED_ENDIAN_64BIT_FLOAT603  u64 sqlite3FloatSwap(u64 in);604# define swapMixedEndianFloat(X)  X = sqlite3FloatSwap(X)605#else606# define swapMixedEndianFloat(X)607#endif608void sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);609void sqlite3VdbeDeleteAuxData(sqlite3*, AuxData**, int, int);610 611int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);612int sqlite3VdbeIdxKeyCompare(sqlite3*,VdbeCursor*,UnpackedRecord*,int*);613int sqlite3VdbeIdxRowid(sqlite3*, BtCursor*, i64*);614int sqlite3VdbeExec(Vdbe*);615#if !defined(SQLITE_OMIT_EXPLAIN) || defined(SQLITE_ENABLE_BYTECODE_VTAB)616int sqlite3VdbeNextOpcode(Vdbe*,Mem*,int,int*,int*,Op**);617char *sqlite3VdbeDisplayP4(sqlite3*,Op*);618#endif619#if defined(SQLITE_ENABLE_EXPLAIN_COMMENTS)620char *sqlite3VdbeDisplayComment(sqlite3*,const Op*,const char*);621#endif622#if !defined(SQLITE_OMIT_EXPLAIN)623int sqlite3VdbeList(Vdbe*);624#endif625int sqlite3VdbeHalt(Vdbe*);626int sqlite3VdbeChangeEncoding(Mem *, int);627int sqlite3VdbeMemTooBig(Mem*);628int sqlite3VdbeMemCopy(Mem*, const Mem*);629void sqlite3VdbeMemShallowCopy(Mem*, const Mem*, int);630void sqlite3VdbeMemMove(Mem*, Mem*);631int sqlite3VdbeMemNulTerminate(Mem*);632int sqlite3VdbeMemSetStr(Mem*, const char*, i64, u8, void(*)(void*));633void sqlite3VdbeMemSetInt64(Mem*, i64);634#ifdef SQLITE_OMIT_FLOATING_POINT635# define sqlite3VdbeMemSetDouble sqlite3VdbeMemSetInt64636#else637  void sqlite3VdbeMemSetDouble(Mem*, double);638#endif639void sqlite3VdbeMemSetPointer(Mem*, void*, const char*, void(*)(void*));640void sqlite3VdbeMemInit(Mem*,sqlite3*,u16);641void sqlite3VdbeMemSetNull(Mem*);642#ifndef SQLITE_OMIT_INCRBLOB643void sqlite3VdbeMemSetZeroBlob(Mem*,int);644#else645int sqlite3VdbeMemSetZeroBlob(Mem*,int);646#endif647#ifdef SQLITE_DEBUG648int sqlite3VdbeMemIsRowSet(const Mem*);649#endif650int sqlite3VdbeMemSetRowSet(Mem*);651void sqlite3VdbeMemZeroTerminateIfAble(Mem*);652int sqlite3VdbeMemMakeWriteable(Mem*);653int sqlite3VdbeMemStringify(Mem*, u8, u8);654int sqlite3IntFloatCompare(i64,double);655i64 sqlite3VdbeIntValue(const Mem*);656int sqlite3VdbeMemIntegerify(Mem*);657double sqlite3VdbeRealValue(Mem*);658int sqlite3VdbeBooleanValue(Mem*, int ifNull);659void sqlite3VdbeIntegerAffinity(Mem*);660int sqlite3VdbeMemRealify(Mem*);661int sqlite3VdbeMemNumerify(Mem*);662int sqlite3VdbeMemCast(Mem*,u8,u8);663int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*);664int sqlite3VdbeMemFromBtreeZeroOffset(BtCursor*,u32,Mem*);665void sqlite3VdbeMemRelease(Mem *p);666void sqlite3VdbeMemReleaseMalloc(Mem*p);667int sqlite3VdbeMemFinalize(Mem*, FuncDef*);668#ifndef SQLITE_OMIT_WINDOWFUNC669int sqlite3VdbeMemAggValue(Mem*, Mem*, FuncDef*);670#endif671#if !defined(SQLITE_OMIT_EXPLAIN) || defined(SQLITE_ENABLE_BYTECODE_VTAB)672const char *sqlite3OpcodeName(int);673#endif674int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);675int sqlite3VdbeMemClearAndResize(Mem *pMem, int n);676int sqlite3VdbeCloseStatement(Vdbe *, int);677#ifdef SQLITE_DEBUG678int sqlite3VdbeFrameIsValid(VdbeFrame*);679#endif680void sqlite3VdbeFrameMemDel(void*);      /* Destructor on Mem */681void sqlite3VdbeFrameDelete(VdbeFrame*); /* Actually deletes the Frame */682int sqlite3VdbeFrameRestore(VdbeFrame *);683#ifdef SQLITE_ENABLE_PREUPDATE_HOOK684void sqlite3VdbePreUpdateHook(685    Vdbe*,VdbeCursor*,int,const char*,Table*,i64,int,int);686#endif687int sqlite3VdbeTransferError(Vdbe *p);688 689int sqlite3VdbeSorterInit(sqlite3 *, int, VdbeCursor *);690void sqlite3VdbeSorterReset(sqlite3 *, VdbeSorter *);691void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);692int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *);693int sqlite3VdbeSorterNext(sqlite3 *, const VdbeCursor *);694int sqlite3VdbeSorterRewind(const VdbeCursor *, int *);695int sqlite3VdbeSorterWrite(const VdbeCursor *, Mem *);696int sqlite3VdbeSorterCompare(const VdbeCursor *, Mem *, int, int *);697 698void sqlite3VdbeValueListFree(void*);699 700#ifdef SQLITE_DEBUG701  void sqlite3VdbeIncrWriteCounter(Vdbe*, VdbeCursor*);702  void sqlite3VdbeAssertAbortable(Vdbe*);703#else704# define sqlite3VdbeIncrWriteCounter(V,C)705# define sqlite3VdbeAssertAbortable(V)706#endif707 708#if !defined(SQLITE_OMIT_SHARED_CACHE)709  void sqlite3VdbeEnter(Vdbe*);710#else711# define sqlite3VdbeEnter(X)712#endif713 714#if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0715  void sqlite3VdbeLeave(Vdbe*);716#else717# define sqlite3VdbeLeave(X)718#endif719 720#ifdef SQLITE_DEBUG721void sqlite3VdbeMemAboutToChange(Vdbe*,Mem*);722int sqlite3VdbeCheckMemInvariants(Mem*);723#endif724 725#ifndef SQLITE_OMIT_FOREIGN_KEY726int sqlite3VdbeCheckFkImmediate(Vdbe*);727int sqlite3VdbeCheckFkDeferred(Vdbe*);728#else729# define sqlite3VdbeCheckFkImmediate(p) 0730# define sqlite3VdbeCheckFkDeferred(p) 0731#endif732 733#ifdef SQLITE_DEBUG734  void sqlite3VdbePrintSql(Vdbe*);735  void sqlite3VdbeMemPrettyPrint(Mem *pMem, StrAccum *pStr);736#endif737#ifndef SQLITE_OMIT_UTF16738  int sqlite3VdbeMemTranslate(Mem*, u8);739  int sqlite3VdbeMemHandleBom(Mem *pMem);740#endif741 742#ifndef SQLITE_OMIT_INCRBLOB743  int sqlite3VdbeMemExpandBlob(Mem *);744  #define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)745#else746  #define sqlite3VdbeMemExpandBlob(x) SQLITE_OK747  #define ExpandBlob(P) SQLITE_OK748#endif749 750#endif /* !defined(SQLITE_VDBEINT_H) */751