Commit Graph

6 Commits

Author SHA1 Message Date
agra
b5b8ab092b sqlite bindings: adopt the cstring type
Whole C strings now cross as cstring (sx 1d17b0a): IN via to_cstring
with literal coercion, OUT as ?cstring copied through sq_from_cstr
(std from_cstring + substr) before sqlite's buffer dies. sq_cstr and
the manual strlen loop are gone. column_text/column_blob/serialize
deliberately stay ?*u8 + explicit byte counts — their payloads may
carry interior NULs that a strlen would truncate. 21/21 green.
2026-06-12 14:56:09 +03:00
agra
cd896f92ec sqlite bindings: cite sx issue 0128 for the ?[:0]u8 boundary 2026-06-12 13:23:13 +03:00
agra
9d8b334e32 sqlite bindings: nullable C-string returns as ?*u8
The null moves into the type: errmsg/errstr/libversion/sourceid/
column_text/blob/name/decltype/*_name/db_filename/sql/expanded_sql/
bind_parameter_name/serialize return ?*u8 instead of *u8 with manual
cast null-checks, and the helpers take the optional directly. Verified
that an optional pointer crosses the FFI with the null-pointer niche in
both JIT and AOT modes.

?[:0]u8 would be the ideal shape (nullable null-terminated string) but
does not resolve in sx yet — it panics LLVM emission; filed as an sx
followup. The header comment records the constraint.
2026-06-12 13:16:49 +03:00
agra
fabc9062cb sqlite: map the full practical C API
src/db/sqlite.sx grows from the P5.1 subset (~19 fns) to the complete
practical surface (~100): open_v2 + flags, extended errcodes +
error_offset, txn_state/autocommit, changes64/total_changes64, limits,
the full bind/column families (double/blob/zeroblob), parameter and
column introspection (built with SQLITE_ENABLE_COLUMN_METADATA),
table_column_metadata, statement introspection (sql/expanded_sql/
readonly/busy/isexplain/status), incremental blob I/O (SqliteBlob),
online backup (SqliteBackup + sqlite_backup_run), serialize/
deserialize, and library utilities (complete, strglob/strlike/stricmp,
randomness, memory, compileoptions). One variant per duplicate family
(modern/64-bit preferred; bind_text/blob keep the 32-bit length forms
that skip text64's encoding arg). Not bound, by design: callback-taking
APIs (hooks/UDFs/collations need C->sx callbacks), sqlite3_value_*
(UDF-coupled), varargs config, UTF-16, and subsystems this build omits
— the boundary list lives in the module header and vendor README.

rename.h is now GENERATED by make into build/vendor/ from the bindings'
#foreign names — src/db/sqlite.sx is the single source of truth and the
rename list cannot drift (checked-in vendor/sqlite/rename.h removed).

make test 21/21 (new: sqlite_api.sx — 15 cases over every wrapper
family, including a blob round trip with interior NULs, UNIQUE
constraint extended errcodes, txn_state through BEGIN IMMEDIATE,
backup db->db, and a serialize->deserialize round trip).

KNOWN sx BOUNDARY (filed as a followup): 'if !e' on an error binding
evaluates true even when the error is set — negated error logic in
tests routes through plain bools.
2026-06-12 13:11:14 +03:00
agra
ad34fe88f2 sqlite bindings: idiomatic FFI string types
Whole C strings IN are [:0]u8 (the std convention, popen/getenv) with
terminated copies built via cstring(); nullable C strings OUT are *u8
with the getenv-style cast null-check — usize said nothing about what
crossed the boundary. prepare_v2/bind_text stay [*]u8 + explicit byte
length on purpose: those are (ptr, nByte) APIs, which is what lets
un-terminated sx string views pass without copying. Handles stay usize
so sqlite3_open's out-param is a single-level *usize.
2026-06-12 12:41:12 +03:00
agra
afec94a113 P5.1: vendor SQLite 3.53.2 + sx bindings
Subplan 02 Slice 2 foundation. vendor/sqlite/ holds the amalgamation
(provenance + upgrade notes in its README); make build compiles it into
build/vendor/libsqlite3.a (statically linked into dist via -L) and
build/vendor/jit/libsqlite3.dylib (dlopen'd by sx run via tests/run.sh's
-L flag) — separate directories because the macOS linker prefers a dylib
over an archive in one search dir.

The sx JIT resolves #foreign symbols via dlsym(RTLD_DEFAULT), where the
already-loaded OS libsqlite3 wins by load order — so the vendored build
renames its API to dist_sqlite3_* (vendor/sqlite/rename.h, -include'd),
making resolution unambiguous in both modes: those symbols exist only in
the vendored products.

src/db/sqlite.sx binds the renamed surface behind Sqlite/SqliteStmt
(open/exec/prepare/bind/step/column/finalize, errmsg, last_insert_rowid,
changes, libversion); opaque handles cross the FFI as usize, strings
read from sqlite are copied before its buffers die.

make test 20/20 (new: sqlite_smoke.sx — pins the loaded version to the
vendored 3.53.2, round trip, reopen persistence, BEGIN/ROLLBACK, errmsg;
also verified as an AOT binary with no libsqlite3 in otool -L).
2026-06-12 12:07:22 +03:00