diff options
| author | Paul Oliver <contact@pauloliver.dev> | 2026-05-25 23:00:48 +0200 |
|---|---|---|
| committer | Paul Oliver <contact@pauloliver.dev> | 2026-05-25 23:00:48 +0200 |
| commit | 848c5cca715c514ce6e57e0fa7ef8e71b09c0b08 (patch) | |
| tree | 7eb840e773c068a23819b03819d06ff2901c5b5b | |
| parent | bace2d7f20acc609d552a80bb018939d5e8afab8 (diff) | |
Updates sql_exec function to allow reading data
| -rw-r--r-- | arch/v1/arch.c | 9 | ||||
| -rw-r--r-- | core/salis.c | 4 | ||||
| -rw-r--r-- | core/sql.c | 18 | ||||
| -rw-r--r-- | data/client.cpp | 5 |
4 files changed, 20 insertions, 16 deletions
diff --git a/arch/v1/arch.c b/arch/v1/arch.c index e0203cb..0053ec9 100644 --- a/arch/v1/arch.c +++ b/arch/v1/arch.c @@ -860,7 +860,7 @@ void arch_push_data_header(void) { log_info("Creating arch table in SQLite database"); sql_exec( - 0, NULL, NULL, + 0, NULL, NULL, NULL, NULL, "create table arch (" #define INST(core, pref, index, label, mnemonic, symbol) \ #label "_" #pref "_" #core " int not null, " @@ -870,7 +870,6 @@ void arch_push_data_header(void) { #ev "_size_" #core " int not null, " \ #ev "_" #core " blob not null, " #define FOR_CORE(i) \ - "cycl_" #i " int not null, " \ "wmb0_" #i " int not null, " \ "wmb1_" #i " int not null, " \ "wdea_" #i " int not null, " \ @@ -948,7 +947,7 @@ void arch_push_data_line(void) { log_info("Pushing row to arch table in SQLite database"); sql_exec( - CORES * ARCH_EVENT_ARRAYS_COUNT, (const void **)blobs, (int *)blob_sizes, + CORES * ARCH_EVENT_ARRAYS_COUNT, (const void **)blobs, (int *)blob_sizes, NULL, NULL, "insert into arch (" #define INST(core, pref, index, label, mnemonic, symbol) \ #label "_" #pref "_" #core ", " @@ -958,7 +957,6 @@ void arch_push_data_line(void) { #ev "_size_" #core ", " \ #ev "_" #core ", " #define FOR_CORE(i) \ - "cycl_" #i ", " \ "wmb0_" #i ", " \ "wmb1_" #i ", " \ "wdea_" #i ", " \ @@ -978,7 +976,7 @@ void arch_push_data_line(void) { #define ARCH_EVENT_ARRAY(core, index, ev) \ "%ld, ?, " #define FOR_CORE(i) \ - "%ld, %ld, %ld, %ld, " \ + "%ld, %ld, %ld, " \ INST_EVENT_ARRAYS(i) \ ARCH_EVENT_ARRAYS(i) FOR_CORES @@ -995,7 +993,6 @@ void arch_push_data_line(void) { #define ARCH_EVENT_ARRAY(core, index, ev) \ blob_sizes[core][index], #define FOR_CORE(i) \ - g_cores[i].cycl, \ g_cores[i].wmb0, \ g_cores[i].wmb1, \ g_cores[i].wdea, \ diff --git a/core/salis.c b/core/salis.c index d6efcf2..a5b517a 100644 --- a/core/salis.c +++ b/core/salis.c @@ -691,7 +691,7 @@ void salis_push_data_header(void) { log_info("Creating core table in SQLite database"); sql_exec( - 0, NULL, NULL, + 0, NULL, NULL, NULL, NULL, "create table core (" #define EVENT_ARRAY(core, index, ev) \ #ev "_size_" #core " int not null, " \ @@ -778,7 +778,7 @@ void salis_push_data_line(void) { log_info("Pushing row to core table in SQLite database"); sql_exec( - CORES * EVENT_ARRAYS_COUNT, (const void **)blobs, (int *)blob_sizes, + CORES * EVENT_ARRAYS_COUNT, (const void **)blobs, (int *)blob_sizes, NULL, NULL, "insert into core (" #define EVENT_ARRAY(core, index, ev) \ #ev "_size_" #core ", " \ @@ -2,7 +2,7 @@ sqlite3 *g_sim_db; -void sql_exec(int blob_cnt, const void **blobs, const int *blob_sizes, const char *sql_format, ...) { +void sql_exec(int blob_cnt, const void **blobs, const int *blob_sizes, void (*callback)(void *data), void *data, const char *sql_format, ...) { assert(sql_format); va_list args; @@ -29,18 +29,26 @@ void sql_exec(int blob_cnt, const void **blobs, const int *blob_sizes, const cha assert(sql_res == SQLITE_OK); } - // Only handle SQLITE_BUSY error, in which case we retry the query. - // Setting 'journal_mode=wal;' should help prevent busy database errors. while (true) { sql_res = sqlite3_step(sql_stmt); - if (sql_res == SQLITE_DONE || sql_res == SQLITE_ROW) { + if (sql_res == SQLITE_ROW) { + if (callback) { + callback(data); + } + + continue; + } + + if (sql_res == SQLITE_DONE) { break; } log_warn("SQLite database returned error %d with message:", sql_res); log_warn(sqlite3_errmsg(g_sim_db)); + // Only handle SQLITE_BUSY error, in which case we retry the query. + // Setting 'journal_mode=wal;' should help prevent busy database errors. if (sql_res == SQLITE_BUSY) { log_info("Will retry query..."); continue; @@ -62,7 +70,7 @@ void sql_open(void) { // 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;"); + sql_exec(0, NULL, NULL, NULL, NULL, "pragma journal_mode=wal;"); } void sql_close(void) { diff --git a/data/client.cpp b/data/client.cpp index 65494b0..730ea7a 100644 --- a/data/client.cpp +++ b/data/client.cpp @@ -57,8 +57,7 @@ ImPlotStyle *g_implot_style; // Data globals const char *g_x_axes[] = { - "rowid", - "steps", + "step", #define FOR_CORE(i) "cycl_" #i, FOR_CORES #undef FOR_CORE @@ -272,7 +271,7 @@ void gui_print_data_col(void) { if (ImGui::InputInt("nth", &g_nth, 0, 0, ImGuiInputTextFlags_CharsDecimal)) data_touched(); if (ImGui::BeginCombo("x-axis", g_x_axes[g_x_axis])) { - for (int i = 0; i < CORES + 2; i++) { + for (int i = 0; i < CORES + 1; i++) { if (ImGui::Selectable(g_x_axes[i], g_x_axis == i)) { g_x_axis = i; data_touched(); |
