blob: 3214d5bce36819fb2f50e2bf64fe717ed53e916f [file] [log] [blame]
drh75897232000-05-29 14:26:00 +00001/*
drhb19a2bc2001-09-16 00:13:26 +00002** 2001 September 15
drh75897232000-05-29 14:26:00 +00003**
drhb19a2bc2001-09-16 00:13:26 +00004** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
drh75897232000-05-29 14:26:00 +00006**
drhb19a2bc2001-09-16 00:13:26 +00007** 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.
drh75897232000-05-29 14:26:00 +000010**
11*************************************************************************
12** Header file for the Virtual DataBase Engine (VDBE)
13**
14** This header defines the interface to the virtual database engine
15** or VDBE. The VDBE implements an abstract machine that runs a
16** simple program to access and modify the underlying database.
drh75897232000-05-29 14:26:00 +000017*/
drh43f58d62016-07-09 16:14:45 +000018#ifndef SQLITE_VDBE_H
19#define SQLITE_VDBE_H
drh75897232000-05-29 14:26:00 +000020#include <stdio.h>
21
22/*
23** A single VDBE is an opaque structure named "Vdbe". Only routines
24** in the source file sqliteVdbe.c are allowed to see the insides
25** of this structure.
26*/
27typedef struct Vdbe Vdbe;
28
29/*
danielk19772dca4ac2008-01-03 11:50:29 +000030** The names of the following types declared in vdbeInt.h are required
31** for the VdbeOp definition.
32*/
drh7a6ea932017-04-09 19:23:55 +000033typedef struct sqlite3_value Mem;
dan165921a2009-08-28 18:53:45 +000034typedef struct SubProgram SubProgram;
danielk19772dca4ac2008-01-03 11:50:29 +000035
36/*
drh75897232000-05-29 14:26:00 +000037** A single instruction of the virtual machine has an opcode
38** and as many as three operands. The instruction is recorded
39** as an instance of the following structure:
40*/
41struct VdbeOp {
drh905793e2004-02-21 13:31:09 +000042 u8 opcode; /* What operation to perform */
drhc9206282008-01-09 18:31:45 +000043 signed char p4type; /* One of the P4_xxx constants for p4 */
drh585ce192017-01-25 14:58:27 +000044 u16 p5; /* Fifth parameter is an unsigned 16-bit integer */
drh75897232000-05-29 14:26:00 +000045 int p1; /* First operand */
46 int p2; /* Second parameter (often the jump destination) */
drh66a51672008-01-03 00:01:23 +000047 int p3; /* The third parameter */
drh9c7c9132015-06-26 18:16:52 +000048 union p4union { /* fourth parameter */
danielk19772dca4ac2008-01-03 11:50:29 +000049 int i; /* Integer value if p4type==P4_INT32 */
50 void *p; /* Generic pointer */
51 char *z; /* Pointer to data for string (char array) types */
52 i64 *pI64; /* Used when p4type is P4_INT64 */
53 double *pReal; /* Used when p4type is P4_REAL */
54 FuncDef *pFunc; /* Used when p4type is P4_FUNCDEF */
drh9c7c9132015-06-26 18:16:52 +000055 sqlite3_context *pCtx; /* Used when p4type is P4_FUNCCTX */
danielk19772dca4ac2008-01-03 11:50:29 +000056 CollSeq *pColl; /* Used when p4type is P4_COLLSEQ */
57 Mem *pMem; /* Used when p4type is P4_MEM */
danielk1977595a5232009-07-24 17:58:53 +000058 VTable *pVtab; /* Used when p4type is P4_VTAB */
danielk19772dca4ac2008-01-03 11:50:29 +000059 KeyInfo *pKeyInfo; /* Used when p4type is P4_KEYINFO */
drh0acb7e42008-06-25 00:12:41 +000060 int *ai; /* Used when p4type is P4_INTARRAY */
dan165921a2009-08-28 18:53:45 +000061 SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */
dan319eeb72011-03-19 08:38:50 +000062 Table *pTab; /* Used when p4type is P4_TABLE */
drh28935362013-12-07 20:39:19 +000063#ifdef SQLITE_ENABLE_CURSOR_HINTS
64 Expr *pExpr; /* Used when p4type is P4_EXPR */
65#endif
drh2ab792e2017-05-30 18:34:07 +000066 int (*xAdvance)(BtCursor *, int);
drh66a51672008-01-03 00:01:23 +000067 } p4;
drhc7379ce2013-10-30 02:28:23 +000068#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
shane9bcbdad2008-05-29 20:22:37 +000069 char *zComment; /* Comment to improve readability */
drhd4e70eb2008-01-02 00:34:36 +000070#endif
drh7b396862003-01-01 23:06:20 +000071#ifdef VDBE_PROFILE
drh15ab9412014-02-24 14:24:01 +000072 u32 cnt; /* Number of times this instruction was executed */
shane9bcbdad2008-05-29 20:22:37 +000073 u64 cycles; /* Total time spent executing this instruction */
drh7b396862003-01-01 23:06:20 +000074#endif
drh688852a2014-02-17 22:40:43 +000075#ifdef SQLITE_VDBE_COVERAGE
drh7083a482018-07-10 16:04:04 +000076 u32 iSrcLine; /* Source-code line that generated this opcode
77 ** with flags in the upper 8 bits */
drh688852a2014-02-17 22:40:43 +000078#endif
drh75897232000-05-29 14:26:00 +000079};
80typedef struct VdbeOp VdbeOp;
81
dan165921a2009-08-28 18:53:45 +000082
83/*
84** A sub-routine used to implement a trigger program.
85*/
86struct SubProgram {
87 VdbeOp *aOp; /* Array of opcodes for sub-program */
88 int nOp; /* Elements in aOp[] */
89 int nMem; /* Number of memory cells required */
90 int nCsr; /* Number of cursors required */
drhab087d42017-03-24 17:59:56 +000091 u8 *aOnce; /* Array of OP_Once flags */
dan165921a2009-08-28 18:53:45 +000092 void *token; /* id that may be used to recursive triggers */
dand46def72010-07-24 11:28:28 +000093 SubProgram *pNext; /* Next sub-program already visited */
dan165921a2009-08-28 18:53:45 +000094};
95
drh75897232000-05-29 14:26:00 +000096/*
drh905793e2004-02-21 13:31:09 +000097** A smaller version of VdbeOp used for the VdbeAddOpList() function because
98** it takes up less space.
99*/
100struct VdbeOpList {
101 u8 opcode; /* What operation to perform */
102 signed char p1; /* First operand */
drh24003452008-01-03 01:28:59 +0000103 signed char p2; /* Second parameter (often the jump destination) */
104 signed char p3; /* Third parameter */
drh905793e2004-02-21 13:31:09 +0000105};
106typedef struct VdbeOpList VdbeOpList;
107
108/*
dan165921a2009-08-28 18:53:45 +0000109** Allowed values of VdbeOp.p4type
drh99fcd712001-10-13 01:06:47 +0000110*/
drh0c243302017-07-12 20:43:23 +0000111#define P4_NOTUSED 0 /* The P4 parameter is not used */
112#define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */
113#define P4_STATIC (-1) /* Pointer to a static string */
114#define P4_COLLSEQ (-2) /* P4 is a pointer to a CollSeq structure */
115#define P4_INT32 (-3) /* P4 is a 32-bit signed integer */
116#define P4_SUBPROGRAM (-4) /* P4 is a pointer to a SubProgram structure */
117#define P4_ADVANCE (-5) /* P4 is a pointer to BtreeNext() or BtreePrev() */
118#define P4_TABLE (-6) /* P4 is a pointer to a Table structure */
119/* Above do not own any resources. Must free those below */
120#define P4_FREE_IF_LE (-7)
121#define P4_DYNAMIC (-7) /* Pointer to memory from sqliteMalloc() */
122#define P4_FUNCDEF (-8) /* P4 is a pointer to a FuncDef structure */
123#define P4_KEYINFO (-9) /* P4 is a pointer to a KeyInfo structure */
124#define P4_EXPR (-10) /* P4 is a pointer to an Expr tree */
125#define P4_MEM (-11) /* P4 is a pointer to a Mem* structure */
126#define P4_VTAB (-12) /* P4 is a pointer to an sqlite3_vtab structure */
127#define P4_REAL (-13) /* P4 is a 64-bit floating point value */
128#define P4_INT64 (-14) /* P4 is a 64-bit signed integer */
129#define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */
130#define P4_FUNCCTX (-16) /* P4 is a pointer to an sqlite3_context object */
dan614efe22018-01-12 16:44:29 +0000131#define P4_DYNBLOB (-17) /* Pointer to memory from sqliteMalloc() */
drh99fcd712001-10-13 01:06:47 +0000132
drhf9c8ce32013-11-05 13:33:55 +0000133/* Error message codes for OP_Halt */
134#define P5_ConstraintNotNull 1
135#define P5_ConstraintUnique 2
136#define P5_ConstraintCheck 3
137#define P5_ConstraintFK 4
drhffbc3082004-05-21 01:29:06 +0000138
drh99fcd712001-10-13 01:06:47 +0000139/*
danielk1977955de522006-02-10 02:27:42 +0000140** The Vdbe.aColName array contains 5n Mem structures, where n is the
141** number of columns of data returned by the statement.
142*/
143#define COLNAME_NAME 0
144#define COLNAME_DECLTYPE 1
145#define COLNAME_DATABASE 2
146#define COLNAME_TABLE 3
147#define COLNAME_COLUMN 4
drh3f913572008-03-22 01:07:17 +0000148#ifdef SQLITE_ENABLE_COLUMN_METADATA
149# define COLNAME_N 5 /* Number of COLNAME_xxx symbols */
150#else
151# ifdef SQLITE_OMIT_DECLTYPE
152# define COLNAME_N 1 /* Store only the name */
153# else
154# define COLNAME_N 2 /* Store the name and decltype */
155# endif
156#endif
danielk1977955de522006-02-10 02:27:42 +0000157
158/*
drhd1d158b2018-12-29 14:23:22 +0000159** The following macro converts a label returned by sqlite3VdbeMakeLabel()
160** into an index into the Parse.aLabel[] array that contains the resolved
161** address of that label.
drh75897232000-05-29 14:26:00 +0000162*/
drhd1d158b2018-12-29 14:23:22 +0000163#define ADDR(X) (~(X))
drh75897232000-05-29 14:26:00 +0000164
165/*
drh8f619cc2002-09-08 00:04:50 +0000166** The makefile scans the vdbe.c source file and creates the "opcodes.h"
167** header file that defines a number for each opcode used by the VDBE.
drh75897232000-05-29 14:26:00 +0000168*/
drh8f619cc2002-09-08 00:04:50 +0000169#include "opcodes.h"
drh75897232000-05-29 14:26:00 +0000170
171/*
drh2c2f3922017-06-01 00:54:35 +0000172** Additional non-public SQLITE_PREPARE_* flags
173*/
174#define SQLITE_PREPARE_SAVESQL 0x80 /* Preserve SQL text */
175#define SQLITE_PREPARE_MASK 0x0f /* Mask of public flags */
176
177/*
drh75897232000-05-29 14:26:00 +0000178** Prototypes for the VDBE interface. See comments on the implementation
179** for a description of what each of these routines does.
180*/
drh9ac79622013-12-18 15:11:47 +0000181Vdbe *sqlite3VdbeCreate(Parse*);
drh6df9c4b2019-10-18 12:52:08 +0000182Parse *sqlite3VdbeParser(Vdbe*);
drh66a51672008-01-03 00:01:23 +0000183int sqlite3VdbeAddOp0(Vdbe*,int);
184int sqlite3VdbeAddOp1(Vdbe*,int,int);
185int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
drh076e85f2015-09-03 13:46:12 +0000186int sqlite3VdbeGoto(Vdbe*,int);
187int sqlite3VdbeLoadString(Vdbe*,int,const char*);
188void sqlite3VdbeMultiLoad(Vdbe*,int,const char*,...);
drh66a51672008-01-03 00:01:23 +0000189int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
190int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
drh97bae792015-06-05 15:59:57 +0000191int sqlite3VdbeAddOp4Dup8(Vdbe*,int,int,int,int,const u8*,int);
drh8cff69d2009-11-12 19:59:44 +0000192int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
drh920cf592019-10-30 16:29:02 +0000193int sqlite3VdbeAddFunctionCall(Parse*,int,int,int,int,const FuncDef*,int);
drh2fade2f2016-02-09 02:12:20 +0000194void sqlite3VdbeEndCoroutine(Vdbe*,int);
drhdad300d2016-01-18 00:20:26 +0000195#if defined(SQLITE_DEBUG) && !defined(SQLITE_TEST_REALLOC_STRESS)
196 void sqlite3VdbeVerifyNoMallocRequired(Vdbe *p, int N);
dan9e1ab1a2017-01-05 19:32:48 +0000197 void sqlite3VdbeVerifyNoResultRow(Vdbe *p);
drh2ce18652016-01-16 20:50:21 +0000198#else
drhdad300d2016-01-18 00:20:26 +0000199# define sqlite3VdbeVerifyNoMallocRequired(A,B)
dan9e1ab1a2017-01-05 19:32:48 +0000200# define sqlite3VdbeVerifyNoResultRow(A)
drh341141c2018-05-28 17:43:28 +0000201#endif
202#if defined(SQLITE_DEBUG)
203 void sqlite3VdbeVerifyAbortable(Vdbe *p, int);
204#else
drh4031baf2018-05-28 17:31:20 +0000205# define sqlite3VdbeVerifyAbortable(A,B)
drh2ce18652016-01-16 20:50:21 +0000206#endif
drhe2ca99c2018-05-02 00:33:43 +0000207VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp,int iLineno);
208#ifndef SQLITE_OMIT_EXPLAIN
209 void sqlite3VdbeExplain(Parse*,u8,const char*,...);
210 void sqlite3VdbeExplainPop(Parse*);
211 int sqlite3VdbeExplainParent(Parse*);
212# define ExplainQueryPlan(P) sqlite3VdbeExplain P
213# define ExplainQueryPlanPop(P) sqlite3VdbeExplainPop(P)
214# define ExplainQueryPlanParent(P) sqlite3VdbeExplainParent(P)
drhe2ca99c2018-05-02 00:33:43 +0000215#else
216# define ExplainQueryPlan(P)
217# define ExplainQueryPlanPop(P)
218# define ExplainQueryPlanParent(P) 0
drhbd462bc2018-12-24 20:21:06 +0000219# define sqlite3ExplainBreakpoint(A,B) /*no-op*/
220#endif
221#if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_EXPLAIN)
222 void sqlite3ExplainBreakpoint(const char*,const char*);
223#else
224# define sqlite3ExplainBreakpoint(A,B) /*no-op*/
drhe2ca99c2018-05-02 00:33:43 +0000225#endif
drh5d9c9da2011-06-03 20:11:17 +0000226void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
mistachkin044388c2019-08-09 01:59:14 +0000227void sqlite3VdbeChangeOpcode(Vdbe*, int addr, u8);
drh3728b842019-08-09 01:11:32 +0000228void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
229void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
230void sqlite3VdbeChangeP3(Vdbe*, int addr, int P3);
drh585ce192017-01-25 14:58:27 +0000231void sqlite3VdbeChangeP5(Vdbe*, u16 P5);
drhd654be82005-09-20 17:42:23 +0000232void sqlite3VdbeJumpHere(Vdbe*, int addr);
drh2ce18652016-01-16 20:50:21 +0000233int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
drh61019c72014-01-04 16:49:02 +0000234int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
drh66a51672008-01-03 00:01:23 +0000235void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
drhf14b7fb2016-12-07 21:35:55 +0000236void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
drh2ec2fb22013-11-06 19:59:23 +0000237void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
drhfb982642007-08-30 01:19:59 +0000238void sqlite3VdbeUsesBtree(Vdbe*, int);
danielk19774adee202004-05-08 08:23:19 +0000239VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
drhec4ccdb2018-12-29 02:26:59 +0000240int sqlite3VdbeMakeLabel(Parse*);
drh4611d922010-02-25 14:47:01 +0000241void sqlite3VdbeRunOnlyOnce(Vdbe*);
drhf71a3662016-03-16 20:44:45 +0000242void sqlite3VdbeReusable(Vdbe*);
danielk19774adee202004-05-08 08:23:19 +0000243void sqlite3VdbeDelete(Vdbe*);
drhcb103b92012-10-26 00:11:23 +0000244void sqlite3VdbeClearObject(sqlite3*,Vdbe*);
drh124c0b42011-06-01 18:15:55 +0000245void sqlite3VdbeMakeReady(Vdbe*,Parse*);
danielk19779e6db7d2004-06-21 08:18:51 +0000246int sqlite3VdbeFinalize(Vdbe*);
danielk19774adee202004-05-08 08:23:19 +0000247void sqlite3VdbeResolveLabel(Vdbe*, int);
248int sqlite3VdbeCurrentAddr(Vdbe*);
drh87cc3b32007-05-08 21:45:27 +0000249#ifdef SQLITE_DEBUG
danf3677212009-09-10 16:14:50 +0000250 int sqlite3VdbeAssertMayAbort(Vdbe *, int);
drh87cc3b32007-05-08 21:45:27 +0000251#endif
drh3c23a882007-01-09 14:01:13 +0000252void sqlite3VdbeResetStepResult(Vdbe*);
drh124c0b42011-06-01 18:15:55 +0000253void sqlite3VdbeRewind(Vdbe*);
drhc890fec2008-08-01 20:10:08 +0000254int sqlite3VdbeReset(Vdbe*);
danielk197722322fd2004-05-25 23:35:17 +0000255void sqlite3VdbeSetNumCols(Vdbe*,int);
danielk197710fb7492008-10-31 10:53:22 +0000256int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, void(*)(void*));
danielk1977b28af712004-06-21 06:50:26 +0000257void sqlite3VdbeCountChanges(Vdbe*);
danielk1977aee18ef2005-03-09 12:26:50 +0000258sqlite3 *sqlite3VdbeDb(Vdbe*);
drh2c2f3922017-06-01 00:54:35 +0000259u8 sqlite3VdbePrepareFlags(Vdbe*);
260void sqlite3VdbeSetSql(Vdbe*, const char *z, int n, u8);
drh893bd372018-12-07 16:32:11 +0000261#ifdef SQLITE_ENABLE_NORMALIZE
262void sqlite3VdbeAddDblquoteStr(sqlite3*,Vdbe*,const char*);
drh643d8552018-12-10 16:00:57 +0000263int sqlite3VdbeUsesDoubleQuotedString(Vdbe*,const char*);
drh893bd372018-12-07 16:32:11 +0000264#endif
drhc5155252007-01-08 21:07:17 +0000265void sqlite3VdbeSwap(Vdbe*,Vdbe*);
dan165921a2009-08-28 18:53:45 +0000266VdbeOp *sqlite3VdbeTakeOpArray(Vdbe*, int*, int*);
drhcf0fd4a2013-08-01 12:21:58 +0000267sqlite3_value *sqlite3VdbeGetBoundValue(Vdbe*, int, u8);
dan1d2ce4f2009-10-19 18:11:09 +0000268void sqlite3VdbeSetVarmask(Vdbe*, int);
drhc7bc4fd2009-11-25 18:03:42 +0000269#ifndef SQLITE_OMIT_TRACE
270 char *sqlite3VdbeExpandSql(Vdbe*, const char*);
271#endif
drh3eddb232014-06-28 14:28:06 +0000272int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
drh8d7b2122018-06-11 13:10:45 +0000273int sqlite3BlobCompare(const Mem*, const Mem*);
drh75897232000-05-29 14:26:00 +0000274
dan03e9cfc2011-09-05 14:20:27 +0000275void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
drh75179de2014-09-16 14:37:35 +0000276int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
dan7004f3f2015-03-30 12:06:26 +0000277int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
drha582b012016-12-21 19:45:54 +0000278UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo*);
drh1e968a02008-03-25 00:22:21 +0000279
drh75179de2014-09-16 14:37:35 +0000280typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
dan3b9330f2014-02-27 20:44:18 +0000281RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
dan1fed5da2014-02-25 21:01:25 +0000282
dand19c9332010-07-26 12:05:17 +0000283void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
drh06baba52019-10-24 19:35:26 +0000284int sqlite3VdbeHasSubProgram(Vdbe*);
dand19c9332010-07-26 12:05:17 +0000285
drh6e97f8e2017-07-20 13:17:08 +0000286int sqlite3NotPureFunc(sqlite3_context*);
drh3e34eab2017-07-19 19:48:40 +0000287
drh72ffd092013-10-30 15:52:32 +0000288/* Use SQLITE_ENABLE_COMMENTS to enable generation of extra comments on
289** each VDBE opcode.
290**
291** Use the SQLITE_ENABLE_MODULE_COMMENTS macro to see some extra no-op
292** comments in VDBE programs that show key decision points in the code
293** generator.
294*/
drhc7379ce2013-10-30 02:28:23 +0000295#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
drhd3d39e92004-05-20 22:16:29 +0000296 void sqlite3VdbeComment(Vdbe*, const char*, ...);
297# define VdbeComment(X) sqlite3VdbeComment X
drh16ee60f2008-06-20 18:13:25 +0000298 void sqlite3VdbeNoopComment(Vdbe*, const char*, ...);
299# define VdbeNoopComment(X) sqlite3VdbeNoopComment X
drh72ffd092013-10-30 15:52:32 +0000300# ifdef SQLITE_ENABLE_MODULE_COMMENTS
301# define VdbeModuleComment(X) sqlite3VdbeNoopComment X
302# else
303# define VdbeModuleComment(X)
304# endif
drhd3d39e92004-05-20 22:16:29 +0000305#else
306# define VdbeComment(X)
drh16ee60f2008-06-20 18:13:25 +0000307# define VdbeNoopComment(X)
drh72ffd092013-10-30 15:52:32 +0000308# define VdbeModuleComment(X)
drhd3d39e92004-05-20 22:16:29 +0000309#endif
310
drh5655c542014-02-19 19:14:34 +0000311/*
312** The VdbeCoverage macros are used to set a coverage testing point
313** for VDBE branch instructions. The coverage testing points are line
314** numbers in the sqlite3.c source file. VDBE branch coverage testing
315** only works with an amalagmation build. That's ok since a VDBE branch
316** coverage build designed for testing the test suite only. No application
317** should ever ship with VDBE branch coverage measuring turned on.
318**
319** VdbeCoverage(v) // Mark the previously coded instruction
320** // as a branch
321**
322** VdbeCoverageIf(v, conditional) // Mark previous if conditional true
323**
324** VdbeCoverageAlwaysTaken(v) // Previous branch is always taken
325**
326** VdbeCoverageNeverTaken(v) // Previous branch is never taken
327**
drh7083a482018-07-10 16:04:04 +0000328** VdbeCoverageNeverNull(v) // Previous three-way branch is only
329** // taken on the first two ways. The
330** // NULL option is not possible
331**
332** VdbeCoverageEqNe(v) // Previous OP_Jump is only interested
333** // in distingishing equal and not-equal.
334**
drh5655c542014-02-19 19:14:34 +0000335** Every VDBE branch operation must be tagged with one of the macros above.
336** If not, then when "make test" is run with -DSQLITE_VDBE_COVERAGE and
337** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch()
338** routine in vdbe.c, alerting the developer to the missed tag.
drh7083a482018-07-10 16:04:04 +0000339**
340** During testing, the test application will invoke
341** sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE,...) to set a callback
342** routine that is invoked as each bytecode branch is taken. The callback
343** contains the sqlite3.c source line number ov the VdbeCoverage macro and
344** flags to indicate whether or not the branch was taken. The test application
345** is responsible for keeping track of this and reporting byte-code branches
346** that are never taken.
347**
348** See the VdbeBranchTaken() macro and vdbeTakeBranch() function in the
349** vdbe.c source file for additional information.
drh5655c542014-02-19 19:14:34 +0000350*/
drh688852a2014-02-17 22:40:43 +0000351#ifdef SQLITE_VDBE_COVERAGE
352 void sqlite3VdbeSetLineNumber(Vdbe*,int);
353# define VdbeCoverage(v) sqlite3VdbeSetLineNumber(v,__LINE__)
354# define VdbeCoverageIf(v,x) if(x)sqlite3VdbeSetLineNumber(v,__LINE__)
drh7083a482018-07-10 16:04:04 +0000355# define VdbeCoverageAlwaysTaken(v) \
356 sqlite3VdbeSetLineNumber(v,__LINE__|0x5000000);
357# define VdbeCoverageNeverTaken(v) \
358 sqlite3VdbeSetLineNumber(v,__LINE__|0x6000000);
359# define VdbeCoverageNeverNull(v) \
360 sqlite3VdbeSetLineNumber(v,__LINE__|0x4000000);
drh6ccbd272018-07-10 17:10:44 +0000361# define VdbeCoverageNeverNullIf(v,x) \
362 if(x)sqlite3VdbeSetLineNumber(v,__LINE__|0x4000000);
drh7083a482018-07-10 16:04:04 +0000363# define VdbeCoverageEqNe(v) \
364 sqlite3VdbeSetLineNumber(v,__LINE__|0x8000000);
drhb06a4ec2014-03-10 18:03:09 +0000365# define VDBE_OFFSET_LINENO(x) (__LINE__+x)
drh688852a2014-02-17 22:40:43 +0000366#else
367# define VdbeCoverage(v)
368# define VdbeCoverageIf(v,x)
drh5655c542014-02-19 19:14:34 +0000369# define VdbeCoverageAlwaysTaken(v)
370# define VdbeCoverageNeverTaken(v)
drh7083a482018-07-10 16:04:04 +0000371# define VdbeCoverageNeverNull(v)
drh6ccbd272018-07-10 17:10:44 +0000372# define VdbeCoverageNeverNullIf(v,x)
drh7083a482018-07-10 16:04:04 +0000373# define VdbeCoverageEqNe(v)
drhb06a4ec2014-03-10 18:03:09 +0000374# define VDBE_OFFSET_LINENO(x) 0
drh688852a2014-02-17 22:40:43 +0000375#endif
376
dan6f9702e2014-11-01 20:38:06 +0000377#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
drh518140e2014-11-06 03:55:10 +0000378void sqlite3VdbeScanStatus(Vdbe*, int, int, int, LogEst, const char*);
dan6f9702e2014-11-01 20:38:06 +0000379#else
dan037b5322014-11-03 11:25:32 +0000380# define sqlite3VdbeScanStatus(a,b,c,d,e)
dan6f9702e2014-11-01 20:38:06 +0000381#endif
382
drh299bf7c2018-06-11 17:35:02 +0000383#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
384void sqlite3VdbePrintOp(FILE*, int, VdbeOp*);
385#endif
386
drh43f58d62016-07-09 16:14:45 +0000387#endif /* SQLITE_VDBE_H */