2018-07-06 13:30:23 +02:00
|
|
|
#include "database.h"
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
Database::Database(const std::string& dbname) : db(nullptr)
|
|
|
|
{
|
|
|
|
const int errCode = sqlite3_open(dbname.c_str(), &db);
|
2018-07-09 13:03:03 +02:00
|
|
|
if (errCode) {
|
2018-07-06 13:30:23 +02:00
|
|
|
throw std::runtime_error("Could not open database file.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-09 13:03:03 +02:00
|
|
|
Database::~Database() { sqlite3_close(db); }
|
2018-07-06 13:30:23 +02:00
|
|
|
|
|
|
|
void Database::exec(const std::string& sql)
|
|
|
|
{
|
|
|
|
const int errCode = sqlite3_exec(db, sql.c_str(), nullptr, nullptr, nullptr);
|
2018-07-09 13:03:03 +02:00
|
|
|
if (errCode) {
|
2018-07-06 13:30:23 +02:00
|
|
|
throw std::runtime_error("Error in SQL execution.");
|
|
|
|
}
|
|
|
|
}
|