From f3b1fd19330f9bd7acde2d0ae8bc2e00eea3ddae Mon Sep 17 00:00:00 2001 From: Tyler Karaszewski Date: Mon, 4 Nov 2024 14:05:06 -0800 Subject: [PATCH] Fix bug reading queries in HC-Tree mode --- test/lib/BedrockTester.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/test/lib/BedrockTester.cpp b/test/lib/BedrockTester.cpp index 9824a017f..8f1e3ac05 100644 --- a/test/lib/BedrockTester.cpp +++ b/test/lib/BedrockTester.cpp @@ -1,4 +1,5 @@ #include "BedrockTester.h" +#include "libstuff/libstuff.h" #include #include @@ -547,31 +548,33 @@ void BedrockTester::freeDB() { string BedrockTester::readDB(const string& query, bool online) { - if (ENABLE_HCTREE && online) { - SData command("Query"); - command["Query"] = query; - command["Format"] = "JSON"; - auto row0 = SParseJSONObject(executeWaitMultipleData({command})[0].content)["rows"]; - if (row0 == "") { - return ""; - } + SQResult result; + bool success = readDB(query, result, online); + if (!success) { + return ""; + } - return SParseJSONArray(SParseJSONArray(row0).front()).front(); - } else { - SQLite& db = getSQLiteDB(); - db.beginTransaction(); - string result = db.read(query); - db.rollback(); - return result; + if (result.empty()) { + return ""; } + + if (result.rows[0].empty()) { + return ""; + } + + return result.rows[0][0]; } bool BedrockTester::readDB(const string& query, SQResult& result, bool online) { if (ENABLE_HCTREE && online) { + string fixedQuery = query; + if (!SEndsWith(query, ";")) { + fixedQuery += ";"; + } result.clear(); SData command("Query"); - command["Query"] = query; + command["Query"] = fixedQuery; command["Format"] = "JSON"; auto row0 = SParseJSONObject(executeWaitMultipleData({command})[0].content)["rows"];