added shadowrun database
This commit is contained in:
35
src/database/database.cpp
Normal file
35
src/database/database.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "crow.h"
|
||||
#include "database.hpp"
|
||||
|
||||
Database::Database() :
|
||||
m_db(nullptr)
|
||||
{}
|
||||
|
||||
Database::~Database() {
|
||||
sqlite3_close(m_db);
|
||||
}
|
||||
|
||||
bool Database::exec(const char* sqlQuery) {
|
||||
char* errmsg = nullptr;
|
||||
int rc = sqlite3_exec(m_db, sqlQuery, nullptr, nullptr, &errmsg);
|
||||
if (rc != SQLITE_OK) {
|
||||
CROW_LOG_ERROR << "SQL error: " << errmsg;
|
||||
sqlite3_free(errmsg);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Database::exec(const std::string& sqlQuery)
|
||||
{
|
||||
exec(sqlQuery.c_str());
|
||||
}
|
||||
|
||||
bool Database::open(){
|
||||
int rc = sqlite3_open("example.db", &m_db);
|
||||
if (rc) {
|
||||
CROW_LOG_ERROR << "Can't open database: " << sqlite3_errmsg(m_db);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
21
src/database/database.hpp
Normal file
21
src/database/database.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef __DATABASE_H__
|
||||
#define __DATABASE_H__
|
||||
|
||||
#include "sqlite3.h"
|
||||
#include <string>
|
||||
|
||||
class Database {
|
||||
|
||||
public:
|
||||
Database();
|
||||
~Database();
|
||||
|
||||
bool open();
|
||||
bool exec(const char* sqlQuery);
|
||||
bool exec(const std::string& sqlQuery);
|
||||
|
||||
private:
|
||||
sqlite3* m_db;
|
||||
};
|
||||
|
||||
#endif // __DATABASE_H__
|
||||
Reference in New Issue
Block a user