mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-27 04:07: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:
@@ -91,19 +91,19 @@ public:
|
||||
|
||||
static CharacterBandolier NewEntity()
|
||||
{
|
||||
CharacterBandolier entry{};
|
||||
CharacterBandolier e{};
|
||||
|
||||
entry.id = 0;
|
||||
entry.bandolier_id = 0;
|
||||
entry.bandolier_slot = 0;
|
||||
entry.item_id = 0;
|
||||
entry.icon = 0;
|
||||
entry.bandolier_name = "0";
|
||||
e.id = 0;
|
||||
e.bandolier_id = 0;
|
||||
e.bandolier_slot = 0;
|
||||
e.item_id = 0;
|
||||
e.icon = 0;
|
||||
e.bandolier_name = "0";
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static CharacterBandolier GetCharacterBandolierEntry(
|
||||
static CharacterBandolier GetCharacterBandolier(
|
||||
const std::vector<CharacterBandolier> &character_bandoliers,
|
||||
int character_bandolier_id
|
||||
)
|
||||
@@ -132,16 +132,16 @@ public:
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
CharacterBandolier entry{};
|
||||
CharacterBandolier e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.bandolier_id = atoi(row[1]);
|
||||
entry.bandolier_slot = atoi(row[2]);
|
||||
entry.item_id = atoi(row[3]);
|
||||
entry.icon = atoi(row[4]);
|
||||
entry.bandolier_name = row[5] ? row[5] : "";
|
||||
e.id = atoi(row[0]);
|
||||
e.bandolier_id = atoi(row[1]);
|
||||
e.bandolier_slot = atoi(row[2]);
|
||||
e.item_id = atoi(row[3]);
|
||||
e.icon = atoi(row[4]);
|
||||
e.bandolier_name = row[5] ? row[5] : "";
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
@@ -166,27 +166,27 @@ public:
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
CharacterBandolier character_bandolier_entry
|
||||
const CharacterBandolier &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> update_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
update_values.push_back(columns[0] + " = " + std::to_string(character_bandolier_entry.id));
|
||||
update_values.push_back(columns[1] + " = " + std::to_string(character_bandolier_entry.bandolier_id));
|
||||
update_values.push_back(columns[2] + " = " + std::to_string(character_bandolier_entry.bandolier_slot));
|
||||
update_values.push_back(columns[3] + " = " + std::to_string(character_bandolier_entry.item_id));
|
||||
update_values.push_back(columns[4] + " = " + std::to_string(character_bandolier_entry.icon));
|
||||
update_values.push_back(columns[5] + " = '" + Strings::Escape(character_bandolier_entry.bandolier_name) + "'");
|
||||
v.push_back(columns[0] + " = " + std::to_string(e.id));
|
||||
v.push_back(columns[1] + " = " + std::to_string(e.bandolier_id));
|
||||
v.push_back(columns[2] + " = " + std::to_string(e.bandolier_slot));
|
||||
v.push_back(columns[3] + " = " + std::to_string(e.item_id));
|
||||
v.push_back(columns[4] + " = " + std::to_string(e.icon));
|
||||
v.push_back(columns[5] + " = '" + Strings::Escape(e.bandolier_name) + "'");
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", update_values),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
character_bandolier_entry.id
|
||||
e.id
|
||||
)
|
||||
);
|
||||
|
||||
@@ -195,57 +195,57 @@ public:
|
||||
|
||||
static CharacterBandolier InsertOne(
|
||||
Database& db,
|
||||
CharacterBandolier character_bandolier_entry
|
||||
CharacterBandolier e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(character_bandolier_entry.id));
|
||||
insert_values.push_back(std::to_string(character_bandolier_entry.bandolier_id));
|
||||
insert_values.push_back(std::to_string(character_bandolier_entry.bandolier_slot));
|
||||
insert_values.push_back(std::to_string(character_bandolier_entry.item_id));
|
||||
insert_values.push_back(std::to_string(character_bandolier_entry.icon));
|
||||
insert_values.push_back("'" + Strings::Escape(character_bandolier_entry.bandolier_name) + "'");
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.bandolier_id));
|
||||
v.push_back(std::to_string(e.bandolier_slot));
|
||||
v.push_back(std::to_string(e.item_id));
|
||||
v.push_back(std::to_string(e.icon));
|
||||
v.push_back("'" + Strings::Escape(e.bandolier_name) + "'");
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseInsert(),
|
||||
Strings::Implode(",", insert_values)
|
||||
Strings::Implode(",", v)
|
||||
)
|
||||
);
|
||||
|
||||
if (results.Success()) {
|
||||
character_bandolier_entry.id = results.LastInsertedID();
|
||||
return character_bandolier_entry;
|
||||
e.id = results.LastInsertedID();
|
||||
return e;
|
||||
}
|
||||
|
||||
character_bandolier_entry = NewEntity();
|
||||
e = NewEntity();
|
||||
|
||||
return character_bandolier_entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
Database& db,
|
||||
std::vector<CharacterBandolier> character_bandolier_entries
|
||||
const std::vector<CharacterBandolier> &entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &character_bandolier_entry: character_bandolier_entries) {
|
||||
std::vector<std::string> insert_values;
|
||||
for (auto &e: entries) {
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(character_bandolier_entry.id));
|
||||
insert_values.push_back(std::to_string(character_bandolier_entry.bandolier_id));
|
||||
insert_values.push_back(std::to_string(character_bandolier_entry.bandolier_slot));
|
||||
insert_values.push_back(std::to_string(character_bandolier_entry.item_id));
|
||||
insert_values.push_back(std::to_string(character_bandolier_entry.icon));
|
||||
insert_values.push_back("'" + Strings::Escape(character_bandolier_entry.bandolier_name) + "'");
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.bandolier_id));
|
||||
v.push_back(std::to_string(e.bandolier_slot));
|
||||
v.push_back(std::to_string(e.item_id));
|
||||
v.push_back(std::to_string(e.icon));
|
||||
v.push_back("'" + Strings::Escape(e.bandolier_name) + "'");
|
||||
|
||||
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(
|
||||
@@ -272,22 +272,22 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
CharacterBandolier entry{};
|
||||
CharacterBandolier e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.bandolier_id = atoi(row[1]);
|
||||
entry.bandolier_slot = atoi(row[2]);
|
||||
entry.item_id = atoi(row[3]);
|
||||
entry.icon = atoi(row[4]);
|
||||
entry.bandolier_name = row[5] ? row[5] : "";
|
||||
e.id = atoi(row[0]);
|
||||
e.bandolier_id = atoi(row[1]);
|
||||
e.bandolier_slot = atoi(row[2]);
|
||||
e.item_id = atoi(row[3]);
|
||||
e.icon = atoi(row[4]);
|
||||
e.bandolier_name = row[5] ? row[5] : "";
|
||||
|
||||
all_entries.push_back(entry);
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<CharacterBandolier> GetWhere(Database& db, std::string where_filter)
|
||||
static std::vector<CharacterBandolier> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<CharacterBandolier> all_entries;
|
||||
|
||||
@@ -302,22 +302,22 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
CharacterBandolier entry{};
|
||||
CharacterBandolier e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.bandolier_id = atoi(row[1]);
|
||||
entry.bandolier_slot = atoi(row[2]);
|
||||
entry.item_id = atoi(row[3]);
|
||||
entry.icon = atoi(row[4]);
|
||||
entry.bandolier_name = row[5] ? row[5] : "";
|
||||
e.id = atoi(row[0]);
|
||||
e.bandolier_id = atoi(row[1]);
|
||||
e.bandolier_slot = atoi(row[2]);
|
||||
e.item_id = atoi(row[3]);
|
||||
e.icon = atoi(row[4]);
|
||||
e.bandolier_name = row[5] ? row[5] : "";
|
||||
|
||||
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(
|
||||
@@ -342,6 +342,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_CHARACTER_BANDOLIER_REPOSITORY_H
|
||||
|
||||
Reference in New Issue
Block a user