xref: /sqlite-3.40.0/src/vdbe.h (revision e995d2c2)
175897234Sdrh /*
2b19a2bc6Sdrh ** 2001 September 15
375897234Sdrh **
4b19a2bc6Sdrh ** The author disclaims copyright to this source code.  In place of
5b19a2bc6Sdrh ** a legal notice, here is a blessing:
675897234Sdrh **
7b19a2bc6Sdrh **    May you do good and not evil.
8b19a2bc6Sdrh **    May you find forgiveness for yourself and forgive others.
9b19a2bc6Sdrh **    May you share freely, never taking more than you give.
1075897234Sdrh **
1175897234Sdrh *************************************************************************
1275897234Sdrh ** Header file for the Virtual DataBase Engine (VDBE)
1375897234Sdrh **
1475897234Sdrh ** This header defines the interface to the virtual database engine
1575897234Sdrh ** or VDBE.  The VDBE implements an abstract machine that runs a
1675897234Sdrh ** simple program to access and modify the underlying database.
1775897234Sdrh */
1843f58d6aSdrh #ifndef SQLITE_VDBE_H
1943f58d6aSdrh #define SQLITE_VDBE_H
2075897234Sdrh #include <stdio.h>
2175897234Sdrh 
2275897234Sdrh /*
2375897234Sdrh ** A single VDBE is an opaque structure named "Vdbe".  Only routines
2475897234Sdrh ** in the source file sqliteVdbe.c are allowed to see the insides
2575897234Sdrh ** of this structure.
2675897234Sdrh */
2775897234Sdrh typedef struct Vdbe Vdbe;
2875897234Sdrh 
2975897234Sdrh /*
302dca4ac1Sdanielk1977 ** The names of the following types declared in vdbeInt.h are required
312dca4ac1Sdanielk1977 ** for the VdbeOp definition.
322dca4ac1Sdanielk1977 */
337a6ea93fSdrh typedef struct sqlite3_value Mem;
34165921a7Sdan typedef struct SubProgram SubProgram;
352dca4ac1Sdanielk1977 
362dca4ac1Sdanielk1977 /*
3775897234Sdrh ** A single instruction of the virtual machine has an opcode
3875897234Sdrh ** and as many as three operands.  The instruction is recorded
3975897234Sdrh ** as an instance of the following structure:
4075897234Sdrh */
4175897234Sdrh struct VdbeOp {
42905793e2Sdrh   u8 opcode;          /* What operation to perform */
43c920628fSdrh   signed char p4type; /* One of the P4_xxx constants for p4 */
44585ce192Sdrh   u16 p5;             /* Fifth parameter is an unsigned 16-bit integer */
4575897234Sdrh   int p1;             /* First operand */
4675897234Sdrh   int p2;             /* Second parameter (often the jump destination) */
4766a5167bSdrh   int p3;             /* The third parameter */
489c7c913cSdrh   union p4union {     /* fourth parameter */
492dca4ac1Sdanielk1977     int i;                 /* Integer value if p4type==P4_INT32 */
502dca4ac1Sdanielk1977     void *p;               /* Generic pointer */
512dca4ac1Sdanielk1977     char *z;               /* Pointer to data for string (char array) types */
522dca4ac1Sdanielk1977     i64 *pI64;             /* Used when p4type is P4_INT64 */
532dca4ac1Sdanielk1977     double *pReal;         /* Used when p4type is P4_REAL */
542dca4ac1Sdanielk1977     FuncDef *pFunc;        /* Used when p4type is P4_FUNCDEF */
559c7c913cSdrh     sqlite3_context *pCtx; /* Used when p4type is P4_FUNCCTX */
562dca4ac1Sdanielk1977     CollSeq *pColl;        /* Used when p4type is P4_COLLSEQ */
572dca4ac1Sdanielk1977     Mem *pMem;             /* Used when p4type is P4_MEM */
58595a523aSdanielk1977     VTable *pVtab;         /* Used when p4type is P4_VTAB */
592dca4ac1Sdanielk1977     KeyInfo *pKeyInfo;     /* Used when p4type is P4_KEYINFO */
60abc38158Sdrh     u32 *ai;               /* Used when p4type is P4_INTARRAY */
61165921a7Sdan     SubProgram *pProgram;  /* Used when p4type is P4_SUBPROGRAM */
62319eeb7bSdan     Table *pTab;           /* Used when p4type is P4_TABLE */
6328935364Sdrh #ifdef SQLITE_ENABLE_CURSOR_HINTS
6428935364Sdrh     Expr *pExpr;           /* Used when p4type is P4_EXPR */
6528935364Sdrh #endif
6666a5167bSdrh   } p4;
67c7379ce4Sdrh #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
68d4e70ebdSdrh   char *zComment;          /* Comment to improve readability */
69d4e70ebdSdrh #endif
707b396867Sdrh #ifdef VDBE_PROFILE
7115ab9418Sdrh   u32 cnt;                 /* Number of times this instruction was executed */
729bcbdad2Sshane   u64 cycles;              /* Total time spent executing this instruction */
737b396867Sdrh #endif
74688852abSdrh #ifdef SQLITE_VDBE_COVERAGE
757083a487Sdrh   u32 iSrcLine;            /* Source-code line that generated this opcode
767083a487Sdrh                            ** with flags in the upper 8 bits */
77688852abSdrh #endif
7875897234Sdrh };
7975897234Sdrh typedef struct VdbeOp VdbeOp;
8075897234Sdrh 
81165921a7Sdan 
82165921a7Sdan /*
83165921a7Sdan ** A sub-routine used to implement a trigger program.
84165921a7Sdan */
85165921a7Sdan struct SubProgram {
86165921a7Sdan   VdbeOp *aOp;                  /* Array of opcodes for sub-program */
87165921a7Sdan   int nOp;                      /* Elements in aOp[] */
88165921a7Sdan   int nMem;                     /* Number of memory cells required */
89165921a7Sdan   int nCsr;                     /* Number of cursors required */
90ab087d4eSdrh   u8 *aOnce;                    /* Array of OP_Once flags */
91165921a7Sdan   void *token;                  /* id that may be used to recursive triggers */
92d46def77Sdan   SubProgram *pNext;            /* Next sub-program already visited */
93165921a7Sdan };
94165921a7Sdan 
9575897234Sdrh /*
96905793e2Sdrh ** A smaller version of VdbeOp used for the VdbeAddOpList() function because
97905793e2Sdrh ** it takes up less space.
98905793e2Sdrh */
99905793e2Sdrh struct VdbeOpList {
100905793e2Sdrh   u8 opcode;          /* What operation to perform */
101905793e2Sdrh   signed char p1;     /* First operand */
1022400345aSdrh   signed char p2;     /* Second parameter (often the jump destination) */
1032400345aSdrh   signed char p3;     /* Third parameter */
104905793e2Sdrh };
105905793e2Sdrh typedef struct VdbeOpList VdbeOpList;
106905793e2Sdrh 
107905793e2Sdrh /*
108165921a7Sdan ** Allowed values of VdbeOp.p4type
10999fcd718Sdrh */
11066a5167bSdrh #define P4_NOTUSED      0   /* The P4 parameter is not used */
1118d129422Sdrh #define P4_TRANSIENT    0   /* P4 is a pointer to a transient string */
1120c243300Sdrh #define P4_STATIC     (-1)  /* Pointer to a static string */
1130c243300Sdrh #define P4_COLLSEQ    (-2)  /* P4 is a pointer to a CollSeq structure */
1140c243300Sdrh #define P4_INT32      (-3)  /* P4 is a 32-bit signed integer */
1150c243300Sdrh #define P4_SUBPROGRAM (-4)  /* P4 is a pointer to a SubProgram structure */
116c45924ebSdrh #define P4_TABLE      (-5)  /* P4 is a pointer to a Table structure */
1170c243300Sdrh /* Above do not own any resources.  Must free those below */
118c45924ebSdrh #define P4_FREE_IF_LE (-6)
119c45924ebSdrh #define P4_DYNAMIC    (-6)  /* Pointer to memory from sqliteMalloc() */
120c45924ebSdrh #define P4_FUNCDEF    (-7)  /* P4 is a pointer to a FuncDef structure */
121c45924ebSdrh #define P4_KEYINFO    (-8)  /* P4 is a pointer to a KeyInfo structure */
122c45924ebSdrh #define P4_EXPR       (-9) /* P4 is a pointer to an Expr tree */
123c45924ebSdrh #define P4_MEM        (-10) /* P4 is a pointer to a Mem*    structure */
124c45924ebSdrh #define P4_VTAB       (-11) /* P4 is a pointer to an sqlite3_vtab structure */
125c45924ebSdrh #define P4_REAL       (-12) /* P4 is a 64-bit floating point value */
126c45924ebSdrh #define P4_INT64      (-13) /* P4 is a 64-bit signed integer */
127c45924ebSdrh #define P4_INTARRAY   (-14) /* P4 is a vector of 32-bit integers */
128c45924ebSdrh #define P4_FUNCCTX    (-15) /* P4 is a pointer to an sqlite3_context object */
12999fcd718Sdrh 
130f9c8ce3cSdrh /* Error message codes for OP_Halt */
131f9c8ce3cSdrh #define P5_ConstraintNotNull 1
132f9c8ce3cSdrh #define P5_ConstraintUnique  2
133f9c8ce3cSdrh #define P5_ConstraintCheck   3
134f9c8ce3cSdrh #define P5_ConstraintFK      4
135ffbc3088Sdrh 
13699fcd718Sdrh /*
137955de52cSdanielk1977 ** The Vdbe.aColName array contains 5n Mem structures, where n is the
138955de52cSdanielk1977 ** number of columns of data returned by the statement.
139955de52cSdanielk1977 */
140955de52cSdanielk1977 #define COLNAME_NAME     0
141955de52cSdanielk1977 #define COLNAME_DECLTYPE 1
142955de52cSdanielk1977 #define COLNAME_DATABASE 2
143955de52cSdanielk1977 #define COLNAME_TABLE    3
144955de52cSdanielk1977 #define COLNAME_COLUMN   4
1453f913576Sdrh #ifdef SQLITE_ENABLE_COLUMN_METADATA
146955de52cSdanielk1977 # define COLNAME_N        5      /* Number of COLNAME_xxx symbols */
1473f913576Sdrh #else
1483f913576Sdrh # ifdef SQLITE_OMIT_DECLTYPE
1493f913576Sdrh #   define COLNAME_N      1      /* Store only the name */
1503f913576Sdrh # else
1513f913576Sdrh #   define COLNAME_N      2      /* Store the name and decltype */
1523f913576Sdrh # endif
1533f913576Sdrh #endif
154955de52cSdanielk1977 
155955de52cSdanielk1977 /*
156d1d158bfSdrh ** The following macro converts a label returned by sqlite3VdbeMakeLabel()
157d1d158bfSdrh ** into an index into the Parse.aLabel[] array that contains the resolved
158d1d158bfSdrh ** address of that label.
15975897234Sdrh */
160d1d158bfSdrh #define ADDR(X)  (~(X))
16175897234Sdrh 
16275897234Sdrh /*
1638f619ccdSdrh ** The makefile scans the vdbe.c source file and creates the "opcodes.h"
1648f619ccdSdrh ** header file that defines a number for each opcode used by the VDBE.
16575897234Sdrh */
1668f619ccdSdrh #include "opcodes.h"
16775897234Sdrh 
16875897234Sdrh /*
1692c2f392dSdrh ** Additional non-public SQLITE_PREPARE_* flags
1702c2f392dSdrh */
1712c2f392dSdrh #define SQLITE_PREPARE_SAVESQL  0x80  /* Preserve SQL text */
1722c2f392dSdrh #define SQLITE_PREPARE_MASK     0x0f  /* Mask of public flags */
1732c2f392dSdrh 
1742c2f392dSdrh /*
17575897234Sdrh ** Prototypes for the VDBE interface.  See comments on the implementation
17675897234Sdrh ** for a description of what each of these routines does.
17775897234Sdrh */
1789ac7962aSdrh Vdbe *sqlite3VdbeCreate(Parse*);
1796df9c4b9Sdrh Parse *sqlite3VdbeParser(Vdbe*);
18066a5167bSdrh int sqlite3VdbeAddOp0(Vdbe*,int);
18166a5167bSdrh int sqlite3VdbeAddOp1(Vdbe*,int,int);
18266a5167bSdrh int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
183076e85f5Sdrh int sqlite3VdbeGoto(Vdbe*,int);
184076e85f5Sdrh int sqlite3VdbeLoadString(Vdbe*,int,const char*);
185076e85f5Sdrh void sqlite3VdbeMultiLoad(Vdbe*,int,const char*,...);
18666a5167bSdrh int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
18766a5167bSdrh int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
18897bae794Sdrh int sqlite3VdbeAddOp4Dup8(Vdbe*,int,int,int,int,const u8*,int);
1898cff69dfSdrh int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
190920cf596Sdrh int sqlite3VdbeAddFunctionCall(Parse*,int,int,int,int,const FuncDef*,int);
1912fade2f7Sdrh void sqlite3VdbeEndCoroutine(Vdbe*,int);
192dad300d8Sdrh #if defined(SQLITE_DEBUG) && !defined(SQLITE_TEST_REALLOC_STRESS)
193dad300d8Sdrh   void sqlite3VdbeVerifyNoMallocRequired(Vdbe *p, int N);
1949e1ab1a8Sdan   void sqlite3VdbeVerifyNoResultRow(Vdbe *p);
1952ce1865dSdrh #else
196dad300d8Sdrh # define sqlite3VdbeVerifyNoMallocRequired(A,B)
1979e1ab1a8Sdan # define sqlite3VdbeVerifyNoResultRow(A)
198341141c3Sdrh #endif
199341141c3Sdrh #if defined(SQLITE_DEBUG)
200341141c3Sdrh   void sqlite3VdbeVerifyAbortable(Vdbe *p, int);
201b77c3129Sdrh   void sqlite3VdbeNoJumpsOutsideSubrtn(Vdbe*,int,int,int);
202341141c3Sdrh #else
2034031bafaSdrh # define sqlite3VdbeVerifyAbortable(A,B)
204b77c3129Sdrh # define sqlite3VdbeNoJumpsOutsideSubrtn(A,B,C,D)
2052ce1865dSdrh #endif
2062ce1865dSdrh VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp,int iLineno);
207e2ca99c9Sdrh #ifndef SQLITE_OMIT_EXPLAIN
208e2ca99c9Sdrh   void sqlite3VdbeExplain(Parse*,u8,const char*,...);
209e2ca99c9Sdrh   void sqlite3VdbeExplainPop(Parse*);
210e2ca99c9Sdrh   int sqlite3VdbeExplainParent(Parse*);
211e2ca99c9Sdrh # define ExplainQueryPlan(P)        sqlite3VdbeExplain P
212e2ca99c9Sdrh # define ExplainQueryPlanPop(P)     sqlite3VdbeExplainPop(P)
213e2ca99c9Sdrh # define ExplainQueryPlanParent(P)  sqlite3VdbeExplainParent(P)
214e2ca99c9Sdrh #else
215e2ca99c9Sdrh # define ExplainQueryPlan(P)
216e2ca99c9Sdrh # define ExplainQueryPlanPop(P)
217e2ca99c9Sdrh # define ExplainQueryPlanParent(P) 0
218bd462bccSdrh # define sqlite3ExplainBreakpoint(A,B) /*no-op*/
219bd462bccSdrh #endif
220bd462bccSdrh #if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_EXPLAIN)
221bd462bccSdrh   void sqlite3ExplainBreakpoint(const char*,const char*);
222bd462bccSdrh #else
223bd462bccSdrh # define sqlite3ExplainBreakpoint(A,B) /*no-op*/
224e2ca99c9Sdrh #endif
2256a5a13dfSdan void sqlite3VdbeAddParseSchemaOp(Vdbe*, int, char*, u16);
226044388cfSmistachkin void sqlite3VdbeChangeOpcode(Vdbe*, int addr, u8);
2273728b84cSdrh void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
2283728b84cSdrh void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
2293728b84cSdrh void sqlite3VdbeChangeP3(Vdbe*, int addr, int P3);
230585ce192Sdrh void sqlite3VdbeChangeP5(Vdbe*, u16 P5);
231*e995d2c2Sdrh void sqlite3VdbeTypeofColumn(Vdbe*, int);
232d654be80Sdrh void sqlite3VdbeJumpHere(Vdbe*, int addr);
233dc4f6fc0Sdrh void sqlite3VdbeJumpHereOrPopInst(Vdbe*, int addr);
2342ce1865dSdrh int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
23561019c78Sdrh int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
23613d79502Sdrh #ifdef SQLITE_DEBUG
2373aef2fb1Sdrh   void sqlite3VdbeReleaseRegisters(Parse*,int addr, int n, u32 mask, int);
23813d79502Sdrh #else
2393aef2fb1Sdrh # define sqlite3VdbeReleaseRegisters(P,A,N,M,F)
24013d79502Sdrh #endif
24166a5167bSdrh void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
242f14b7fb7Sdrh void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
2432ec2fb22Sdrh void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
244fb98264aSdrh void sqlite3VdbeUsesBtree(Vdbe*, int);
2454adee20fSdanielk1977 VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
246058e9950Sdrh VdbeOp *sqlite3VdbeGetLastOp(Vdbe*);
247ec4ccdbcSdrh int sqlite3VdbeMakeLabel(Parse*);
2484611d925Sdrh void sqlite3VdbeRunOnlyOnce(Vdbe*);
249f71a3664Sdrh void sqlite3VdbeReusable(Vdbe*);
2504adee20fSdanielk1977 void sqlite3VdbeDelete(Vdbe*);
251124c0b49Sdrh void sqlite3VdbeMakeReady(Vdbe*,Parse*);
2529e6db7d7Sdanielk1977 int sqlite3VdbeFinalize(Vdbe*);
2534adee20fSdanielk1977 void sqlite3VdbeResolveLabel(Vdbe*, int);
2544adee20fSdanielk1977 int sqlite3VdbeCurrentAddr(Vdbe*);
25587cc3b31Sdrh #ifdef SQLITE_DEBUG
256f3677212Sdan   int sqlite3VdbeAssertMayAbort(Vdbe *, int);
25787cc3b31Sdrh #endif
2583c23a885Sdrh void sqlite3VdbeResetStepResult(Vdbe*);
259124c0b49Sdrh void sqlite3VdbeRewind(Vdbe*);
260c890fec3Sdrh int sqlite3VdbeReset(Vdbe*);
26122322fd4Sdanielk1977 void sqlite3VdbeSetNumCols(Vdbe*,int);
26210fb749bSdanielk1977 int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, void(*)(void*));
263b28af71aSdanielk1977 void sqlite3VdbeCountChanges(Vdbe*);
264aee18ef8Sdanielk1977 sqlite3 *sqlite3VdbeDb(Vdbe*);
2652c2f392dSdrh u8 sqlite3VdbePrepareFlags(Vdbe*);
2662c2f392dSdrh void sqlite3VdbeSetSql(Vdbe*, const char *z, int n, u8);
267893bd375Sdrh #ifdef SQLITE_ENABLE_NORMALIZE
268893bd375Sdrh void sqlite3VdbeAddDblquoteStr(sqlite3*,Vdbe*,const char*);
269643d855dSdrh int sqlite3VdbeUsesDoubleQuotedString(Vdbe*,const char*);
270893bd375Sdrh #endif
271c5155257Sdrh void sqlite3VdbeSwap(Vdbe*,Vdbe*);
272165921a7Sdan VdbeOp *sqlite3VdbeTakeOpArray(Vdbe*, int*, int*);
273cf0fd4a5Sdrh sqlite3_value *sqlite3VdbeGetBoundValue(Vdbe*, int, u8);
2741d2ce4f8Sdan void sqlite3VdbeSetVarmask(Vdbe*, int);
275c7bc4fdeSdrh #ifndef SQLITE_OMIT_TRACE
276c7bc4fdeSdrh   char *sqlite3VdbeExpandSql(Vdbe*, const char*);
277c7bc4fdeSdrh #endif
2783eddb23eSdrh int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
2798d7b212cSdrh int sqlite3BlobCompare(const Mem*, const Mem*);
28075897234Sdrh 
28103e9cfc2Sdan void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
28275179dedSdrh int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
2837004f3f6Sdan int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
284a582b016Sdrh UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo*);
2851e968a0cSdrh 
28675179dedSdrh typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
2871fed5dabSdan RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
2881fed5dabSdan 
289d19c933eSdan void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
29006baba54Sdrh int sqlite3VdbeHasSubProgram(Vdbe*);
291d19c933eSdan 
2926e97f8ecSdrh int sqlite3NotPureFunc(sqlite3_context*);
293691b5c54Sdrh #ifdef SQLITE_ENABLE_BYTECODE_VTAB
294691b5c54Sdrh int sqlite3VdbeBytecodeVtabInit(sqlite3*);
295691b5c54Sdrh #endif
2963e34eabcSdrh 
29772ffd091Sdrh /* Use SQLITE_ENABLE_COMMENTS to enable generation of extra comments on
29872ffd091Sdrh ** each VDBE opcode.
29972ffd091Sdrh **
30072ffd091Sdrh ** Use the SQLITE_ENABLE_MODULE_COMMENTS macro to see some extra no-op
30172ffd091Sdrh ** comments in VDBE programs that show key decision points in the code
30272ffd091Sdrh ** generator.
30372ffd091Sdrh */
304c7379ce4Sdrh #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
305d3d39e93Sdrh   void sqlite3VdbeComment(Vdbe*, const char*, ...);
306d3d39e93Sdrh # define VdbeComment(X)  sqlite3VdbeComment X
30716ee60ffSdrh   void sqlite3VdbeNoopComment(Vdbe*, const char*, ...);
30816ee60ffSdrh # define VdbeNoopComment(X)  sqlite3VdbeNoopComment X
30972ffd091Sdrh # ifdef SQLITE_ENABLE_MODULE_COMMENTS
31072ffd091Sdrh #   define VdbeModuleComment(X)  sqlite3VdbeNoopComment X
31172ffd091Sdrh # else
31272ffd091Sdrh #   define VdbeModuleComment(X)
31372ffd091Sdrh # endif
314d3d39e93Sdrh #else
315d3d39e93Sdrh # define VdbeComment(X)
31616ee60ffSdrh # define VdbeNoopComment(X)
31772ffd091Sdrh # define VdbeModuleComment(X)
318d3d39e93Sdrh #endif
319d3d39e93Sdrh 
3205655c549Sdrh /*
3215655c549Sdrh ** The VdbeCoverage macros are used to set a coverage testing point
3225655c549Sdrh ** for VDBE branch instructions.  The coverage testing points are line
3235655c549Sdrh ** numbers in the sqlite3.c source file.  VDBE branch coverage testing
3245655c549Sdrh ** only works with an amalagmation build.  That's ok since a VDBE branch
3255655c549Sdrh ** coverage build designed for testing the test suite only.  No application
3265655c549Sdrh ** should ever ship with VDBE branch coverage measuring turned on.
3275655c549Sdrh **
3285655c549Sdrh **    VdbeCoverage(v)                  // Mark the previously coded instruction
3295655c549Sdrh **                                     // as a branch
3305655c549Sdrh **
3315655c549Sdrh **    VdbeCoverageIf(v, conditional)   // Mark previous if conditional true
3325655c549Sdrh **
3335655c549Sdrh **    VdbeCoverageAlwaysTaken(v)       // Previous branch is always taken
3345655c549Sdrh **
3355655c549Sdrh **    VdbeCoverageNeverTaken(v)        // Previous branch is never taken
3365655c549Sdrh **
3377083a487Sdrh **    VdbeCoverageNeverNull(v)         // Previous three-way branch is only
3387083a487Sdrh **                                     // taken on the first two ways.  The
3397083a487Sdrh **                                     // NULL option is not possible
3407083a487Sdrh **
3417083a487Sdrh **    VdbeCoverageEqNe(v)              // Previous OP_Jump is only interested
3427083a487Sdrh **                                     // in distingishing equal and not-equal.
3437083a487Sdrh **
3445655c549Sdrh ** Every VDBE branch operation must be tagged with one of the macros above.
3455655c549Sdrh ** If not, then when "make test" is run with -DSQLITE_VDBE_COVERAGE and
3465655c549Sdrh ** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch()
3475655c549Sdrh ** routine in vdbe.c, alerting the developer to the missed tag.
3487083a487Sdrh **
3497083a487Sdrh ** During testing, the test application will invoke
3507083a487Sdrh ** sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE,...) to set a callback
3517083a487Sdrh ** routine that is invoked as each bytecode branch is taken.  The callback
3527083a487Sdrh ** contains the sqlite3.c source line number ov the VdbeCoverage macro and
3537083a487Sdrh ** flags to indicate whether or not the branch was taken.  The test application
3547083a487Sdrh ** is responsible for keeping track of this and reporting byte-code branches
3557083a487Sdrh ** that are never taken.
3567083a487Sdrh **
3577083a487Sdrh ** See the VdbeBranchTaken() macro and vdbeTakeBranch() function in the
3587083a487Sdrh ** vdbe.c source file for additional information.
3595655c549Sdrh */
360688852abSdrh #ifdef SQLITE_VDBE_COVERAGE
361688852abSdrh   void sqlite3VdbeSetLineNumber(Vdbe*,int);
362688852abSdrh # define VdbeCoverage(v) sqlite3VdbeSetLineNumber(v,__LINE__)
363688852abSdrh # define VdbeCoverageIf(v,x) if(x)sqlite3VdbeSetLineNumber(v,__LINE__)
3647083a487Sdrh # define VdbeCoverageAlwaysTaken(v) \
3657083a487Sdrh          sqlite3VdbeSetLineNumber(v,__LINE__|0x5000000);
3667083a487Sdrh # define VdbeCoverageNeverTaken(v) \
3677083a487Sdrh          sqlite3VdbeSetLineNumber(v,__LINE__|0x6000000);
3687083a487Sdrh # define VdbeCoverageNeverNull(v) \
3697083a487Sdrh          sqlite3VdbeSetLineNumber(v,__LINE__|0x4000000);
3706ccbd278Sdrh # define VdbeCoverageNeverNullIf(v,x) \
3716ccbd278Sdrh          if(x)sqlite3VdbeSetLineNumber(v,__LINE__|0x4000000);
3727083a487Sdrh # define VdbeCoverageEqNe(v) \
3737083a487Sdrh          sqlite3VdbeSetLineNumber(v,__LINE__|0x8000000);
374b06a4ec1Sdrh # define VDBE_OFFSET_LINENO(x) (__LINE__+x)
375688852abSdrh #else
376688852abSdrh # define VdbeCoverage(v)
377688852abSdrh # define VdbeCoverageIf(v,x)
3785655c549Sdrh # define VdbeCoverageAlwaysTaken(v)
3795655c549Sdrh # define VdbeCoverageNeverTaken(v)
3807083a487Sdrh # define VdbeCoverageNeverNull(v)
3816ccbd278Sdrh # define VdbeCoverageNeverNullIf(v,x)
3827083a487Sdrh # define VdbeCoverageEqNe(v)
383b06a4ec1Sdrh # define VDBE_OFFSET_LINENO(x) 0
384688852abSdrh #endif
385688852abSdrh 
3866f9702edSdan #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
387518140edSdrh void sqlite3VdbeScanStatus(Vdbe*, int, int, int, LogEst, const char*);
3886f9702edSdan #else
389037b5324Sdan # define sqlite3VdbeScanStatus(a,b,c,d,e)
3906f9702edSdan #endif
3916f9702edSdan 
392299bf7c2Sdrh #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
393299bf7c2Sdrh void sqlite3VdbePrintOp(FILE*, int, VdbeOp*);
394299bf7c2Sdrh #endif
395299bf7c2Sdrh 
39643f58d6aSdrh #endif /* SQLITE_VDBE_H */
397