libstd/sqlite3
Bindings to SQLite plus small helpers: open a database, run statements with error checking, prepared statements with text parameters. It links libsqlite3.so on Linux and winsqlite3.dll on Windows, the SQLite that ships with Windows 10 and later.
#include <libstd/sqlite3>
Includes libstd/stdio. Links the shared library libsqlite3.so, winsqlite3.dll (FFI).
Example
#include <libstd/stdio>
#include <libstd/sqlite3>
db =: sqlite3
rc = sqlite3_open("./test.db", &db)
sqlite3_exec_w(db, "CREATE TABLE IF NOT EXISTS Users(valore INTEGER);")
i = 0
while i < 3:
sqlite3_exec_w(db, "INSERT INTO Users(valore) VALUES(" + itoa(i) + ");")
i++
sqlite3_close(db)
print(sqlite3_libversion(), "\n")
Constants
| Name | Value | Meaning |
|---|---|---|
SQLITE_OK | 0 | |
SQLITE_ERROR | 1 | |
SQLITE_INTERNAL | 2 | |
SQLITE_PERM | 3 | |
SQLITE_ABORT | 4 | |
SQLITE_BUSY | 5 | |
SQLITE_LOCKED | 6 | |
SQLITE_NOMEM | 7 | |
SQLITE_READONLY | 8 | |
SQLITE_INTERRUPT | 9 | |
SQLITE_IOERR | 10 | |
SQLITE_CORRUPT | 11 | |
SQLITE_NOTFOUND | 12 | |
SQLITE_FULL | 13 | |
SQLITE_CANTOPEN | 14 | |
SQLITE_TRANSIENT | -1 | |
SQLITE_DONE | 101 | |
SQLITE_ROW | 100 |
Functions
Version string of the library.
Opens (or creates) a database file; writes the handle through ppDb. Returns SQLITE_OK on success.
Runs one or more SQL statements with an optional row callback.
Closes a database handle.
Frees memory allocated by SQLite (error messages).
Compiles an SQL statement into a sqlite3_stmt.
Binds a text value to a ? placeholder (1-based index).
Executes a prepared statement one step; returns SQLITE_ROW or SQLITE_DONE.
Destroys a prepared statement.
If response is not SQLITE_OK, prints error, closes the database and exits. Call after every SQLite call whose failure is fatal.
A callback with the signature sqlite3_exec expects; a template to extend when rows must be read.
Runs a statement that returns no rows (INSERT/UPDATE/CREATE ...) with automatic error checking.
DROP TABLE name.Runs a sample SELECT * FROM Users; through response_sqlite3_query; a starting point for real queries.
Prepares a parameterised statement (? placeholders) for sqlite3_bind and sqlite3_step.
Binds a text value to placeholder index (1-based) of a prepared statement.