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
31 lines
638 B
C++
31 lines
638 B
C++
#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;
|
||
}
|
||
};
|