sqlite doesn't have a datetime type :childish:

This commit is contained in:
malloc 2018-04-27 16:29:30 -05:00
parent 6491e7170b
commit 227a9df1e8
2 changed files with 35 additions and 2 deletions

View file

@ -16,7 +16,7 @@ void sosc::db::init_databases() {
sqlite3_exec(_ctx.mem_db, _mem_db_sql, nullptr, nullptr, nullptr); sqlite3_exec(_ctx.mem_db, _mem_db_sql, nullptr, nullptr, nullptr);
sqlite3_open("scape.db", &_ctx.hard_db); sqlite3_open("scape.db", &_ctx.hard_db);
_ctx.ready = true; _ctx.ready = true;
} }
@ -28,4 +28,4 @@ void sosc::db::close_databases() {
sqlite3_close(_ctx.mem_db); sqlite3_close(_ctx.mem_db);
sqlite3_close(_ctx.hard_db); sqlite3_close(_ctx.hard_db);
_ctx.ready = false; _ctx.ready = false;
} }

View file

@ -2,27 +2,60 @@
#define SOSC_DATABASE_H #define SOSC_DATABASE_H
#include "sqlite/sqlite3.h" #include "sqlite/sqlite3.h"
#include "../utils/time.hpp"
#include <vector> #include <vector>
#include <string> #include <string>
#define DB_COL_TEXT 1
#define DB_COL_BLOB 2
namespace sosc { namespace sosc {
namespace db { namespace db {
class Query;
class ResultSet { class ResultSet {
public: public:
bool IsOpen() const;
bool IsReadable() const;
bool Step();
template<typename T>
T Get(int column);
std::string Get(int column, int type = DB_COL_TEXT);
private: private:
ResultSet(Query* query, sqlite3_stmt* stmt);
sqlite3_stmt* statement;
Query* query;
bool readable;
friend class Query;
}; };
double ResultSet::Get<double>(int column);
int32_t ResultSet::Get<int32_t>(int column);
int64_t ResultSet::Get<int64_t>(int column);
sosc::time ResultSet::Get<sosc::time>(int column);
class Query { class Query {
public: public:
Query(); Query();
Query(const std::string& query); Query(const std::string& query);
void SetQuery(const std::string& query); void SetQuery(const std::string& query);
void NonQuery();
ResultSet* GetResults() const;
inline bool IsOpen() const {
return this->open;
}
void Reset(); void Reset();
void Close(); void Close();
private: private:
ResultSet results;
sqlite3_stmt* statement;
std::string query; std::string query;
bool open; bool open;
}; };