Browse Source

pEpSQLite - Add helper function eval_sql_count()

LIB-12
heck 4 years ago
parent
commit
706431c85c
  1. 26
      src/pEpSQLite.cc
  2. 1
      src/pEpSQLite.hh

26
src/pEpSQLite.cc

@ -132,6 +132,32 @@ namespace pEp {
return ss.str(); 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() pEpSQLite::~pEpSQLite()
{ {
pEpLogClass("called"); pEpLogClass("called");

1
src/pEpSQLite.hh

@ -35,6 +35,7 @@ namespace pEp {
// Utils // Utils
static std::string to_string(const RSRecord& rec); static std::string to_string(const RSRecord& rec);
static std::string to_string(const ResultSet& rs); static std::string to_string(const ResultSet& rs);
static int eval_sql_count(const ResultSet& rs, const std::string& countfieldname);
// Logging // Logging
static bool log_enabled; static bool log_enabled;

Loading…
Cancel
Save