[Repositories] Update repositories (#2040)

This commit is contained in:
Chris Miles
2022-03-11 15:27:36 -08:00
committed by GitHub
parent f22608a43a
commit 3ed6663c4c
170 changed files with 5543 additions and 511 deletions
@@ -14,6 +14,7 @@
#include "../../database.h"
#include "../../string_util.h"
#include <ctime>
class BaseExpeditionLockoutsRepository {
public:
@@ -21,7 +22,7 @@ public:
int id;
int expedition_id;
std::string event_name;
std::string expire_time;
time_t expire_time;
int duration;
std::string from_expedition_uuid;
};
@@ -43,11 +44,28 @@ public:
};
}
static std::vector<std::string> SelectColumns()
{
return {
"id",
"expedition_id",
"event_name",
"UNIX_TIMESTAMP(expire_time)",
"duration",
"from_expedition_uuid",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string SelectColumnsRaw()
{
return std::string(implode(", ", SelectColumns()));
}
static std::string TableName()
{
return std::string("expedition_lockouts");
@@ -57,7 +75,7 @@ public:
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
SelectColumnsRaw(),
TableName()
);
}
@@ -78,7 +96,7 @@ public:
entry.id = 0;
entry.expedition_id = 0;
entry.event_name = "";
entry.expire_time = "";
entry.expire_time = std::time(nullptr);
entry.duration = 0;
entry.from_expedition_uuid = "";
@@ -119,7 +137,7 @@ public:
entry.id = atoi(row[0]);
entry.expedition_id = atoi(row[1]);
entry.event_name = row[2] ? row[2] : "";
entry.expire_time = row[3] ? row[3] : "";
entry.expire_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10);
entry.duration = atoi(row[4]);
entry.from_expedition_uuid = row[5] ? row[5] : "";
@@ -157,7 +175,7 @@ public:
update_values.push_back(columns[1] + " = " + std::to_string(expedition_lockouts_entry.expedition_id));
update_values.push_back(columns[2] + " = '" + EscapeString(expedition_lockouts_entry.event_name) + "'");
update_values.push_back(columns[3] + " = '" + EscapeString(expedition_lockouts_entry.expire_time) + "'");
update_values.push_back(columns[3] + " = FROM_UNIXTIME(" + (expedition_lockouts_entry.expire_time > 0 ? std::to_string(expedition_lockouts_entry.expire_time) : "null") + ")");
update_values.push_back(columns[4] + " = " + std::to_string(expedition_lockouts_entry.duration));
update_values.push_back(columns[5] + " = '" + EscapeString(expedition_lockouts_entry.from_expedition_uuid) + "'");
@@ -184,7 +202,7 @@ public:
insert_values.push_back(std::to_string(expedition_lockouts_entry.id));
insert_values.push_back(std::to_string(expedition_lockouts_entry.expedition_id));
insert_values.push_back("'" + EscapeString(expedition_lockouts_entry.event_name) + "'");
insert_values.push_back("'" + EscapeString(expedition_lockouts_entry.expire_time) + "'");
insert_values.push_back("FROM_UNIXTIME(" + (expedition_lockouts_entry.expire_time > 0 ? std::to_string(expedition_lockouts_entry.expire_time) : "null") + ")");
insert_values.push_back(std::to_string(expedition_lockouts_entry.duration));
insert_values.push_back("'" + EscapeString(expedition_lockouts_entry.from_expedition_uuid) + "'");
@@ -219,7 +237,7 @@ public:
insert_values.push_back(std::to_string(expedition_lockouts_entry.id));
insert_values.push_back(std::to_string(expedition_lockouts_entry.expedition_id));
insert_values.push_back("'" + EscapeString(expedition_lockouts_entry.event_name) + "'");
insert_values.push_back("'" + EscapeString(expedition_lockouts_entry.expire_time) + "'");
insert_values.push_back("FROM_UNIXTIME(" + (expedition_lockouts_entry.expire_time > 0 ? std::to_string(expedition_lockouts_entry.expire_time) : "null") + ")");
insert_values.push_back(std::to_string(expedition_lockouts_entry.duration));
insert_values.push_back("'" + EscapeString(expedition_lockouts_entry.from_expedition_uuid) + "'");
@@ -258,7 +276,7 @@ public:
entry.id = atoi(row[0]);
entry.expedition_id = atoi(row[1]);
entry.event_name = row[2] ? row[2] : "";
entry.expire_time = row[3] ? row[3] : "";
entry.expire_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10);
entry.duration = atoi(row[4]);
entry.from_expedition_uuid = row[5] ? row[5] : "";
@@ -288,7 +306,7 @@ public:
entry.id = atoi(row[0]);
entry.expedition_id = atoi(row[1]);
entry.event_name = row[2] ? row[2] : "";
entry.expire_time = row[3] ? row[3] : "";
entry.expire_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10);
entry.duration = atoi(row[4]);
entry.from_expedition_uuid = row[5] ? row[5] : "";