Congratulations and thank you for your purchase!

This commit is contained in:
malloc 2018-04-30 17:11:14 -05:00
parent 9ebac99dcc
commit 77d401e8d3
6 changed files with 47 additions and 8 deletions

Binary file not shown.

0
server/mem_schema.db Normal file
View file

Binary file not shown.

View file

@ -1,8 +1,13 @@
#include <vector> #include <vector>
const char* _mem_db_sql = 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<const char*> _hard_db_sql = { const std::vector<const char*> _hard_db_sql = {
/** START MIGRATION 0 **/ /** START MIGRATION 0 **/
@ -13,6 +18,12 @@ const std::vector<const char*> _hard_db_sql = {
"PRIMARY KEY(`ID`)" "PRIMARY KEY(`ID`)"
") WITHOUT ROWID;\n" ") 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` (" "CREATE TABLE `USERS` ("
"`ID` INTEGER PRIMARY KEY AUTOINCREMENT," "`ID` INTEGER PRIMARY KEY AUTOINCREMENT,"
"`USERNAME` TEXT NOT NULL," "`USERNAME` TEXT NOT NULL,"

View file

@ -16,7 +16,9 @@ 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);
db::Query query("SELECT * FROM MIGRATIONS ORDER BY ID ASC");
auto results = query.GetResults();
while()
_ctx.ready = true; _ctx.ready = true;
} }
@ -29,3 +31,18 @@ void sosc::db::close_databases() {
sqlite3_close(_ctx.hard_db); sqlite3_close(_ctx.hard_db);
_ctx.ready = false; _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;
}

View file

@ -21,20 +21,21 @@ public:
template<typename T> template<typename T>
T Get(int column); T Get(int column);
std::string Get(int column, int type = DB_COL_TEXT); template<typename T>
T Get(int column, int type);
private: private:
ResultSet(Query* query, sqlite3_stmt* stmt); ResultSet(Query* query);
sqlite3_stmt* statement;
Query* query; Query* query;
bool readable; bool readable;
friend class Query; friend class Query;
}; };
double ResultSet::Get<double>(int column); /*double ResultSet::Get<double>(int column);
int32_t ResultSet::Get<int32_t>(int column); int32_t ResultSet::Get<int32_t>(int column);
int64_t ResultSet::Get<int64_t>(int column); int64_t ResultSet::Get<int64_t>(int column);
sosc::time ResultSet::Get<sosc::time>(int column); sosc::time ResultSet::Get<sosc::time>(int column);
std::string ResultSet::Get<std::string>(int column, int type = DB_COL_TEXT);*/
class Query { class Query {
public: public:
@ -44,8 +45,12 @@ public:
void NonQuery(); void NonQuery();
ResultSet* GetResults() const; template<typename T>
T Scalar();
template<typename T>
T Scalar(int type);
ResultSet* GetResults() const;
inline bool IsOpen() const { inline bool IsOpen() const {
return this->open; return this->open;
} }
@ -60,6 +65,12 @@ private:
bool open; bool open;
}; };
/*double Query::Scalar<double>();
int32_t Query::Scalar<int32_t>();
int64_t Query::Scalar<int64_t>();
sosc::time Query::Scalar<sosc::time>();
std::string Query::Scalar<std::string>(int type = DB_COL_TEXT);*/
// THE FOLLOWING ARE NOT THREAD SAFE !! // THE FOLLOWING ARE NOT THREAD SAFE !!
// CALL THEM ONLY WHEN MASTER POOL IS INACTIVE // CALL THEM ONLY WHEN MASTER POOL IS INACTIVE
void init_databases(); void init_databases();