qswiki/database/sqlitedao.h

45 rivejä
936 B
C
Raaka Normaali näkymä Historia

2018-11-03 17:12:20 +01:00
#ifndef SQLITEDAO_H
#define SQLITEDAO_H
#include <string_view>
#include <sqlite3.h>
#include <stdarg.h>
#include <sqlite_modern_cpp.h>
#include <sqlite_modern_cpp/errors.h>
#include "queryoption.h"
#include "exceptions.h"
#include "../logger.h"
class SqliteDao
{
protected:
std::shared_ptr<sqlite::database> db;
public:
SqliteDao()
{
}
SqliteDao(std::shared_ptr<sqlite::database> db)
{
this->db = db;
}
void setDb(std::shared_ptr<sqlite::database> db)
{
this->db = db;
}
inline void throwFrom(const sqlite::sqlite_exception &e) const
{
std::string msg = "Sqlite Error: " + std::to_string(e.get_code()) + " SQL: " + e.get_sql();
Logger::error() << msg << " Extended code: " << e.get_extended_code();
throw DatabaseQueryException(msg);
}
bool execBool(sqlite::database_binder &binder) const;
int execInt(sqlite::database_binder &binder) const;
virtual ~SqliteDao() = default;
2018-11-03 17:12:20 +01:00
};
#endif // SQLITEDAO_H