Did you know ... Search Documentation:
Pack swiplite -- prolog/sqlite.pl
PublicShow source

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_eval/1, sqlite_eval/2, and sqlite_eval/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.
 sqlite_version(-Version:atom) is det
Unify Version with the version of SQLite currently in use

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

 sqlite_open(Arg1, Arg2, Arg3)
 sqlite_close(Arg1)
 sqlite_prepare(Arg1, Arg2, Arg3)
 sqlite_bind(Arg1, Arg2)
 sqlite_reset(Arg1)
 sqlite_sql(Arg1, Arg2)
 sqlite_expanded_sql(Arg1, Arg2)
 sqlite_column_names(Arg1, Arg2)
 sqlite_finalize(Arg1)
 sqlite_eval(Arg1)
 sqlite_eval(Arg1, Arg2)
 sqlite_eval(Arg1, Arg2, Arg3, Arg4)