Documentation Source Text

Check-in [ebd923dab6]
Login

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

Overview
Comment:Further enhancements to the virtual table documentation.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ebd923dab6e1dbdabcc7b3ca60c8ceae0e1dabc7
User & Date: drh 2009-04-13 14:43:00
References
2009-04-13
15:07
Merge [ebd923dab6] and [491737c7cf]. check-in: 8f18472bac user: dan tags: trunk
Context
2009-07-29
23:07
Merge lang.html and vtab.html corrections that got marooned on a branch into the main line. check-in: ab7c4f5247 user: drh tags: trunk
2009-04-13
14:43
Further enhancements to the virtual table documentation. check-in: ebd923dab6 user: drh tags: trunk
12:58
Initial check-in of documentation on the virtual table interface. check-in: 0776bf4007 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to pages/lang.in.

933
934
935
936
937
938
939

940
941
942
943
944
945
946
947
prior to issuing the CREATE VIRTUAL TABLE statement.
The module takes zero or more comma-separated arguments.
The arguments can be just about any text as long as it has balanced
parentheses.  The argument syntax is sufficiently general that the
arguments can be made to appear as column definitions in a traditional
[CREATE TABLE] statement.  
SQLite passes the module arguments directly

to the module without any interpretation.  It is the responsibility
of the module implementation to parse and interpret its own arguments.</p>

<p>A virtual table is destroyed using the ordinary
[DROP TABLE] statement.  There is no
DROP VIRTUAL TABLE statement.</p>

<tcl>







>
|







933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
prior to issuing the CREATE VIRTUAL TABLE statement.
The module takes zero or more comma-separated arguments.
The arguments can be just about any text as long as it has balanced
parentheses.  The argument syntax is sufficiently general that the
arguments can be made to appear as column definitions in a traditional
[CREATE TABLE] statement.  
SQLite passes the module arguments directly
to the [xCreate] and [xConnect] methods of the module implementation
without any interpretation.  It is the responsibility
of the module implementation to parse and interpret its own arguments.</p>

<p>A virtual table is destroyed using the ordinary
[DROP TABLE] statement.  There is no
DROP VIRTUAL TABLE statement.</p>

<tcl>

Changes to pages/vtab.in.

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48


49
50
51
52
53
54
55
56
57
58
59
60
61
62
..
66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
...
130
131
132
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
...
167
168
169
170
171
172
173

174
175
176
177
178
179
180
181
182
...
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
...
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
...
254
255
256
257
258
259
260

261
262
263
264
265
266
267
...
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
...
327
328
329
330
331
332
333

334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
...
371
372
373
374
375
376
377

378
379
380
381
382
383
384
...
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
...
566
567
568
569
570
571
572

573
574
575
576
577
578
579
580
581
582
583

584
585
586
587
588
589
590
591
592
593
594
595
596
597

598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615

616
617
618
619
620
621
622

623
624
625
626
627
628
629

630
631
632
633
634
635
636
637
638
639
640

641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
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

701
702
703
704
705
706
707

708

709
710
711
712
713
714
715
...
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
...
765
766
767
768
769
770
771

772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805

806
807
808
809
810
811
812
813

814
815
816
817
818
819
820
821

822
823
824
825
826
827
828
829

830
831
832
833
834
835
836
837

838
839
840
841
842
843
844
845
846
847

<h1 align="center">The Virtual Table Mechanism Of SQLite</h1>
<tcl>hd_keywords {virtual table} {virtual tables}</tcl>

<h2>1.0 Introduction</h2>

<p>A virtual table is an object that is registered with an open SQLite
database connection. From the perspective of an SQL statement,
the virtual table object looks like any other table or view. 
But behind the scenes, queries from and updates to a virtual table
invoke callback methods on 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
................................................................................

<p>
<ul>
<li> One cannot create a trigger on a virtual table.
<li> One cannot create additional indices on a virtual table. 
     (Virtual tables can have indices but that must be built into
     the virtual table implementation.  Indices cannot be added
     separately using CREATE INDEX statements.)
<li> One cannot run ALTER TABLE commands against a virtual table.
<li> Virtual tables cannot be used in a database that makes use of
     the [shared cache] feature. 
</ul>

<p>Particular virtual table implementations might impose additional
constraints. For example, some virtual implementations might provide
read-only tables. Or some virtual table implementations might allow
INSERT or DELETE but not UPDATE.  Or some virtual table implementations
might limit the kinds of UPDATEs that can be made.

<p>A virtual table might represent an in-memory data structures. 
Or it might represent a view of data on disk that is not in the
SQLite format. Or the application might compute the content of the 
virtual table on demand.

<p>Here are some postulated uses for virtual tables:

<ul>
<li> A full-text search interface
<li> Spatial indices using R-Trees


<li> Access to the filesystem of the host computer
<li> Enabling SQL manipulation of data in statistics packages like R
</ul>

<h3>1.1 Usage</h3>

<p>A virtual table is created using using a CREATE VIRTUAL TABLE statement.
This statement creates a table with a particular name and associates the
table with a "module".

<blockquote><pre>
   CREATE VIRTUAL TABLE tablename USING modulename;
</pre></blockquote>

................................................................................
<blockquote><pre>
   CREATE VIRTUAL TABLE tablename USING modulename(arg1, arg2, ...);
</pre></blockquote>

<p>The format of the arguments to the module is very general. Each argument 
can consist of keywords, string literals, identifiers, numbers, and 
punctuation. The arguments are passed as written (as text) into the
constructor metod of the virtual table implementation when the virtual 

table is created and that constructor is responsible for parsing and 
interpreting the arguments. The argument syntax is sufficiently general 
that a virtual table implementation can, if it wants to, interpret its
arguments as column definitions in an ordinary CREATE TABLE statement. 
The implementation could also impose some other interpretation on the 
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
DROP TABLE syntax.

<h2>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;
  typedef struct sqlite3_module sqlite3_module;
</pre></blockquote>

<p>The sqlite3_module structure defines a module object used to implement
a virtual table. Think of a module as a class from which you can 
construct multiple virtual tables having similar properties. For example,
one might have a module that provides read-only access to 
comma-separated-value (CSV) files on disk. That one module can then be
used to create several virtual tables where each virtual table refers
to a different CSV file.

<p>The module structure contains methods that are invoked by SQLite to
perform various actions on the virtual table such as creating new
instances of a virtual table or destroying old ones, reading and
writing data, searching for and deleting, updating, or inserting rows. 
The module structure is explained in more detail below.

<p>Each virtual table instance is represented by an sqlite3_vtab structure. 
The sqlite3_vtab structure looks like this:

<blockquote><pre>
  struct sqlite3_vtab {
    const sqlite3_module *pModule;
    int nRef;
    char *zErrMsg;
................................................................................
[sqlite3_free()]. Failure to do this might result in a memory leak. 
The SQLite core will free and zero the content of zErrMsg when it 
delivers the error message text to the client application or when 
it destroys the virtual table. The virtual table implementation only 
needs to worry about freeing the zErrMsg content when it overwrites 
the content with a new, different error message.

<p>The sqlite3_vtab_cursor structure represents a pointer to a specific
row of a virtual table. This is what an sqlite3_vtab_cursor looks like:

<blockquote><pre>
  struct sqlite3_vtab_cursor {
    sqlite3_vtab *pVtab;
  };
</pre></blockquote>

<p>Once again, practical implementations will likely subclass this 
structure to add additional private fields.

<p>The sqlite3_index_info structure is used to pass information into
and out of the xBestIndex method of the module that implements a 
virtual table.

<p>Before a CREATE VIRTUAL TABLE statement can be run, the module 
specified in that statement must be registered with the database 
connection. This is accomplished using either of the [sqlite3_create_module()]
or [sqlite3_create_module_v2()] interfaces:

<blockquote><pre>
  int sqlite3_create_module(
    sqlite3 *db,               /* SQLite connection to register module with */
................................................................................
    const char *zName,         /* Name of the module */
    const sqlite3_module *,    /* Methods for the module */
    void *,                    /* Client data for xCreate/xConnect */
    void(*xDestroy)(void*)     /* Client data destructor function */
  );
</pre></blockquote>


<p>The sqlite3_create_module() routines associates a module name with 
an sqlite3_module structure and a separate client data that is specific 
to each module.  The only difference between the two create_module methods
is that the _v2 method includes an extra parameter that specifies a
destructor for client data pointer.  The module structure is what defines
the behavior of a virtual table.  The module structure looks like this:

<blockquote><pre>  
  struct sqlite3_module {
................................................................................
                       void **ppArg);
    int (*Rename)(sqlite3_vtab *pVtab, const char *zNew);
  };
</pre></blockquote>

<p>The module structure defines all of the methods for each virtual 
table object. The module structure also contains the iVersion field which
 defines the particular edition of the module table structure. Currently, 
iVersion is always 1, but in future releases of SQLite the module structure 
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.2 Virtual Tables And Shared Cache</h3>

<p>The virtual table mechanism assumes that each database connection keeps 
its own copy of the database schema. Hence, the virtual table mechanism
cannot be used in a database that has [shared cache] enabled. 
The [sqlite3_create_module()] interface will return an error if 
the [shared cache] feature is enabled.

<h3>1.3 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 [sqlite3_module] structure containing pointers
     to all the methods from step 1.
<li> Register your [sqlite3_module] structure using the
     [sqlite3_create_module()] API.
<li> Run a [CREATE VIRTUAL TABLE] command that specifies your module in 
     the USING clause. 
</ol>

<p>The only really hard part is step 1. You might want to start with an 
existing virtual table implementation and modify it to suit your needs.
There are several virtual table implementations in the SQLite source tree 
(for testing purposes). You might use one of those as a guide. Locate 
................................................................................
for "sqlite3_create_module".

<p>You might also want to implement your new virtual table as a 
[sqlite3_load_extension | loadable extension].

<h2>2.0 Virtual Table Methods</h2>


<h3>2.1 The xCreate Method</h3>

<blockquote><pre>
  int (*xCreate)(sqlite3 *db, void *pAux,
               int argc, char **argv,
               sqlite3_vtab **ppVTab,
               char **pzErr);
................................................................................
If present, the fourth and subsquent strings in the argv[] array report 
the arguments to the module name in the [CREATE VIRTUAL TABLE] statement.

<p>The job of this method is to construct the new virtual table object
(an [sqlite3_vtab] object) and return a pointer to it in *ppVTab.

<p>As part of the task of creating a new [sqlite3_vtab] structure, this 
method must invoke [sqlite3_declare_vtab()] to tell the SQLite core about 
the columns and datatypes in the virtual table. 
The [sqlite3_declare_vtab()] API has the following prototype:

<blockquote><pre>
    int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable)
</pre></blockquote>

<p>The first argument to [sqlite3_declare_vtab()] is the pointer to the 
................................................................................

<p>The xCreate method should return [SQLITE_OK] if it is successful in 
creating the new virtual table, or [SQLITE_ERROR] if it is not successful.
If not successful, no [sqlite3_vtab] structure should be allocated. 
An error message may optionally be returned in *pzErr if unsuccessful.
The text of the error message should be obtained from [sqlite3_mprintf()].


<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>

<p>The xConnect method is very similar to xCreate. 
It has the same parameters and constructs a new [sqlite3_vtab] structure 
just like xCreate. 
And it must also call [sqlite3_declare_vtab()] like xCreate.

<p>The difference is that xConnect is called to establish a new 
connection to an existing virtual table whereas xCreate is called 
to create a new virtual table from scratch.
................................................................................
<p>The xConnect method should return [SQLITE_OK] if it is successful 
in creating the new virtual table, or [SQLITE_ERROR] if it is not 
successful. If not successful, no [sqlite3_vtab] structure should be 
allocated. An error message may optionally be returned in *pzErr if 
unsuccessful. 
The text of the error message should be obtained from [sqlite3_mprintf()].


<h3>2.3 The xBestIndex Method</h3>

<p>The xBestIndex method has a prototype like this:

<blockquote><pre>
  int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
</pre></blockquote>
................................................................................
<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 xFilter 
method. The information in idxNum and idxStr is arbitrary as far 
as the SQLite core is concerned. The SQLite core just copies the 
information through to the xFilter method. Any desired meaning can 
be assigned to idxNum and idxStr as long as xBestIndex and xFilter 
agree on what that meaning is.

<p>The idxStr value can be a string obtained from [sqlite3_mprintf()]. 
If this is the case, then the needToFreeIdxStr flag must be set to 
true so that the SQLite core will know to call [sqlite3_free()] on 
that string when it has finished with it, and thus avoid a memory leak.
................................................................................
the EXPR value of the aConstraint[3] constraint.

<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 check by 
setting aConstraintUsage[].omit.


<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. 
The virtual table is not destroyed and any backing store 
associated with the virtual table persists. 
This method is the opposite of xConnect.


<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 xDisconnect method, and it also destroys the underlying 
table implementation. This method is the opposite of xCreate.

<p>The xDisconnect method is called whenever a database connection
that uses a virtual table is closed. The xDestroy method is only 
called when a [DROP TABLE] statement is executed against the virtual table.


<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 reading information
out of a virtual table.  A successful invocation of this method 
will allocate the memory for the [sqlite3_vtab_cursor] (or a subclass),
initialize the new object, and make *ppCursor point to the new object.
The successful call then returns [SQLITE_OK].

<p>The cursor is not immediately usable. It must first be positioned 
using xFilter. Then elements of a row of the virtual table can be 
accessed using xColumn and xRowid.

<p>The xClose method is used to close the cursor.


<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 xOpen. 

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 if it
returns an error.


<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 
xFilter and xNext invocation.


<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 to begin a search of a virtual table. 
The first argument is a cursor opened by xOpen. 
The next two argument define a particular search index previously 
choosen by xBestIndex The specific meanings of idxNum and idxStr 
are unimportant as long as xFilter and xBestIndex agree on what 
that meaning is.

<p>The xBestIndex function may have requested the values of 
certain expressions using the aConstraintUsage[].argvIndex values 
of the sqlite3_index_info structure. 
Those values are passed to xFilter using the argc and argv parameters.

<p>If the filtering constraints configured by idxNum and idxStr do 
not match any rows of the virtual table (i.e. no rows of data will 
be returned), then a subsequent call to the xEof method of the same 
table should return non-zero. Otherwise, xEof should return zero 
and the cursor should be left pointing at a row of the virtual table. 
The xColumn and xRowid methods can be used to access that row. 
The xNext method can be used to advance to the next row.

<p>This method should return SQLITE_OK if successful, or an sqlite 
error code if an error occurs.


<h3>2.10 The xNext Method</h3>

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

<p>The xNext method advances a virtual table cursor to the next row 
of a result set initiated by xFilter. 
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 xEof method should return non-zero. 
Otherwise, the xEof method returns zero.

<p>This method should return SQLITE_OK if successful, or an sqlite 
error code if an error occurs.


<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 
is numbered 0. The xColumn method uses one of the 
[sqlite3_result_blob | sqlite3_result_*() APIs] 
to return the result. 
This method can invoke [sqlite3_result_error()] to raise an exception, 
if desired.


<h3>2.12 The xRowid Method</h3>

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

<p>This method writes the 64-bit rowid of the current row into *pRowid.



<h3>2.13 The xUpdate Method</h3>

<blockquote><pre>
  int (*xUpdate)(
    sqlite3_vtab *pVTab,
    int argc,
    sqlite3_value **argv,
................................................................................
<p>All changes to a virtual table are made using the xUpdate method.
This one method can be used to insert, delete, or update.

<p>The argc parameter specifies the number of entries in the argv array. 
Every argv entry will have a non-NULL value in C (but may contain the 
SQL value NULL).

<p>The argv[0] parameter is the rowid of a row in the virtual table 
to be deleted. If argv[0] is NULL, then no deletion occurs.

<p>The argv[1] parameter is the rowid of a new row to be inserted 
into the virtual table. If argv[1] is NULL, then the implementation 
must choose a rowid for the newly inserted row. Subsequent argv[] 
entries contain values of the columns of the virtual table, in the 
order that the columns were declared. The number of columns will
match the table declaration that the xConnect or xCreate method made 
using the [sqlite3_declare_vtab()] call.

<p>When doing an insert without a rowid (argc>1, argv[1]==NULL), the 
implementation must set *pRowid to the id of the newly inserted row; 
this will become the value returned by the [sqlite3_last_insert_rowid()]
function. Setting this value in all the other cases has no effect,
and cannot be used to change the rowid of an existing row or if you 
don't like what was in argv[1].

<p>Each call to xUpdate will fall into one of the following cases:

................................................................................
</blockquote>
</dl>
</blockquote>

<p>It is currently undocumented what effect changes should have on 
existing cursors.


<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**),
    void **ppArg
  );
</pre></blockquote>

<p>This method is called during sqlite3_prepare to give the virtual
table implementation an opportunity to overload functions. 
This method may be set to NULL in which case no overloading occurs.

<p>When a function uses a column from a virtual table as its first 
argument, this method is called to see if the virtual table would 
like to overload the function. The first three parameters are inputs: 
the virtual table, the number of arguments to the function, and the 
name of the function. If no overloading is desired, this method
returns 0. To overload the function, this method writes the new 
function implementation into *pxFunc and writes user data into *ppArg 
and returns 1.

<p>Note that infix functions (LIKE, GLOB, REGEXP, and MATCH) reverse 
the order of their arguments. So "like(A,B)" is equivalent to "B like A". 
For the form "B like A" the B term is considered the first argument 
to the function. But for "like(A,B)" the A term is considered the 
first argument.

<p>It is currently undocumented how often this function is called or 
when you can free any resources allocated in order to respond - #2095


<h3>2.15 The xBegin Method</h3>

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

<i>TBD...</i>


<h3>2.16 The xSync Method</h3>

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

<i>TBD...</i>


<h3>2.17 The xCommit Method</h3>

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

<i>TBD...</i>


<h3>2.18 The xRollback Method</h3>

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

<i>TBD...</i>


<h3>2.19 The xRename Method</h3>

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

<p>This method provides sotification that the virtual table implementation
that the virtual table will be given a new name. 
If this method returns SQLITE_OK then SQLite renames the table.
If this method returns an error then the renaming is prevented.







|







 







|
|







|












>
>






|







 







|
>



|






|












|
|












|







 







|











|



|







 







>
|
|







 







|










|







 







|
|
|







 







>







 







|
|







 







>









|







 







>







 







|







 







>









|

>








|





>













|
|



>






|
>







>









|

>








|

|





|







|
|

|


>






|
|


|


|
|

>







 







>



|


|
>

>







 







|







|



|







 







>












|












|








>








>








>








>








>










2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
..
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
...
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
...
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
...
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
...
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
...
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
...
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
...
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
...
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
...
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
...
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
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
701
702
703
704
705
706
707
708
709
...
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
...
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
...
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872

<h1 align="center">The Virtual Table Mechanism Of SQLite</h1>
<tcl>hd_keywords {virtual table} {virtual tables}</tcl>

<h2>1.0 Introduction</h2>

<p>A virtual table is an object that is registered with an open SQLite
[database connection]. From the perspective of an SQL statement,
the virtual table object looks like any other table or view. 
But behind the scenes, queries from and updates to a virtual table
invoke callback methods on 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
................................................................................

<p>
<ul>
<li> One cannot create a trigger on a virtual table.
<li> One cannot create additional indices on a virtual table. 
     (Virtual tables can have indices but that must be built into
     the virtual table implementation.  Indices cannot be added
     separately using [CREATE INDEX] statements.)
<li> One cannot run [ALTER TABLE] commands against a virtual table.
<li> Virtual tables cannot be used in a database that makes use of
     the [shared cache] feature. 
</ul>

<p>Particular virtual table implementations might impose additional
constraints. For example, some virtual implementations might provide
read-only tables. Or some virtual table implementations might allow
[INSERT] or [DELETE] but not [UPDATE].  Or some virtual table implementations
might limit the kinds of UPDATEs that can be made.

<p>A virtual table might represent an in-memory data structures. 
Or it might represent a view of data on disk that is not in the
SQLite format. Or the application might compute the content of the 
virtual table on demand.

<p>Here are some postulated uses for virtual tables:

<ul>
<li> A full-text search interface
<li> Spatial indices using R-Trees
<li> Read and/or write the content of a comma-separated value (CSV)
     file
<li> Access to the filesystem of the host computer
<li> Enabling SQL manipulation of data in statistics packages like R
</ul>

<h3>1.1 Usage</h3>

<p>A virtual table is created using using a [CREATE VIRTUAL TABLE] statement.
This statement creates a table with a particular name and associates the
table with a "module".

<blockquote><pre>
   CREATE VIRTUAL TABLE tablename USING modulename;
</pre></blockquote>

................................................................................
<blockquote><pre>
   CREATE VIRTUAL TABLE tablename USING modulename(arg1, arg2, ...);
</pre></blockquote>

<p>The format of the arguments to the module is very general. Each argument 
can consist of keywords, string literals, identifiers, numbers, and 
punctuation. The arguments are passed as written (as text) into the
[xCreate | constructor method] of the virtual table implementation 
when the virtual 
table is created and that constructor is responsible for parsing and 
interpreting the arguments. The argument syntax is sufficiently general 
that a virtual table implementation can, if it wants to, interpret its
arguments as column definitions in an ordinary [CREATE TABLE] statement. 
The implementation could also impose some other interpretation on the 
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
[DROP TABLE] syntax.

<h2>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;
  typedef struct sqlite3_module sqlite3_module;
</pre></blockquote>

<p>The [sqlite3_module] structure defines a module object used to implement
a virtual table. Think of a module as a class from which one can 
construct multiple virtual tables having similar properties. For example,
one might have a module that provides read-only access to 
comma-separated-value (CSV) files on disk. That one module can then be
used to create several virtual tables where each virtual table refers
to a different CSV file.

<p>The module structure contains methods that are invoked by SQLite to
perform various actions on the virtual table such as creating new
instances of a virtual table or destroying old ones, reading and
writing data, searching for and deleting, updating, or inserting rows. 
The module structure is explained in more detail below.

<p>Each virtual table instance is represented by an [sqlite3_vtab] structure. 
The sqlite3_vtab structure looks like this:

<blockquote><pre>
  struct sqlite3_vtab {
    const sqlite3_module *pModule;
    int nRef;
    char *zErrMsg;
................................................................................
[sqlite3_free()]. Failure to do this might result in a memory leak. 
The SQLite core will free and zero the content of zErrMsg when it 
delivers the error message text to the client application or when 
it destroys the virtual table. The virtual table implementation only 
needs to worry about freeing the zErrMsg content when it overwrites 
the content with a new, different error message.

<p>The [sqlite3_vtab_cursor] structure represents a pointer to a specific
row of a virtual table. This is what an sqlite3_vtab_cursor looks like:

<blockquote><pre>
  struct sqlite3_vtab_cursor {
    sqlite3_vtab *pVtab;
  };
</pre></blockquote>

<p>Once again, practical implementations will likely subclass this 
structure to add additional private fields.

<p>The [sqlite3_index_info] structure is used to pass information into
and out of the xBestIndex method of the module that implements a 
virtual table.

<p>Before a [CREATE VIRTUAL TABLE] statement can be run, the module 
specified in that statement must be registered with the database 
connection. This is accomplished using either of the [sqlite3_create_module()]
or [sqlite3_create_module_v2()] interfaces:

<blockquote><pre>
  int sqlite3_create_module(
    sqlite3 *db,               /* SQLite connection to register module with */
................................................................................
    const char *zName,         /* Name of the module */
    const sqlite3_module *,    /* Methods for the module */
    void *,                    /* Client data for xCreate/xConnect */
    void(*xDestroy)(void*)     /* Client data destructor function */
  );
</pre></blockquote>

<p>The [sqlite3_create_module()] and [sqlite3_create_module_v2()]
routines associates a module name with 
an [sqlite3_module] structure and a separate client data that is specific 
to each module.  The only difference between the two create_module methods
is that the _v2 method includes an extra parameter that specifies a
destructor for client data pointer.  The module structure is what defines
the behavior of a virtual table.  The module structure looks like this:

<blockquote><pre>  
  struct sqlite3_module {
................................................................................
                       void **ppArg);
    int (*Rename)(sqlite3_vtab *pVtab, const char *zNew);
  };
</pre></blockquote>

<p>The module structure defines all of the methods for each virtual 
table object. The module structure also contains the iVersion field which
defines the particular edition of the module table structure. Currently, 
iVersion is always 1, but in future releases of SQLite the module structure 
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.2 Virtual Tables And Shared Cache</h3>

<p>The virtual table mechanism assumes that each [database connection] keeps 
its own copy of the database schema. Hence, the virtual table mechanism
cannot be used in a database that has [shared cache] enabled. 
The [sqlite3_create_module()] interface will return an error if 
the [shared cache] feature is enabled.

<h3>1.3 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 [sqlite3_module] structure containing pointers
     to all the methods from step 1.
<li> Register your [sqlite3_module] structure using one of the
     [sqlite3_create_module()] or [sqlite3_create_module_v2()] interfaces.
<li> Run a [CREATE VIRTUAL TABLE] command that specifies the new module in 
     the USING clause. 
</ol>

<p>The only really hard part is step 1. You might want to start with an 
existing virtual table implementation and modify it to suit your needs.
There are several virtual table implementations in the SQLite source tree 
(for testing purposes). You might use one of those as a guide. Locate 
................................................................................
for "sqlite3_create_module".

<p>You might also want to implement your new virtual table as a 
[sqlite3_load_extension | loadable extension].

<h2>2.0 Virtual Table Methods</h2>

<tcl>hd_fragment xcreate {sqlite3_module.xCreate} {xCreate}</tcl>
<h3>2.1 The xCreate Method</h3>

<blockquote><pre>
  int (*xCreate)(sqlite3 *db, void *pAux,
               int argc, char **argv,
               sqlite3_vtab **ppVTab,
               char **pzErr);
................................................................................
If present, the fourth and subsquent strings in the argv[] array report 
the arguments to the module name in the [CREATE VIRTUAL TABLE] statement.

<p>The job of this method is to construct the new virtual table object
(an [sqlite3_vtab] object) and return a pointer to it in *ppVTab.

<p>As part of the task of creating a new [sqlite3_vtab] structure, this 
method <u>must</u> invoke [sqlite3_declare_vtab()] to tell the SQLite 
core about the columns and datatypes in the virtual table. 
The [sqlite3_declare_vtab()] API has the following prototype:

<blockquote><pre>
    int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable)
</pre></blockquote>

<p>The first argument to [sqlite3_declare_vtab()] is the pointer to the 
................................................................................

<p>The xCreate method should return [SQLITE_OK] if it is successful in 
creating the new virtual table, or [SQLITE_ERROR] if it is not successful.
If not successful, no [sqlite3_vtab] structure should be allocated. 
An error message may optionally be returned in *pzErr if unsuccessful.
The text of the error message should be obtained from [sqlite3_mprintf()].

<tcl>hd_fragment xconnect {sqlite3_module.xConnect} {xConnect}</tcl>
<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>

<p>The xConnect method is very similar to [xCreate]. 
It has the same parameters and constructs a new [sqlite3_vtab] structure 
just like xCreate. 
And it must also call [sqlite3_declare_vtab()] like xCreate.

<p>The difference is that xConnect is called to establish a new 
connection to an existing virtual table whereas xCreate is called 
to create a new virtual table from scratch.
................................................................................
<p>The xConnect method should return [SQLITE_OK] if it is successful 
in creating the new virtual table, or [SQLITE_ERROR] if it is not 
successful. If not successful, no [sqlite3_vtab] structure should be 
allocated. An error message may optionally be returned in *pzErr if 
unsuccessful. 
The text of the error message should be obtained from [sqlite3_mprintf()].

<tcl>hd_fragment xbestindex {sqlite3_module.xBestIndex} {xBestIndex}</tcl>
<h3>2.3 The xBestIndex Method</h3>

<p>The xBestIndex method has a prototype like this:

<blockquote><pre>
  int (*xBestIndex)(sqlite3_vtab *pVTab, sqlite3_index_info*);
</pre></blockquote>
................................................................................
<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 xFilter 
method. The information in idxNum and idxStr is arbitrary as far 
as the SQLite core is concerned. The SQLite core just copies the 
information through to the [xFilter] method. Any desired meaning can 
be assigned to idxNum and idxStr as long as xBestIndex and xFilter 
agree on what that meaning is.

<p>The idxStr value can be a string obtained from [sqlite3_mprintf()]. 
If this is the case, then the needToFreeIdxStr flag must be set to 
true so that the SQLite core will know to call [sqlite3_free()] on 
that string when it has finished with it, and thus avoid a memory leak.
................................................................................
the EXPR value of the aConstraint[3] constraint.

<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 check by 
setting aConstraintUsage[].omit.

<tcl>hd_fragment xdisconnect {sqlite3_module.xDisconnect} {xDisconnect}</tcl>
<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. 
The virtual table is not destroyed and any backing store 
associated with the virtual table persists. 
This method is the opposite of [xConnect].

<tcl>hd_fragment {sqlite3_module.xDestroy} {xDestroy}</tcl>
<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 xDisconnect method, and it also destroys the underlying 
table implementation. This method is the opposite of [xCreate].

<p>The xDisconnect method is called whenever a database connection
that uses a virtual table is closed. The xDestroy method is only 
called when a [DROP TABLE] statement is executed against the virtual table.

<tcl>hd_fragment xopen {sqlite3_module.xOpen}</tcl>
<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 reading information
out of a virtual table.  A successful invocation of this method 
will allocate the memory for the [sqlite3_vtab_cursor] (or a subclass),
initialize the new object, and make *ppCursor point to the new object.
The successful call then returns [SQLITE_OK].

<p>The cursor is not immediately usable. It must first be positioned 
using [xFilter]. Then elements of a row of the virtual table can be 
accessed using [xColumn] and [xRowid].

<p>The xClose method is used to close the cursor.

<tcl>hd_fragment xclose {sqlite3_module.xClose}</tcl>
<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 
[sqlite3_module.xOpen | xOpen]. 
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 if it
returns an error.

<tcl>hd_fragment xeof {sqlite3_module.xEof} {xEof}</tcl>
<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 
[xFilter] and [xNext] invocation.

<tcl>hd_fragment xfilter {sqlite3_module.xFilter} {xFilter}</tcl>
<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 to begin a search of a virtual table. 
The first argument is a cursor opened by [sqlite3_module.xOpen | xOpen]. 
The next two argument define a particular search index previously 
choosen by [xBestIndex]. The specific meanings of idxNum and idxStr 
are unimportant as long as xFilter and xBestIndex agree on what 
that meaning is.

<p>The xBestIndex function may have requested the values of 
certain expressions using the aConstraintUsage[].argvIndex values 
of the [sqlite3_index_info] structure. 
Those values are passed to xFilter using the argc and argv parameters.

<p>If the filtering constraints configured by idxNum and idxStr do 
not match any rows of the virtual table (i.e. no rows of data will 
be returned), then a subsequent call to the xEof method of the same 
table should return non-zero. Otherwise, xEof should return zero 
and the cursor should be left pointing at a row of the virtual table. 
The [xColumn] and [xRowid] methods can be used to access that row. 
The [xNext] method can be used to advance to the next row.

<p>This method should return [SQLITE_OK] if successful, or an sqlite 
error code if an error occurs.

<tcl>hd_fragment xnext {sqlite3_module.xNext} {xNext}</tcl>
<h3>2.10 The xNext Method</h3>

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

<p>The xNext method advances a [virtual table cursor] to the next row 
of a result set initiated by [xFilter]. 
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 [xEof] method should return non-zero. 
Otherwise, the xEof method returns zero.

<p>This method should return [SQLITE_OK] if successful, or an sqlite 
[error code] if an error occurs.

<tcl>hd_fragment xcolumn {sqlite3_module.xColumn} {xColumn}</tcl>
<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 
is numbered 0. The xColumn method uses one of the 
[sqlite3_result_blob | sqlite3_result_*() APIs] 
to return the result. 
This method can invoke [sqlite3_result_error()] to raise an exception, 
if desired.

<tcl>hd_fragment xrowid {sqlite3_module.xRowid} {xRowid}</tcl>
<h3>2.12 The xRowid Method</h3>

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

<p>This method writes into *pRowid the 64-bit [rowid] of row that the
[virtual table cursor] pCur is currently pointing at.</p>

<tcl>hd_fragment xupdate {sqlite3_module.xUpdate} {xUpdate}</tcl>
<h3>2.13 The xUpdate Method</h3>

<blockquote><pre>
  int (*xUpdate)(
    sqlite3_vtab *pVTab,
    int argc,
    sqlite3_value **argv,
................................................................................
<p>All changes to a virtual table are made using the xUpdate method.
This one method can be used to insert, delete, or update.

<p>The argc parameter specifies the number of entries in the argv array. 
Every argv entry will have a non-NULL value in C (but may contain the 
SQL value NULL).

<p>The argv[0] parameter is the [rowid] of a row in the virtual table 
to be deleted. If argv[0] is NULL, then no deletion occurs.

<p>The argv[1] parameter is the rowid of a new row to be inserted 
into the virtual table. If argv[1] is NULL, then the implementation 
must choose a rowid for the newly inserted row. Subsequent argv[] 
entries contain values of the columns of the virtual table, in the 
order that the columns were declared. The number of columns will
match the table declaration that the [xConnect] or [xCreate] method made 
using the [sqlite3_declare_vtab()] call.

<p>When doing an insert without a rowid (argc>1, argv[1]==NULL), the 
implementation must set *pRowid to the rowid of the newly inserted row; 
this will become the value returned by the [sqlite3_last_insert_rowid()]
function. Setting this value in all the other cases has no effect,
and cannot be used to change the rowid of an existing row or if you 
don't like what was in argv[1].

<p>Each call to xUpdate will fall into one of the following cases:

................................................................................
</blockquote>
</dl>
</blockquote>

<p>It is currently undocumented what effect changes should have on 
existing cursors.

<tcl>hd_fragment xfindfunction {sqlite3_module.xFindFunction} {xFindFunction}</tcl>
<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**),
    void **ppArg
  );
</pre></blockquote>

<p>This method is called during [sqlite3_prepare()] to give the virtual
table implementation an opportunity to overload functions. 
This method may be set to NULL in which case no overloading occurs.

<p>When a function uses a column from a virtual table as its first 
argument, this method is called to see if the virtual table would 
like to overload the function. The first three parameters are inputs: 
the virtual table, the number of arguments to the function, and the 
name of the function. If no overloading is desired, this method
returns 0. To overload the function, this method writes the new 
function implementation into *pxFunc and writes user data into *ppArg 
and returns 1.

<p>Note that infix functions ([LIKE], [GLOB], [REGEXP], and [MATCH]) reverse 
the order of their arguments. So "like(A,B)" is equivalent to "B like A". 
For the form "B like A" the B term is considered the first argument 
to the function. But for "like(A,B)" the A term is considered the 
first argument.

<p>It is currently undocumented how often this function is called or 
when you can free any resources allocated in order to respond - #2095

<tcl>hd_fragment xBegin {sqlite3_module.xBegin} {xBegin}</tcl>
<h3>2.15 The xBegin Method</h3>

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

<i>TBD...</i>

<tcl>hd_fragment xsync {sqlite3_module.xSync}</tcl>
<h3>2.16 The xSync Method</h3>

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

<i>TBD...</i>

<tcl>hd_fragment xcommit {sqlite3_module.xCommit} {xCommit}</tcl>
<h3>2.17 The xCommit Method</h3>

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

<i>TBD...</i>

<tcl>hd_fragment xrollback {sqlite3_module.xRollback} {xRollback}</tcl>
<h3>2.18 The xRollback Method</h3>

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

<i>TBD...</i>

<tcl>hd_fragment xrename {sqlite3_module.xRename} {xRename}</tcl>
<h3>2.19 The xRename Method</h3>

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

<p>This method provides sotification that the virtual table implementation
that the virtual table will be given a new name. 
If this method returns SQLITE_OK then SQLite renames the table.
If this method returns an error then the renaming is prevented.