aboutsummaryrefslogtreecommitdiff
path: root/core/sql.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/sql.c')
-rw-r--r--core/sql.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/core/sql.c b/core/sql.c
index a03ce5d..fab6eeb 100644
--- a/core/sql.c
+++ b/core/sql.c
@@ -1,4 +1,8 @@
-void salis_exec_sql(int blob_cnt, const void **blobs, const int *blob_sizes, const char *sql_format, ...) {
+#define DATA_PUSH_BUSY_TIMEOUT 600000
+
+sqlite3 *g_sim_db;
+
+void sql_exec(int blob_cnt, const void **blobs, const int *blob_sizes, const char *sql_format, ...) {
assert(sql_format);
va_list args;
@@ -47,3 +51,21 @@ void salis_exec_sql(int blob_cnt, const void **blobs, const int *blob_sizes, con
sqlite3_finalize(sql_stmt);
}
+
+void sql_open(void) {
+ sqlite3_open(DATA_PUSH_PATH, &g_sim_db);
+ assert(g_sim_db);
+
+ // Install busy handler to retry transactions if DB is locked
+ sqlite3_busy_timeout(g_sim_db, DATA_PUSH_BUSY_TIMEOUT);
+
+ // Enable Write-Ahead Logging (WAL)
+ // This seems to help prevent DB locks when displaying live data.
+ // See: https://sqlite.org/wal.html
+ sql_exec(0, NULL, NULL, "pragma journal_mode=wal;");
+}
+
+void sql_close(void) {
+ assert(g_sim_db);
+ sqlite3_close(g_sim_db);
+}