mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-25 02:08:23 +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:
@@ -124,30 +124,30 @@ public:
|
||||
|
||||
static GlobalLoot NewEntity()
|
||||
{
|
||||
GlobalLoot entry{};
|
||||
GlobalLoot e{};
|
||||
|
||||
entry.id = 0;
|
||||
entry.description = "";
|
||||
entry.loottable_id = 0;
|
||||
entry.enabled = 1;
|
||||
entry.min_level = 0;
|
||||
entry.max_level = 0;
|
||||
entry.rare = 0;
|
||||
entry.raid = 0;
|
||||
entry.race = "";
|
||||
entry.class_ = "";
|
||||
entry.bodytype = "";
|
||||
entry.zone = "";
|
||||
entry.hot_zone = 0;
|
||||
entry.min_expansion = -1;
|
||||
entry.max_expansion = -1;
|
||||
entry.content_flags = "";
|
||||
entry.content_flags_disabled = "";
|
||||
e.id = 0;
|
||||
e.description = "";
|
||||
e.loottable_id = 0;
|
||||
e.enabled = 1;
|
||||
e.min_level = 0;
|
||||
e.max_level = 0;
|
||||
e.rare = 0;
|
||||
e.raid = 0;
|
||||
e.race = "";
|
||||
e.class_ = "";
|
||||
e.bodytype = "";
|
||||
e.zone = "";
|
||||
e.hot_zone = 0;
|
||||
e.min_expansion = -1;
|
||||
e.max_expansion = -1;
|
||||
e.content_flags = "";
|
||||
e.content_flags_disabled = "";
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static GlobalLoot GetGlobalLootEntry(
|
||||
static GlobalLoot GetGlobalLoot(
|
||||
const std::vector<GlobalLoot> &global_loots,
|
||||
int global_loot_id
|
||||
)
|
||||
@@ -176,27 +176,27 @@ public:
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
GlobalLoot entry{};
|
||||
GlobalLoot e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.description = row[1] ? row[1] : "";
|
||||
entry.loottable_id = atoi(row[2]);
|
||||
entry.enabled = atoi(row[3]);
|
||||
entry.min_level = atoi(row[4]);
|
||||
entry.max_level = atoi(row[5]);
|
||||
entry.rare = atoi(row[6]);
|
||||
entry.raid = atoi(row[7]);
|
||||
entry.race = row[8] ? row[8] : "";
|
||||
entry.class_ = row[9] ? row[9] : "";
|
||||
entry.bodytype = row[10] ? row[10] : "";
|
||||
entry.zone = row[11] ? row[11] : "";
|
||||
entry.hot_zone = atoi(row[12]);
|
||||
entry.min_expansion = atoi(row[13]);
|
||||
entry.max_expansion = atoi(row[14]);
|
||||
entry.content_flags = row[15] ? row[15] : "";
|
||||
entry.content_flags_disabled = row[16] ? row[16] : "";
|
||||
e.id = atoi(row[0]);
|
||||
e.description = row[1] ? row[1] : "";
|
||||
e.loottable_id = atoi(row[2]);
|
||||
e.enabled = atoi(row[3]);
|
||||
e.min_level = atoi(row[4]);
|
||||
e.max_level = atoi(row[5]);
|
||||
e.rare = atoi(row[6]);
|
||||
e.raid = atoi(row[7]);
|
||||
e.race = row[8] ? row[8] : "";
|
||||
e.class_ = row[9] ? row[9] : "";
|
||||
e.bodytype = row[10] ? row[10] : "";
|
||||
e.zone = row[11] ? row[11] : "";
|
||||
e.hot_zone = atoi(row[12]);
|
||||
e.min_expansion = atoi(row[13]);
|
||||
e.max_expansion = atoi(row[14]);
|
||||
e.content_flags = row[15] ? row[15] : "";
|
||||
e.content_flags_disabled = row[16] ? row[16] : "";
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
@@ -221,37 +221,37 @@ public:
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
GlobalLoot global_loot_entry
|
||||
const GlobalLoot &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> update_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
update_values.push_back(columns[1] + " = '" + Strings::Escape(global_loot_entry.description) + "'");
|
||||
update_values.push_back(columns[2] + " = " + std::to_string(global_loot_entry.loottable_id));
|
||||
update_values.push_back(columns[3] + " = " + std::to_string(global_loot_entry.enabled));
|
||||
update_values.push_back(columns[4] + " = " + std::to_string(global_loot_entry.min_level));
|
||||
update_values.push_back(columns[5] + " = " + std::to_string(global_loot_entry.max_level));
|
||||
update_values.push_back(columns[6] + " = " + std::to_string(global_loot_entry.rare));
|
||||
update_values.push_back(columns[7] + " = " + std::to_string(global_loot_entry.raid));
|
||||
update_values.push_back(columns[8] + " = '" + Strings::Escape(global_loot_entry.race) + "'");
|
||||
update_values.push_back(columns[9] + " = '" + Strings::Escape(global_loot_entry.class_) + "'");
|
||||
update_values.push_back(columns[10] + " = '" + Strings::Escape(global_loot_entry.bodytype) + "'");
|
||||
update_values.push_back(columns[11] + " = '" + Strings::Escape(global_loot_entry.zone) + "'");
|
||||
update_values.push_back(columns[12] + " = " + std::to_string(global_loot_entry.hot_zone));
|
||||
update_values.push_back(columns[13] + " = " + std::to_string(global_loot_entry.min_expansion));
|
||||
update_values.push_back(columns[14] + " = " + std::to_string(global_loot_entry.max_expansion));
|
||||
update_values.push_back(columns[15] + " = '" + Strings::Escape(global_loot_entry.content_flags) + "'");
|
||||
update_values.push_back(columns[16] + " = '" + Strings::Escape(global_loot_entry.content_flags_disabled) + "'");
|
||||
v.push_back(columns[1] + " = '" + Strings::Escape(e.description) + "'");
|
||||
v.push_back(columns[2] + " = " + std::to_string(e.loottable_id));
|
||||
v.push_back(columns[3] + " = " + std::to_string(e.enabled));
|
||||
v.push_back(columns[4] + " = " + std::to_string(e.min_level));
|
||||
v.push_back(columns[5] + " = " + std::to_string(e.max_level));
|
||||
v.push_back(columns[6] + " = " + std::to_string(e.rare));
|
||||
v.push_back(columns[7] + " = " + std::to_string(e.raid));
|
||||
v.push_back(columns[8] + " = '" + Strings::Escape(e.race) + "'");
|
||||
v.push_back(columns[9] + " = '" + Strings::Escape(e.class_) + "'");
|
||||
v.push_back(columns[10] + " = '" + Strings::Escape(e.bodytype) + "'");
|
||||
v.push_back(columns[11] + " = '" + Strings::Escape(e.zone) + "'");
|
||||
v.push_back(columns[12] + " = " + std::to_string(e.hot_zone));
|
||||
v.push_back(columns[13] + " = " + std::to_string(e.min_expansion));
|
||||
v.push_back(columns[14] + " = " + std::to_string(e.max_expansion));
|
||||
v.push_back(columns[15] + " = '" + Strings::Escape(e.content_flags) + "'");
|
||||
v.push_back(columns[16] + " = '" + Strings::Escape(e.content_flags_disabled) + "'");
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", update_values),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
global_loot_entry.id
|
||||
e.id
|
||||
)
|
||||
);
|
||||
|
||||
@@ -260,79 +260,79 @@ public:
|
||||
|
||||
static GlobalLoot InsertOne(
|
||||
Database& db,
|
||||
GlobalLoot global_loot_entry
|
||||
GlobalLoot e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(global_loot_entry.id));
|
||||
insert_values.push_back("'" + Strings::Escape(global_loot_entry.description) + "'");
|
||||
insert_values.push_back(std::to_string(global_loot_entry.loottable_id));
|
||||
insert_values.push_back(std::to_string(global_loot_entry.enabled));
|
||||
insert_values.push_back(std::to_string(global_loot_entry.min_level));
|
||||
insert_values.push_back(std::to_string(global_loot_entry.max_level));
|
||||
insert_values.push_back(std::to_string(global_loot_entry.rare));
|
||||
insert_values.push_back(std::to_string(global_loot_entry.raid));
|
||||
insert_values.push_back("'" + Strings::Escape(global_loot_entry.race) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(global_loot_entry.class_) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(global_loot_entry.bodytype) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(global_loot_entry.zone) + "'");
|
||||
insert_values.push_back(std::to_string(global_loot_entry.hot_zone));
|
||||
insert_values.push_back(std::to_string(global_loot_entry.min_expansion));
|
||||
insert_values.push_back(std::to_string(global_loot_entry.max_expansion));
|
||||
insert_values.push_back("'" + Strings::Escape(global_loot_entry.content_flags) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(global_loot_entry.content_flags_disabled) + "'");
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back("'" + Strings::Escape(e.description) + "'");
|
||||
v.push_back(std::to_string(e.loottable_id));
|
||||
v.push_back(std::to_string(e.enabled));
|
||||
v.push_back(std::to_string(e.min_level));
|
||||
v.push_back(std::to_string(e.max_level));
|
||||
v.push_back(std::to_string(e.rare));
|
||||
v.push_back(std::to_string(e.raid));
|
||||
v.push_back("'" + Strings::Escape(e.race) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.class_) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.bodytype) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.zone) + "'");
|
||||
v.push_back(std::to_string(e.hot_zone));
|
||||
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()) {
|
||||
global_loot_entry.id = results.LastInsertedID();
|
||||
return global_loot_entry;
|
||||
e.id = results.LastInsertedID();
|
||||
return e;
|
||||
}
|
||||
|
||||
global_loot_entry = NewEntity();
|
||||
e = NewEntity();
|
||||
|
||||
return global_loot_entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
Database& db,
|
||||
std::vector<GlobalLoot> global_loot_entries
|
||||
const std::vector<GlobalLoot> &entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &global_loot_entry: global_loot_entries) {
|
||||
std::vector<std::string> insert_values;
|
||||
for (auto &e: entries) {
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(global_loot_entry.id));
|
||||
insert_values.push_back("'" + Strings::Escape(global_loot_entry.description) + "'");
|
||||
insert_values.push_back(std::to_string(global_loot_entry.loottable_id));
|
||||
insert_values.push_back(std::to_string(global_loot_entry.enabled));
|
||||
insert_values.push_back(std::to_string(global_loot_entry.min_level));
|
||||
insert_values.push_back(std::to_string(global_loot_entry.max_level));
|
||||
insert_values.push_back(std::to_string(global_loot_entry.rare));
|
||||
insert_values.push_back(std::to_string(global_loot_entry.raid));
|
||||
insert_values.push_back("'" + Strings::Escape(global_loot_entry.race) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(global_loot_entry.class_) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(global_loot_entry.bodytype) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(global_loot_entry.zone) + "'");
|
||||
insert_values.push_back(std::to_string(global_loot_entry.hot_zone));
|
||||
insert_values.push_back(std::to_string(global_loot_entry.min_expansion));
|
||||
insert_values.push_back(std::to_string(global_loot_entry.max_expansion));
|
||||
insert_values.push_back("'" + Strings::Escape(global_loot_entry.content_flags) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(global_loot_entry.content_flags_disabled) + "'");
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back("'" + Strings::Escape(e.description) + "'");
|
||||
v.push_back(std::to_string(e.loottable_id));
|
||||
v.push_back(std::to_string(e.enabled));
|
||||
v.push_back(std::to_string(e.min_level));
|
||||
v.push_back(std::to_string(e.max_level));
|
||||
v.push_back(std::to_string(e.rare));
|
||||
v.push_back(std::to_string(e.raid));
|
||||
v.push_back("'" + Strings::Escape(e.race) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.class_) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.bodytype) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.zone) + "'");
|
||||
v.push_back(std::to_string(e.hot_zone));
|
||||
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(
|
||||
@@ -359,33 +359,33 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
GlobalLoot entry{};
|
||||
GlobalLoot e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.description = row[1] ? row[1] : "";
|
||||
entry.loottable_id = atoi(row[2]);
|
||||
entry.enabled = atoi(row[3]);
|
||||
entry.min_level = atoi(row[4]);
|
||||
entry.max_level = atoi(row[5]);
|
||||
entry.rare = atoi(row[6]);
|
||||
entry.raid = atoi(row[7]);
|
||||
entry.race = row[8] ? row[8] : "";
|
||||
entry.class_ = row[9] ? row[9] : "";
|
||||
entry.bodytype = row[10] ? row[10] : "";
|
||||
entry.zone = row[11] ? row[11] : "";
|
||||
entry.hot_zone = atoi(row[12]);
|
||||
entry.min_expansion = atoi(row[13]);
|
||||
entry.max_expansion = atoi(row[14]);
|
||||
entry.content_flags = row[15] ? row[15] : "";
|
||||
entry.content_flags_disabled = row[16] ? row[16] : "";
|
||||
e.id = atoi(row[0]);
|
||||
e.description = row[1] ? row[1] : "";
|
||||
e.loottable_id = atoi(row[2]);
|
||||
e.enabled = atoi(row[3]);
|
||||
e.min_level = atoi(row[4]);
|
||||
e.max_level = atoi(row[5]);
|
||||
e.rare = atoi(row[6]);
|
||||
e.raid = atoi(row[7]);
|
||||
e.race = row[8] ? row[8] : "";
|
||||
e.class_ = row[9] ? row[9] : "";
|
||||
e.bodytype = row[10] ? row[10] : "";
|
||||
e.zone = row[11] ? row[11] : "";
|
||||
e.hot_zone = atoi(row[12]);
|
||||
e.min_expansion = atoi(row[13]);
|
||||
e.max_expansion = atoi(row[14]);
|
||||
e.content_flags = row[15] ? row[15] : "";
|
||||
e.content_flags_disabled = row[16] ? row[16] : "";
|
||||
|
||||
all_entries.push_back(entry);
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<GlobalLoot> GetWhere(Database& db, std::string where_filter)
|
||||
static std::vector<GlobalLoot> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<GlobalLoot> all_entries;
|
||||
|
||||
@@ -400,33 +400,33 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
GlobalLoot entry{};
|
||||
GlobalLoot e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.description = row[1] ? row[1] : "";
|
||||
entry.loottable_id = atoi(row[2]);
|
||||
entry.enabled = atoi(row[3]);
|
||||
entry.min_level = atoi(row[4]);
|
||||
entry.max_level = atoi(row[5]);
|
||||
entry.rare = atoi(row[6]);
|
||||
entry.raid = atoi(row[7]);
|
||||
entry.race = row[8] ? row[8] : "";
|
||||
entry.class_ = row[9] ? row[9] : "";
|
||||
entry.bodytype = row[10] ? row[10] : "";
|
||||
entry.zone = row[11] ? row[11] : "";
|
||||
entry.hot_zone = atoi(row[12]);
|
||||
entry.min_expansion = atoi(row[13]);
|
||||
entry.max_expansion = atoi(row[14]);
|
||||
entry.content_flags = row[15] ? row[15] : "";
|
||||
entry.content_flags_disabled = row[16] ? row[16] : "";
|
||||
e.id = atoi(row[0]);
|
||||
e.description = row[1] ? row[1] : "";
|
||||
e.loottable_id = atoi(row[2]);
|
||||
e.enabled = atoi(row[3]);
|
||||
e.min_level = atoi(row[4]);
|
||||
e.max_level = atoi(row[5]);
|
||||
e.rare = atoi(row[6]);
|
||||
e.raid = atoi(row[7]);
|
||||
e.race = row[8] ? row[8] : "";
|
||||
e.class_ = row[9] ? row[9] : "";
|
||||
e.bodytype = row[10] ? row[10] : "";
|
||||
e.zone = row[11] ? row[11] : "";
|
||||
e.hot_zone = atoi(row[12]);
|
||||
e.min_expansion = atoi(row[13]);
|
||||
e.max_expansion = atoi(row[14]);
|
||||
e.content_flags = row[15] ? row[15] : "";
|
||||
e.content_flags_disabled = row[16] ? row[16] : "";
|
||||
|
||||
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(
|
||||
@@ -451,6 +451,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_GLOBAL_LOOT_REPOSITORY_H
|
||||
|
||||
Reference in New Issue
Block a user