# Vendored SQLite

- Version: **3.53.2** (`SQLITE_VERSION` in `sqlite3.h`)
- Source: <https://sqlite.org/2026/sqlite-amalgamation-3530200.zip>
- Zip sha256: `8a310d0a16c7a90cacd4c884e70faa51c902afed2a89f63aaa0126ab83558a32`
- Files kept: `sqlite3.c`, `sqlite3.h` (the amalgamation; `shell.c` and
  `sqlite3ext.h` dropped — no shell, no loadable extensions)
- License: public domain (<https://sqlite.org/copyright.html>)

`make build` compiles this into `build/vendor/libsqlite3.a` (statically
linked into the `dist` binary via `-L build/vendor`) and
`build/vendor/jit/libsqlite3.dylib` (dlopen'd by `sx run`, which is how
`make test` executes the test programs). The two locations are separate
on purpose: the macOS linker prefers a dylib over an archive in the same
search directory, and the AOT binary must link the static copy.
`tests/sqlite_smoke.sx` asserts `sqlite3_libversion()` equals the version
above, so a fallback to the OS libsqlite3 fails loudly in both modes.

## Symbol renaming

The sx JIT resolves `#foreign` symbols via `dlsym(RTLD_DEFAULT)`, which
searches every image already loaded into the process — the OS libsqlite3
is usually among them and wins by load order. So every API function the
bindings use is renamed `dist_sqlite3_*` in the vendored build: those
symbols exist ONLY here, making resolution unambiguous in both JIT and
AOT modes. The rename header is GENERATED by `make` into
`build/vendor/rename.h` from the `#foreign` names in
`src/db/sqlite.sx` — the bindings file is the single source of truth,
and the rename list cannot drift from it.

## Bound surface

`src/db/sqlite.sx` maps the full practical C API (~100 functions):
connection lifecycle + open_v2 flags, errors (extended codes included),
statements with the complete bind/column families, parameter and column
introspection (built with `SQLITE_ENABLE_COLUMN_METADATA`), incremental
blob I/O, the online backup API, serialize/deserialize, and the library
utilities. Not bound, by design: callback-taking APIs (hooks, UDFs,
collations, authorizers — they need C→sx callbacks), the
`sqlite3_value_*` family (UDF-coupled), varargs configuration, UTF-16
variants, and subsystems this build omits (mutex/VFS under
`SQLITE_THREADSAFE=0`, sessions/snapshots/vtabs, deprecated API).

To upgrade: replace `sqlite3.c`/`sqlite3.h` with a newer amalgamation,
update this file and the version constant in `tests/sqlite_smoke.sx`, and
run `make clean test`.
