Documentation Source Text

Check-in [7d40b68595]
Login

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

Overview
Comment:Merge changes from 3.10.0.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7d40b685958ed7407ffb7caa3ed0795865ecb357
User & Date: drh 2016-01-12 13:44:54.758
Context
2016-01-13
20:52
Add documentation for the fts5 detail= option. (check-in: 08f6990b8a user: dan tags: trunk)
2016-01-12
13:44
Merge changes from 3.10.0. (check-in: 7d40b68595 user: drh tags: trunk)
13:44
Fix typos in the TCL interface documentation. (check-in: 217ea4895f user: drh tags: branch-3.10)
2016-01-11
13:00
Begin entering 3.11.0 changes. (check-in: 166fc2da3a user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to pages/tclsqlite.in.
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

<dt><b>-readonly</b> <i>BOOLEAN</i></dt>
<dd><p>
If true, then open the database file read-only.  If false, then the
database is opened for both reading and writing if filesystem permissions
allow, or for reading only if filesystem write permission is denied
by the operating system.  The default setting is "false".  Note that
if the previous process to have the database did not exits cleanly
and left behind a [hot journal], then the write permission is required
to recover the database after opening, and the database cannot be
opened read-only.
</p></dd>

<dt><b>-uri</b> <i>BOOLEAN</i></dt>
<dd><p>
If true, then interpret the filename argument as a [URI filename].  If
false, then the argument is a literal filename.  The default value is
"false".
</p></dd>

<dt><b>-vfs</b> <i>VFSNAME</i></dt>
<dd><p>
Use an alternative [VFS] named by the argument.
</p></dd>

</dl>
</blockquote>

<p>
Once an SQLite database is open, it can be controlled using 
methods of the <i>dbcmd</i>.  There are currently 22 methods
defined.</p>

<p>
<ul>

<tcl>
foreach m [lsort {
 authorizer
 backup
 busy
 cache
 changes
 close
 collate







|




















<
<
<
<
<
<
<
<

|







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

<dt><b>-readonly</b> <i>BOOLEAN</i></dt>
<dd><p>
If true, then open the database file read-only.  If false, then the
database is opened for both reading and writing if filesystem permissions
allow, or for reading only if filesystem write permission is denied
by the operating system.  The default setting is "false".  Note that
if the previous process to have the database did not exit cleanly
and left behind a [hot journal], then the write permission is required
to recover the database after opening, and the database cannot be
opened read-only.
</p></dd>

<dt><b>-uri</b> <i>BOOLEAN</i></dt>
<dd><p>
If true, then interpret the filename argument as a [URI filename].  If
false, then the argument is a literal filename.  The default value is
"false".
</p></dd>

<dt><b>-vfs</b> <i>VFSNAME</i></dt>
<dd><p>
Use an alternative [VFS] named by the argument.
</p></dd>

</dl>
</blockquote>









<tcl>
set method_list [lsort {
 authorizer
 backup
 busy
 cache
 changes
 close
 collate
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
168
169
170
171
172
173
174
175
 total_changes
 trace
 transaction
 unlock_notify
 update_hook
 version
 wal_hook
}] {





















 hd_puts "<li><a href=\"#$m\">$m</a></li>"
}
</tcl>
</ul>
</p>


<p>The use of each of these methods will be explained in the sequel, though
not in the order shown above.</p>

<tcl>
##############################################################################
METHOD eval {
<p>
The most useful <i>dbcmd</i> method is "eval".  The eval method is used
to execute SQL on the database.  The syntax of the eval method looks
like this:</p>

<blockquote>
<i>dbcmd</i>&nbsp;&nbsp;<b>eval</b>&nbsp;&nbsp;<i>sql</i>
&nbsp;&nbsp;&nbsp;&nbsp;?<i>array-name&nbsp;</i>?&nbsp;?<i>script</i>?
</blockquote>

<p>
The job of the eval method is to execute the SQL statement or statements
given in the second argument.  For example, to create a new table in
a database, you can do this:</p>








|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|


|
|
>














|







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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
 total_changes
 trace
 transaction
 unlock_notify
 update_hook
 version
 wal_hook
}]
</tcl>

<p>
Once an SQLite database is open, it can be controlled using 
methods of the <i>dbcmd</i>.
<tcl>
hd_puts "There are currently [llength $method_list] methods\n"
hd_puts "defined.</p>\n"
</tcl>

<table border=0 cellpadding=10 width='100%'>
<tr><td valign='top'><ul>
<tcl>
set nbr [expr {int(([llength $method_list]+2)/3)}]
set i -1
foreach m $method_list {
  incr i
  if {$i==$nbr} {
    hd_puts "</ul></td>\n<td valign='top'><ul>\n"
    set i 0
  }
  hd_puts "<li><a href=\"#$m\">$m</a></li>\n"
}
</tcl>
</ul></td></tr>
</table>


<p>The use of each of these methods will be explained in the sequel, though
not in the order shown above.</p>

<tcl>
##############################################################################
METHOD eval {
<p>
The most useful <i>dbcmd</i> method is "eval".  The eval method is used
to execute SQL on the database.  The syntax of the eval method looks
like this:</p>

<blockquote>
<i>dbcmd</i>&nbsp;&nbsp;<b>eval</b>&nbsp;&nbsp;<i>sql</i>
&nbsp;&nbsp;?<i>array-name</i>?&nbsp;&nbsp;?<i>script</i>?
</blockquote>

<p>
The job of the eval method is to execute the SQL statement or statements
given in the second argument.  For example, to create a new table in
a database, you can do this:</p>

279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
</p>

<p>
If the $bigstring variable has both a string and a "bytearray" representation,
then TCL inserts the value as a string.  If it has only a "bytearray"
representation, then the value is inserted as a BLOB.  To force a
value to be inserted as a BLOB even if it also has a text representation,
us a "@" character to in place of the "$".  Like this:
</p>

<blockquote><b>
db1 eval {INSERT INTO t1 VALUES(5,@bigstring)}
</b></blockquote>

<p>







|







293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
</p>

<p>
If the $bigstring variable has both a string and a "bytearray" representation,
then TCL inserts the value as a string.  If it has only a "bytearray"
representation, then the value is inserted as a BLOB.  To force a
value to be inserted as a BLOB even if it also has a text representation,
use a "@" character to in place of the "$".  Like this:
</p>

<blockquote><b>
db1 eval {INSERT INTO t1 VALUES(5,@bigstring)}
</b></blockquote>

<p>
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378

<p>
The syntax looks like this:
</p>

<blockquote>
<i>dbcmd</i>&nbsp;&nbsp;<b>transaction</b>&nbsp;&nbsp;<i>?transaction-type?</i>
&nbsp;&nbsp;<i>SCRIPT,</i>
</blockquote>


<p>
The <i>transaction-type</i> can be one of <b>deferred</b>,
<b>exclusive</b> or <b>immediate</b>.  The default is deferred.
</p>







|







378
379
380
381
382
383
384
385
386
387
388
389
390
391
392

<p>
The syntax looks like this:
</p>

<blockquote>
<i>dbcmd</i>&nbsp;&nbsp;<b>transaction</b>&nbsp;&nbsp;<i>?transaction-type?</i>
&nbsp;&nbsp;<i>script</i>
</blockquote>


<p>
The <i>transaction-type</i> can be one of <b>deferred</b>,
<b>exclusive</b> or <b>immediate</b>.  The default is deferred.
</p>
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
The "copy" method copies data from a file into a table.
It returns the number of rows processed successfully from the file.
The syntax of the copy method looks like this:</p>

<blockquote>
<i>dbcmd</i>&nbsp;&nbsp;<b>copy</b>&nbsp;&nbsp;<i>conflict-algorithm</i>
&nbsp;&nbsp;<i>table-name&nbsp;</i>&nbsp;&nbsp;<i>file-name&nbsp;</i>
&nbsp;&nbsp;&nbsp;&nbsp;?<i>column-separator&nbsp;</i>?
&nbsp;&nbsp;?<i>null-indicator</i>?
</blockquote>

<p>Conflict-algorithm must be one of the SQLite conflict algorithms for
the INSERT statement: <i>rollback</i>, <i>abort</i>,
<i>fail</i>,<i>ignore</i>, or <i>replace</i>. See the SQLite Language
section for <a href="lang.html#conflict">ON CONFLICT</a> for more information.







|







446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
The "copy" method copies data from a file into a table.
It returns the number of rows processed successfully from the file.
The syntax of the copy method looks like this:</p>

<blockquote>
<i>dbcmd</i>&nbsp;&nbsp;<b>copy</b>&nbsp;&nbsp;<i>conflict-algorithm</i>
&nbsp;&nbsp;<i>table-name&nbsp;</i>&nbsp;&nbsp;<i>file-name&nbsp;</i>
&nbsp;&nbsp;&nbsp;&nbsp;?<i>column-separator</i>?
&nbsp;&nbsp;?<i>null-indicator</i>?
</blockquote>

<p>Conflict-algorithm must be one of the SQLite conflict algorithms for
the INSERT statement: <i>rollback</i>, <i>abort</i>,
<i>fail</i>,<i>ignore</i>, or <i>replace</i>. See the SQLite Language
section for <a href="lang.html#conflict">ON CONFLICT</a> for more information.
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
The default is an empty string.  Note that column-separator and
null-indicator are optional positional arguments; if null-indicator
is specified, a column-separator argument must be specified and
precede the null-indicator argument.</p>

<p>The copy method implements similar functionality to the <b>.import</b>
SQLite shell command. 
The SQLite 2.x <a href="lang.html#copy"><b>COPY</b></a> statement 
(using the PostgreSQL COPY file format)
can be implemented with this method as:</p>

<blockquote>
dbcmd&nbsp;&nbsp;copy&nbsp;&nbsp;$conflictalgo
&nbsp;&nbsp;$tablename&nbsp;&nbsp;&nbsp;$filename&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;\t&nbsp;
&nbsp;&nbsp;\\N
</blockquote>

}

##############################################################################
METHOD timeout {

<p>The "timeout" method is used to control how long the SQLite library
will wait for locks to clear before giving up on a database transaction.







<
<
<
<
<
<
<
<
<
<
<







473
474
475
476
477
478
479











480
481
482
483
484
485
486
The default is an empty string.  Note that column-separator and
null-indicator are optional positional arguments; if null-indicator
is specified, a column-separator argument must be specified and
precede the null-indicator argument.</p>

<p>The copy method implements similar functionality to the <b>.import</b>
SQLite shell command. 











}

##############################################################################
METHOD timeout {

<p>The "timeout" method is used to control how long the SQLite library
will wait for locks to clear before giving up on a database transaction.
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
##############################################################################
METHOD incrblob {

<p>This method opens a TCL channel that can be used to read or write
into a preexisting BLOB in the database.  The syntax is like this:</p>

<blockquote>
<i>dbcmd</i>&nbsp;&nbsp;<b>incrblob</b>&nbsp;&nbsp;<b>?-readonly??</b>
&nbsp;&nbsp;<i>?DB?&nbsp;&nbsp;TABLE&nbsp;&nbsp;COLUMN&nbsp;&nbsp;ROWID</i>
</blockquote>

<p>
The command returns a new TCL channel for reading or writing to the BLOB.
The channel is opened using the underlying 
<a href="c3ref/blob_open.html">sqlite3_blob_open()</a> C-language







|







783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
##############################################################################
METHOD incrblob {

<p>This method opens a TCL channel that can be used to read or write
into a preexisting BLOB in the database.  The syntax is like this:</p>

<blockquote>
<i>dbcmd</i>&nbsp;&nbsp;<b>incrblob</b>&nbsp;&nbsp;<b>?-readonly?</b>
&nbsp;&nbsp;<i>?DB?&nbsp;&nbsp;TABLE&nbsp;&nbsp;COLUMN&nbsp;&nbsp;ROWID</i>
</blockquote>

<p>
The command returns a new TCL channel for reading or writing to the BLOB.
The channel is opened using the underlying 
<a href="c3ref/blob_open.html">sqlite3_blob_open()</a> C-language
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
written.  <i>Backup-filename</i> does not have to exist ahead of time, but if
it does, it must be a well-formed SQLite database.</p>
}

##############################################################################
METHOD restore {

<p>The "restore" method copies the content a separate database file 
into the current database connection, overwriting any preexisting content.
The command syntax is like this:</p>

<blockquote>
<i>dbcmd</i>&nbsp;&nbsp;<b>restore</b>&nbsp;&nbsp;?<i>target-database</i>?&nbsp;&nbsp;<i>source-filename</i>
</blockquote>








|







837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
written.  <i>Backup-filename</i> does not have to exist ahead of time, but if
it does, it must be a well-formed SQLite database.</p>
}

##############################################################################
METHOD restore {

<p>The "restore" method copies the content from a separate database file 
into the current database connection, overwriting any preexisting content.
The command syntax is like this:</p>

<blockquote>
<i>dbcmd</i>&nbsp;&nbsp;<b>restore</b>&nbsp;&nbsp;?<i>target-database</i>?&nbsp;&nbsp;<i>source-filename</i>
</blockquote>