mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-31 09:06:46 +00:00
[Repositories] Add GetMaxId, Count (#2371)
* [Repositories] Add GetMaxId, Count * Update cmake with repositories, regenerate extended repos * Remove license from files * Simplify receivers * Receiver simplify remaining * Simplify receivers final * Pass params by const reference * Modernize grid tables * Remove guild members since it doesn't conform as a generatable table * PR comment
This commit is contained in:
@@ -115,27 +115,27 @@ public:
|
||||
|
||||
static SpawnEvents NewEntity()
|
||||
{
|
||||
SpawnEvents entry{};
|
||||
SpawnEvents e{};
|
||||
|
||||
entry.id = 0;
|
||||
entry.zone = "";
|
||||
entry.cond_id = 0;
|
||||
entry.name = "";
|
||||
entry.period = 0;
|
||||
entry.next_minute = 0;
|
||||
entry.next_hour = 0;
|
||||
entry.next_day = 0;
|
||||
entry.next_month = 0;
|
||||
entry.next_year = 0;
|
||||
entry.enabled = 1;
|
||||
entry.action = 0;
|
||||
entry.argument = 0;
|
||||
entry.strict = 0;
|
||||
e.id = 0;
|
||||
e.zone = "";
|
||||
e.cond_id = 0;
|
||||
e.name = "";
|
||||
e.period = 0;
|
||||
e.next_minute = 0;
|
||||
e.next_hour = 0;
|
||||
e.next_day = 0;
|
||||
e.next_month = 0;
|
||||
e.next_year = 0;
|
||||
e.enabled = 1;
|
||||
e.action = 0;
|
||||
e.argument = 0;
|
||||
e.strict = 0;
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static SpawnEvents GetSpawnEventsEntry(
|
||||
static SpawnEvents GetSpawnEvents(
|
||||
const std::vector<SpawnEvents> &spawn_eventss,
|
||||
int spawn_events_id
|
||||
)
|
||||
@@ -164,24 +164,24 @@ public:
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
SpawnEvents entry{};
|
||||
SpawnEvents e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.zone = row[1] ? row[1] : "";
|
||||
entry.cond_id = atoi(row[2]);
|
||||
entry.name = row[3] ? row[3] : "";
|
||||
entry.period = atoi(row[4]);
|
||||
entry.next_minute = atoi(row[5]);
|
||||
entry.next_hour = atoi(row[6]);
|
||||
entry.next_day = atoi(row[7]);
|
||||
entry.next_month = atoi(row[8]);
|
||||
entry.next_year = atoi(row[9]);
|
||||
entry.enabled = atoi(row[10]);
|
||||
entry.action = atoi(row[11]);
|
||||
entry.argument = atoi(row[12]);
|
||||
entry.strict = atoi(row[13]);
|
||||
e.id = atoi(row[0]);
|
||||
e.zone = row[1] ? row[1] : "";
|
||||
e.cond_id = atoi(row[2]);
|
||||
e.name = row[3] ? row[3] : "";
|
||||
e.period = atoi(row[4]);
|
||||
e.next_minute = atoi(row[5]);
|
||||
e.next_hour = atoi(row[6]);
|
||||
e.next_day = atoi(row[7]);
|
||||
e.next_month = atoi(row[8]);
|
||||
e.next_year = atoi(row[9]);
|
||||
e.enabled = atoi(row[10]);
|
||||
e.action = atoi(row[11]);
|
||||
e.argument = atoi(row[12]);
|
||||
e.strict = atoi(row[13]);
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
@@ -206,34 +206,34 @@ public:
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
SpawnEvents spawn_events_entry
|
||||
const SpawnEvents &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> update_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
update_values.push_back(columns[1] + " = '" + Strings::Escape(spawn_events_entry.zone) + "'");
|
||||
update_values.push_back(columns[2] + " = " + std::to_string(spawn_events_entry.cond_id));
|
||||
update_values.push_back(columns[3] + " = '" + Strings::Escape(spawn_events_entry.name) + "'");
|
||||
update_values.push_back(columns[4] + " = " + std::to_string(spawn_events_entry.period));
|
||||
update_values.push_back(columns[5] + " = " + std::to_string(spawn_events_entry.next_minute));
|
||||
update_values.push_back(columns[6] + " = " + std::to_string(spawn_events_entry.next_hour));
|
||||
update_values.push_back(columns[7] + " = " + std::to_string(spawn_events_entry.next_day));
|
||||
update_values.push_back(columns[8] + " = " + std::to_string(spawn_events_entry.next_month));
|
||||
update_values.push_back(columns[9] + " = " + std::to_string(spawn_events_entry.next_year));
|
||||
update_values.push_back(columns[10] + " = " + std::to_string(spawn_events_entry.enabled));
|
||||
update_values.push_back(columns[11] + " = " + std::to_string(spawn_events_entry.action));
|
||||
update_values.push_back(columns[12] + " = " + std::to_string(spawn_events_entry.argument));
|
||||
update_values.push_back(columns[13] + " = " + std::to_string(spawn_events_entry.strict));
|
||||
v.push_back(columns[1] + " = '" + Strings::Escape(e.zone) + "'");
|
||||
v.push_back(columns[2] + " = " + std::to_string(e.cond_id));
|
||||
v.push_back(columns[3] + " = '" + Strings::Escape(e.name) + "'");
|
||||
v.push_back(columns[4] + " = " + std::to_string(e.period));
|
||||
v.push_back(columns[5] + " = " + std::to_string(e.next_minute));
|
||||
v.push_back(columns[6] + " = " + std::to_string(e.next_hour));
|
||||
v.push_back(columns[7] + " = " + std::to_string(e.next_day));
|
||||
v.push_back(columns[8] + " = " + std::to_string(e.next_month));
|
||||
v.push_back(columns[9] + " = " + std::to_string(e.next_year));
|
||||
v.push_back(columns[10] + " = " + std::to_string(e.enabled));
|
||||
v.push_back(columns[11] + " = " + std::to_string(e.action));
|
||||
v.push_back(columns[12] + " = " + std::to_string(e.argument));
|
||||
v.push_back(columns[13] + " = " + std::to_string(e.strict));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", update_values),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
spawn_events_entry.id
|
||||
e.id
|
||||
)
|
||||
);
|
||||
|
||||
@@ -242,73 +242,73 @@ public:
|
||||
|
||||
static SpawnEvents InsertOne(
|
||||
Database& db,
|
||||
SpawnEvents spawn_events_entry
|
||||
SpawnEvents e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.id));
|
||||
insert_values.push_back("'" + Strings::Escape(spawn_events_entry.zone) + "'");
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.cond_id));
|
||||
insert_values.push_back("'" + Strings::Escape(spawn_events_entry.name) + "'");
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.period));
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.next_minute));
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.next_hour));
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.next_day));
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.next_month));
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.next_year));
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.enabled));
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.action));
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.argument));
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.strict));
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back("'" + Strings::Escape(e.zone) + "'");
|
||||
v.push_back(std::to_string(e.cond_id));
|
||||
v.push_back("'" + Strings::Escape(e.name) + "'");
|
||||
v.push_back(std::to_string(e.period));
|
||||
v.push_back(std::to_string(e.next_minute));
|
||||
v.push_back(std::to_string(e.next_hour));
|
||||
v.push_back(std::to_string(e.next_day));
|
||||
v.push_back(std::to_string(e.next_month));
|
||||
v.push_back(std::to_string(e.next_year));
|
||||
v.push_back(std::to_string(e.enabled));
|
||||
v.push_back(std::to_string(e.action));
|
||||
v.push_back(std::to_string(e.argument));
|
||||
v.push_back(std::to_string(e.strict));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseInsert(),
|
||||
Strings::Implode(",", insert_values)
|
||||
Strings::Implode(",", v)
|
||||
)
|
||||
);
|
||||
|
||||
if (results.Success()) {
|
||||
spawn_events_entry.id = results.LastInsertedID();
|
||||
return spawn_events_entry;
|
||||
e.id = results.LastInsertedID();
|
||||
return e;
|
||||
}
|
||||
|
||||
spawn_events_entry = NewEntity();
|
||||
e = NewEntity();
|
||||
|
||||
return spawn_events_entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
Database& db,
|
||||
std::vector<SpawnEvents> spawn_events_entries
|
||||
const std::vector<SpawnEvents> &entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &spawn_events_entry: spawn_events_entries) {
|
||||
std::vector<std::string> insert_values;
|
||||
for (auto &e: entries) {
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.id));
|
||||
insert_values.push_back("'" + Strings::Escape(spawn_events_entry.zone) + "'");
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.cond_id));
|
||||
insert_values.push_back("'" + Strings::Escape(spawn_events_entry.name) + "'");
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.period));
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.next_minute));
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.next_hour));
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.next_day));
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.next_month));
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.next_year));
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.enabled));
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.action));
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.argument));
|
||||
insert_values.push_back(std::to_string(spawn_events_entry.strict));
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back("'" + Strings::Escape(e.zone) + "'");
|
||||
v.push_back(std::to_string(e.cond_id));
|
||||
v.push_back("'" + Strings::Escape(e.name) + "'");
|
||||
v.push_back(std::to_string(e.period));
|
||||
v.push_back(std::to_string(e.next_minute));
|
||||
v.push_back(std::to_string(e.next_hour));
|
||||
v.push_back(std::to_string(e.next_day));
|
||||
v.push_back(std::to_string(e.next_month));
|
||||
v.push_back(std::to_string(e.next_year));
|
||||
v.push_back(std::to_string(e.enabled));
|
||||
v.push_back(std::to_string(e.action));
|
||||
v.push_back(std::to_string(e.argument));
|
||||
v.push_back(std::to_string(e.strict));
|
||||
|
||||
insert_chunks.push_back("(" + Strings::Implode(",", insert_values) + ")");
|
||||
insert_chunks.push_back("(" + Strings::Implode(",", v) + ")");
|
||||
}
|
||||
|
||||
std::vector<std::string> insert_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
@@ -335,30 +335,30 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
SpawnEvents entry{};
|
||||
SpawnEvents e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.zone = row[1] ? row[1] : "";
|
||||
entry.cond_id = atoi(row[2]);
|
||||
entry.name = row[3] ? row[3] : "";
|
||||
entry.period = atoi(row[4]);
|
||||
entry.next_minute = atoi(row[5]);
|
||||
entry.next_hour = atoi(row[6]);
|
||||
entry.next_day = atoi(row[7]);
|
||||
entry.next_month = atoi(row[8]);
|
||||
entry.next_year = atoi(row[9]);
|
||||
entry.enabled = atoi(row[10]);
|
||||
entry.action = atoi(row[11]);
|
||||
entry.argument = atoi(row[12]);
|
||||
entry.strict = atoi(row[13]);
|
||||
e.id = atoi(row[0]);
|
||||
e.zone = row[1] ? row[1] : "";
|
||||
e.cond_id = atoi(row[2]);
|
||||
e.name = row[3] ? row[3] : "";
|
||||
e.period = atoi(row[4]);
|
||||
e.next_minute = atoi(row[5]);
|
||||
e.next_hour = atoi(row[6]);
|
||||
e.next_day = atoi(row[7]);
|
||||
e.next_month = atoi(row[8]);
|
||||
e.next_year = atoi(row[9]);
|
||||
e.enabled = atoi(row[10]);
|
||||
e.action = atoi(row[11]);
|
||||
e.argument = atoi(row[12]);
|
||||
e.strict = atoi(row[13]);
|
||||
|
||||
all_entries.push_back(entry);
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<SpawnEvents> GetWhere(Database& db, std::string where_filter)
|
||||
static std::vector<SpawnEvents> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<SpawnEvents> all_entries;
|
||||
|
||||
@@ -373,30 +373,30 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
SpawnEvents entry{};
|
||||
SpawnEvents e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.zone = row[1] ? row[1] : "";
|
||||
entry.cond_id = atoi(row[2]);
|
||||
entry.name = row[3] ? row[3] : "";
|
||||
entry.period = atoi(row[4]);
|
||||
entry.next_minute = atoi(row[5]);
|
||||
entry.next_hour = atoi(row[6]);
|
||||
entry.next_day = atoi(row[7]);
|
||||
entry.next_month = atoi(row[8]);
|
||||
entry.next_year = atoi(row[9]);
|
||||
entry.enabled = atoi(row[10]);
|
||||
entry.action = atoi(row[11]);
|
||||
entry.argument = atoi(row[12]);
|
||||
entry.strict = atoi(row[13]);
|
||||
e.id = atoi(row[0]);
|
||||
e.zone = row[1] ? row[1] : "";
|
||||
e.cond_id = atoi(row[2]);
|
||||
e.name = row[3] ? row[3] : "";
|
||||
e.period = atoi(row[4]);
|
||||
e.next_minute = atoi(row[5]);
|
||||
e.next_hour = atoi(row[6]);
|
||||
e.next_day = atoi(row[7]);
|
||||
e.next_month = atoi(row[8]);
|
||||
e.next_year = atoi(row[9]);
|
||||
e.enabled = atoi(row[10]);
|
||||
e.action = atoi(row[11]);
|
||||
e.argument = atoi(row[12]);
|
||||
e.strict = atoi(row[13]);
|
||||
|
||||
all_entries.push_back(entry);
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static int DeleteWhere(Database& db, std::string where_filter)
|
||||
static int DeleteWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
@@ -421,6 +421,32 @@ public:
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static int64 GetMaxId(Database& db)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"SELECT COALESCE(MAX({}), 0) FROM {}",
|
||||
PrimaryKey(),
|
||||
TableName()
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0);
|
||||
}
|
||||
|
||||
static int64 Count(Database& db, const std::string &where_filter = "")
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"SELECT COUNT(*) FROM {} {}",
|
||||
TableName(),
|
||||
(where_filter.empty() ? "" : "WHERE " + where_filter)
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //EQEMU_BASE_SPAWN_EVENTS_REPOSITORY_H
|
||||
|
||||
Reference in New Issue
Block a user