[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:
Chris Miles
2022-08-13 18:40:56 -05:00
committed by GitHub
parent b79e1947f1
commit 79285b1002
374 changed files with 26837 additions and 26020 deletions
@@ -97,21 +97,21 @@ public:
static Spawnentry NewEntity()
{
Spawnentry entry{};
Spawnentry e{};
entry.spawngroupID = 0;
entry.npcID = 0;
entry.chance = 0;
entry.condition_value_filter = 1;
entry.min_expansion = -1;
entry.max_expansion = -1;
entry.content_flags = "";
entry.content_flags_disabled = "";
e.spawngroupID = 0;
e.npcID = 0;
e.chance = 0;
e.condition_value_filter = 1;
e.min_expansion = -1;
e.max_expansion = -1;
e.content_flags = "";
e.content_flags_disabled = "";
return entry;
return e;
}
static Spawnentry GetSpawnentryEntry(
static Spawnentry GetSpawnentry(
const std::vector<Spawnentry> &spawnentrys,
int spawnentry_id
)
@@ -140,18 +140,18 @@ public:
auto row = results.begin();
if (results.RowCount() == 1) {
Spawnentry entry{};
Spawnentry e{};
entry.spawngroupID = atoi(row[0]);
entry.npcID = atoi(row[1]);
entry.chance = atoi(row[2]);
entry.condition_value_filter = atoi(row[3]);
entry.min_expansion = atoi(row[4]);
entry.max_expansion = atoi(row[5]);
entry.content_flags = row[6] ? row[6] : "";
entry.content_flags_disabled = row[7] ? row[7] : "";
e.spawngroupID = atoi(row[0]);
e.npcID = atoi(row[1]);
e.chance = atoi(row[2]);
e.condition_value_filter = atoi(row[3]);
e.min_expansion = atoi(row[4]);
e.max_expansion = atoi(row[5]);
e.content_flags = row[6] ? row[6] : "";
e.content_flags_disabled = row[7] ? row[7] : "";
return entry;
return e;
}
return NewEntity();
@@ -176,29 +176,29 @@ public:
static int UpdateOne(
Database& db,
Spawnentry spawnentry_entry
const Spawnentry &e
)
{
std::vector<std::string> update_values;
std::vector<std::string> v;
auto columns = Columns();
update_values.push_back(columns[0] + " = " + std::to_string(spawnentry_entry.spawngroupID));
update_values.push_back(columns[1] + " = " + std::to_string(spawnentry_entry.npcID));
update_values.push_back(columns[2] + " = " + std::to_string(spawnentry_entry.chance));
update_values.push_back(columns[3] + " = " + std::to_string(spawnentry_entry.condition_value_filter));
update_values.push_back(columns[4] + " = " + std::to_string(spawnentry_entry.min_expansion));
update_values.push_back(columns[5] + " = " + std::to_string(spawnentry_entry.max_expansion));
update_values.push_back(columns[6] + " = '" + Strings::Escape(spawnentry_entry.content_flags) + "'");
update_values.push_back(columns[7] + " = '" + Strings::Escape(spawnentry_entry.content_flags_disabled) + "'");
v.push_back(columns[0] + " = " + std::to_string(e.spawngroupID));
v.push_back(columns[1] + " = " + std::to_string(e.npcID));
v.push_back(columns[2] + " = " + std::to_string(e.chance));
v.push_back(columns[3] + " = " + std::to_string(e.condition_value_filter));
v.push_back(columns[4] + " = " + std::to_string(e.min_expansion));
v.push_back(columns[5] + " = " + std::to_string(e.max_expansion));
v.push_back(columns[6] + " = '" + Strings::Escape(e.content_flags) + "'");
v.push_back(columns[7] + " = '" + Strings::Escape(e.content_flags_disabled) + "'");
auto results = db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
Strings::Implode(", ", update_values),
Strings::Implode(", ", v),
PrimaryKey(),
spawnentry_entry.spawngroupID
e.spawngroupID
)
);
@@ -207,61 +207,61 @@ public:
static Spawnentry InsertOne(
Database& db,
Spawnentry spawnentry_entry
Spawnentry e
)
{
std::vector<std::string> insert_values;
std::vector<std::string> v;
insert_values.push_back(std::to_string(spawnentry_entry.spawngroupID));
insert_values.push_back(std::to_string(spawnentry_entry.npcID));
insert_values.push_back(std::to_string(spawnentry_entry.chance));
insert_values.push_back(std::to_string(spawnentry_entry.condition_value_filter));
insert_values.push_back(std::to_string(spawnentry_entry.min_expansion));
insert_values.push_back(std::to_string(spawnentry_entry.max_expansion));
insert_values.push_back("'" + Strings::Escape(spawnentry_entry.content_flags) + "'");
insert_values.push_back("'" + Strings::Escape(spawnentry_entry.content_flags_disabled) + "'");
v.push_back(std::to_string(e.spawngroupID));
v.push_back(std::to_string(e.npcID));
v.push_back(std::to_string(e.chance));
v.push_back(std::to_string(e.condition_value_filter));
v.push_back(std::to_string(e.min_expansion));
v.push_back(std::to_string(e.max_expansion));
v.push_back("'" + Strings::Escape(e.content_flags) + "'");
v.push_back("'" + Strings::Escape(e.content_flags_disabled) + "'");
auto results = db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
Strings::Implode(",", insert_values)
Strings::Implode(",", v)
)
);
if (results.Success()) {
spawnentry_entry.spawngroupID = results.LastInsertedID();
return spawnentry_entry;
e.spawngroupID = results.LastInsertedID();
return e;
}
spawnentry_entry = NewEntity();
e = NewEntity();
return spawnentry_entry;
return e;
}
static int InsertMany(
Database& db,
std::vector<Spawnentry> spawnentry_entries
const std::vector<Spawnentry> &entries
)
{
std::vector<std::string> insert_chunks;
for (auto &spawnentry_entry: spawnentry_entries) {
std::vector<std::string> insert_values;
for (auto &e: entries) {
std::vector<std::string> v;
insert_values.push_back(std::to_string(spawnentry_entry.spawngroupID));
insert_values.push_back(std::to_string(spawnentry_entry.npcID));
insert_values.push_back(std::to_string(spawnentry_entry.chance));
insert_values.push_back(std::to_string(spawnentry_entry.condition_value_filter));
insert_values.push_back(std::to_string(spawnentry_entry.min_expansion));
insert_values.push_back(std::to_string(spawnentry_entry.max_expansion));
insert_values.push_back("'" + Strings::Escape(spawnentry_entry.content_flags) + "'");
insert_values.push_back("'" + Strings::Escape(spawnentry_entry.content_flags_disabled) + "'");
v.push_back(std::to_string(e.spawngroupID));
v.push_back(std::to_string(e.npcID));
v.push_back(std::to_string(e.chance));
v.push_back(std::to_string(e.condition_value_filter));
v.push_back(std::to_string(e.min_expansion));
v.push_back(std::to_string(e.max_expansion));
v.push_back("'" + Strings::Escape(e.content_flags) + "'");
v.push_back("'" + Strings::Escape(e.content_flags_disabled) + "'");
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(
@@ -288,24 +288,24 @@ public:
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Spawnentry entry{};
Spawnentry e{};
entry.spawngroupID = atoi(row[0]);
entry.npcID = atoi(row[1]);
entry.chance = atoi(row[2]);
entry.condition_value_filter = atoi(row[3]);
entry.min_expansion = atoi(row[4]);
entry.max_expansion = atoi(row[5]);
entry.content_flags = row[6] ? row[6] : "";
entry.content_flags_disabled = row[7] ? row[7] : "";
e.spawngroupID = atoi(row[0]);
e.npcID = atoi(row[1]);
e.chance = atoi(row[2]);
e.condition_value_filter = atoi(row[3]);
e.min_expansion = atoi(row[4]);
e.max_expansion = atoi(row[5]);
e.content_flags = row[6] ? row[6] : "";
e.content_flags_disabled = row[7] ? row[7] : "";
all_entries.push_back(entry);
all_entries.push_back(e);
}
return all_entries;
}
static std::vector<Spawnentry> GetWhere(Database& db, std::string where_filter)
static std::vector<Spawnentry> GetWhere(Database& db, const std::string &where_filter)
{
std::vector<Spawnentry> all_entries;
@@ -320,24 +320,24 @@ public:
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Spawnentry entry{};
Spawnentry e{};
entry.spawngroupID = atoi(row[0]);
entry.npcID = atoi(row[1]);
entry.chance = atoi(row[2]);
entry.condition_value_filter = atoi(row[3]);
entry.min_expansion = atoi(row[4]);
entry.max_expansion = atoi(row[5]);
entry.content_flags = row[6] ? row[6] : "";
entry.content_flags_disabled = row[7] ? row[7] : "";
e.spawngroupID = atoi(row[0]);
e.npcID = atoi(row[1]);
e.chance = atoi(row[2]);
e.condition_value_filter = atoi(row[3]);
e.min_expansion = atoi(row[4]);
e.max_expansion = atoi(row[5]);
e.content_flags = row[6] ? row[6] : "";
e.content_flags_disabled = row[7] ? row[7] : "";
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(
@@ -362,6 +362,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_SPAWNENTRY_REPOSITORY_H