Add jextract module: SQLite bindings generated with jextract, FFM arenas, C strings, out-parameters, errors, upcalls, and a JMH comparison with JNI
jextract-25 early-access build (25-jextract+2-4) on JDK 25.0.5+8 against SQLite 3.45.1: 25 functions and 13 constants generated into 4 committed files (the whole header would be 83 files), a small Db wrapper, the four arena kinds used wrongly on purpose, ADDRESS vs C_POINTER zero-length vs unbounded segments and the SIGSEGV from getString on a NULL pointer, sqlite3_open out-parameter, return codes to exceptions, a sqlite3_exec upcall and the VM exit when it throws, the JDK 25 native-access warning and --illegal-native-access=deny, library loading failures, and a JMH benchmark of FFM vs hand-written JNI vs plain Java (indicative only: shared 2-CPU machine). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6Kg9RWSTJzyz6KP9X
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package demo;
|
||||
|
||||
import static demo.sqlite.sqlite3_h.*;
|
||||
|
||||
/** Return codes become exceptions. Each failure below is real SQLite output. */
|
||||
public class Errors {
|
||||
static void attempt(String label, Runnable r) {
|
||||
try {
|
||||
r.run();
|
||||
System.out.println(label + " -> no error");
|
||||
} catch (SqliteException e) {
|
||||
System.out.println(label + " -> " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
attempt("open in a directory that does not exist", () -> Db.open("/no/such/dir/app.db").close());
|
||||
attempt("open a missing file read-only", () -> Db.open("/tmp/jextract-demo-missing.db", SQLITE_OPEN_READONLY()).close());
|
||||
try (Db db = Db.open(":memory:")) {
|
||||
attempt("syntax error", () -> db.exec("SELEC 1"));
|
||||
attempt("missing table", () -> db.exec("INSERT INTO ghost VALUES (1)"));
|
||||
db.exec("CREATE TABLE t(id INTEGER PRIMARY KEY, name TEXT NOT NULL)");
|
||||
attempt("NOT NULL violation", () -> db.exec("INSERT INTO t(id) VALUES (1)"));
|
||||
db.exec("INSERT INTO t VALUES (1, 'a')");
|
||||
attempt("PRIMARY KEY violation", () -> db.exec("INSERT INTO t VALUES (1, 'b')"));
|
||||
System.out.println("SQLITE_CONSTRAINT = " + SQLITE_CONSTRAINT() + ", sqlite3_errstr(19) = " + sqlite3_errstr(19).getString(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user