diff options
author | dan miller | 2007-10-20 02:49:29 +0000 |
---|---|---|
committer | dan miller | 2007-10-20 02:49:29 +0000 |
commit | e36d23a85ebff914d74bb541558c2b6082b78edb (patch) | |
tree | 54b58fdf162e78af64055282a6035c8d2443389d /libraries/sqlite/unix/sqlite-3.5.1/www/tclsqlite.tcl | |
parent | * Fixed an issue whereby avatar chat distances were being calculated against ... (diff) | |
download | opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.zip opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.gz opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.bz2 opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.xz |
sqlite source (unix build) added to libraries
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/www/tclsqlite.tcl')
-rw-r--r-- | libraries/sqlite/unix/sqlite-3.5.1/www/tclsqlite.tcl | 666 |
1 files changed, 666 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/www/tclsqlite.tcl b/libraries/sqlite/unix/sqlite-3.5.1/www/tclsqlite.tcl new file mode 100644 index 0000000..141cb5e --- /dev/null +++ b/libraries/sqlite/unix/sqlite-3.5.1/www/tclsqlite.tcl | |||
@@ -0,0 +1,666 @@ | |||
1 | # | ||
2 | # Run this Tcl script to generate the tclsqlite.html file. | ||
3 | # | ||
4 | set rcsid {$Id: tclsqlite.tcl,v 1.17 2007/06/19 17:48:57 drh Exp $} | ||
5 | source common.tcl | ||
6 | header {The Tcl interface to the SQLite library} | ||
7 | proc METHOD {name text} { | ||
8 | puts "<a name=\"$name\">\n<h3>The \"$name\" method</h3>\n" | ||
9 | puts $text | ||
10 | } | ||
11 | puts { | ||
12 | <h2>The Tcl interface to the SQLite library</h2> | ||
13 | |||
14 | <p>The SQLite library is designed to be very easy to use from | ||
15 | a Tcl or Tcl/Tk script. This document gives an overview of the Tcl | ||
16 | programming interface.</p> | ||
17 | |||
18 | <h3>The API</h3> | ||
19 | |||
20 | <p>The interface to the SQLite library consists of single | ||
21 | tcl command named <b>sqlite3</b> | ||
22 | Because there is only this | ||
23 | one command, the interface is not placed in a separate | ||
24 | namespace.</p> | ||
25 | |||
26 | <p>The <b>sqlite3</b> command is used as follows:</p> | ||
27 | |||
28 | <blockquote> | ||
29 | <b>sqlite3</b> <i>dbcmd database-name</i> | ||
30 | </blockquote> | ||
31 | |||
32 | <p> | ||
33 | The <b>sqlite3</b> command opens the database named in the second | ||
34 | argument. If the database does not already exist, it is | ||
35 | automatically created. | ||
36 | The <b>sqlite3</b> command also creates a new Tcl | ||
37 | command to control the database. The name of the new Tcl command | ||
38 | is given by the first argument. This approach is similar to the | ||
39 | way widgets are created in Tk. | ||
40 | </p> | ||
41 | |||
42 | <p> | ||
43 | The name of the database is just the name of a disk file in which | ||
44 | the database is stored. If the name of the database is an empty | ||
45 | string or the special name ":memory:" then a new database is created | ||
46 | in memory. | ||
47 | </p> | ||
48 | |||
49 | <p> | ||
50 | Once an SQLite database is open, it can be controlled using | ||
51 | methods of the <i>dbcmd</i>. There are currently 22 methods | ||
52 | defined.</p> | ||
53 | |||
54 | <p> | ||
55 | <ul> | ||
56 | } | ||
57 | foreach m [lsort { | ||
58 | authorizer | ||
59 | busy | ||
60 | cache | ||
61 | changes | ||
62 | close | ||
63 | collate | ||
64 | collation_needed | ||
65 | commit_hook | ||
66 | complete | ||
67 | copy | ||
68 | enable_load_extension | ||
69 | errorcode | ||
70 | eval | ||
71 | exists | ||
72 | function | ||
73 | last_insert_rowid | ||
74 | nullvalue | ||
75 | onecolumn | ||
76 | profile | ||
77 | progress | ||
78 | rollback_hook | ||
79 | timeout | ||
80 | total_changes | ||
81 | trace | ||
82 | transaction | ||
83 | update_hook | ||
84 | version | ||
85 | }] { | ||
86 | puts "<li><a href=\"#$m\">$m</a></li>" | ||
87 | } | ||
88 | puts { | ||
89 | </ul> | ||
90 | </p> | ||
91 | |||
92 | <p>The use of each of these methods will be explained in the sequel, though | ||
93 | not in the order shown above.</p> | ||
94 | |||
95 | } | ||
96 | |||
97 | ############################################################################## | ||
98 | METHOD eval { | ||
99 | <p> | ||
100 | The most useful <i>dbcmd</i> method is "eval". The eval method is used | ||
101 | to execute SQL on the database. The syntax of the eval method looks | ||
102 | like this:</p> | ||
103 | |||
104 | <blockquote> | ||
105 | <i>dbcmd</i> <b>eval</b> <i>sql</i> | ||
106 | ?<i>array-name </i>? ?<i>script</i>? | ||
107 | </blockquote> | ||
108 | |||
109 | <p> | ||
110 | The job of the eval method is to execute the SQL statement or statements | ||
111 | given in the second argument. For example, to create a new table in | ||
112 | a database, you can do this:</p> | ||
113 | |||
114 | <blockquote> | ||
115 | <b>sqlite3 db1 ./testdb<br> | ||
116 | db1 eval {CREATE TABLE t1(a int, b text)}</b> | ||
117 | </blockquote> | ||
118 | |||
119 | <p>The above code creates a new table named <b>t1</b> with columns | ||
120 | <b>a</b> and <b>b</b>. What could be simpler?</p> | ||
121 | |||
122 | <p>Query results are returned as a list of column values. If a | ||
123 | query requests 2 columns and there are 3 rows matching the query, | ||
124 | then the returned list will contain 6 elements. For example:</p> | ||
125 | |||
126 | <blockquote> | ||
127 | <b>db1 eval {INSERT INTO t1 VALUES(1,'hello')}<br> | ||
128 | db1 eval {INSERT INTO t1 VALUES(2,'goodbye')}<br> | ||
129 | db1 eval {INSERT INTO t1 VALUES(3,'howdy!')}<br> | ||
130 | set x [db1 eval {SELECT * FROM t1 ORDER BY a}]</b> | ||
131 | </blockquote> | ||
132 | |||
133 | <p>The variable <b>$x</b> is set by the above code to</p> | ||
134 | |||
135 | <blockquote> | ||
136 | <b>1 hello 2 goodbye 3 howdy!</b> | ||
137 | </blockquote> | ||
138 | |||
139 | <p>You can also process the results of a query one row at a time | ||
140 | by specifying the name of an array variable and a script following | ||
141 | the SQL code. For each row of the query result, the values of all | ||
142 | columns will be inserted into the array variable and the script will | ||
143 | be executed. For instance:</p> | ||
144 | |||
145 | <blockquote> | ||
146 | <b>db1 eval {SELECT * FROM t1 ORDER BY a} values {<br> | ||
147 | parray values<br> | ||
148 | puts ""<br> | ||
149 | }</b> | ||
150 | </blockquote> | ||
151 | |||
152 | <p>This last code will give the following output:</p> | ||
153 | |||
154 | <blockquote><b> | ||
155 | values(*) = a b<br> | ||
156 | values(a) = 1<br> | ||
157 | values(b) = hello<p> | ||
158 | |||
159 | values(*) = a b<br> | ||
160 | values(a) = 2<br> | ||
161 | values(b) = goodbye<p> | ||
162 | |||
163 | values(*) = a b<br> | ||
164 | values(a) = 3<br> | ||
165 | values(b) = howdy!</b> | ||
166 | </blockquote> | ||
167 | |||
168 | <p> | ||
169 | For each column in a row of the result, the name of that column | ||
170 | is used as an index in to array. The value of the column is stored | ||
171 | in the corresponding array entry. The special array index * is | ||
172 | used to store a list of column names in the order that they appear. | ||
173 | </p> | ||
174 | |||
175 | <p> | ||
176 | If the array variable name is omitted or is the empty string, then the value of | ||
177 | each column is stored in a variable with the same name as the column | ||
178 | itself. For example: | ||
179 | </p> | ||
180 | |||
181 | <blockquote> | ||
182 | <b>db1 eval {SELECT * FROM t1 ORDER BY a} {<br> | ||
183 | puts "a=$a b=$b"<br> | ||
184 | }</b> | ||
185 | </blockquote> | ||
186 | |||
187 | <p> | ||
188 | From this we get the following output | ||
189 | </p> | ||
190 | |||
191 | <blockquote><b> | ||
192 | a=1 b=hello<br> | ||
193 | a=2 b=goodbye<br> | ||
194 | a=3 b=howdy!</b> | ||
195 | </blockquote> | ||
196 | |||
197 | <p> | ||
198 | Tcl variable names can appear in the SQL statement of the second argument | ||
199 | in any position where it is legal to put a string or number literal. The | ||
200 | value of the variable is substituted for the variable name. If the | ||
201 | variable does not exist a NULL values is used. For example: | ||
202 | </p> | ||
203 | |||
204 | <blockquote><b> | ||
205 | db1 eval {INSERT INTO t1 VALUES(5,$bigstring)} | ||
206 | </b></blockquote> | ||
207 | |||
208 | <p> | ||
209 | Note that it is not necessary to quote the $bigstring value. That happens | ||
210 | automatically. If $bigstring is a large string or binary object, this | ||
211 | technique is not only easier to write, it is also much more efficient | ||
212 | since it avoids making a copy of the content of $bigstring. | ||
213 | </p> | ||
214 | |||
215 | <p> | ||
216 | If the $bigstring variable has both a string and a "bytearray" representation, | ||
217 | then TCL inserts the value as a string. If it has only a "bytearray" | ||
218 | representation, then the value is inserted as a BLOB. To force a | ||
219 | value to be inserted as a BLOB even if it also has a text representation, | ||
220 | us a "@" character to in place of the "$". Like this: | ||
221 | </p> | ||
222 | |||
223 | <blockquote><b> | ||
224 | db1 eval {INSERT INTO t1 VALUES(5,@bigstring)} | ||
225 | </b></blockquote> | ||
226 | |||
227 | <p> | ||
228 | If the variable does not have a bytearray representation, then "@" works | ||
229 | just like "$". | ||
230 | </p> | ||
231 | |||
232 | } | ||
233 | |||
234 | ############################################################################## | ||
235 | METHOD close { | ||
236 | |||
237 | <p> | ||
238 | As its name suggests, the "close" method to an SQLite database just | ||
239 | closes the database. This has the side-effect of deleting the | ||
240 | <i>dbcmd</i> Tcl command. Here is an example of opening and then | ||
241 | immediately closing a database: | ||
242 | </p> | ||
243 | |||
244 | <blockquote> | ||
245 | <b>sqlite3 db1 ./testdb<br> | ||
246 | db1 close</b> | ||
247 | </blockquote> | ||
248 | |||
249 | <p> | ||
250 | If you delete the <i>dbcmd</i> directly, that has the same effect | ||
251 | as invoking the "close" method. So the following code is equivalent | ||
252 | to the previous:</p> | ||
253 | |||
254 | <blockquote> | ||
255 | <b>sqlite3 db1 ./testdb<br> | ||
256 | rename db1 {}</b> | ||
257 | </blockquote> | ||
258 | } | ||
259 | |||
260 | ############################################################################## | ||
261 | METHOD transaction { | ||
262 | |||
263 | <p> | ||
264 | The "transaction" method is used to execute a TCL script inside an SQLite | ||
265 | database transaction. The transaction is committed when the script completes, | ||
266 | or it rolls back if the script fails. If the transaction occurs within | ||
267 | another transaction (even one that is started manually using BEGIN) it | ||
268 | is a no-op. | ||
269 | </p> | ||
270 | |||
271 | <p> | ||
272 | The transaction command can be used to group together several SQLite | ||
273 | commands in a safe way. You can always start transactions manually using | ||
274 | BEGIN, of | ||
275 | course. But if an error occurs so that the COMMIT or ROLLBACK are never | ||
276 | run, then the database will remain locked indefinitely. Also, BEGIN | ||
277 | does not nest, so you have to make sure no other transactions are active | ||
278 | before starting a new one. The "transaction" method takes care of | ||
279 | all of these details automatically. | ||
280 | </p> | ||
281 | |||
282 | <p> | ||
283 | The syntax looks like this: | ||
284 | </p> | ||
285 | |||
286 | <blockquote> | ||
287 | <i>dbcmd</i> <b>transaction</b> <i>?transaction-type?</i> | ||
288 | <i>SCRIPT,</i> | ||
289 | </blockquote> | ||
290 | |||
291 | |||
292 | <p> | ||
293 | The <i>transaction-type</i> can be one of <b>deferred</b>, | ||
294 | <b>exclusive</b> or <b>immediate</b>. The default is deferred. | ||
295 | </p> | ||
296 | } | ||
297 | |||
298 | ############################################################################## | ||
299 | METHOD cache { | ||
300 | |||
301 | <p> | ||
302 | The "eval" method described <a href="#eval">above</a> keeps a cache of | ||
303 | <a href="capi3ref.html#sqlite3_prepare">prepared statements</a> | ||
304 | for recently evaluated SQL commands. | ||
305 | The "cache" method is used to control this cache. | ||
306 | The first form of this command is:</p> | ||
307 | |||
308 | <blockquote> | ||
309 | <i>dbcmd</i> <b>cache size</b> <i>N</i> | ||
310 | </blockquote> | ||
311 | |||
312 | <p>This sets the maximum number of statements that can be cached. | ||
313 | The upper limit is 100. The default is 10. If you set the cache size | ||
314 | to 0, no caching is done.</p> | ||
315 | |||
316 | <p>The second form of the command is this:</p> | ||
317 | |||
318 | |||
319 | <blockquote> | ||
320 | <i>dbcmd</i> <b>cache flush</b> | ||
321 | </blockquote> | ||
322 | |||
323 | <p>The cache-flush method | ||
324 | <a href="capi3ref.html#sqlite3_finalize">finalizes</a> | ||
325 | all prepared statements currently | ||
326 | in the cache.</p> | ||
327 | |||
328 | } | ||
329 | |||
330 | ############################################################################## | ||
331 | METHOD complete { | ||
332 | |||
333 | <p> | ||
334 | The "complete" method takes a string of supposed SQL as its only argument. | ||
335 | It returns TRUE if the string is a complete statement of SQL and FALSE if | ||
336 | there is more to be entered.</p> | ||
337 | |||
338 | <p>The "complete" method is useful when building interactive applications | ||
339 | in order to know when the user has finished entering a line of SQL code. | ||
340 | This is really just an interface to the | ||
341 | <a href="capi3ref.html#sqlite3_complete"><b>sqlite3_complete()</b></a> C | ||
342 | function. | ||
343 | } | ||
344 | |||
345 | ############################################################################## | ||
346 | METHOD copy { | ||
347 | |||
348 | <p> | ||
349 | The "copy" method copies data from a file into a table. | ||
350 | It returns the number of rows processed successfully from the file. | ||
351 | The syntax of the copy method looks like this:</p> | ||
352 | |||
353 | <blockquote> | ||
354 | <i>dbcmd</i> <b>copy</b> <i>conflict-algorithm</i> | ||
355 | <i>table-name </i> <i>file-name </i> | ||
356 | ?<i>column-separator </i>? | ||
357 | ?<i>null-indicator</i>? | ||
358 | </blockquote> | ||
359 | |||
360 | <p>Conflict-alogrithm must be one of the SQLite conflict algorithms for | ||
361 | the INSERT statement: <i>rollback</i>, <i>abort</i>, | ||
362 | <i>fail</i>,<i>ignore</i>, or <i>replace</i>. See the SQLite Language | ||
363 | section for <a href="lang.html#conflict">ON CONFLICT</a> for more information. | ||
364 | The conflict-algorithm must be specified in lower case. | ||
365 | </p> | ||
366 | |||
367 | <p>Table-name must already exists as a table. File-name must exist, and | ||
368 | each row must contain the same number of columns as defined in the table. | ||
369 | If a line in the file contains more or less than the number of columns defined, | ||
370 | the copy method rollbacks any inserts, and returns an error.</p> | ||
371 | |||
372 | <p>Column-separator is an optional column separator string. The default is | ||
373 | the ASCII tab character \t. </p> | ||
374 | |||
375 | <p>Null-indicator is an optional string that indicates a column value is null. | ||
376 | The default is an empty string. Note that column-separator and | ||
377 | null-indicator are optional positional arguments; if null-indicator | ||
378 | is specified, a column-separator argument must be specifed and | ||
379 | precede the null-indicator argument.</p> | ||
380 | |||
381 | <p>The copy method implements similar functionality to the <b>.import</b> | ||
382 | SQLite shell command. | ||
383 | The SQLite 2.x <a href="lang.html#copy"><b>COPY</b></a> statement | ||
384 | (using the PostgreSQL COPY file format) | ||
385 | can be implemented with this method as:</p> | ||
386 | |||
387 | <blockquote> | ||
388 | dbcmd copy $conflictalgo | ||
389 | $tablename $filename | ||
390 | \t | ||
391 | \\N | ||
392 | </blockquote> | ||
393 | |||
394 | } | ||
395 | |||
396 | ############################################################################## | ||
397 | METHOD timeout { | ||
398 | |||
399 | <p>The "timeout" method is used to control how long the SQLite library | ||
400 | will wait for locks to clear before giving up on a database transaction. | ||
401 | The default timeout is 0 millisecond. (In other words, the default behavior | ||
402 | is not to wait at all.)</p> | ||
403 | |||
404 | <p>The SQLite database allows multiple simultaneous | ||
405 | readers or a single writer but not both. If any process is writing to | ||
406 | the database no other process is allows to read or write. If any process | ||
407 | is reading the database other processes are allowed to read but not write. | ||
408 | The entire database shared a single lock.</p> | ||
409 | |||
410 | <p>When SQLite tries to open a database and finds that it is locked, it | ||
411 | can optionally delay for a short while and try to open the file again. | ||
412 | This process repeats until the query times out and SQLite returns a | ||
413 | failure. The timeout is adjustable. It is set to 0 by default so that | ||
414 | if the database is locked, the SQL statement fails immediately. But you | ||
415 | can use the "timeout" method to change the timeout value to a positive | ||
416 | number. For example:</p> | ||
417 | |||
418 | <blockquote><b>db1 timeout 2000</b></blockquote> | ||
419 | |||
420 | <p>The argument to the timeout method is the maximum number of milliseconds | ||
421 | to wait for the lock to clear. So in the example above, the maximum delay | ||
422 | would be 2 seconds.</p> | ||
423 | } | ||
424 | |||
425 | ############################################################################## | ||
426 | METHOD busy { | ||
427 | |||
428 | <p>The "busy" method, like "timeout", only comes into play when the | ||
429 | database is locked. But the "busy" method gives the programmer much more | ||
430 | control over what action to take. The "busy" method specifies a callback | ||
431 | Tcl procedure that is invoked whenever SQLite tries to open a locked | ||
432 | database. This callback can do whatever is desired. Presumably, the | ||
433 | callback will do some other useful work for a short while (such as service | ||
434 | GUI events) then return | ||
435 | so that the lock can be tried again. The callback procedure should | ||
436 | return "0" if it wants SQLite to try again to open the database and | ||
437 | should return "1" if it wants SQLite to abandon the current operation. | ||
438 | } | ||
439 | |||
440 | ############################################################################## | ||
441 | METHOD exists { | ||
442 | |||
443 | <p>The "exists" method is similar to "onecolumn" and "eval" in that | ||
444 | it executes SQL statements. The difference is that the "exists" method | ||
445 | always returns a boolean value which is TRUE if a query in the SQL | ||
446 | statement it executes returns one or more rows and FALSE if the SQL | ||
447 | returns an empty set.</p> | ||
448 | |||
449 | <p>The "exists" method is often used to test for the existance of | ||
450 | rows in a table. For example:</p> | ||
451 | |||
452 | <blockquote><b> | ||
453 | if {[db exists {SELECT 1 FROM table1 WHERE user=$user}]} {<br> | ||
454 | # Processing if $user exists<br> | ||
455 | } else {<br> | ||
456 | # Processing if $user does not exist<br> | ||
457 | } | ||
458 | </b></blockquote> | ||
459 | } | ||
460 | |||
461 | |||
462 | ############################################################################## | ||
463 | METHOD last_insert_rowid { | ||
464 | |||
465 | <p>The "last_insert_rowid" method returns an integer which is the ROWID | ||
466 | of the most recently inserted database row.</p> | ||
467 | } | ||
468 | |||
469 | ############################################################################## | ||
470 | METHOD function { | ||
471 | |||
472 | <p>The "function" method registers new SQL functions with the SQLite engine. | ||
473 | The arguments are the name of the new SQL function and a TCL command that | ||
474 | implements that function. Arguments to the function are appended to the | ||
475 | TCL command before it is invoked.</p> | ||
476 | |||
477 | <p> | ||
478 | The following example creates a new SQL function named "hex" that converts | ||
479 | its numeric argument in to a hexadecimal encoded string: | ||
480 | </p> | ||
481 | |||
482 | <blockquote><b> | ||
483 | db function hex {format 0x%X} | ||
484 | </b></blockquote> | ||
485 | |||
486 | } | ||
487 | |||
488 | ############################################################################## | ||
489 | METHOD nullvalue { | ||
490 | |||
491 | <p> | ||
492 | The "nullvalue" method changes the representation for NULL returned | ||
493 | as result of the "eval" method.</p> | ||
494 | |||
495 | <blockquote><b> | ||
496 | db1 nullvalue NULL | ||
497 | </b></blockquote> | ||
498 | |||
499 | <p>The "nullvalue" method is useful to differ between NULL and empty | ||
500 | column values as Tcl lacks a NULL representation. The default | ||
501 | representation for NULL values is an empty string.</p> | ||
502 | } | ||
503 | |||
504 | |||
505 | |||
506 | ############################################################################## | ||
507 | METHOD onecolumn { | ||
508 | |||
509 | <p>The "onecolumn" method works like | ||
510 | "<a href="#eval">eval</a>" in that it evaluates the | ||
511 | SQL query statement given as its argument. The difference is that | ||
512 | "onecolumn" returns a single element which is the first column of the | ||
513 | first row of the query result.</p> | ||
514 | |||
515 | <p>This is a convenience method. It saves the user from having to | ||
516 | do a "<tt>[lindex ... 0]</tt>" on the results of an "eval" | ||
517 | in order to extract a single column result.</p> | ||
518 | } | ||
519 | |||
520 | ############################################################################## | ||
521 | METHOD changes { | ||
522 | |||
523 | <p>The "changes" method returns an integer which is the number of rows | ||
524 | in the database that were inserted, deleted, and/or modified by the most | ||
525 | recent "eval" method.</p> | ||
526 | } | ||
527 | |||
528 | ############################################################################## | ||
529 | METHOD total_changes { | ||
530 | |||
531 | <p>The "total_changes" method returns an integer which is the number of rows | ||
532 | in the database that were inserted, deleted, and/or modified since the | ||
533 | current database connection was first opened.</p> | ||
534 | } | ||
535 | |||
536 | ############################################################################## | ||
537 | METHOD authorizer { | ||
538 | |||
539 | <p>The "authorizer" method provides access to the | ||
540 | <a href="capi3ref.html#sqlite3_set_authorizer">sqlite3_set_authorizer</a> | ||
541 | C/C++ interface. The argument to authorizer is the name of a procedure that | ||
542 | is called when SQL statements are being compiled in order to authorize | ||
543 | certain operations. The callback procedure takes 5 arguments which describe | ||
544 | the operation being coded. If the callback returns the text string | ||
545 | "SQLITE_OK", then the operation is allowed. If it returns "SQLITE_IGNORE", | ||
546 | then the operation is silently disabled. If the return is "SQLITE_DENY" | ||
547 | then the compilation fails with an error. | ||
548 | </p> | ||
549 | |||
550 | <p>If the argument is an empty string then the authorizer is disabled. | ||
551 | If the argument is omitted, then the current authorizer is returned.</p> | ||
552 | } | ||
553 | |||
554 | ############################################################################## | ||
555 | METHOD progress { | ||
556 | |||
557 | <p>This method registers a callback that is invoked periodically during | ||
558 | query processing. There are two arguments: the number of SQLite virtual | ||
559 | machine opcodes between invocations, and the TCL command to invoke. | ||
560 | Setting the progress callback to an empty string disables it.</p> | ||
561 | |||
562 | <p>The progress callback can be used to display the status of a lengthy | ||
563 | query or to process GUI events during a lengthy query.</p> | ||
564 | } | ||
565 | |||
566 | |||
567 | ############################################################################## | ||
568 | METHOD collate { | ||
569 | |||
570 | <p>This method registers new text collating sequences. There are | ||
571 | two arguments: the name of the collating sequence and the name of a | ||
572 | TCL procedure that implements a comparison function for the collating | ||
573 | sequence. | ||
574 | </p> | ||
575 | |||
576 | <p>For example, the following code implements a collating sequence called | ||
577 | "NOCASE" that sorts in text order without regard to case: | ||
578 | </p> | ||
579 | |||
580 | <blockquote><b> | ||
581 | proc nocase_compare {a b} {<br> | ||
582 | return [string compare [string tolower $a] [string tolower $b]]<br> | ||
583 | }<br> | ||
584 | db collate NOCASE nocase_compare<br> | ||
585 | </b></blockquote> | ||
586 | } | ||
587 | |||
588 | ############################################################################## | ||
589 | METHOD collation_needed { | ||
590 | |||
591 | <p>This method registers a callback routine that is invoked when the SQLite | ||
592 | engine needs a particular collating sequence but does not have that | ||
593 | collating sequence registered. The callback can register the collating | ||
594 | sequence. The callback is invoked with a single parameter which is the | ||
595 | name of the needed collating sequence.</p> | ||
596 | } | ||
597 | |||
598 | ############################################################################## | ||
599 | METHOD commit_hook { | ||
600 | |||
601 | <p>This method registers a callback routine that is invoked just before | ||
602 | SQLite tries to commit changes to a database. If the callback throws | ||
603 | an exception or returns a non-zero result, then the transaction rolls back | ||
604 | rather than commit.</p> | ||
605 | } | ||
606 | |||
607 | ############################################################################## | ||
608 | METHOD rollback_hook { | ||
609 | |||
610 | <p>This method registers a callback routine that is invoked just before | ||
611 | SQLite tries to do a rollback. The script argument is run without change.</p> | ||
612 | } | ||
613 | |||
614 | ############################################################################## | ||
615 | METHOD update_hook { | ||
616 | |||
617 | <p>This method registers a callback routine that is invoked just before | ||
618 | each row is modified by an UPDATE, INSERT, or DELETE statement. Four | ||
619 | arguments are appended to the callback before it is invoked:</p> | ||
620 | |||
621 | <ul> | ||
622 | <li>The keyword "INSERT", "UPDATE", or "DELETE", as appropriate</li> | ||
623 | <li>The name of the database which is being changed</li> | ||
624 | <li>The table that is being changed</li> | ||
625 | <li>The rowid of the row in the table being changed</li> | ||
626 | </ul> | ||
627 | } | ||
628 | |||
629 | ############################################################################## | ||
630 | METHOD incrblob { | ||
631 | |||
632 | <p>This method opens a TCL channel that can be used to read or write | ||
633 | into a preexisting BLOB in the database. The syntax is like this:</p> | ||
634 | |||
635 | <blockquote> | ||
636 | <i>dbcmd</i> <b>incrblob</b> <b>?-readonly??</b> | ||
637 | <i>?DB? TABLE COLUMN ROWID</i> | ||
638 | </blockquote> | ||
639 | |||
640 | <p> | ||
641 | The command returns a new TCL channel for reading or writing to the BLOB. | ||
642 | The channel is opened using the underlying | ||
643 | <a href="/capi3ref.html#sqlite3_blob_open">sqlite3_blob_open()</a> C-langauge | ||
644 | interface. Close the channel using the <b>close</b> command of TCL. | ||
645 | </p> | ||
646 | } | ||
647 | |||
648 | ############################################################################## | ||
649 | METHOD errorcode { | ||
650 | |||
651 | <p>This method returns the numeric error code that resulted from the most | ||
652 | recent SQLite operation.</p> | ||
653 | } | ||
654 | |||
655 | ############################################################################## | ||
656 | METHOD trace { | ||
657 | |||
658 | <p>The "trace" method registers a callback that is invoked as each SQL | ||
659 | statement is compiled. The text of the SQL is appended as a single string | ||
660 | to the command before it is invoked. This can be used (for example) to | ||
661 | keep a log of all SQL operations that an application performs. | ||
662 | </p> | ||
663 | } | ||
664 | |||
665 | |||
666 | footer $rcsid | ||