[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
+129 -103
View File
@@ -106,24 +106,24 @@ public:
static Fishing NewEntity()
{
Fishing entry{};
Fishing e{};
entry.id = 0;
entry.zoneid = 0;
entry.Itemid = 0;
entry.skill_level = 0;
entry.chance = 0;
entry.npc_id = 0;
entry.npc_chance = 0;
entry.min_expansion = -1;
entry.max_expansion = -1;
entry.content_flags = "";
entry.content_flags_disabled = "";
e.id = 0;
e.zoneid = 0;
e.Itemid = 0;
e.skill_level = 0;
e.chance = 0;
e.npc_id = 0;
e.npc_chance = 0;
e.min_expansion = -1;
e.max_expansion = -1;
e.content_flags = "";
e.content_flags_disabled = "";
return entry;
return e;
}
static Fishing GetFishingEntry(
static Fishing GetFishing(
const std::vector<Fishing> &fishings,
int fishing_id
)
@@ -152,21 +152,21 @@ public:
auto row = results.begin();
if (results.RowCount() == 1) {
Fishing entry{};
Fishing e{};
entry.id = atoi(row[0]);
entry.zoneid = atoi(row[1]);
entry.Itemid = atoi(row[2]);
entry.skill_level = atoi(row[3]);
entry.chance = atoi(row[4]);
entry.npc_id = atoi(row[5]);
entry.npc_chance = atoi(row[6]);
entry.min_expansion = atoi(row[7]);
entry.max_expansion = atoi(row[8]);
entry.content_flags = row[9] ? row[9] : "";
entry.content_flags_disabled = row[10] ? row[10] : "";
e.id = atoi(row[0]);
e.zoneid = atoi(row[1]);
e.Itemid = atoi(row[2]);
e.skill_level = atoi(row[3]);
e.chance = atoi(row[4]);
e.npc_id = atoi(row[5]);
e.npc_chance = atoi(row[6]);
e.min_expansion = atoi(row[7]);
e.max_expansion = atoi(row[8]);
e.content_flags = row[9] ? row[9] : "";
e.content_flags_disabled = row[10] ? row[10] : "";
return entry;
return e;
}
return NewEntity();
@@ -191,31 +191,31 @@ public:
static int UpdateOne(
Database& db,
Fishing fishing_entry
const Fishing &e
)
{
std::vector<std::string> update_values;
std::vector<std::string> v;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(fishing_entry.zoneid));
update_values.push_back(columns[2] + " = " + std::to_string(fishing_entry.Itemid));
update_values.push_back(columns[3] + " = " + std::to_string(fishing_entry.skill_level));
update_values.push_back(columns[4] + " = " + std::to_string(fishing_entry.chance));
update_values.push_back(columns[5] + " = " + std::to_string(fishing_entry.npc_id));
update_values.push_back(columns[6] + " = " + std::to_string(fishing_entry.npc_chance));
update_values.push_back(columns[7] + " = " + std::to_string(fishing_entry.min_expansion));
update_values.push_back(columns[8] + " = " + std::to_string(fishing_entry.max_expansion));
update_values.push_back(columns[9] + " = '" + Strings::Escape(fishing_entry.content_flags) + "'");
update_values.push_back(columns[10] + " = '" + Strings::Escape(fishing_entry.content_flags_disabled) + "'");
v.push_back(columns[1] + " = " + std::to_string(e.zoneid));
v.push_back(columns[2] + " = " + std::to_string(e.Itemid));
v.push_back(columns[3] + " = " + std::to_string(e.skill_level));
v.push_back(columns[4] + " = " + std::to_string(e.chance));
v.push_back(columns[5] + " = " + std::to_string(e.npc_id));
v.push_back(columns[6] + " = " + std::to_string(e.npc_chance));
v.push_back(columns[7] + " = " + std::to_string(e.min_expansion));
v.push_back(columns[8] + " = " + std::to_string(e.max_expansion));
v.push_back(columns[9] + " = '" + Strings::Escape(e.content_flags) + "'");
v.push_back(columns[10] + " = '" + Strings::Escape(e.content_flags_disabled) + "'");
auto results = db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
Strings::Implode(", ", update_values),
Strings::Implode(", ", v),
PrimaryKey(),
fishing_entry.id
e.id
)
);
@@ -224,67 +224,67 @@ public:
static Fishing InsertOne(
Database& db,
Fishing fishing_entry
Fishing e
)
{
std::vector<std::string> insert_values;
std::vector<std::string> v;
insert_values.push_back(std::to_string(fishing_entry.id));
insert_values.push_back(std::to_string(fishing_entry.zoneid));
insert_values.push_back(std::to_string(fishing_entry.Itemid));
insert_values.push_back(std::to_string(fishing_entry.skill_level));
insert_values.push_back(std::to_string(fishing_entry.chance));
insert_values.push_back(std::to_string(fishing_entry.npc_id));
insert_values.push_back(std::to_string(fishing_entry.npc_chance));
insert_values.push_back(std::to_string(fishing_entry.min_expansion));
insert_values.push_back(std::to_string(fishing_entry.max_expansion));
insert_values.push_back("'" + Strings::Escape(fishing_entry.content_flags) + "'");
insert_values.push_back("'" + Strings::Escape(fishing_entry.content_flags_disabled) + "'");
v.push_back(std::to_string(e.id));
v.push_back(std::to_string(e.zoneid));
v.push_back(std::to_string(e.Itemid));
v.push_back(std::to_string(e.skill_level));
v.push_back(std::to_string(e.chance));
v.push_back(std::to_string(e.npc_id));
v.push_back(std::to_string(e.npc_chance));
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()) {
fishing_entry.id = results.LastInsertedID();
return fishing_entry;
e.id = results.LastInsertedID();
return e;
}
fishing_entry = NewEntity();
e = NewEntity();
return fishing_entry;
return e;
}
static int InsertMany(
Database& db,
std::vector<Fishing> fishing_entries
const std::vector<Fishing> &entries
)
{
std::vector<std::string> insert_chunks;
for (auto &fishing_entry: fishing_entries) {
std::vector<std::string> insert_values;
for (auto &e: entries) {
std::vector<std::string> v;
insert_values.push_back(std::to_string(fishing_entry.id));
insert_values.push_back(std::to_string(fishing_entry.zoneid));
insert_values.push_back(std::to_string(fishing_entry.Itemid));
insert_values.push_back(std::to_string(fishing_entry.skill_level));
insert_values.push_back(std::to_string(fishing_entry.chance));
insert_values.push_back(std::to_string(fishing_entry.npc_id));
insert_values.push_back(std::to_string(fishing_entry.npc_chance));
insert_values.push_back(std::to_string(fishing_entry.min_expansion));
insert_values.push_back(std::to_string(fishing_entry.max_expansion));
insert_values.push_back("'" + Strings::Escape(fishing_entry.content_flags) + "'");
insert_values.push_back("'" + Strings::Escape(fishing_entry.content_flags_disabled) + "'");
v.push_back(std::to_string(e.id));
v.push_back(std::to_string(e.zoneid));
v.push_back(std::to_string(e.Itemid));
v.push_back(std::to_string(e.skill_level));
v.push_back(std::to_string(e.chance));
v.push_back(std::to_string(e.npc_id));
v.push_back(std::to_string(e.npc_chance));
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(
@@ -311,27 +311,27 @@ public:
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Fishing entry{};
Fishing e{};
entry.id = atoi(row[0]);
entry.zoneid = atoi(row[1]);
entry.Itemid = atoi(row[2]);
entry.skill_level = atoi(row[3]);
entry.chance = atoi(row[4]);
entry.npc_id = atoi(row[5]);
entry.npc_chance = atoi(row[6]);
entry.min_expansion = atoi(row[7]);
entry.max_expansion = atoi(row[8]);
entry.content_flags = row[9] ? row[9] : "";
entry.content_flags_disabled = row[10] ? row[10] : "";
e.id = atoi(row[0]);
e.zoneid = atoi(row[1]);
e.Itemid = atoi(row[2]);
e.skill_level = atoi(row[3]);
e.chance = atoi(row[4]);
e.npc_id = atoi(row[5]);
e.npc_chance = atoi(row[6]);
e.min_expansion = atoi(row[7]);
e.max_expansion = atoi(row[8]);
e.content_flags = row[9] ? row[9] : "";
e.content_flags_disabled = row[10] ? row[10] : "";
all_entries.push_back(entry);
all_entries.push_back(e);
}
return all_entries;
}
static std::vector<Fishing> GetWhere(Database& db, std::string where_filter)
static std::vector<Fishing> GetWhere(Database& db, const std::string &where_filter)
{
std::vector<Fishing> all_entries;
@@ -346,27 +346,27 @@ public:
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Fishing entry{};
Fishing e{};
entry.id = atoi(row[0]);
entry.zoneid = atoi(row[1]);
entry.Itemid = atoi(row[2]);
entry.skill_level = atoi(row[3]);
entry.chance = atoi(row[4]);
entry.npc_id = atoi(row[5]);
entry.npc_chance = atoi(row[6]);
entry.min_expansion = atoi(row[7]);
entry.max_expansion = atoi(row[8]);
entry.content_flags = row[9] ? row[9] : "";
entry.content_flags_disabled = row[10] ? row[10] : "";
e.id = atoi(row[0]);
e.zoneid = atoi(row[1]);
e.Itemid = atoi(row[2]);
e.skill_level = atoi(row[3]);
e.chance = atoi(row[4]);
e.npc_id = atoi(row[5]);
e.npc_chance = atoi(row[6]);
e.min_expansion = atoi(row[7]);
e.max_expansion = atoi(row[8]);
e.content_flags = row[9] ? row[9] : "";
e.content_flags_disabled = row[10] ? row[10] : "";
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(
@@ -391,6 +391,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_FISHING_REPOSITORY_H