diff options
| author | Paul Oliver <contact@pauloliver.dev> | 2026-05-25 21:15:22 +0200 |
|---|---|---|
| committer | Paul Oliver <contact@pauloliver.dev> | 2026-05-25 21:15:22 +0200 |
| commit | 54342ed0cc61585d953183ec29309eb0db846b72 (patch) | |
| tree | d852870f968869fd74ccdac1943e02fe5655059e /core/sql.c | |
| parent | 5ce8953bcb98e037f50a37abadf664d95ee69cc2 (diff) | |
Reorganizes includes
Diffstat (limited to 'core/sql.c')
| -rw-r--r-- | core/sql.c | 24 |
1 files changed, 23 insertions, 1 deletions
@@ -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); +} |
