Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions jsonhelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ using namespace std;
nlohmann::json packResultsJson(const vector<unordered_map<string, MiniSQLite::outvar_t>>& 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<decltype(arg)>;
if constexpr (std::is_same_v<T, nullptr_t>) {
Expand All @@ -23,7 +23,6 @@ nlohmann::json packResultsJson(const vector<unordered_map<string, MiniSQLite::ou
}
}, col.second);
}
arr += j;
}
return arr;
}
Expand Down
11 changes: 4 additions & 7 deletions sqlwriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ void MiniSQLite::execPrep(const std::string& table, std::vector<std::unordered_m
rows->clear();

DeadlineCatcher dc(d_sqlite, msec); // noop if msec = 0

std::unordered_map<string, outvar_t> row;

for(;;) {
rc = sqlite3_step(d_stmts[table]);
if(rc == SQLITE_DONE)
break;
else if(rows && rc == SQLITE_ROW) {
row.clear();
std::unordered_map<string, outvar_t>& 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);

Expand Down Expand Up @@ -184,9 +184,7 @@ void MiniSQLite::execPrep(const std::string& table, std::vector<std::unordered_m
else if(type == SQLITE_NULL) {
row[sqlite3_column_name(d_stmts[table], n)]= nullptr;
}

}
rows->push_back(row);
}
else {
sqlite3_reset(d_stmts[table]);
Expand Down Expand Up @@ -365,7 +363,7 @@ std::vector<std::unordered_map<std::string, std::string>> SQLiteWriter::query(co
auto res = queryGen(q, values);
std::vector<std::unordered_map<std::string, std::string>> ret;
for(const auto& rowin : res) {
std::unordered_map<std::string, std::string> rowout;
std::unordered_map<std::string, std::string>& rowout = ret.emplace_back();
for(const auto& f : rowin) {
string str;
std::visit([&str](auto&& arg) {
Expand All @@ -380,7 +378,6 @@ std::vector<std::unordered_map<std::string, std::string>> SQLiteWriter::query(co
}, f.second);
rowout[f.first] = str;
}
ret.push_back(rowout);
}
return ret;
}
Expand Down