From 706431c85c2df9125e65294c79f90cefdbd06068 Mon Sep 17 00:00:00 2001 From: heck Date: Mon, 19 Apr 2021 20:20:46 +0200 Subject: [PATCH] pEpSQLite - Add helper function eval_sql_count() --- src/pEpSQLite.cc | 26 ++++++++++++++++++++++++++ src/pEpSQLite.hh | 1 + 2 files changed, 27 insertions(+) diff --git a/src/pEpSQLite.cc b/src/pEpSQLite.cc index 322d8a2..dddc13c 100644 --- a/src/pEpSQLite.cc +++ b/src/pEpSQLite.cc @@ -132,6 +132,32 @@ namespace pEp { return ss.str(); } + //Helper + int pEpSQLite::eval_sql_count(const ResultSet& rs, const string& countfieldname) + { + int rescount = 0; + // Get row + RSRecord rec{}; + if (rs.size() != 1) { + runtime_error e{ "ListManagerDummy: eval_sql_count() - row count != 1" }; + throw_with_nested(e); + } + try { + rec = rs.at(0); + } catch (...) { + runtime_error e{ "ListManagerDummy: eval_sql_count() - cant get row nr 0" }; + throw_with_nested(e); + } + // Get field + try { + rescount = stoi(rec.at(countfieldname)); + } catch (...) { + runtime_error e{ "ListManagerDummy: eval_sql_count() - field not existing" }; + throw_with_nested(e); + } + return rescount; + } + pEpSQLite::~pEpSQLite() { pEpLogClass("called"); diff --git a/src/pEpSQLite.hh b/src/pEpSQLite.hh index 2bd8019..179acc2 100644 --- a/src/pEpSQLite.hh +++ b/src/pEpSQLite.hh @@ -35,6 +35,7 @@ namespace pEp { // Utils static std::string to_string(const RSRecord& rec); static std::string to_string(const ResultSet& rs); + static int eval_sql_count(const ResultSet& rs, const std::string& countfieldname); // Logging static bool log_enabled;