aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/sqlite/unix/sqlite-3.5.1/www/opcode.tcl
diff options
context:
space:
mode:
authordan miller2007-10-21 08:36:32 +0000
committerdan miller2007-10-21 08:36:32 +0000
commit2f8d7092bc2c9609fa98d6888106b96f38b22828 (patch)
treeda6c37579258cc965b52a75aee6135fe44237698 /libraries/sqlite/unix/sqlite-3.5.1/www/opcode.tcl
parent* Committing new PolicyManager based on an ACL system. (diff)
downloadopensim-SC_OLD-2f8d7092bc2c9609fa98d6888106b96f38b22828.zip
opensim-SC_OLD-2f8d7092bc2c9609fa98d6888106b96f38b22828.tar.gz
opensim-SC_OLD-2f8d7092bc2c9609fa98d6888106b96f38b22828.tar.bz2
opensim-SC_OLD-2f8d7092bc2c9609fa98d6888106b96f38b22828.tar.xz
libraries moved to opensim-libs, a new repository
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/www/opcode.tcl')
-rw-r--r--libraries/sqlite/unix/sqlite-3.5.1/www/opcode.tcl243
1 files changed, 0 insertions, 243 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/www/opcode.tcl b/libraries/sqlite/unix/sqlite-3.5.1/www/opcode.tcl
deleted file mode 100644
index f28534f..0000000
--- a/libraries/sqlite/unix/sqlite-3.5.1/www/opcode.tcl
+++ /dev/null
@@ -1,243 +0,0 @@
1#
2# Run this Tcl script to generate the sqlite.html file.
3#
4set rcsid {$Id: opcode.tcl,v 1.15 2005/03/09 12:26:51 danielk1977 Exp $}
5source common.tcl
6header {SQLite Virtual Machine Opcodes}
7puts {
8<h2>SQLite Virtual Machine Opcodes</h2>
9}
10
11set fd [open [lindex $argv 0] r]
12set file [read $fd [file size [lindex $argv 0]]]
13close $fd
14set current_op {}
15foreach line [split $file \n] {
16 set line [string trim $line]
17 if {[string index $line 1]!="*"} {
18 set current_op {}
19 continue
20 }
21 if {[regexp {^/\* Opcode: } $line]} {
22 set current_op [lindex $line 2]
23 set txt [lrange $line 3 end]
24 regsub -all {>} $txt {\&gt;} txt
25 regsub -all {<} $txt {\&lt;} txt
26 set Opcode($current_op:args) $txt
27 lappend OpcodeList $current_op
28 continue
29 }
30 if {$current_op==""} continue
31 if {[regexp {^\*/} $line]} {
32 set current_op {}
33 continue
34 }
35 set line [string trim [string range $line 3 end]]
36 if {$line==""} {
37 append Opcode($current_op:text) \n<p>
38 } else {
39 regsub -all {>} $line {\&gt;} line
40 regsub -all {<} $line {\&lt;} line
41 append Opcode($current_op:text) \n$line
42 }
43}
44unset file
45
46puts {
47<h3>Introduction</h3>
48
49<p>In order to execute an SQL statement, the SQLite library first parses
50the SQL, analyzes the statement, then generates a short program to execute
51the statement. The program is generated for a "virtual machine" implemented
52by the SQLite library. This document describes the operation of that
53virtual machine.</p>
54
55<p>This document is intended as a reference, not a tutorial.
56A separate <a href="vdbe.html">Virtual Machine Tutorial</a> is
57available. If you are looking for a narrative description
58of how the virtual machine works, you should read the tutorial
59and not this document. Once you have a basic idea of what the
60virtual machine does, you can refer back to this document for
61the details on a particular opcode.
62Unfortunately, the virtual machine tutorial was written for
63SQLite version 1.0. There are substantial changes in the virtual
64machine for version 2.0 and the document has not been updated.
65</p>
66
67<p>The source code to the virtual machine is in the <b>vdbe.c</b> source
68file. All of the opcode definitions further down in this document are
69contained in comments in the source file. In fact, the opcode table
70in this document
71was generated by scanning the <b>vdbe.c</b> source file
72and extracting the necessary information from comments. So the
73source code comments are really the canonical source of information
74about the virtual machine. When in doubt, refer to the source code.</p>
75
76<p>Each instruction in the virtual machine consists of an opcode and
77up to three operands named P1, P2 and P3. P1 may be an arbitrary
78integer. P2 must be a non-negative integer. P2 is always the
79jump destination in any operation that might cause a jump.
80P3 is a null-terminated
81string or NULL. Some operators use all three operands. Some use
82one or two. Some operators use none of the operands.<p>
83
84<p>The virtual machine begins execution on instruction number 0.
85Execution continues until (1) a Halt instruction is seen, or
86(2) the program counter becomes one greater than the address of
87last instruction, or (3) there is an execution error.
88When the virtual machine halts, all memory
89that it allocated is released and all database cursors it may
90have had open are closed. If the execution stopped due to an
91error, any pending transactions are terminated and changes made
92to the database are rolled back.</p>
93
94<p>The virtual machine also contains an operand stack of unlimited
95depth. Many of the opcodes use operands from the stack. See the
96individual opcode descriptions for details.</p>
97
98<p>The virtual machine can have zero or more cursors. Each cursor
99is a pointer into a single table or index within the database.
100There can be multiple cursors pointing at the same index or table.
101All cursors operate independently, even cursors pointing to the same
102indices or tables.
103The only way for the virtual machine to interact with a database
104file is through a cursor.
105Instructions in the virtual
106machine can create a new cursor (Open), read data from a cursor
107(Column), advance the cursor to the next entry in the table
108(Next) or index (NextIdx), and many other operations.
109All cursors are automatically
110closed when the virtual machine terminates.</p>
111
112<p>The virtual machine contains an arbitrary number of fixed memory
113locations with addresses beginning at zero and growing upward.
114Each memory location can hold an arbitrary string. The memory
115cells are typically used to hold the result of a scalar SELECT
116that is part of a larger expression.</p>
117
118<p>The virtual machine contains a single sorter.
119The sorter is able to accumulate records, sort those records,
120then play the records back in sorted order. The sorter is used
121to implement the ORDER BY clause of a SELECT statement.</p>
122
123<p>The virtual machine contains a single "List".
124The list stores a list of integers. The list is used to hold the
125rowids for records of a database table that needs to be modified.
126The WHERE clause of an UPDATE or DELETE statement scans through
127the table and writes the rowid of every record to be modified
128into the list. Then the list is played back and the table is modified
129in a separate step.</p>
130
131<p>The virtual machine can contain an arbitrary number of "Sets".
132Each set holds an arbitrary number of strings. Sets are used to
133implement the IN operator with a constant right-hand side.</p>
134
135<p>The virtual machine can open a single external file for reading.
136This external read file is used to implement the COPY command.</p>
137
138<p>Finally, the virtual machine can have a single set of aggregators.
139An aggregator is a device used to implement the GROUP BY clause
140of a SELECT. An aggregator has one or more slots that can hold
141values being extracted by the select. The number of slots is the
142same for all aggregators and is defined by the AggReset operation.
143At any point in time a single aggregator is current or "has focus".
144There are operations to read or write to memory slots of the aggregator
145in focus. There are also operations to change the focus aggregator
146and to scan through all aggregators.</p>
147
148<h3>Viewing Programs Generated By SQLite</h3>
149
150<p>Every SQL statement that SQLite interprets results in a program
151for the virtual machine. But if you precede the SQL statement with
152the keyword "EXPLAIN" the virtual machine will not execute the
153program. Instead, the instructions of the program will be returned
154like a query result. This feature is useful for debugging and
155for learning how the virtual machine operates.</p>
156
157<p>You can use the <b>sqlite</b> command-line tool to see the
158instructions generated by an SQL statement. The following is
159an example:</p>}
160
161proc Code {body} {
162 puts {<blockquote><tt>}
163 regsub -all {&} [string trim $body] {\&amp;} body
164 regsub -all {>} $body {\&gt;} body
165 regsub -all {<} $body {\&lt;} body
166 regsub -all {\(\(\(} $body {<b>} body
167 regsub -all {\)\)\)} $body {</b>} body
168 regsub -all { } $body {\&nbsp;} body
169 regsub -all \n $body <br>\n body
170 puts $body
171 puts {</tt></blockquote>}
172}
173
174Code {
175$ (((sqlite ex1)))
176sqlite> (((.explain)))
177sqlite> (((explain delete from tbl1 where two<20;)))
178addr opcode p1 p2 p3
179---- ------------ ----- ----- ----------------------------------------
1800 Transaction 0 0
1811 VerifyCookie 219 0
1822 ListOpen 0 0
1833 Open 0 3 tbl1
1844 Rewind 0 0
1855 Next 0 12
1866 Column 0 1
1877 Integer 20 0
1888 Ge 0 5
1899 Recno 0 0
19010 ListWrite 0 0
19111 Goto 0 5
19212 Close 0 0
19313 ListRewind 0 0
19414 OpenWrite 0 3
19515 ListRead 0 19
19616 MoveTo 0 0
19717 Delete 0 0
19818 Goto 0 15
19919 ListClose 0 0
20020 Commit 0 0
201}
202
203puts {
204<p>All you have to do is add the "EXPLAIN" keyword to the front of the
205SQL statement. But if you use the ".explain" command to <b>sqlite</b>
206first, it will set up the output mode to make the program more easily
207viewable.</p>
208
209<p>If <b>sqlite</b> has been compiled without the "-DNDEBUG=1" option
210(that is, with the NDEBUG preprocessor macro not defined) then you
211can put the SQLite virtual machine in a mode where it will trace its
212execution by writing messages to standard output. The non-standard
213SQL "PRAGMA" comments can be used to turn tracing on and off. To
214turn tracing on, enter:
215</p>
216
217<blockquote><pre>
218PRAGMA vdbe_trace=on;
219</pre></blockquote>
220
221<p>
222You can turn tracing back off by entering a similar statement but
223changing the value "on" to "off".</p>
224
225<h3>The Opcodes</h3>
226}
227
228puts "<p>There are currently [llength $OpcodeList] opcodes defined by
229the virtual machine."
230puts {All currently defined opcodes are described in the table below.
231This table was generated automatically by scanning the source code
232from the file <b>vdbe.c</b>.</p>}
233
234puts {
235<p><table cellspacing="1" border="1" cellpadding="10">
236<tr><th>Opcode&nbsp;Name</th><th>Description</th></tr>}
237foreach op [lsort -dictionary $OpcodeList] {
238 puts {<tr><td valign="top" align="center">}
239 puts "<a name=\"$op\">$op</a>"
240 puts "<td>[string trim $Opcode($op:text)]</td></tr>"
241}
242puts {</table></p>}
243footer $rcsid