library: vendors/sqlite — SQLite ships with sx
The vendored amalgamation (3.53.2, public domain) plus the curated bindings move from the distribution repo into the sx library: '#import "vendors/sqlite/sqlite.sx"' gives any sx program SQLite with no system dependency and no build flags — the bindings declare the C as a named #import c unit (pinned defines + -O2), compiled through the object cache and shadow-proof via unit-first resolution. examples/1624 pins the version and a typed round trip in-suite.
This commit is contained in:
37
examples/1624-vendor-sqlite-module.sx
Normal file
37
examples/1624-vendor-sqlite-module.sx
Normal file
@@ -0,0 +1,37 @@
|
||||
// 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
|
||||
}
|
||||
1
examples/expected/1624-vendor-sqlite-module.exit
Normal file
1
examples/expected/1624-vendor-sqlite-module.exit
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
0
examples/expected/1624-vendor-sqlite-module.stderr
Normal file
0
examples/expected/1624-vendor-sqlite-module.stderr
Normal file
2
examples/expected/1624-vendor-sqlite-module.stdout
Normal file
2
examples/expected/1624-vendor-sqlite-module.stdout
Normal file
@@ -0,0 +1,2 @@
|
||||
row: b 2
|
||||
vendored sqlite 3.53.2 ok
|
||||
Reference in New Issue
Block a user