xref: /sqlite-3.40.0/src/vdbeInt.h (revision e5928b17)
19a32464bSdrh /*
29a32464bSdrh ** 2003 September 6
39a32464bSdrh **
49a32464bSdrh ** The author disclaims copyright to this source code.  In place of
59a32464bSdrh ** a legal notice, here is a blessing:
69a32464bSdrh **
79a32464bSdrh **    May you do good and not evil.
89a32464bSdrh **    May you find forgiveness for yourself and forgive others.
99a32464bSdrh **    May you share freely, never taking more than you give.
109a32464bSdrh **
119a32464bSdrh *************************************************************************
129a32464bSdrh ** This is the header file for information that is private to the
139a32464bSdrh ** VDBE.  This information used to all be at the top of the single
149a32464bSdrh ** source code file "vdbe.c".  When that file became too big (over
159a32464bSdrh ** 6000 lines long) it was split up into several smaller files and
169a32464bSdrh ** this header information was factored out.
179a32464bSdrh */
1843f58d6aSdrh #ifndef SQLITE_VDBEINT_H
1943f58d6aSdrh #define SQLITE_VDBEINT_H
209a32464bSdrh 
219a32464bSdrh /*
2260625313Sdrh ** The maximum number of times that a statement will try to reparse
2360625313Sdrh ** itself before giving up and returning SQLITE_SCHEMA.
2460625313Sdrh */
2560625313Sdrh #ifndef SQLITE_MAX_SCHEMA_RETRY
2660625313Sdrh # define SQLITE_MAX_SCHEMA_RETRY 50
2760625313Sdrh #endif
2860625313Sdrh 
2960625313Sdrh /*
30f7e36907Sdrh ** VDBE_DISPLAY_P4 is true or false depending on whether or not the
31f7e36907Sdrh ** "explain" P4 display logic is enabled.
32f7e36907Sdrh */
33f7e36907Sdrh #if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) \
348c5163a6Sdrh      || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG) \
358c5163a6Sdrh      || defined(SQLITE_ENABLE_BYTECODE_VTAB)
36f7e36907Sdrh # define VDBE_DISPLAY_P4 1
37f7e36907Sdrh #else
38f7e36907Sdrh # define VDBE_DISPLAY_P4 0
39f7e36907Sdrh #endif
40f7e36907Sdrh 
41f7e36907Sdrh /*
429a32464bSdrh ** SQL is translated into a sequence of instructions to be
439a32464bSdrh ** executed by a virtual machine.  Each instruction is an instance
449a32464bSdrh ** of the following structure.
459a32464bSdrh */
469a32464bSdrh typedef struct VdbeOp Op;
479a32464bSdrh 
489a32464bSdrh /*
499a32464bSdrh ** Boolean values
509a32464bSdrh */
5114da87f8Sdrh typedef unsigned Bool;
529a32464bSdrh 
53a20fde64Sdan /* Opaque type used by code in vdbesort.c */
54a20fde64Sdan typedef struct VdbeSorter VdbeSorter;
55a20fde64Sdan 
560c547799Sdan /* Elements of the linked list at Vdbe.pAuxData */
570c547799Sdan typedef struct AuxData AuxData;
580c547799Sdan 
59c960dcbaSdrh /* Types of VDBE cursors */
60c960dcbaSdrh #define CURTYPE_BTREE       0
61c960dcbaSdrh #define CURTYPE_SORTER      1
62c960dcbaSdrh #define CURTYPE_VTAB        2
63c960dcbaSdrh #define CURTYPE_PSEUDO      3
64c960dcbaSdrh 
659a32464bSdrh /*
66c960dcbaSdrh ** A VdbeCursor is an superclass (a wrapper) for various cursor objects:
679a32464bSdrh **
68c960dcbaSdrh **      * A b-tree cursor
69c960dcbaSdrh **          -  In the main database or in an ephemeral database
70c960dcbaSdrh **          -  On either an index or a table
71c960dcbaSdrh **      * A sorter
72c960dcbaSdrh **      * A virtual table
73c960dcbaSdrh **      * A one-row "pseudotable" stored in a single register
749a32464bSdrh */
75de892d96Sdan typedef struct VdbeCursor VdbeCursor;
76dfe88eceSdrh struct VdbeCursor {
77c960dcbaSdrh   u8 eCurType;            /* One of the CURTYPE_* values above */
78b248668bSdrh   i8 iDb;                 /* Index of cursor database in db->aDb[] */
791fd522ffSdrh   u8 nullRow;             /* True if pointing to a row with no data */
801fd522ffSdrh   u8 deferredMoveto;      /* A call to sqlite3BtreeMoveto() is needed */
81c960dcbaSdrh   u8 isTable;             /* True for rowid tables.  False for indexes */
82c960dcbaSdrh #ifdef SQLITE_DEBUG
83c960dcbaSdrh   u8 seekOp;              /* Most recent seek operation on this cursor */
84b89aeb6aSdrh   u8 wrFlag;              /* The wrFlag argument to sqlite3BtreeCursor() */
85c960dcbaSdrh #endif
86079a3072Sdrh   Bool isEphemeral:1;     /* True for an ephemeral table */
8714da87f8Sdrh   Bool useRandomRowid:1;  /* Generate new record numbers semi-randomly */
8826bcc7cfSdrh   Bool isOrdered:1;       /* True if the table is not BTREE_UNORDERED */
8927a242c6Sdrh   Bool noReuse:1;         /* OpenEphemeral may not reuse this cursor */
90fa17e134Sdrh   u16 seekHit;            /* See the OP_SeekHit and OP_IfNoHope opcodes */
91b248668bSdrh   union {                 /* pBtx for isEphermeral.  pAltMap otherwise */
92fbd8cbdcSdrh     Btree *pBtx;            /* Separate file holding temporary table */
93abc38158Sdrh     u32 *aAltMap;           /* Mapping from table to index column numbers */
94b248668bSdrh   } ub;
95b248668bSdrh   i64 seqCount;           /* Sequence counter */
96fbd8cbdcSdrh 
97fbd8cbdcSdrh   /* Cached OP_Column parse information is only valid if cacheStatus matches
98fbd8cbdcSdrh   ** Vdbe.cacheCtr.  Vdbe.cacheCtr will never take on the value of
99fbd8cbdcSdrh   ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
100fbd8cbdcSdrh   ** the cache is out of date. */
101fbd8cbdcSdrh   u32 cacheStatus;        /* Cache is valid if this matches Vdbe.cacheCtr */
102fbd8cbdcSdrh   int seekResult;         /* Result of previous sqlite3BtreeMoveto() or 0
103fbd8cbdcSdrh                           ** if there have been no prior seeks on the cursor. */
104fe0cf7a1Sdrh   /* seekResult does not distinguish between "no seeks have ever occurred
105fe0cf7a1Sdrh   ** on this cursor" and "the most recent seek was an exact match".
106fe0cf7a1Sdrh   ** For CURTYPE_PSEUDO, seekResult is the register holding the record */
107fbd8cbdcSdrh 
108fbd8cbdcSdrh   /* When a new VdbeCursor is allocated, only the fields above are zeroed.
109fbd8cbdcSdrh   ** The fields that follow are uninitialized, and must be individually
110fbd8cbdcSdrh   ** initialized prior to first use. */
111fbd8cbdcSdrh   VdbeCursor *pAltCursor; /* Associated index cursor from which to read */
112c960dcbaSdrh   union {
113fe0cf7a1Sdrh     BtCursor *pCursor;          /* CURTYPE_BTREE or _PSEUDO.  Btree cursor */
114c960dcbaSdrh     sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB.              Vtab cursor */
115c960dcbaSdrh     VdbeSorter *pSorter;        /* CURTYPE_SORTER.            Sorter object */
116c960dcbaSdrh   } uc;
117c960dcbaSdrh   KeyInfo *pKeyInfo;      /* Info about index keys needed by index cursors */
118fbd8cbdcSdrh   u32 iHdrOffset;         /* Offset to next unparsed byte of the header */
119fbd8cbdcSdrh   Pgno pgnoRoot;          /* Root page of the open btree cursor */
120fbd8cbdcSdrh   i16 nField;             /* Number of fields in the header */
121fbd8cbdcSdrh   u16 nHdrParsed;         /* Number of header fields parsed so far */
1222e5de2f2Sdrh   i64 movetoTarget;       /* Argument to the deferred sqlite3BtreeMoveto() */
123fbd8cbdcSdrh   u32 *aOffset;           /* Pointer to aType[nField] */
124fbd8cbdcSdrh   const u8 *aRow;         /* Data for the current row, if all on one page */
125fbd8cbdcSdrh   u32 payloadSize;        /* Total number of bytes in the record */
126fbd8cbdcSdrh   u32 szRow;              /* Byte available in aRow */
12797bae794Sdrh #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
12897bae794Sdrh   u64 maskUsed;           /* Mask of columns used by this cursor */
12997bae794Sdrh #endif
1309188b389Sdrh 
1315cc1023eSdrh   /* 2*nField extra array elements allocated for aType[], beyond the one
1325cc1023eSdrh   ** static element declared in the structure.  nField total array slots for
1335cc1023eSdrh   ** aType[] and nField+1 array slots for aOffset[] */
134fbd8cbdcSdrh   u32 aType[1];           /* Type values record decode.  MUST BE LAST */
1359a32464bSdrh };
1369a32464bSdrh 
137eab6c125Sdrh /* Return true if P is a null-only cursor
138eab6c125Sdrh */
139eab6c125Sdrh #define IsNullCursor(P) \
140eab6c125Sdrh   ((P)->eCurType==CURTYPE_PSEUDO && (P)->nullRow && (P)->seekResult==0)
141eab6c125Sdrh 
14222fa36dcSdrh 
14322fa36dcSdrh /*
14422fa36dcSdrh ** A value for VdbeCursor.cacheStatus that means the cache is always invalid.
14522fa36dcSdrh */
14622fa36dcSdrh #define CACHE_STALE 0
14722fa36dcSdrh 
14865a7cd16Sdan /*
14965a7cd16Sdan ** When a sub-program is executed (OP_Program), a structure of this type
15065a7cd16Sdan ** is allocated to store the current value of the program counter, as
15165a7cd16Sdan ** well as the current memory cell array and various other frame specific
15265a7cd16Sdan ** values stored in the Vdbe struct. When the sub-program is finished,
15365a7cd16Sdan ** these values are copied back to the Vdbe from the VdbeFrame structure,
15465a7cd16Sdan ** restoring the state of the VM to as it was before the sub-program
15565a7cd16Sdan ** began executing.
15665a7cd16Sdan **
15727106570Sdan ** The memory for a VdbeFrame object is allocated and managed by a memory
15827106570Sdan ** cell in the parent (calling) frame. When the memory cell is deleted or
15927106570Sdan ** overwritten, the VdbeFrame object is not freed immediately. Instead, it
16027106570Sdan ** is linked into the Vdbe.pDelFrame list. The contents of the Vdbe.pDelFrame
16127106570Sdan ** list is deleted when the VM is reset in VdbeHalt(). The reason for doing
16227106570Sdan ** this instead of deleting the VdbeFrame immediately is to avoid recursive
16327106570Sdan ** calls to sqlite3VdbeMemRelease() when the memory cells belonging to the
16427106570Sdan ** child frame are released.
16527106570Sdan **
16627106570Sdan ** The currently executing frame is stored in Vdbe.pFrame. Vdbe.pFrame is
16727106570Sdan ** set to NULL if the currently executing frame is the main program.
16865a7cd16Sdan */
169165921a7Sdan typedef struct VdbeFrame VdbeFrame;
170165921a7Sdan struct VdbeFrame {
171165921a7Sdan   Vdbe *v;                /* VM this frame belongs to */
1723fb757b4Sdrh   VdbeFrame *pParent;     /* Parent of this frame, or NULL if parent is main */
17327106570Sdan   Op *aOp;                /* Program instructions for parent frame */
17443764a8eSdan   i64 *anExec;            /* Event counters from parent frame */
17527106570Sdan   Mem *aMem;              /* Array of memory cells for parent frame */
17627106570Sdan   VdbeCursor **apCsr;     /* Array of Vdbe cursors for parent frame */
177ab087d4eSdrh   u8 *aOnce;              /* Bitmask used by OP_Once */
178165921a7Sdan   void *token;            /* Copy of SubProgram.token */
1793fb757b4Sdrh   i64 lastRowid;          /* Last insert rowid (sqlite3.lastRowid) */
1803200132aSdan   AuxData *pAuxData;      /* Linked list of auxdata allocations */
18172f56ef9Sdrh #if SQLITE_DEBUG
18272f56ef9Sdrh   u32 iFrameMagic;        /* magic number for sanity checking */
18372f56ef9Sdrh #endif
184928d9c62Sdrh   int nCursor;            /* Number of entries in apCsr */
1853fb757b4Sdrh   int pc;                 /* Program Counter in parent (calling) frame */
1863fb757b4Sdrh   int nOp;                /* Size of aOp array */
1873fb757b4Sdrh   int nMem;               /* Number of entries in aMem */
188165921a7Sdan   int nChildMem;          /* Number of memory cells for child frame */
189165921a7Sdan   int nChildCsr;          /* Number of cursors for child frame */
1902c718873Sdan   i64 nChange;            /* Statement changes (Vdbe.nChange)     */
1912c718873Sdan   i64 nDbChange;          /* Value of db->nChange */
192165921a7Sdan };
193165921a7Sdan 
19472f56ef9Sdrh /* Magic number for sanity checking on VdbeFrame objects */
19572f56ef9Sdrh #define SQLITE_FRAME_MAGIC 0x879fb71e
19672f56ef9Sdrh 
19772f56ef9Sdrh /*
19872f56ef9Sdrh ** Return a pointer to the array of registers allocated for use
19972f56ef9Sdrh ** by a VdbeFrame.
20072f56ef9Sdrh */
201165921a7Sdan #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
202165921a7Sdan 
2039a32464bSdrh /*
2047e18c259Sdanielk1977 ** Internally, the vdbe manipulates nearly all SQL values as Mem
2057e18c259Sdanielk1977 ** structures. Each Mem struct may cache multiple representations (string,
2062e5de2f2Sdrh ** integer etc.) of the same value.
2079a32464bSdrh */
2087a6ea93fSdrh struct sqlite3_value {
20974eaba4dSdrh   union MemValue {
21074eaba4dSdrh     double r;           /* Real value used when MEM_Real is set in flags */
2112e5de2f2Sdrh     i64 i;              /* Integer value used when MEM_Int is set in flags */
21222930062Sdrh     int nZero;          /* Extra zero bytes when MEM_Zero and MEM_Blob set */
213a0024e6cSdrh     const char *zPType; /* Pointer type when MEM_Term|MEM_Subtype|MEM_Null */
2143c024d69Sdrh     FuncDef *pDef;      /* Used only when flags==MEM_Agg */
2153c024d69Sdrh   } u;
216c9373e86Sdrh   char *z;            /* String or BLOB value */
217c9373e86Sdrh   int n;              /* Number of characters in string value, excluding '\0' */
21869174eb4Sdrh   u16 flags;          /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
219fdf972a9Sdrh   u8  enc;            /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
220bcdf78a6Sdrh   u8  eSubtype;       /* Subtype for this value */
221035e563bSdrh   /* ShallowCopy only needs to copy the information above */
222c9373e86Sdrh   sqlite3 *db;        /* The associated database connection */
22317bcb102Sdrh   int szMalloc;       /* Size of the zMalloc allocation */
224facf47a8Sdrh   u32 uTemp;          /* Transient storage for serial_type in OP_MakeRecord */
225c9373e86Sdrh   char *zMalloc;      /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
226d3b74200Sdrh   void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */
2272b4ded99Sdrh #ifdef SQLITE_DEBUG
2282b4ded99Sdrh   Mem *pScopyFrom;    /* This Mem is a shallow copy of pScopyFrom */
22958773a53Sdrh   u16 mScopyFlags;    /* flags value immediately after the shallow copy */
2302b4ded99Sdrh #endif
2319a32464bSdrh };
2329a32464bSdrh 
2334f03f413Sdrh /*
2344f03f413Sdrh ** Size of struct Mem not including the Mem.zMalloc member or anything that
2354f03f413Sdrh ** follows.
2364f03f413Sdrh */
237c9373e86Sdrh #define MEMCELLSIZE offsetof(Mem,db)
2384f03f413Sdrh 
23974a12dd6Sdrh /* One or more of the following flags are set to indicate the
240b77f5dadSdanielk1977 ** representations of the value stored in the Mem struct.
2413dc0b8ebSdrh **
24274a12dd6Sdrh **  *  MEM_Null                An SQL NULL value
24374a12dd6Sdrh **
24474a12dd6Sdrh **  *  MEM_Null|MEM_Zero       An SQL NULL with the virtual table
24574a12dd6Sdrh **                             UPDATE no-change flag set
24674a12dd6Sdrh **
24774a12dd6Sdrh **  *  MEM_Null|MEM_Term|      An SQL NULL, but also contains a
24874a12dd6Sdrh **        MEM_Subtype          pointer accessible using
24974a12dd6Sdrh **                             sqlite3_value_pointer().
25074a12dd6Sdrh **
25174a12dd6Sdrh **  *  MEM_Null|MEM_Cleared    Special SQL NULL that compares non-equal
25274a12dd6Sdrh **                             to other NULLs even using the IS operator.
25374a12dd6Sdrh **
25474a12dd6Sdrh **  *  MEM_Str                 A string, stored in Mem.z with
25574a12dd6Sdrh **                             length Mem.n.  Zero-terminated if
25674a12dd6Sdrh **                             MEM_Term is set.  This flag is
25774a12dd6Sdrh **                             incompatible with MEM_Blob and
25874a12dd6Sdrh **                             MEM_Null, but can appear with MEM_Int,
25974a12dd6Sdrh **                             MEM_Real, and MEM_IntReal.
26074a12dd6Sdrh **
26174a12dd6Sdrh **  *  MEM_Blob                A blob, stored in Mem.z length Mem.n.
26274a12dd6Sdrh **                             Incompatible with MEM_Str, MEM_Null,
26374a12dd6Sdrh **                             MEM_Int, MEM_Real, and MEM_IntReal.
26474a12dd6Sdrh **
26574a12dd6Sdrh **  *  MEM_Blob|MEM_Zero       A blob in Mem.z of length Mem.n plus
26674a12dd6Sdrh **                             MEM.u.i extra 0x00 bytes at the end.
26774a12dd6Sdrh **
26874a12dd6Sdrh **  *  MEM_Int                 Integer stored in Mem.u.i.
26974a12dd6Sdrh **
27074a12dd6Sdrh **  *  MEM_Real                Real stored in Mem.u.r.
27174a12dd6Sdrh **
27274a12dd6Sdrh **  *  MEM_IntReal             Real stored as an integer in Mem.u.i.
27374a12dd6Sdrh **
274b77f5dadSdanielk1977 ** If the MEM_Null flag is set, then the value is an SQL NULL value.
275a0024e6cSdrh ** For a pointer type created using sqlite3_bind_pointer() or
276a0024e6cSdrh ** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set.
2773dc0b8ebSdrh **
278b77f5dadSdanielk1977 ** If the MEM_Str flag is set then Mem.z points at a string representation.
279b77f5dadSdanielk1977 ** Usually this is encoded in the same unicode encoding as the main
280b77f5dadSdanielk1977 ** database (see below for exceptions). If the MEM_Term flag is also
281b77f5dadSdanielk1977 ** set, then the string is nul terminated. The MEM_Int and MEM_Real
282b77f5dadSdanielk1977 ** flags may coexist with the MEM_Str flag.
2839a32464bSdrh */
2848552b10cSdrh #define MEM_Undefined 0x0000   /* Value is undefined */
285a0024e6cSdrh #define MEM_Null      0x0001   /* Value is NULL (or a pointer) */
28600706be3Sdrh #define MEM_Str       0x0002   /* Value is a string */
28700706be3Sdrh #define MEM_Int       0x0004   /* Value is an integer */
28800706be3Sdrh #define MEM_Real      0x0008   /* Value is a real number */
2893dc0b8ebSdrh #define MEM_Blob      0x0010   /* Value is a BLOB */
290de7109e6Sdrh #define MEM_IntReal   0x0020   /* MEM_Int that stringifies like MEM_Real */
291de7109e6Sdrh #define MEM_AffMask   0x003f   /* Mask of affinity bits */
292053a128fSdrh 
2938552b10cSdrh /* Extra bits that modify the meanings of the core datatypes above
294b77f5dadSdanielk1977 */
2958552b10cSdrh #define MEM_FromBind  0x0040   /* Value originates from sqlite3_bind() */
2968552b10cSdrh  /*                   0x0080   // Available */
2978552b10cSdrh #define MEM_Cleared   0x0100   /* NULL set by OP_Null, not from data */
298a0024e6cSdrh #define MEM_Term      0x0200   /* String in Mem.z is zero terminated */
2998552b10cSdrh #define MEM_Zero      0x0400   /* Mem.i contains count of 0s appended to blob */
3008552b10cSdrh #define MEM_Subtype   0x0800   /* Mem.eSubtype is valid */
3018552b10cSdrh #define MEM_TypeMask  0x0dbf   /* Mask of type bits */
3028552b10cSdrh 
3038552b10cSdrh /* Bits that determine the storage for Mem.z for a string or blob or
3048552b10cSdrh ** aggregate accumulator.
3058552b10cSdrh */
3068552b10cSdrh #define MEM_Dyn       0x1000   /* Need to call Mem.xDel() on Mem.z */
3078552b10cSdrh #define MEM_Static    0x2000   /* Mem.z points to a static string */
3088552b10cSdrh #define MEM_Ephem     0x4000   /* Mem.z points to an ephemeral string */
3098552b10cSdrh #define MEM_Agg       0x8000   /* Mem.z points to an agg function context */
310246ad31dSdanielk1977 
3115b6c8e4eSdan /* Return TRUE if Mem X contains dynamically allocated content - anything
3125b6c8e4eSdan ** that needs to be deallocated to avoid a leak.
3135b6c8e4eSdan */
3145b6c8e4eSdan #define VdbeMemDynamic(X)  \
3159d67afc4Sdrh   (((X)->flags&(MEM_Agg|MEM_Dyn))!=0)
3165b6c8e4eSdan 
3173d4501e5Sdrh /*
3183d4501e5Sdrh ** Clear any existing type flags from a Mem and replace them with f
3193d4501e5Sdrh */
32068ac65ecSdrh #define MemSetTypeFlag(p, f) \
32168ac65ecSdrh    ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)
3223d4501e5Sdrh 
3232b4ded99Sdrh /*
3247d683394Sdrh ** True if Mem X is a NULL-nochng type.
3257d683394Sdrh */
3267d683394Sdrh #define MemNullNochng(X) \
327093589deSdrh   (((X)->flags&MEM_TypeMask)==(MEM_Null|MEM_Zero) \
328093589deSdrh     && (X)->n==0 && (X)->u.nZero==0)
3297d683394Sdrh 
3307d683394Sdrh /*
3318552b10cSdrh ** Return true if a memory cell has been initialized and is valid.
3322b4ded99Sdrh ** is for use inside assert() statements only.
3338552b10cSdrh **
3348552b10cSdrh ** A Memory cell is initialized if at least one of the
3358552b10cSdrh ** MEM_Null, MEM_Str, MEM_Int, MEM_Real, MEM_Blob, or MEM_IntReal bits
3368552b10cSdrh ** is set.  It is "undefined" if all those bits are zero.
3372b4ded99Sdrh */
3382b4ded99Sdrh #ifdef SQLITE_DEBUG
3398552b10cSdrh #define memIsValid(M)  ((M)->flags & MEM_AffMask)!=0
3402b4ded99Sdrh #endif
3412b4ded99Sdrh 
3420c547799Sdan /*
34360ec914cSpeter.d.reid ** Each auxiliary data pointer stored by a user defined function
3440c547799Sdan ** implementation calling sqlite3_set_auxdata() is stored in an instance
3450c547799Sdan ** of this structure. All such structures associated with a single VM
3460c547799Sdan ** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed
3470c547799Sdan ** when the VM is halted (if not before).
348998da3a2Sdrh */
349682f68b0Sdanielk1977 struct AuxData {
350e6941397Sdrh   int iAuxOp;                     /* Instruction number of OP_Function opcode */
351e6941397Sdrh   int iAuxArg;                    /* Index of function argument. */
3520c547799Sdan   void *pAux;                     /* Aux data pointer */
353e6941397Sdrh   void (*xDeleteAux)(void*);      /* Destructor for the aux data */
354e6941397Sdrh   AuxData *pNextAux;              /* Next element in list */
355682f68b0Sdanielk1977 };
356682f68b0Sdanielk1977 
3579a32464bSdrh /*
35860ec914cSpeter.d.reid ** The "context" argument for an installable function.  A pointer to an
3599a32464bSdrh ** instance of this structure is the first argument to the routines used
3609a32464bSdrh ** implement the SQL functions.
3619a32464bSdrh **
3629a32464bSdrh ** There is a typedef for this structure in sqlite.h.  So all routines,
3639a32464bSdrh ** even the public interface to SQLite, can use a pointer to this structure.
3649a32464bSdrh ** But this file is the only place where the internal details of this
3659a32464bSdrh ** structure are known.
3669a32464bSdrh **
367abfcea25Sdrh ** This structure is defined inside of vdbeInt.h because it uses substructures
36800706be3Sdrh ** (Mem) which are only defined there.
3699a32464bSdrh */
3700ae8b831Sdanielk1977 struct sqlite3_context {
3719bd038f1Sdrh   Mem *pOut;              /* The return value is stored here */
37226c79a06Smistachkin   FuncDef *pFunc;         /* Pointer to function information */
373abfcea25Sdrh   Mem *pMem;              /* Memory cell used to store aggregate context */
3740c547799Sdan   Vdbe *pVdbe;            /* The VM that owns this context */
3759b47ee3fSdrh   int iOp;                /* Instruction number of OP_Function */
3769b47ee3fSdrh   int isError;            /* Error code returned by the function. */
377659fdb4dSdrh   u8 enc;                 /* Encoding to use for results */
37826c79a06Smistachkin   u8 skipFlag;            /* Skip accumulator loading if true */
3799c7c913cSdrh   u8 argc;                /* Number of arguments */
3809c7c913cSdrh   sqlite3_value *argv[1]; /* Argument set */
3819a32464bSdrh };
3829a32464bSdrh 
38337f58e99Sdrh /* A bitfield type for use inside of structures.  Always follow with :N where
38437f58e99Sdrh ** N is the number of bits.
38537f58e99Sdrh */
38637f58e99Sdrh typedef unsigned bft;  /* Bit Field Type */
38737f58e99Sdrh 
388893bd375Sdrh /* The ScanStatus object holds a single value for the
389893bd375Sdrh ** sqlite3_stmt_scanstatus() interface.
390893bd375Sdrh */
391037b5324Sdan typedef struct ScanStatus ScanStatus;
392037b5324Sdan struct ScanStatus {
3936f9702edSdan   int addrExplain;                /* OP_Explain for loop */
3946f9702edSdan   int addrLoop;                   /* Address of "loops" counter */
3956f9702edSdan   int addrVisit;                  /* Address of "rows visited" counter */
396c6652b1eSdrh   int iSelectID;                  /* The "Select-ID" for this loop */
397518140edSdrh   LogEst nEst;                    /* Estimated output rows per loop */
3986f9702edSdan   char *zName;                    /* Name of table or index */
3996f9702edSdan };
4006f9702edSdan 
401893bd375Sdrh /* The DblquoteStr object holds the text of a double-quoted
402893bd375Sdrh ** string for a prepared statement.  A linked list of these objects
403893bd375Sdrh ** is constructed during statement parsing and is held on Vdbe.pDblStr.
404893bd375Sdrh ** When computing a normalized SQL statement for an SQL statement, that
405893bd375Sdrh ** list is consulted for each double-quoted identifier to see if the
406893bd375Sdrh ** identifier should really be a string literal.
407893bd375Sdrh */
408893bd375Sdrh typedef struct DblquoteStr DblquoteStr;
409893bd375Sdrh struct DblquoteStr {
410893bd375Sdrh   DblquoteStr *pNextStr;   /* Next string literal in the list */
411893bd375Sdrh   char z[8];               /* Dequoted value for the string */
412893bd375Sdrh };
413893bd375Sdrh 
4147e02e5e6Sdrh /*
4159a32464bSdrh ** An instance of the virtual machine.  This structure contains the complete
4169a32464bSdrh ** state of the virtual machine.
4179a32464bSdrh **
4182e5de2f2Sdrh ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
4199a32464bSdrh ** is really a pointer to an instance of this structure.
4209a32464bSdrh */
4219a32464bSdrh struct Vdbe {
4228bfdf721Sdrh   sqlite3 *db;            /* The database connection that owns this statement */
423*e5928b17Sdrh   Vdbe **ppVPrev,*pVNext; /* Linked list of VDBEs with the same Vdbe.db */
424ab3182f7Sdrh   Parse *pParse;          /* Parsing context used to create this Vdbe */
425ab3182f7Sdrh   ynVar nVar;             /* Number of entries in aVar[] */
426ab3182f7Sdrh   int nMem;               /* Number of memory locations currently allocated */
427ab3182f7Sdrh   int nCursor;            /* Number of slots in apCsr[] */
428ab3182f7Sdrh   u32 cacheCtr;           /* VdbeCursor row cache generation counter */
429ab3182f7Sdrh   int pc;                 /* The program counter */
430ab3182f7Sdrh   int rc;                 /* Value to return */
4312c718873Sdan   i64 nChange;            /* Number of db changes made since last reset */
432893bd375Sdrh   int iStatement;         /* Statement number (or 0 if has no opened stmt) */
433ab3182f7Sdrh   i64 iCurrentTime;       /* Value of julianday('now') for this statement */
434ab3182f7Sdrh   i64 nFkConstraint;      /* Number of imm. FK constraints this VM */
435ab3182f7Sdrh   i64 nStmtDefCons;       /* Number of def. constraints when stmt started */
436ab3182f7Sdrh   i64 nStmtDefImmCons;    /* Number of def. imm constraints when stmt started */
43781f9159bSdrh   Mem *aMem;              /* The memory locations */
43881f9159bSdrh   Mem **apArg;            /* Arguments to currently executing user function */
43981f9159bSdrh   VdbeCursor **apCsr;     /* One element of this array for each open cursor */
44081f9159bSdrh   Mem *aVar;              /* Values for the OP_Variable opcode. */
441ab3182f7Sdrh 
442ab3182f7Sdrh   /* When allocating a new Vdbe object, all of the fields below should be
443ab3182f7Sdrh   ** initialized to zero or NULL */
444ab3182f7Sdrh 
4459a32464bSdrh   Op *aOp;                /* Space to hold the virtual machine's program */
446b6991796Sdrh   int nOp;                /* Number of instructions in the program */
447b6991796Sdrh   int nOpAlloc;           /* Slots allocated for aOp[] */
4483cf86063Sdanielk1977   Mem *aColName;          /* Column names to return */
4498bfdf721Sdrh   Mem *pResultSet;        /* Pointer to an array of results */
4502e5de2f2Sdrh   char *zErrMsg;          /* Error message written here */
4519bf755ccSdrh   VList *pVList;          /* Name of variables */
452ab3182f7Sdrh #ifndef SQLITE_OMIT_TRACE
453ab3182f7Sdrh   i64 startTime;          /* Time when query started - used for profiling */
454ab3182f7Sdrh #endif
455983b5ee7Sdrh #ifdef SQLITE_DEBUG
456983b5ee7Sdrh   int rcApp;              /* errcode set by sqlite3_result_error_code() */
4574031bafaSdrh   u32 nWrite;             /* Number of write operations that have occurred */
458983b5ee7Sdrh #endif
45973d5b8f5Sdrh   u16 nResColumn;         /* Number of columns in one row of the result set */
4602e5de2f2Sdrh   u8 errorAction;         /* Recovery action to do in case of an error */
461ab3182f7Sdrh   u8 minWriteFileFormat;  /* Minimum file format for writable database files */
4622c2f392dSdrh   u8 prepFlags;           /* SQLITE_PREPARE_* flags */
46366181ce2Sdrh   u8 eVdbeState;          /* On of the VDBE_*_STATE values */
464ba968dbfSdrh   bft expired:2;          /* 1: recompile VM immediately  2: when convenient */
46537f58e99Sdrh   bft explain:2;          /* True if EXPLAIN present on SQL command */
46637f58e99Sdrh   bft changeCntOn:1;      /* True to update the change-counter */
46737f58e99Sdrh   bft usesStmtJournal:1;  /* True if uses a statement journal */
4689e92a47bSdrh   bft readOnly:1;         /* True for statements that do not write */
4691713afb0Sdrh   bft bIsReader:1;        /* True for statements that read */
47064123585Sdrh   yDbMask btreeMask;      /* Bitmask of db->aDb[] entries referenced */
471dc5b047eSdrh   yDbMask lockMask;       /* Subset of btreeMask that requires a lock */
47223d41e63Sdrh   u32 aCounter[9];        /* Counters used by sqlite3_stmt_status() */
4732e5de2f2Sdrh   char *zSql;             /* Text of the SQL statement that generated this */
4748bee11a4Smistachkin #ifdef SQLITE_ENABLE_NORMALIZE
4758bee11a4Smistachkin   char *zNormSql;         /* Normalization of the associated SQL statement */
476893bd375Sdrh   DblquoteStr *pDblStr;   /* List of double-quoted string literals */
4778bee11a4Smistachkin #endif
4782e5de2f2Sdrh   void *pFree;            /* Free this when deleting the vdbe */
479165921a7Sdan   VdbeFrame *pFrame;      /* Parent frame */
48027106570Sdan   VdbeFrame *pDelFrame;   /* List of frame objects to free on VM reset */
481165921a7Sdan   int nFrame;             /* Number of frames in pFrame list */
482937d0deaSdan   u32 expmask;            /* Binding to these vars invalidates VM */
483d19c933eSdan   SubProgram *pProgram;   /* Linked list of all sub-programs used by VM */
4840c547799Sdan   AuxData *pAuxData;      /* Linked list of auxdata allocations */
4856f9702edSdan #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
4866f9702edSdan   i64 *anExec;            /* Number of times each op has been executed */
4876f9702edSdan   int nScan;              /* Entries in aScan[] */
488037b5324Sdan   ScanStatus *aScan;      /* Scan definitions for sqlite3_stmt_scanstatus() */
4896f9702edSdan #endif
4909a32464bSdrh };
4919a32464bSdrh 
4929a32464bSdrh /*
49366181ce2Sdrh ** The following are allowed values for Vdbe.eVdbeState
4949a32464bSdrh */
49566181ce2Sdrh #define VDBE_INIT_STATE     0   /* Prepared statement under construction */
49666181ce2Sdrh #define VDBE_READY_STATE    1   /* Ready to run but not yet started */
49766181ce2Sdrh #define VDBE_RUN_STATE      2   /* Run in progress */
49866181ce2Sdrh #define VDBE_HALT_STATE     3   /* Finished.  Need reset() or finalize() */
4999a32464bSdrh 
5009a32464bSdrh /*
50146c47d46Sdan ** Structure used to store the context required by the
50246c47d46Sdan ** sqlite3_preupdate_*() API functions.
50346c47d46Sdan */
50446c47d46Sdan struct PreUpdate {
50537db03bfSdan   Vdbe *v;
50646c47d46Sdan   VdbeCursor *pCsr;               /* Cursor to read old values from */
50746c47d46Sdan   int op;                         /* One of SQLITE_INSERT, UPDATE, DELETE */
50846c47d46Sdan   u8 *aRecord;                    /* old.* database record */
5094fccf43aSdan   KeyInfo keyinfo;
51046c47d46Sdan   UnpackedRecord *pUnpacked;      /* Unpacked version of aRecord[] */
51137db03bfSdan   UnpackedRecord *pNewUnpacked;   /* Unpacked version of new.* record */
51237db03bfSdan   int iNewReg;                    /* Register for new.* values */
513a23a873fSdan   int iBlobWrite;                 /* Value returned by preupdate_blobwrite() */
514319eeb7bSdan   i64 iKey1;                      /* First key value passed to hook */
515319eeb7bSdan   i64 iKey2;                      /* Second key value passed to hook */
51637db03bfSdan   Mem *aNew;                      /* Array of new.* values */
517e43635aaSdan   Table *pTab;                    /* Schema object being upated */
518cb9a3643Sdan   Index *pPk;                     /* PK index if pTab is WITHOUT ROWID */
51946c47d46Sdan };
52046c47d46Sdan 
52146c47d46Sdan /*
52230e314e4Sdrh ** An instance of this object is used to pass an vector of values into
52330e314e4Sdrh ** OP_VFilter, the xFilter method of a virtual table.  The vector is the
52430e314e4Sdrh ** set of values on the right-hand side of an IN constraint.
52530e314e4Sdrh **
52630e314e4Sdrh ** The value as passed into xFilter is an sqlite3_value with a "pointer"
52730e314e4Sdrh ** type, such as is generated by sqlite3_result_pointer() and read by
52830e314e4Sdrh ** sqlite3_value_pointer.  Such values have MEM_Term|MEM_Subtype|MEM_Null
52930e314e4Sdrh ** and a subtype of 'p'.  The sqlite3_vtab_in_first() and _next() interfaces
53030e314e4Sdrh ** know how to use this object to step through all the values in the
53130e314e4Sdrh ** right operand of the IN constraint.
53230e314e4Sdrh */
53330e314e4Sdrh typedef struct ValueList ValueList;
53430e314e4Sdrh struct ValueList {
53530e314e4Sdrh   BtCursor *pCsr;          /* An ephemeral table holding all values */
53630e314e4Sdrh   sqlite3_value *pOut;     /* Register to hold each decoded output value */
53730e314e4Sdrh };
53830e314e4Sdrh 
5391f416db2Sdrh /* Size of content associated with serial types that fit into a
5401f416db2Sdrh ** single-byte varint.
5411f416db2Sdrh */
5421f416db2Sdrh #ifndef SQLITE_AMALGAMATION
5431f416db2Sdrh extern const u8 sqlite3SmallTypeSizes[];
5441f416db2Sdrh #endif
545d859dc2bSdrh 
54630e314e4Sdrh /*
5479a32464bSdrh ** Function prototypes
5489a32464bSdrh */
54922c17b8bSdrh void sqlite3VdbeError(Vdbe*, const char *, ...);
550dfe88eceSdrh void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
551473571b0Sdrh void sqlite3VdbeFreeCursorNN(Vdbe*,VdbeCursor*);
5529a32464bSdrh void sqliteVdbePopStack(Vdbe*,int);
553fc569503Sdrh int SQLITE_NOINLINE sqlite3VdbeHandleMovedCursor(VdbeCursor *p);
554be3da241Sdrh int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*);
555c22284f4Sdrh int sqlite3VdbeCursorRestore(VdbeCursor*);
55635cd643cSdrh u32 sqlite3VdbeSerialTypeLen(u32);
557faf37279Sdrh u8 sqlite3VdbeOneByteSerialTypeLen(u8);
558d859dc2bSdrh #ifdef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
559d859dc2bSdrh   u64 sqlite3FloatSwap(u64 in);
560d859dc2bSdrh # define swapMixedEndianFloat(X)  X = sqlite3FloatSwap(X)
561d859dc2bSdrh #else
562d859dc2bSdrh # define swapMixedEndianFloat(X)
563d859dc2bSdrh #endif
56406164b23Sdrh void sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
565b9626cfaSdrh void sqlite3VdbeDeleteAuxData(sqlite3*, AuxData**, int, int);
5664adee20fSdanielk1977 
567189621d8Sdanielk1977 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
568d3b74200Sdrh int sqlite3VdbeIdxKeyCompare(sqlite3*,VdbeCursor*,UnpackedRecord*,int*);
56935f6b936Sdrh int sqlite3VdbeIdxRowid(sqlite3*, BtCursor*, i64*);
570106bb236Sdanielk1977 int sqlite3VdbeExec(Vdbe*);
5718c5163a6Sdrh #if !defined(SQLITE_OMIT_EXPLAIN) || defined(SQLITE_ENABLE_BYTECODE_VTAB)
572356cd76aSdrh int sqlite3VdbeNextOpcode(Vdbe*,Mem*,int,int*,int*,Op**);
5738c5163a6Sdrh char *sqlite3VdbeDisplayP4(sqlite3*,Op*);
574e0ef4e2bSdrh #endif
575c004bd54Sdrh #if defined(SQLITE_ENABLE_EXPLAIN_COMMENTS)
5768c5163a6Sdrh char *sqlite3VdbeDisplayComment(sqlite3*,const Op*,const char*);
5778c5163a6Sdrh #endif
5788c5163a6Sdrh #if !defined(SQLITE_OMIT_EXPLAIN)
579106bb236Sdanielk1977 int sqlite3VdbeList(Vdbe*);
58092cd307cSdrh #endif
58192f02c31Sdrh int sqlite3VdbeHalt(Vdbe*);
582b21c8cd4Sdrh int sqlite3VdbeChangeEncoding(Mem *, int);
583023ae03aSdrh int sqlite3VdbeMemTooBig(Mem*);
584b21c8cd4Sdrh int sqlite3VdbeMemCopy(Mem*, const Mem*);
585febe1060Sdrh void sqlite3VdbeMemShallowCopy(Mem*, const Mem*, int);
586643167ffSdrh void sqlite3VdbeMemMove(Mem*, Mem*);
587b21c8cd4Sdrh int sqlite3VdbeMemNulTerminate(Mem*);
588d622855eSdrh int sqlite3VdbeMemSetStr(Mem*, const char*, i64, u8, void(*)(void*));
589efad9995Sdrh void sqlite3VdbeMemSetInt64(Mem*, i64);
5907ec5ea94Sdrh #ifdef SQLITE_OMIT_FLOATING_POINT
5917ec5ea94Sdrh # define sqlite3VdbeMemSetDouble sqlite3VdbeMemSetInt64
5927ec5ea94Sdrh #else
593f4479501Sdrh   void sqlite3VdbeMemSetDouble(Mem*, double);
5947ec5ea94Sdrh #endif
59522930062Sdrh void sqlite3VdbeMemSetPointer(Mem*, void*, const char*, void(*)(void*));
596d3b74200Sdrh void sqlite3VdbeMemInit(Mem*,sqlite3*,u16);
597f4479501Sdrh void sqlite3VdbeMemSetNull(Mem*);
598a32536b4Sdan #ifndef SQLITE_OMIT_INCRBLOB
599b026e05eSdrh void sqlite3VdbeMemSetZeroBlob(Mem*,int);
600a32536b4Sdan #else
601a32536b4Sdan int sqlite3VdbeMemSetZeroBlob(Mem*,int);
602a32536b4Sdan #endif
6039d67afc4Sdrh #ifdef SQLITE_DEBUG
6049d67afc4Sdrh int sqlite3VdbeMemIsRowSet(const Mem*);
6059d67afc4Sdrh #endif
6069d67afc4Sdrh int sqlite3VdbeMemSetRowSet(Mem*);
607b21c8cd4Sdrh int sqlite3VdbeMemMakeWriteable(Mem*);
608bd9507c8Sdrh int sqlite3VdbeMemStringify(Mem*, u8, u8);
609de324617Sdrh int sqlite3IntFloatCompare(i64,double);
6102db144c3Sdrh i64 sqlite3VdbeIntValue(const Mem*);
611eb2e176aSdrh int sqlite3VdbeMemIntegerify(Mem*);
6126a6124e2Sdrh double sqlite3VdbeRealValue(Mem*);
6131fcfa724Sdrh int sqlite3VdbeBooleanValue(Mem*, int ifNull);
6148df447f0Sdrh void sqlite3VdbeIntegerAffinity(Mem*);
615eb2e176aSdrh int sqlite3VdbeMemRealify(Mem*);
6168a51256cSdrh int sqlite3VdbeMemNumerify(Mem*);
6170af6ddd3Sdrh int sqlite3VdbeMemCast(Mem*,u8,u8);
618cb3cabd0Sdrh int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*);
6192a740060Sdrh int sqlite3VdbeMemFromBtreeZeroOffset(BtCursor*,u32,Mem*);
620d8123366Sdanielk1977 void sqlite3VdbeMemRelease(Mem *p);
621fc854505Sdrh void sqlite3VdbeMemReleaseMalloc(Mem*p);
62290669c1dSdrh int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
62367a9b8edSdan #ifndef SQLITE_OMIT_WINDOWFUNC
62486fb6e17Sdan int sqlite3VdbeMemAggValue(Mem*, Mem*, FuncDef*);
62567a9b8edSdan #endif
6268c5163a6Sdrh #if !defined(SQLITE_OMIT_EXPLAIN) || defined(SQLITE_ENABLE_BYTECODE_VTAB)
62746c99e0fSdrh const char *sqlite3OpcodeName(int);
62892cd307cSdrh #endif
629a7a8e14bSdanielk1977 int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
630322f2852Sdrh int sqlite3VdbeMemClearAndResize(Mem *pMem, int n);
631bd43455cSdanielk1977 int sqlite3VdbeCloseStatement(Vdbe *, int);
63272f56ef9Sdrh #ifdef SQLITE_DEBUG
63372f56ef9Sdrh int sqlite3VdbeFrameIsValid(VdbeFrame*);
63472f56ef9Sdrh #endif
63572f56ef9Sdrh void sqlite3VdbeFrameMemDel(void*);      /* Destructor on Mem */
63672f56ef9Sdrh void sqlite3VdbeFrameDelete(VdbeFrame*); /* Actually deletes the Frame */
637165921a7Sdan int sqlite3VdbeFrameRestore(VdbeFrame *);
63874c3302fSdrh #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
639a23a873fSdan void sqlite3VdbePreUpdateHook(
640a23a873fSdan     Vdbe*,VdbeCursor*,int,const char*,Table*,i64,int,int);
64174c3302fSdrh #endif
642029ead64Sdan int sqlite3VdbeTransferError(Vdbe *p);
643e54e0518Sdrh 
644fad9f9a8Sdan int sqlite3VdbeSorterInit(sqlite3 *, int, VdbeCursor *);
64565ea12cbSdrh void sqlite3VdbeSorterReset(sqlite3 *, VdbeSorter *);
646a20fde64Sdan void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);
647c041c16cSdrh int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *);
6482ab792e4Sdrh int sqlite3VdbeSorterNext(sqlite3 *, const VdbeCursor *);
649958d261bSdrh int sqlite3VdbeSorterRewind(const VdbeCursor *, int *);
650958d261bSdrh int sqlite3VdbeSorterWrite(const VdbeCursor *, Mem *);
6511153c7b2Sdrh int sqlite3VdbeSorterCompare(const VdbeCursor *, Mem *, int, int *);
6527fe6270bSdan 
6534031bafaSdrh #ifdef SQLITE_DEBUG
6544031bafaSdrh   void sqlite3VdbeIncrWriteCounter(Vdbe*, VdbeCursor*);
6554031bafaSdrh   void sqlite3VdbeAssertAbortable(Vdbe*);
6564031bafaSdrh #else
6574031bafaSdrh # define sqlite3VdbeIncrWriteCounter(V,C)
6584031bafaSdrh # define sqlite3VdbeAssertAbortable(V)
6594031bafaSdrh #endif
6604031bafaSdrh 
66120d876faSdan #if !defined(SQLITE_OMIT_SHARED_CACHE)
662bdaec52cSdrh   void sqlite3VdbeEnter(Vdbe*);
663e54e0518Sdrh #else
664e54e0518Sdrh # define sqlite3VdbeEnter(X)
66520d876faSdan #endif
66620d876faSdan 
66720d876faSdan #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
66820d876faSdan   void sqlite3VdbeLeave(Vdbe*);
66920d876faSdan #else
670e54e0518Sdrh # define sqlite3VdbeLeave(X)
671e54e0518Sdrh #endif
67246c99e0fSdrh 
6732b4ded99Sdrh #ifdef SQLITE_DEBUG
674e4c88c0cSdrh void sqlite3VdbeMemAboutToChange(Vdbe*,Mem*);
67575fd0542Sdrh int sqlite3VdbeCheckMemInvariants(Mem*);
6762b4ded99Sdrh #endif
6772b4ded99Sdrh 
6781da40a38Sdan #ifndef SQLITE_OMIT_FOREIGN_KEY
6798a2fff7aSdan int sqlite3VdbeCheckFk(Vdbe *, int);
6801da40a38Sdan #else
6818a2fff7aSdan # define sqlite3VdbeCheckFk(p,i) 0
6821da40a38Sdan #endif
6831da40a38Sdan 
68487cc3b31Sdrh #ifdef SQLITE_DEBUG
68587cc3b31Sdrh   void sqlite3VdbePrintSql(Vdbe*);
6865ca06329Sdrh   void sqlite3VdbeMemPrettyPrint(Mem *pMem, StrAccum *pStr);
68787cc3b31Sdrh #endif
688f0f44b79Sdrh #ifndef SQLITE_OMIT_UTF16
689f0f44b79Sdrh   int sqlite3VdbeMemTranslate(Mem*, u8);
690b21c8cd4Sdrh   int sqlite3VdbeMemHandleBom(Mem *pMem);
691f0f44b79Sdrh #endif
6924e78be69Sdrh 
693246ad31dSdanielk1977 #ifndef SQLITE_OMIT_INCRBLOB
694b21c8cd4Sdrh   int sqlite3VdbeMemExpandBlob(Mem *);
69545d29309Sdrh   #define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
696246ad31dSdanielk1977 #else
697b21c8cd4Sdrh   #define sqlite3VdbeMemExpandBlob(x) SQLITE_OK
69845d29309Sdrh   #define ExpandBlob(P) SQLITE_OK
699246ad31dSdanielk1977 #endif
700246ad31dSdanielk1977 
70143f58d6aSdrh #endif /* !defined(SQLITE_VDBEINT_H) */
702