Documentation Source Text

Check-in [feccb40483]
Login

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

Overview
Comment:Update to the virtual table documentation - in particular the documentation on the xUpdate method.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: feccb40483d9b5550015462ac07d88e27e71d9b9
User & Date: drh 2009-04-14 18:15:09
Context
2009-04-14
18:20
More virtual table documentation tweaks. check-in: 0d0a959a73 user: drh tags: trunk
18:15
Update to the virtual table documentation - in particular the documentation on the xUpdate method. check-in: feccb40483 user: drh tags: trunk
11:45
Additional virtual table documentation improvements. Fix the "when-to-use" document to omit discussion of the obsolete bitmap size limits. check-in: 9ef2178fee user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to pages/vtab.in.

871
872
873
874
875
876
877
878
879



880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899



900
901
902
903
904
905
906
907


908
909

910
911
912
913

914
915
916
917
918
919
920
  );
</pre></blockquote>

<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.  All hidden columns are included.

<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 is a harmless no-op;
the SQLite engine ignores the *pRowid return value if argc==1 or 
argv[1]!=NULL.

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




<blockquote>
<dl>
<dt><b>argc == 1</b>
<dd><p>The single row argv[0] is deleted; no insert occurs

<dt><b>argc > 1 && argv[0] == NULL</b>
<dd><p>A new row is inserted with rowid argv[1]



<dt><b>argc > 1 && argv[0] != NULL && argv[0] == argv[1]</b>

<dd><p>The row with rowid argv[0] is updated with new values 
       in argv[2] and following parameters

<dt><b>argc > 1 && argv[0] != NULL && argv[0] != argv[1]</b>

<dd><p> The row with rowid argv[0] is updated with rowid argv[1] 
and new values in argv[2] and following parameters. This will occur 
when an SQL statement updates a rowid, as in the statement:
<blockquote>
   [UPDATE] table SET rowid=rowid+1 WHERE ...; 
</blockquote>
</dl>







|
|
>
>
>


|


|






|




|

|
>
>
>



|
|

|
|
>
>

<
>

|

<
>







871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916

917
918
919
920

921
922
923
924
925
926
927
928
  );
</pre></blockquote>

<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.  In other words, it is always true that
<tt>argv&#91;i&#93;!=0</tt> for <b>i</b> between 0 and <tt>argc-1</tt>.
However, it might be the case that
<tt>sqlite3_value_type(argv&#91;i&#93;)==SQLITE_NULL</tt>.

<p>The argv[0] parameter is the [rowid] of a row in the virtual table 
to be deleted. If argv[0] is an SQL 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 an SQL 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.  All hidden columns are included.

<p>When doing an insert without a rowid (argc>1, argv[1] is an SQL 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 is a harmless no-op;
the SQLite engine ignores the *pRowid return value if argc==1 or 
argv[1] is not an SQL NULL.

<p>Each call to xUpdate will fall into one of cases shown below.
Not that references to <b>argv&#91;i&#93</b> mean the SQL value
held within the argv&#91;i&#93; object, not the argv&#91;i&#93;
object itself.

<blockquote>
<dl>
<dt><b>argc = 1</b>
<dd><p>The single row with rowid equal to argv[0] is deleted. No insert occurs.

<dt><b>argc > 1 <br> argv[0] = NULL</b>
<dd><p>A new row is inserted with a rowid argv[1] and column values in
       argv[2] and following.  If argv[1] is an SQL NULL,
       the a new unique rowid is generated automatically.


<dt><b>argc > 1 <br> argv[0] &ne; NULL <br> argv[0] = argv[1]</b>
<dd><p>The row with rowid argv[0] is updated with new values 
       in argv[2] and following parameters.


<dt><b>argc > 1 <br> argv[0] &ne; NULL <br> argv[0] &ne; argv[1]</b>
<dd><p> The row with rowid argv[0] is updated with rowid argv[1] 
and new values in argv[2] and following parameters. This will occur 
when an SQL statement updates a rowid, as in the statement:
<blockquote>
   [UPDATE] table SET rowid=rowid+1 WHERE ...; 
</blockquote>
</dl>