diff --git a/jsonhelper.cc b/jsonhelper.cc index cb28e5b..865e18c 100644 --- a/jsonhelper.cc +++ b/jsonhelper.cc @@ -6,10 +6,10 @@ using namespace std; nlohmann::json packResultsJson(const vector>& result, bool fillnull) { nlohmann::json arr = nlohmann::json::array(); - + for(const auto& row : result) { - nlohmann::json j; - for(auto& col : row) { + nlohmann::json &j = arr.emplace_back(); + for(const auto& col : row) { std::visit([&j, &col, &fillnull](auto&& arg) { using T = std::decay_t; if constexpr (std::is_same_v) { @@ -23,7 +23,6 @@ nlohmann::json packResultsJson(const vectorclear(); DeadlineCatcher dc(d_sqlite, msec); // noop if msec = 0 - - std::unordered_map row; + for(;;) { rc = sqlite3_step(d_stmts[table]); if(rc == SQLITE_DONE) break; else if(rows && rc == SQLITE_ROW) { - row.clear(); + std::unordered_map& row = rows->emplace_back(); + for(int n = 0 ; n < sqlite3_column_count(d_stmts[table]);++n) { int type = sqlite3_column_type(d_stmts[table], n); @@ -184,9 +184,7 @@ void MiniSQLite::execPrep(const std::string& table, std::vectorpush_back(row); } else { sqlite3_reset(d_stmts[table]); @@ -365,7 +363,7 @@ std::vector> SQLiteWriter::query(co auto res = queryGen(q, values); std::vector> ret; for(const auto& rowin : res) { - std::unordered_map rowout; + std::unordered_map& rowout = ret.emplace_back(); for(const auto& f : rowin) { string str; std::visit([&str](auto&& arg) { @@ -380,7 +378,6 @@ std::vector> SQLiteWriter::query(co }, f.second); rowout[f.first] = str; } - ret.push_back(rowout); } return ret; }