address boundary error not my beloved
This commit is contained in:
@@ -1,9 +1,31 @@
|
|||||||
#include <groundext.h>
|
#include <groundext.h>
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
sqlite3* getDB(List args) {
|
||||||
|
return (sqlite3*)args.values[0].data.intVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
GroundValue exec_sql(GroundScope* scope, List args) {
|
||||||
|
printf("hi\n");
|
||||||
|
sqlite3* DB = getDB(args);
|
||||||
|
printf("got db\n");
|
||||||
|
char* sqlCode = args.values[1].data.stringVal;
|
||||||
|
printf("%s\n", sqlCode);
|
||||||
|
|
||||||
|
char* errMessage;
|
||||||
|
int exitCode = sqlite3_exec(DB, sqlCode, NULL, 0, &errMessage);
|
||||||
|
|
||||||
|
if (exitCode != SQLITE_OK) {
|
||||||
|
ERROR(errMessage, "SQLite3Error");
|
||||||
|
} else {
|
||||||
|
return groundCreateValue(INT, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GroundValue close_db(GroundScope* scope, List args) {
|
GroundValue close_db(GroundScope* scope, List args) {
|
||||||
sqlite3* DB = (sqlite3*)args.values[0].data.intVal;
|
sqlite3* DB = getDB(args);
|
||||||
sqlite3_close(DB);
|
sqlite3_close(DB);
|
||||||
return groundCreateValue(INT, 0);
|
return groundCreateValue(INT, 0);
|
||||||
}
|
}
|
||||||
@@ -24,4 +46,5 @@ GroundValue open_db(GroundScope* scope, List args) {
|
|||||||
void ground_init(GroundScope* scope) {
|
void ground_init(GroundScope* scope) {
|
||||||
groundAddNativeFunction(scope, "sqlite3_Open", open_db, INT, 1, STRING, "dbPath");
|
groundAddNativeFunction(scope, "sqlite3_Open", open_db, INT, 1, STRING, "dbPath");
|
||||||
groundAddNativeFunction(scope, "sqlite3_Close", close_db, INT, 1, INT, "db");
|
groundAddNativeFunction(scope, "sqlite3_Close", close_db, INT, 1, INT, "db");
|
||||||
|
groundAddNativeFunction(scope, "sqlite3_Exec", exec_sql, INT, 2, INT, "db", STRING, "sql");
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
extern "sqlite3"
|
extern "sqlite3"
|
||||||
|
|
||||||
|
|
||||||
call !sqlite3_Open "test.db" &db
|
call !sqlite3_Open "test.db" &db
|
||||||
|
call !sqlite3_Exec $db "CREATE TABLE COMPANY(ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS CHAR(50), SALARY REAL)" &
|
||||||
call !sqlite3_Close $db &
|
call !sqlite3_Close $db &
|
||||||
Reference in New Issue
Block a user