272 exported symbols · the complete native SQLite API (v3 interface family)

sqlite Extension Reference

Built in by the build.bat sqlite variant: the engine is statically linked into the host, scripts do #include <sqlite3.h> (provided by the VFS) — it is what drives the demo's db/main.db. For semantic documentation, SQLite's official docs are authoritative — this page provides the grouped index and the XServer-context caveats.

XServer-context caveats

Multi-worker safety

The demo opens in FULLMUTEX mode (an open_v2 flag), so a single handle can serve callbacks from multiple workers — but cross-thread reuse of statement objects should still be avoided (keep prepare-through-finalize on one thread where possible).

How to open

The demo uses sqlite3_open_v2(path, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); paths are relative to the application directory (the db/ directory is shared across generations, ch. 05).

Variant dependency

The default variant has none of these symbols — a script referencing sqlite3_* fails to compile (this behavior was verified experimentally in the ch. 02 exercise).

Connections & execution family

sqlite3_open_v2 / close / close_v2 connection

Open (flags control read-write / create / threading mode) and close. The demo's mode: READWRITE | CREATE + FULLMUTEX.

int sqlite3_open_v2(const char *filename, sqlite3 **ppDb, int flags, const char *zVfs); int sqlite3_close(sqlite3 *db);

sqlite3_exec execution

One-step execution of result-free SQL (DDL, PRAGMA, simple writes) — the demo's table-creation path.

int sqlite3_exec(sqlite3 *db, const char *sql, int (*callback)(void*,int,char**,char**), void *arg, char **errmsg);

sqlite3_errmsg / sqlite3_errcode diagnostics

Error text and code — the first stop of troubleshooting (the demo prints them when opening fails).

The statement five-step (the parameterized-query backbone)

The five-step pattern (as actually used in demo database.h / item.h)verified on a real machinesource: demo-single/modules
sqlite3_stmt* pStmt = NULL;
/* 1. prepare: SQL text -> statement object (? placeholders, no injection) */
sqlite3_prepare_v2(G_DB, sSQL, -1, &pStmt, NULL);
/* 2. bind: bind parameters by index (text via SQLITE_TRANSIENT copy) */
sqlite3_bind_text(pStmt, 1, sName, -1, SQLITE_TRANSIENT);
sqlite3_bind_int64(pStmt, 2, iId);
/* 3. step: advance one row (SELECT) or execute (writes) */
while ( sqlite3_step(pStmt) == SQLITE_ROW ) {
    /* 4. column: read values by column */
    int64 iId = sqlite3_column_int64(pStmt, 0);
    const unsigned char* sName = sqlite3_column_text(pStmt, 1);
}
/* 5. finalize: release the statement - every prepare needs a finalize */
sqlite3_finalize(pStmt);

Family members: sqlite3_prepare_v2, sqlite3_bind_text/int64/int/double/null/blob, sqlite3_step, sqlite3_column_*, sqlite3_reset (statement reuse), sqlite3_finalize. Binding indices start at 1; column indices start at 0 — that off-by-one is the most common slip.

Transactions & batching family

  • BEGIN / COMMIT / ROLLBACK run via exec or a statement; batch writes must be grouped (the demo's bench-write bulk insert is wrapped in a transaction)
  • sqlite3_last_insert_rowid: retrieving an autoincrement primary key
  • sqlite3_changes: affected row count
  • The backup/restore family (sqlite3_backup_*) is inside the export surface — hot-backup scripts can use it directly

Utilities family overview

The 272 exported symbols cover: the core v3 interface, blob IO, blob and text utilities, errors and status, memory statistics (sqlite3_memory_used etc.), runtime control (sqlite3_limit / busy_timeout), the disabled extension-loading domain, and more. The full list is in /xs/sqlite3.h inside the VFS (present only in the sqlite variant); for per-function semantics, consult the official SQLite documentation.

The tutorial side of the full story (connection management, prepared-statement reuse, transactional batch writes, and the handle-handover decision across hot reloads) is in chapter 32 and Project 1.