diff --git a/server/hard_schema.db-journal b/server/hard_schema.db-journal new file mode 100644 index 0000000..9ea002f Binary files /dev/null and b/server/hard_schema.db-journal differ diff --git a/server/mem_schema.db b/server/mem_schema.db new file mode 100644 index 0000000..e69de29 diff --git a/server/mem_schema.db-journal b/server/mem_schema.db-journal new file mode 100644 index 0000000..88535c0 Binary files /dev/null and b/server/mem_schema.db-journal differ diff --git a/server/src/db/_init_sql.cpp b/server/src/db/_init_sql.cpp index 32ced8f..7d03c35 100644 --- a/server/src/db/_init_sql.cpp +++ b/server/src/db/_init_sql.cpp @@ -1,8 +1,13 @@ #include const char* _mem_db_sql = - "CREATE TABLE SERVER_LIST ( " - ");"; + "CREATE TABLE `SERVER_LIST` (" + "`ID` INTEGER PRIMARY KEY AUTOINCREMENT," + "`NAME` TEXT NOT NULL," + "`LICENSE` TEXT NOT NULL," + "`IP_ADDR` TEXT NOT NULL," + "`PORT` INTEGER NOT NULL" + ");\n"; const std::vector _hard_db_sql = { /** START MIGRATION 0 **/ @@ -13,6 +18,12 @@ const std::vector _hard_db_sql = { "PRIMARY KEY(`ID`)" ") WITHOUT ROWID;\n" + "CREATE TABLE `SERVER_LICENSES` (" + "`KEY_ID` TEXT NOT NULL UNIQUE," + "`SECRET` TEXT NOT NULL UNIQUE," + "`ALLOWANCE` INTEGER NOT NULL" + ");\n" + "CREATE TABLE `USERS` (" "`ID` INTEGER PRIMARY KEY AUTOINCREMENT," "`USERNAME` TEXT NOT NULL," diff --git a/server/src/db/database.cpp b/server/src/db/database.cpp index 48baed7..bdd31e4 100644 --- a/server/src/db/database.cpp +++ b/server/src/db/database.cpp @@ -16,7 +16,9 @@ void sosc::db::init_databases() { sqlite3_exec(_ctx.mem_db, _mem_db_sql, nullptr, nullptr, nullptr); sqlite3_open("scape.db", &_ctx.hard_db); - + db::Query query("SELECT * FROM MIGRATIONS ORDER BY ID ASC"); + auto results = query.GetResults(); + while() _ctx.ready = true; } @@ -29,3 +31,18 @@ void sosc::db::close_databases() { sqlite3_close(_ctx.hard_db); _ctx.ready = false; } + +sosc::db::Query::Query() : results(this) { + this->open = false; +} + +sosc::db::Query::Query(const std::string& query) : results(this) { + this->open = false; + this->SetQuery(query); +} + +void sosc::db::Query::SetQuery(const std::string &query) { + this->Close(); + + this->open = true; +} diff --git a/server/src/db/database.hpp b/server/src/db/database.hpp index 4382e3e..90c8c11 100644 --- a/server/src/db/database.hpp +++ b/server/src/db/database.hpp @@ -21,20 +21,21 @@ public: template T Get(int column); - std::string Get(int column, int type = DB_COL_TEXT); + template + T Get(int column, int type); private: - ResultSet(Query* query, sqlite3_stmt* stmt); - sqlite3_stmt* statement; + ResultSet(Query* query); Query* query; bool readable; friend class Query; }; -double ResultSet::Get(int column); +/*double ResultSet::Get(int column); int32_t ResultSet::Get(int column); int64_t ResultSet::Get(int column); sosc::time ResultSet::Get(int column); +std::string ResultSet::Get(int column, int type = DB_COL_TEXT);*/ class Query { public: @@ -44,8 +45,12 @@ public: void NonQuery(); - ResultSet* GetResults() const; + template + T Scalar(); + template + T Scalar(int type); + ResultSet* GetResults() const; inline bool IsOpen() const { return this->open; } @@ -60,6 +65,12 @@ private: bool open; }; +/*double Query::Scalar(); +int32_t Query::Scalar(); +int64_t Query::Scalar(); +sosc::time Query::Scalar(); +std::string Query::Scalar(int type = DB_COL_TEXT);*/ + // THE FOLLOWING ARE NOT THREAD SAFE !! // CALL THEM ONLY WHEN MASTER POOL IS INACTIVE void init_databases();