mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-24 05:18:40 +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:
@@ -88,18 +88,18 @@ public:
|
||||
|
||||
static CharacterActivities NewEntity()
|
||||
{
|
||||
CharacterActivities entry{};
|
||||
CharacterActivities e{};
|
||||
|
||||
entry.charid = 0;
|
||||
entry.taskid = 0;
|
||||
entry.activityid = 0;
|
||||
entry.donecount = 0;
|
||||
entry.completed = 0;
|
||||
e.charid = 0;
|
||||
e.taskid = 0;
|
||||
e.activityid = 0;
|
||||
e.donecount = 0;
|
||||
e.completed = 0;
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static CharacterActivities GetCharacterActivitiesEntry(
|
||||
static CharacterActivities GetCharacterActivities(
|
||||
const std::vector<CharacterActivities> &character_activitiess,
|
||||
int character_activities_id
|
||||
)
|
||||
@@ -128,15 +128,15 @@ public:
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
CharacterActivities entry{};
|
||||
CharacterActivities e{};
|
||||
|
||||
entry.charid = atoi(row[0]);
|
||||
entry.taskid = atoi(row[1]);
|
||||
entry.activityid = atoi(row[2]);
|
||||
entry.donecount = atoi(row[3]);
|
||||
entry.completed = atoi(row[4]);
|
||||
e.charid = atoi(row[0]);
|
||||
e.taskid = atoi(row[1]);
|
||||
e.activityid = atoi(row[2]);
|
||||
e.donecount = atoi(row[3]);
|
||||
e.completed = atoi(row[4]);
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
@@ -161,26 +161,26 @@ public:
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
CharacterActivities character_activities_entry
|
||||
const CharacterActivities &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_activities_entry.charid));
|
||||
update_values.push_back(columns[1] + " = " + std::to_string(character_activities_entry.taskid));
|
||||
update_values.push_back(columns[2] + " = " + std::to_string(character_activities_entry.activityid));
|
||||
update_values.push_back(columns[3] + " = " + std::to_string(character_activities_entry.donecount));
|
||||
update_values.push_back(columns[4] + " = " + std::to_string(character_activities_entry.completed));
|
||||
v.push_back(columns[0] + " = " + std::to_string(e.charid));
|
||||
v.push_back(columns[1] + " = " + std::to_string(e.taskid));
|
||||
v.push_back(columns[2] + " = " + std::to_string(e.activityid));
|
||||
v.push_back(columns[3] + " = " + std::to_string(e.donecount));
|
||||
v.push_back(columns[4] + " = " + std::to_string(e.completed));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", update_values),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
character_activities_entry.charid
|
||||
e.charid
|
||||
)
|
||||
);
|
||||
|
||||
@@ -189,55 +189,55 @@ public:
|
||||
|
||||
static CharacterActivities InsertOne(
|
||||
Database& db,
|
||||
CharacterActivities character_activities_entry
|
||||
CharacterActivities e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(character_activities_entry.charid));
|
||||
insert_values.push_back(std::to_string(character_activities_entry.taskid));
|
||||
insert_values.push_back(std::to_string(character_activities_entry.activityid));
|
||||
insert_values.push_back(std::to_string(character_activities_entry.donecount));
|
||||
insert_values.push_back(std::to_string(character_activities_entry.completed));
|
||||
v.push_back(std::to_string(e.charid));
|
||||
v.push_back(std::to_string(e.taskid));
|
||||
v.push_back(std::to_string(e.activityid));
|
||||
v.push_back(std::to_string(e.donecount));
|
||||
v.push_back(std::to_string(e.completed));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseInsert(),
|
||||
Strings::Implode(",", insert_values)
|
||||
Strings::Implode(",", v)
|
||||
)
|
||||
);
|
||||
|
||||
if (results.Success()) {
|
||||
character_activities_entry.charid = results.LastInsertedID();
|
||||
return character_activities_entry;
|
||||
e.charid = results.LastInsertedID();
|
||||
return e;
|
||||
}
|
||||
|
||||
character_activities_entry = NewEntity();
|
||||
e = NewEntity();
|
||||
|
||||
return character_activities_entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
Database& db,
|
||||
std::vector<CharacterActivities> character_activities_entries
|
||||
const std::vector<CharacterActivities> &entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &character_activities_entry: character_activities_entries) {
|
||||
std::vector<std::string> insert_values;
|
||||
for (auto &e: entries) {
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(character_activities_entry.charid));
|
||||
insert_values.push_back(std::to_string(character_activities_entry.taskid));
|
||||
insert_values.push_back(std::to_string(character_activities_entry.activityid));
|
||||
insert_values.push_back(std::to_string(character_activities_entry.donecount));
|
||||
insert_values.push_back(std::to_string(character_activities_entry.completed));
|
||||
v.push_back(std::to_string(e.charid));
|
||||
v.push_back(std::to_string(e.taskid));
|
||||
v.push_back(std::to_string(e.activityid));
|
||||
v.push_back(std::to_string(e.donecount));
|
||||
v.push_back(std::to_string(e.completed));
|
||||
|
||||
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(
|
||||
@@ -264,21 +264,21 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
CharacterActivities entry{};
|
||||
CharacterActivities e{};
|
||||
|
||||
entry.charid = atoi(row[0]);
|
||||
entry.taskid = atoi(row[1]);
|
||||
entry.activityid = atoi(row[2]);
|
||||
entry.donecount = atoi(row[3]);
|
||||
entry.completed = atoi(row[4]);
|
||||
e.charid = atoi(row[0]);
|
||||
e.taskid = atoi(row[1]);
|
||||
e.activityid = atoi(row[2]);
|
||||
e.donecount = atoi(row[3]);
|
||||
e.completed = atoi(row[4]);
|
||||
|
||||
all_entries.push_back(entry);
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<CharacterActivities> GetWhere(Database& db, std::string where_filter)
|
||||
static std::vector<CharacterActivities> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<CharacterActivities> all_entries;
|
||||
|
||||
@@ -293,21 +293,21 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
CharacterActivities entry{};
|
||||
CharacterActivities e{};
|
||||
|
||||
entry.charid = atoi(row[0]);
|
||||
entry.taskid = atoi(row[1]);
|
||||
entry.activityid = atoi(row[2]);
|
||||
entry.donecount = atoi(row[3]);
|
||||
entry.completed = atoi(row[4]);
|
||||
e.charid = atoi(row[0]);
|
||||
e.taskid = atoi(row[1]);
|
||||
e.activityid = atoi(row[2]);
|
||||
e.donecount = atoi(row[3]);
|
||||
e.completed = atoi(row[4]);
|
||||
|
||||
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(
|
||||
@@ -332,6 +332,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_ACTIVITIES_REPOSITORY_H
|
||||
|
||||
Reference in New Issue
Block a user