2
|
1 |
/*
|
|
2 |
** 2001 September 15
|
|
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 |
** 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.
|
|
17 |
**
|
|
18 |
** $Id: vdbe.h 1282 2008-11-13 09:31:33Z LarsPson $
|
|
19 |
*/
|
|
20 |
#ifndef _SQLITE_VDBE_H_
|
|
21 |
#define _SQLITE_VDBE_H_
|
|
22 |
#include <stdio.h>
|
|
23 |
|
|
24 |
/*
|
|
25 |
** A single VDBE is an opaque structure named "Vdbe". Only routines
|
|
26 |
** in the source file sqliteVdbe.c are allowed to see the insides
|
|
27 |
** of this structure.
|
|
28 |
*/
|
|
29 |
typedef struct Vdbe Vdbe;
|
|
30 |
|
|
31 |
/*
|
|
32 |
** A single instruction of the virtual machine has an opcode
|
|
33 |
** and as many as three operands. The instruction is recorded
|
|
34 |
** as an instance of the following structure:
|
|
35 |
*/
|
|
36 |
struct VdbeOp {
|
|
37 |
u8 opcode; /* What operation to perform */
|
|
38 |
int p1; /* First operand */
|
|
39 |
int p2; /* Second parameter (often the jump destination) */
|
|
40 |
char *p3; /* Third parameter */
|
|
41 |
int p3type; /* One of the P3_xxx constants defined below */
|
|
42 |
#ifdef VDBE_PROFILE
|
|
43 |
int cnt; /* Number of times this instruction was executed */
|
|
44 |
long long cycles; /* Total time spend executing this instruction */
|
|
45 |
#endif
|
|
46 |
};
|
|
47 |
typedef struct VdbeOp VdbeOp;
|
|
48 |
|
|
49 |
/*
|
|
50 |
** A smaller version of VdbeOp used for the VdbeAddOpList() function because
|
|
51 |
** it takes up less space.
|
|
52 |
*/
|
|
53 |
struct VdbeOpList {
|
|
54 |
u8 opcode; /* What operation to perform */
|
|
55 |
signed char p1; /* First operand */
|
|
56 |
short int p2; /* Second parameter (often the jump destination) */
|
|
57 |
char *p3; /* Third parameter */
|
|
58 |
};
|
|
59 |
typedef struct VdbeOpList VdbeOpList;
|
|
60 |
|
|
61 |
/*
|
|
62 |
** Allowed values of VdbeOp.p3type
|
|
63 |
*/
|
|
64 |
#define P3_NOTUSED 0 /* The P3 parameter is not used */
|
|
65 |
#define P3_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */
|
|
66 |
#define P3_STATIC (-2) /* Pointer to a static string */
|
|
67 |
#define P3_COLLSEQ (-4) /* P3 is a pointer to a CollSeq structure */
|
|
68 |
#define P3_FUNCDEF (-5) /* P3 is a pointer to a FuncDef structure */
|
|
69 |
#define P3_KEYINFO (-6) /* P3 is a pointer to a KeyInfo structure */
|
|
70 |
#define P3_VDBEFUNC (-7) /* P3 is a pointer to a VdbeFunc structure */
|
|
71 |
#define P3_MEM (-8) /* P3 is a pointer to a Mem* structure */
|
|
72 |
#define P3_TRANSIENT (-9) /* P3 is a pointer to a transient string */
|
|
73 |
#define P3_VTAB (-10) /* P3 is a pointer to an sqlite3_vtab structure */
|
|
74 |
#define P3_MPRINTF (-11) /* P3 is a string obtained from sqlite3_mprintf() */
|
|
75 |
#define P3_REAL (-12) /* P3 is a 64-bit floating point value */
|
|
76 |
#define P3_INT64 (-13) /* P3 is a 64-bit signed integer */
|
|
77 |
|
|
78 |
/* When adding a P3 argument using P3_KEYINFO, a copy of the KeyInfo structure
|
|
79 |
** is made. That copy is freed when the Vdbe is finalized. But if the
|
|
80 |
** argument is P3_KEYINFO_HANDOFF, the passed in pointer is used. It still
|
|
81 |
** gets freed when the Vdbe is finalized so it still should be obtained
|
|
82 |
** from a single sqliteMalloc(). But no copy is made and the calling
|
|
83 |
** function should *not* try to free the KeyInfo.
|
|
84 |
*/
|
|
85 |
#define P3_KEYINFO_HANDOFF (-9)
|
|
86 |
|
|
87 |
/*
|
|
88 |
** The Vdbe.aColName array contains 5n Mem structures, where n is the
|
|
89 |
** number of columns of data returned by the statement.
|
|
90 |
*/
|
|
91 |
#define COLNAME_NAME 0
|
|
92 |
#define COLNAME_DECLTYPE 1
|
|
93 |
#define COLNAME_DATABASE 2
|
|
94 |
#define COLNAME_TABLE 3
|
|
95 |
#define COLNAME_COLUMN 4
|
|
96 |
#define COLNAME_N 5 /* Number of COLNAME_xxx symbols */
|
|
97 |
|
|
98 |
/*
|
|
99 |
** The following macro converts a relative address in the p2 field
|
|
100 |
** of a VdbeOp structure into a negative number so that
|
|
101 |
** sqlite3VdbeAddOpList() knows that the address is relative. Calling
|
|
102 |
** the macro again restores the address.
|
|
103 |
*/
|
|
104 |
#define ADDR(X) (-1-(X))
|
|
105 |
|
|
106 |
/*
|
|
107 |
** The makefile scans the vdbe.c source file and creates the "opcodes.h"
|
|
108 |
** header file that defines a number for each opcode used by the VDBE.
|
|
109 |
*/
|
|
110 |
#include "opcodes.h"
|
|
111 |
|
|
112 |
/*
|
|
113 |
** Prototypes for the VDBE interface. See comments on the implementation
|
|
114 |
** for a description of what each of these routines does.
|
|
115 |
*/
|
|
116 |
Vdbe *sqlite3VdbeCreate(sqlite3*);
|
|
117 |
int sqlite3VdbeAddOp(Vdbe*,int,int,int);
|
|
118 |
int sqlite3VdbeOp3(Vdbe*,int,int,int,const char *zP3,int);
|
|
119 |
int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
|
|
120 |
void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
|
|
121 |
void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
|
|
122 |
void sqlite3VdbeJumpHere(Vdbe*, int addr);
|
|
123 |
void sqlite3VdbeChangeToNoop(Vdbe*, int addr, int N);
|
|
124 |
void sqlite3VdbeChangeP3(Vdbe*, int addr, const char *zP1, int N);
|
|
125 |
void sqlite3VdbeUsesBtree(Vdbe*, int);
|
|
126 |
VdbeOp *sqlite3VdbeGetOp(Vdbe*, int);
|
|
127 |
int sqlite3VdbeMakeLabel(Vdbe*);
|
|
128 |
void sqlite3VdbeDelete(Vdbe*);
|
|
129 |
void sqlite3VdbeMakeReady(Vdbe*,int,int,int,int);
|
|
130 |
int sqlite3VdbeFinalize(Vdbe*);
|
|
131 |
void sqlite3VdbeResolveLabel(Vdbe*, int);
|
|
132 |
int sqlite3VdbeCurrentAddr(Vdbe*);
|
|
133 |
#ifdef SQLITE_DEBUG
|
|
134 |
void sqlite3VdbeTrace(Vdbe*,FILE*);
|
|
135 |
#endif
|
|
136 |
void sqlite3VdbeResetStepResult(Vdbe*);
|
|
137 |
int sqlite3VdbeReset(Vdbe*);
|
|
138 |
void sqlite3VdbeSetNumCols(Vdbe*,int);
|
|
139 |
int sqlite3VdbeSetColName(Vdbe*, int, int, const char *, int);
|
|
140 |
void sqlite3VdbeCountChanges(Vdbe*);
|
|
141 |
sqlite3 *sqlite3VdbeDb(Vdbe*);
|
|
142 |
void sqlite3VdbeSetSql(Vdbe*, const char *z, int n);
|
|
143 |
void sqlite3VdbeSwap(Vdbe*,Vdbe*);
|
|
144 |
|
|
145 |
#ifndef NDEBUG
|
|
146 |
void sqlite3VdbeComment(Vdbe*, const char*, ...);
|
|
147 |
# define VdbeComment(X) sqlite3VdbeComment X
|
|
148 |
#else
|
|
149 |
# define VdbeComment(X)
|
|
150 |
#endif
|
|
151 |
|
|
152 |
#endif
|