diff options
Diffstat (limited to 'core.j2.c')
| -rw-r--r-- | core.j2.c | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -609,6 +609,31 @@ void salis_auto_save() { } {% endif %} +{% if data_push_path is defined %} +void salis_exec_sql(const char *sql) { + assert(sql); + + int sql_res; + char *sql_err; + + while ((sql_res = sqlite3_exec(g_sim_data, sql, NULL, NULL, &sql_err)) == SQLITE_BUSY) { + g_warn("SQLite database returned error '%d' with message:", sql_res); + g_warn(sql_err); + sqlite3_free(sql_err); + + switch (sql_res) { + case SQLITE_BUSY: + // Only handle busy database errors + g_info("Will retry query..."); + continue; + default: + // Application should fail on all other error conditions + assert(false); + } + } +} +{% endif %} + {% if args.command in ["bench", "new"] %} void salis_init() { assert(g_info); @@ -631,6 +656,11 @@ void salis_init() { // Install busy handler to retry transactions if DB is locked sqlite3_busy_timeout(g_sim_data, {{ 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 + salis_exec_sql("pragma journal_mode=wal;"); + arch_push_data_header(); arch_push_data_line(); {% endif %} |
