Database class added
This commit is contained in:
parent
d8b39eab0a
commit
1e8c4eac5f
3 changed files with 49 additions and 1 deletions
24
src/core/database.cpp
Normal file
24
src/core/database.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include "database.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
Database::Database(const std::string& dbname) : db(nullptr)
|
||||
{
|
||||
const int errCode = sqlite3_open(dbname.c_str(), &db);
|
||||
if(errCode) {
|
||||
throw std::runtime_error("Could not open database file.");
|
||||
}
|
||||
}
|
||||
|
||||
Database::~Database()
|
||||
{
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
void Database::exec(const std::string& sql)
|
||||
{
|
||||
const int errCode = sqlite3_exec(db, sql.c_str(), nullptr, nullptr, nullptr);
|
||||
if(errCode) {
|
||||
throw std::runtime_error("Error in SQL execution.");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue