1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-01 06:27:03 +03:00

:-) (CVS 37)

FossilOrigin-Name: 2b55f9b790e2914bbd2fd27ef23bbab79fa76937
This commit is contained in:
drh
2000-06-02 13:27:59 +00:00
parent bdc2df79b6
commit bed8690fde
17 changed files with 334 additions and 122 deletions

View File

@ -1,7 +1,7 @@
#
# Run this Tcl script to generate the sqlite.html file.
#
set rcsid {$Id: c_interface.tcl,v 1.2 2000/05/29 18:32:17 drh Exp $}
set rcsid {$Id: c_interface.tcl,v 1.3 2000/06/02 13:28:00 drh Exp $}
puts {<html>
<head>
@ -22,8 +22,9 @@ programming interface.</p>
<h2>The API</h2>
<p>The interface to the SQLite library consists of 4 functions
and one opaque data structure.</p>
<p>The interface to the SQLite library consists of 4 functions,
one opaque data structure, and some constants used as return
values from sqlite_exec():</p>
<blockquote><pre>
typedef struct sqlite sqlite;
@ -41,6 +42,15 @@ int sqlite_exec(
);
int sqlite_complete(const char *sql);
#define SQLITE_OK 0 /* Successful result */
#define SQLITE_INTERNAL 1 /* An internal logic error in SQLite */
#define SQLITE_ERROR 2 /* SQL error or missing database */
#define SQLITE_PERM 3 /* Access permission denied */
#define SQLITE_ABORT 4 /* Callback routine requested an abort */
#define SQLITE_BUSY 5 /* One or more database files are locked */
#define SQLITE_NOMEM 6 /* A malloc() failed */
#define SQLITE_READONLY 7 /* Attempt to write a readonly database */
</pre></blockquote>
<p>All of the above definitions are included in the "sqlite.h"
@ -48,7 +58,7 @@ header file that comes in the source tree.</p>
<h2>Opening a database</h2>
<p>Use the <b>sqlite_open</b> function to open an existing SQLite
<p>Use the <b>sqlite_open()</b> function to open an existing SQLite
database or to create a new SQLite database. The first argument
is the database name. The second argument is a constant 0666 to
open the database for reading and writing and 0444 to open the
@ -73,7 +83,8 @@ an empty directory and the second parameter set to 0666.</p>
<p>The return value of the <b>sqlite_open()</b> function is a
pointer to an opaque <b>sqlite</b> structure. This pointer will
be the first argument to all subsequent SQLite function calls that
deal with the same database.</p>
deal with the same database. NULL is returned if the open fails
for any reason.</p>
<h2>Closing the database</h2>
@ -89,14 +100,17 @@ and queries. This function requires 5 parameters as follows:</p>
<ol>
<li><p>A pointer to the sqlite structure obtained from a prior call
to <b>sqlite_open()</b>.</p></li>
<li><p>A null-terminated string containing the text of the SQL statements
and/or queries to be processed.</p></li>
<li><p>A null-terminated string containing the text of one or more
SQL statements and/or queries to be processed.</p></li>
<li><p>A pointer to a callback function which is invoked once for each
row in the result of a query. This argument may be NULL, in which
case no callbacks will ever be invoked.</p></li>
<li><p>A pointer to anything that is forward to become the first argument
<li><p>A pointer that is forwarded to become the first argument
to the callback function.</p></li>
<li><p>A pointer to a string pointer into which error messages are written.
<li><p>A pointer to an error string. Error messages are written to space
obtained from malloc() and the error string is made to point to
the malloced space. The calling function is responsible for freeing
this space when it has finished with it.
This argument may be NULL, in which case error messages are not
reported back to the calling function.</p></li>
</ol>
@ -115,34 +129,43 @@ int Callback(void *pArg, int argc, char **argv, char **columnNames){
to <b>sqlite_exec()</b> This parameter can be used to pass arbitrary
information through to the callback function from client code.
The second argument is the number columns in the query result.
The third argument is an array of pointers to string where each string
The third argument is an array of pointers to strings where each string
is a single column of the result for that record. The names of the
columns are contained in the fourth argument.</p>
<p>The callback function should normally return 0. If the callback
function returns non-zero, the query is immediately aborted and the
return value of the callback is returned from <b>sqlite_exec()</b>.
function returns non-zero, the query is immediately aborted and
<b>sqlite_exec()</b> will return SQLITE_ABORT.</p>
<h2>Testing for a complete SQL statement</h2>
<p>The last interface routine to SQLite is a convenience function used
to test whether or not a string forms a complete SQL statement.
If the <b>sqlite_complete</b> function returns true when its input
If the <b>sqlite_complete()</b> function returns true when its input
is a string, then the argument forms a complete SQL statement.
There are no guarantees that the syntax of that statement is correct,
but we at least know the statement is complete. If <b>sqlite_complete</b>
but we at least know the statement is complete. If <b>sqlite_complete()</b>
returns false, then more text is required to complete the SQL statement.</p>
<p>For the purpose of the <b>sqlite_complete()</b> function, an SQL
statement is complete if it ends in a semicolon.</p>
<p>The <b>sqlite</b> command-line utility uses the <b>sqlite_complete()</b>
function to know when it needs to call <b>sqlite_exec()</b>. After each
line of input is received, <b>sqlite</b> calls <b>sqlite_complete()</b>
on all input in its buffer. If <b>sqlite_complete()</b> returns true,
then <b>sqlite_exec()</b> is called and the input buffer is reset. If
<b>sqlite_complete()</b> returns false, then the prompt is changed to
the continuation prompt and another line of text is read and added to
the input buffer.</p>
<h2>Usage Examples</h2>
<p>For examples of how the SQLite C/C++ interface can be used,
refer to the source code for the "sqlite" program in the
refer to the source code for the <b>sqlite</b> program in the
file <b>src/shell.c</b> of the source tree.
(Additional information about sqlite is available at
<a href="sqlite.html">sqlite.html</a>.)
Additional information about sqlite is available at
<a href="sqlite.html">sqlite.html</a>.
See also the sources to the Tcl interface for SQLite in
the source file <b>src/tclsqlite.c</b>.</p>
}