interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / src / vdbeInt.h

766 lines · 33076 bytes Raw Blame History
1/*
2** 2003 September 6
3**
4** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
6**
7** May you do good and not evil.
8** May you find forgiveness for yourself and forgive others.
9** May you share freely, never taking more than you give.
10**
11*************************************************************************
12** This is the header file for information that is private to the
13** VDBE. This information used to all be at the top of the single
14** source code file "vdbe.c". When that file became too big (over
15** 6000 lines long) it was split up into several smaller files and
16** this header information was factored out.
17*/
18#ifndef SQLITE_VDBEINT_H
19#define SQLITE_VDBEINT_H
20
21/*
22** The maximum number of times that a statement will try to reparse
23** itself before giving up and returning SQLITE_SCHEMA.
24*/
25#ifndef SQLITE_MAX_SCHEMA_RETRY
26# define SQLITE_MAX_SCHEMA_RETRY 50
27#endif
28
29/*
30** VDBE_DISPLAY_P4 is true or false depending on whether or not the
31** "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 1
37#else
38# define VDBE_DISPLAY_P4 0
39#endif
40
41/*
42** SQL is translated into a sequence of instructions to be
43** executed by a virtual machine. Each instruction is an instance
44** of the following structure.
45*/
46typedef struct VdbeOp Op;
47
48/*
49** Boolean values
50*/
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 0
64#define CURTYPE_SORTER 1
65#define CURTYPE_VTAB 2
66#define CURTYPE_PSEUDO 3
67
68/*
69** A VdbeCursor is an superclass (a wrapper) for various cursor objects:
70**
71** * A b-tree cursor
72** - In the main database or in an ephemeral database
73** - On either an index or a table
74** * A sorter
75** * A virtual table
76** * A one-row "pseudotable" stored in a single register
77*/
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_DEBUG
86 u8 seekOp; /* Most recent seek operation on this cursor */
87 u8 wrFlag; /* The wrFlag argument to sqlite3BtreeCursor() */
88#endif
89 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 matches
102 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
103 ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
104 ** 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 0
107 ** if there have been no prior seeks on the cursor. */
108 /* seekResult does not distinguish between "no seeks have ever occurred
109 ** 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 individually
114 ** 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_MASK
132 u64 maskUsed; /* Mask of columns used by this cursor */
133#endif
134 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 N
143** or less. The value of SZ_VDBECURSOR(n) is guaranteed to be a multiple
144** 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 cursor
150*/
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 0
158
159/*
160** Large TEXT or BLOB values can be slow to load, so we want to avoid
161** loading them more than once. For that reason, large TEXT and BLOB values
162** can be stored in a cache defined by this object, and attached to the
163** 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 type
175** is allocated to store the current value of the program counter, as
176** well as the current memory cell array and various other frame specific
177** 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-program
180** began executing.
181**
182** The memory for a VdbeFrame object is allocated and managed by a memory
183** cell in the parent (calling) frame. When the memory cell is deleted or
184** overwritten, the VdbeFrame object is not freed immediately. Instead, it
185** is linked into the Vdbe.pDelFrame list. The contents of the Vdbe.pDelFrame
186** list is deleted when the VM is reset in VdbeHalt(). The reason for doing
187** this instead of deleting the VdbeFrame immediately is to avoid recursive
188** calls to sqlite3VdbeMemRelease() when the memory cells belonging to the
189** child frame are released.
190**
191** The currently executing frame is stored in Vdbe.pFrame. Vdbe.pFrame is
192** 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_DEBUG
206 u32 iFrameMagic; /* magic number for sanity checking */
207#endif
208 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 0x879fb71e
220
221/*
222** Return a pointer to the array of registers allocated for use
223** 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 Mem
229** 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_DEBUG
252 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#endif
256};
257
258/*
259** Size of struct Mem not including the Mem.zMalloc member or anything that
260** follows.
261*/
262#define MEMCELLSIZE offsetof(Mem,db)
263
264/* One or more of the following flags are set to indicate the
265** representations of the value stored in the Mem struct.
266**
267** * MEM_Null An SQL NULL value
268**
269** * MEM_Null|MEM_Zero An SQL NULL with the virtual table
270** UPDATE no-change flag set
271**
272** * MEM_Null|MEM_Term| An SQL NULL, but also contains a
273** MEM_Subtype pointer accessible using
274** sqlite3_value_pointer().
275**
276** * MEM_Null|MEM_Cleared Special SQL NULL that compares non-equal
277** to other NULLs even using the IS operator.
278**
279** * MEM_Str A string, stored in Mem.z with
280** length Mem.n. Zero-terminated if
281** MEM_Term is set. This flag is
282** incompatible with MEM_Blob and
283** 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 plus
291** 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() or
301** 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 main
305** database (see below for exceptions). If the MEM_Term flag is also
306** set, then the string is nul terminated. The MEM_Int and MEM_Real
307** 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 above
319*/
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 or
329** 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 - anything
337** 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 f
344*/
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 the
360** MEM_Null, MEM_Str, MEM_Int, MEM_Real, MEM_Blob, or MEM_IntReal bits
361** is set. It is "undefined" if all those bits are zero.
362*/
363#ifdef SQLITE_DEBUG
364#define memIsValid(M) ((M)->flags & MEM_AffMask)!=0
365#endif
366
367/*
368** Each auxiliary data pointer stored by a user defined function
369** implementation calling sqlite3_set_auxdata() is stored in an instance
370** of this structure. All such structures associated with a single VM
371** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed
372** 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 an
384** instance of this structure is the first argument to the routines used
385** 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 this
390** structure are known.
391**
392** This structure is defined inside of vdbeInt.h because it uses substructures
393** (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 N
410** 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 the
417** sqlite3_stmt_scanstatus() interface.
418**
419** aAddrRange[]:
420** This array is used by ScanStatus elements associated with EQP
421** notes that make an SQLITE_SCANSTAT_NCYCLE value available. It is
422** 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 of
424** integer addresses is a start and end address (both inclusive) for a range
425** 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-quoted
439** string for a prepared statement. A linked list of these objects
440** is constructed during statement parsing and is held on Vdbe.pDblStr.
441** When computing a normalized SQL statement for an SQL statement, that
442** list is consulted for each double-quoted identifier to see if the
443** 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 complete
453** 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 be
480 ** 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_TRACE
490 i64 startTime; /* Time when query started - used for profiling */
491#endif
492#ifdef SQLITE_DEBUG
493 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#endif
497 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_NORMALIZE
515 char *zNormSql; /* Normalization of the associated SQL statement */
516 DblquoteStr *pDblStr; /* List of double-quoted string literals */
517#endif
518 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 might invalidate VM */
523 u32 smimask; /* Only invalid if changing to/from small integer */
524 /* Note: smimask is always a subset of expmask */
525 SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
526 AuxData *pAuxData; /* Linked list of auxdata allocations */
527#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
528 int nScan; /* Entries in aScan[] */
529 ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */
530#endif
531};
532
533/*
534** The following are allowed values for Vdbe.eVdbeState
535*/
536#define VDBE_INIT_STATE 0 /* Prepared statement under construction */
537#define VDBE_READY_STATE 1 /* Ready to run but not yet started */
538#define VDBE_RUN_STATE 2 /* Run in progress */
539#define VDBE_HALT_STATE 3 /* Finished. Need reset() or finalize() */
540
541/*
542** Structure used to store the context required by the
543** sqlite3_preupdate_*() API functions.
544*/
545struct PreUpdate {
546 Vdbe *v;
547 VdbeCursor *pCsr; /* Cursor to read old values from */
548 int op; /* One of SQLITE_INSERT, UPDATE, DELETE */
549 u8 *aRecord; /* old.* database record */
550 KeyInfo *pKeyinfo; /* Key information */
551 UnpackedRecord *pUnpacked; /* Unpacked version of aRecord[] */
552 UnpackedRecord *pNewUnpacked; /* Unpacked version of new.* record */
553 int iNewReg; /* Register for new.* values */
554 int iBlobWrite; /* Value returned by preupdate_blobwrite() */
555 i64 iKey1; /* First key value passed to hook */
556 i64 iKey2; /* Second key value passed to hook */
557 Mem oldipk; /* Memory cell holding "old" IPK value */
558 Mem *aNew; /* Array of new.* values */
559 Table *pTab; /* Schema object being updated */
560 Index *pPk; /* PK index if pTab is WITHOUT ROWID */
561 sqlite3_value **apDflt; /* Array of default values, if required */
562 struct {
563 u8 keyinfoSpace[SZ_KEYINFO_0]; /* Space to hold pKeyinfo[0] content */
564 } uKey;
565};
566
567/*
568** An instance of this object is used to pass an vector of values into
569** OP_VFilter, the xFilter method of a virtual table. The vector is the
570** set of values on the right-hand side of an IN constraint.
571**
572** The value as passed into xFilter is an sqlite3_value with a "pointer"
573** type, such as is generated by sqlite3_result_pointer() and read by
574** sqlite3_value_pointer. Such values have MEM_Term|MEM_Subtype|MEM_Null
575** and a subtype of 'p'. The sqlite3_vtab_in_first() and _next() interfaces
576** know how to use this object to step through all the values in the
577** right operand of the IN constraint.
578*/
579typedef struct ValueList ValueList;
580struct ValueList {
581 BtCursor *pCsr; /* An ephemeral table holding all values */
582 sqlite3_value *pOut; /* Register to hold each decoded output value */
583};
584
585/* Size of content associated with serial types that fit into a
586** single-byte varint.
587*/
588#ifndef SQLITE_AMALGAMATION
589extern const u8 sqlite3SmallTypeSizes[];
590#endif
591
592/* Input "x" is a sequence of unsigned characters that represent a
593** big-endian integer. Return the equivalent native integer
594*/
595#define ONE_BYTE_INT(x) ((i8)(x)[0])
596#define TWO_BYTE_INT(x) (256*(i8)((x)[0])|(x)[1])
597#define THREE_BYTE_INT(x) (65536*(i8)((x)[0])|((x)[1]<<8)|(x)[2])
598#define FOUR_BYTE_UINT(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
599#define FOUR_BYTE_U64(x) (((u64)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3])
600#define FOUR_BYTE_INT(x) ((int)FOUR_BYTE_UINT(x))
601#define SIX_BYTE_INT(x) (FOUR_BYTE_UINT(x+2)+4294967296LL*TWO_BYTE_INT(x))
602
603/*
604** Function prototypes
605*/
606void sqlite3VdbeError(Vdbe*, const char *, ...);
607void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
608void sqlite3VdbeFreeCursorNN(Vdbe*,VdbeCursor*);
609void sqliteVdbePopStack(Vdbe*,int);
610int SQLITE_NOINLINE sqlite3VdbeHandleMovedCursor(VdbeCursor *p);
611int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*);
612int sqlite3VdbeCursorRestore(VdbeCursor*);
613u32 sqlite3VdbeSerialTypeLen(u32);
614u8 sqlite3VdbeOneByteSerialTypeLen(u8);
615#ifdef SQLITE_MIXED_ENDIAN_64BIT_FLOAT
616 u64 sqlite3FloatSwap(u64 in);
617# define swapMixedEndianFloat(X) X = sqlite3FloatSwap(X)
618#else
619# define swapMixedEndianFloat(X)
620#endif
621void sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
622void sqlite3VdbeDeleteAuxData(sqlite3*, AuxData**, int, int);
623
624int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
625int sqlite3VdbeIdxKeyCompare(sqlite3*,VdbeCursor*,UnpackedRecord*,int*);
626int sqlite3VdbeIdxRowid(sqlite3*, BtCursor*, i64*);
627int sqlite3VdbeExec(Vdbe*);
628#if !defined(SQLITE_OMIT_EXPLAIN) || defined(SQLITE_ENABLE_BYTECODE_VTAB)
629int sqlite3VdbeNextOpcode(Vdbe*,Mem*,int,int*,int*,Op**);
630char *sqlite3VdbeDisplayP4(sqlite3*,Op*);
631#endif
632#if defined(SQLITE_ENABLE_EXPLAIN_COMMENTS)
633char *sqlite3VdbeDisplayComment(sqlite3*,const Op*,const char*);
634#endif
635#if !defined(SQLITE_OMIT_EXPLAIN)
636int sqlite3VdbeList(Vdbe*);
637#endif
638int sqlite3VdbeHalt(Vdbe*);
639int sqlite3VdbeChangeEncoding(Mem *, int);
640int sqlite3VdbeMemTooBig(Mem*);
641int sqlite3VdbeMemCopy(Mem*, const Mem*);
642void sqlite3VdbeMemShallowCopy(Mem*, const Mem*, int);
643void sqlite3VdbeMemMove(Mem*, Mem*);
644int sqlite3VdbeMemNulTerminate(Mem*);
645int sqlite3VdbeMemSetStr(Mem*, const char*, i64, u8, void(*)(void*));
646int sqlite3VdbeMemSetText(Mem*, const char*, i64, void(*)(void*));
647void sqlite3VdbeMemSetInt64(Mem*, i64);
648#ifdef SQLITE_OMIT_FLOATING_POINT
649# define sqlite3VdbeMemSetDouble sqlite3VdbeMemSetInt64
650#else
651 void sqlite3VdbeMemSetDouble(Mem*, double);
652#endif
653void sqlite3VdbeMemSetPointer(Mem*, void*, const char*, void(*)(void*));
654void sqlite3VdbeMemInit(Mem*,sqlite3*,u16);
655void sqlite3VdbeMemSetNull(Mem*);
656#ifndef SQLITE_OMIT_INCRBLOB
657void sqlite3VdbeMemSetZeroBlob(Mem*,int);
658#else
659int sqlite3VdbeMemSetZeroBlob(Mem*,int);
660#endif
661#ifdef SQLITE_DEBUG
662int sqlite3VdbeMemIsRowSet(const Mem*);
663#endif
664int sqlite3VdbeMemSetRowSet(Mem*);
665int sqlite3VdbeMemZeroTerminateIfAble(Mem*);
666int sqlite3VdbeMemMakeWriteable(Mem*);
667int sqlite3VdbeMemStringify(Mem*, u8, u8);
668int sqlite3IntFloatCompare(i64,double);
669i64 sqlite3VdbeIntValue(const Mem*);
670int sqlite3VdbeMemIntegerify(Mem*);
671double sqlite3VdbeRealValue(Mem*);
672int sqlite3MemRealValueRC(Mem*, double*);
673int sqlite3VdbeBooleanValue(Mem*, int ifNull);
674void sqlite3VdbeIntegerAffinity(Mem*,int bFromText);
675int sqlite3VdbeMemRealify(Mem*);
676int sqlite3VdbeMemNumerify(Mem*);
677int sqlite3VdbeMemCast(Mem*,u8,u8);
678int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*);
679int sqlite3VdbeMemFromBtreeZeroOffset(BtCursor*,u32,Mem*);
680void sqlite3VdbeMemRelease(Mem *p);
681void sqlite3VdbeMemReleaseMalloc(Mem*p);
682int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
683#ifndef SQLITE_OMIT_WINDOWFUNC
684int sqlite3VdbeMemAggValue(Mem*, Mem*, FuncDef*);
685#endif
686#if !defined(SQLITE_OMIT_EXPLAIN) || defined(SQLITE_ENABLE_BYTECODE_VTAB)
687const char *sqlite3OpcodeName(int);
688#endif
689int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
690int sqlite3VdbeMemClearAndResize(Mem *pMem, int n);
691int sqlite3VdbeCloseStatement(Vdbe *, int);
692#ifdef SQLITE_DEBUG
693int sqlite3VdbeFrameIsValid(VdbeFrame*);
694#endif
695void sqlite3VdbeFrameMemDel(void*); /* Destructor on Mem */
696void sqlite3VdbeFrameDelete(VdbeFrame*); /* Actually deletes the Frame */
697int sqlite3VdbeFrameRestore(VdbeFrame *);
698#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
699void sqlite3VdbePreUpdateHook(
700 Vdbe*,VdbeCursor*,int,const char*,Table*,i64,int,int);
701#endif
702int sqlite3VdbeTransferError(Vdbe *p);
703int sqlite3VdbeFindIndexKey(BtCursor*, Index*, UnpackedRecord*, int*, int);
704
705int sqlite3VdbeSorterInit(sqlite3 *, int, VdbeCursor *);
706void sqlite3VdbeSorterReset(sqlite3 *, VdbeSorter *);
707void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);
708int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *);
709int sqlite3VdbeSorterNext(sqlite3 *, const VdbeCursor *);
710int sqlite3VdbeSorterRewind(const VdbeCursor *, int *);
711int sqlite3VdbeSorterWrite(const VdbeCursor *, Mem *);
712int sqlite3VdbeSorterCompare(const VdbeCursor *, Mem *, int, int *);
713
714void sqlite3VdbeValueListFree(void*);
715
716#ifdef SQLITE_DEBUG
717 void sqlite3VdbeIncrWriteCounter(Vdbe*, VdbeCursor*);
718 void sqlite3VdbeAssertAbortable(Vdbe*);
719#else
720# define sqlite3VdbeIncrWriteCounter(V,C)
721# define sqlite3VdbeAssertAbortable(V)
722#endif
723
724#if !defined(SQLITE_OMIT_SHARED_CACHE)
725 void sqlite3VdbeEnter(Vdbe*);
726#else
727# define sqlite3VdbeEnter(X)
728#endif
729
730#if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
731 void sqlite3VdbeLeave(Vdbe*);
732#else
733# define sqlite3VdbeLeave(X)
734#endif
735
736#ifdef SQLITE_DEBUG
737void sqlite3VdbeMemAboutToChange(Vdbe*,Mem*);
738int sqlite3VdbeCheckMemInvariants(Mem*);
739#endif
740
741#ifndef SQLITE_OMIT_FOREIGN_KEY
742int sqlite3VdbeCheckFkImmediate(Vdbe*);
743int sqlite3VdbeCheckFkDeferred(Vdbe*);
744#else
745# define sqlite3VdbeCheckFkImmediate(p) 0
746# define sqlite3VdbeCheckFkDeferred(p) 0
747#endif
748
749#ifdef SQLITE_DEBUG
750 void sqlite3VdbePrintSql(Vdbe*);
751 void sqlite3VdbeMemPrettyPrint(Mem *pMem, StrAccum *pStr);
752#endif
753#ifndef SQLITE_OMIT_UTF16
754 int sqlite3VdbeMemTranslate(Mem*, u8);
755 int sqlite3VdbeMemHandleBom(Mem *pMem);
756#endif
757
758#ifndef SQLITE_OMIT_INCRBLOB
759 int sqlite3VdbeMemExpandBlob(Mem *);
760 #define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
761#else
762 #define sqlite3VdbeMemExpandBlob(x) SQLITE_OK
763 #define ExpandBlob(P) SQLITE_OK
764#endif
765
766#endif /* !defined(SQLITE_VDBEINT_H) */