Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: third_party/sqlite/src/src/vdbeInt.h

Issue 2751253002: [sql] Import SQLite 3.17.0. (Closed)
Patch Set: also clang on Linux i386 Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/sqlite/src/src/vdbe.c ('k') | third_party/sqlite/src/src/vdbeapi.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 ** 2003 September 6 2 ** 2003 September 6
3 ** 3 **
4 ** The author disclaims copyright to this source code. In place of 4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing: 5 ** a legal notice, here is a blessing:
6 ** 6 **
7 ** May you do good and not evil. 7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others. 8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give. 9 ** May you share freely, never taking more than you give.
10 ** 10 **
11 ************************************************************************* 11 *************************************************************************
12 ** This is the header file for information that is private to the 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 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 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 15 ** 6000 lines long) it was split up into several smaller files and
16 ** this header information was factored out. 16 ** this header information was factored out.
17 */ 17 */
18 #ifndef _VDBEINT_H_ 18 #ifndef SQLITE_VDBEINT_H
19 #define _VDBEINT_H_ 19 #define SQLITE_VDBEINT_H
20 20
21 /* 21 /*
22 ** The maximum number of times that a statement will try to reparse 22 ** The maximum number of times that a statement will try to reparse
23 ** itself before giving up and returning SQLITE_SCHEMA. 23 ** itself before giving up and returning SQLITE_SCHEMA.
24 */ 24 */
25 #ifndef SQLITE_MAX_SCHEMA_RETRY 25 #ifndef SQLITE_MAX_SCHEMA_RETRY
26 # define SQLITE_MAX_SCHEMA_RETRY 50 26 # define SQLITE_MAX_SCHEMA_RETRY 50
27 #endif 27 #endif
28 28
29 /* 29 /*
(...skipping 15 matching lines...) Expand all
45 typedef struct VdbeOp Op; 45 typedef struct VdbeOp Op;
46 46
47 /* 47 /*
48 ** Boolean values 48 ** Boolean values
49 */ 49 */
50 typedef unsigned Bool; 50 typedef unsigned Bool;
51 51
52 /* Opaque type used by code in vdbesort.c */ 52 /* Opaque type used by code in vdbesort.c */
53 typedef struct VdbeSorter VdbeSorter; 53 typedef struct VdbeSorter VdbeSorter;
54 54
55 /* Opaque type used by the explainer */
56 typedef struct Explain Explain;
57
58 /* Elements of the linked list at Vdbe.pAuxData */ 55 /* Elements of the linked list at Vdbe.pAuxData */
59 typedef struct AuxData AuxData; 56 typedef struct AuxData AuxData;
60 57
61 /* Types of VDBE cursors */ 58 /* Types of VDBE cursors */
62 #define CURTYPE_BTREE 0 59 #define CURTYPE_BTREE 0
63 #define CURTYPE_SORTER 1 60 #define CURTYPE_SORTER 1
64 #define CURTYPE_VTAB 2 61 #define CURTYPE_VTAB 2
65 #define CURTYPE_PSEUDO 3 62 #define CURTYPE_PSEUDO 3
66 63
67 /* 64 /*
68 ** A VdbeCursor is an superclass (a wrapper) for various cursor objects: 65 ** A VdbeCursor is an superclass (a wrapper) for various cursor objects:
69 ** 66 **
70 ** * A b-tree cursor 67 ** * A b-tree cursor
71 ** - In the main database or in an ephemeral database 68 ** - In the main database or in an ephemeral database
72 ** - On either an index or a table 69 ** - On either an index or a table
73 ** * A sorter 70 ** * A sorter
74 ** * A virtual table 71 ** * A virtual table
75 ** * A one-row "pseudotable" stored in a single register 72 ** * A one-row "pseudotable" stored in a single register
76 */ 73 */
74 typedef struct VdbeCursor VdbeCursor;
77 struct VdbeCursor { 75 struct VdbeCursor {
78 u8 eCurType; /* One of the CURTYPE_* values above */ 76 u8 eCurType; /* One of the CURTYPE_* values above */
79 i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */ 77 i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
80 u8 nullRow; /* True if pointing to a row with no data */ 78 u8 nullRow; /* True if pointing to a row with no data */
81 u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */ 79 u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
82 u8 isTable; /* True for rowid tables. False for indexes */ 80 u8 isTable; /* True for rowid tables. False for indexes */
83 #ifdef SQLITE_DEBUG 81 #ifdef SQLITE_DEBUG
84 u8 seekOp; /* Most recent seek operation on this cursor */ 82 u8 seekOp; /* Most recent seek operation on this cursor */
83 u8 wrFlag; /* The wrFlag argument to sqlite3BtreeCursor() */
85 #endif 84 #endif
86 Bool isEphemeral:1; /* True for an ephemeral table */ 85 Bool isEphemeral:1; /* True for an ephemeral table */
87 Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */ 86 Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */
88 Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */ 87 Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */
89 Pgno pgnoRoot; /* Root page of the open btree cursor */ 88 Btree *pBtx; /* Separate file holding temporary table */
90 i16 nField; /* Number of fields in the header */ 89 i64 seqCount; /* Sequence counter */
91 u16 nHdrParsed; /* Number of header fields parsed so far */ 90 int *aAltMap; /* Mapping from table to index column numbers */
91
92 /* Cached OP_Column parse information is only valid if cacheStatus matches
93 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
94 ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
95 ** the cache is out of date. */
96 u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
97 int seekResult; /* Result of previous sqlite3BtreeMoveto() or 0
98 ** if there have been no prior seeks on the cursor. */
99 /* NB: seekResult does not distinguish between "no seeks have ever occurred
100 ** on this cursor" and "the most recent seek was an exact match". */
101
102 /* When a new VdbeCursor is allocated, only the fields above are zeroed.
103 ** The fields that follow are uninitialized, and must be individually
104 ** initialized prior to first use. */
105 VdbeCursor *pAltCursor; /* Associated index cursor from which to read */
92 union { 106 union {
93 BtCursor *pCursor; /* CURTYPE_BTREE. Btree cursor */ 107 BtCursor *pCursor; /* CURTYPE_BTREE. Btree cursor */
94 sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB. Vtab cursor */ 108 sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB. Vtab cursor */
95 int pseudoTableReg; /* CURTYPE_PSEUDO. Reg holding content. */ 109 int pseudoTableReg; /* CURTYPE_PSEUDO. Reg holding content. */
96 VdbeSorter *pSorter; /* CURTYPE_SORTER. Sorter object */ 110 VdbeSorter *pSorter; /* CURTYPE_SORTER. Sorter object */
97 } uc; 111 } uc;
98 Btree *pBt; /* Separate file holding temporary table */ 112 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
99 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */ 113 u32 iHdrOffset; /* Offset to next unparsed byte of the header */
100 int seekResult; /* Result of previous sqlite3BtreeMoveto() */ 114 Pgno pgnoRoot; /* Root page of the open btree cursor */
101 i64 seqCount; /* Sequence counter */ 115 i16 nField; /* Number of fields in the header */
102 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */ 116 u16 nHdrParsed; /* Number of header fields parsed so far */
117 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
118 u32 *aOffset; /* Pointer to aType[nField] */
119 const u8 *aRow; /* Data for the current row, if all on one page */
120 u32 payloadSize; /* Total number of bytes in the record */
121 u32 szRow; /* Byte available in aRow */
103 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK 122 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
104 u64 maskUsed; /* Mask of columns used by this cursor */ 123 u64 maskUsed; /* Mask of columns used by this cursor */
105 #endif 124 #endif
106 125
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 126 /* 2*nField extra array elements allocated for aType[], beyond the one
124 ** static element declared in the structure. nField total array slots for 127 ** static element declared in the structure. nField total array slots for
125 ** aType[] and nField+1 array slots for aOffset[] */ 128 ** aType[] and nField+1 array slots for aOffset[] */
129 u32 aType[1]; /* Type values record decode. MUST BE LAST */
126 }; 130 };
127 typedef struct VdbeCursor VdbeCursor; 131
132
133 /*
134 ** A value for VdbeCursor.cacheStatus that means the cache is always invalid.
135 */
136 #define CACHE_STALE 0
128 137
129 /* 138 /*
130 ** When a sub-program is executed (OP_Program), a structure of this type 139 ** 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 140 ** 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 141 ** 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, 142 ** 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, 143 ** 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 144 ** restoring the state of the VM to as it was before the sub-program
136 ** began executing. 145 ** began executing.
137 ** 146 **
138 ** The memory for a VdbeFrame object is allocated and managed by a memory 147 ** 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 148 ** cell in the parent (calling) frame. When the memory cell is deleted or
140 ** overwritten, the VdbeFrame object is not freed immediately. Instead, it 149 ** overwritten, the VdbeFrame object is not freed immediately. Instead, it
141 ** is linked into the Vdbe.pDelFrame list. The contents of the Vdbe.pDelFrame 150 ** 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 151 ** 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 152 ** this instead of deleting the VdbeFrame immediately is to avoid recursive
144 ** calls to sqlite3VdbeMemRelease() when the memory cells belonging to the 153 ** calls to sqlite3VdbeMemRelease() when the memory cells belonging to the
145 ** child frame are released. 154 ** child frame are released.
146 ** 155 **
147 ** The currently executing frame is stored in Vdbe.pFrame. Vdbe.pFrame is 156 ** 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. 157 ** set to NULL if the currently executing frame is the main program.
149 */ 158 */
150 typedef struct VdbeFrame VdbeFrame; 159 typedef struct VdbeFrame VdbeFrame;
151 struct VdbeFrame { 160 struct VdbeFrame {
152 Vdbe *v; /* VM this frame belongs to */ 161 Vdbe *v; /* VM this frame belongs to */
153 VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */ 162 VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */
154 Op *aOp; /* Program instructions for parent frame */ 163 Op *aOp; /* Program instructions for parent frame */
155 i64 *anExec; /* Event counters from parent frame */ 164 i64 *anExec; /* Event counters from parent frame */
156 Mem *aMem; /* Array of memory cells for parent frame */ 165 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 */ 166 VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */
159 void *token; /* Copy of SubProgram.token */ 167 void *token; /* Copy of SubProgram.token */
160 i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */ 168 i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
169 AuxData *pAuxData; /* Linked list of auxdata allocations */
161 int nCursor; /* Number of entries in apCsr */ 170 int nCursor; /* Number of entries in apCsr */
162 int pc; /* Program Counter in parent (calling) frame */ 171 int pc; /* Program Counter in parent (calling) frame */
163 int nOp; /* Size of aOp array */ 172 int nOp; /* Size of aOp array */
164 int nMem; /* Number of entries in aMem */ 173 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 */ 174 int nChildMem; /* Number of memory cells for child frame */
167 int nChildCsr; /* Number of cursors for child frame */ 175 int nChildCsr; /* Number of cursors for child frame */
168 int nChange; /* Statement changes (Vdbe.nChange) */ 176 int nChange; /* Statement changes (Vdbe.nChange) */
169 int nDbChange; /* Value of db->nChange */ 177 int nDbChange; /* Value of db->nChange */
170 }; 178 };
171 179
172 #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))]) 180 #define VdbeFrameMem(p) ((Mem *)&((u8 *)p)[ROUND8(sizeof(VdbeFrame))])
173 181
174 /* 182 /*
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 183 ** Internally, the vdbe manipulates nearly all SQL values as Mem
181 ** structures. Each Mem struct may cache multiple representations (string, 184 ** structures. Each Mem struct may cache multiple representations (string,
182 ** integer etc.) of the same value. 185 ** integer etc.) of the same value.
183 */ 186 */
184 struct Mem { 187 struct Mem {
185 union MemValue { 188 union MemValue {
186 double r; /* Real value used when MEM_Real is set in flags */ 189 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 */ 190 i64 i; /* Integer value used when MEM_Int is set in flags */
188 int nZero; /* Used when bit MEM_Zero is set in flags */ 191 int nZero; /* Used when bit MEM_Zero is set in flags */
189 FuncDef *pDef; /* Used only when flags==MEM_Agg */ 192 FuncDef *pDef; /* Used only when flags==MEM_Agg */
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 #define MEM_Null 0x0001 /* Value is NULL */ 231 #define MEM_Null 0x0001 /* Value is NULL */
229 #define MEM_Str 0x0002 /* Value is a string */ 232 #define MEM_Str 0x0002 /* Value is a string */
230 #define MEM_Int 0x0004 /* Value is an integer */ 233 #define MEM_Int 0x0004 /* Value is an integer */
231 #define MEM_Real 0x0008 /* Value is a real number */ 234 #define MEM_Real 0x0008 /* Value is a real number */
232 #define MEM_Blob 0x0010 /* Value is a BLOB */ 235 #define MEM_Blob 0x0010 /* Value is a BLOB */
233 #define MEM_AffMask 0x001f /* Mask of affinity bits */ 236 #define MEM_AffMask 0x001f /* Mask of affinity bits */
234 #define MEM_RowSet 0x0020 /* Value is a RowSet object */ 237 #define MEM_RowSet 0x0020 /* Value is a RowSet object */
235 #define MEM_Frame 0x0040 /* Value is a VdbeFrame object */ 238 #define MEM_Frame 0x0040 /* Value is a VdbeFrame object */
236 #define MEM_Undefined 0x0080 /* Value is undefined */ 239 #define MEM_Undefined 0x0080 /* Value is undefined */
237 #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */ 240 #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */
238 #define MEM_TypeMask 0x01ff /* Mask of type bits */ 241 #define MEM_TypeMask 0x81ff /* Mask of type bits */
239 242
240 243
241 /* Whenever Mem contains a valid string or blob representation, one of 244 /* Whenever Mem contains a valid string or blob representation, one of
242 ** the following flags must be set to determine the memory management 245 ** 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 246 ** policy for Mem.z. The MEM_Term flag tells us whether or not the
244 ** string is \000 or \u0000 terminated 247 ** string is \000 or \u0000 terminated
245 */ 248 */
246 #define MEM_Term 0x0200 /* String rep is nul terminated */ 249 #define MEM_Term 0x0200 /* String rep is nul terminated */
247 #define MEM_Dyn 0x0400 /* Need to call Mem.xDel() on Mem.z */ 250 #define MEM_Dyn 0x0400 /* Need to call Mem.xDel() on Mem.z */
248 #define MEM_Static 0x0800 /* Mem.z points to a static string */ 251 #define MEM_Static 0x0800 /* Mem.z points to a static string */
249 #define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */ 252 #define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
250 #define MEM_Agg 0x2000 /* Mem.z points to an agg function context */ 253 #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 */ 254 #define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
255 #define MEM_Subtype 0x8000 /* Mem.eSubtype is valid */
252 #ifdef SQLITE_OMIT_INCRBLOB 256 #ifdef SQLITE_OMIT_INCRBLOB
253 #undef MEM_Zero 257 #undef MEM_Zero
254 #define MEM_Zero 0x0000 258 #define MEM_Zero 0x0000
255 #endif 259 #endif
256 260
261 /* Return TRUE if Mem X contains dynamically allocated content - anything
262 ** that needs to be deallocated to avoid a leak.
263 */
264 #define VdbeMemDynamic(X) \
265 (((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame))!=0)
266
257 /* 267 /*
258 ** Clear any existing type flags from a Mem and replace them with f 268 ** Clear any existing type flags from a Mem and replace them with f
259 */ 269 */
260 #define MemSetTypeFlag(p, f) \ 270 #define MemSetTypeFlag(p, f) \
261 ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f) 271 ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)
262 272
263 /* 273 /*
264 ** Return true if a memory cell is not marked as invalid. This macro 274 ** Return true if a memory cell is not marked as invalid. This macro
265 ** is for use inside assert() statements only. 275 ** is for use inside assert() statements only.
266 */ 276 */
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 Mem *pMem; /* Memory cell used to store aggregate context */ 312 Mem *pMem; /* Memory cell used to store aggregate context */
303 Vdbe *pVdbe; /* The VM that owns this context */ 313 Vdbe *pVdbe; /* The VM that owns this context */
304 int iOp; /* Instruction number of OP_Function */ 314 int iOp; /* Instruction number of OP_Function */
305 int isError; /* Error code returned by the function. */ 315 int isError; /* Error code returned by the function. */
306 u8 skipFlag; /* Skip accumulator loading if true */ 316 u8 skipFlag; /* Skip accumulator loading if true */
307 u8 fErrorOrAux; /* isError!=0 or pVdbe->pAuxData modified */ 317 u8 fErrorOrAux; /* isError!=0 or pVdbe->pAuxData modified */
308 u8 argc; /* Number of arguments */ 318 u8 argc; /* Number of arguments */
309 sqlite3_value *argv[1]; /* Argument set */ 319 sqlite3_value *argv[1]; /* Argument set */
310 }; 320 };
311 321
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 322 /* A bitfield type for use inside of structures. Always follow with :N where
325 ** N is the number of bits. 323 ** N is the number of bits.
326 */ 324 */
327 typedef unsigned bft; /* Bit Field Type */ 325 typedef unsigned bft; /* Bit Field Type */
328 326
329 typedef struct ScanStatus ScanStatus; 327 typedef struct ScanStatus ScanStatus;
330 struct ScanStatus { 328 struct ScanStatus {
331 int addrExplain; /* OP_Explain for loop */ 329 int addrExplain; /* OP_Explain for loop */
332 int addrLoop; /* Address of "loops" counter */ 330 int addrLoop; /* Address of "loops" counter */
333 int addrVisit; /* Address of "rows visited" counter */ 331 int addrVisit; /* Address of "rows visited" counter */
334 int iSelectID; /* The "Select-ID" for this loop */ 332 int iSelectID; /* The "Select-ID" for this loop */
335 LogEst nEst; /* Estimated output rows per loop */ 333 LogEst nEst; /* Estimated output rows per loop */
336 char *zName; /* Name of table or index */ 334 char *zName; /* Name of table or index */
337 }; 335 };
338 336
339 /* 337 /*
340 ** An instance of the virtual machine. This structure contains the complete 338 ** An instance of the virtual machine. This structure contains the complete
341 ** state of the virtual machine. 339 ** state of the virtual machine.
342 ** 340 **
343 ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare() 341 ** The "sqlite3_stmt" structure pointer that is returned by sqlite3_prepare()
344 ** is really a pointer to an instance of this structure. 342 ** is really a pointer to an instance of this structure.
345 */ 343 */
346 struct Vdbe { 344 struct Vdbe {
347 sqlite3 *db; /* The database connection that owns this statement */ 345 sqlite3 *db; /* The database connection that owns this statement */
346 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
347 Parse *pParse; /* Parsing context used to create this Vdbe */
348 ynVar nVar; /* Number of entries in aVar[] */
349 u32 magic; /* Magic number for sanity checking */
350 int nMem; /* Number of memory locations currently allocated */
351 int nCursor; /* Number of slots in apCsr[] */
352 u32 cacheCtr; /* VdbeCursor row cache generation counter */
353 int pc; /* The program counter */
354 int rc; /* Value to return */
355 int nChange; /* Number of db changes made since last reset */
356 int iStatement; /* Statement number (or 0 if has not opened stmt) */
357 i64 iCurrentTime; /* Value of julianday('now') for this statement */
358 i64 nFkConstraint; /* Number of imm. FK constraints this VM */
359 i64 nStmtDefCons; /* Number of def. constraints when stmt started */
360 i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
361
362 /* When allocating a new Vdbe object, all of the fields below should be
363 ** initialized to zero or NULL */
364
348 Op *aOp; /* Space to hold the virtual machine's program */ 365 Op *aOp; /* Space to hold the virtual machine's program */
349 Mem *aMem; /* The memory locations */ 366 Mem *aMem; /* The memory locations */
350 Mem **apArg; /* Arguments to currently executing user function */ 367 Mem **apArg; /* Arguments to currently executing user function */
351 Mem *aColName; /* Column names to return */ 368 Mem *aColName; /* Column names to return */
352 Mem *pResultSet; /* Pointer to an array of results */ 369 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 */ 370 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 */ 371 VdbeCursor **apCsr; /* One element of this array for each open cursor */
361 Mem *aVar; /* Values for the OP_Variable opcode. */ 372 Mem *aVar; /* Values for the OP_Variable opcode. */
362 char **azVar; /* Name of variables */ 373 VList *pVList; /* Name of variables */
363 ynVar nVar; /* Number of entries in aVar[] */ 374 #ifndef SQLITE_OMIT_TRACE
364 ynVar nzVar; /* Number of entries in azVar[] */ 375 i64 startTime; /* Time when query started - used for profiling */
365 u32 cacheCtr; /* VdbeCursor row cache generation counter */ 376 #endif
366 int pc; /* The program counter */ 377 int nOp; /* Number of instructions in the program */
367 int rc; /* Value to return */
368 #ifdef SQLITE_DEBUG 378 #ifdef SQLITE_DEBUG
369 int rcApp; /* errcode set by sqlite3_result_error_code() */ 379 int rcApp; /* errcode set by sqlite3_result_error_code() */
370 #endif 380 #endif
371 u16 nResColumn; /* Number of columns in one row of the result set */ 381 u16 nResColumn; /* Number of columns in one row of the result set */
372 u8 errorAction; /* Recovery action to do in case of an error */ 382 u8 errorAction; /* Recovery action to do in case of an error */
373 u8 minWriteFileFormat; /* Minimum file format for writable database files */ 383 u8 minWriteFileFormat; /* Minimum file format for writable database files */
384 bft expired:1; /* True if the VM needs to be recompiled */
385 bft doingRerun:1; /* True if rerunning after an auto-reprepare */
374 bft explain:2; /* True if EXPLAIN present on SQL command */ 386 bft explain:2; /* True if EXPLAIN present on SQL command */
375 bft changeCntOn:1; /* True to update the change-counter */ 387 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 */ 388 bft runOnlyOnce:1; /* Automatically expire on reset */
378 bft usesStmtJournal:1; /* True if uses a statement journal */ 389 bft usesStmtJournal:1; /* True if uses a statement journal */
379 bft readOnly:1; /* True for statements that do not write */ 390 bft readOnly:1; /* True for statements that do not write */
380 bft bIsReader:1; /* True for statements that read */ 391 bft bIsReader:1; /* True for statements that read */
381 bft isPrepareV2:1; /* True if prepared with prepare_v2() */ 392 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 */ 393 yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
385 yDbMask lockMask; /* Subset of btreeMask that requires a lock */ 394 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() */ 395 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 char *zSql; /* Text of the SQL statement that generated this */
396 void *pFree; /* Free this when deleting the vdbe */ 397 void *pFree; /* Free this when deleting the vdbe */
397 VdbeFrame *pFrame; /* Parent frame */ 398 VdbeFrame *pFrame; /* Parent frame */
398 VdbeFrame *pDelFrame; /* List of frame objects to free on VM reset */ 399 VdbeFrame *pDelFrame; /* List of frame objects to free on VM reset */
399 int nFrame; /* Number of frames in pFrame list */ 400 int nFrame; /* Number of frames in pFrame list */
400 u32 expmask; /* Binding to these vars invalidates VM */ 401 u32 expmask; /* Binding to these vars invalidates VM */
401 SubProgram *pProgram; /* Linked list of all sub-programs used by VM */ 402 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 */ 403 AuxData *pAuxData; /* Linked list of auxdata allocations */
405 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS 404 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
406 i64 *anExec; /* Number of times each op has been executed */ 405 i64 *anExec; /* Number of times each op has been executed */
407 int nScan; /* Entries in aScan[] */ 406 int nScan; /* Entries in aScan[] */
408 ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */ 407 ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */
409 #endif 408 #endif
410 }; 409 };
411 410
412 /* 411 /*
413 ** The following are allowed values for Vdbe.magic 412 ** The following are allowed values for Vdbe.magic
414 */ 413 */
415 #define VDBE_MAGIC_INIT 0x26bceaa5 /* Building a VDBE program */ 414 #define VDBE_MAGIC_INIT 0x16bceaa5 /* Building a VDBE program */
416 #define VDBE_MAGIC_RUN 0xbdf20da3 /* VDBE is ready to execute */ 415 #define VDBE_MAGIC_RUN 0x2df20da3 /* VDBE is ready to execute */
417 #define VDBE_MAGIC_HALT 0x519c2973 /* VDBE has completed execution */ 416 #define VDBE_MAGIC_HALT 0x319c2973 /* VDBE has completed execution */
418 #define VDBE_MAGIC_DEAD 0xb606c3c8 /* The VDBE has been deallocated */ 417 #define VDBE_MAGIC_RESET 0x48fa9f76 /* Reset and ready to run again */
418 #define VDBE_MAGIC_DEAD 0x5606c3c8 /* The VDBE has been deallocated */
419
420 /*
421 ** Structure used to store the context required by the
422 ** sqlite3_preupdate_*() API functions.
423 */
424 struct PreUpdate {
425 Vdbe *v;
426 VdbeCursor *pCsr; /* Cursor to read old values from */
427 int op; /* One of SQLITE_INSERT, UPDATE, DELETE */
428 u8 *aRecord; /* old.* database record */
429 KeyInfo keyinfo;
430 UnpackedRecord *pUnpacked; /* Unpacked version of aRecord[] */
431 UnpackedRecord *pNewUnpacked; /* Unpacked version of new.* record */
432 int iNewReg; /* Register for new.* values */
433 i64 iKey1; /* First key value passed to hook */
434 i64 iKey2; /* Second key value passed to hook */
435 Mem *aNew; /* Array of new.* values */
436 Table *pTab; /* Schema object being upated */
437 Index *pPk; /* PK index if pTab is WITHOUT ROWID */
438 };
419 439
420 /* 440 /*
421 ** Function prototypes 441 ** Function prototypes
422 */ 442 */
423 void sqlite3VdbeError(Vdbe*, const char *, ...); 443 void sqlite3VdbeError(Vdbe*, const char *, ...);
424 void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*); 444 void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*);
425 void sqliteVdbePopStack(Vdbe*,int); 445 void sqliteVdbePopStack(Vdbe*,int);
426 int sqlite3VdbeCursorMoveto(VdbeCursor*); 446 int sqlite3VdbeCursorMoveto(VdbeCursor**, int*);
427 int sqlite3VdbeCursorRestore(VdbeCursor*); 447 int sqlite3VdbeCursorRestore(VdbeCursor*);
428 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) 448 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
429 void sqlite3VdbePrintOp(FILE*, int, Op*); 449 void sqlite3VdbePrintOp(FILE*, int, Op*);
430 #endif 450 #endif
431 u32 sqlite3VdbeSerialTypeLen(u32); 451 u32 sqlite3VdbeSerialTypeLen(u32);
432 u8 sqlite3VdbeOneByteSerialTypeLen(u8); 452 u8 sqlite3VdbeOneByteSerialTypeLen(u8);
433 u32 sqlite3VdbeSerialType(Mem*, int, u32*); 453 u32 sqlite3VdbeSerialType(Mem*, int, u32*);
434 u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32); 454 u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32);
435 u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); 455 u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
436 void sqlite3VdbeDeleteAuxData(Vdbe*, int, int); 456 void sqlite3VdbeDeleteAuxData(sqlite3*, AuxData**, int, int);
437 457
438 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *); 458 int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
439 int sqlite3VdbeIdxKeyCompare(sqlite3*,VdbeCursor*,UnpackedRecord*,int*); 459 int sqlite3VdbeIdxKeyCompare(sqlite3*,VdbeCursor*,UnpackedRecord*,int*);
440 int sqlite3VdbeIdxRowid(sqlite3*, BtCursor*, i64*); 460 int sqlite3VdbeIdxRowid(sqlite3*, BtCursor*, i64*);
441 int sqlite3VdbeExec(Vdbe*); 461 int sqlite3VdbeExec(Vdbe*);
442 int sqlite3VdbeList(Vdbe*); 462 int sqlite3VdbeList(Vdbe*);
443 int sqlite3VdbeHalt(Vdbe*); 463 int sqlite3VdbeHalt(Vdbe*);
444 int sqlite3VdbeChangeEncoding(Mem *, int); 464 int sqlite3VdbeChangeEncoding(Mem *, int);
445 int sqlite3VdbeMemTooBig(Mem*); 465 int sqlite3VdbeMemTooBig(Mem*);
446 int sqlite3VdbeMemCopy(Mem*, const Mem*); 466 int sqlite3VdbeMemCopy(Mem*, const Mem*);
(...skipping 13 matching lines...) Expand all
460 void sqlite3VdbeMemSetRowSet(Mem*); 480 void sqlite3VdbeMemSetRowSet(Mem*);
461 int sqlite3VdbeMemMakeWriteable(Mem*); 481 int sqlite3VdbeMemMakeWriteable(Mem*);
462 int sqlite3VdbeMemStringify(Mem*, u8, u8); 482 int sqlite3VdbeMemStringify(Mem*, u8, u8);
463 i64 sqlite3VdbeIntValue(Mem*); 483 i64 sqlite3VdbeIntValue(Mem*);
464 int sqlite3VdbeMemIntegerify(Mem*); 484 int sqlite3VdbeMemIntegerify(Mem*);
465 double sqlite3VdbeRealValue(Mem*); 485 double sqlite3VdbeRealValue(Mem*);
466 void sqlite3VdbeIntegerAffinity(Mem*); 486 void sqlite3VdbeIntegerAffinity(Mem*);
467 int sqlite3VdbeMemRealify(Mem*); 487 int sqlite3VdbeMemRealify(Mem*);
468 int sqlite3VdbeMemNumerify(Mem*); 488 int sqlite3VdbeMemNumerify(Mem*);
469 void sqlite3VdbeMemCast(Mem*,u8,u8); 489 void sqlite3VdbeMemCast(Mem*,u8,u8);
470 int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*); 490 int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*);
471 void sqlite3VdbeMemRelease(Mem *p); 491 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*); 492 int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
475 const char *sqlite3OpcodeName(int); 493 const char *sqlite3OpcodeName(int);
476 int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve); 494 int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
477 int sqlite3VdbeMemClearAndResize(Mem *pMem, int n); 495 int sqlite3VdbeMemClearAndResize(Mem *pMem, int n);
478 int sqlite3VdbeCloseStatement(Vdbe *, int); 496 int sqlite3VdbeCloseStatement(Vdbe *, int);
479 void sqlite3VdbeFrameDelete(VdbeFrame*); 497 void sqlite3VdbeFrameDelete(VdbeFrame*);
480 int sqlite3VdbeFrameRestore(VdbeFrame *); 498 int sqlite3VdbeFrameRestore(VdbeFrame *);
499 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
500 void sqlite3VdbePreUpdateHook(Vdbe*,VdbeCursor*,int,const char*,Table*,i64,int);
501 #endif
481 int sqlite3VdbeTransferError(Vdbe *p); 502 int sqlite3VdbeTransferError(Vdbe *p);
482 503
483 int sqlite3VdbeSorterInit(sqlite3 *, int, VdbeCursor *); 504 int sqlite3VdbeSorterInit(sqlite3 *, int, VdbeCursor *);
484 void sqlite3VdbeSorterReset(sqlite3 *, VdbeSorter *); 505 void sqlite3VdbeSorterReset(sqlite3 *, VdbeSorter *);
485 void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *); 506 void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);
486 int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *); 507 int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *);
487 int sqlite3VdbeSorterNext(sqlite3 *, const VdbeCursor *, int *); 508 int sqlite3VdbeSorterNext(sqlite3 *, const VdbeCursor *, int *);
488 int sqlite3VdbeSorterRewind(const VdbeCursor *, int *); 509 int sqlite3VdbeSorterRewind(const VdbeCursor *, int *);
489 int sqlite3VdbeSorterWrite(const VdbeCursor *, Mem *); 510 int sqlite3VdbeSorterWrite(const VdbeCursor *, Mem *);
490 int sqlite3VdbeSorterCompare(const VdbeCursor *, Mem *, int, int *); 511 int sqlite3VdbeSorterCompare(const VdbeCursor *, Mem *, int, int *);
491 512
513 #if !defined(SQLITE_OMIT_SHARED_CACHE)
514 void sqlite3VdbeEnter(Vdbe*);
515 #else
516 # define sqlite3VdbeEnter(X)
517 #endif
518
492 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0 519 #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
493 void sqlite3VdbeEnter(Vdbe*);
494 void sqlite3VdbeLeave(Vdbe*); 520 void sqlite3VdbeLeave(Vdbe*);
495 #else 521 #else
496 # define sqlite3VdbeEnter(X)
497 # define sqlite3VdbeLeave(X) 522 # define sqlite3VdbeLeave(X)
498 #endif 523 #endif
499 524
500 #ifdef SQLITE_DEBUG 525 #ifdef SQLITE_DEBUG
501 void sqlite3VdbeMemAboutToChange(Vdbe*,Mem*); 526 void sqlite3VdbeMemAboutToChange(Vdbe*,Mem*);
502 int sqlite3VdbeCheckMemInvariants(Mem*); 527 int sqlite3VdbeCheckMemInvariants(Mem*);
503 #endif 528 #endif
504 529
505 #ifndef SQLITE_OMIT_FOREIGN_KEY 530 #ifndef SQLITE_OMIT_FOREIGN_KEY
506 int sqlite3VdbeCheckFk(Vdbe *, int); 531 int sqlite3VdbeCheckFk(Vdbe *, int);
507 #else 532 #else
508 # define sqlite3VdbeCheckFk(p,i) 0 533 # define sqlite3VdbeCheckFk(p,i) 0
509 #endif 534 #endif
510 535
511 int sqlite3VdbeMemTranslate(Mem*, u8); 536 int sqlite3VdbeMemTranslate(Mem*, u8);
512 #ifdef SQLITE_DEBUG 537 #ifdef SQLITE_DEBUG
513 void sqlite3VdbePrintSql(Vdbe*); 538 void sqlite3VdbePrintSql(Vdbe*);
514 void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf); 539 void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf);
515 #endif 540 #endif
516 int sqlite3VdbeMemHandleBom(Mem *pMem); 541 int sqlite3VdbeMemHandleBom(Mem *pMem);
517 542
518 #ifndef SQLITE_OMIT_INCRBLOB 543 #ifndef SQLITE_OMIT_INCRBLOB
519 int sqlite3VdbeMemExpandBlob(Mem *); 544 int sqlite3VdbeMemExpandBlob(Mem *);
520 #define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0) 545 #define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0)
521 #else 546 #else
522 #define sqlite3VdbeMemExpandBlob(x) SQLITE_OK 547 #define sqlite3VdbeMemExpandBlob(x) SQLITE_OK
523 #define ExpandBlob(P) SQLITE_OK 548 #define ExpandBlob(P) SQLITE_OK
524 #endif 549 #endif
525 550
526 #endif /* !defined(_VDBEINT_H_) */ 551 #endif /* !defined(SQLITE_VDBEINT_H) */
OLDNEW
« no previous file with comments | « third_party/sqlite/src/src/vdbe.c ('k') | third_party/sqlite/src/src/vdbeapi.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698