xref: /sqlite-3.40.0/src/vdbeInt.h (revision 8ccdef6b)
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 _VDBEINT_H_
19 #define _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 # define VDBE_DISPLAY_P4 1
36 #else
37 # define VDBE_DISPLAY_P4 0
38 #endif
39 
40 /*
41 ** SQL is translated into a sequence of instructions to be
42 ** executed by a virtual machine.  Each instruction is an instance
43 ** of the following structure.
44 */
45 typedef struct VdbeOp Op;
46 
47 /*
48 ** Boolean values
49 */
50 typedef unsigned Bool;
51 
52 /* Opaque type used by code in vdbesort.c */
53 typedef struct VdbeSorter VdbeSorter;
54 
55 /* Opaque type used by the explainer */
56 typedef struct Explain Explain;
57 
58 /* Elements of the linked list at Vdbe.pAuxData */
59 typedef struct AuxData AuxData;
60 
61 /* Types of VDBE cursors */
62 #define CURTYPE_BTREE       0
63 #define CURTYPE_SORTER      1
64 #define CURTYPE_VTAB        2
65 #define CURTYPE_PSEUDO      3
66 
67 /*
68 ** A VdbeCursor is an superclass (a wrapper) for various cursor objects:
69 **
70 **      * A b-tree cursor
71 **          -  In the main database or in an ephemeral database
72 **          -  On either an index or a table
73 **      * A sorter
74 **      * A virtual table
75 **      * A one-row "pseudotable" stored in a single register
76 */
77 struct VdbeCursor {
78   u8 eCurType;          /* One of the CURTYPE_* values above */
79   i8 iDb;               /* Index of cursor database in db->aDb[] (or -1) */
80   u8 nullRow;           /* True if pointing to a row with no data */
81   u8 deferredMoveto;    /* A call to sqlite3BtreeMoveto() is needed */
82   u8 isTable;           /* True for rowid tables.  False for indexes */
83 #ifdef SQLITE_DEBUG
84   u8 seekOp;            /* Most recent seek operation on this cursor */
85 #endif
86   Bool isEphemeral:1;   /* True for an ephemeral table */
87   Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
88   Bool isOrdered:1;     /* True if the underlying table is BTREE_UNORDERED */
89   Pgno pgnoRoot;        /* Root page of the open btree cursor */
90   i16 nField;           /* Number of fields in the header */
91   u16 nHdrParsed;       /* Number of header fields parsed so far */
92   union {
93     BtCursor *pCursor;          /* CURTYPE_BTREE.  Btree cursor */
94     sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB.   Vtab cursor */
95     int pseudoTableReg;         /* CURTYPE_PSEUDO. Reg holding content. */
96     VdbeSorter *pSorter;        /* CURTYPE_SORTER. Sorter object */
97   } uc;
98   Btree *pBt;           /* Separate file holding temporary table */
99   KeyInfo *pKeyInfo;    /* Info about index keys needed by index cursors */
100   int seekResult;       /* Result of previous sqlite3BtreeMoveto() */
101   i64 seqCount;         /* Sequence counter */
102   i64 movetoTarget;     /* Argument to the deferred sqlite3BtreeMoveto() */
103 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
104   u64 maskUsed;         /* Mask of columns used by this cursor */
105 #endif
106 
107   /* Cached information about the header for the data record that the
108   ** cursor is currently pointing to.  Only valid if cacheStatus matches
109   ** Vdbe.cacheCtr.  Vdbe.cacheCtr will never take on the value of
110   ** CACHE_STALE and so setting cacheStatus=CACHE_STALE guarantees that
111   ** the cache is out of date.
112   **
113   ** aRow might point to (ephemeral) data for the current row, or it might
114   ** be NULL.
115   */
116   u32 cacheStatus;      /* Cache is valid if this matches Vdbe.cacheCtr */
117   u32 payloadSize;      /* Total number of bytes in the record */
118   u32 szRow;            /* Byte available in aRow */
119   u32 iHdrOffset;       /* Offset to next unparsed byte of the header */
120   const u8 *aRow;       /* Data for the current row, if all on one page */
121   u32 *aOffset;         /* Pointer to aType[nField] */
122   u32 aType[1];         /* Type values for all entries in the record */
123   /* 2*nField extra array elements allocated for aType[], beyond the one
124   ** static element declared in the structure.  nField total array slots for
125   ** aType[] and nField+1 array slots for aOffset[] */
126 };
127 typedef struct VdbeCursor VdbeCursor;
128 
129 /*
130 ** When a sub-program is executed (OP_Program), a structure of this type
131 ** is allocated to store the current value of the program counter, as
132 ** well as the current memory cell array and various other frame specific
133 ** values stored in the Vdbe struct. When the sub-program is finished,
134 ** these values are copied back to the Vdbe from the VdbeFrame structure,
135 ** restoring the state of the VM to as it was before the sub-program
136 ** began executing.
137 **
138 ** The memory for a VdbeFrame object is allocated and managed by a memory
139 ** cell in the parent (calling) frame. When the memory cell is deleted or
140 ** overwritten, the VdbeFrame object is not freed immediately. Instead, it
141 ** is linked into the Vdbe.pDelFrame list. The contents of the Vdbe.pDelFrame
142 ** list is deleted when the VM is reset in VdbeHalt(). The reason for doing
143 ** this instead of deleting the VdbeFrame immediately is to avoid recursive
144 ** calls to sqlite3VdbeMemRelease() when the memory cells belonging to the
145 ** child frame are released.
146 **
147 ** The currently executing frame is stored in Vdbe.pFrame. Vdbe.pFrame is
148 ** set to NULL if the currently executing frame is the main program.
149 */
150 typedef struct VdbeFrame VdbeFrame;
151 struct VdbeFrame {
152   Vdbe *v;                /* VM this frame belongs to */
153   VdbeFrame *pParent;     /* Parent of this frame, or NULL if parent is main */
154   Op *aOp;                /* Program instructions for parent frame */
155   i64 *anExec;            /* Event counters from parent frame */
156   Mem *aMem;              /* Array of memory cells for parent frame */
157   u8 *aOnceFlag;          /* Array of OP_Once flags for parent frame */
158   VdbeCursor **apCsr;     /* Array of Vdbe cursors for parent frame */
159   void *token;            /* Copy of SubProgram.token */
160   i64 lastRowid;          /* Last insert rowid (sqlite3.lastRowid) */
161   int nCursor;            /* Number of entries in apCsr */
162   int pc;                 /* Program Counter in parent (calling) frame */
163   int nOp;                /* Size of aOp array */
164   int nMem;               /* Number of entries in aMem */
165   int nOnceFlag;          /* Number of entries in aOnceFlag */
166   int nChildMem;          /* Number of memory cells for child frame */
167   int nChildCsr;          /* Number of cursors for child frame */
168   int nChange;            /* Statement changes (Vdbe.nChange)     */
169   int nDbChange;          /* Value of db->nChange */
170 };
171 
172 #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
173 
174 /*
175 ** A value for VdbeCursor.cacheValid that means the cache is always invalid.
176 */
177 #define CACHE_STALE 0
178 
179 /*
180 ** Internally, the vdbe manipulates nearly all SQL values as Mem
181 ** structures. Each Mem struct may cache multiple representations (string,
182 ** integer etc.) of the same value.
183 */
184 struct Mem {
185   union MemValue {
186     double r;           /* Real value used when MEM_Real is set in flags */
187     i64 i;              /* Integer value used when MEM_Int is set in flags */
188     int nZero;          /* Used when bit MEM_Zero is set in flags */
189     FuncDef *pDef;      /* Used only when flags==MEM_Agg */
190     RowSet *pRowSet;    /* Used only when flags==MEM_RowSet */
191     VdbeFrame *pFrame;  /* Used when flags==MEM_Frame */
192   } u;
193   u16 flags;          /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
194   u8  enc;            /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
195   u8  eSubtype;       /* Subtype for this value */
196   int n;              /* Number of characters in string value, excluding '\0' */
197   char *z;            /* String or BLOB value */
198   /* ShallowCopy only needs to copy the information above */
199   char *zMalloc;      /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
200   int szMalloc;       /* Size of the zMalloc allocation */
201   u32 uTemp;          /* Transient storage for serial_type in OP_MakeRecord */
202   sqlite3 *db;        /* The associated database connection */
203   void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */
204 #ifdef SQLITE_DEBUG
205   Mem *pScopyFrom;    /* This Mem is a shallow copy of pScopyFrom */
206   void *pFiller;      /* So that sizeof(Mem) is a multiple of 8 */
207 #endif
208 };
209 
210 /*
211 ** Size of struct Mem not including the Mem.zMalloc member or anything that
212 ** follows.
213 */
214 #define MEMCELLSIZE offsetof(Mem,zMalloc)
215 
216 /* One or more of the following flags are set to indicate the validOK
217 ** representations of the value stored in the Mem struct.
218 **
219 ** If the MEM_Null flag is set, then the value is an SQL NULL value.
220 ** No other flags may be set in this case.
221 **
222 ** If the MEM_Str flag is set then Mem.z points at a string representation.
223 ** Usually this is encoded in the same unicode encoding as the main
224 ** database (see below for exceptions). If the MEM_Term flag is also
225 ** set, then the string is nul terminated. The MEM_Int and MEM_Real
226 ** flags may coexist with the MEM_Str flag.
227 */
228 #define MEM_Null      0x0001   /* Value is NULL */
229 #define MEM_Str       0x0002   /* Value is a string */
230 #define MEM_Int       0x0004   /* Value is an integer */
231 #define MEM_Real      0x0008   /* Value is a real number */
232 #define MEM_Blob      0x0010   /* Value is a BLOB */
233 #define MEM_AffMask   0x001f   /* Mask of affinity bits */
234 #define MEM_RowSet    0x0020   /* Value is a RowSet object */
235 #define MEM_Frame     0x0040   /* Value is a VdbeFrame object */
236 #define MEM_Undefined 0x0080   /* Value is undefined */
237 #define MEM_Cleared   0x0100   /* NULL set by OP_Null, not from data */
238 #define MEM_TypeMask  0x01ff   /* Mask of type bits */
239 
240 
241 /* Whenever Mem contains a valid string or blob representation, one of
242 ** the following flags must be set to determine the memory management
243 ** policy for Mem.z.  The MEM_Term flag tells us whether or not the
244 ** string is \000 or \u0000 terminated
245 */
246 #define MEM_Term      0x0200   /* String rep is nul terminated */
247 #define MEM_Dyn       0x0400   /* Need to call Mem.xDel() on Mem.z */
248 #define MEM_Static    0x0800   /* Mem.z points to a static string */
249 #define MEM_Ephem     0x1000   /* Mem.z points to an ephemeral string */
250 #define MEM_Agg       0x2000   /* Mem.z points to an agg function context */
251 #define MEM_Zero      0x4000   /* Mem.i contains count of 0s appended to blob */
252 #ifdef SQLITE_OMIT_INCRBLOB
253   #undef MEM_Zero
254   #define MEM_Zero 0x0000
255 #endif
256 
257 /*
258 ** Clear any existing type flags from a Mem and replace them with f
259 */
260 #define MemSetTypeFlag(p, f) \
261    ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)
262 
263 /*
264 ** Return true if a memory cell is not marked as invalid.  This macro
265 ** is for use inside assert() statements only.
266 */
267 #ifdef SQLITE_DEBUG
268 #define memIsValid(M)  ((M)->flags & MEM_Undefined)==0
269 #endif
270 
271 /*
272 ** Each auxiliary data pointer stored by a user defined function
273 ** implementation calling sqlite3_set_auxdata() is stored in an instance
274 ** of this structure. All such structures associated with a single VM
275 ** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed
276 ** when the VM is halted (if not before).
277 */
278 struct AuxData {
279   int iOp;                        /* Instruction number of OP_Function opcode */
280   int iArg;                       /* Index of function argument. */
281   void *pAux;                     /* Aux data pointer */
282   void (*xDelete)(void *);        /* Destructor for the aux data */
283   AuxData *pNext;                 /* Next element in list */
284 };
285 
286 /*
287 ** The "context" argument for an installable function.  A pointer to an
288 ** instance of this structure is the first argument to the routines used
289 ** implement the SQL functions.
290 **
291 ** There is a typedef for this structure in sqlite.h.  So all routines,
292 ** even the public interface to SQLite, can use a pointer to this structure.
293 ** But this file is the only place where the internal details of this
294 ** structure are known.
295 **
296 ** This structure is defined inside of vdbeInt.h because it uses substructures
297 ** (Mem) which are only defined there.
298 */
299 struct sqlite3_context {
300   Mem *pOut;              /* The return value is stored here */
301   FuncDef *pFunc;         /* Pointer to function information */
302   Mem *pMem;              /* Memory cell used to store aggregate context */
303   Vdbe *pVdbe;            /* The VM that owns this context */
304   int iOp;                /* Instruction number of OP_Function */
305   int isError;            /* Error code returned by the function. */
306   u8 skipFlag;            /* Skip accumulator loading if true */
307   u8 fErrorOrAux;         /* isError!=0 or pVdbe->pAuxData modified */
308   u8 argc;                /* Number of arguments */
309   sqlite3_value *argv[1]; /* Argument set */
310 };
311 
312 /*
313 ** An Explain object accumulates indented output which is helpful
314 ** in describing recursive data structures.
315 */
316 struct Explain {
317   Vdbe *pVdbe;       /* Attach the explanation to this Vdbe */
318   StrAccum str;      /* The string being accumulated */
319   int nIndent;       /* Number of elements in aIndent */
320   u16 aIndent[100];  /* Levels of indentation */
321   char zBase[100];   /* Initial space */
322 };
323 
324 /* A bitfield type for use inside of structures.  Always follow with :N where
325 ** N is the number of bits.
326 */
327 typedef unsigned bft;  /* Bit Field Type */
328 
329 typedef struct ScanStatus ScanStatus;
330 struct ScanStatus {
331   int addrExplain;                /* OP_Explain for loop */
332   int addrLoop;                   /* Address of "loops" counter */
333   int addrVisit;                  /* Address of "rows visited" counter */
334   int iSelectID;                  /* The "Select-ID" for this loop */
335   LogEst nEst;                    /* Estimated output rows per loop */
336   char *zName;                    /* Name of table or index */
337 };
338 
339 /*
340 ** An instance of the virtual machine.  This structure contains the complete
341 ** state of the virtual machine.
342 **
343 ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
344 ** is really a pointer to an instance of this structure.
345 */
346 struct Vdbe {
347   sqlite3 *db;            /* The database connection that owns this statement */
348   Op *aOp;                /* Space to hold the virtual machine's program */
349   Mem *aMem;              /* The memory locations */
350   Mem **apArg;            /* Arguments to currently executing user function */
351   Mem *aColName;          /* Column names to return */
352   Mem *pResultSet;        /* Pointer to an array of results */
353   Parse *pParse;          /* Parsing context used to create this Vdbe */
354   int nMem;               /* Number of memory locations currently allocated */
355   int nOp;                /* Number of instructions in the program */
356   int nCursor;            /* Number of slots in apCsr[] */
357   u32 magic;              /* Magic number for sanity checking */
358   char *zErrMsg;          /* Error message written here */
359   Vdbe *pPrev,*pNext;     /* Linked list of VDBEs with the same Vdbe.db */
360   VdbeCursor **apCsr;     /* One element of this array for each open cursor */
361   Mem *aVar;              /* Values for the OP_Variable opcode. */
362   char **azVar;           /* Name of variables */
363   ynVar nVar;             /* Number of entries in aVar[] */
364   ynVar nzVar;            /* Number of entries in azVar[] */
365   u32 cacheCtr;           /* VdbeCursor row cache generation counter */
366   int pc;                 /* The program counter */
367   int rc;                 /* Value to return */
368 #ifdef SQLITE_DEBUG
369   int rcApp;              /* errcode set by sqlite3_result_error_code() */
370 #endif
371   u16 nResColumn;         /* Number of columns in one row of the result set */
372   u8 errorAction;         /* Recovery action to do in case of an error */
373   u8 minWriteFileFormat;  /* Minimum file format for writable database files */
374   bft explain:2;          /* True if EXPLAIN present on SQL command */
375   bft changeCntOn:1;      /* True to update the change-counter */
376   bft expired:1;          /* True if the VM needs to be recompiled */
377   bft runOnlyOnce:1;      /* Automatically expire on reset */
378   bft usesStmtJournal:1;  /* True if uses a statement journal */
379   bft readOnly:1;         /* True for statements that do not write */
380   bft bIsReader:1;        /* True for statements that read */
381   bft isPrepareV2:1;      /* True if prepared with prepare_v2() */
382   bft doingRerun:1;       /* True if rerunning after an auto-reprepare */
383   int nChange;            /* Number of db changes made since last reset */
384   yDbMask btreeMask;      /* Bitmask of db->aDb[] entries referenced */
385   yDbMask lockMask;       /* Subset of btreeMask that requires a lock */
386   int iStatement;         /* Statement number (or 0 if has not opened stmt) */
387   u32 aCounter[5];        /* Counters used by sqlite3_stmt_status() */
388 #ifndef SQLITE_OMIT_TRACE
389   i64 startTime;          /* Time when query started - used for profiling */
390 #endif
391   i64 iCurrentTime;       /* Value of julianday('now') for this statement */
392   i64 nFkConstraint;      /* Number of imm. FK constraints this VM */
393   i64 nStmtDefCons;       /* Number of def. constraints when stmt started */
394   i64 nStmtDefImmCons;    /* Number of def. imm constraints when stmt started */
395   char *zSql;             /* Text of the SQL statement that generated this */
396   void *pFree;            /* Free this when deleting the vdbe */
397   VdbeFrame *pFrame;      /* Parent frame */
398   VdbeFrame *pDelFrame;   /* List of frame objects to free on VM reset */
399   int nFrame;             /* Number of frames in pFrame list */
400   u32 expmask;            /* Binding to these vars invalidates VM */
401   SubProgram *pProgram;   /* Linked list of all sub-programs used by VM */
402   int nOnceFlag;          /* Size of array aOnceFlag[] */
403   u8 *aOnceFlag;          /* Flags for OP_Once */
404   AuxData *pAuxData;      /* Linked list of auxdata allocations */
405 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
406   i64 *anExec;            /* Number of times each op has been executed */
407   int nScan;              /* Entries in aScan[] */
408   ScanStatus *aScan;      /* Scan definitions for sqlite3_stmt_scanstatus() */
409 #endif
410 };
411 
412 /*
413 ** The following are allowed values for Vdbe.magic
414 */
415 #define VDBE_MAGIC_INIT     0x26bceaa5    /* Building a VDBE program */
416 #define VDBE_MAGIC_RUN      0xbdf20da3    /* VDBE is ready to execute */
417 #define VDBE_MAGIC_HALT     0x519c2973    /* VDBE has completed execution */
418 #define VDBE_MAGIC_DEAD     0xb606c3c8    /* The VDBE has been deallocated */
419 
420 /*
421 ** Function prototypes
422 */
423 void sqlite3VdbeError(Vdbe*, const char *, ...);
424 void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
425 void sqliteVdbePopStack(Vdbe*,int);
426 int sqlite3VdbeCursorMoveto(VdbeCursor*);
427 int sqlite3VdbeCursorRestore(VdbeCursor*);
428 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
429 void sqlite3VdbePrintOp(FILE*, int, Op*);
430 #endif
431 u32 sqlite3VdbeSerialTypeLen(u32);
432 u8 sqlite3VdbeOneByteSerialTypeLen(u8);
433 u32 sqlite3VdbeSerialType(Mem*, int, u32*);
434 u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
435 u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
436 void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
437 
438 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
439 int sqlite3VdbeIdxKeyCompare(sqlite3*,VdbeCursor*,UnpackedRecord*,int*);
440 int sqlite3VdbeIdxRowid(sqlite3*, BtCursor*, i64*);
441 int sqlite3VdbeExec(Vdbe*);
442 int sqlite3VdbeList(Vdbe*);
443 int sqlite3VdbeHalt(Vdbe*);
444 int sqlite3VdbeChangeEncoding(Mem *, int);
445 int sqlite3VdbeMemTooBig(Mem*);
446 int sqlite3VdbeMemCopy(Mem*, const Mem*);
447 void sqlite3VdbeMemShallowCopy(Mem*, const Mem*, int);
448 void sqlite3VdbeMemMove(Mem*, Mem*);
449 int sqlite3VdbeMemNulTerminate(Mem*);
450 int sqlite3VdbeMemSetStr(Mem*, const char*, int, u8, void(*)(void*));
451 void sqlite3VdbeMemSetInt64(Mem*, i64);
452 #ifdef SQLITE_OMIT_FLOATING_POINT
453 # define sqlite3VdbeMemSetDouble sqlite3VdbeMemSetInt64
454 #else
455   void sqlite3VdbeMemSetDouble(Mem*, double);
456 #endif
457 void sqlite3VdbeMemInit(Mem*,sqlite3*,u16);
458 void sqlite3VdbeMemSetNull(Mem*);
459 void sqlite3VdbeMemSetZeroBlob(Mem*,int);
460 void sqlite3VdbeMemSetRowSet(Mem*);
461 int sqlite3VdbeMemMakeWriteable(Mem*);
462 int sqlite3VdbeMemStringify(Mem*, u8, u8);
463 i64 sqlite3VdbeIntValue(Mem*);
464 int sqlite3VdbeMemIntegerify(Mem*);
465 double sqlite3VdbeRealValue(Mem*);
466 void sqlite3VdbeIntegerAffinity(Mem*);
467 int sqlite3VdbeMemRealify(Mem*);
468 int sqlite3VdbeMemNumerify(Mem*);
469 void sqlite3VdbeMemCast(Mem*,u8,u8);
470 int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*);
471 void sqlite3VdbeMemRelease(Mem *p);
472 #define VdbeMemDynamic(X)  \
473   (((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame))!=0)
474 int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
475 const char *sqlite3OpcodeName(int);
476 int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
477 int sqlite3VdbeMemClearAndResize(Mem *pMem, int n);
478 int sqlite3VdbeCloseStatement(Vdbe *, int);
479 void sqlite3VdbeFrameDelete(VdbeFrame*);
480 int sqlite3VdbeFrameRestore(VdbeFrame *);
481 int sqlite3VdbeTransferError(Vdbe *p);
482 
483 int sqlite3VdbeSorterInit(sqlite3 *, int, VdbeCursor *);
484 void sqlite3VdbeSorterReset(sqlite3 *, VdbeSorter *);
485 void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);
486 int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *);
487 int sqlite3VdbeSorterNext(sqlite3 *, const VdbeCursor *, int *);
488 int sqlite3VdbeSorterRewind(const VdbeCursor *, int *);
489 int sqlite3VdbeSorterWrite(const VdbeCursor *, Mem *);
490 int sqlite3VdbeSorterCompare(const VdbeCursor *, Mem *, int, int *);
491 
492 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
493   void sqlite3VdbeEnter(Vdbe*);
494   void sqlite3VdbeLeave(Vdbe*);
495 #else
496 # define sqlite3VdbeEnter(X)
497 # define sqlite3VdbeLeave(X)
498 #endif
499 
500 #ifdef SQLITE_DEBUG
501 void sqlite3VdbeMemAboutToChange(Vdbe*,Mem*);
502 int sqlite3VdbeCheckMemInvariants(Mem*);
503 #endif
504 
505 #ifndef SQLITE_OMIT_FOREIGN_KEY
506 int sqlite3VdbeCheckFk(Vdbe *, int);
507 #else
508 # define sqlite3VdbeCheckFk(p,i) 0
509 #endif
510 
511 int sqlite3VdbeMemTranslate(Mem*, u8);
512 #ifdef SQLITE_DEBUG
513   void sqlite3VdbePrintSql(Vdbe*);
514   void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf);
515 #endif
516 int sqlite3VdbeMemHandleBom(Mem *pMem);
517 
518 #ifndef SQLITE_OMIT_INCRBLOB
519   int sqlite3VdbeMemExpandBlob(Mem *);
520   #define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
521 #else
522   #define sqlite3VdbeMemExpandBlob(x) SQLITE_OK
523   #define ExpandBlob(P) SQLITE_OK
524 #endif
525 
526 #endif /* !defined(_VDBEINT_H_) */
527