Debian Codegraph @

www/bytecodevtab.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 Bytecode() And Tables_Used() Table-Valued Functions</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 Bytecode() And Tables_Used() Table-Valued Functions
122 </div>
123 </div>
124
125
126
127
128 <h1 id="overview"><span>1. </span>Overview</h1>
129
130 <p>
131 Bytecode and tables_used are <a href="vtab.html">virtual tables</a> built into SQLite that
132 access information about <a href="c3ref/stmt.html">prepared statements</a>.
133 Both bytecode and tables_used operate as <a href="vtab.html#tabfunc2">table-valued functions</a>.
134 They take a single required argument which is either the text of
135 an SQL statement, or a pointer to an existing prepared statement.
136 The bytecode function returns one row of result for each <a href="opcode.html">bytecode</a>
137 operation in the prepared statement. The tables_used function returns
138 one row for each persistent btree (either a table or an index) accessed
139 by the prepared statement.
140
141 </p><h1 id="usage"><span>2. </span>Usage</h1>
142
143 <p>
144 The bytecode and tables_used tables are only available if SQLite has
145 been compiled with the <a href="compile.html#enable_bytecode_vtab">-DSQLITE_ENABLE_BYTECODE_VTAB</a> compile-time option.
146 The <a href="cli.html">CLI</a> has been compiled that way, and so you can use the standard
147 <a href="cli.html">CLI</a> as a test platform to experiement.
148
149 </p><p>
150 Both virtual tables are read-only <a href="vtab.html#epoonlyvtab">eponymous-only virtual tables</a>. You use them
151 by mentioning them directly in the FROM clause of a SELECT statement.
152 They both require a single argument which is the SQL statement to be
153 analyzed. For example:
154
155 </p><div class="codeblock"><pre>SELECT * FROM bytecode('SELECT * FROM bytecode(?1)');
156 </pre></div>
157
158 <p>
159 The argument can be either the text of an SQL statement, in which case
160 the bytecode (or tables_used) for that statement is returned, or the
161 argument can be a parameter such as ?1 or $stmt that is later bound
162 to a <a href="c3ref/stmt.html">prepared statement</a> object using the
163 <a href="c3ref/bind_blob.html">sqlite3_bind_pointer()</a> interface. Use a pointer type of
164 "stmt-pointer" for the <a href="c3ref/bind_blob.html">sqlite3_bind_pointer()</a> interface.
165
166 </p><h2 id="schema"><span>2.1. </span>Schema</h2>
167
168 <p>
169 The schema of the bytecode table is:
170
171 </p><div class="codeblock"><pre>CREATE TABLE bytecode(
172 addr INT,
173 opcode TEXT,
174 p1 INT,
175 p2 INT,
176 p3 INT,
177 p4 TEXT,
178 p5 INT,
179 comment TEXT,
180 subprog TEXT,
181 stmt HIDDEN
182 );
183 </pre></div>
184
185 <p>
186 The first eight columns are the address, opcode, and operands for a
187 single <a href="opcode.html">bytecode</a> in the virtual machine that implements the statement.
188 These columns are the same columns output when using EXPLAIN. The
189 bytecode virtual tables shows all operations in the prepared statement,
190 both the main body of the prepared statement and in subprograms used
191 to implement triggers or foreign key actions. The "subprog" field
192 is NULL for the main body of the prepared statement, or is the trigger
193 name or the string "(FK)" for triggers and foreign key actions.
194
195 </p><p>
196 The schema for the tables_used table is:
197
198 </p><div class="codeblock"><pre>CREATE TABLE tables_used(
199 type TEXT,
200 schema TEXT,
201 name TEXT,
202 wr INT,
203 subprog TEXT,
204 stmt HIDDEN
205 );
206 </pre></div>
207
208 <p>
209 The tables_used table is intended to show which btrees of the database file
210 are read or written by a prepared statement, both by the main statement
211 itself but also by related triggers and foreign key actions. The columns
212 are as follows:
213
214 </p><ul>
215 <li><p><b>type</b> &rarr; Either "table" or "index", depending on what role
216 the btree is serving.
217
218 </p></li><li><p><b>schema</b> &rarr; Which database file the btree is located in.
219 This will be "main" for the main database (the usual case), or "temp" for
220 TEMP tables and indexes, or the name assigned to <a href="lang_attach.html">attached</a> databases by
221 the <a href="lang_attach.html">ATTACH</a> statement.
222
223 </p></li><li><p><b>name</b> &rarr; The name of the table or index
224
225 </p></li><li><p><b>wr</b> &rarr; 0 if the object is read, 1 if the object is written
226
227 </p></li><li><p><b>subprog</b> &rarr; The sub-program in which the object is
228 accessed. NULL means the main body of the prepared statement. Otherwise
229 this field is the name of a trigger or "(FK)" for a foreign key action.
230 </p></li></ul>
231 <p align="center"><small><i>This page last modified on <a href="https://sqlite.org/docsrc/honeypot" id="mtimelink" data-href="https://sqlite.org/docsrc/finfo/pages/bytecodevtab.in?m=fe69f4a05c">2022-01-08 05:02:57</a> UTC </small></i></p>
232