mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-31 13:16:39 +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:
@@ -100,22 +100,22 @@ public:
|
||||
|
||||
static Forage NewEntity()
|
||||
{
|
||||
Forage entry{};
|
||||
Forage e{};
|
||||
|
||||
entry.id = 0;
|
||||
entry.zoneid = 0;
|
||||
entry.Itemid = 0;
|
||||
entry.level = 0;
|
||||
entry.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.level = 0;
|
||||
e.chance = 0;
|
||||
e.min_expansion = -1;
|
||||
e.max_expansion = -1;
|
||||
e.content_flags = "";
|
||||
e.content_flags_disabled = "";
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static Forage GetForageEntry(
|
||||
static Forage GetForage(
|
||||
const std::vector<Forage> &forages,
|
||||
int forage_id
|
||||
)
|
||||
@@ -144,19 +144,19 @@ public:
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
Forage entry{};
|
||||
Forage e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.zoneid = atoi(row[1]);
|
||||
entry.Itemid = atoi(row[2]);
|
||||
entry.level = atoi(row[3]);
|
||||
entry.chance = atoi(row[4]);
|
||||
entry.min_expansion = atoi(row[5]);
|
||||
entry.max_expansion = atoi(row[6]);
|
||||
entry.content_flags = row[7] ? row[7] : "";
|
||||
entry.content_flags_disabled = row[8] ? row[8] : "";
|
||||
e.id = atoi(row[0]);
|
||||
e.zoneid = atoi(row[1]);
|
||||
e.Itemid = atoi(row[2]);
|
||||
e.level = atoi(row[3]);
|
||||
e.chance = atoi(row[4]);
|
||||
e.min_expansion = atoi(row[5]);
|
||||
e.max_expansion = atoi(row[6]);
|
||||
e.content_flags = row[7] ? row[7] : "";
|
||||
e.content_flags_disabled = row[8] ? row[8] : "";
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
@@ -181,29 +181,29 @@ public:
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
Forage forage_entry
|
||||
const Forage &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> update_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
update_values.push_back(columns[1] + " = " + std::to_string(forage_entry.zoneid));
|
||||
update_values.push_back(columns[2] + " = " + std::to_string(forage_entry.Itemid));
|
||||
update_values.push_back(columns[3] + " = " + std::to_string(forage_entry.level));
|
||||
update_values.push_back(columns[4] + " = " + std::to_string(forage_entry.chance));
|
||||
update_values.push_back(columns[5] + " = " + std::to_string(forage_entry.min_expansion));
|
||||
update_values.push_back(columns[6] + " = " + std::to_string(forage_entry.max_expansion));
|
||||
update_values.push_back(columns[7] + " = '" + Strings::Escape(forage_entry.content_flags) + "'");
|
||||
update_values.push_back(columns[8] + " = '" + Strings::Escape(forage_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.level));
|
||||
v.push_back(columns[4] + " = " + std::to_string(e.chance));
|
||||
v.push_back(columns[5] + " = " + std::to_string(e.min_expansion));
|
||||
v.push_back(columns[6] + " = " + std::to_string(e.max_expansion));
|
||||
v.push_back(columns[7] + " = '" + Strings::Escape(e.content_flags) + "'");
|
||||
v.push_back(columns[8] + " = '" + Strings::Escape(e.content_flags_disabled) + "'");
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", update_values),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
forage_entry.id
|
||||
e.id
|
||||
)
|
||||
);
|
||||
|
||||
@@ -212,63 +212,63 @@ public:
|
||||
|
||||
static Forage InsertOne(
|
||||
Database& db,
|
||||
Forage forage_entry
|
||||
Forage e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(forage_entry.id));
|
||||
insert_values.push_back(std::to_string(forage_entry.zoneid));
|
||||
insert_values.push_back(std::to_string(forage_entry.Itemid));
|
||||
insert_values.push_back(std::to_string(forage_entry.level));
|
||||
insert_values.push_back(std::to_string(forage_entry.chance));
|
||||
insert_values.push_back(std::to_string(forage_entry.min_expansion));
|
||||
insert_values.push_back(std::to_string(forage_entry.max_expansion));
|
||||
insert_values.push_back("'" + Strings::Escape(forage_entry.content_flags) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(forage_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.level));
|
||||
v.push_back(std::to_string(e.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()) {
|
||||
forage_entry.id = results.LastInsertedID();
|
||||
return forage_entry;
|
||||
e.id = results.LastInsertedID();
|
||||
return e;
|
||||
}
|
||||
|
||||
forage_entry = NewEntity();
|
||||
e = NewEntity();
|
||||
|
||||
return forage_entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
Database& db,
|
||||
std::vector<Forage> forage_entries
|
||||
const std::vector<Forage> &entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &forage_entry: forage_entries) {
|
||||
std::vector<std::string> insert_values;
|
||||
for (auto &e: entries) {
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(forage_entry.id));
|
||||
insert_values.push_back(std::to_string(forage_entry.zoneid));
|
||||
insert_values.push_back(std::to_string(forage_entry.Itemid));
|
||||
insert_values.push_back(std::to_string(forage_entry.level));
|
||||
insert_values.push_back(std::to_string(forage_entry.chance));
|
||||
insert_values.push_back(std::to_string(forage_entry.min_expansion));
|
||||
insert_values.push_back(std::to_string(forage_entry.max_expansion));
|
||||
insert_values.push_back("'" + Strings::Escape(forage_entry.content_flags) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(forage_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.level));
|
||||
v.push_back(std::to_string(e.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(
|
||||
@@ -295,25 +295,25 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
Forage entry{};
|
||||
Forage e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.zoneid = atoi(row[1]);
|
||||
entry.Itemid = atoi(row[2]);
|
||||
entry.level = atoi(row[3]);
|
||||
entry.chance = atoi(row[4]);
|
||||
entry.min_expansion = atoi(row[5]);
|
||||
entry.max_expansion = atoi(row[6]);
|
||||
entry.content_flags = row[7] ? row[7] : "";
|
||||
entry.content_flags_disabled = row[8] ? row[8] : "";
|
||||
e.id = atoi(row[0]);
|
||||
e.zoneid = atoi(row[1]);
|
||||
e.Itemid = atoi(row[2]);
|
||||
e.level = atoi(row[3]);
|
||||
e.chance = atoi(row[4]);
|
||||
e.min_expansion = atoi(row[5]);
|
||||
e.max_expansion = atoi(row[6]);
|
||||
e.content_flags = row[7] ? row[7] : "";
|
||||
e.content_flags_disabled = row[8] ? row[8] : "";
|
||||
|
||||
all_entries.push_back(entry);
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<Forage> GetWhere(Database& db, std::string where_filter)
|
||||
static std::vector<Forage> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<Forage> all_entries;
|
||||
|
||||
@@ -328,25 +328,25 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
Forage entry{};
|
||||
Forage e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.zoneid = atoi(row[1]);
|
||||
entry.Itemid = atoi(row[2]);
|
||||
entry.level = atoi(row[3]);
|
||||
entry.chance = atoi(row[4]);
|
||||
entry.min_expansion = atoi(row[5]);
|
||||
entry.max_expansion = atoi(row[6]);
|
||||
entry.content_flags = row[7] ? row[7] : "";
|
||||
entry.content_flags_disabled = row[8] ? row[8] : "";
|
||||
e.id = atoi(row[0]);
|
||||
e.zoneid = atoi(row[1]);
|
||||
e.Itemid = atoi(row[2]);
|
||||
e.level = atoi(row[3]);
|
||||
e.chance = atoi(row[4]);
|
||||
e.min_expansion = atoi(row[5]);
|
||||
e.max_expansion = atoi(row[6]);
|
||||
e.content_flags = row[7] ? row[7] : "";
|
||||
e.content_flags_disabled = row[8] ? row[8] : "";
|
||||
|
||||
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(
|
||||
@@ -371,6 +371,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_FORAGE_REPOSITORY_H
|
||||
|
||||
Reference in New Issue
Block a user