System.Data.SQLite

Check-in [70455e449b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Pickup the SQLite core library 3.14 doc changes from upstream.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 70455e449be2e7811ede5d1e54eff001616ab7b6
User & Date: mistachkin 2016-08-09 00:02:18.409
Context
2016-08-09
00:20
Pickup the 'vtab.html' doc fix from upstream. check-in: 006a35fb5e user: mistachkin tags: trunk
00:02
Pickup the SQLite core library 3.14 doc changes from upstream. check-in: 70455e449b user: mistachkin tags: trunk
2016-08-08
22:47
Update SQLite core library to the 3.14 release. check-in: e7806a71e7 user: mistachkin tags: trunk
Changes
Unified Diff Show Whitespace Changes Patch
Changes to Doc/Extra/Core/images/syntax/expr.gif.

cannot compute difference between binary files

Changes to Doc/Extra/Core/lang_expr.html.
544
545
546
547
548
549
550



551
552
553
554
555
556
557
558
559
560
561
<h3>The IN and NOT IN operators</h3>
<p>The IN and NOT IN operators take a single scalar operand on the
left and a vector operand on the right
formed by an explicit list of zero or more scalars or by a 
single subquery.
When the right operand of an IN or NOT IN operator is a subquery, the
subquery must have a single result column.



When the right operand is an empty set, the result of IN is false and the
result of NOT IN is true, regardless of the left operand and even if the
left operand is NULL.
The result of an IN or NOT IN operator is determined by the following
matrix:

<center>
<table border=1>
<tr>
<th>Left operand <br>is NULL
<th>Right operand <br>contains NULL







>
>
>



|







544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
<h3>The IN and NOT IN operators</h3>
<p>The IN and NOT IN operators take a single scalar operand on the
left and a vector operand on the right
formed by an explicit list of zero or more scalars or by a 
single subquery.
When the right operand of an IN or NOT IN operator is a subquery, the
subquery must have a single result column.
The "subquery" on the right-hand side of an IN operator can be a
table name or <a href="vtab.html#tabfunc2">table-valued function</a> name in which case the
subquery is understood to be "(SELECT * FROM <i>name</i>)".
When the right operand is an empty set, the result of IN is false and the
result of NOT IN is true, regardless of the left operand and even if the
left operand is NULL.
<p>The result of an IN or NOT IN operator is determined by the following
matrix:

<center>
<table border=1>
<tr>
<th>Left operand <br>is NULL
<th>Right operand <br>contains NULL
Changes to Doc/Special/Core/vtab.html.
133
134
135
136
137
138
139





140





141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
    </div>
  </table>

<div class=startsearch></div>
  







<h1 align="center">The Virtual Table Mechanism Of SQLite</h1>







<h2>1.0 Introduction</h2>

<p>A virtual table is an object that is registered with an open SQLite
<a href="c3ref/sqlite3.html">database connection</a>. From the perspective of an SQL statement,
the virtual table object looks like any other table or view. 
But behind the scenes, queries and updates on a virtual table
invoke callback methods of the virtual table object instead of
reading and writing to the database file.

<p>The virtual table mechanism allows an application to publish
interfaces that are accessible from SQL statements as if they were
tables. SQL statements can do almost anything to a
virtual table that they can do to a real table, with the following
exceptions:








>
>
>
>
>
|
>
>
>
>
>


|






|







133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
    </div>
  </table>

<div class=startsearch></div>
  





    <div class=fancy>
    <div style="font-size:2em;text-align:center;color:#044a64">
      The Virtual Table Mechanism Of SQLite
    </div>
    <div style="font-size:1.5em;margin:1em;color:#044a64">
      Table Of Contents</div>
    <div id=toc> <div style="margin-left:6ex"><a href="#section_1">1. Introduction</a></div><div style="margin-left:12ex"><a href="#section_1_1">1.1. Usage</a></div><div style="margin-left:18ex"><a href="#section_1_1_1">1.1.1. Temporary virtual tables</a></div><div style="margin-left:18ex"><a href="#section_1_1_2">1.1.2. Eponymous virtual tables</a></div><div style="margin-left:18ex"><a href="#section_1_1_3">1.1.3. Eponymous-only virtual tables</a></div><div style="margin-left:12ex"><a href="#section_1_2">1.2. Implementation</a></div><div style="margin-left:12ex"><a href="#section_1_3">1.3. Virtual Tables And Shared Cache</a></div><div style="margin-left:12ex"><a href="#section_1_4">1.4. Creating New Virtual Table Implementations</a></div><div style="margin-left:6ex"><a href="#section_2">2. Virtual Table Methods</a></div><div style="margin-left:12ex"><a href="#section_2_1">2.1. The xCreate Method</a></div><div style="margin-left:18ex"><a href="#section_2_1_1">2.1.1. Hidden columns in virtual tables</a></div><div style="margin-left:18ex"><a href="#section_2_1_2">2.1.2. Table-valued functions</a></div><div style="margin-left:18ex"><a href="#section_2_1_3">2.1.3.  WITHOUT ROWID Virtual Tables </a></div><div style="margin-left:12ex"><a href="#section_2_2">2.2. The xConnect Method</a></div><div style="margin-left:12ex"><a href="#section_2_3">2.3. The xBestIndex Method</a></div><div style="margin-left:18ex"><a href="#section_2_3_1">2.3.1. Inputs</a></div><div style="margin-left:18ex"><a href="#section_2_3_2">2.3.2. Outputs</a></div><div style="margin-left:12ex"><a href="#section_2_4">2.4. The xDisconnect Method</a></div><div style="margin-left:12ex"><a href="#section_2_5">2.5. The xDestroy Method</a></div><div style="margin-left:12ex"><a href="#section_2_6">2.6. The xOpen Method</a></div><div style="margin-left:12ex"><a href="#section_2_7">2.7. The xClose Method</a></div><div style="margin-left:12ex"><a href="#section_2_8">2.8. The xEof Method</a></div><div style="margin-left:12ex"><a href="#section_2_9">2.9. The xFilter Method</a></div><div style="margin-left:12ex"><a href="#section_2_10">2.10. The xNext Method</a></div><div style="margin-left:12ex"><a href="#section_2_11">2.11. The xColumn Method</a></div><div style="margin-left:12ex"><a href="#section_2_12">2.12. The xRowid Method</a></div><div style="margin-left:12ex"><a href="#section_2_13">2.13. The xUpdate Method</a></div><div style="margin-left:12ex"><a href="#section_2_14">2.14. The xFindFunction Method</a></div><div style="margin-left:12ex"><a href="#section_2_15">2.15. The xBegin Method</a></div><div style="margin-left:12ex"><a href="#section_2_16">2.16. The xSync Method</a></div><div style="margin-left:12ex"><a href="#section_2_17">2.17. The xCommit Method</a></div><div style="margin-left:12ex"><a href="#section_2_18">2.18. The xRollback Method</a></div><div style="margin-left:12ex"><a href="#section_2_19">2.19. The xRename Method</a></div><div style="margin-left:12ex"><a href="#section_2_20">2.20. The xSavepoint, xRelease, and xRollbackTo Methods</a></div> </div>
    <div class=startsearch></div>


<h1 id="section_1">1. Introduction</h1>

<p>A virtual table is an object that is registered with an open SQLite
<a href="c3ref/sqlite3.html">database connection</a>. From the perspective of an SQL statement,
the virtual table object looks like any other table or view. 
But behind the scenes, queries and updates on a virtual table
invoke callback methods of the virtual table object instead of
reading and writing on the database file.

<p>The virtual table mechanism allows an application to publish
interfaces that are accessible from SQL statements as if they were
tables. SQL statements can do almost anything to a
virtual table that they can do to a real table, with the following
exceptions:

186
187
188
189
190
191
192
193

194
195
196
197
198
199
200
     (the <a href="dbstat.html">dbstat virtual table</a>)
<li> Read and/or write the content of a comma-separated value (CSV)
     file
<li> Access the filesystem of the host computer as if it were a database table
<li> Enabling SQL manipulation of data in statistics packages like R
</ul>

<h3>1.1 Usage</h3>


<p>A virtual table is created using a <a href="lang_createvtab.html">CREATE VIRTUAL TABLE</a> statement.

<p><b><a href="syntax/create-virtual-table-stmt.html">create-virtual-table-stmt:</a></b>
<button id='x1475' onclick='hideorshow("x1475","x1476")'>hide</button></p>
 <blockquote id='x1476'>
 <img alt="syntax diagram create-virtual-table-stmt" src="images/syntax/create-virtual-table-stmt.gif" />







|
>







196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
     (the <a href="dbstat.html">dbstat virtual table</a>)
<li> Read and/or write the content of a comma-separated value (CSV)
     file
<li> Access the filesystem of the host computer as if it were a database table
<li> Enabling SQL manipulation of data in statistics packages like R
</ul>


<h2 id="section_1_1">1.1. Usage</h2>

<p>A virtual table is created using a <a href="lang_createvtab.html">CREATE VIRTUAL TABLE</a> statement.

<p><b><a href="syntax/create-virtual-table-stmt.html">create-virtual-table-stmt:</a></b>
<button id='x1475' onclick='hideorshow("x1475","x1476")'>hide</button></p>
 <blockquote id='x1476'>
 <img alt="syntax diagram create-virtual-table-stmt" src="images/syntax/create-virtual-table-stmt.gif" />
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
arguments.

<p>Once a virtual table has been created, it can be used like any other 
table with the exceptions noted above and imposed by specific virtual
table implementations. A virtual table is destroyed using the ordinary
<a href="lang_droptable.html">DROP TABLE</a> syntax.

<h4>1.1.1 Temporary virtual tables</h4>

<p>There is no "CREATE TEMP VIRTUAL TABLE" statement.  To create a
temporary virtual table, add the "temp" schema
before the virtual table name.

<blockcuqote><pre>
   CREATE VIRTUAL TABLE <b>temp.</b>tablename USING module(arg1, ...);
</pre></blockquote>

<a name="epovtab"></a>

<h4>1.1.2 Eponymous virtual tables</h4>

<p>Some virtual tables exist automatically in the "main" schema of
every database connection in which their
module is registered, even without a <a href="lang_createvtab.html">CREATE VIRTUAL TABLE</a> statement.
Such virtual tables are called "eponymous virtual tables".
To use an eponymous virtual table, simply use the 
module name as if it were a table.







|











|







244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
arguments.

<p>Once a virtual table has been created, it can be used like any other 
table with the exceptions noted above and imposed by specific virtual
table implementations. A virtual table is destroyed using the ordinary
<a href="lang_droptable.html">DROP TABLE</a> syntax.

<h3 id="section_1_1_1">1.1.1. Temporary virtual tables</h3>

<p>There is no "CREATE TEMP VIRTUAL TABLE" statement.  To create a
temporary virtual table, add the "temp" schema
before the virtual table name.

<blockcuqote><pre>
   CREATE VIRTUAL TABLE <b>temp.</b>tablename USING module(arg1, ...);
</pre></blockquote>

<a name="epovtab"></a>

<h3 id="section_1_1_2">1.1.2. Eponymous virtual tables</h3>

<p>Some virtual tables exist automatically in the "main" schema of
every database connection in which their
module is registered, even without a <a href="lang_createvtab.html">CREATE VIRTUAL TABLE</a> statement.
Such virtual tables are called "eponymous virtual tables".
To use an eponymous virtual table, simply use the 
module name as if it were a table.
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
using the <a href="lang_createvtab.html">CREATE VIRTUAL TABLE</a> statement.  The <a href="vtab.html#xconnect">xConnect</a> method whenever
a database connection attaches to or reparses a schema. When these two methods
are the same, that indicates that the virtual table has no persistent
state that needs to be created and destroyed.

<a name="epoonlyvtab"></a>

<h5>1.1.2.1 Eponymous-only virtual tables</h5>
<p>If the <a href="vtab.html#xcreate">xCreate</a> method is NULL, then
<a href="lang_createvtab.html">CREATE VIRTUAL TABLE</a> statements are prohibited for that virtual table,
and the virtual table is an "eponymous-only virtual table".
Eponymous-only virtual tables are useful as 
<a href="vtab.html#tabfunc2">table-valued functions</a>.

<p>
Note that SQLite versions prior to 3.9.0 did not check the xCreate method
for NULL before invoking it.  So if an eponymous-only virtual table is
registered with SQLite version 3.8.11.1 or earlier and a <a href="lang_createvtab.html">CREATE VIRTUAL TABLE</a>
command is attempted against that virtual table module, a jump to a NULL
pointer will occur, resulting in a crash.

<h3>1.2 Implementation</h3>

<p>Several new C-level objects are used by the virtual table implementation:

<blockquote><pre>
  typedef struct sqlite3_vtab sqlite3_vtab;
  typedef struct sqlite3_index_info sqlite3_index_info;
  typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;







|













|







288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
using the <a href="lang_createvtab.html">CREATE VIRTUAL TABLE</a> statement.  The <a href="vtab.html#xconnect">xConnect</a> method whenever
a database connection attaches to or reparses a schema. When these two methods
are the same, that indicates that the virtual table has no persistent
state that needs to be created and destroyed.

<a name="epoonlyvtab"></a>

<h3 id="section_1_1_3">1.1.3. Eponymous-only virtual tables</h3>
<p>If the <a href="vtab.html#xcreate">xCreate</a> method is NULL, then
<a href="lang_createvtab.html">CREATE VIRTUAL TABLE</a> statements are prohibited for that virtual table,
and the virtual table is an "eponymous-only virtual table".
Eponymous-only virtual tables are useful as 
<a href="vtab.html#tabfunc2">table-valued functions</a>.

<p>
Note that SQLite versions prior to 3.9.0 did not check the xCreate method
for NULL before invoking it.  So if an eponymous-only virtual table is
registered with SQLite version 3.8.11.1 or earlier and a <a href="lang_createvtab.html">CREATE VIRTUAL TABLE</a>
command is attempted against that virtual table module, a jump to a NULL
pointer will occur, resulting in a crash.

<h2 id="section_1_2">1.2. Implementation</h2>

<p>Several new C-level objects are used by the virtual table implementation:

<blockquote><pre>
  typedef struct sqlite3_vtab sqlite3_vtab;
  typedef struct sqlite3_index_info sqlite3_index_info;
  typedef struct sqlite3_vtab_cursor sqlite3_vtab_cursor;
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
definition might be extended with additional methods and in that case 
the iVersion value will be increased.

<p>The rest of the module structure consists of methods used to implement
various features of the virtual table. Details on what each of these 
methods do are provided in the sequel.

<h3>1.3 Virtual Tables And Shared Cache</h3>

<p>Prior to SQLite <a href="releaselog/3_6_17.html">version 3.6.17</a>, the virtual table mechanism assumes 
that each <a href="c3ref/sqlite3.html">database connection</a> kept
its own copy of the database schema. Hence, the virtual table mechanism
could not be used in a database that has <a href="sharedcache.html">shared cache mode</a> enabled. 
The <a href="c3ref/create_module.html">sqlite3_create_module()</a> interface would return an error if 
<a href="sharedcache.html">shared cache mode</a> is enabled.  That restriction was relaxed
beginning with SQLite <a href="releaselog/3_6_17.html">version 3.6.17</a>.

<h3>1.4 Creating New Virtual Table Implementations</h3>

<p>Follow these steps to create your own virtual table:

<p>
<ol>
<li> Write all necessary methods.
<li> Create an instance of the <a href="c3ref/module.html">sqlite3_module</a> structure containing pointers







|









|







451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
definition might be extended with additional methods and in that case 
the iVersion value will be increased.

<p>The rest of the module structure consists of methods used to implement
various features of the virtual table. Details on what each of these 
methods do are provided in the sequel.

<h2 id="section_1_3">1.3. Virtual Tables And Shared Cache</h2>

<p>Prior to SQLite <a href="releaselog/3_6_17.html">version 3.6.17</a>, the virtual table mechanism assumes 
that each <a href="c3ref/sqlite3.html">database connection</a> kept
its own copy of the database schema. Hence, the virtual table mechanism
could not be used in a database that has <a href="sharedcache.html">shared cache mode</a> enabled. 
The <a href="c3ref/create_module.html">sqlite3_create_module()</a> interface would return an error if 
<a href="sharedcache.html">shared cache mode</a> is enabled.  That restriction was relaxed
beginning with SQLite <a href="releaselog/3_6_17.html">version 3.6.17</a>.

<h2 id="section_1_4">1.4. Creating New Virtual Table Implementations</h2>

<p>Follow these steps to create your own virtual table:

<p>
<ol>
<li> Write all necessary methods.
<li> Create an instance of the <a href="c3ref/module.html">sqlite3_module</a> structure containing pointers
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496






497
498
499
500
501
502
503
504
(for testing purposes). You might use one of those as a guide. Locate 
these test virtual table implementations by searching 
for "sqlite3_create_module".

<p>You might also want to implement your new virtual table as a 
<a href="c3ref/load_extension.html">loadable extension</a>.

<h2>2.0 Virtual Table Methods</h2>

<a name="xcreate"></a>

<h3>2.1 The xCreate Method</h3>

<blockquote><pre>
  int (*xCreate)(sqlite3 *db, void *pAux,
               int argc, char **argv,
               sqlite3_vtab **ppVTab,
               char **pzErr);
</pre></blockquote>

<p>This method is called to create a new instance of a virtual table 
in response to a <a href="lang_createvtab.html">CREATE VIRTUAL TABLE</a> statement. 






The db parameter is a pointer to the SQLite <a href="c3ref/sqlite3.html">database connection</a> that 
is executing the <a href="lang_createvtab.html">CREATE VIRTUAL TABLE</a> statement. 
The pAux argument is the copy of the client data pointer that was the 
fourth argument to the <a href="c3ref/create_module.html">sqlite3_create_module()</a> or
<a href="c3ref/create_module.html">sqlite3_create_module_v2()</a> call that registered the 
<a href="c3ref/module.html">virtual table module</a>. 
The argv parameter is an array of argc pointers to null terminated strings. 
The first string, argv[0], is the name of the module being invoked.   The







|



|








|

>
>
>
>
>
>
|







486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
(for testing purposes). You might use one of those as a guide. Locate 
these test virtual table implementations by searching 
for "sqlite3_create_module".

<p>You might also want to implement your new virtual table as a 
<a href="c3ref/load_extension.html">loadable extension</a>.

<h1 id="section_2">2. Virtual Table Methods</h1>

<a name="xcreate"></a>

<h2 id="section_2_1">2.1. The xCreate Method</h2>

<blockquote><pre>
  int (*xCreate)(sqlite3 *db, void *pAux,
               int argc, char **argv,
               sqlite3_vtab **ppVTab,
               char **pzErr);
</pre></blockquote>

<p>The xCreate method is called to create a new instance of a virtual table 
in response to a <a href="lang_createvtab.html">CREATE VIRTUAL TABLE</a> statement. 
If the xCreate method is the same pointer as the <a href="vtab.html#xconnect">xConnect</a> method, then the
virtual table is an <a href="vtab.html#epovtab">eponymous virtual table</a>.
If the xCreate method is omitted (if it is a NULL pointer) then the virtual 
table is an <a href="vtab.html#epoonlyvtab">eponymous-only virtual table</a>.


<p>The db parameter is a pointer to the SQLite <a href="c3ref/sqlite3.html">database connection</a> that 
is executing the <a href="lang_createvtab.html">CREATE VIRTUAL TABLE</a> statement. 
The pAux argument is the copy of the client data pointer that was the 
fourth argument to the <a href="c3ref/create_module.html">sqlite3_create_module()</a> or
<a href="c3ref/create_module.html">sqlite3_create_module_v2()</a> call that registered the 
<a href="c3ref/module.html">virtual table module</a>. 
The argv parameter is an array of argc pointers to null terminated strings. 
The first string, argv[0], is the name of the module being invoked.   The
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
If the xCreate method is the exact same pointer as the <a href="vtab.html#xconnect">xConnect</a> method,
that indicates that the virtual table does not need to initialize backing
store.  Such a virtual table can be used as an <a href="vtab.html#epovtab">eponymous virtual table</a>
or as a named virtual table using <a href="lang_createvtab.html">CREATE VIRTUAL TABLE</a> or both.

<a name="hiddencol"></a>

<h4>2.1.1 Hidden columns in virtual tables</h4>
<p>If a column datatype contains the special keyword "HIDDEN"
(in any combination of upper and lower case letters) then that keyword
it is omitted from the column datatype name and the column is marked 
as a hidden column internally. 
A hidden column differs from a normal column in three respects:

<p>







|







582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
If the xCreate method is the exact same pointer as the <a href="vtab.html#xconnect">xConnect</a> method,
that indicates that the virtual table does not need to initialize backing
store.  Such a virtual table can be used as an <a href="vtab.html#epovtab">eponymous virtual table</a>
or as a named virtual table using <a href="lang_createvtab.html">CREATE VIRTUAL TABLE</a> or both.

<a name="hiddencol"></a>

<h3 id="section_2_1_1">2.1.1. Hidden columns in virtual tables</h3>
<p>If a column datatype contains the special keyword "HIDDEN"
(in any combination of upper and lower case letters) then that keyword
it is omitted from the column datatype name and the column is marked 
as a hidden column internally. 
A hidden column differs from a normal column in three respects:

<p>
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
<p>An example use of hidden columns can be seen in the <a href="fts3.html">FTS3</a> virtual 
table implementation, where every FTS virtual table
contains an <a href="fts3.html#hiddencol">FTS hidden column</a> that is used to pass information from the
virtual table into <a href="fts3.html#snippet">FTS auxiliary functions</a> and to the <a href="fts3.html#section_3">FTS MATCH</a> operator.

<a name="tabfunc2"></a>

<h4>2.1.2 Table-valued functions</h4>

<p>A <a href="vtab.html">virtual table</a> that contains <a href="vtab.html#hiddencol">hidden columns</a> can be used like
a table-valued function in the FROM clause of a <a href="lang_select.html">SELECT</a> statement.
The arguments to the table-valued function become constraints on 
the HIDDEN columns of the virtual table.

<p>For example, the "generate_series" extension (located in the







|







615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
<p>An example use of hidden columns can be seen in the <a href="fts3.html">FTS3</a> virtual 
table implementation, where every FTS virtual table
contains an <a href="fts3.html#hiddencol">FTS hidden column</a> that is used to pass information from the
virtual table into <a href="fts3.html#snippet">FTS auxiliary functions</a> and to the <a href="fts3.html#section_3">FTS MATCH</a> operator.

<a name="tabfunc2"></a>

<h3 id="section_2_1_2">2.1.2. Table-valued functions</h3>

<p>A <a href="vtab.html">virtual table</a> that contains <a href="vtab.html#hiddencol">hidden columns</a> can be used like
a table-valued function in the FROM clause of a <a href="lang_select.html">SELECT</a> statement.
The arguments to the table-valued function become constraints on 
the HIDDEN columns of the virtual table.

<p>For example, the "generate_series" extension (located in the
641
642
643
644
645
646
647

648
























649
650
651
652
653
654
655
656
657
658

<p>Arguments on the virtual table name are matched to <a href="vtab.html#hiddencol">hidden columns</a>
in order.  The number of arguments can be less than the
number of hidden columns, in which case the latter hidden columns are
unconstrained.  However, an error results if there are more arguments
than there are hidden columns in the virtual table.



























<a name="xconnect"></a>

<h3>2.2 The xConnect Method</h3>

<blockquote><pre>
  int (*xConnect)(sqlite3*, void *pAux,
               int argc, char **argv,
               sqlite3_vtab **ppVTab,
               char **pzErr);
</pre></blockquote>







>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


|







658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700

<p>Arguments on the virtual table name are matched to <a href="vtab.html#hiddencol">hidden columns</a>
in order.  The number of arguments can be less than the
number of hidden columns, in which case the latter hidden columns are
unconstrained.  However, an error results if there are more arguments
than there are hidden columns in the virtual table.

<a name="worid"></a>

<h3 id="section_2_1_3">2.1.3.  WITHOUT ROWID Virtual Tables </h3>

<p>Beginning with SQLite <a href="releaselog/3_14.html">version 3.14.0</a>, the CREATE TABLE statement that
is passed into <a href="c3ref/declare_vtab.html">sqlite3_declare_vtab()</a> may contain a <a href="withoutrowid.html">WITHOUT ROWID</a> clause.
This is useful for cases where the virtual table rows 
cannot easily be mapped into unique integers.  A CREATE TABLE
statement that includes WITHOUT ROWID must define one or more columns as
the PRIMARY KEY.  Every column of the PRIMARY KEY must individually be
NOT NULL and all columns for each row must be collectively unique.

<p>Note that SQLite does not enforce the PRIMARY KEY for a WITHOUT ROWID
virtual table.  Enforcement is the responsibility of the underlying
virtual table implementation.  But SQLite does assume that the PRIMARY KEY
constraint is valid - that the identified columns really are UNIQUE and
NOT NULL - and it uses that assumption to optimize queries against the
virtual table.

<p>The rowid column is not accessible on a
WITHOUT ROWID virtual table (of course).  Furthermore, since the
<a href="vtab.html#xupdate">xUpdate</a> method depends on having a valid rowid, the <a href="vtab.html#xupdate">xUpdate</a> method 
must be NULL for a WITHOUT ROWID virtual table.  That in turn means that
WITHOUT ROWID virtual tables must be read-only.


<a name="xconnect"></a>

<h2 id="section_2_2">2.2. The xConnect Method</h2>

<blockquote><pre>
  int (*xConnect)(sqlite3*, void *pAux,
               int argc, char **argv,
               sqlite3_vtab **ppVTab,
               char **pzErr);
</pre></blockquote>
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
<p>The xConnect method is required for every virtual table implementation, 
though the <a href="vtab.html#xcreate">xCreate</a> and xConnect pointers of the <a href="c3ref/module.html">sqlite3_module</a> object
may point to the same function if the virtual table does not need to
initialize backing store.

<a name="xbestindex"></a>

<h3>2.3 The xBestIndex Method</h3>

<p>SQLite uses the xBestIndex method of a virtual table module to determine
the best way to access the virtual table. 
The xBestIndex method has a prototype like this:

<blockquote><pre>
  int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);







|







742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
<p>The xConnect method is required for every virtual table implementation, 
though the <a href="vtab.html#xcreate">xCreate</a> and xConnect pointers of the <a href="c3ref/module.html">sqlite3_module</a> object
may point to the same function if the virtual table does not need to
initialize backing store.

<a name="xbestindex"></a>

<h2 id="section_2_3">2.3. The xBestIndex Method</h2>

<p>SQLite uses the xBestIndex method of a virtual table module to determine
the best way to access the virtual table. 
The xBestIndex method has a prototype like this:

<blockquote><pre>
  int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
<p>Note that xBestIndex will always be called before <a href="vtab.html#xfilter">xFilter</a>, since
the idxNum and idxStr outputs from xBestIndex are required inputs to
xFilter.  However, there is no guarantee that xFilter will be called
following a successful xBestIndex.  

<p>The xBestIndex method is required for every virtual table implementation.

<h4>2.3.1 Inputs</h4>

<p>The main thing that the SQLite core is trying to communicate to 
the virtual table is the constraints that are available to limit 
the number of rows that need to be searched. The aConstraint[] array 
contains one entry for each constraint. There will be exactly 
nConstraint entries in that array.








|







855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
<p>Note that xBestIndex will always be called before <a href="vtab.html#xfilter">xFilter</a>, since
the idxNum and idxStr outputs from xBestIndex are required inputs to
xFilter.  However, there is no guarantee that xFilter will be called
following a successful xBestIndex.  

<p>The xBestIndex method is required for every virtual table implementation.

<h3 id="section_2_3_1">2.3.1. Inputs</h3>

<p>The main thing that the SQLite core is trying to communicate to 
the virtual table is the constraints that are available to limit 
the number of rows that need to be searched. The aConstraint[] array 
contains one entry for each constraint. There will be exactly 
nConstraint entries in that array.

895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
means that the first column is used.  The second lowest bit corresponds
to the second column.  And so forth.  If the most significant bit of
colUsed is set, that means that one or more columns other than the 
first 63 columns are used.  If column usage information is needed by the
<a href="vtab.html#xfilter">xFilter</a> method, then the required bits must be encoded into either
the idxNum or idxStr output fields.

<h4>2.3.2 Outputs</h4>

<p>Given all of the information above, the job of the xBestIndex 
method it to figure out the best way to search the virtual table.

<p>The xBestIndex method fills the idxNum and idxStr fields with 
information that communicates an indexing strategy to the <a href="vtab.html#xfilter">xFilter</a> 
method. The information in idxNum and idxStr is arbitrary as far 







|







937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
means that the first column is used.  The second lowest bit corresponds
to the second column.  And so forth.  If the most significant bit of
colUsed is set, that means that one or more columns other than the 
first 63 columns are used.  If column usage information is needed by the
<a href="vtab.html#xfilter">xFilter</a> method, then the required bits must be encoded into either
the idxNum or idxStr output fields.

<h3 id="section_2_3_2">2.3.2. Outputs</h3>

<p>Given all of the information above, the job of the xBestIndex 
method it to figure out the best way to search the virtual table.

<p>The xBestIndex method fills the idxNum and idxStr fields with 
information that communicates an indexing strategy to the <a href="vtab.html#xfilter">xFilter</a> 
method. The information in idxNum and idxStr is arbitrary as far 
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
<p>By default, the SQLite core double checks all constraints on 
each row of the virtual table that it receives. If such a check 
is redundant, the xBestFilter method can suppress that double-check by 
setting aConstraintUsage[].omit.

<a name="xdisconnect"></a>

<h3>2.4 The xDisconnect Method</h3>

<blockquote><pre>
  int (*xDisconnect)(sqlite3_vtab *pVTab);
</pre></blockquote>

<p>This method releases a connection to a virtual table. 
Only the <a href="c3ref/vtab.html">sqlite3_vtab</a> object is destroyed.







|







1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
<p>By default, the SQLite core double checks all constraints on 
each row of the virtual table that it receives. If such a check 
is redundant, the xBestFilter method can suppress that double-check by 
setting aConstraintUsage[].omit.

<a name="xdisconnect"></a>

<h2 id="section_2_4">2.4. The xDisconnect Method</h2>

<blockquote><pre>
  int (*xDisconnect)(sqlite3_vtab *pVTab);
</pre></blockquote>

<p>This method releases a connection to a virtual table. 
Only the <a href="c3ref/vtab.html">sqlite3_vtab</a> object is destroyed.
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018

<p>The xDisconnect method is required for every virtual table implementation,
though it is acceptable for the xDisconnect and <a href="vtab.html#sqlite3_module.xDestroy">xDestroy</a> methods to be
the same function if that makes sense for the particular virtual table.

<a name="sqlite3_module.xDestroy"></a>

<h3>2.5 The xDestroy Method</h3>

<blockquote><pre>
  int (*xDestroy)(sqlite3_vtab *pVTab);
</pre></blockquote>

<p>This method releases a connection to a virtual table, just like 
the <a href="vtab.html#xdisconnect">xDisconnect</a> method, and it also destroys the underlying 
table implementation. This method undoes the work of <a href="vtab.html#xcreate">xCreate</a>.

<p>The <a href="vtab.html#xdisconnect">xDisconnect</a> method is called whenever a database connection
that uses a virtual table is closed. The xDestroy method is only 
called when a <a href="lang_droptable.html">DROP TABLE</a> statement is executed against the virtual table.

<p>The xDestroy method is required for every virtual table implementation,
though it is acceptable for the <a href="vtab.html#xdisconnect">xDisconnect</a> and xDestroy methods to be
the same function if that makes sense for the particular virtual table.

<a name="xopen"></a>

<h3>2.6 The xOpen Method</h3>

<blockquote><pre>
  int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
</pre></blockquote>

<p>The xOpen method creates a new cursor used for accessing (read and/or
writing) a virtual table.  A successful invocation of this method 







|



















|







1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060

<p>The xDisconnect method is required for every virtual table implementation,
though it is acceptable for the xDisconnect and <a href="vtab.html#sqlite3_module.xDestroy">xDestroy</a> methods to be
the same function if that makes sense for the particular virtual table.

<a name="sqlite3_module.xDestroy"></a>

<h2 id="section_2_5">2.5. The xDestroy Method</h2>

<blockquote><pre>
  int (*xDestroy)(sqlite3_vtab *pVTab);
</pre></blockquote>

<p>This method releases a connection to a virtual table, just like 
the <a href="vtab.html#xdisconnect">xDisconnect</a> method, and it also destroys the underlying 
table implementation. This method undoes the work of <a href="vtab.html#xcreate">xCreate</a>.

<p>The <a href="vtab.html#xdisconnect">xDisconnect</a> method is called whenever a database connection
that uses a virtual table is closed. The xDestroy method is only 
called when a <a href="lang_droptable.html">DROP TABLE</a> statement is executed against the virtual table.

<p>The xDestroy method is required for every virtual table implementation,
though it is acceptable for the <a href="vtab.html#xdisconnect">xDisconnect</a> and xDestroy methods to be
the same function if that makes sense for the particular virtual table.

<a name="xopen"></a>

<h2 id="section_2_6">2.6. The xOpen Method</h2>

<blockquote><pre>
  int (*xOpen)(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor);
</pre></blockquote>

<p>The xOpen method creates a new cursor used for accessing (read and/or
writing) a virtual table.  A successful invocation of this method 
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
The SQLite core will invoke the <a href="vtab.html#xfilter">xFilter</a> method
on the cursor prior to any attempt to position or read from the cursor.

<p>The xOpen method is required for every virtual table implementation.

<a name="xclose"></a>

<h3>2.7 The xClose Method</h3>

<blockquote><pre>
  int (*xClose)(sqlite3_vtab_cursor*);
</pre></blockquote>

<p>The xClose method closes a cursor previously opened by 
<a href="vtab.html#xopen">xOpen</a>. 
The SQLite core will always call xClose once for each cursor opened 
using xOpen.

<p>This method must release all resources allocated by the
corresponding xOpen call. The routine will not be called again even if it
returns an error.  The SQLite core will not use the
<a href="c3ref/vtab_cursor.html">sqlite3_vtab_cursor</a> again after it has been closed.

<p>The xClose method is required for every virtual table implementation.

<a name="xeof"></a>

<h3>2.8 The xEof Method</h3>

<blockquote><pre>
  int (*xEof)(sqlite3_vtab_cursor*);
</pre></blockquote>

<p>The xEof method must return false (zero) if the specified cursor 
currently points to a valid row of data, or true (non-zero) otherwise. 
This method is called by the SQL engine immediately after each 
<a href="vtab.html#xfilter">xFilter</a> and <a href="vtab.html#xnext">xNext</a> invocation.

<p>The xEof method is required for every virtual table implementation.

<a name="xfilter"></a>

<h3>2.9 The xFilter Method</h3>

<blockquote><pre>
  int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
                int argc, sqlite3_value **argv);
</pre></blockquote>

<p>This method begins a search of a virtual table. 







|



















|














|







1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
The SQLite core will invoke the <a href="vtab.html#xfilter">xFilter</a> method
on the cursor prior to any attempt to position or read from the cursor.

<p>The xOpen method is required for every virtual table implementation.

<a name="xclose"></a>

<h2 id="section_2_7">2.7. The xClose Method</h2>

<blockquote><pre>
  int (*xClose)(sqlite3_vtab_cursor*);
</pre></blockquote>

<p>The xClose method closes a cursor previously opened by 
<a href="vtab.html#xopen">xOpen</a>. 
The SQLite core will always call xClose once for each cursor opened 
using xOpen.

<p>This method must release all resources allocated by the
corresponding xOpen call. The routine will not be called again even if it
returns an error.  The SQLite core will not use the
<a href="c3ref/vtab_cursor.html">sqlite3_vtab_cursor</a> again after it has been closed.

<p>The xClose method is required for every virtual table implementation.

<a name="xeof"></a>

<h2 id="section_2_8">2.8. The xEof Method</h2>

<blockquote><pre>
  int (*xEof)(sqlite3_vtab_cursor*);
</pre></blockquote>

<p>The xEof method must return false (zero) if the specified cursor 
currently points to a valid row of data, or true (non-zero) otherwise. 
This method is called by the SQL engine immediately after each 
<a href="vtab.html#xfilter">xFilter</a> and <a href="vtab.html#xnext">xNext</a> invocation.

<p>The xEof method is required for every virtual table implementation.

<a name="xfilter"></a>

<h2 id="section_2_9">2.9. The xFilter Method</h2>

<blockquote><pre>
  int (*xFilter)(sqlite3_vtab_cursor*, int idxNum, const char *idxStr,
                int argc, sqlite3_value **argv);
</pre></blockquote>

<p>This method begins a search of a virtual table. 
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
<p>This method must return <a href="rescode.html#ok">SQLITE_OK</a> if successful, or an sqlite 
<a href="rescode.html">error code</a> if an error occurs.

<p>The xFilter method is required for every virtual table implementation.

<a name="xnext"></a>

<h3>2.10 The xNext Method</h3>

<blockquote><pre>
  int (*xNext)(sqlite3_vtab_cursor*);
</pre></blockquote>

<p>The xNext method advances a <a href="c3ref/vtab_cursor.html">virtual table cursor</a>
to the next row of a result set initiated by <a href="vtab.html#xfilter">xFilter</a>. 
If the cursor is already pointing at the last row when this 
routine is called, then the cursor no longer points to valid 
data and a subsequent call to the <a href="vtab.html#xeof">xEof</a> method must return true (non-zero). 
If the cursor is successfully advanced to another row of content, then
subsequent calls to <a href="vtab.html#xeof">xEof</a> must return false (zero).

<p>This method must return <a href="rescode.html#ok">SQLITE_OK</a> if successful, or an sqlite 
<a href="rescode.html">error code</a> if an error occurs.

<p>The xNext method is required for every virtual table implementation.

<a name="xcolumn"></a>

<h3>2.11 The xColumn Method</h3>

<blockquote><pre>
  int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int N);
</pre></blockquote>

<p>The SQLite core invokes this method in order to find the value for 
the N-th column of the current row. N is zero-based so the first column 







|




















|







1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
<p>This method must return <a href="rescode.html#ok">SQLITE_OK</a> if successful, or an sqlite 
<a href="rescode.html">error code</a> if an error occurs.

<p>The xFilter method is required for every virtual table implementation.

<a name="xnext"></a>

<h2 id="section_2_10">2.10. The xNext Method</h2>

<blockquote><pre>
  int (*xNext)(sqlite3_vtab_cursor*);
</pre></blockquote>

<p>The xNext method advances a <a href="c3ref/vtab_cursor.html">virtual table cursor</a>
to the next row of a result set initiated by <a href="vtab.html#xfilter">xFilter</a>. 
If the cursor is already pointing at the last row when this 
routine is called, then the cursor no longer points to valid 
data and a subsequent call to the <a href="vtab.html#xeof">xEof</a> method must return true (non-zero). 
If the cursor is successfully advanced to another row of content, then
subsequent calls to <a href="vtab.html#xeof">xEof</a> must return false (zero).

<p>This method must return <a href="rescode.html#ok">SQLITE_OK</a> if successful, or an sqlite 
<a href="rescode.html">error code</a> if an error occurs.

<p>The xNext method is required for every virtual table implementation.

<a name="xcolumn"></a>

<h2 id="section_2_11">2.11. The xColumn Method</h2>

<blockquote><pre>
  int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int N);
</pre></blockquote>

<p>The SQLite core invokes this method in order to find the value for 
the N-th column of the current row. N is zero-based so the first column 
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
methods to set the error message text, then return an appropriate
<a href="rescode.html">error code</a>.  The xColumn method must return <a href="rescode.html#ok">SQLITE_OK</a> on success.

<p>The xColumn method is required for every virtual table implementation.

<a name="xrowid"></a>

<h3>2.12 The xRowid Method</h3>

<blockquote><pre>
  int (*xRowid)(sqlite3_vtab_cursor *pCur, sqlite_int64 *pRowid);
</pre></blockquote>

<p>A successful invocation of this method will cause *pRowid to be
filled with the <a href="lang_createtable.html#rowid">rowid</a> of row that the
<a href="c3ref/vtab_cursor.html">virtual table cursor</a> pCur is currently pointing at.
This method returns <a href="rescode.html#ok">SQLITE_OK</a> on success.
It returns an appropriate <a href="rescode.html">error code</a> on failure.</p>

<p>The xRowid method is required for every virtual table implementation.

<a name="xupdate"></a>

<h3>2.13 The xUpdate Method</h3>

<blockquote><pre>
  int (*xUpdate)(
    sqlite3_vtab *pVTab,
    int argc,
    sqlite3_value **argv,
    sqlite_int64 *pRowid







|















|







1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
methods to set the error message text, then return an appropriate
<a href="rescode.html">error code</a>.  The xColumn method must return <a href="rescode.html#ok">SQLITE_OK</a> on success.

<p>The xColumn method is required for every virtual table implementation.

<a name="xrowid"></a>

<h2 id="section_2_12">2.12. The xRowid Method</h2>

<blockquote><pre>
  int (*xRowid)(sqlite3_vtab_cursor *pCur, sqlite_int64 *pRowid);
</pre></blockquote>

<p>A successful invocation of this method will cause *pRowid to be
filled with the <a href="lang_createtable.html#rowid">rowid</a> of row that the
<a href="c3ref/vtab_cursor.html">virtual table cursor</a> pCur is currently pointing at.
This method returns <a href="rescode.html#ok">SQLITE_OK</a> on success.
It returns an appropriate <a href="rescode.html">error code</a> on failure.</p>

<p>The xRowid method is required for every virtual table implementation.

<a name="xupdate"></a>

<h2 id="section_2_13">2.13. The xUpdate Method</h2>

<blockquote><pre>
  int (*xUpdate)(
    sqlite3_vtab *pVTab,
    int argc,
    sqlite3_value **argv,
    sqlite_int64 *pRowid
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
<p>The xUpdate method is optional.
If the xUpdate pointer in the <a href="c3ref/module.html">sqlite3_module</a> for a virtual table
is a NULL pointer, then the virtual table is read-only.


<a name="xfindfunction"></a>

<h3>2.14 The xFindFunction Method</h3>

<blockquote><pre>
  int (*xFindFunction)(
    sqlite3_vtab *pVtab,
    int nArg,
    const char *zName,
    void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),







|







1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
<p>The xUpdate method is optional.
If the xUpdate pointer in the <a href="c3ref/module.html">sqlite3_module</a> for a virtual table
is a NULL pointer, then the virtual table is read-only.


<a name="xfindfunction"></a>

<h2 id="section_2_14">2.14. The xFindFunction Method</h2>

<blockquote><pre>
  int (*xFindFunction)(
    sqlite3_vtab *pVtab,
    int nArg,
    const char *zName,
    void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
first argument.

<p>The function pointer returned by this routine must be valid for
the lifetime of the <a href="c3ref/vtab.html">sqlite3_vtab</a> object given in the first parameter.

<a name="xBegin"></a>

<h3>2.15 The xBegin Method</h3>

<blockquote><pre>
  int (*xBegin)(sqlite3_vtab *pVTab);
</pre></blockquote>

<p>This method begins a transaction on a virtual table.
This is method is optional.  The xBegin pointer of <a href="c3ref/module.html">sqlite3_module</a>
may be NULL.

<p>This method is always followed by one call to either the
<a href="vtab.html#xcommit">xCommit</a> or <a href="vtab.html#xrollback">xRollback</a> method.  Virtual table transactions do
not nest, so the xBegin method will not be invoked more than once
on a single virtual table
without an intervening call to either <a href="vtab.html#xcommit">xCommit</a> or <a href="vtab.html#xrollback">xRollback</a>.
Multiple calls to other methods can and likely will occur in between
the xBegin and the corresponding <a href="vtab.html#xcommit">xCommit</a> or <a href="vtab.html#xrollback">xRollback</a>.

<a name="xsync"></a>

<h3>2.16 The xSync Method</h3>

<blockquote><pre>
  int (*xSync)(sqlite3_vtab *pVTab);
</pre></blockquote>


<p>This method signals the start of a two-phase commit on a virtual
table.
This is method is optional.  The xSync pointer of <a href="c3ref/module.html">sqlite3_module</a>
may be NULL.

<p>This method is only invoked after call to the <a href="vtab.html#xBegin">xBegin</a> method and
prior to an <a href="vtab.html#xcommit">xCommit</a> or <a href="vtab.html#xrollback">xRollback</a>.  In order to implement two-phase
commit, the xSync method on all virtual tables is invoked prior to
invoking the <a href="vtab.html#xcommit">xCommit</a> method on any virtual table.  If any of the 
xSync methods fail, the entire transaction is rolled back.

<a name="xcommit"></a>

<h3>2.17 The xCommit Method</h3>

<blockquote><pre>
  int (*xCommit)(sqlite3_vtab *pVTab);
</pre></blockquote>

<p>This method causes a virtual table transaction to commit.
This is method is optional.  The xCommit pointer of <a href="c3ref/module.html">sqlite3_module</a>
may be NULL.

<p>A call to this method always follows a prior call to <a href="vtab.html#xBegin">xBegin</a> and
<a href="vtab.html#xsync">xSync</a>.


<a name="xrollback"></a>

<h3>2.18 The xRollback Method</h3>

<blockquote><pre>
  int (*xRollback)(sqlite3_vtab *pVTab);
</pre></blockquote>

<p>This method causes a virtual table transaction to rollback.
This is method is optional.  The xRollback pointer of <a href="c3ref/module.html">sqlite3_module</a>
may be NULL.

<p>A call to this method always follows a prior call to <a href="vtab.html#xBegin">xBegin</a>.


<a name="xrename"></a>

<h3>2.19 The xRename Method</h3>

<blockquote><pre>
  int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
</pre></blockquote>

<p>This method provides notification that the virtual table implementation
that the virtual table will be given a new name. 
If this method returns <a href="rescode.html#ok">SQLITE_OK</a> then SQLite renames the table.
If this method returns an <a href="rescode.html">error code</a> then the renaming is prevented.

<p>The xRename method is required for every virtual table implementation.

<a name="xsavepoint"></a>

<h3>2.20 The xSavepoint, xRelease, and xRollbackTo Methods</h3>

<blockquote><pre>
  int (*xSavepoint)(sqlite3_vtab *pVtab, int);
  int (*xRelease)(sqlite3_vtab *pVtab, int);
  int (*xRollbackTo)(sqlite3_vtab *pVtab, int);
</pre></blockquote>








|



















|



















|















|














|














|







1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
first argument.

<p>The function pointer returned by this routine must be valid for
the lifetime of the <a href="c3ref/vtab.html">sqlite3_vtab</a> object given in the first parameter.

<a name="xBegin"></a>

<h2 id="section_2_15">2.15. The xBegin Method</h2>

<blockquote><pre>
  int (*xBegin)(sqlite3_vtab *pVTab);
</pre></blockquote>

<p>This method begins a transaction on a virtual table.
This is method is optional.  The xBegin pointer of <a href="c3ref/module.html">sqlite3_module</a>
may be NULL.

<p>This method is always followed by one call to either the
<a href="vtab.html#xcommit">xCommit</a> or <a href="vtab.html#xrollback">xRollback</a> method.  Virtual table transactions do
not nest, so the xBegin method will not be invoked more than once
on a single virtual table
without an intervening call to either <a href="vtab.html#xcommit">xCommit</a> or <a href="vtab.html#xrollback">xRollback</a>.
Multiple calls to other methods can and likely will occur in between
the xBegin and the corresponding <a href="vtab.html#xcommit">xCommit</a> or <a href="vtab.html#xrollback">xRollback</a>.

<a name="xsync"></a>

<h2 id="section_2_16">2.16. The xSync Method</h2>

<blockquote><pre>
  int (*xSync)(sqlite3_vtab *pVTab);
</pre></blockquote>


<p>This method signals the start of a two-phase commit on a virtual
table.
This is method is optional.  The xSync pointer of <a href="c3ref/module.html">sqlite3_module</a>
may be NULL.

<p>This method is only invoked after call to the <a href="vtab.html#xBegin">xBegin</a> method and
prior to an <a href="vtab.html#xcommit">xCommit</a> or <a href="vtab.html#xrollback">xRollback</a>.  In order to implement two-phase
commit, the xSync method on all virtual tables is invoked prior to
invoking the <a href="vtab.html#xcommit">xCommit</a> method on any virtual table.  If any of the 
xSync methods fail, the entire transaction is rolled back.

<a name="xcommit"></a>

<h2 id="section_2_17">2.17. The xCommit Method</h2>

<blockquote><pre>
  int (*xCommit)(sqlite3_vtab *pVTab);
</pre></blockquote>

<p>This method causes a virtual table transaction to commit.
This is method is optional.  The xCommit pointer of <a href="c3ref/module.html">sqlite3_module</a>
may be NULL.

<p>A call to this method always follows a prior call to <a href="vtab.html#xBegin">xBegin</a> and
<a href="vtab.html#xsync">xSync</a>.


<a name="xrollback"></a>

<h2 id="section_2_18">2.18. The xRollback Method</h2>

<blockquote><pre>
  int (*xRollback)(sqlite3_vtab *pVTab);
</pre></blockquote>

<p>This method causes a virtual table transaction to rollback.
This is method is optional.  The xRollback pointer of <a href="c3ref/module.html">sqlite3_module</a>
may be NULL.

<p>A call to this method always follows a prior call to <a href="vtab.html#xBegin">xBegin</a>.


<a name="xrename"></a>

<h2 id="section_2_19">2.19. The xRename Method</h2>

<blockquote><pre>
  int (*xRename)(sqlite3_vtab *pVtab, const char *zNew);
</pre></blockquote>

<p>This method provides notification that the virtual table implementation
that the virtual table will be given a new name. 
If this method returns <a href="rescode.html#ok">SQLITE_OK</a> then SQLite renames the table.
If this method returns an <a href="rescode.html">error code</a> then the renaming is prevented.

<p>The xRename method is required for every virtual table implementation.

<a name="xsavepoint"></a>

<h2 id="section_2_20">2.20. The xSavepoint, xRelease, and xRollbackTo Methods</h2>

<blockquote><pre>
  int (*xSavepoint)(sqlite3_vtab *pVtab, int);
  int (*xRelease)(sqlite3_vtab *pVtab, int);
  int (*xRollbackTo)(sqlite3_vtab *pVtab, int);
</pre></blockquote>

Changes to Doc/vtab.tcl.
24
25
26
27
28
29
30





31
32
33
34
35
36
37
}

proc escapeSubSpec { data } {
  regsub -all -- {&} $data {\\\&} data
  regsub -all -- {\\(\d+)} $data {\\\\\1} data
  return $data
}






proc englishToList { value } {
  set result [list]

  foreach element [split $value "\t\n ,"] {
    if {[string tolower $element] ni [list "" and or]} then {
      lappend result $element







>
>
>
>
>







24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
}

proc escapeSubSpec { data } {
  regsub -all -- {&} $data {\\\&} data
  regsub -all -- {\\(\d+)} $data {\\\\\1} data
  return $data
}

proc removeSectionId { value } {
  regsub -- { id="section(?:_\d+)+"} $value "" value
  return $value
}

proc englishToList { value } {
  set result [list]

  foreach element [split $value "\t\n ,"] {
    if {[string tolower $element] ni [list "" and or]} then {
      lappend result $element
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  upvar 1 $indexVarName index
  upvar 1 $methodsVarName methods

  array set levels {p 0}
  set length [llength $lines]

  while {$index < $length} {
    set line [lindex $lines $index]

    if {[regexp -- $pattern $line]} then {
      break; # stop on this line for outer loop.
    } else {
      set trimLine [string trim $line]; set data ""

      if {$levels(p) > 0 && [string length $trimLine] == 0} then {







|







87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  upvar 1 $indexVarName index
  upvar 1 $methodsVarName methods

  array set levels {p 0}
  set length [llength $lines]

  while {$index < $length} {
    set line [removeSectionId [lindex $lines $index]]

    if {[regexp -- $pattern $line]} then {
      break; # stop on this line for outer loop.
    } else {
      set trimLine [string trim $line]; set data ""

      if {$levels(p) > 0 && [string length $trimLine] == 0} then {
187
188
189
190
191
192
193

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221

set inputData [string map [list \
    {<font size="6" color="red">*** DRAFT ***</font>} ""] $inputData]

set inputData [string map [list {<p align="center"></p>} ""] $inputData]

set lines [split [string map [list \r\n \n] $inputData] \n]

set patterns(method) {^<h3>2\.\d+ The (.*) Method(?:s)?</h3>$}
set prefix "        /// "
unset -nocomplain methods; set start false

for {set index 0} {$index < [llength $lines]} {} {
  set line [lindex $lines $index]

  if {$start} then {
    if {[regexp -- $patterns(method) $line dummy capture]} then {
      foreach method [englishToList $capture] {
        set methodIndex [expr {$index + 1}]

        extractMethod \
            $method $lines $patterns(method) $prefix methodIndex methods
      }

      set index $methodIndex
    } else {
      incr index
    }
  } elseif {[regexp -- {^<h2>2\.0 Virtual Table Methods</h2>$} $line]} then {
    set start true; incr index
  } else {
    incr index
  }
}

set outputData [string map [list \r\n \n] [readFile $outputFileName]]







>
|




|














|







192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227

set inputData [string map [list \
    {<font size="6" color="red">*** DRAFT ***</font>} ""] $inputData]

set inputData [string map [list {<p align="center"></p>} ""] $inputData]

set lines [split [string map [list \r\n \n] $inputData] \n]

set patterns(method) {^<h2>2\.\d+\. The (.*) Method(?:s)?</h2>$}
set prefix "        /// "
unset -nocomplain methods; set start false

for {set index 0} {$index < [llength $lines]} {} {
  set line [removeSectionId [lindex $lines $index]]

  if {$start} then {
    if {[regexp -- $patterns(method) $line dummy capture]} then {
      foreach method [englishToList $capture] {
        set methodIndex [expr {$index + 1}]

        extractMethod \
            $method $lines $patterns(method) $prefix methodIndex methods
      }

      set index $methodIndex
    } else {
      incr index
    }
  } elseif {[regexp -- {^<h1>2\. Virtual Table Methods</h1>$} $line]} then {
    set start true; incr index
  } else {
    incr index
  }
}

set outputData [string map [list \r\n \n] [readFile $outputFileName]]
Changes to System.Data.SQLite/ISQLiteNativeModule.cs.
18
19
20
21
22
23
24
25
26






27
28
29
30
31
32
33
        /// <para><code>
        ///   int (*xCreate)(sqlite3 *db, void *pAux,
        ///                int argc, char **argv,
        ///                sqlite3_vtab **ppVTab,
        ///                char **pzErr);
        /// </code></para>
        /// <para>
        /// This method is called to create a new instance of a virtual table 
        /// in response to a CREATE VIRTUAL TABLE statement. 






        /// The db parameter is a pointer to the SQLite database connection that 
        /// is executing the CREATE VIRTUAL TABLE statement. 
        /// The pAux argument is the copy of the client data pointer that was the 
        /// fourth argument to the sqlite3_create_module() or
        /// sqlite3_create_module_v2() call that registered the 
        /// virtual table module. 
        /// The argv parameter is an array of argc pointers to null terminated strings. 







|

>
>
>
>
>
>







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
        /// <para><code>
        ///   int (*xCreate)(sqlite3 *db, void *pAux,
        ///                int argc, char **argv,
        ///                sqlite3_vtab **ppVTab,
        ///                char **pzErr);
        /// </code></para>
        /// <para>
        /// The xCreate method is called to create a new instance of a virtual table 
        /// in response to a CREATE VIRTUAL TABLE statement. 
        /// If the xCreate method is the same pointer as the xConnect method, then the
        /// virtual table is an eponymous virtual table.
        /// If the xCreate method is omitted (if it is a NULL pointer) then the virtual 
        /// table is an eponymous-only virtual table.
        /// </para>
        /// <para>
        /// The db parameter is a pointer to the SQLite database connection that 
        /// is executing the CREATE VIRTUAL TABLE statement. 
        /// The pAux argument is the copy of the client data pointer that was the 
        /// fourth argument to the sqlite3_create_module() or
        /// sqlite3_create_module_v2() call that registered the 
        /// virtual table module. 
        /// The argv parameter is an array of argc pointers to null terminated strings. 
173
174
175
176
177
178
179
























180
181
182
183
184
185
186
        /// <para>
        /// Arguments on the virtual table name are matched to hidden columns
        /// in order.  The number of arguments can be less than the
        /// number of hidden columns, in which case the latter hidden columns are
        /// unconstrained.  However, an error results if there are more arguments
        /// than there are hidden columns in the virtual table.
        /// </para>
























        /// </summary>
        /// <param name="pDb">
        /// The native database connection handle.
        /// </param>
        /// <param name="pAux">
        /// The original native pointer value that was provided to the
        /// sqlite3_create_module(), sqlite3_create_module_v2() or







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
        /// <para>
        /// Arguments on the virtual table name are matched to hidden columns
        /// in order.  The number of arguments can be less than the
        /// number of hidden columns, in which case the latter hidden columns are
        /// unconstrained.  However, an error results if there are more arguments
        /// than there are hidden columns in the virtual table.
        /// </para>
        /// <para>
        /// Beginning with SQLite version 3.14.0, the CREATE TABLE statement that
        /// is passed into sqlite3_declare_vtab() may contain a WITHOUT ROWID clause.
        /// This is useful for cases where the virtual table rows 
        /// cannot easily be mapped into unique integers.  A CREATE TABLE
        /// statement that includes WITHOUT ROWID must define one or more columns as
        /// the PRIMARY KEY.  Every column of the PRIMARY KEY must individually be
        /// NOT NULL and all columns for each row must be collectively unique.
        /// </para>
        /// <para>
        /// Note that SQLite does not enforce the PRIMARY KEY for a WITHOUT ROWID
        /// virtual table.  Enforcement is the responsibility of the underlying
        /// virtual table implementation.  But SQLite does assume that the PRIMARY KEY
        /// constraint is valid - that the identified columns really are UNIQUE and
        /// NOT NULL - and it uses that assumption to optimize queries against the
        /// virtual table.
        /// </para>
        /// <para>
        /// The rowid column is not accessible on a
        /// WITHOUT ROWID virtual table (of course).  Furthermore, since the
        /// xUpdate method depends on having a valid rowid, the xUpdate method 
        /// must be NULL for a WITHOUT ROWID virtual table.  That in turn means that
        /// WITHOUT ROWID virtual tables must be read-only.
        /// </para>
        /// </summary>
        /// <param name="pDb">
        /// The native database connection handle.
        /// </param>
        /// <param name="pAux">
        /// The original native pointer value that was provided to the
        /// sqlite3_create_module(), sqlite3_create_module_v2() or