Files
biboumi/src/database/count_query.hpp
T
louiz’ 414bbca0bc Handle postgresql and sqlite3 libs properly
Do not fail to compile when one of them is missing but the other one is not.

Raise an error when trying to open a database with the missing library.

see #3237
2017-12-02 20:08:50 +01:00

31 lines
638 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include <database/query.hpp>
#include <database/table.hpp>
#include <database/statement.hpp>
#include <string>
struct CountQuery: public Query
{
CountQuery(std::string name):
Query("SELECT count(*) FROM ")
{
this->body += std::move(name);
}
int64_t execute(DatabaseEngine& db)
{
auto statement = db.prepare(this->body);
int64_t res = 0;
if (statement->step() != StepResult::Error)
res = statement->get_column_int64(0);
else
{
log_error("Count request didn’t return a result");
return 0;
}
return res;
}
};