| Did you know ... | Search Documentation: |
| Pack swiplite -- prolog/sqlite.pl |
This module provides partial access to the C-language interface of SQLite.
It exposes the database connection object sqlite3 and the
prepared statement object sqlite3_stmt, along with some of the
essential functions using these objects. Please refer to the
SQLite documentation
and the implementation in c/swiplite.c when using this library.
To make it easier to find the relevant docs, I have tried to
consistently provide links.
Most of the predicates in this module are as close as possible in
naming and semantics to the corresponding functions in the C
interface. One exception is sqlite_bind/2, which converts values
from Prolog terms to corresponding
SQLite column datatype.
Similarly, sqlite_do/1, sqlite_one/2, and sqlite_many/4 wrap
the necessary calls to sqlite3_step() and convert the results of
SELECT queries to Prolog terms.
The database connection and prepared statement objects are
represented in SWI-Prolog as
blobs.
They are garbage collected, but
finalizing a statement
or closing a database connection
(and, alternatively, not doing it) have reprecussions, especially for
long-running programs. The code in this library uses exclusively the
*_v2 versions of the SQLite C interface. In particular:
The sqlite3_close_v2() interface is intended for use with host languages that are garbage collected, and where the order in which destructors are called is arbitrary.
This assumes that the command is not a SELECT query and
it does not return any rows.
If the result set is empty, fail.
This is a convenience predicate returning the sql column of the table
sqlite_schema.
The options are used to set the flags argument in the call to
sqlite3_open_v2().
The following options are recognized:
| Value | Corresponding flags |
read (default) | SQLITE_OPEN_READONLY |
write | SQLITE_OPEN_READWRITE |
create | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
| Value | Corresponding flags |
false (default) | (empty) |
true | SQLITE_OPEN_MEMORY |
| Value | Corresponding flags |
single (default) | (empty) |
multi | SQLITE_OPEN_NOMUTEX |
serialized= | SQLITE_OPEN_FULLMUTEX |
true and will enable foreign
keys for this connection and throw an error if foreign keys are
not supported. Setting this option to false is required
if the used version of SQLite does not support foreign keys.
| Value | Behaviour |
true (default) | Enable foreign keys |
false | Do not check for foreign keys |
The UTF-8 encoded text in SQL is parsed up to the first nul, or
up to the end of the first SQL statement. SQL parameters are
initially all set to NULL. Anonymous variables are not allowed.
If ?NNN parameters are used, they must be numbered
starting from 1, without any gaps.
Two options are supported. If the option bind_parameter_count(Value)
is provided, Value is unified with the number of bind variables in the
prepared statement.
If the option rest(SQL_rest) is provided, the trailing content of SQL is
unified with SQL_rest as a string.
The following predicates are exported, but not or incorrectly documented.