summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-01-12 13:30:14 +0100
committerFlorian Dold <florian@dold.me>2024-01-12 13:30:14 +0100
commitaa071962b81d60485d5c4032d5e49ec0c92d1116 (patch)
tree41f650df5dc31dcb5c094561633da54133e7cfc6
parent248834b1b48905ff29d52d6f14ff5abda175a4d9 (diff)
downloadquickjs-tart-aa071962b81d60485d5c4032d5e49ec0c92d1116.tar.gz
quickjs-tart-aa071962b81d60485d5c4032d5e49ec0c92d1116.tar.bz2
quickjs-tart-aa071962b81d60485d5c4032d5e49ec0c92d1116.zip
more logging for sqlite3
-rw-r--r--qtart.c24
-rw-r--r--tart_module.c5
2 files changed, 29 insertions, 0 deletions
diff --git a/qtart.c b/qtart.c
index c670b46..cabde5a 100644
--- a/qtart.c
+++ b/qtart.c
@@ -305,6 +305,23 @@ handle_host_message(void *cls, const char *msg)
printf("message from JS to host: %s\n", msg);
}
+static JSValue js_native_log(JSContext *ctx,
+ JSValueConst this_obj,
+ int argc, JSValueConst *argv)
+{
+ const char *tag = NULL;
+ const char *msg = NULL;
+ uint32_t level = 0;
+
+ JS_ToUint32(ctx, &level, argv[0]);
+ tag = JS_ToCString(ctx, argv[1]);
+ msg = JS_ToCString(ctx, argv[2]);
+ printf("log: %u, %s, %s\n", (unsigned int) level, tag, msg);
+ JS_FreeCString(ctx, tag);
+ JS_FreeCString(ctx, msg);
+ return JS_UNDEFINED;
+}
+
int main(int argc, char **argv)
{
JSRuntime *rt;
@@ -455,8 +472,15 @@ int main(int argc, char **argv)
NULL);
if (!empty_run) {
+ JSValue global_obj;
+
js_std_add_helpers(ctx, argc - optind, argv + optind);
+ global_obj = JS_GetGlobalObject(ctx);
+ JS_SetPropertyStr(ctx, global_obj, "__nativeLog",
+ JS_NewCFunction(ctx, js_native_log, "__nativeLog", 3));
+ JS_FreeValue(ctx, global_obj);
+
/* make 'std', 'os' and 'tart' visible to non module code */
if (load_std) {
const char *str = "import * as std from 'std';\n"
diff --git a/tart_module.c b/tart_module.c
index 71ab7c4..2bd9377 100644
--- a/tart_module.c
+++ b/tart_module.c
@@ -1598,6 +1598,7 @@ static JSValue js_sqlite3_open(JSContext *ctx, JSValue this_val,
goto done;
}
+ fprintf(stderr, "opening sqlite3 db at %s", filename),
ret = sqlite3_open_v2(filename, &sqlite3_db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
if (SQLITE_OK != ret) {
if (NULL == sqlite3_db) {
@@ -1605,7 +1606,11 @@ static JSValue js_sqlite3_open(JSContext *ctx, JSValue this_val,
ret_val = JS_ThrowInternalError(ctx, "unable to open database (OOM)");
} else {
// get error details from DB before we close it
+ fprintf(stderr, "sqlite3_open failed: %s / %s\n",
+ sqlite3_errstr(ret),
+ sqlite3_errmsg(sqlite3_db));
ret_val = throw_sqlite3_error(ctx, sqlite3_db);
+ fprintf(stderr, "calling sqlite3 close on failed db\n");
(void)sqlite3_close_v2(sqlite3_db);
}
goto done;