blob: 3caf1f787209e13ba28e9c25164f88463e6b4513 [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 */
drhabc38152020-07-22 13:38:04 +000060 u32 *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
drh66a51672008-01-03 00:01:23 +000066 } p4;
drhc7379ce2013-10-30 02:28:23 +000067#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
shane9bcbdad2008-05-29 20:22:37 +000068 char *zComment; /* Comment to improve readability */
drhd4e70eb2008-01-02 00:34:36 +000069#endif
drh688852a2014-02-17 22:40:43 +000070#ifdef SQLITE_VDBE_COVERAGE
drh7083a482018-07-10 16:04:04 +000071 u32 iSrcLine; /* Source-code line that generated this opcode
72 ** with flags in the upper 8 bits */
drh688852a2014-02-17 22:40:43 +000073#endif
dan7f4b0662022-12-07 20:09:54 +000074#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
75 u64 nExec;
76 u64 nCycle;
77#endif
drh75897232000-05-29 14:26:00 +000078};
79typedef struct VdbeOp VdbeOp;
80
dan165921a2009-08-28 18:53:45 +000081
82/*
83** A sub-routine used to implement a trigger program.
84*/
85struct SubProgram {
86 VdbeOp *aOp; /* Array of opcodes for sub-program */
87 int nOp; /* Elements in aOp[] */
88 int nMem; /* Number of memory cells required */
89 int nCsr; /* Number of cursors required */
drhab087d42017-03-24 17:59:56 +000090 u8 *aOnce; /* Array of OP_Once flags */
dan165921a2009-08-28 18:53:45 +000091 void *token; /* id that may be used to recursive triggers */
dand46def72010-07-24 11:28:28 +000092 SubProgram *pNext; /* Next sub-program already visited */
dan165921a2009-08-28 18:53:45 +000093};
94
drh75897232000-05-29 14:26:00 +000095/*
drh905793e2004-02-21 13:31:09 +000096** A smaller version of VdbeOp used for the VdbeAddOpList() function because
97** it takes up less space.
98*/
99struct VdbeOpList {
100 u8 opcode; /* What operation to perform */
101 signed char p1; /* First operand */
drh24003452008-01-03 01:28:59 +0000102 signed char p2; /* Second parameter (often the jump destination) */
103 signed char p3; /* Third parameter */
drh905793e2004-02-21 13:31:09 +0000104};
105typedef struct VdbeOpList VdbeOpList;
106
107/*
dan165921a2009-08-28 18:53:45 +0000108** Allowed values of VdbeOp.p4type
drh99fcd712001-10-13 01:06:47 +0000109*/
drh0c243302017-07-12 20:43:23 +0000110#define P4_NOTUSED 0 /* The P4 parameter is not used */
111#define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */
112#define P4_STATIC (-1) /* Pointer to a static string */
113#define P4_COLLSEQ (-2) /* P4 is a pointer to a CollSeq structure */
114#define P4_INT32 (-3) /* P4 is a 32-bit signed integer */
115#define P4_SUBPROGRAM (-4) /* P4 is a pointer to a SubProgram structure */
drhc45924e2022-02-25 01:10:57 +0000116#define P4_TABLE (-5) /* P4 is a pointer to a Table structure */
drh0c243302017-07-12 20:43:23 +0000117/* Above do not own any resources. Must free those below */
drhc45924e2022-02-25 01:10:57 +0000118#define P4_FREE_IF_LE (-6)
119#define P4_DYNAMIC (-6) /* Pointer to memory from sqliteMalloc() */
120#define P4_FUNCDEF (-7) /* P4 is a pointer to a FuncDef structure */
121#define P4_KEYINFO (-8) /* P4 is a pointer to a KeyInfo structure */
122#define P4_EXPR (-9) /* P4 is a pointer to an Expr tree */
123#define P4_MEM (-10) /* P4 is a pointer to a Mem* structure */
124#define P4_VTAB (-11) /* P4 is a pointer to an sqlite3_vtab structure */
125#define P4_REAL (-12) /* P4 is a 64-bit floating point value */
126#define P4_INT64 (-13) /* P4 is a 64-bit signed integer */
127#define P4_INTARRAY (-14) /* P4 is a vector of 32-bit integers */
128#define P4_FUNCCTX (-15) /* P4 is a pointer to an sqlite3_context object */
drh99fcd712001-10-13 01:06:47 +0000129
drhf9c8ce32013-11-05 13:33:55 +0000130/* Error message codes for OP_Halt */
131#define P5_ConstraintNotNull 1
132#define P5_ConstraintUnique 2
133#define P5_ConstraintCheck 3
134#define P5_ConstraintFK 4
drhffbc3082004-05-21 01:29:06 +0000135
drh99fcd712001-10-13 01:06:47 +0000136/*
danielk1977955de522006-02-10 02:27:42 +0000137** The Vdbe.aColName array contains 5n Mem structures, where n is the
138** number of columns of data returned by the statement.
139*/
140#define COLNAME_NAME 0
141#define COLNAME_DECLTYPE 1
142#define COLNAME_DATABASE 2
143#define COLNAME_TABLE 3
144#define COLNAME_COLUMN 4
drh3f913572008-03-22 01:07:17 +0000145#ifdef SQLITE_ENABLE_COLUMN_METADATA
146# define COLNAME_N 5 /* Number of COLNAME_xxx symbols */
147#else
148# ifdef SQLITE_OMIT_DECLTYPE
149# define COLNAME_N 1 /* Store only the name */
150# else
151# define COLNAME_N 2 /* Store the name and decltype */
152# endif
153#endif
danielk1977955de522006-02-10 02:27:42 +0000154
155/*
drhd1d158b2018-12-29 14:23:22 +0000156** The following macro converts a label returned by sqlite3VdbeMakeLabel()
157** into an index into the Parse.aLabel[] array that contains the resolved
158** address of that label.
drh75897232000-05-29 14:26:00 +0000159*/
drhd1d158b2018-12-29 14:23:22 +0000160#define ADDR(X) (~(X))
drh75897232000-05-29 14:26:00 +0000161
162/*
drh8f619cc2002-09-08 00:04:50 +0000163** The makefile scans the vdbe.c source file and creates the "opcodes.h"
164** header file that defines a number for each opcode used by the VDBE.
drh75897232000-05-29 14:26:00 +0000165*/
drh8f619cc2002-09-08 00:04:50 +0000166#include "opcodes.h"
drh75897232000-05-29 14:26:00 +0000167
168/*
drh2c2f3922017-06-01 00:54:35 +0000169** Additional non-public SQLITE_PREPARE_* flags
170*/
171#define SQLITE_PREPARE_SAVESQL 0x80 /* Preserve SQL text */
172#define SQLITE_PREPARE_MASK 0x0f /* Mask of public flags */
173
174/*
drh75897232000-05-29 14:26:00 +0000175** Prototypes for the VDBE interface. See comments on the implementation
176** for a description of what each of these routines does.
177*/
drh9ac79622013-12-18 15:11:47 +0000178Vdbe *sqlite3VdbeCreate(Parse*);
drh6df9c4b2019-10-18 12:52:08 +0000179Parse *sqlite3VdbeParser(Vdbe*);
drh66a51672008-01-03 00:01:23 +0000180int sqlite3VdbeAddOp0(Vdbe*,int);
181int sqlite3VdbeAddOp1(Vdbe*,int,int);
182int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
drh076e85f2015-09-03 13:46:12 +0000183int sqlite3VdbeGoto(Vdbe*,int);
184int sqlite3VdbeLoadString(Vdbe*,int,const char*);
185void sqlite3VdbeMultiLoad(Vdbe*,int,const char*,...);
drh66a51672008-01-03 00:01:23 +0000186int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
187int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
drh97bae792015-06-05 15:59:57 +0000188int sqlite3VdbeAddOp4Dup8(Vdbe*,int,int,int,int,const u8*,int);
drh8cff69d2009-11-12 19:59:44 +0000189int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
drh920cf592019-10-30 16:29:02 +0000190int sqlite3VdbeAddFunctionCall(Parse*,int,int,int,int,const FuncDef*,int);
drh2fade2f2016-02-09 02:12:20 +0000191void sqlite3VdbeEndCoroutine(Vdbe*,int);
drhdad300d2016-01-18 00:20:26 +0000192#if defined(SQLITE_DEBUG) && !defined(SQLITE_TEST_REALLOC_STRESS)
193 void sqlite3VdbeVerifyNoMallocRequired(Vdbe *p, int N);
dan9e1ab1a2017-01-05 19:32:48 +0000194 void sqlite3VdbeVerifyNoResultRow(Vdbe *p);
drh2ce18652016-01-16 20:50:21 +0000195#else
drhdad300d2016-01-18 00:20:26 +0000196# define sqlite3VdbeVerifyNoMallocRequired(A,B)
dan9e1ab1a2017-01-05 19:32:48 +0000197# define sqlite3VdbeVerifyNoResultRow(A)
drh341141c2018-05-28 17:43:28 +0000198#endif
199#if defined(SQLITE_DEBUG)
200 void sqlite3VdbeVerifyAbortable(Vdbe *p, int);
drhb77c3122022-04-23 18:04:31 +0000201 void sqlite3VdbeNoJumpsOutsideSubrtn(Vdbe*,int,int,int);
drh341141c2018-05-28 17:43:28 +0000202#else
drh4031baf2018-05-28 17:31:20 +0000203# define sqlite3VdbeVerifyAbortable(A,B)
drhb77c3122022-04-23 18:04:31 +0000204# define sqlite3VdbeNoJumpsOutsideSubrtn(A,B,C,D)
drh2ce18652016-01-16 20:50:21 +0000205#endif
drhe2ca99c2018-05-02 00:33:43 +0000206VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp,int iLineno);
207#ifndef SQLITE_OMIT_EXPLAIN
dan231ff4b2022-12-02 20:32:22 +0000208 int sqlite3VdbeExplain(Parse*,u8,const char*,...);
drhe2ca99c2018-05-02 00:33:43 +0000209 void sqlite3VdbeExplainPop(Parse*);
210 int sqlite3VdbeExplainParent(Parse*);
211# define ExplainQueryPlan(P) sqlite3VdbeExplain P
dan231ff4b2022-12-02 20:32:22 +0000212# ifdef SQLITE_ENABLE_STMT_SCANSTATUS
213# define ExplainQueryPlan2(V,P) (V = sqlite3VdbeExplain P)
214# else
215# define ExplainQueryPlan2(V,P) ExplainQueryPlan(P)
216# endif
drhe2ca99c2018-05-02 00:33:43 +0000217# define ExplainQueryPlanPop(P) sqlite3VdbeExplainPop(P)
218# define ExplainQueryPlanParent(P) sqlite3VdbeExplainParent(P)
drhe2ca99c2018-05-02 00:33:43 +0000219#else
220# define ExplainQueryPlan(P)
dan231ff4b2022-12-02 20:32:22 +0000221# define ExplainQueryPlan2(V,P)
drhe2ca99c2018-05-02 00:33:43 +0000222# define ExplainQueryPlanPop(P)
223# define ExplainQueryPlanParent(P) 0
drhbd462bc2018-12-24 20:21:06 +0000224# define sqlite3ExplainBreakpoint(A,B) /*no-op*/
225#endif
226#if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_EXPLAIN)
227 void sqlite3ExplainBreakpoint(const char*,const char*);
228#else
229# define sqlite3ExplainBreakpoint(A,B) /*no-op*/
drhe2ca99c2018-05-02 00:33:43 +0000230#endif
dan6a5a13d2021-02-17 20:08:22 +0000231void sqlite3VdbeAddParseSchemaOp(Vdbe*, int, char*, u16);
mistachkin044388c2019-08-09 01:59:14 +0000232void sqlite3VdbeChangeOpcode(Vdbe*, int addr, u8);
drh3728b842019-08-09 01:11:32 +0000233void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
234void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
235void sqlite3VdbeChangeP3(Vdbe*, int addr, int P3);
drh585ce192017-01-25 14:58:27 +0000236void sqlite3VdbeChangeP5(Vdbe*, u16 P5);
drhe995d2c2022-10-13 12:47:33 +0000237void sqlite3VdbeTypeofColumn(Vdbe*, int);
drhd654be82005-09-20 17:42:23 +0000238void sqlite3VdbeJumpHere(Vdbe*, int addr);
drhdc4f6fc2020-02-07 19:44:13 +0000239void sqlite3VdbeJumpHereOrPopInst(Vdbe*, int addr);
drh2ce18652016-01-16 20:50:21 +0000240int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
drh61019c72014-01-04 16:49:02 +0000241int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);
drh13d79502019-12-23 02:18:49 +0000242#ifdef SQLITE_DEBUG
drh3aef2fb2020-01-02 17:46:02 +0000243 void sqlite3VdbeReleaseRegisters(Parse*,int addr, int n, u32 mask, int);
drh13d79502019-12-23 02:18:49 +0000244#else
drh3aef2fb2020-01-02 17:46:02 +0000245# define sqlite3VdbeReleaseRegisters(P,A,N,M,F)
drh13d79502019-12-23 02:18:49 +0000246#endif
drh66a51672008-01-03 00:01:23 +0000247void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);
drhf14b7fb2016-12-07 21:35:55 +0000248void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type);
drh2ec2fb22013-11-06 19:59:23 +0000249void sqlite3VdbeSetP4KeyInfo(Parse*, Index*);
drhfb982642007-08-30 01:19:59 +0000250void sqlite3VdbeUsesBtree(Vdbe*, int);
danielk19774adee202004-05-08 08:23:19 +0000251VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
drh058e9952022-07-25 19:05:24 +0000252VdbeOp *sqlite3VdbeGetLastOp(Vdbe*);
drhec4ccdb2018-12-29 02:26:59 +0000253int sqlite3VdbeMakeLabel(Parse*);
drh4611d922010-02-25 14:47:01 +0000254void sqlite3VdbeRunOnlyOnce(Vdbe*);
drhf71a3662016-03-16 20:44:45 +0000255void sqlite3VdbeReusable(Vdbe*);
danielk19774adee202004-05-08 08:23:19 +0000256void sqlite3VdbeDelete(Vdbe*);
drh124c0b42011-06-01 18:15:55 +0000257void sqlite3VdbeMakeReady(Vdbe*,Parse*);
danielk19779e6db7d2004-06-21 08:18:51 +0000258int sqlite3VdbeFinalize(Vdbe*);
danielk19774adee202004-05-08 08:23:19 +0000259void sqlite3VdbeResolveLabel(Vdbe*, int);
260int sqlite3VdbeCurrentAddr(Vdbe*);
drh87cc3b32007-05-08 21:45:27 +0000261#ifdef SQLITE_DEBUG
danf3677212009-09-10 16:14:50 +0000262 int sqlite3VdbeAssertMayAbort(Vdbe *, int);
drh87cc3b32007-05-08 21:45:27 +0000263#endif
drh3c23a882007-01-09 14:01:13 +0000264void sqlite3VdbeResetStepResult(Vdbe*);
drh124c0b42011-06-01 18:15:55 +0000265void sqlite3VdbeRewind(Vdbe*);
drhc890fec2008-08-01 20:10:08 +0000266int sqlite3VdbeReset(Vdbe*);
danielk197722322fd2004-05-25 23:35:17 +0000267void sqlite3VdbeSetNumCols(Vdbe*,int);
danielk197710fb7492008-10-31 10:53:22 +0000268int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, void(*)(void*));
danielk1977b28af712004-06-21 06:50:26 +0000269void sqlite3VdbeCountChanges(Vdbe*);
danielk1977aee18ef2005-03-09 12:26:50 +0000270sqlite3 *sqlite3VdbeDb(Vdbe*);
drh2c2f3922017-06-01 00:54:35 +0000271u8 sqlite3VdbePrepareFlags(Vdbe*);
272void sqlite3VdbeSetSql(Vdbe*, const char *z, int n, u8);
drh893bd372018-12-07 16:32:11 +0000273#ifdef SQLITE_ENABLE_NORMALIZE
274void sqlite3VdbeAddDblquoteStr(sqlite3*,Vdbe*,const char*);
drh643d8552018-12-10 16:00:57 +0000275int sqlite3VdbeUsesDoubleQuotedString(Vdbe*,const char*);
drh893bd372018-12-07 16:32:11 +0000276#endif
drhc5155252007-01-08 21:07:17 +0000277void sqlite3VdbeSwap(Vdbe*,Vdbe*);
dan165921a2009-08-28 18:53:45 +0000278VdbeOp *sqlite3VdbeTakeOpArray(Vdbe*, int*, int*);
drhcf0fd4a2013-08-01 12:21:58 +0000279sqlite3_value *sqlite3VdbeGetBoundValue(Vdbe*, int, u8);
dan1d2ce4f2009-10-19 18:11:09 +0000280void sqlite3VdbeSetVarmask(Vdbe*, int);
drhc7bc4fd2009-11-25 18:03:42 +0000281#ifndef SQLITE_OMIT_TRACE
282 char *sqlite3VdbeExpandSql(Vdbe*, const char*);
283#endif
drh3eddb232014-06-28 14:28:06 +0000284int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
drh8d7b2122018-06-11 13:10:45 +0000285int sqlite3BlobCompare(const Mem*, const Mem*);
drh75897232000-05-29 14:26:00 +0000286
dan03e9cfc2011-09-05 14:20:27 +0000287void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
drh75179de2014-09-16 14:37:35 +0000288int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
dan7004f3f2015-03-30 12:06:26 +0000289int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
drha582b012016-12-21 19:45:54 +0000290UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo*);
drh1e968a02008-03-25 00:22:21 +0000291
drh75179de2014-09-16 14:37:35 +0000292typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
dan3b9330f2014-02-27 20:44:18 +0000293RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
dan1fed5da2014-02-25 21:01:25 +0000294
dand19c9332010-07-26 12:05:17 +0000295void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
drh06baba52019-10-24 19:35:26 +0000296int sqlite3VdbeHasSubProgram(Vdbe*);
dand19c9332010-07-26 12:05:17 +0000297
drh6e97f8e2017-07-20 13:17:08 +0000298int sqlite3NotPureFunc(sqlite3_context*);
drh691b5c52020-03-23 15:49:22 +0000299#ifdef SQLITE_ENABLE_BYTECODE_VTAB
300int sqlite3VdbeBytecodeVtabInit(sqlite3*);
301#endif
drh3e34eab2017-07-19 19:48:40 +0000302
drh72ffd092013-10-30 15:52:32 +0000303/* Use SQLITE_ENABLE_COMMENTS to enable generation of extra comments on
304** each VDBE opcode.
305**
306** Use the SQLITE_ENABLE_MODULE_COMMENTS macro to see some extra no-op
307** comments in VDBE programs that show key decision points in the code
308** generator.
309*/
drhc7379ce2013-10-30 02:28:23 +0000310#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
drhd3d39e92004-05-20 22:16:29 +0000311 void sqlite3VdbeComment(Vdbe*, const char*, ...);
312# define VdbeComment(X) sqlite3VdbeComment X
drh16ee60f2008-06-20 18:13:25 +0000313 void sqlite3VdbeNoopComment(Vdbe*, const char*, ...);
314# define VdbeNoopComment(X) sqlite3VdbeNoopComment X
drh72ffd092013-10-30 15:52:32 +0000315# ifdef SQLITE_ENABLE_MODULE_COMMENTS
316# define VdbeModuleComment(X) sqlite3VdbeNoopComment X
317# else
318# define VdbeModuleComment(X)
319# endif
drhd3d39e92004-05-20 22:16:29 +0000320#else
321# define VdbeComment(X)
drh16ee60f2008-06-20 18:13:25 +0000322# define VdbeNoopComment(X)
drh72ffd092013-10-30 15:52:32 +0000323# define VdbeModuleComment(X)
drhd3d39e92004-05-20 22:16:29 +0000324#endif
325
drh5655c542014-02-19 19:14:34 +0000326/*
327** The VdbeCoverage macros are used to set a coverage testing point
328** for VDBE branch instructions. The coverage testing points are line
329** numbers in the sqlite3.c source file. VDBE branch coverage testing
330** only works with an amalagmation build. That's ok since a VDBE branch
331** coverage build designed for testing the test suite only. No application
332** should ever ship with VDBE branch coverage measuring turned on.
333**
334** VdbeCoverage(v) // Mark the previously coded instruction
335** // as a branch
336**
337** VdbeCoverageIf(v, conditional) // Mark previous if conditional true
338**
339** VdbeCoverageAlwaysTaken(v) // Previous branch is always taken
340**
341** VdbeCoverageNeverTaken(v) // Previous branch is never taken
342**
drh7083a482018-07-10 16:04:04 +0000343** VdbeCoverageNeverNull(v) // Previous three-way branch is only
344** // taken on the first two ways. The
345** // NULL option is not possible
346**
347** VdbeCoverageEqNe(v) // Previous OP_Jump is only interested
348** // in distingishing equal and not-equal.
349**
drh5655c542014-02-19 19:14:34 +0000350** Every VDBE branch operation must be tagged with one of the macros above.
351** If not, then when "make test" is run with -DSQLITE_VDBE_COVERAGE and
352** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch()
353** routine in vdbe.c, alerting the developer to the missed tag.
drh7083a482018-07-10 16:04:04 +0000354**
355** During testing, the test application will invoke
356** sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE,...) to set a callback
357** routine that is invoked as each bytecode branch is taken. The callback
358** contains the sqlite3.c source line number ov the VdbeCoverage macro and
359** flags to indicate whether or not the branch was taken. The test application
360** is responsible for keeping track of this and reporting byte-code branches
361** that are never taken.
362**
363** See the VdbeBranchTaken() macro and vdbeTakeBranch() function in the
364** vdbe.c source file for additional information.
drh5655c542014-02-19 19:14:34 +0000365*/
drh688852a2014-02-17 22:40:43 +0000366#ifdef SQLITE_VDBE_COVERAGE
367 void sqlite3VdbeSetLineNumber(Vdbe*,int);
368# define VdbeCoverage(v) sqlite3VdbeSetLineNumber(v,__LINE__)
369# define VdbeCoverageIf(v,x) if(x)sqlite3VdbeSetLineNumber(v,__LINE__)
drh7083a482018-07-10 16:04:04 +0000370# define VdbeCoverageAlwaysTaken(v) \
371 sqlite3VdbeSetLineNumber(v,__LINE__|0x5000000);
372# define VdbeCoverageNeverTaken(v) \
373 sqlite3VdbeSetLineNumber(v,__LINE__|0x6000000);
374# define VdbeCoverageNeverNull(v) \
375 sqlite3VdbeSetLineNumber(v,__LINE__|0x4000000);
drh6ccbd272018-07-10 17:10:44 +0000376# define VdbeCoverageNeverNullIf(v,x) \
377 if(x)sqlite3VdbeSetLineNumber(v,__LINE__|0x4000000);
drh7083a482018-07-10 16:04:04 +0000378# define VdbeCoverageEqNe(v) \
379 sqlite3VdbeSetLineNumber(v,__LINE__|0x8000000);
drhb06a4ec2014-03-10 18:03:09 +0000380# define VDBE_OFFSET_LINENO(x) (__LINE__+x)
drh688852a2014-02-17 22:40:43 +0000381#else
382# define VdbeCoverage(v)
383# define VdbeCoverageIf(v,x)
drh5655c542014-02-19 19:14:34 +0000384# define VdbeCoverageAlwaysTaken(v)
385# define VdbeCoverageNeverTaken(v)
drh7083a482018-07-10 16:04:04 +0000386# define VdbeCoverageNeverNull(v)
drh6ccbd272018-07-10 17:10:44 +0000387# define VdbeCoverageNeverNullIf(v,x)
drh7083a482018-07-10 16:04:04 +0000388# define VdbeCoverageEqNe(v)
drhb06a4ec2014-03-10 18:03:09 +0000389# define VDBE_OFFSET_LINENO(x) 0
drh688852a2014-02-17 22:40:43 +0000390#endif
391
dan6f9702e2014-11-01 20:38:06 +0000392#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
drh518140e2014-11-06 03:55:10 +0000393void sqlite3VdbeScanStatus(Vdbe*, int, int, int, LogEst, const char*);
danf6f01f12022-12-03 18:16:25 +0000394void sqlite3VdbeScanStatusRange(Vdbe*, int, int, int);
dana3d0c152022-12-05 18:19:56 +0000395void sqlite3VdbeScanStatusCounters(Vdbe*, int, int, int);
dan6f9702e2014-11-01 20:38:06 +0000396#else
dan231ff4b2022-12-02 20:32:22 +0000397# define sqlite3VdbeScanStatus(a,b,c,d,e,f)
danf6f01f12022-12-03 18:16:25 +0000398# define sqlite3VdbeScanStatusRange(a,b,c,d)
dana3d0c152022-12-05 18:19:56 +0000399# define sqlite3VdbeScanStatusCounters(a,b,c,d)
dan6f9702e2014-11-01 20:38:06 +0000400#endif
401
drh299bf7c2018-06-11 17:35:02 +0000402#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
403void sqlite3VdbePrintOp(FILE*, int, VdbeOp*);
404#endif
405
drh43f58d62016-07-09 16:14:45 +0000406#endif /* SQLITE_VDBE_H */