From 90192be2b17ce39529b6e51f3d325913f28d9e4c Mon Sep 17 00:00:00 2001 From: SpookyDervish Date: Tue, 20 Jan 2026 17:13:04 +1100 Subject: [PATCH] working on bindings for sqlite3 --- sqlite3/sqlite3.c | 27 +++++++++++++++++++++++++++ test.db | 0 test.grnd | 4 ++++ 3 files changed, 31 insertions(+) create mode 100644 sqlite3/sqlite3.c create mode 100644 test.db create mode 100644 test.grnd diff --git a/sqlite3/sqlite3.c b/sqlite3/sqlite3.c new file mode 100644 index 0000000..c78f2cd --- /dev/null +++ b/sqlite3/sqlite3.c @@ -0,0 +1,27 @@ +#include +#include +#include + +GroundValue close_db(GroundScope* scope, List args) { + sqlite3* DB = (sqlite3*)args.values[0].data.intVal; + sqlite3_close(DB); + return groundCreateValue(INT, 0); +} + +GroundValue open_db(GroundScope* scope, List args) { + sqlite3* DB; + + const char* dbPath = args.values[0].data.stringVal; + int errorCode = sqlite3_open(dbPath, &DB); + + if (errorCode) { + ERROR(sqlite3_errmsg(DB), "SQLite3Error"); + } + + return groundCreateValue(INT, (uint64_t)DB); +} + +void ground_init(GroundScope* scope) { + groundAddNativeFunction(scope, "sqlite3_Open", open_db, INT, 1, STRING, "dbPath"); + groundAddNativeFunction(scope, "sqlite3_Close", close_db, INT, 1, INT, "db"); +} \ No newline at end of file diff --git a/test.db b/test.db new file mode 100644 index 0000000..e69de29 diff --git a/test.grnd b/test.grnd new file mode 100644 index 0000000..47f90cc --- /dev/null +++ b/test.grnd @@ -0,0 +1,4 @@ +extern "sqlite3" + +call !sqlite3_Open "test.db" &db +call !sqlite3_Close $db & \ No newline at end of file