Debian Codegraph @

www/dbpage.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_DBPAGE Virtual Table</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_DBPAGE Virtual Table
122 </div>
123 </div>
124
125
126
127
128 <h1 id="overview"><span>1. </span>Overview</h1>
129
130 <p>
131 The SQLITE_DBPAGE extension implements an <a href="vtab.html#epoonlyvtab">eponymous-only virtual table</a> that
132 provides direct access to the underlying database file by interacting
133 with the pager. SQLITE_DBPAGE is capable of both reading and writing any
134 page of the database. Because interaction is through the pager layer, all
135 changes are transactional.
136 </p>
137
138 <p>
139 <b>Warning:</b> writing to the SQLITE_DBPAGE virtual table can very easily
140 cause unrecoverably database corruption. Do not allow untrusted components
141 to access the SQLITE_DBPAGE table. Use appropriate care while using the
142 SQLITE_DBPAGE table. Back up important data prior to experimenting with the
143 SQLITE_DBPAGE table. Writes to the SQLITE_DBPAGE virtual table are
144 disabled when the <a href="c3ref/c_dbconfig_defensive.html#sqlitedbconfigdefensive">SQLITE_DBCONFIG_DEFENSIVE</a> flag is set.
145
146 </p><p>
147 The SQLITE_DBPAGE extension is included in the <a href="amalgamation.html">amalgamation</a> though
148 it is disabled
149 by default. Use the <a href="compile.html#enable_dbpage_vtab">SQLITE_ENABLE_DBPAGE_VTAB</a> compile-time option to enable
150 the SQLITE_DBPAGE extension. The SQLITE_DBPAGE extension makes use of
151 unpublished internal interfaces and is not run-time loadable. The only way
152 to add SQLITE_DBPAGE to an application is to compile it in using the
153 <a href="compile.html#enable_dbpage_vtab">SQLITE_ENABLE_DBPAGE_VTAB</a> compile-time option.
154 </p>
155
156 <p>
157 The SQLITE_DBPAGE extension is enabled in default builds
158 of the <a href="cli.html">command-line shell</a>.
159
160 </p><h1 id="usage"><span>2. </span>Usage</h1>
161
162 <p>
163 The SQLITE_DBPAGE virtual table read/write table that provides direct
164 access to the underlying disk file on a page-by-page basis. The
165 virtual table appears to have a schema like this:
166
167 </p><div class="codeblock"><pre>CREATE TABLE sqlite_dbpage(
168 pgno INTEGER PRIMARY KEY,
169 data BLOB
170 );
171 </pre></div>
172
173 <p>
174 An SQLite database file is divided into pages.
175 The first page is 1, the second page is 2, and so forth.
176 There is no page 0.
177 Every page is the same size.
178 The size of every page is a power of 2 between 512 and 65536.
179 See the <a href="fileformat2.html">file format</a> documentation for further details.
180
181 </p><p>
182 The SQLITE_DBPAGE table allows an application to view or replace the
183 raw binary content of each page of the database file.
184 No attempt is made to interpret the content of the page.
185 Content is returned byte-for-byte as it appears on disk.
186
187 </p><p>
188 The SQLITE_DBPAGE table has one row for each page in the database file.
189 SQLITE_DBPAGE allows pages to be read or to be overwritten.
190 However the size of the database file cannot be changed. It is not
191 possible to change the number of rows in the SQLITE_DBPAGE table by
192 running DELETE or INSERT operations against that table.
193
194 </p><h2 id="using_sqlite_dbpage_on_attach_ed_databases"><span>2.1. </span>Using SQLITE_DBPAGE On ATTACH-ed Databases</h2>
195
196 <p>
197 The SQLITE_DBPAGE table schema shown above is incomplete. There is
198 a third <a href="vtab.html#hiddencol">hidden column</a> named "schema" that determines which
199 <a href="lang_attach.html">ATTACH-ed database</a> should be read or written. Because
200 the "schema" column is hidden, it can be used as a parameter when
201 SQLITE_DBPAGE is invoked as a <a href="vtab.html#tabfunc2">table-valued function</a>.
202
203 </p><p>
204 For example, suppose an additional database is attached to the
205 database connection using a statement like this:
206
207 </p><div class="codeblock"><pre>ATTACH 'auxdata1.db' AS aux1;
208 </pre></div>
209
210 <p>
211 Then to read the first page of that database file, one merely runs:
212
213 </p><div class="codeblock"><pre>SELECT data FROM sqlite_dbpage('aux1') WHERE pgno=1;
214 </pre></div>
215
216 <p>
217 If the "schema" is omitted, it defaults to the primary database
218 (usually called 'main', unless renamed using <a href="c3ref/c_dbconfig_defensive.html#sqlitedbconfigmaindbname">SQLITE_DBCONFIG_MAINDBNAME</a>).
219 Hence, the following two queries are normally equivalent:
220
221 </p><div class="codeblock"><pre>SELECT data FROM sqlite_dbpage('main') WHERE pgno=1;
222 SELECT data FROM sqlite_dbpage WHERE pgno=1;
223 </pre></div>
224
225 <p>
226 The SQLITE_DBPAGE table can participate in a join just like any other
227 table. Hence, to see the content of the first page to all connected
228 database files, one might run a statement like this:
229
230 </p><div class="codeblock"><pre>SELECT dbpage.data, dblist.name
231 FROM pragma_database_list AS dblist
232 JOIN sqlite_dbpage(dblist.name) AS dbpage
233 WHERE dbpage.pgno=1;
234 </pre></div>
235 <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/dbpage.in?m=21798cdb09">2022-01-08 05:02:57</a> UTC </small></i></p>
236