From 6506c1cff280fa5eecc29f59de9ad21b8dddecc3 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 29 May 2023 19:08:56 +0200 Subject: [PATCH] Fix formation JSON export. --- json.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/json.cpp b/json.cpp index 09b2c4d..0bd2452 100644 --- a/json.cpp +++ b/json.cpp @@ -80,7 +80,7 @@ QJsonArray export_matches_to_json(sqlite3 *db) // Load the events, splitting them into matches as we go. std::map events_per_match; sqlite3_stmt *stmt; - int ret = sqlite3_prepare_v2(db, "SELECT match, t, player, type FROM event ORDER BY t", -1, &stmt, 0); + int ret = sqlite3_prepare_v2(db, "SELECT match, t, player, formation, type FROM event ORDER BY t", -1, &stmt, 0); if (ret != SQLITE_OK) { fprintf(stderr, "SELECT prepare: %s\n", sqlite3_errmsg(db)); abort(); @@ -100,7 +100,12 @@ QJsonArray export_matches_to_json(sqlite3 *db) } else { e.insert("player", QJsonValue()); // null } - e.insert("type", (const char *)sqlite3_column_text(stmt, 3)); + if (sqlite3_column_type(stmt, 3) == SQLITE_INTEGER) { + e.insert("formation", sqlite3_column_int(stmt, 3)); + } else { + e.insert("formation", QJsonValue()); // null + } + e.insert("type", (const char *)sqlite3_column_text(stmt, 4)); events_per_match[match]->push_back(std::move(e)); } else if (ret == SQLITE_DONE) { break; -- 2.39.2