Debian Codegraph @

www/opcode.html

raw
1 <!DOCTYPE html>
2 <html><head>
3 <meta name="viewport" content="width=device-width, initial-scale=1.0">
4 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
5 <link href="sqlite.css" rel="stylesheet">
6 <title>The SQLite Bytecode Engine</title>
7 <!-- path= -->
8 </head>
9 <body>
10 <div class=nosearch>
11 <a href="index.html">
12 <img class="logo" src="images/sqlite370_banner.gif" alt="SQLite" border="0">
13 </a>
14 <div><!-- IE hack to prevent disappearing logo --></div>
15 <div class="tagline desktoponly">
16 Small. Fast. Reliable.<br>Choose any three.
17 </div>
18 <div class="menu mainmenu">
19 <ul>
20 <li><a href="index.html">Home</a>
21 <li class='mobileonly'><a href="javascript:void(0)" onclick='toggle_div("submenu")'>Menu</a>
22 <li class='wideonly'><a href='about.html'>About</a>
23 <li class='desktoponly'><a href="docs.html">Documentation</a>
24 <li class='desktoponly'><a href="download.html">Download</a>
25 <li class='wideonly'><a href='copyright.html'>License</a>
26 <li class='desktoponly'><a href="support.html">Support</a>
27 <li class='desktoponly'><a href="prosupport.html">Purchase</a>
28 <li class='search' id='search_menubutton'>
29 <a href="javascript:void(0)" onclick='toggle_search()'>Search</a>
30 </ul>
31 </div>
32 <div class="menu submenu" id="submenu">
33 <ul>
34 <li><a href='about.html'>About</a>
35 <li><a href='docs.html'>Documentation</a>
36 <li><a href='download.html'>Download</a>
37 <li><a href='support.html'>Support</a>
38 <li><a href='prosupport.html'>Purchase</a>
39 </ul>
40 </div>
41 <div class="searchmenu" id="searchmenu">
42 <form method="GET" action="search">
43 <select name="s" id="searchtype">
44 <option value="d">Search Documentation</option>
45 <option value="c">Search Changelog</option>
46 </select>
47 <input type="text" name="q" id="searchbox" value="">
48 <input type="submit" value="Go">
49 </form>
50 </div>
51 </div>
52 <script>
53 function toggle_div(nm) {
54 var w = document.getElementById(nm);
55 if( w.style.display=="block" ){
56 w.style.display = "none";
57 }else{
58 w.style.display = "block";
59 }
60 }
61 function toggle_search() {
62 var w = document.getElementById("searchmenu");
63 if( w.style.display=="block" ){
64 w.style.display = "none";
65 } else {
66 w.style.display = "block";
67 setTimeout(function(){
68 document.getElementById("searchbox").focus()
69 }, 30);
70 }
71 }
72 function div_off(nm){document.getElementById(nm).style.display="none";}
73 window.onbeforeunload = function(e){div_off("submenu");}
74 /* Disable the Search feature if we are not operating from CGI, since */
75 /* Search is accomplished using CGI and will not work without it. */
76 if( !location.origin || !location.origin.match || !location.origin.match(/http/) ){
77 document.getElementById("search_menubutton").style.display = "none";
78 }
79 /* Used by the Hide/Show button beside syntax diagrams, to toggle the */
80 function hideorshow(btn,obj){
81 var x = document.getElementById(obj);
82 var b = document.getElementById(btn);
83 if( x.style.display!='none' ){
84 x.style.display = 'none';
85 b.innerHTML='show';
86 }else{
87 x.style.display = '';
88 b.innerHTML='hide';
89 }
90 return false;
91 }
92 var antiRobot = 0;
93 function antiRobotGo(){
94 if( antiRobot!=3 ) return;
95 antiRobot = 7;
96 var j = document.getElementById("mtimelink");
97 if(j && j.hasAttribute("data-href")) j.href=j.getAttribute("data-href");
98 }
99 function antiRobotDefense(){
100 document.body.onmousedown=function(){
101 antiRobot |= 2;
102 antiRobotGo();
103 document.body.onmousedown=null;
104 }
105 document.body.onmousemove=function(){
106 antiRobot |= 2;
107 antiRobotGo();
108 document.body.onmousemove=null;
109 }
110 setTimeout(function(){
111 antiRobot |= 1;
112 antiRobotGo();
113 }, 100)
114 antiRobotGo();
115 }
116 antiRobotDefense();
117 </script>
118 <div class=fancy>
119 <div class=nosearch>
120 <div class="fancy_title">
121 The SQLite Bytecode Engine
122 </div>
123 <div class="fancy_toc">
124 <a onclick="toggle_toc()">
125 <span class="fancy_toc_mark" id="toc_mk">&#x25ba;</span>
126 Table Of Contents
127 </a>
128 <div id="toc_sub"><div class="fancy-toc1"><a href="#executive_summary">1. Executive Summary</a></div>
129 <div class="fancy-toc1"><a href="#introduction">2. Introduction</a></div>
130 <div class="fancy-toc2"><a href="#vdbe_source_code">2.1. VDBE Source Code</a></div>
131 <div class="fancy-toc2"><a href="#instruction_format">2.2. Instruction Format</a></div>
132 <div class="fancy-toc2"><a href="#registers">2.3. Registers</a></div>
133 <div class="fancy-toc2"><a href="#b_tree_cursors">2.4. B-Tree Cursors</a></div>
134 <div class="fancy-toc2"><a href="#subroutines_coroutines_and_subprograms">2.5. Subroutines, Coroutines, and Subprograms</a></div>
135 <div class="fancy-toc2"><a href="#self_altering_code">2.6. Self-Altering Code</a></div>
136 <div class="fancy-toc1"><a href="#viewing_the_bytecode">3. Viewing The Bytecode</a></div>
137 <div class="fancy-toc1"><a href="#the_opcodes">4. The Opcodes</a></div>
138 </div>
139 </div>
140 <script>
141 function toggle_toc(){
142 var sub = document.getElementById("toc_sub")
143 var mk = document.getElementById("toc_mk")
144 if( sub.style.display!="block" ){
145 sub.style.display = "block";
146 mk.innerHTML = "&#x25bc;";
147 } else {
148 sub.style.display = "none";
149 mk.innerHTML = "&#x25ba;";
150 }
151 }
152 </script>
153 </div>
154
155
156
157
158
159 <h1 id="executive_summary"><span>1. </span>Executive Summary</h1>
160
161 <p>SQLite works by translating SQL statements into bytecode and
162 then running that bytecode in a virtual machine. This document
163 describes how the bytecode engine works.
164
165 </p><p>This document describes SQLite internals. The information provided
166 here is not needed for routine application development using SQLite.
167 This document is intended for people who want to delve more deeply into
168 the internal operation of SQLite.
169
170 </p><p>The bytecode engine is <u>not</u> an API of SQLite. Details
171 about the bytecode engine change from one release of SQLite to the next.
172 Applications that use SQLite should not depend on any of the details
173 found in this document.
174
175 </p><p>See the document "<a href="whybytecode.html">Why SQLite Uses Bytecode</a>" for some reasons why
176 SQLite prefers to use bytecode to implement SQL.
177
178
179
180 </p><h1 id="introduction"><span>2. </span>Introduction</h1>
181
182 <p>SQLite works by translating each SQL statement into bytecode and
183 then running that bytecode.
184 A <a href="c3ref/stmt.html">prepared statement</a> in SQLite is mostly just the bytecode needed to
185 implement the corresponding SQL. The <a href="c3ref/prepare.html">sqlite3_prepare_v2()</a> interface
186 is a compiler that translates SQL into bytecode.
187 The <a href="c3ref/step.html">sqlite3_step()</a> interface is the virtual machine that runs the
188 bytecode contained within the <a href="c3ref/stmt.html">prepared statement</a>.
189
190 </p><p>The bytecode virtual machine is the heart of SQLite.
191 Programmers who want to understand how SQLite operates internally
192 must be familiar with the bytecode engine.
193
194 </p><p>Historically, the bytecode engine in SQLite is called the
195 "Virtual DataBase Engine" or "VDBE". This website uses the terms
196 "bytecode engine", "VDBE", "virtual machine", and "bytecode virtual
197 machine" interchangeably, as they all mean the same thing.
198
199 </p><p>
200 This article also uses the terms "bytecode program" and
201 "prepared statement" interchangeably, as they are mostly the same thing.
202
203 </p><h2 id="vdbe_source_code"><span>2.1. </span>VDBE Source Code</h2>
204
205 <p>The source code to the bytecode engine is in the
206 <a href="https://www.sqlite.org/src/file/src/vdbe.c">vdbe.c</a> source
207 file. The <a href="opcode.html#codes">opcode definitions</a> in this document are derived
208 from comments in that source file. The
209 source code comments are the canonical source of information
210 about the bytecode engine. When in doubt, refer to the source code.</p>
211
212 <p>In addition to the primary vdbe.c source code file, there are
213 other helper code files in the source tree, all of whose names
214 begin with "vdbe" - short for "Virtual DataBase Engine".
215
216 </p><p>Remember that the names and meanings of opcodes often change from
217 one release of SQLite to the next. So if you are studying the <a href="lang_explain.html">EXPLAIN</a>
218 output from SQLite, you should reference the version of this document
219 (or the vdbe.c source code)
220 that corresponds to the version of SQLite that ran the <a href="lang_explain.html">EXPLAIN</a>.
221 Otherwise, the description of the opcodes may not be accurate.
222 This document is derived from SQLite
223 version 3.46.1 check-in
224 <a href='https://www.sqlite.org/src/timeline?c=c9c2ab54ba1f5'>c9c2ab54ba1f5</a> dated 2024-08-13.
225
226
227
228
229 </p><h2 id="instruction_format"><span>2.2. </span>Instruction Format</h2>
230
231
232 <p>A bytecoded program in SQLite consists of one or more instructions.
233 Each instruction has an opcode and
234 five operands named P1, P2 P3, P4, and P5. The P1, P2, and P3
235 operands are 32-bit signed integers. These operands often refer to
236 registers. For instructions that operate on b-tree cursors,
237 the P1 operand is usually the cursor number.
238 For jump instructions, P2 is usually the jump destination.
239 P4 may be a 32-bit signed integer, a 64-bit signed integer, a
240 64-bit floating point value, a string literal, a Blob literal,
241 a pointer to a collating sequence comparison function, or a
242 pointer to the implementation of an application-defined SQL
243 function, or various other things. P5 is a 16-bit unsigned integer
244 normally used to hold flags. Bits of the P5 flag can sometimes affect
245 the opcode in subtle ways. For example, if the
246 SQLITE_NULLEQ (0x0080) bit of the P5 operand
247 is set on the <a href="opcode.html#Eq">Eq</a> opcode, then the NULL values compare
248 equal to one another. Otherwise NULL values compare different
249 from one another.
250
251
252 <p>Some opcodes use all five operands. Some opcodes use
253 one or two. Some opcodes use none of the operands.</p><p>
254
255
256 <p>The bytecode engine begins execution on instruction number 0.
257 Execution continues until a <a href="opcode.html#Halt">Halt</a> instruction is seen, or until
258 the program counter becomes greater than the address of
259 last instruction, or until there is an error.
260 When the bytecode engine halts, all memory
261 that it allocated is released and all database cursors it may
262 have had open are closed. If the execution stopped due to an
263 error, any pending transactions are terminated and changes made
264 to the database are rolled back.</p>
265
266
267
268 <p>The <a href="opcode.html#ResultRow">ResultRow</a> opcode causes the
269 bytecode engine to pause and the corresponding <a href="c3ref/step.html">sqlite3_step()</a>
270 call to return <a href="rescode.html#row">SQLITE_ROW</a>. Before invoking
271 <a href="opcode.html#ResultRow">ResultRow</a>, the bytecoded program will
272 have loaded the results for a single row of a query into a series
273 of registers. C-language APIs such as <a href="c3ref/column_blob.html">sqlite3_column_int()</a>
274 or <a href="c3ref/column_blob.html">sqlite3_column_text()</a> extract the query results from those
275 registers. The bytecode engine resumes with the next instruction
276 after the <a href="opcode.html#ResultRow">ResultRow</a> on the next call
277 to <a href="c3ref/step.html">sqlite3_step()</a>.
278
279
280 </p><h2 id="registers"><span>2.3. </span>Registers</h2>
281
282
283 <p>Every bytecode program has a fixed (but potentially large) number of
284 registers. A single register can hold a variety of objects:
285 <ul>
286 <li> A NULL value
287 <li> A signed 64-bit integer
288 <li> An IEEE double-precision (64-bit) floating point number
289 <li> An arbitrary length string
290 <li> An arbitrary length BLOB
291 <li> A RowSet object (See the <a href="opcode.html#RowSetAdd">RowSetAdd</a>, <a href="opcode.html#RowSetRead">RowSetRead</a>, and
292 <a href="opcode.html#RowSetTest">RowSetTest</a> opcodes)
293 <li> A Frame object (Used by <a href="opcode.html#subprog">subprograms</a> - see <a href="opcode.html#Program">Program</a>)
294 </ul>
295
296
297 <p>A register can also be "Undefined" meaning that it holds no value
298 at all. Undefined is different from NULL. Depending on compile-time
299 options, an attempt to read an undefined register will usually cause
300 a run-time error. If the code generator (<a href="c3ref/prepare.html">sqlite3_prepare_v2()</a>)
301 ever generates a <a href="c3ref/stmt.html">prepared statement</a> that reads an Undefined register,
302 that is a bug in the code generator.
303
304 </p><p>
305 Registers are numbered beginning with 0.
306 Most opcodes refer to at least one register.
307
308 </p><p>The number of registers in a single prepared statement is fixed
309 at compile-time. The content of all registers is cleared when
310 a prepared statement is <a href="c3ref/reset.html">reset</a> or
311 <a href="c3ref/finalize.html">finalized</a>.
312
313 </p><p>The internal Mem object stores the value for a single register.
314 The abstract <a href="c3ref/value.html">sqlite3_value</a> object that is exposed in the API is really
315 just a Mem object or register.
316
317 </p><h2 id="b_tree_cursors"><span>2.4. </span>B-Tree Cursors</h2>
318
319
320 <p>A prepared statement can have
321 zero or more open cursors. Each cursor is identified by a
322 small integer, which is usually the P1 parameter to the opcode
323 that uses the cursor.
324 There can be multiple cursors open on the same index or table.
325 All cursors operate independently, even cursors pointing to the same
326 indices or tables.
327 The only way for the virtual machine to interact with a database
328 file is through a cursor.
329 Instructions in the virtual machine can create a new cursor
330 (ex: <a href="opcode.html#OpenRead">OpenRead</a> or <a href="opcode.html#OpenWrite">OpenWrite</a>),
331 read data from a cursor (<a href="opcode.html#Column">Column</a>),
332 advance the cursor to the next entry in the table
333 (ex: <a href="opcode.html#Next">Next</a> or <a href="opcode.html#Prev">Prev</a>), and so forth.
334 All cursors are automatically
335 closed when the prepared statement is <a href="c3ref/reset.html">reset</a> or
336 <a href="c3ref/finalize.html">finalized</a>.
337
338
339 <a name="subprog"></a>
340
341 <h2 id="subroutines_coroutines_and_subprograms"><span>2.5. </span>Subroutines, Coroutines, and Subprograms</h2>
342
343 <p>The bytecode engine has no stack on which to store the return address
344 of a subroutine. Return addresses must be stored in registers.
345 Hence, bytecode subroutines are not reentrant.
346
347
348 <p>The <a href="opcode.html#Gosub">Gosub</a> opcode stores the current program counter into
349 register P1 then jumps to address P2. The <a href="opcode.html#Return">Return</a> opcode jumps
350 to address P1+1. Hence, every subroutine is associated with two integers:
351 the address of the entry point in the subroutine and the register number
352 that is used to hold the return address.
353
354 <p>The <a href="opcode.html#Yield">Yield</a> opcode swaps the value of the program counter with
355 the integer value in register P1. This opcode is used to implement
356 coroutines. Coroutines are often used to implement subqueries from
357 which content is pulled on an as-needed basis.
358
359
360 </p><p><a href="lang_createtrigger.html">Triggers</a> need to be reentrant.
361
362
363 Since bytecode
364 subroutines are not reentrant a different mechanism must be used to
365 implement triggers. Each trigger is implemented using a separate bytecode
366 program with its own opcodes, program counter, and register set. The
367 <a href="opcode.html#Program">Program</a> opcode invokes the trigger subprogram. The <a href="opcode.html#Program">Program</a> instruction
368 allocates and initializes a fresh register set for each invocation of the
369 subprogram, so subprograms can be reentrant and recursive. The
370 <a href="opcode.html#Param">Param</a> opcode is used by subprograms to access content in registers
371 of the calling bytecode program.
372
373
374 </p><h2 id="self_altering_code"><span>2.6. </span>Self-Altering Code</h2>
375
376
377 <p>Some opcodes are self-altering.
378 For example, the <a href="opcode.html#Init">Init</a> opcode (which is always the first opcode
379 in every bytecode program) increments its P1 operand. Subsequent
380 <a href="opcode.html#Once">Once</a> opcodes compare their P1 operands to the P1 value for
381 the <a href="opcode.html#Init">Init</a> opcode in order to determine if the one-time initialization
382 code that follows should be skipped.
383 Another example is the <a href="opcode.html#String8">String8</a> opcode which converts its P4
384 operand from UTF-8 into the correct database string encoding, then
385 converts itself into a <a href="opcode.html#String">String</a> opcode.
386
387
388
389 <h1 id="viewing_the_bytecode"><span>3. </span>Viewing The Bytecode</h1>
390
391 <p>Every SQL statement that SQLite interprets results in a program
392 for the virtual machine. But if the SQL statement begins with
393 the keyword <a href="lang_explain.html">EXPLAIN</a> the virtual machine will not execute the
394 program. Instead, the instructions of the program will be returned,
395 one instruction per row,
396 like a query result. This feature is useful for debugging and
397 for learning how the virtual machine operates. For example:
398 </p>
399
400 <blockquote><pre>$&nbsp;<b>sqlite3&nbsp;ex1.db</b>
401 sqlite&gt;&nbsp;<b>explain&nbsp;delete&nbsp;from&nbsp;tbl1&nbsp;where&nbsp;two&lt;20;</b>
402 addr&nbsp;&nbsp;opcode&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p1&nbsp;&nbsp;&nbsp;&nbsp;p2&nbsp;&nbsp;&nbsp;&nbsp;p3&nbsp;&nbsp;&nbsp;&nbsp;p4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p5&nbsp;&nbsp;comment&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
403 ----&nbsp;&nbsp;-------------&nbsp;&nbsp;----&nbsp;&nbsp;----&nbsp;&nbsp;----&nbsp;&nbsp;-------------&nbsp;&nbsp;--&nbsp;&nbsp;-------------
404 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Init&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;12&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;00&nbsp;&nbsp;Start&nbsp;at&nbsp;12&nbsp;&nbsp;
405 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Null&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;00&nbsp;&nbsp;r[1]=NULL&nbsp;&nbsp;&nbsp;&nbsp;
406 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OpenWrite&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;00&nbsp;&nbsp;root=2&nbsp;iDb=0;&nbsp;tbl1
407 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rewind&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;00&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
408 4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Column&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;00&nbsp;&nbsp;r[2]=tbl1.two
409 5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ge&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;9&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(BINARY)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;51&nbsp;&nbsp;if&nbsp;r[2]&gt;=r[3]&nbsp;goto&nbsp;9
410 6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Rowid&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;00&nbsp;&nbsp;r[4]=rowid&nbsp;&nbsp;&nbsp;
411 7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Once&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;00&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
412 8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Delete&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tbl1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;02&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
413 9&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Next&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;01&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
414 10&nbsp;&nbsp;&nbsp;&nbsp;Noop&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;00&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
415 11&nbsp;&nbsp;&nbsp;&nbsp;Halt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;00&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
416 12&nbsp;&nbsp;&nbsp;&nbsp;Transaction&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;01&nbsp;&nbsp;usesStmtJournal=0
417 13&nbsp;&nbsp;&nbsp;&nbsp;TableLock&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tbl1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;00&nbsp;&nbsp;iDb=0&nbsp;root=2&nbsp;write=1
418 14&nbsp;&nbsp;&nbsp;&nbsp;Integer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20&nbsp;&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;00&nbsp;&nbsp;r[3]=20&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
419 15&nbsp;&nbsp;&nbsp;&nbsp;Goto&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;00</pre></blockquote>
420
421 <p>Any application can run an <a href="lang_explain.html">EXPLAIN</a> query to get output similar to
422 the above.
423 However, indentation to show the loop structure is not generated
424 by the SQLite core. The <a href="cli.html">command-line shell</a> contains extra logic
425 for indenting loops.
426 Also, the "comment" column in the <a href="lang_explain.html">EXPLAIN</a> output
427 is only provided if SQLite is compiled with the
428 <a href="compile.html#enable_explain_comments">-DSQLITE_ENABLE_EXPLAIN_COMMENTS</a> options.
429
430 </p><p>When SQLite is compiled with the <a href="compile.html#debug">SQLITE_DEBUG</a> compile-time option,
431 extra <a href="pragma.html#syntax">PRAGMA</a> commands are available that are useful for debugging and
432 for exploring the operation of the VDBE. For example the <a href="pragma.html#pragma_vdbe_trace">vdbe_trace</a>
433 pragma can be enabled to cause a disassembly of each VDBE opcode to be
434 printed on standard output as the opcode is executed. These debugging
435 pragmas include:
436 </p><ul>
437 <li> <a href="pragma.html#pragma_parser_trace">PRAGMA parser_trace</a>
438 </li><li> <a href="pragma.html#pragma_vdbe_addoptrace">PRAGMA vdbe_addoptrace</a>
439 </li><li> <a href="pragma.html#pragma_vdbe_debug">PRAGMA vdbe_debug</a>
440 </li><li> <a href="pragma.html#pragma_vdbe_listing">PRAGMA vdbe_listing</a>
441 </li><li> <a href="pragma.html#pragma_vdbe_trace">PRAGMA vdbe_trace</a>
442 </li></ul>
443
444
445 <h1 id="the_opcodes"><span>4. </span>The Opcodes</h1>
446
447 <p>There are currently 189
448 opcodes defined by the virtual machine.
449 All currently defined opcodes are described in the table below.
450 This table was generated automatically by scanning the source code
451 from the file
452 <a href="https://www.sqlite.org/src/artifact/3b1793c5d2235ae89b01ef051a33d7d2ad3704c71799653b112686735ad401ff">vdbe.c</a>.
453
454
455 </p><p>Remember: The VDBE opcodes are <u>not</u> part of the interface
456 definition for SQLite. The number of opcodes and their names and meanings
457 change from one release of SQLite to the next.
458 The opcodes shown in the table below are valid for SQLite
459 version 3.46.1 check-in
460 <a href='https://www.sqlite.org/src/timeline?c=c9c2ab54ba1f5'>c9c2ab54ba1f5</a> dated 2024-08-13.
461
462 <a name="codes"></a>
463
464 </div>
465 <style>.optab td {vertical-align:top; padding: 1ex 1ex;}</style>
466 <div class="optab">
467 <blockquote><table cellspacing=0 border=1 cellpaddin>
468 <tr><th>Opcode Name</th><th>Description</th></tr>
469 <tr><td valign="top" align="center">
470 <a name="Abortable"></a>Abortable
471 <td>Verify that an Abort can happen. Assert if an Abort at this point
472 might cause database corruption. This opcode only appears in debugging
473 builds.</p>
474
475 <p>An Abort is safe if either there have been no writes, or if there is
476 an active statement journal.</td></tr>
477 <tr><td valign="top" align="center">
478 <a name="Add"></a>Add
479 <td>Add the value in register P1 to the value in register P2
480 and store the result in register P3.
481 If either input is NULL, the result is NULL.</td></tr>
482 <tr><td valign="top" align="center">
483 <a name="AddImm"></a>AddImm
484 <td>Add the constant P2 to the value in register P1.
485 The result is always an integer.</p>
486
487 <p>To force any register to be an integer, just add 0.</td></tr>
488 <tr><td valign="top" align="center">
489 <a name="Affinity"></a>Affinity
490 <td>Apply affinities to a range of P2 registers starting with P1.</p>
491
492 <p>P4 is a string that is P2 characters long. The N-th character of the
493 string indicates the column affinity that should be used for the N-th
494 memory cell in the range.</td></tr>
495 <tr><td valign="top" align="center">
496 <a name="AggFinal"></a>AggFinal
497 <td>P1 is the memory location that is the accumulator for an aggregate
498 or window function. Execute the finalizer function
499 for an aggregate and store the result in P1.</p>
500
501 <p>P2 is the number of arguments that the step function takes and
502 P4 is a pointer to the FuncDef for this function. The P2
503 argument is not used by this opcode. It is only there to disambiguate
504 functions that can take varying numbers of arguments. The
505 P4 argument is only needed for the case where
506 the step function was not previously called.</td></tr>
507 <tr><td valign="top" align="center">
508 <a name="AggInverse"></a>AggInverse
509 <td>Execute the xInverse function for an aggregate.
510 The function has P5 arguments. P4 is a pointer to the
511 FuncDef structure that specifies the function. Register P3 is the
512 accumulator.</p>
513
514 <p>The P5 arguments are taken from register P2 and its
515 successors.</td></tr>
516 <tr><td valign="top" align="center">
517 <a name="AggStep"></a>AggStep
518 <td>Execute the xStep function for an aggregate.
519 The function has P5 arguments. P4 is a pointer to the
520 FuncDef structure that specifies the function. Register P3 is the
521 accumulator.</p>
522
523 <p>The P5 arguments are taken from register P2 and its
524 successors.</td></tr>
525 <tr><td valign="top" align="center">
526 <a name="AggStep1"></a>AggStep1
527 <td>Execute the xStep (if P1==0) or xInverse (if P1!=0) function for an
528 aggregate. The function has P5 arguments. P4 is a pointer to the
529 FuncDef structure that specifies the function. Register P3 is the
530 accumulator.</p>
531
532 <p>The P5 arguments are taken from register P2 and its
533 successors.</p>
534
535 <p>This opcode is initially coded as OP_AggStep0. On first evaluation,
536 the FuncDef stored in P4 is converted into an sqlite3_context and
537 the opcode is changed. In this way, the initialization of the
538 sqlite3_context only happens once, instead of on each call to the
539 step function.</td></tr>
540 <tr><td valign="top" align="center">
541 <a name="AggValue"></a>AggValue
542 <td>Invoke the xValue() function and store the result in register P3.</p>
543
544 <p>P2 is the number of arguments that the step function takes and
545 P4 is a pointer to the FuncDef for this function. The P2
546 argument is not used by this opcode. It is only there to disambiguate
547 functions that can take varying numbers of arguments. The
548 P4 argument is only needed for the case where
549 the step function was not previously called.</td></tr>
550 <tr><td valign="top" align="center">
551 <a name="And"></a>And
552 <td>Take the logical AND of the values in registers P1 and P2 and
553 write the result into register P3.</p>
554
555 <p>If either P1 or P2 is 0 (false) then the result is 0 even if
556 the other input is NULL. A NULL and true or two NULLs give
557 a NULL output.</td></tr>
558 <tr><td valign="top" align="center">
559 <a name="AutoCommit"></a>AutoCommit
560 <td>Set the database auto-commit flag to P1 (1 or 0). If P2 is true, roll
561 back any currently active btree transactions. If there are any active
562 VMs (apart from this one), then a ROLLBACK fails. A COMMIT fails if
563 there are active writing VMs or active VMs that use shared cache.</p>
564
565 <p>This instruction causes the VM to halt.</td></tr>
566 <tr><td valign="top" align="center">
567 <a name="BeginSubrtn"></a>BeginSubrtn
568 <td>Mark the beginning of a subroutine that can be entered in-line
569 or that can be called using <a href="opcode.html#Gosub">Gosub</a>. The subroutine should
570 be terminated by an <a href="opcode.html#Return">Return</a> instruction that has a P1 operand that
571 is the same as the P2 operand to this opcode and that has P3 set to 1.
572 If the subroutine is entered in-line, then the <a href="opcode.html#Return">Return</a> will simply
573 fall through. But if the subroutine is entered using <a href="opcode.html#Gosub">Gosub</a>, then
574 the <a href="opcode.html#Return">Return</a> will jump back to the first instruction after the <a href="opcode.html#Gosub">Gosub</a>.</p>
575
576 <p>This routine works by loading a NULL into the P2 register. When the
577 return address register contains a NULL, the <a href="opcode.html#Return">Return</a> instruction is
578 a no-op that simply falls through to the next instruction (assuming that
579 the <a href="opcode.html#Return">Return</a> opcode has a P3 value of 1). Thus if the subroutine is
580 entered in-line, then the <a href="opcode.html#Return">Return</a> will cause in-line execution to
581 continue. But if the subroutine is entered via <a href="opcode.html#Gosub">Gosub</a>, then the
582 <a href="opcode.html#Return">Return</a> will cause a return to the address following the <a href="opcode.html#Gosub">Gosub</a>.</p>
583
584 <p>This opcode is identical to <a href="opcode.html#Null">Null</a>. It has a different name
585 only to make the byte code easier to read and verify.</td></tr>
586 <tr><td valign="top" align="center">
587 <a name="BitAnd"></a>BitAnd
588 <td>Take the bit-wise AND of the values in register P1 and P2 and
589 store the result in register P3.
590 If either input is NULL, the result is NULL.</td></tr>
591 <tr><td valign="top" align="center">
592 <a name="BitNot"></a>BitNot
593 <td>Interpret the content of register P1 as an integer. Store the
594 ones-complement of the P1 value into register P2. If P1 holds
595 a NULL then store a NULL in P2.</td></tr>
596 <tr><td valign="top" align="center">
597 <a name="BitOr"></a>BitOr
598 <td>Take the bit-wise OR of the values in register P1 and P2 and
599 store the result in register P3.
600 If either input is NULL, the result is NULL.</td></tr>
601 <tr><td valign="top" align="center">
602 <a name="Blob"></a>Blob
603 <td>P4 points to a blob of data P1 bytes long. Store this
604 blob in register P2. If P4 is a NULL pointer, then construct
605 a zero-filled blob that is P1 bytes long in P2.</td></tr>
606 <tr><td valign="top" align="center">
607 <a name="Cast"></a>Cast
608 <td>Force the value in register P1 to be the type defined by P2.</p>
609
610 <p><ul>
611 <li> P2=='A' &rarr; BLOB
612 <li> P2=='B' &rarr; TEXT
613 <li> P2=='C' &rarr; NUMERIC
614 <li> P2=='D' &rarr; INTEGER
615 <li> P2=='E' &rarr; REAL
616 </ul></p>
617
618 <p>A NULL value is not changed by this routine. It remains NULL.</td></tr>
619 <tr><td valign="top" align="center">
620 <a name="Checkpoint"></a>Checkpoint
621 <td>Checkpoint database P1. This is a no-op if P1 is not currently in
622 WAL mode. Parameter P2 is one of SQLITE_CHECKPOINT_PASSIVE, FULL,
623 RESTART, or TRUNCATE. Write 1 or 0 into mem&#91;P3&#93; if the checkpoint returns
624 SQLITE_BUSY or not, respectively. Write the number of pages in the
625 WAL after the checkpoint into mem&#91;P3+1&#93; and the number of pages
626 in the WAL that have been checkpointed after the checkpoint
627 completes into mem&#91;P3+2&#93;. However on an error, mem&#91;P3+1&#93; and
628 mem&#91;P3+2&#93; are initialized to -1.</td></tr>
629 <tr><td valign="top" align="center">
630 <a name="Clear"></a>Clear
631 <td>Delete all contents of the database table or index whose root page
632 in the database file is given by P1. But, unlike <a href="opcode.html#Destroy">Destroy</a>, do not
633 remove the table or index from the database file.</p>
634
635 <p>The table being cleared is in the main database file if P2==0. If
636 P2==1 then the table to be cleared is in the auxiliary database file
637 that is used to store tables create using CREATE TEMPORARY TABLE.</p>
638
639 <p>If the P3 value is non-zero, then the row change count is incremented
640 by the number of rows in the table being cleared. If P3 is greater
641 than zero, then the value stored in register P3 is also incremented
642 by the number of rows in the table being cleared.</p>
643
644 <p>See also: <a href="opcode.html#Destroy">Destroy</a></td></tr>
645 <tr><td valign="top" align="center">
646 <a name="Close"></a>Close
647 <td>Close a cursor previously opened as P1. If P1 is not
648 currently open, this instruction is a no-op.</td></tr>
649 <tr><td valign="top" align="center">
650 <a name="ClrSubtype"></a>ClrSubtype
651 <td>Clear the subtype from register P1.</td></tr>
652 <tr><td valign="top" align="center">
653 <a name="CollSeq"></a>CollSeq
654 <td>P4 is a pointer to a CollSeq object. If the next call to a user function
655 or aggregate calls sqlite3GetFuncCollSeq(), this collation sequence will
656 be returned. This is used by the built-in min(), max() and nullif()
657 functions.</p>
658
659 <p>If P1 is not zero, then it is a register that a subsequent min() or
660 max() aggregate will set to 1 if the current row is not the minimum or
661 maximum. The P1 register is initialized to 0 by this instruction.</p>
662
663 <p>The interface used by the implementation of the aforementioned functions
664 to retrieve the collation sequence set by this opcode is not available
665 publicly. Only built-in functions have access to this feature.</td></tr>
666 <tr><td valign="top" align="center">
667 <a name="Column"></a>Column
668 <td>Interpret the data that cursor P1 points to as a structure built using
669 the <a href="opcode.html#MakeRecord">MakeRecord</a> instruction. (See the <a href="opcode.html#MakeRecord">MakeRecord</a> opcode for additional
670 information about the format of the data.) Extract the P2-th column
671 from this record. If there are less than (P2+1)
672 values in the record, extract a NULL.</p>
673
674 <p>The value extracted is stored in register P3.</p>
675
676 <p>If the record contains fewer than P2 fields, then extract a NULL. Or,
677 if the P4 argument is a P4_MEM use the value of the P4 argument as
678 the result.</p>
679
680 <p>If the OPFLAG_LENGTHARG bit is set in P5 then the result is guaranteed
681 to only be used by the length() function or the equivalent. The content
682 of large blobs is not loaded, thus saving CPU cycles. If the
683 OPFLAG_TYPEOFARG bit is set then the result will only be used by the
684 typeof() function or the IS NULL or IS NOT NULL operators or the
685 equivalent. In this case, all content loading can be omitted.</td></tr>
686 <tr><td valign="top" align="center">
687 <a name="ColumnsUsed"></a>ColumnsUsed
688 <td>This opcode (which only exists if SQLite was compiled with
689 SQLITE_ENABLE_COLUMN_USED_MASK) identifies which columns of the
690 table or index for cursor P1 are used. P4 is a 64-bit integer
691 (P4_INT64) in which the first 63 bits are one for each of the
692 first 63 columns of the table or index that are actually used
693 by the cursor. The high-order bit is set if any column after
694 the 64th is used.</td></tr>
695 <tr><td valign="top" align="center">
696 <a name="Compare"></a>Compare
697 <td>Compare two vectors of registers in reg(P1)..reg(P1+P3-1) (call this
698 vector "A") and in reg(P2)..reg(P2+P3-1) ("B"). Save the result of
699 the comparison for use by the next <a href="opcode.html#Jump">Jump</a> instruct.</p>
700
701 <p>If P5 has the OPFLAG_PERMUTE bit set, then the order of comparison is
702 determined by the most recent <a href="opcode.html#Permutation">Permutation</a> operator. If the
703 OPFLAG_PERMUTE bit is clear, then register are compared in sequential
704 order.</p>
705
706 <p>P4 is a KeyInfo structure that defines collating sequences and sort
707 orders for the comparison. The permutation applies to registers
708 only. The KeyInfo elements are used sequentially.</p>
709
710 <p>The comparison is a sort comparison, so NULLs compare equal,
711 NULLs are less than numbers, numbers are less than strings,
712 and strings are less than blobs.</p>
713
714 <p>This opcode must be immediately followed by an <a href="opcode.html#Jump">Jump</a> opcode.</td></tr>
715 <tr><td valign="top" align="center">
716 <a name="Concat"></a>Concat
717 <td>Add the text in register P1 onto the end of the text in
718 register P2 and store the result in register P3.
719 If either the P1 or P2 text are NULL then store NULL in P3.</p>
720
721 <p>P3 = P2 || P1</p>
722
723 <p>It is illegal for P1 and P3 to be the same register. Sometimes,
724 if P3 is the same register as P2, the implementation is able
725 to avoid a memcpy().</td></tr>
726 <tr><td valign="top" align="center">
727 <a name="Copy"></a>Copy
728 <td>Make a copy of registers P1..P1+P3 into registers P2..P2+P3.</p>
729
730 <p>If the 0x0002 bit of P5 is set then also clear the MEM_Subtype flag in the
731 destination. The 0x0001 bit of P5 indicates that this <a href="opcode.html#Copy">Copy</a> opcode cannot
732 be merged. The 0x0001 bit is used by the query planner and does not
733 come into play during query execution.</p>
734
735 <p>This instruction makes a deep copy of the value. A duplicate
736 is made of any string or blob constant. See also <a href="opcode.html#SCopy">SCopy</a>.</td></tr>
737 <tr><td valign="top" align="center">
738 <a name="Count"></a>Count
739 <td>Store the number of entries (an integer value) in the table or index
740 opened by cursor P1 in register P2.</p>
741
742 <p>If P3==0, then an exact count is obtained, which involves visiting
743 every btree page of the table. But if P3 is non-zero, an estimate
744 is returned based on the current cursor position.</td></tr>
745 <tr><td valign="top" align="center">
746 <a name="CreateBtree"></a>CreateBtree
747 <td>Allocate a new b-tree in the main database file if P1==0 or in the
748 TEMP database file if P1==1 or in an attached database if
749 P1&gt;1. The P3 argument must be 1 (BTREE_INTKEY) for a rowid table
750 it must be 2 (BTREE_BLOBKEY) for an index or WITHOUT ROWID table.
751 The root page number of the new b-tree is stored in register P2.</td></tr>
752 <tr><td valign="top" align="center">
753 <a name="CursorHint"></a>CursorHint
754 <td>Provide a hint to cursor P1 that it only needs to return rows that
755 satisfy the Expr in P4. TK_REGISTER terms in the P4 expression refer
756 to values currently held in registers. TK_COLUMN terms in the P4
757 expression refer to columns in the b-tree to which cursor P1 is pointing.</td></tr>
758 <tr><td valign="top" align="center">
759 <a name="CursorLock"></a>CursorLock
760 <td>Lock the btree to which cursor P1 is pointing so that the btree cannot be
761 written by an other cursor.</td></tr>
762 <tr><td valign="top" align="center">
763 <a name="CursorUnlock"></a>CursorUnlock
764 <td>Unlock the btree to which cursor P1 is pointing so that it can be
765 written by other cursors.</td></tr>
766 <tr><td valign="top" align="center">
767 <a name="DecrJumpZero"></a>DecrJumpZero
768 <td>Register P1 must hold an integer. Decrement the value in P1
769 and jump to P2 if the new value is exactly zero.</td></tr>
770 <tr><td valign="top" align="center">
771 <a name="DeferredSeek"></a>DeferredSeek
772 <td>P1 is an open index cursor and P3 is a cursor on the corresponding
773 table. This opcode does a deferred seek of the P3 table cursor
774 to the row that corresponds to the current row of P1.</p>
775
776 <p>This is a deferred seek. Nothing actually happens until
777 the cursor is used to read a record. That way, if no reads
778 occur, no unnecessary I/O happens.</p>
779
780 <p>P4 may be an array of integers (type P4_INTARRAY) containing
781 one entry for each column in the P3 table. If array entry a(i)
782 is non-zero, then reading column a(i)-1 from cursor P3 is
783 equivalent to performing the deferred seek and then reading column i
784 from P1. This information is stored in P3 and used to redirect
785 reads against P3 over to P1, thus possibly avoiding the need to
786 seek and read cursor P3.</td></tr>
787 <tr><td valign="top" align="center">
788 <a name="Delete"></a>Delete
789 <td>Delete the record at which the P1 cursor is currently pointing.</p>
790
791 <p>If the OPFLAG_SAVEPOSITION bit of the P5 parameter is set, then
792 the cursor will be left pointing at either the next or the previous
793 record in the table. If it is left pointing at the next record, then
794 the next <a href="opcode.html#Next">Next</a> instruction will be a no-op. As a result, in this case
795 it is ok to delete a record from within a <a href="opcode.html#Next">Next</a> loop. If
796 OPFLAG_SAVEPOSITION bit of P5 is clear, then the cursor will be
797 left in an undefined state.</p>
798
799 <p>If the OPFLAG_AUXDELETE bit is set on P5, that indicates that this
800 delete is one of several associated with deleting a table row and
801 all its associated index entries. Exactly one of those deletes is
802 the "primary" delete. The others are all on OPFLAG_FORDELETE
803 cursors or else are marked with the AUXDELETE flag.</p>
804
805 <p>If the OPFLAG_NCHANGE (0x01) flag of P2 (NB: P2 not P5) is set, then
806 the row change count is incremented (otherwise not).</p>
807
808 <p>If the OPFLAG_ISNOOP (0x40) flag of P2 (not P5!) is set, then the
809 pre-update-hook for deletes is run, but the btree is otherwise unchanged.
810 This happens when the <a href="opcode.html#Delete">Delete</a> is to be shortly followed by an <a href="opcode.html#Insert">Insert</a>
811 with the same key, causing the btree entry to be overwritten.</p>
812
813 <p>P1 must not be pseudo-table. It has to be a real table with
814 multiple rows.</p>
815
816 <p>If P4 is not NULL then it points to a Table object. In this case either
817 the update or pre-update hook, or both, may be invoked. The P1 cursor must
818 have been positioned using <a href="opcode.html#NotFound">NotFound</a> prior to invoking this opcode in
819 this case. Specifically, if one is configured, the pre-update hook is
820 invoked if P4 is not NULL. The update-hook is invoked if one is configured,
821 P4 is not NULL, and the OPFLAG_NCHANGE flag is set in P2.</p>
822
823 <p>If the OPFLAG_ISUPDATE flag is set in P2, then P3 contains the address
824 of the memory cell that contains the value that the rowid of the row will
825 be set to by the update.</td></tr>
826 <tr><td valign="top" align="center">
827 <a name="Destroy"></a>Destroy
828 <td>Delete an entire database table or index whose root page in the database
829 file is given by P1.</p>
830
831 <p>The table being destroyed is in the main database file if P3==0. If
832 P3==1 then the table to be destroyed is in the auxiliary database file
833 that is used to store tables create using CREATE TEMPORARY TABLE.</p>
834
835 <p>If AUTOVACUUM is enabled then it is possible that another root page
836 might be moved into the newly deleted root page in order to keep all
837 root pages contiguous at the beginning of the database. The former
838 value of the root page that moved - its value before the move occurred -
839 is stored in register P2. If no page movement was required (because the
840 table being dropped was already the last one in the database) then a
841 zero is stored in register P2. If AUTOVACUUM is disabled then a zero
842 is stored in register P2.</p>
843
844 <p>This opcode throws an error if there are any active reader VMs when
845 it is invoked. This is done to avoid the difficulty associated with
846 updating existing cursors when a root page is moved in an AUTOVACUUM
847 database. This error is thrown even if the database is not an AUTOVACUUM
848 db in order to avoid introducing an incompatibility between autovacuum
849 and non-autovacuum modes.</p>
850
851 <p>See also: <a href="opcode.html#Clear">Clear</a></td></tr>
852 <tr><td valign="top" align="center">
853 <a name="Divide"></a>Divide
854 <td>Divide the value in register P1 by the value in register P2
855 and store the result in register P3 (P3=P2/P1). If the value in
856 register P1 is zero, then the result is NULL. If either input is
857 NULL, the result is NULL.</td></tr>
858 <tr><td valign="top" align="center">
859 <a name="DropIndex"></a>DropIndex
860 <td>Remove the internal (in-memory) data structures that describe
861 the index named P4 in database P1. This is called after an index
862 is dropped from disk (using the <a href="opcode.html#Destroy">Destroy</a> opcode)
863 in order to keep the internal representation of the
864 schema consistent with what is on disk.</td></tr>
865 <tr><td valign="top" align="center">
866 <a name="DropTable"></a>DropTable
867 <td>Remove the internal (in-memory) data structures that describe
868 the table named P4 in database P1. This is called after a table
869 is dropped from disk (using the <a href="opcode.html#Destroy">Destroy</a> opcode) in order to keep
870 the internal representation of the
871 schema consistent with what is on disk.</td></tr>
872 <tr><td valign="top" align="center">
873 <a name="DropTrigger"></a>DropTrigger
874 <td>Remove the internal (in-memory) data structures that describe
875 the trigger named P4 in database P1. This is called after a trigger
876 is dropped from disk (using the <a href="opcode.html#Destroy">Destroy</a> opcode) in order to keep
877 the internal representation of the
878 schema consistent with what is on disk.</td></tr>
879 <tr><td valign="top" align="center">
880 <a name="ElseEq"></a>ElseEq
881 <td>This opcode must follow an <a href="opcode.html#Lt">Lt</a> or <a href="opcode.html#Gt">Gt</a> comparison operator. There
882 can be zero or more OP_ReleaseReg opcodes intervening, but no other
883 opcodes are allowed to occur between this instruction and the previous
884 <a href="opcode.html#Lt">Lt</a> or <a href="opcode.html#Gt">Gt</a>.</p>
885
886 <p>If the result of an <a href="opcode.html#Eq">Eq</a> comparison on the same two operands as
887 the prior <a href="opcode.html#Lt">Lt</a> or <a href="opcode.html#Gt">Gt</a> would have been true, then jump to P2. If
888 the result of an <a href="opcode.html#Eq">Eq</a> comparison on the two previous operands
889 would have been false or NULL, then fall through.</td></tr>
890 <tr><td valign="top" align="center">
891 <a name="EndCoroutine"></a>EndCoroutine
892 <td>The instruction at the address in register P1 is a <a href="opcode.html#Yield">Yield</a>.
893 <a href="opcode.html#Jump">Jump</a> to the P2 parameter of that <a href="opcode.html#Yield">Yield</a>.
894 After the jump, the value register P1 is left with a value
895 such that subsequent OP_Yields go back to the this same
896 <a href="opcode.html#EndCoroutine">EndCoroutine</a> instruction.</p>
897
898 <p>See also: <a href="opcode.html#InitCoroutine">InitCoroutine</a></td></tr>
899 <tr><td valign="top" align="center">
900 <a name="Eq"></a>Eq
901 <td>Compare the values in register P1 and P3. If reg(P3)==reg(P1) then
902 jump to address P2.</p>
903
904 <p>The SQLITE_AFF_MASK portion of P5 must be an affinity character -
905 SQLITE_AFF_TEXT, SQLITE_AFF_INTEGER, and so forth. An attempt is made
906 to coerce both inputs according to this affinity before the
907 comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
908 affinity is used. Note that the affinity conversions are stored
909 back into the input registers P1 and P3. So this opcode can cause
910 persistent changes to registers P1 and P3.</p>
911
912 <p>Once any conversions have taken place, and neither value is NULL,
913 the values are compared. If both values are blobs then memcmp() is
914 used to determine the results of the comparison. If both values
915 are text, then the appropriate collating function specified in
916 P4 is used to do the comparison. If P4 is not specified then
917 memcmp() is used to compare text string. If both values are
918 numeric, then a numeric comparison is used. If the two values
919 are of different types, then numbers are considered less than
920 strings and strings are considered less than blobs.</p>
921
922 <p>If SQLITE_NULLEQ is set in P5 then the result of comparison is always either
923 true or false and is never NULL. If both operands are NULL then the result
924 of comparison is true. If either operand is NULL then the result is false.
925 If neither operand is NULL the result is the same as it would be if
926 the SQLITE_NULLEQ flag were omitted from P5.</p>
927
928 <p>This opcode saves the result of comparison for use by the new
929 <a href="opcode.html#Jump">Jump</a> opcode.</td></tr>
930 <tr><td valign="top" align="center">
931 <a name="Expire"></a>Expire
932 <td>Cause precompiled statements to expire. When an expired statement
933 is executed using sqlite3_step() it will either automatically
934 reprepare itself (if it was originally created using sqlite3_prepare_v2())
935 or it will fail with SQLITE_SCHEMA.</p>
936
937 <p>If P1 is 0, then all SQL statements become expired. If P1 is non-zero,
938 then only the currently executing statement is expired.</p>
939
940 <p>If P2 is 0, then SQL statements are expired immediately. If P2 is 1,
941 then running SQL statements are allowed to continue to run to completion.
942 The P2==1 case occurs when a CREATE INDEX or similar schema change happens
943 that might help the statement run faster but which does not affect the
944 correctness of operation.</td></tr>
945 <tr><td valign="top" align="center">
946 <a name="Filter"></a>Filter
947 <td>Compute a hash on the key contained in the P4 registers starting
948 with r&#91;P3&#93;. Check to see if that hash is found in the
949 bloom filter hosted by register P1. If it is not present then
950 maybe jump to P2. Otherwise fall through.</p>
951
952 <p>False negatives are harmless. It is always safe to fall through,
953 even if the value is in the bloom filter. A false negative causes
954 more CPU cycles to be used, but it should still yield the correct
955 answer. However, an incorrect answer may well arise from a
956 false positive - if the jump is taken when it should fall through.</td></tr>
957 <tr><td valign="top" align="center">
958 <a name="FilterAdd"></a>FilterAdd
959 <td>Compute a hash on the P4 registers starting with r&#91;P3&#93; and
960 add that hash to the bloom filter contained in r&#91;P1&#93;.</td></tr>
961 <tr><td valign="top" align="center">
962 <a name="FinishSeek"></a>FinishSeek
963 <td>If cursor P1 was previously moved via <a href="opcode.html#DeferredSeek">DeferredSeek</a>, complete that
964 seek operation now, without further delay. If the cursor seek has
965 already occurred, this instruction is a no-op.</td></tr>
966 <tr><td valign="top" align="center">
967 <a name="FkCheck"></a>FkCheck
968 <td>Halt with an SQLITE_CONSTRAINT error if there are any unresolved
969 foreign key constraint violations. If there are no foreign key
970 constraint violations, this is a no-op.</p>
971
972 <p>FK constraint violations are also checked when the prepared statement
973 exits. This opcode is used to raise foreign key constraint errors prior
974 to returning results such as a row change count or the result of a
975 RETURNING clause.</td></tr>
976 <tr><td valign="top" align="center">
977 <a name="FkCounter"></a>FkCounter
978 <td>Increment a "constraint counter" by P2 (P2 may be negative or positive).
979 If P1 is non-zero, the database constraint counter is incremented
980 (deferred foreign key constraints). Otherwise, if P1 is zero, the
981 statement counter is incremented (immediate foreign key constraints).</td></tr>
982 <tr><td valign="top" align="center">
983 <a name="FkIfZero"></a>FkIfZero
984 <td>This opcode tests if a foreign key constraint-counter is currently zero.
985 If so, jump to instruction P2. Otherwise, fall through to the next
986 instruction.</p>
987
988 <p>If P1 is non-zero, then the jump is taken if the database constraint-counter
989 is zero (the one that counts deferred constraint violations). If P1 is
990 zero, the jump is taken if the statement constraint-counter is zero
991 (immediate foreign key constraint violations).</td></tr>
992 <tr><td valign="top" align="center">
993 <a name="Found"></a>Found
994 <td>If P4==0 then register P3 holds a blob constructed by <a href="opcode.html#MakeRecord">MakeRecord</a>. If
995 P4&gt;0 then register P3 is the first of P4 registers that form an unpacked
996 record.</p>
997
998 <p>Cursor P1 is on an index btree. If the record identified by P3 and P4
999 is a prefix of any entry in P1 then a jump is made to P2 and
1000 P1 is left pointing at the matching entry.</p>
1001
1002 <p>This operation leaves the cursor in a state where it can be
1003 advanced in the forward direction. The <a href="opcode.html#Next">Next</a> instruction will work,
1004 but not the <a href="opcode.html#Prev">Prev</a> instruction.</p>
1005
1006 <p>See also: <a href="opcode.html#NotFound">NotFound</a>, <a href="opcode.html#NoConflict">NoConflict</a>, <a href="opcode.html#NotExists">NotExists</a>. SeekGe</td></tr>
1007 <tr><td valign="top" align="center">
1008 <a name="Function"></a>Function
1009 <td>Invoke a user function (P4 is a pointer to an sqlite3_context object that
1010 contains a pointer to the function to be run) with arguments taken
1011 from register P2 and successors. The number of arguments is in
1012 the sqlite3_context object that P4 points to.
1013 The result of the function is stored
1014 in register P3. Register P3 must not be one of the function inputs.</p>
1015
1016 <p>P1 is a 32-bit bitmask indicating whether or not each argument to the
1017 function was determined to be constant at compile time. If the first
1018 argument was constant then bit 0 of P1 is set. This is used to determine
1019 whether meta data associated with a user function argument using the
1020 sqlite3_set_auxdata() API may be safely retained until the next
1021 invocation of this opcode.</p>
1022
1023 <p>See also: <a href="opcode.html#AggStep">AggStep</a>, <a href="opcode.html#AggFinal">AggFinal</a>, <a href="opcode.html#PureFunc">PureFunc</a></td></tr>
1024 <tr><td valign="top" align="center">
1025 <a name="Ge"></a>Ge
1026 <td>This works just like the Lt opcode except that the jump is taken if
1027 the content of register P3 is greater than or equal to the content of
1028 register P1. See the Lt opcode for additional information.</td></tr>
1029 <tr><td valign="top" align="center">
1030 <a name="GetSubtype"></a>GetSubtype
1031 <td>Extract the subtype value from register P1 and write that subtype
1032 into register P2. If P1 has no subtype, then P1 gets a NULL.</td></tr>
1033 <tr><td valign="top" align="center">
1034 <a name="Gosub"></a>Gosub
1035 <td>Write the current address onto register P1
1036 and then jump to address P2.</td></tr>
1037 <tr><td valign="top" align="center">
1038 <a name="Goto"></a>Goto
1039 <td>An unconditional jump to address P2.
1040 The next instruction executed will be
1041 the one at index P2 from the beginning of
1042 the program.</p>
1043
1044 <p>The P1 parameter is not actually used by this opcode. However, it
1045 is sometimes set to 1 instead of 0 as a hint to the command-line shell
1046 that this <a href="opcode.html#Goto">Goto</a> is the bottom of a loop and that the lines from P2 down
1047 to the current line should be indented for EXPLAIN output.</td></tr>
1048 <tr><td valign="top" align="center">
1049 <a name="Gt"></a>Gt
1050 <td>This works just like the Lt opcode except that the jump is taken if
1051 the content of register P3 is greater than the content of
1052 register P1. See the Lt opcode for additional information.</td></tr>
1053 <tr><td valign="top" align="center">
1054 <a name="Halt"></a>Halt
1055 <td>Exit immediately. All open cursors, etc are closed
1056 automatically.</p>
1057
1058 <p>P1 is the result code returned by sqlite3_exec(), sqlite3_reset(),
1059 or sqlite3_finalize(). For a normal halt, this should be SQLITE_OK (0).
1060 For errors, it can be some other value. If P1!=0 then P2 will determine
1061 whether or not to rollback the current transaction. Do not rollback
1062 if P2==OE_Fail. Do the rollback if P2==OE_Rollback. If P2==OE_Abort,
1063 then back out all changes that have occurred during this execution of the
1064 VDBE, but do not rollback the transaction.</p>
1065
1066 <p>If P4 is not null then it is an error message string.</p>
1067
1068 <p>P5 is a value between 0 and 4, inclusive, that modifies the P4 string.</p>
1069
1070 <p>0: (no change)
1071 1: NOT NULL constraint failed: P4
1072 2: UNIQUE constraint failed: P4
1073 3: CHECK constraint failed: P4
1074 4: FOREIGN KEY constraint failed: P4</p>
1075
1076 <p>If P5 is not zero and P4 is NULL, then everything after the ":" is
1077 omitted.</p>
1078
1079 <p>There is an implied "<a href="opcode.html#Halt">Halt</a> 0 0 0" instruction inserted at the very end of
1080 every program. So a jump past the last instruction of the program
1081 is the same as executing <a href="opcode.html#Halt">Halt</a>.</td></tr>
1082 <tr><td valign="top" align="center">
1083 <a name="HaltIfNull"></a>HaltIfNull
1084 <td>Check the value in register P3. If it is NULL then <a href="opcode.html#Halt">Halt</a> using
1085 parameter P1, P2, and P4 as if this were a <a href="opcode.html#Halt">Halt</a> instruction. If the
1086 value in register P3 is not NULL, then this routine is a no-op.
1087 The P5 parameter should be 1.</td></tr>
1088 <tr><td valign="top" align="center">
1089 <a name="IdxDelete"></a>IdxDelete
1090 <td>The content of P3 registers starting at register P2 form
1091 an unpacked index key. This opcode removes that entry from the
1092 index opened by cursor P1.</p>
1093
1094 <p>If P5 is not zero, then raise an SQLITE_CORRUPT_INDEX error
1095 if no matching index entry is found. This happens when running
1096 an UPDATE or DELETE statement and the index entry to be updated
1097 or deleted is not found. For some uses of <a href="opcode.html#IdxDelete">IdxDelete</a>
1098 (example: the EXCEPT operator) it does not matter that no matching
1099 entry is found. For those cases, P5 is zero. Also, do not raise
1100 this (self-correcting and non-critical) error if in writable_schema mode.</td></tr>
1101 <tr><td valign="top" align="center">
1102 <a name="IdxGE"></a>IdxGE
1103 <td>The P4 register values beginning with P3 form an unpacked index
1104 key that omits the PRIMARY KEY. <a href="opcode.html#Compare">Compare</a> this key value against the index
1105 that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID
1106 fields at the end.</p>
1107
1108 <p>If the P1 index entry is greater than or equal to the key value
1109 then jump to P2. Otherwise fall through to the next instruction.</td></tr>
1110 <tr><td valign="top" align="center">
1111 <a name="IdxGT"></a>IdxGT
1112 <td>The P4 register values beginning with P3 form an unpacked index
1113 key that omits the PRIMARY KEY. <a href="opcode.html#Compare">Compare</a> this key value against the index
1114 that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID
1115 fields at the end.</p>
1116
1117 <p>If the P1 index entry is greater than the key value
1118 then jump to P2. Otherwise fall through to the next instruction.</td></tr>
1119 <tr><td valign="top" align="center">
1120 <a name="IdxInsert"></a>IdxInsert
1121 <td>Register P2 holds an SQL index key made using the
1122 <a href="opcode.html#MakeRecord">MakeRecord</a> instructions. This opcode writes that key
1123 into the index P1. Data for the entry is nil.</p>
1124
1125 <p>If P4 is not zero, then it is the number of values in the unpacked
1126 key of reg(P2). In that case, P3 is the index of the first register
1127 for the unpacked key. The availability of the unpacked key can sometimes
1128 be an optimization.</p>
1129
1130 <p>If P5 has the OPFLAG_APPEND bit set, that is a hint to the b-tree layer
1131 that this insert is likely to be an append.</p>
1132
1133 <p>If P5 has the OPFLAG_NCHANGE bit set, then the change counter is
1134 incremented by this instruction. If the OPFLAG_NCHANGE bit is clear,
1135 then the change counter is unchanged.</p>
1136
1137 <p>If the OPFLAG_USESEEKRESULT flag of P5 is set, the implementation might
1138 run faster by avoiding an unnecessary seek on cursor P1. However,
1139 the OPFLAG_USESEEKRESULT flag must only be set if there have been no prior
1140 seeks on the cursor or if the most recent seek used a key equivalent
1141 to P2.</p>
1142
1143 <p>This instruction only works for indices. The equivalent instruction
1144 for tables is <a href="opcode.html#Insert">Insert</a>.</td></tr>
1145 <tr><td valign="top" align="center">
1146 <a name="IdxLE"></a>IdxLE
1147 <td>The P4 register values beginning with P3 form an unpacked index
1148 key that omits the PRIMARY KEY or ROWID. <a href="opcode.html#Compare">Compare</a> this key value against
1149 the index that P1 is currently pointing to, ignoring the PRIMARY KEY or
1150 ROWID on the P1 index.</p>
1151
1152 <p>If the P1 index entry is less than or equal to the key value then jump
1153 to P2. Otherwise fall through to the next instruction.</td></tr>
1154 <tr><td valign="top" align="center">
1155 <a name="IdxLT"></a>IdxLT
1156 <td>The P4 register values beginning with P3 form an unpacked index
1157 key that omits the PRIMARY KEY or ROWID. <a href="opcode.html#Compare">Compare</a> this key value against
1158 the index that P1 is currently pointing to, ignoring the PRIMARY KEY or
1159 ROWID on the P1 index.</p>
1160
1161 <p>If the P1 index entry is less than the key value then jump to P2.
1162 Otherwise fall through to the next instruction.</td></tr>
1163 <tr><td valign="top" align="center">
1164 <a name="IdxRowid"></a>IdxRowid
1165 <td>Write into register P2 an integer which is the last entry in the record at
1166 the end of the index key pointed to by cursor P1. This integer should be
1167 the rowid of the table entry to which this index entry points.</p>
1168
1169 <p>See also: <a href="opcode.html#Rowid">Rowid</a>, <a href="opcode.html#MakeRecord">MakeRecord</a>.</td></tr>
1170 <tr><td valign="top" align="center">
1171 <a name="If"></a>If
1172 <td>Jump to P2 if the value in register P1 is true. The value
1173 is considered true if it is numeric and non-zero. If the value
1174 in P1 is NULL then take the jump if and only if P3 is non-zero.</td></tr>
1175 <tr><td valign="top" align="center">
1176 <a name="IfNoHope"></a>IfNoHope
1177 <td>Register P3 is the first of P4 registers that form an unpacked
1178 record. Cursor P1 is an index btree. P2 is a jump destination.
1179 In other words, the operands to this opcode are the same as the
1180 operands to <a href="opcode.html#NotFound">NotFound</a> and <a href="opcode.html#IdxGT">IdxGT</a>.</p>
1181
1182 <p>This opcode is an optimization attempt only. If this opcode always
1183 falls through, the correct answer is still obtained, but extra work
1184 is performed.</p>
1185
1186 <p>A value of N in the seekHit flag of cursor P1 means that there exists
1187 a key P3:N that will match some record in the index. We want to know
1188 if it is possible for a record P3:P4 to match some record in the
1189 index. If it is not possible, we can skip some work. So if seekHit
1190 is less than P4, attempt to find out if a match is possible by running
1191 <a href="opcode.html#NotFound">NotFound</a>.</p>
1192
1193 <p>This opcode is used in IN clause processing for a multi-column key.
1194 If an IN clause is attached to an element of the key other than the
1195 left-most element, and if there are no matches on the most recent
1196 seek over the whole key, then it might be that one of the key element
1197 to the left is prohibiting a match, and hence there is "no hope" of
1198 any match regardless of how many IN clause elements are checked.
1199 In such a case, we abandon the IN clause search early, using this
1200 opcode. The opcode name comes from the fact that the
1201 jump is taken if there is "no hope" of achieving a match.</p>
1202
1203 <p>See also: <a href="opcode.html#NotFound">NotFound</a>, <a href="opcode.html#SeekHit">SeekHit</a></td></tr>
1204 <tr><td valign="top" align="center">
1205 <a name="IfNot"></a>IfNot
1206 <td>Jump to P2 if the value in register P1 is False. The value
1207 is considered false if it has a numeric value of zero. If the value
1208 in P1 is NULL then take the jump if and only if P3 is non-zero.</td></tr>
1209 <tr><td valign="top" align="center">
1210 <a name="IfNotOpen"></a>IfNotOpen
1211 <td>If cursor P1 is not open or if P1 is set to a NULL row using the
1212 <a href="opcode.html#NullRow">NullRow</a> opcode, then jump to instruction P2. Otherwise, fall through.</td></tr>
1213 <tr><td valign="top" align="center">
1214 <a name="IfNotZero"></a>IfNotZero
1215 <td>Register P1 must contain an integer. If the content of register P1 is
1216 initially greater than zero, then decrement the value in register P1.
1217 If it is non-zero (negative or positive) and then also jump to P2.
1218 If register P1 is initially zero, leave it unchanged and fall through.</td></tr>
1219 <tr><td valign="top" align="center">
1220 <a name="IfNullRow"></a>IfNullRow
1221 <td>Check the cursor P1 to see if it is currently pointing at a NULL row.
1222 If it is, then set register P3 to NULL and jump immediately to P2.
1223 If P1 is not on a NULL row, then fall through without making any
1224 changes.</p>
1225
1226 <p>If P1 is not an open cursor, then this opcode is a no-op.</td></tr>
1227 <tr><td valign="top" align="center">
1228 <a name="IfPos"></a>IfPos
1229 <td>Register P1 must contain an integer.
1230 If the value of register P1 is 1 or greater, subtract P3 from the
1231 value in P1 and jump to P2.</p>
1232
1233 <p>If the initial value of register P1 is less than 1, then the
1234 value is unchanged and control passes through to the next instruction.</td></tr>
1235 <tr><td valign="top" align="center">
1236 <a name="IfSizeBetween"></a>IfSizeBetween
1237 <td>Let N be the approximate number of rows in the table or index
1238 with cursor P1 and let X be 10*log2(N) if N is positive or -1
1239 if N is zero.</p>
1240
1241 <p>Jump to P2 if X is in between P3 and P4, inclusive.</td></tr>
1242 <tr><td valign="top" align="center">
1243 <a name="IncrVacuum"></a>IncrVacuum
1244 <td>Perform a single step of the incremental vacuum procedure on
1245 the P1 database. If the vacuum has finished, jump to instruction
1246 P2. Otherwise, fall through to the next instruction.</td></tr>
1247 <tr><td valign="top" align="center">
1248 <a name="Init"></a>Init
1249 <td>Programs contain a single instance of this opcode as the very first
1250 opcode.</p>
1251
1252 <p>If tracing is enabled (by the sqlite3_trace()) interface, then
1253 the UTF-8 string contained in P4 is emitted on the trace callback.
1254 Or if P4 is blank, use the string returned by sqlite3_sql().</p>
1255
1256 <p>If P2 is not zero, jump to instruction P2.</p>
1257
1258 <p>Increment the value of P1 so that <a href="opcode.html#Once">Once</a> opcodes will jump the
1259 first time they are evaluated for this run.</p>
1260
1261 <p>If P3 is not zero, then it is an address to jump to if an SQLITE_CORRUPT
1262 error is encountered.</td></tr>
1263 <tr><td valign="top" align="center">
1264 <a name="InitCoroutine"></a>InitCoroutine
1265 <td>Set up register P1 so that it will <a href="opcode.html#Yield">Yield</a> to the coroutine
1266 located at address P3.</p>
1267
1268 <p>If P2!=0 then the coroutine implementation immediately follows
1269 this opcode. So jump over the coroutine implementation to
1270 address P2.</p>
1271
1272 <p>See also: <a href="opcode.html#EndCoroutine">EndCoroutine</a></td></tr>
1273 <tr><td valign="top" align="center">
1274 <a name="Insert"></a>Insert
1275 <td>Write an entry into the table of cursor P1. A new entry is
1276 created if it doesn't already exist or the data for an existing
1277 entry is overwritten. The data is the value MEM_Blob stored in register
1278 number P2. The key is stored in register P3. The key must
1279 be a MEM_Int.</p>
1280
1281 <p>If the OPFLAG_NCHANGE flag of P5 is set, then the row change count is
1282 incremented (otherwise not). If the OPFLAG_LASTROWID flag of P5 is set,
1283 then rowid is stored for subsequent return by the
1284 sqlite3_last_insert_rowid() function (otherwise it is unmodified).</p>
1285
1286 <p>If the OPFLAG_USESEEKRESULT flag of P5 is set, the implementation might
1287 run faster by avoiding an unnecessary seek on cursor P1. However,
1288 the OPFLAG_USESEEKRESULT flag must only be set if there have been no prior
1289 seeks on the cursor or if the most recent seek used a key equal to P3.</p>
1290
1291 <p>If the OPFLAG_ISUPDATE flag is set, then this opcode is part of an
1292 UPDATE operation. Otherwise (if the flag is clear) then this opcode
1293 is part of an INSERT operation. The difference is only important to
1294 the update hook.</p>
1295
1296 <p>Parameter P4 may point to a Table structure, or may be NULL. If it is
1297 not NULL, then the update-hook (sqlite3.xUpdateCallback) is invoked
1298 following a successful insert.</p>
1299
1300 <p>(WARNING/TODO: If P1 is a pseudo-cursor and P2 is dynamically
1301 allocated, then ownership of P2 is transferred to the pseudo-cursor
1302 and register P2 becomes ephemeral. If the cursor is changed, the
1303 value of register P2 will then change. Make sure this does not
1304 cause any problems.)</p>
1305
1306 <p>This instruction only works on tables. The equivalent instruction
1307 for indices is <a href="opcode.html#IdxInsert">IdxInsert</a>.</td></tr>
1308 <tr><td valign="top" align="center">
1309 <a name="Int64"></a>Int64
1310 <td>P4 is a pointer to a 64-bit integer value.
1311 Write that value into register P2.</td></tr>
1312 <tr><td valign="top" align="center">
1313 <a name="IntCopy"></a>IntCopy
1314 <td>Transfer the integer value held in register P1 into register P2.</p>
1315
1316 <p>This is an optimized version of <a href="opcode.html#SCopy">SCopy</a> that works only for integer
1317 values.</td></tr>
1318 <tr><td valign="top" align="center">
1319 <a name="Integer"></a>Integer
1320 <td>The 32-bit integer value P1 is written into register P2.</td></tr>
1321 <tr><td valign="top" align="center">
1322 <a name="IntegrityCk"></a>IntegrityCk
1323 <td>Do an analysis of the currently open database. Store in
1324 register (P1+1) the text of an error message describing any problems.
1325 If no problems are found, store a NULL in register (P1+1).</p>
1326
1327 <p>The register (P1) contains one less than the maximum number of allowed
1328 errors. At most reg(P1) errors will be reported.
1329 In other words, the analysis stops as soon as reg(P1) errors are
1330 seen. Reg(P1) is updated with the number of errors remaining.</p>
1331
1332 <p>The root page numbers of all tables in the database are integers
1333 stored in P4_INTARRAY argument.</p>
1334
1335 <p>If P5 is not zero, the check is done on the auxiliary database
1336 file, not the main database file.</p>
1337
1338 <p>This opcode is used to implement the integrity_check pragma.</td></tr>
1339 <tr><td valign="top" align="center">
1340 <a name="IsNull"></a>IsNull
1341 <td>Jump to P2 if the value in register P1 is NULL.</td></tr>
1342 <tr><td valign="top" align="center">
1343 <a name="IsTrue"></a>IsTrue
1344 <td>This opcode implements the IS TRUE, IS FALSE, IS NOT TRUE, and
1345 IS NOT FALSE operators.</p>
1346
1347 <p>Interpret the value in register P1 as a boolean value. Store that
1348 boolean (a 0 or 1) in register P2. Or if the value in register P1 is
1349 NULL, then the P3 is stored in register P2. Invert the answer if P4
1350 is 1.</p>
1351
1352 <p>The logic is summarized like this:</p>
1353
1354 <p><ul>
1355 <li> If P3==0 and P4==0 then r&#91;P2&#93; := r&#91;P1&#93; IS TRUE
1356 <li> If P3==1 and P4==1 then r&#91;P2&#93; := r&#91;P1&#93; IS FALSE
1357 <li> If P3==0 and P4==1 then r&#91;P2&#93; := r&#91;P1&#93; IS NOT TRUE
1358 <li> If P3==1 and P4==0 then r&#91;P2&#93; := r&#91;P1&#93; IS NOT FALSE
1359 </ul></td></tr>
1360 <tr><td valign="top" align="center">
1361 <a name="IsType"></a>IsType
1362 <td>Jump to P2 if the type of a column in a btree is one of the types specified
1363 by the P5 bitmask.</p>
1364
1365 <p>P1 is normally a cursor on a btree for which the row decode cache is
1366 valid through at least column P3. In other words, there should have been
1367 a prior <a href="opcode.html#Column">Column</a> for column P3 or greater. If the cursor is not valid,
1368 then this opcode might give spurious results.
1369 The the btree row has fewer than P3 columns, then use P4 as the
1370 datatype.</p>
1371
1372 <p>If P1 is -1, then P3 is a register number and the datatype is taken
1373 from the value in that register.</p>
1374
1375 <p>P5 is a bitmask of data types. SQLITE_INTEGER is the least significant
1376 (0x01) bit. SQLITE_FLOAT is the 0x02 bit. SQLITE_TEXT is 0x04.
1377 SQLITE_BLOB is 0x08. SQLITE_NULL is 0x10.</p>
1378
1379 <p>WARNING: This opcode does not reliably distinguish between NULL and REAL
1380 when P1&gt;=0. If the database contains a NaN value, this opcode will think
1381 that the datatype is REAL when it should be NULL. When P1&lt;0 and the value
1382 is already stored in register P3, then this opcode does reliably
1383 distinguish between NULL and REAL. The problem only arises then P1&gt;=0.</p>
1384
1385 <p>Take the jump to address P2 if and only if the datatype of the
1386 value determined by P1 and P3 corresponds to one of the bits in the
1387 P5 bitmask.</p></td></tr>
1388 <tr><td valign="top" align="center">
1389 <a name="JournalMode"></a>JournalMode
1390 <td>Change the journal mode of database P1 to P3. P3 must be one of the
1391 PAGER_JOURNALMODE_XXX values. If changing between the various rollback
1392 modes (delete, truncate, persist, off and memory), this is a simple
1393 operation. No IO is required.</p>
1394
1395 <p>If changing into or out of WAL mode the procedure is more complicated.</p>
1396
1397 <p>Write a string containing the final journal-mode to register P2.</td></tr>
1398 <tr><td valign="top" align="center">
1399 <a name="Jump"></a>Jump
1400 <td>Jump to the instruction at address P1, P2, or P3 depending on whether
1401 in the most recent <a href="opcode.html#Compare">Compare</a> instruction the P1 vector was less than,
1402 equal to, or greater than the P2 vector, respectively.</p>
1403
1404 <p>This opcode must immediately follow an <a href="opcode.html#Compare">Compare</a> opcode.</td></tr>
1405 <tr><td valign="top" align="center">
1406 <a name="Last"></a>Last
1407 <td>The next use of the <a href="opcode.html#Rowid">Rowid</a> or <a href="opcode.html#Column">Column</a> or <a href="opcode.html#Prev">Prev</a> instruction for P1
1408 will refer to the last entry in the database table or index.
1409 If the table or index is empty and P2&gt;0, then jump immediately to P2.
1410 If P2 is 0 or if the table or index is not empty, fall through
1411 to the following instruction.</p>
1412
1413 <p>This opcode leaves the cursor configured to move in reverse order,
1414 from the end toward the beginning. In other words, the cursor is
1415 configured to use <a href="opcode.html#Prev">Prev</a>, not <a href="opcode.html#Next">Next</a>.</td></tr>
1416 <tr><td valign="top" align="center">
1417 <a name="Le"></a>Le
1418 <td>This works just like the Lt opcode except that the jump is taken if
1419 the content of register P3 is less than or equal to the content of
1420 register P1. See the Lt opcode for additional information.</td></tr>
1421 <tr><td valign="top" align="center">
1422 <a name="LoadAnalysis"></a>LoadAnalysis
1423 <td>Read the sqlite_stat1 table for database P1 and load the content
1424 of that table into the internal index hash table. This will cause
1425 the analysis to be used when preparing all subsequent queries.</td></tr>
1426 <tr><td valign="top" align="center">
1427 <a name="Lt"></a>Lt
1428 <td>Compare the values in register P1 and P3. If reg(P3)&lt;reg(P1) then
1429 jump to address P2.</p>
1430
1431 <p>If the SQLITE_JUMPIFNULL bit of P5 is set and either reg(P1) or
1432 reg(P3) is NULL then the take the jump. If the SQLITE_JUMPIFNULL
1433 bit is clear then fall through if either operand is NULL.</p>
1434
1435 <p>The SQLITE_AFF_MASK portion of P5 must be an affinity character -
1436 SQLITE_AFF_TEXT, SQLITE_AFF_INTEGER, and so forth. An attempt is made
1437 to coerce both inputs according to this affinity before the
1438 comparison is made. If the SQLITE_AFF_MASK is 0x00, then numeric
1439 affinity is used. Note that the affinity conversions are stored
1440 back into the input registers P1 and P3. So this opcode can cause
1441 persistent changes to registers P1 and P3.</p>
1442
1443 <p>Once any conversions have taken place, and neither value is NULL,
1444 the values are compared. If both values are blobs then memcmp() is
1445 used to determine the results of the comparison. If both values
1446 are text, then the appropriate collating function specified in
1447 P4 is used to do the comparison. If P4 is not specified then
1448 memcmp() is used to compare text string. If both values are
1449 numeric, then a numeric comparison is used. If the two values
1450 are of different types, then numbers are considered less than
1451 strings and strings are considered less than blobs.</p>
1452
1453 <p>This opcode saves the result of comparison for use by the new
1454 <a href="opcode.html#Jump">Jump</a> opcode.</td></tr>
1455 <tr><td valign="top" align="center">
1456 <a name="MakeRecord"></a>MakeRecord
1457 <td>Convert P2 registers beginning with P1 into the <a href="fileformat2.html#record_format">record format</a>
1458 use as a data record in a database table or as a key
1459 in an index. The <a href="opcode.html#Column">Column</a> opcode can decode the record later.</p>
1460
1461 <p>P4 may be a string that is P2 characters long. The N-th character of the
1462 string indicates the column affinity that should be used for the N-th
1463 field of the index key.</p>
1464
1465 <p>The mapping from character to affinity is given by the SQLITE_AFF_
1466 macros defined in sqliteInt.h.</p>
1467
1468 <p>If P4 is NULL then all index fields have the affinity BLOB.</p>
1469
1470 <p>The meaning of P5 depends on whether or not the SQLITE_ENABLE_NULL_TRIM
1471 compile-time option is enabled:</p>
1472
1473 <p>* If SQLITE_ENABLE_NULL_TRIM is enabled, then the P5 is the index
1474 of the right-most table that can be null-trimmed.</p>
1475
1476 <p>* If SQLITE_ENABLE_NULL_TRIM is omitted, then P5 has the value
1477 OPFLAG_NOCHNG_MAGIC if the <a href="opcode.html#MakeRecord">MakeRecord</a> opcode is allowed to
1478 accept no-change records with serial_type 10. This value is
1479 only used inside an assert() and does not affect the end result.</td></tr>
1480 <tr><td valign="top" align="center">
1481 <a name="MaxPgcnt"></a>MaxPgcnt
1482 <td>Try to set the maximum page count for database P1 to the value in P3.
1483 Do not let the maximum page count fall below the current page count and
1484 do not change the maximum page count value if P3==0.</p>
1485
1486 <p>Store the maximum page count after the change in register P2.</td></tr>
1487 <tr><td valign="top" align="center">
1488 <a name="MemMax"></a>MemMax
1489 <td>P1 is a register in the root frame of this VM (the root frame is
1490 different from the current frame if this instruction is being executed
1491 within a sub-program). Set the value of register P1 to the maximum of
1492 its current value and the value in register P2.</p>
1493
1494 <p>This instruction throws an error if the memory cell is not initially
1495 an integer.</td></tr>
1496 <tr><td valign="top" align="center">
1497 <a name="Move"></a>Move
1498 <td>Move the P3 values in register P1..P1+P3-1 over into
1499 registers P2..P2+P3-1. Registers P1..P1+P3-1 are
1500 left holding a NULL. It is an error for register ranges
1501 P1..P1+P3-1 and P2..P2+P3-1 to overlap. It is an error
1502 for P3 to be less than 1.</td></tr>
1503 <tr><td valign="top" align="center">
1504 <a name="Multiply"></a>Multiply
1505 <td>Multiply the value in register P1 by the value in register P2
1506 and store the result in register P3.
1507 If either input is NULL, the result is NULL.</td></tr>
1508 <tr><td valign="top" align="center">
1509 <a name="MustBeInt"></a>MustBeInt
1510 <td>Force the value in register P1 to be an integer. If the value
1511 in P1 is not an integer and cannot be converted into an integer
1512 without data loss, then jump immediately to P2, or if P2==0
1513 raise an SQLITE_MISMATCH exception.</td></tr>
1514 <tr><td valign="top" align="center">
1515 <a name="Ne"></a>Ne
1516 <td>This works just like the Eq opcode except that the jump is taken if
1517 the operands in registers P1 and P3 are not equal. See the Eq opcode for
1518 additional information.</td></tr>
1519 <tr><td valign="top" align="center">
1520 <a name="NewRowid"></a>NewRowid
1521 <td>Get a new integer record number (a.k.a "rowid") used as the key to a table.
1522 The record number is not previously used as a key in the database
1523 table that cursor P1 points to. The new record number is written
1524 written to register P2.</p>
1525
1526 <p>If P3&gt;0 then P3 is a register in the root frame of this VDBE that holds
1527 the largest previously generated record number. No new record numbers are
1528 allowed to be less than this value. When this value reaches its maximum,
1529 an SQLITE_FULL error is generated. The P3 register is updated with the '
1530 generated record number. This P3 mechanism is used to help implement the
1531 AUTOINCREMENT feature.</td></tr>
1532 <tr><td valign="top" align="center">
1533 <a name="Next"></a>Next
1534 <td>Advance cursor P1 so that it points to the next key/data pair in its
1535 table or index. If there are no more key/value pairs then fall through
1536 to the following instruction. But if the cursor advance was successful,
1537 jump immediately to P2.</p>
1538
1539 <p>The <a href="opcode.html#Next">Next</a> opcode is only valid following an <a href="opcode.html#SeekGT">SeekGT</a>, <a href="opcode.html#SeekGE">SeekGE</a>, or
1540 <a href="opcode.html#Rewind">Rewind</a> opcode used to position the cursor. <a href="opcode.html#Next">Next</a> is not allowed
1541 to follow <a href="opcode.html#SeekLT">SeekLT</a>, <a href="opcode.html#SeekLE">SeekLE</a>, or <a href="opcode.html#Last">Last</a>.</p>
1542
1543 <p>The P1 cursor must be for a real table, not a pseudo-table. P1 must have
1544 been opened prior to this opcode or the program will segfault.</p>
1545
1546 <p>The P3 value is a hint to the btree implementation. If P3==1, that
1547 means P1 is an SQL index and that this instruction could have been
1548 omitted if that index had been unique. P3 is usually 0. P3 is
1549 always either 0 or 1.</p>
1550
1551 <p>If P5 is positive and the jump is taken, then event counter
1552 number P5-1 in the prepared statement is incremented.</p>
1553
1554 <p>See also: <a href="opcode.html#Prev">Prev</a></td></tr>
1555 <tr><td valign="top" align="center">
1556 <a name="NoConflict"></a>NoConflict
1557 <td>If P4==0 then register P3 holds a blob constructed by <a href="opcode.html#MakeRecord">MakeRecord</a>. If
1558 P4&gt;0 then register P3 is the first of P4 registers that form an unpacked
1559 record.</p>
1560
1561 <p>Cursor P1 is on an index btree. If the record identified by P3 and P4
1562 contains any NULL value, jump immediately to P2. If all terms of the
1563 record are not-NULL then a check is done to determine if any row in the
1564 P1 index btree has a matching key prefix. If there are no matches, jump
1565 immediately to P2. If there is a match, fall through and leave the P1
1566 cursor pointing to the matching row.</p>
1567
1568 <p>This opcode is similar to <a href="opcode.html#NotFound">NotFound</a> with the exceptions that the
1569 branch is always taken if any part of the search key input is NULL.</p>
1570
1571 <p>This operation leaves the cursor in a state where it cannot be
1572 advanced in either direction. In other words, the <a href="opcode.html#Next">Next</a> and <a href="opcode.html#Prev">Prev</a>
1573 opcodes do not work after this operation.</p>
1574
1575 <p>See also: <a href="opcode.html#NotFound">NotFound</a>, <a href="opcode.html#Found">Found</a>, <a href="opcode.html#NotExists">NotExists</a></td></tr>
1576 <tr><td valign="top" align="center">
1577 <a name="Noop"></a>Noop
1578 <td>Do nothing. This instruction is often useful as a jump
1579 destination.</td></tr>
1580 <tr><td valign="top" align="center">
1581 <a name="Not"></a>Not
1582 <td>Interpret the value in register P1 as a boolean value. Store the
1583 boolean complement in register P2. If the value in register P1 is
1584 NULL, then a NULL is stored in P2.</td></tr>
1585 <tr><td valign="top" align="center">
1586 <a name="NotExists"></a>NotExists
1587 <td>P1 is the index of a cursor open on an SQL table btree (with integer
1588 keys). P3 is an integer rowid. If P1 does not contain a record with
1589 rowid P3 then jump immediately to P2. Or, if P2 is 0, raise an
1590 SQLITE_CORRUPT error. If P1 does contain a record with rowid P3 then
1591 leave the cursor pointing at that record and fall through to the next
1592 instruction.</p>
1593
1594 <p>The <a href="opcode.html#SeekRowid">SeekRowid</a> opcode performs the same operation but also allows the
1595 P3 register to contain a non-integer value, in which case the jump is
1596 always taken. This opcode requires that P3 always contain an integer.</p>
1597
1598 <p>The <a href="opcode.html#NotFound">NotFound</a> opcode performs the same operation on index btrees
1599 (with arbitrary multi-value keys).</p>
1600
1601 <p>This opcode leaves the cursor in a state where it cannot be advanced
1602 in either direction. In other words, the <a href="opcode.html#Next">Next</a> and <a href="opcode.html#Prev">Prev</a> opcodes will
1603 not work following this opcode.</p>
1604
1605 <p>See also: <a href="opcode.html#Found">Found</a>, <a href="opcode.html#NotFound">NotFound</a>, <a href="opcode.html#NoConflict">NoConflict</a>, <a href="opcode.html#SeekRowid">SeekRowid</a></td></tr>
1606 <tr><td valign="top" align="center">
1607 <a name="NotFound"></a>NotFound
1608 <td>If P4==0 then register P3 holds a blob constructed by <a href="opcode.html#MakeRecord">MakeRecord</a>. If
1609 P4&gt;0 then register P3 is the first of P4 registers that form an unpacked
1610 record.</p>
1611
1612 <p>Cursor P1 is on an index btree. If the record identified by P3 and P4
1613 is not the prefix of any entry in P1 then a jump is made to P2. If P1
1614 does contain an entry whose prefix matches the P3/P4 record then control
1615 falls through to the next instruction and P1 is left pointing at the
1616 matching entry.</p>
1617
1618 <p>This operation leaves the cursor in a state where it cannot be
1619 advanced in either direction. In other words, the <a href="opcode.html#Next">Next</a> and <a href="opcode.html#Prev">Prev</a>
1620 opcodes do not work after this operation.</p>
1621
1622 <p>See also: <a href="opcode.html#Found">Found</a>, <a href="opcode.html#NotExists">NotExists</a>, <a href="opcode.html#NoConflict">NoConflict</a>, <a href="opcode.html#IfNoHope">IfNoHope</a></td></tr>
1623 <tr><td valign="top" align="center">
1624 <a name="NotNull"></a>NotNull
1625 <td>Jump to P2 if the value in register P1 is not NULL.</td></tr>
1626 <tr><td valign="top" align="center">
1627 <a name="Null"></a>Null
1628 <td>Write a NULL into registers P2. If P3 greater than P2, then also write
1629 NULL into register P3 and every register in between P2 and P3. If P3
1630 is less than P2 (typically P3 is zero) then only register P2 is
1631 set to NULL.</p>
1632
1633 <p>If the P1 value is non-zero, then also set the MEM_Cleared flag so that
1634 NULL values will not compare equal even if SQLITE_NULLEQ is set on
1635 <a href="opcode.html#Ne">Ne</a> or <a href="opcode.html#Eq">Eq</a>.</td></tr>
1636 <tr><td valign="top" align="center">
1637 <a name="NullRow"></a>NullRow
1638 <td>Move the cursor P1 to a null row. Any <a href="opcode.html#Column">Column</a> operations
1639 that occur while the cursor is on the null row will always
1640 write a NULL.</p>
1641
1642 <p>If cursor P1 is not previously opened, open it now to a special
1643 pseudo-cursor that always returns NULL for every column.</td></tr>
1644 <tr><td valign="top" align="center">
1645 <a name="Offset"></a>Offset
1646 <td>Store in register r&#91;P3&#93; the byte offset into the database file that is the
1647 start of the payload for the record at which that cursor P1 is currently
1648 pointing.</p>
1649
1650 <p>P2 is the column number for the argument to the sqlite_offset() function.
1651 This opcode does not use P2 itself, but the P2 value is used by the
1652 code generator. The P1, P2, and P3 operands to this opcode are the
1653 same as for <a href="opcode.html#Column">Column</a>.</p>
1654
1655 <p>This opcode is only available if SQLite is compiled with the
1656 -DSQLITE_ENABLE_OFFSET_SQL_FUNC option.</td></tr>
1657 <tr><td valign="top" align="center">
1658 <a name="OffsetLimit"></a>OffsetLimit
1659 <td>This opcode performs a commonly used computation associated with
1660 LIMIT and OFFSET processing. r&#91;P1&#93; holds the limit counter. r&#91;P3&#93;
1661 holds the offset counter. The opcode computes the combined value
1662 of the LIMIT and OFFSET and stores that value in r&#91;P2&#93;. The r&#91;P2&#93;
1663 value computed is the total number of rows that will need to be
1664 visited in order to complete the query.</p>
1665
1666 <p>If r&#91;P3&#93; is zero or negative, that means there is no OFFSET
1667 and r&#91;P2&#93; is set to be the value of the LIMIT, r&#91;P1&#93;.</p>
1668
1669 <p>if r&#91;P1&#93; is zero or negative, that means there is no LIMIT
1670 and r&#91;P2&#93; is set to -1.</p>
1671
1672 <p>Otherwise, r&#91;P2&#93; is set to the sum of r&#91;P1&#93; and r&#91;P3&#93;.</td></tr>
1673 <tr><td valign="top" align="center">
1674 <a name="Once"></a>Once
1675 <td>Fall through to the next instruction the first time this opcode is
1676 encountered on each invocation of the byte-code program. <a href="opcode.html#Jump">Jump</a> to P2
1677 on the second and all subsequent encounters during the same invocation.</p>
1678
1679 <p>Top-level programs determine first invocation by comparing the P1
1680 operand against the P1 operand on the <a href="opcode.html#Init">Init</a> opcode at the beginning
1681 of the program. If the P1 values differ, then fall through and make
1682 the P1 of this opcode equal to the P1 of <a href="opcode.html#Init">Init</a>. If P1 values are
1683 the same then take the jump.</p>
1684
1685 <p>For subprograms, there is a bitmask in the VdbeFrame that determines
1686 whether or not the jump should be taken. The bitmask is necessary
1687 because the self-altering code trick does not work for recursive
1688 triggers.</td></tr>
1689 <tr><td valign="top" align="center">
1690 <a name="OpenAutoindex"></a>OpenAutoindex
1691 <td>This opcode works the same as <a href="opcode.html#OpenEphemeral">OpenEphemeral</a>. It has a
1692 different name to distinguish its use. Tables created using
1693 by this opcode will be used for automatically created transient
1694 indices in joins.</td></tr>
1695 <tr><td valign="top" align="center">
1696 <a name="OpenDup"></a>OpenDup
1697 <td>Open a new cursor P1 that points to the same ephemeral table as
1698 cursor P2. The P2 cursor must have been opened by a prior <a href="opcode.html#OpenEphemeral">OpenEphemeral</a>
1699 opcode. Only ephemeral cursors may be duplicated.</p>
1700
1701 <p>Duplicate ephemeral cursors are used for self-joins of materialized views.</td></tr>
1702 <tr><td valign="top" align="center">
1703 <a name="OpenEphemeral"></a>OpenEphemeral
1704 <td>Open a new cursor P1 to a transient table.
1705 The cursor is always opened read/write even if
1706 the main database is read-only. The ephemeral
1707 table is deleted automatically when the cursor is closed.</p>
1708
1709 <p>If the cursor P1 is already opened on an ephemeral table, the table
1710 is cleared (all content is erased).</p>
1711
1712 <p>P2 is the number of columns in the ephemeral table.
1713 The cursor points to a BTree table if P4==0 and to a BTree index
1714 if P4 is not 0. If P4 is not NULL, it points to a KeyInfo structure
1715 that defines the format of keys in the index.</p>
1716
1717 <p>The P5 parameter can be a mask of the BTREE_* flags defined
1718 in btree.h. These flags control aspects of the operation of
1719 the btree. The BTREE_OMIT_JOURNAL and BTREE_SINGLE flags are
1720 added automatically.</p>
1721
1722 <p>If P3 is positive, then reg&#91;P3&#93; is modified slightly so that it
1723 can be used as zero-length data for <a href="opcode.html#Insert">Insert</a>. This is an optimization
1724 that avoids an extra <a href="opcode.html#Blob">Blob</a> opcode to initialize that register.</td></tr>
1725 <tr><td valign="top" align="center">
1726 <a name="OpenPseudo"></a>OpenPseudo
1727 <td>Open a new cursor that points to a fake table that contains a single
1728 row of data. The content of that one row is the content of memory
1729 register P2. In other words, cursor P1 becomes an alias for the
1730 MEM_Blob content contained in register P2.</p>
1731
1732 <p>A pseudo-table created by this opcode is used to hold a single
1733 row output from the sorter so that the row can be decomposed into
1734 individual columns using the <a href="opcode.html#Column">Column</a> opcode. The <a href="opcode.html#Column">Column</a> opcode
1735 is the only cursor opcode that works with a pseudo-table.</p>
1736
1737 <p>P3 is the number of fields in the records that will be stored by
1738 the pseudo-table. If P2 is 0 or negative then the pseudo-cursor
1739 will return NULL for every column.</td></tr>
1740 <tr><td valign="top" align="center">
1741 <a name="OpenRead"></a>OpenRead
1742 <td>Open a read-only cursor for the database table whose root page is
1743 P2 in a database file. The database file is determined by P3.
1744 P3==0 means the main database, P3==1 means the database used for
1745 temporary tables, and P3&gt;1 means used the corresponding attached
1746 database. Give the new cursor an identifier of P1. The P1
1747 values need not be contiguous but all P1 values should be small integers.
1748 It is an error for P1 to be negative.</p>
1749
1750 <p>Allowed P5 bits:
1751 <ul>
1752 <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
1753 equality lookups (implemented as a pair of opcodes <a href="opcode.html#SeekGE">SeekGE</a>/<a href="opcode.html#IdxGT">IdxGT</a>
1754 of <a href="opcode.html#SeekLE">SeekLE</a>/<a href="opcode.html#IdxLT">IdxLT</a>)
1755 </ul></p>
1756
1757 <p>The P4 value may be either an integer (P4_INT32) or a pointer to
1758 a KeyInfo structure (P4_KEYINFO). If it is a pointer to a KeyInfo
1759 object, then table being opened must be an <a href="fileformat2.html#btypes">index b-tree</a> where the
1760 KeyInfo object defines the content and collating
1761 sequence of that index b-tree. Otherwise, if P4 is an integer
1762 value, then the table being opened must be a <a href="fileformat2.html#btypes">table b-tree</a> with a
1763 number of columns no less than the value of P4.</p>
1764
1765 <p>See also: <a href="opcode.html#OpenWrite">OpenWrite</a>, <a href="opcode.html#ReopenIdx">ReopenIdx</a></td></tr>
1766 <tr><td valign="top" align="center">
1767 <a name="OpenWrite"></a>OpenWrite
1768 <td>Open a read/write cursor named P1 on the table or index whose root
1769 page is P2 (or whose root page is held in register P2 if the
1770 OPFLAG_P2ISREG bit is set in P5 - see below).</p>
1771
1772 <p>The P4 value may be either an integer (P4_INT32) or a pointer to
1773 a KeyInfo structure (P4_KEYINFO). If it is a pointer to a KeyInfo
1774 object, then table being opened must be an <a href="fileformat2.html#btypes">index b-tree</a> where the
1775 KeyInfo object defines the content and collating
1776 sequence of that index b-tree. Otherwise, if P4 is an integer
1777 value, then the table being opened must be a <a href="fileformat2.html#btypes">table b-tree</a> with a
1778 number of columns no less than the value of P4.</p>
1779
1780 <p>Allowed P5 bits:
1781 <ul>
1782 <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
1783 equality lookups (implemented as a pair of opcodes <a href="opcode.html#SeekGE">SeekGE</a>/<a href="opcode.html#IdxGT">IdxGT</a>
1784 of <a href="opcode.html#SeekLE">SeekLE</a>/<a href="opcode.html#IdxLT">IdxLT</a>)
1785 <li> <b>0x08 OPFLAG_FORDELETE</b>: This cursor is used only to seek
1786 and subsequently delete entries in an index btree. This is a
1787 hint to the storage engine that the storage engine is allowed to
1788 ignore. The hint is not used by the official SQLite b*tree storage
1789 engine, but is used by COMDB2.
1790 <li> <b>0x10 OPFLAG_P2ISREG</b>: Use the content of register P2
1791 as the root page, not the value of P2 itself.
1792 </ul></p>
1793
1794 <p>This instruction works like <a href="opcode.html#OpenRead">OpenRead</a> except that it opens the cursor
1795 in read/write mode.</p>
1796
1797 <p>See also: <a href="opcode.html#OpenRead">OpenRead</a>, <a href="opcode.html#ReopenIdx">ReopenIdx</a></td></tr>
1798 <tr><td valign="top" align="center">
1799 <a name="Or"></a>Or
1800 <td>Take the logical OR of the values in register P1 and P2 and
1801 store the answer in register P3.</p>
1802
1803 <p>If either P1 or P2 is nonzero (true) then the result is 1 (true)
1804 even if the other input is NULL. A NULL and false or two NULLs
1805 give a NULL output.</td></tr>
1806 <tr><td valign="top" align="center">
1807 <a name="Pagecount"></a>Pagecount
1808 <td>Write the current number of pages in database P1 to memory cell P2.</td></tr>
1809 <tr><td valign="top" align="center">
1810 <a name="Param"></a>Param
1811 <td>This opcode is only ever present in sub-programs called via the
1812 <a href="opcode.html#Program">Program</a> instruction. <a href="opcode.html#Copy">Copy</a> a value currently stored in a memory
1813 cell of the calling (parent) frame to cell P2 in the current frames
1814 address space. This is used by trigger programs to access the new.*
1815 and old.* values.</p>
1816
1817 <p>The address of the cell in the parent frame is determined by adding
1818 the value of the P1 argument to the value of the P1 argument to the
1819 calling <a href="opcode.html#Program">Program</a> instruction.</td></tr>
1820 <tr><td valign="top" align="center">
1821 <a name="ParseSchema"></a>ParseSchema
1822 <td>Read and parse all entries from the schema table of database P1
1823 that match the WHERE clause P4. If P4 is a NULL pointer, then the
1824 entire schema for P1 is reparsed.</p>
1825
1826 <p>This opcode invokes the parser to create a new virtual machine,
1827 then runs the new virtual machine. It is thus a re-entrant opcode.</td></tr>
1828 <tr><td valign="top" align="center">
1829 <a name="Permutation"></a>Permutation
1830 <td>Set the permutation used by the <a href="opcode.html#Compare">Compare</a> operator in the next
1831 instruction. The permutation is stored in the P4 operand.</p>
1832
1833 <p>The permutation is only valid for the next opcode which must be
1834 an <a href="opcode.html#Compare">Compare</a> that has the OPFLAG_PERMUTE bit set in P5.</p>
1835
1836 <p>The first integer in the P4 integer array is the length of the array
1837 and does not become part of the permutation.</td></tr>
1838 <tr><td valign="top" align="center">
1839 <a name="Prev"></a>Prev
1840 <td>Back up cursor P1 so that it points to the previous key/data pair in its
1841 table or index. If there is no previous key/value pairs then fall through
1842 to the following instruction. But if the cursor backup was successful,
1843 jump immediately to P2.</p>
1844
1845 <p>The <a href="opcode.html#Prev">Prev</a> opcode is only valid following an <a href="opcode.html#SeekLT">SeekLT</a>, <a href="opcode.html#SeekLE">SeekLE</a>, or
1846 <a href="opcode.html#Last">Last</a> opcode used to position the cursor. <a href="opcode.html#Prev">Prev</a> is not allowed
1847 to follow <a href="opcode.html#SeekGT">SeekGT</a>, <a href="opcode.html#SeekGE">SeekGE</a>, or <a href="opcode.html#Rewind">Rewind</a>.</p>
1848
1849 <p>The P1 cursor must be for a real table, not a pseudo-table. If P1 is
1850 not open then the behavior is undefined.</p>
1851
1852 <p>The P3 value is a hint to the btree implementation. If P3==1, that
1853 means P1 is an SQL index and that this instruction could have been
1854 omitted if that index had been unique. P3 is usually 0. P3 is
1855 always either 0 or 1.</p>
1856
1857 <p>If P5 is positive and the jump is taken, then event counter
1858 number P5-1 in the prepared statement is incremented.</td></tr>
1859 <tr><td valign="top" align="center">
1860 <a name="Program"></a>Program
1861 <td>Execute the trigger program passed as P4 (type P4_SUBPROGRAM).</p>
1862
1863 <p>P1 contains the address of the memory cell that contains the first memory
1864 cell in an array of values used as arguments to the sub-program. P2
1865 contains the address to jump to if the sub-program throws an IGNORE
1866 exception using the RAISE() function. P2 might be zero, if there is
1867 no possibility that an IGNORE exception will be raised.
1868 Register P3 contains the address
1869 of a memory cell in this (the parent) VM that is used to allocate the
1870 memory required by the sub-vdbe at runtime.</p>
1871
1872 <p>P4 is a pointer to the VM containing the trigger program.</p>
1873
1874 <p>If P5 is non-zero, then recursive program invocation is enabled.</td></tr>
1875 <tr><td valign="top" align="center">
1876 <a name="PureFunc"></a>PureFunc
1877 <td>Invoke a user function (P4 is a pointer to an sqlite3_context object that
1878 contains a pointer to the function to be run) with arguments taken
1879 from register P2 and successors. The number of arguments is in
1880 the sqlite3_context object that P4 points to.
1881 The result of the function is stored
1882 in register P3. Register P3 must not be one of the function inputs.</p>
1883
1884 <p>P1 is a 32-bit bitmask indicating whether or not each argument to the
1885 function was determined to be constant at compile time. If the first
1886 argument was constant then bit 0 of P1 is set. This is used to determine
1887 whether meta data associated with a user function argument using the
1888 sqlite3_set_auxdata() API may be safely retained until the next
1889 invocation of this opcode.</p>
1890
1891 <p>This opcode works exactly like <a href="opcode.html#Function">Function</a>. The only difference is in
1892 its name. This opcode is used in places where the function must be
1893 purely non-deterministic. Some built-in date/time functions can be
1894 either deterministic of non-deterministic, depending on their arguments.
1895 When those function are used in a non-deterministic way, they will check
1896 to see if they were called using <a href="opcode.html#PureFunc">PureFunc</a> instead of <a href="opcode.html#Function">Function</a>, and
1897 if they were, they throw an error.</p>
1898
1899 <p>See also: <a href="opcode.html#AggStep">AggStep</a>, <a href="opcode.html#AggFinal">AggFinal</a>, <a href="opcode.html#Function">Function</a></td></tr>
1900 <tr><td valign="top" align="center">
1901 <a name="ReadCookie"></a>ReadCookie
1902 <td>Read cookie number P3 from database P1 and write it into register P2.
1903 P3==1 is the schema version. P3==2 is the database format.
1904 P3==3 is the recommended pager cache size, and so forth. P1==0 is
1905 the main database file and P1==1 is the database file used to store
1906 temporary tables.</p>
1907
1908 <p>There must be a read-lock on the database (either a transaction
1909 must be started or there must be an open cursor) before
1910 executing this instruction.</td></tr>
1911 <tr><td valign="top" align="center">
1912 <a name="Real"></a>Real
1913 <td>P4 is a pointer to a 64-bit floating point value.
1914 Write that value into register P2.</td></tr>
1915 <tr><td valign="top" align="center">
1916 <a name="RealAffinity"></a>RealAffinity
1917 <td>If register P1 holds an integer convert it to a real value.</p>
1918
1919 <p>This opcode is used when extracting information from a column that
1920 has REAL affinity. Such column values may still be stored as
1921 integers, for space efficiency, but after extraction we want them
1922 to have only a real value.</td></tr>
1923 <tr><td valign="top" align="center">
1924 <a name="ReleaseReg"></a>ReleaseReg
1925 <td>Release registers from service. Any content that was in the
1926 the registers is unreliable after this opcode completes.</p>
1927
1928 <p>The registers released will be the P2 registers starting at P1,
1929 except if bit ii of P3 set, then do not release register P1+ii.
1930 In other words, P3 is a mask of registers to preserve.</p>
1931
1932 <p>Releasing a register clears the Mem.pScopyFrom pointer. That means
1933 that if the content of the released register was set using <a href="opcode.html#SCopy">SCopy</a>,
1934 a change to the value of the source register for the <a href="opcode.html#SCopy">SCopy</a> will no longer
1935 generate an assertion fault in sqlite3VdbeMemAboutToChange().</p>
1936
1937 <p>If P5 is set, then all released registers have their type set
1938 to MEM_Undefined so that any subsequent attempt to read the released
1939 register (before it is reinitialized) will generate an assertion fault.</p>
1940
1941 <p>P5 ought to be set on every call to this opcode.
1942 However, there are places in the code generator will release registers
1943 before their are used, under the (valid) assumption that the registers
1944 will not be reallocated for some other purpose before they are used and
1945 hence are safe to release.</p>
1946
1947 <p>This opcode is only available in testing and debugging builds. It is
1948 not generated for release builds. The purpose of this opcode is to help
1949 validate the generated bytecode. This opcode does not actually contribute
1950 to computing an answer.</td></tr>
1951 <tr><td valign="top" align="center">
1952 <a name="Remainder"></a>Remainder
1953 <td>Compute the remainder after integer register P2 is divided by
1954 register P1 and store the result in register P3.
1955 If the value in register P1 is zero the result is NULL.
1956 If either operand is NULL, the result is NULL.</td></tr>
1957 <tr><td valign="top" align="center">
1958 <a name="ReopenIdx"></a>ReopenIdx
1959 <td>The <a href="opcode.html#ReopenIdx">ReopenIdx</a> opcode works like <a href="opcode.html#OpenRead">OpenRead</a> except that it first
1960 checks to see if the cursor on P1 is already open on the same
1961 b-tree and if it is this opcode becomes a no-op. In other words,
1962 if the cursor is already open, do not reopen it.</p>
1963
1964 <p>The <a href="opcode.html#ReopenIdx">ReopenIdx</a> opcode may only be used with P5==0 or P5==OPFLAG_SEEKEQ
1965 and with P4 being a P4_KEYINFO object. Furthermore, the P3 value must
1966 be the same as every other <a href="opcode.html#ReopenIdx">ReopenIdx</a> or <a href="opcode.html#OpenRead">OpenRead</a> for the same cursor
1967 number.</p>
1968
1969 <p>Allowed P5 bits:
1970 <ul>
1971 <li> <b>0x02 OPFLAG_SEEKEQ</b>: This cursor will only be used for
1972 equality lookups (implemented as a pair of opcodes <a href="opcode.html#SeekGE">SeekGE</a>/<a href="opcode.html#IdxGT">IdxGT</a>
1973 of <a href="opcode.html#SeekLE">SeekLE</a>/<a href="opcode.html#IdxLT">IdxLT</a>)
1974 </ul></p>
1975
1976 <p>See also: <a href="opcode.html#OpenRead">OpenRead</a>, <a href="opcode.html#OpenWrite">OpenWrite</a></td></tr>
1977 <tr><td valign="top" align="center">
1978 <a name="ResetCount"></a>ResetCount
1979 <td>The value of the change counter is copied to the database handle
1980 change counter (returned by subsequent calls to sqlite3_changes()).
1981 Then the VMs internal change counter resets to 0.
1982 This is used by trigger programs.</td></tr>
1983 <tr><td valign="top" align="center">
1984 <a name="ResetSorter"></a>ResetSorter
1985 <td>Delete all contents from the ephemeral table or sorter
1986 that is open on cursor P1.</p>
1987
1988 <p>This opcode only works for cursors used for sorting and
1989 opened with <a href="opcode.html#OpenEphemeral">OpenEphemeral</a> or <a href="opcode.html#SorterOpen">SorterOpen</a>.</td></tr>
1990 <tr><td valign="top" align="center">
1991 <a name="ResultRow"></a>ResultRow
1992 <td>The registers P1 through P1+P2-1 contain a single row of
1993 results. This opcode causes the sqlite3_step() call to terminate
1994 with an SQLITE_ROW return code and it sets up the sqlite3_stmt
1995 structure to provide access to the r(P1)..r(P1+P2-1) values as
1996 the result row.</td></tr>
1997 <tr><td valign="top" align="center">
1998 <a name="Return"></a>Return
1999 <td>Jump to the address stored in register P1. If P1 is a return address
2000 register, then this accomplishes a return from a subroutine.</p>
2001
2002 <p>If P3 is 1, then the jump is only taken if register P1 holds an integer
2003 values, otherwise execution falls through to the next opcode, and the
2004 <a href="opcode.html#Return">Return</a> becomes a no-op. If P3 is 0, then register P1 must hold an
2005 integer or else an assert() is raised. P3 should be set to 1 when
2006 this opcode is used in combination with <a href="opcode.html#BeginSubrtn">BeginSubrtn</a>, and set to 0
2007 otherwise.</p>
2008
2009 <p>The value in register P1 is unchanged by this opcode.</p>
2010
2011 <p>P2 is not used by the byte-code engine. However, if P2 is positive
2012 and also less than the current address, then the "EXPLAIN" output
2013 formatter in the CLI will indent all opcodes from the P2 opcode up
2014 to be not including the current <a href="opcode.html#Return">Return</a>. P2 should be the first opcode
2015 in the subroutine from which this opcode is returning. Thus the P2
2016 value is a byte-code indentation hint. See tag-20220407a in
2017 wherecode.c and shell.c.</td></tr>
2018 <tr><td valign="top" align="center">
2019 <a name="Rewind"></a>Rewind
2020 <td>The next use of the <a href="opcode.html#Rowid">Rowid</a> or <a href="opcode.html#Column">Column</a> or <a href="opcode.html#Next">Next</a> instruction for P1
2021 will refer to the first entry in the database table or index.
2022 If the table or index is empty, jump immediately to P2.
2023 If the table or index is not empty, fall through to the following
2024 instruction.</p>
2025
2026 <p>If P2 is zero, that is an assertion that the P1 table is never
2027 empty and hence the jump will never be taken.</p>
2028
2029 <p>This opcode leaves the cursor configured to move in forward order,
2030 from the beginning toward the end. In other words, the cursor is
2031 configured to use <a href="opcode.html#Next">Next</a>, not <a href="opcode.html#Prev">Prev</a>.</td></tr>
2032 <tr><td valign="top" align="center">
2033 <a name="RowCell"></a>RowCell
2034 <td>P1 and P2 are both open cursors. Both must be opened on the same type
2035 of table - intkey or index. This opcode is used as part of copying
2036 the current row from P2 into P1. If the cursors are opened on intkey
2037 tables, register P3 contains the rowid to use with the new record in
2038 P1. If they are opened on index tables, P3 is not used.</p>
2039
2040 <p>This opcode must be followed by either an <a href="opcode.html#Insert">Insert</a> or InsertIdx opcode
2041 with the OPFLAG_PREFORMAT flag set to complete the insert operation.</td></tr>
2042 <tr><td valign="top" align="center">
2043 <a name="RowData"></a>RowData
2044 <td>Write into register P2 the complete row content for the row at
2045 which cursor P1 is currently pointing.
2046 There is no interpretation of the data.
2047 It is just copied onto the P2 register exactly as
2048 it is found in the database file.</p>
2049
2050 <p>If cursor P1 is an index, then the content is the key of the row.
2051 If cursor P2 is a table, then the content extracted is the data.</p>
2052
2053 <p>If the P1 cursor must be pointing to a valid row (not a NULL row)
2054 of a real table, not a pseudo-table.</p>
2055
2056 <p>If P3!=0 then this opcode is allowed to make an ephemeral pointer
2057 into the database page. That means that the content of the output
2058 register will be invalidated as soon as the cursor moves - including
2059 moves caused by other cursors that "save" the current cursors
2060 position in order that they can write to the same table. If P3==0
2061 then a copy of the data is made into memory. P3!=0 is faster, but
2062 P3==0 is safer.</p>
2063
2064 <p>If P3!=0 then the content of the P2 register is unsuitable for use
2065 in OP_Result and any OP_Result will invalidate the P2 register content.
2066 The P2 register content is invalidated by opcodes like <a href="opcode.html#Function">Function</a> or
2067 by any use of another cursor pointing to the same table.</td></tr>
2068 <tr><td valign="top" align="center">
2069 <a name="Rowid"></a>Rowid
2070 <td>Store in register P2 an integer which is the key of the table entry that
2071 P1 is currently point to.</p>
2072
2073 <p>P1 can be either an ordinary table or a virtual table. There used to
2074 be a separate OP_VRowid opcode for use with virtual tables, but this
2075 one opcode now works for both table types.</td></tr>
2076 <tr><td valign="top" align="center">
2077 <a name="RowSetAdd"></a>RowSetAdd
2078 <td>Insert the integer value held by register P2 into a RowSet object
2079 held in register P1.</p>
2080
2081 <p>An assertion fails if P2 is not an integer.</td></tr>
2082 <tr><td valign="top" align="center">
2083 <a name="RowSetRead"></a>RowSetRead
2084 <td>Extract the smallest value from the RowSet object in P1
2085 and put that value into register P3.
2086 Or, if RowSet object P1 is initially empty, leave P3
2087 unchanged and jump to instruction P2.</td></tr>
2088 <tr><td valign="top" align="center">
2089 <a name="RowSetTest"></a>RowSetTest
2090 <td>Register P3 is assumed to hold a 64-bit integer value. If register P1
2091 contains a RowSet object and that RowSet object contains
2092 the value held in P3, jump to register P2. Otherwise, insert the
2093 integer in P3 into the RowSet and continue on to the
2094 next opcode.</p>
2095
2096 <p>The RowSet object is optimized for the case where sets of integers
2097 are inserted in distinct phases, which each set contains no duplicates.
2098 Each set is identified by a unique P4 value. The first set
2099 must have P4==0, the final set must have P4==-1, and for all other sets
2100 must have P4&gt;0.</p>
2101
2102 <p>This allows optimizations: (a) when P4==0 there is no need to test
2103 the RowSet object for P3, as it is guaranteed not to contain it,
2104 (b) when P4==-1 there is no need to insert the value, as it will
2105 never be tested for, and (c) when a value that is part of set X is
2106 inserted, there is no need to search to see if the same value was
2107 previously inserted as part of set X (only if it was previously
2108 inserted as part of some other set).</td></tr>
2109 <tr><td valign="top" align="center">
2110 <a name="Savepoint"></a>Savepoint
2111 <td>Open, release or rollback the savepoint named by parameter P4, depending
2112 on the value of P1. To open a new savepoint set P1==0 (SAVEPOINT_BEGIN).
2113 To release (commit) an existing savepoint set P1==1 (SAVEPOINT_RELEASE).
2114 To rollback an existing savepoint set P1==2 (SAVEPOINT_ROLLBACK).</td></tr>
2115 <tr><td valign="top" align="center">
2116 <a name="SCopy"></a>SCopy
2117 <td>Make a shallow copy of register P1 into register P2.</p>
2118
2119 <p>This instruction makes a shallow copy of the value. If the value
2120 is a string or blob, then the copy is only a pointer to the
2121 original and hence if the original changes so will the copy.
2122 Worse, if the original is deallocated, the copy becomes invalid.
2123 Thus the program must guarantee that the original will not change
2124 during the lifetime of the copy. Use <a href="opcode.html#Copy">Copy</a> to make a complete
2125 copy.</td></tr>
2126 <tr><td valign="top" align="center">
2127 <a name="SeekEnd"></a>SeekEnd
2128 <td>Position cursor P1 at the end of the btree for the purpose of
2129 appending a new entry onto the btree.</p>
2130
2131 <p>It is assumed that the cursor is used only for appending and so
2132 if the cursor is valid, then the cursor must already be pointing
2133 at the end of the btree and so no changes are made to
2134 the cursor.</td></tr>
2135 <tr><td valign="top" align="center">
2136 <a name="SeekGE"></a>SeekGE
2137 <td>If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
2138 use the value in register P3 as the key. If cursor P1 refers
2139 to an SQL index, then P3 is the first in an array of P4 registers
2140 that are used as an unpacked index key.</p>
2141
2142 <p>Reposition cursor P1 so that it points to the smallest entry that
2143 is greater than or equal to the key value. If there are no records
2144 greater than or equal to the key and P2 is not zero, then jump to P2.</p>
2145
2146 <p>If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this
2147 opcode will either land on a record that exactly matches the key, or
2148 else it will cause a jump to P2. When the cursor is OPFLAG_SEEKEQ,
2149 this opcode must be followed by an <a href="opcode.html#IdxLE">IdxLE</a> opcode with the same arguments.
2150 The <a href="opcode.html#IdxGT">IdxGT</a> opcode will be skipped if this opcode succeeds, but the
2151 <a href="opcode.html#IdxGT">IdxGT</a> opcode will be used on subsequent loop iterations. The
2152 OPFLAG_SEEKEQ flags is a hint to the btree layer to say that this
2153 is an equality search.</p>
2154
2155 <p>This opcode leaves the cursor configured to move in forward order,
2156 from the beginning toward the end. In other words, the cursor is
2157 configured to use <a href="opcode.html#Next">Next</a>, not <a href="opcode.html#Prev">Prev</a>.</p>
2158
2159 <p>See also: <a href="opcode.html#Found">Found</a>, <a href="opcode.html#NotFound">NotFound</a>, SeekLt, SeekGt, SeekLe</td></tr>
2160 <tr><td valign="top" align="center">
2161 <a name="SeekGT"></a>SeekGT
2162 <td>If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
2163 use the value in register P3 as a key. If cursor P1 refers
2164 to an SQL index, then P3 is the first in an array of P4 registers
2165 that are used as an unpacked index key.</p>
2166
2167 <p>Reposition cursor P1 so that it points to the smallest entry that
2168 is greater than the key value. If there are no records greater than
2169 the key and P2 is not zero, then jump to P2.</p>
2170
2171 <p>This opcode leaves the cursor configured to move in forward order,
2172 from the beginning toward the end. In other words, the cursor is
2173 configured to use <a href="opcode.html#Next">Next</a>, not <a href="opcode.html#Prev">Prev</a>.</p>
2174
2175 <p>See also: <a href="opcode.html#Found">Found</a>, <a href="opcode.html#NotFound">NotFound</a>, SeekLt, SeekGe, SeekLe</td></tr>
2176 <tr><td valign="top" align="center">
2177 <a name="SeekHit"></a>SeekHit
2178 <td>Increase or decrease the seekHit value for cursor P1, if necessary,
2179 so that it is no less than P2 and no greater than P3.</p>
2180
2181 <p>The seekHit integer represents the maximum of terms in an index for which
2182 there is known to be at least one match. If the seekHit value is smaller
2183 than the total number of equality terms in an index lookup, then the
2184 <a href="opcode.html#IfNoHope">IfNoHope</a> opcode might run to see if the IN loop can be abandoned
2185 early, thus saving work. This is part of the IN-early-out optimization.</p>
2186
2187 <p>P1 must be a valid b-tree cursor.</td></tr>
2188 <tr><td valign="top" align="center">
2189 <a name="SeekLE"></a>SeekLE
2190 <td>If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
2191 use the value in register P3 as a key. If cursor P1 refers
2192 to an SQL index, then P3 is the first in an array of P4 registers
2193 that are used as an unpacked index key.</p>
2194
2195 <p>Reposition cursor P1 so that it points to the largest entry that
2196 is less than or equal to the key value. If there are no records
2197 less than or equal to the key and P2 is not zero, then jump to P2.</p>
2198
2199 <p>This opcode leaves the cursor configured to move in reverse order,
2200 from the end toward the beginning. In other words, the cursor is
2201 configured to use <a href="opcode.html#Prev">Prev</a>, not <a href="opcode.html#Next">Next</a>.</p>
2202
2203 <p>If the cursor P1 was opened using the OPFLAG_SEEKEQ flag, then this
2204 opcode will either land on a record that exactly matches the key, or
2205 else it will cause a jump to P2. When the cursor is OPFLAG_SEEKEQ,
2206 this opcode must be followed by an <a href="opcode.html#IdxLE">IdxLE</a> opcode with the same arguments.
2207 The <a href="opcode.html#IdxGE">IdxGE</a> opcode will be skipped if this opcode succeeds, but the
2208 <a href="opcode.html#IdxGE">IdxGE</a> opcode will be used on subsequent loop iterations. The
2209 OPFLAG_SEEKEQ flags is a hint to the btree layer to say that this
2210 is an equality search.</p>
2211
2212 <p>See also: <a href="opcode.html#Found">Found</a>, <a href="opcode.html#NotFound">NotFound</a>, SeekGt, SeekGe, SeekLt</td></tr>
2213 <tr><td valign="top" align="center">
2214 <a name="SeekLT"></a>SeekLT
2215 <td>If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
2216 use the value in register P3 as a key. If cursor P1 refers
2217 to an SQL index, then P3 is the first in an array of P4 registers
2218 that are used as an unpacked index key.</p>
2219
2220 <p>Reposition cursor P1 so that it points to the largest entry that
2221 is less than the key value. If there are no records less than
2222 the key and P2 is not zero, then jump to P2.</p>
2223
2224 <p>This opcode leaves the cursor configured to move in reverse order,
2225 from the end toward the beginning. In other words, the cursor is
2226 configured to use <a href="opcode.html#Prev">Prev</a>, not <a href="opcode.html#Next">Next</a>.</p>
2227
2228 <p>See also: <a href="opcode.html#Found">Found</a>, <a href="opcode.html#NotFound">NotFound</a>, SeekGt, SeekGe, SeekLe</td></tr>
2229 <tr><td valign="top" align="center">
2230 <a name="SeekRowid"></a>SeekRowid
2231 <td>P1 is the index of a cursor open on an SQL table btree (with integer
2232 keys). If register P3 does not contain an integer or if P1 does not
2233 contain a record with rowid P3 then jump immediately to P2.
2234 Or, if P2 is 0, raise an SQLITE_CORRUPT error. If P1 does contain
2235 a record with rowid P3 then
2236 leave the cursor pointing at that record and fall through to the next
2237 instruction.</p>
2238
2239 <p>The <a href="opcode.html#NotExists">NotExists</a> opcode performs the same operation, but with <a href="opcode.html#NotExists">NotExists</a>
2240 the P3 register must be guaranteed to contain an integer value. With this
2241 opcode, register P3 might not contain an integer.</p>
2242
2243 <p>The <a href="opcode.html#NotFound">NotFound</a> opcode performs the same operation on index btrees
2244 (with arbitrary multi-value keys).</p>
2245
2246 <p>This opcode leaves the cursor in a state where it cannot be advanced
2247 in either direction. In other words, the <a href="opcode.html#Next">Next</a> and <a href="opcode.html#Prev">Prev</a> opcodes will
2248 not work following this opcode.</p>
2249
2250 <p>See also: <a href="opcode.html#Found">Found</a>, <a href="opcode.html#NotFound">NotFound</a>, <a href="opcode.html#NoConflict">NoConflict</a>, <a href="opcode.html#SeekRowid">SeekRowid</a></td></tr>
2251 <tr><td valign="top" align="center">
2252 <a name="SeekScan"></a>SeekScan
2253 <td>This opcode is a prefix opcode to <a href="opcode.html#SeekGE">SeekGE</a>. In other words, this
2254 opcode must be immediately followed by <a href="opcode.html#SeekGE">SeekGE</a>. This constraint is
2255 checked by assert() statements.</p>
2256
2257 <p>This opcode uses the P1 through P4 operands of the subsequent
2258 <a href="opcode.html#SeekGE">SeekGE</a>. In the text that follows, the operands of the subsequent
2259 <a href="opcode.html#SeekGE">SeekGE</a> opcode are denoted as SeekOP.P1 through SeekOP.P4. Only
2260 the P1, P2 and P5 operands of this opcode are also used, and are called
2261 This.P1, This.P2 and This.P5.</p>
2262
2263 <p>This opcode helps to optimize IN operators on a multi-column index
2264 where the IN operator is on the later terms of the index by avoiding
2265 unnecessary seeks on the btree, substituting steps to the next row
2266 of the b-tree instead. A correct answer is obtained if this opcode
2267 is omitted or is a no-op.</p>
2268
2269 <p>The <a href="opcode.html#SeekGE">SeekGE</a>.P3 and <a href="opcode.html#SeekGE">SeekGE</a>.P4 operands identify an unpacked key which
2270 is the desired entry that we want the cursor <a href="opcode.html#SeekGE">SeekGE</a>.P1 to be pointing
2271 to. Call this <a href="opcode.html#SeekGE">SeekGE</a>.P3/P4 row the "target".</p>
2272
2273 <p>If the <a href="opcode.html#SeekGE">SeekGE</a>.P1 cursor is not currently pointing to a valid row,
2274 then this opcode is a no-op and control passes through into the <a href="opcode.html#SeekGE">SeekGE</a>.</p>
2275
2276 <p>If the <a href="opcode.html#SeekGE">SeekGE</a>.P1 cursor is pointing to a valid row, then that row
2277 might be the target row, or it might be near and slightly before the
2278 target row, or it might be after the target row. If the cursor is
2279 currently before the target row, then this opcode attempts to position
2280 the cursor on or after the target row by invoking sqlite3BtreeStep()
2281 on the cursor between 1 and This.P1 times.</p>
2282
2283 <p>The This.P5 parameter is a flag that indicates what to do if the
2284 cursor ends up pointing at a valid row that is past the target
2285 row. If This.P5 is false (0) then a jump is made to <a href="opcode.html#SeekGE">SeekGE</a>.P2. If
2286 This.P5 is true (non-zero) then a jump is made to This.P2. The P5==0
2287 case occurs when there are no inequality constraints to the right of
2288 the IN constraint. The jump to <a href="opcode.html#SeekGE">SeekGE</a>.P2 ends the loop. The P5!=0 case
2289 occurs when there are inequality constraints to the right of the IN
2290 operator. In that case, the This.P2 will point either directly to or
2291 to setup code prior to the <a href="opcode.html#IdxGT">IdxGT</a> or <a href="opcode.html#IdxGE">IdxGE</a> opcode that checks for
2292 loop terminate.</p>
2293
2294 <p>Possible outcomes from this opcode:<ol></p>
2295
2296 <p><li> If the cursor is initially not pointed to any valid row, then
2297 fall through into the subsequent <a href="opcode.html#SeekGE">SeekGE</a> opcode.</p>
2298
2299 <p><li> If the cursor is left pointing to a row that is before the target
2300 row, even after making as many as This.P1 calls to
2301 sqlite3BtreeNext(), then also fall through into <a href="opcode.html#SeekGE">SeekGE</a>.</p>
2302
2303 <p><li> If the cursor is left pointing at the target row, either because it
2304 was at the target row to begin with or because one or more
2305 sqlite3BtreeNext() calls moved the cursor to the target row,
2306 then jump to This.P2..,</p>
2307
2308 <p><li> If the cursor started out before the target row and a call to
2309 to sqlite3BtreeNext() moved the cursor off the end of the index
2310 (indicating that the target row definitely does not exist in the
2311 btree) then jump to <a href="opcode.html#SeekGE">SeekGE</a>.P2, ending the loop.</p>
2312
2313 <p><li> If the cursor ends up on a valid row that is past the target row
2314 (indicating that the target row does not exist in the btree) then
2315 jump to SeekOP.P2 if This.P5==0 or to This.P2 if This.P5&gt;0.
2316 </ol></td></tr>
2317 <tr><td valign="top" align="center">
2318 <a name="Sequence"></a>Sequence
2319 <td>Find the next available sequence number for cursor P1.
2320 Write the sequence number into register P2.
2321 The sequence number on the cursor is incremented after this
2322 instruction.</td></tr>
2323 <tr><td valign="top" align="center">
2324 <a name="SequenceTest"></a>SequenceTest
2325 <td>P1 is a sorter cursor. If the sequence counter is currently zero, jump
2326 to P2. Regardless of whether or not the jump is taken, increment the
2327 the sequence value.</td></tr>
2328 <tr><td valign="top" align="center">
2329 <a name="SetCookie"></a>SetCookie
2330 <td>Write the integer value P3 into cookie number P2 of database P1.
2331 P2==1 is the schema version. P2==2 is the database format.
2332 P2==3 is the recommended pager cache
2333 size, and so forth. P1==0 is the main database file and P1==1 is the
2334 database file used to store temporary tables.</p>
2335
2336 <p>A transaction must be started before executing this opcode.</p>
2337
2338 <p>If P2 is the SCHEMA_VERSION cookie (cookie number 1) then the internal
2339 schema version is set to P3-P5. The "PRAGMA schema_version=N" statement
2340 has P5 set to 1, so that the internal schema version will be different
2341 from the database schema version, resulting in a schema reset.</td></tr>
2342 <tr><td valign="top" align="center">
2343 <a name="SetSubtype"></a>SetSubtype
2344 <td>Set the subtype value of register P2 to the integer from register P1.
2345 If P1 is NULL, clear the subtype from p2.</td></tr>
2346 <tr><td valign="top" align="center">
2347 <a name="ShiftLeft"></a>ShiftLeft
2348 <td>Shift the integer value in register P2 to the left by the
2349 number of bits specified by the integer in register P1.
2350 Store the result in register P3.
2351 If either input is NULL, the result is NULL.</td></tr>
2352 <tr><td valign="top" align="center">
2353 <a name="ShiftRight"></a>ShiftRight
2354 <td>Shift the integer value in register P2 to the right by the
2355 number of bits specified by the integer in register P1.
2356 Store the result in register P3.
2357 If either input is NULL, the result is NULL.</td></tr>
2358 <tr><td valign="top" align="center">
2359 <a name="SoftNull"></a>SoftNull
2360 <td>Set register P1 to have the value NULL as seen by the <a href="opcode.html#MakeRecord">MakeRecord</a>
2361 instruction, but do not free any string or blob memory associated with
2362 the register, so that if the value was a string or blob that was
2363 previously copied using <a href="opcode.html#SCopy">SCopy</a>, the copies will continue to be valid.</td></tr>
2364 <tr><td valign="top" align="center">
2365 <a name="Sort"></a>Sort
2366 <td>This opcode does exactly the same thing as <a href="opcode.html#Rewind">Rewind</a> except that
2367 it increments an undocumented global variable used for testing.</p>
2368
2369 <p>Sorting is accomplished by writing records into a sorting index,
2370 then rewinding that index and playing it back from beginning to
2371 end. We use the <a href="opcode.html#Sort">Sort</a> opcode instead of <a href="opcode.html#Rewind">Rewind</a> to do the
2372 rewinding so that the global variable will be incremented and
2373 regression tests can determine whether or not the optimizer is
2374 correctly optimizing out sorts.</td></tr>
2375 <tr><td valign="top" align="center">
2376 <a name="SorterCompare"></a>SorterCompare
2377 <td>P1 is a sorter cursor. This instruction compares a prefix of the
2378 record blob in register P3 against a prefix of the entry that
2379 the sorter cursor currently points to. Only the first P4 fields
2380 of r&#91;P3&#93; and the sorter record are compared.</p>
2381
2382 <p>If either P3 or the sorter contains a NULL in one of their significant
2383 fields (not counting the P4 fields at the end which are ignored) then
2384 the comparison is assumed to be equal.</p>
2385
2386 <p>Fall through to next instruction if the two records compare equal to
2387 each other. <a href="opcode.html#Jump">Jump</a> to P2 if they are different.</td></tr>
2388 <tr><td valign="top" align="center">
2389 <a name="SorterData"></a>SorterData
2390 <td>Write into register P2 the current sorter data for sorter cursor P1.
2391 Then clear the column header cache on cursor P3.</p>
2392
2393 <p>This opcode is normally used to move a record out of the sorter and into
2394 a register that is the source for a pseudo-table cursor created using
2395 <a href="opcode.html#OpenPseudo">OpenPseudo</a>. That pseudo-table cursor is the one that is identified by
2396 parameter P3. Clearing the P3 column cache as part of this opcode saves
2397 us from having to issue a separate <a href="opcode.html#NullRow">NullRow</a> instruction to clear that cache.</td></tr>
2398 <tr><td valign="top" align="center">
2399 <a name="SorterInsert"></a>SorterInsert
2400 <td>Register P2 holds an SQL index key made using the
2401 <a href="opcode.html#MakeRecord">MakeRecord</a> instructions. This opcode writes that key
2402 into the sorter P1. Data for the entry is nil.</td></tr>
2403 <tr><td valign="top" align="center">
2404 <a name="SorterNext"></a>SorterNext
2405 <td>This opcode works just like <a href="opcode.html#Next">Next</a> except that P1 must be a
2406 sorter object for which the <a href="opcode.html#SorterSort">SorterSort</a> opcode has been
2407 invoked. This opcode advances the cursor to the next sorted
2408 record, or jumps to P2 if there are no more sorted records.</td></tr>
2409 <tr><td valign="top" align="center">
2410 <a name="SorterOpen"></a>SorterOpen
2411 <td>This opcode works like <a href="opcode.html#OpenEphemeral">OpenEphemeral</a> except that it opens
2412 a transient index that is specifically designed to sort large
2413 tables using an external merge-sort algorithm.</p>
2414
2415 <p>If argument P3 is non-zero, then it indicates that the sorter may
2416 assume that a stable sort considering the first P3 fields of each
2417 key is sufficient to produce the required results.</td></tr>
2418 <tr><td valign="top" align="center">
2419 <a name="SorterSort"></a>SorterSort
2420 <td>After all records have been inserted into the Sorter object
2421 identified by P1, invoke this opcode to actually do the sorting.
2422 <a href="opcode.html#Jump">Jump</a> to P2 if there are no records to be sorted.</p>
2423
2424 <p>This opcode is an alias for <a href="opcode.html#Sort">Sort</a> and <a href="opcode.html#Rewind">Rewind</a> that is used
2425 for Sorter objects.</td></tr>
2426 <tr><td valign="top" align="center">
2427 <a name="SqlExec"></a>SqlExec
2428 <td>Run the SQL statement or statements specified in the P4 string.</p>
2429
2430 <p>The P1 parameter is a bitmask of options:</p>
2431
2432 <p>0x0001 Disable Auth and <a href="opcode.html#Trace">Trace</a> callbacks while the statements
2433 in P4 are running.</p>
2434
2435 <p>0x0002 Set db-&gt;nAnalysisLimit to P2 while the statements in
2436 P4 are running.</p></td></tr>
2437 <tr><td valign="top" align="center">
2438 <a name="String"></a>String
2439 <td>The string value P4 of length P1 (bytes) is stored in register P2.</p>
2440
2441 <p>If P3 is not zero and the content of register P3 is equal to P5, then
2442 the datatype of the register P2 is converted to BLOB. The content is
2443 the same sequence of bytes, it is merely interpreted as a BLOB instead
2444 of a string, as if it had been CAST. In other words:</p>
2445
2446 <p>if( P3!=0 and reg&#91;P3&#93;==P5 ) reg&#91;P2&#93; := CAST(reg&#91;P2&#93; as BLOB)</td></tr>
2447 <tr><td valign="top" align="center">
2448 <a name="String8"></a>String8
2449 <td>P4 points to a nul terminated UTF-8 string. This opcode is transformed
2450 into a <a href="opcode.html#String">String</a> opcode before it is executed for the first time. During
2451 this transformation, the length of string P4 is computed and stored
2452 as the P1 parameter.</td></tr>
2453 <tr><td valign="top" align="center">
2454 <a name="Subtract"></a>Subtract
2455 <td>Subtract the value in register P1 from the value in register P2
2456 and store the result in register P3.
2457 If either input is NULL, the result is NULL.</td></tr>
2458 <tr><td valign="top" align="center">
2459 <a name="TableLock"></a>TableLock
2460 <td>Obtain a lock on a particular table. This instruction is only used when
2461 the shared-cache feature is enabled.</p>
2462
2463 <p>P1 is the index of the database in sqlite3.aDb[] of the database
2464 on which the lock is acquired. A readlock is obtained if P3==0 or
2465 a write lock if P3==1.</p>
2466
2467 <p>P2 contains the root-page of the table to lock.</p>
2468
2469 <p>P4 contains a pointer to the name of the table being locked. This is only
2470 used to generate an error message if the lock cannot be obtained.</td></tr>
2471 <tr><td valign="top" align="center">
2472 <a name="Trace"></a>Trace
2473 <td>Write P4 on the statement trace output if statement tracing is
2474 enabled.</p>
2475
2476 <p>Operand P1 must be 0x7fffffff and P2 must positive.</td></tr>
2477 <tr><td valign="top" align="center">
2478 <a name="Transaction"></a>Transaction
2479 <td>Begin a transaction on database P1 if a transaction is not already
2480 active.
2481 If P2 is non-zero, then a write-transaction is started, or if a
2482 read-transaction is already active, it is upgraded to a write-transaction.
2483 If P2 is zero, then a read-transaction is started. If P2 is 2 or more
2484 then an exclusive transaction is started.</p>
2485
2486 <p>P1 is the index of the database file on which the transaction is
2487 started. Index 0 is the main database file and index 1 is the
2488 file used for temporary tables. Indices of 2 or more are used for
2489 attached databases.</p>
2490
2491 <p>If a write-transaction is started and the Vdbe.usesStmtJournal flag is
2492 true (this flag is set if the Vdbe may modify more than one row and may
2493 throw an ABORT exception), a statement transaction may also be opened.
2494 More specifically, a statement transaction is opened iff the database
2495 connection is currently not in autocommit mode, or if there are other
2496 active statements. A statement transaction allows the changes made by this
2497 VDBE to be rolled back after an error without having to roll back the
2498 entire transaction. If no error is encountered, the statement transaction
2499 will automatically commit when the VDBE halts.</p>
2500
2501 <p>If P5!=0 then this opcode also checks the schema cookie against P3
2502 and the schema generation counter against P4.
2503 The cookie changes its value whenever the database schema changes.
2504 This operation is used to detect when that the cookie has changed
2505 and that the current process needs to reread the schema. If the schema
2506 cookie in P3 differs from the schema cookie in the database header or
2507 if the schema generation counter in P4 differs from the current
2508 generation counter, then an SQLITE_SCHEMA error is raised and execution
2509 halts. The sqlite3_step() wrapper function might then reprepare the
2510 statement and rerun it from the beginning.</td></tr>
2511 <tr><td valign="top" align="center">
2512 <a name="TypeCheck"></a>TypeCheck
2513 <td>Apply affinities to the range of P2 registers beginning with P1.
2514 Take the affinities from the Table object in P4. If any value
2515 cannot be coerced into the correct type, then raise an error.</p>
2516
2517 <p>This opcode is similar to <a href="opcode.html#Affinity">Affinity</a> except that this opcode
2518 forces the register type to the Table column type. This is used
2519 to implement "strict affinity".</p>
2520
2521 <p>GENERATED ALWAYS AS ... STATIC columns are only checked if P3
2522 is zero. When P3 is non-zero, no type checking occurs for
2523 static generated columns. Virtual columns are computed at query time
2524 and so they are never checked.</p>
2525
2526 <p>Preconditions:</p>
2527
2528 <p><ul>
2529 <li> P2 should be the number of non-virtual columns in the
2530 table of P4.
2531 <li> Table P4 should be a STRICT table.
2532 </ul></p>
2533
2534 <p>If any precondition is false, an assertion fault occurs.</td></tr>
2535 <tr><td valign="top" align="center">
2536 <a name="Vacuum"></a>Vacuum
2537 <td>Vacuum the entire database P1. P1 is 0 for "main", and 2 or more
2538 for an attached database. The "temp" database may not be vacuumed.</p>
2539
2540 <p>If P2 is not zero, then it is a register holding a string which is
2541 the file into which the result of vacuum should be written. When
2542 P2 is zero, the vacuum overwrites the original database.</td></tr>
2543 <tr><td valign="top" align="center">
2544 <a name="Variable"></a>Variable
2545 <td>Transfer the values of bound parameter P1 into register P2</td></tr>
2546 <tr><td valign="top" align="center">
2547 <a name="VBegin"></a>VBegin
2548 <td>P4 may be a pointer to an sqlite3_vtab structure. If so, call the
2549 xBegin method for that table.</p>
2550
2551 <p>Also, whether or not P4 is set, check that this is not being called from
2552 within a callback to a virtual table xSync() method. If it is, the error
2553 code will be set to SQLITE_LOCKED.</td></tr>
2554 <tr><td valign="top" align="center">
2555 <a name="VCheck"></a>VCheck
2556 <td>P4 is a pointer to a Table object that is a virtual table in schema P1
2557 that supports the xIntegrity() method. This opcode runs the xIntegrity()
2558 method for that virtual table, using P3 as the integer argument. If
2559 an error is reported back, the table name is prepended to the error
2560 message and that message is stored in P2. If no errors are seen,
2561 register P2 is set to NULL.</td></tr>
2562 <tr><td valign="top" align="center">
2563 <a name="VColumn"></a>VColumn
2564 <td>Store in register P3 the value of the P2-th column of
2565 the current row of the virtual-table of cursor P1.</p>
2566
2567 <p>If the <a href="opcode.html#VColumn">VColumn</a> opcode is being used to fetch the value of
2568 an unchanging column during an UPDATE operation, then the P5
2569 value is OPFLAG_NOCHNG. This will cause the sqlite3_vtab_nochange()
2570 function to return true inside the xColumn method of the virtual
2571 table implementation. The P5 column might also contain other
2572 bits (OPFLAG_LENGTHARG or OPFLAG_TYPEOFARG) but those bits are
2573 unused by <a href="opcode.html#VColumn">VColumn</a>.</td></tr>
2574 <tr><td valign="top" align="center">
2575 <a name="VCreate"></a>VCreate
2576 <td>P2 is a register that holds the name of a virtual table in database
2577 P1. Call the xCreate method for that table.</td></tr>
2578 <tr><td valign="top" align="center">
2579 <a name="VDestroy"></a>VDestroy
2580 <td>P4 is the name of a virtual table in database P1. Call the xDestroy method
2581 of that table.</td></tr>
2582 <tr><td valign="top" align="center">
2583 <a name="VFilter"></a>VFilter
2584 <td>P1 is a cursor opened using <a href="opcode.html#VOpen">VOpen</a>. P2 is an address to jump to if
2585 the filtered result set is empty.</p>
2586
2587 <p>P4 is either NULL or a string that was generated by the xBestIndex
2588 method of the module. The interpretation of the P4 string is left
2589 to the module implementation.</p>
2590
2591 <p>This opcode invokes the xFilter method on the virtual table specified
2592 by P1. The integer query plan parameter to xFilter is stored in register
2593 P3. Register P3+1 stores the argc parameter to be passed to the
2594 xFilter method. Registers P3+2..P3+1+argc are the argc
2595 additional parameters which are passed to
2596 xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.</p>
2597
2598 <p>A jump is made to P2 if the result set after filtering would be empty.</td></tr>
2599 <tr><td valign="top" align="center">
2600 <a name="VInitIn"></a>VInitIn
2601 <td>Set register P2 to be a pointer to a ValueList object for cursor P1
2602 with cache register P3 and output register P3+1. This ValueList object
2603 can be used as the first argument to sqlite3_vtab_in_first() and
2604 sqlite3_vtab_in_next() to extract all of the values stored in the P1
2605 cursor. Register P3 is used to hold the values returned by
2606 sqlite3_vtab_in_first() and sqlite3_vtab_in_next().</td></tr>
2607 <tr><td valign="top" align="center">
2608 <a name="VNext"></a>VNext
2609 <td>Advance virtual table P1 to the next row in its result set and
2610 jump to instruction P2. Or, if the virtual table has reached
2611 the end of its result set, then fall through to the next instruction.</td></tr>
2612 <tr><td valign="top" align="center">
2613 <a name="VOpen"></a>VOpen
2614 <td>P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
2615 P1 is a cursor number. This opcode opens a cursor to the virtual
2616 table and stores that cursor in P1.</td></tr>
2617 <tr><td valign="top" align="center">
2618 <a name="VRename"></a>VRename
2619 <td>P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
2620 This opcode invokes the corresponding xRename method. The value
2621 in register P1 is passed as the zName argument to the xRename method.</td></tr>
2622 <tr><td valign="top" align="center">
2623 <a name="VUpdate"></a>VUpdate
2624 <td>P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
2625 This opcode invokes the corresponding xUpdate method. P2 values
2626 are contiguous memory cells starting at P3 to pass to the xUpdate
2627 invocation. The value in register (P3+P2-1) corresponds to the
2628 p2th element of the argv array passed to xUpdate.</p>
2629
2630 <p>The xUpdate method will do a DELETE or an INSERT or both.
2631 The argv[0] element (which corresponds to memory cell P3)
2632 is the rowid of a row to delete. If argv[0] is NULL then no
2633 deletion occurs. The argv[1] element is the rowid of the new
2634 row. This can be NULL to have the virtual table select the new
2635 rowid for itself. The subsequent elements in the array are
2636 the values of columns in the new row.</p>
2637
2638 <p>If P2==1 then no insert is performed. argv[0] is the rowid of
2639 a row to delete.</p>
2640
2641 <p>P1 is a boolean flag. If it is set to true and the xUpdate call
2642 is successful, then the value returned by sqlite3_last_insert_rowid()
2643 is set to the value of the rowid for the row just inserted.</p>
2644
2645 <p>P5 is the error actions (OE_Replace, OE_Fail, OE_Ignore, etc) to
2646 apply in the case of a constraint failure on an insert or update.</td></tr>
2647 <tr><td valign="top" align="center">
2648 <a name="Yield"></a>Yield
2649 <td>Swap the program counter with the value in register P1. This
2650 has the effect of yielding to a coroutine.</p>
2651
2652 <p>If the coroutine that is launched by this instruction ends with
2653 <a href="opcode.html#Yield">Yield</a> or <a href="opcode.html#Return">Return</a> then continue to the next instruction. But if
2654 the coroutine launched by this instruction ends with
2655 <a href="opcode.html#EndCoroutine">EndCoroutine</a>, then jump to P2 rather than continuing with the
2656 next instruction.</p>
2657
2658 <p>See also: <a href="opcode.html#InitCoroutine">InitCoroutine</a></td></tr>
2659 <tr><td valign="top" align="center">
2660 <a name="ZeroOrNull"></a>ZeroOrNull
2661 <td>If both registers P1 and P3 are NOT NULL, then store a zero in
2662 register P2. If either registers P1 or P3 are NULL then put
2663 a NULL in register P2.</td></tr>
2664
2665 </table></blockquote>
2666 </div>
2667
2668 </p>
2669