Files
sx/examples/vendor/1624-vendor-sqlite-module.sx
agra 66bdc70bf1 test: group examples into per-category folders
Move examples/*.sx and their expected/ snapshots into per-category
subfolders (examples/<category>/...). Folder = leading filename token,
with ffi-objc/ffi-jni kept whole; filenames are unchanged. The corpus
runner and LSP sweep now discover each category's expected/ dir, while
issues/ stays flat. Example 1058's repo-root-relative companion import
is made file-relative. Path strings embedded in 164 snapshots were
regenerated (path-only changes). Test-layout docs in CLAUDE.md updated.
2026-06-21 14:41:34 +03:00

38 lines
1.4 KiB
Plaintext

// The sx library ships SQLite: `#import "vendors/sqlite/sqlite.sx"`
// resolves through the stdlib search paths, compiles the vendored
// amalgamation as a `#import c` unit (cached), and the bindings just
// work — no system dependency, no flags. Pins the vendored version
// (an OS libsqlite3 of another version must never shadow the unit)
// and a typed round trip.
#import "modules/std.sx";
sq :: #import "vendors/sqlite/sqlite.sx";
main :: () -> i32 {
v := sq.sqlite_version();
if v != "3.53.2" {
print("unexpected sqlite version: {}\n", v);
return 1;
}
db, oe := sq.Sqlite.open(":memory:");
if oe { print("open failed\n"); return 1; }
ee := false;
db.exec("CREATE TABLE t (name TEXT, n INTEGER); INSERT INTO t VALUES ('a', 1), ('b', 2)") catch { ee = true; };
if ee { print("exec failed: {}\n", db.errmsg()); db.close(); return 1; }
st, pe := db.prepare("SELECT name, n FROM t WHERE n > ?1 ORDER BY n");
if pe { print("prepare failed\n"); db.close(); return 1; }
st.bind_int64(1, 1) catch { ee = true; };
rc, se := st.step();
serr := false;
if se { serr = true; }
if serr or ee { print("step failed\n"); st.finalize(); db.close(); return 1; }
if rc == sq.SQLITE_ROW {
print("row: {} {}\n", st.column_text(0), st.column_int64(1));
}
st.finalize();
db.close();
print("vendored sqlite {} ok\n", v);
0
}