working on bindings for sqlite3
This commit is contained in:
27
sqlite3/sqlite3.c
Normal file
27
sqlite3/sqlite3.c
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#include <groundext.h>
|
||||||
|
#include <sqlite3.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user