mirror of
https://github.com/EQEmu/Server.git
synced 2026-09-06 04:06:38 +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 AdventureDetails NewEntity()
|
||||
{
|
||||
AdventureDetails entry{};
|
||||
AdventureDetails e{};
|
||||
|
||||
entry.id = 0;
|
||||
entry.adventure_id = 0;
|
||||
entry.instance_id = -1;
|
||||
entry.count = 0;
|
||||
entry.assassinate_count = 0;
|
||||
entry.status = 0;
|
||||
entry.time_created = 0;
|
||||
entry.time_zoned = 0;
|
||||
entry.time_completed = 0;
|
||||
e.id = 0;
|
||||
e.adventure_id = 0;
|
||||
e.instance_id = -1;
|
||||
e.count = 0;
|
||||
e.assassinate_count = 0;
|
||||
e.status = 0;
|
||||
e.time_created = 0;
|
||||
e.time_zoned = 0;
|
||||
e.time_completed = 0;
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static AdventureDetails GetAdventureDetailsEntry(
|
||||
static AdventureDetails GetAdventureDetails(
|
||||
const std::vector<AdventureDetails> &adventure_detailss,
|
||||
int adventure_details_id
|
||||
)
|
||||
@@ -144,19 +144,19 @@ public:
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
AdventureDetails entry{};
|
||||
AdventureDetails e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.adventure_id = atoi(row[1]);
|
||||
entry.instance_id = atoi(row[2]);
|
||||
entry.count = atoi(row[3]);
|
||||
entry.assassinate_count = atoi(row[4]);
|
||||
entry.status = atoi(row[5]);
|
||||
entry.time_created = atoi(row[6]);
|
||||
entry.time_zoned = atoi(row[7]);
|
||||
entry.time_completed = atoi(row[8]);
|
||||
e.id = atoi(row[0]);
|
||||
e.adventure_id = atoi(row[1]);
|
||||
e.instance_id = atoi(row[2]);
|
||||
e.count = atoi(row[3]);
|
||||
e.assassinate_count = atoi(row[4]);
|
||||
e.status = atoi(row[5]);
|
||||
e.time_created = atoi(row[6]);
|
||||
e.time_zoned = atoi(row[7]);
|
||||
e.time_completed = atoi(row[8]);
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
@@ -181,29 +181,29 @@ public:
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
AdventureDetails adventure_details_entry
|
||||
const AdventureDetails &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> update_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
update_values.push_back(columns[1] + " = " + std::to_string(adventure_details_entry.adventure_id));
|
||||
update_values.push_back(columns[2] + " = " + std::to_string(adventure_details_entry.instance_id));
|
||||
update_values.push_back(columns[3] + " = " + std::to_string(adventure_details_entry.count));
|
||||
update_values.push_back(columns[4] + " = " + std::to_string(adventure_details_entry.assassinate_count));
|
||||
update_values.push_back(columns[5] + " = " + std::to_string(adventure_details_entry.status));
|
||||
update_values.push_back(columns[6] + " = " + std::to_string(adventure_details_entry.time_created));
|
||||
update_values.push_back(columns[7] + " = " + std::to_string(adventure_details_entry.time_zoned));
|
||||
update_values.push_back(columns[8] + " = " + std::to_string(adventure_details_entry.time_completed));
|
||||
v.push_back(columns[1] + " = " + std::to_string(e.adventure_id));
|
||||
v.push_back(columns[2] + " = " + std::to_string(e.instance_id));
|
||||
v.push_back(columns[3] + " = " + std::to_string(e.count));
|
||||
v.push_back(columns[4] + " = " + std::to_string(e.assassinate_count));
|
||||
v.push_back(columns[5] + " = " + std::to_string(e.status));
|
||||
v.push_back(columns[6] + " = " + std::to_string(e.time_created));
|
||||
v.push_back(columns[7] + " = " + std::to_string(e.time_zoned));
|
||||
v.push_back(columns[8] + " = " + std::to_string(e.time_completed));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", update_values),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
adventure_details_entry.id
|
||||
e.id
|
||||
)
|
||||
);
|
||||
|
||||
@@ -212,63 +212,63 @@ public:
|
||||
|
||||
static AdventureDetails InsertOne(
|
||||
Database& db,
|
||||
AdventureDetails adventure_details_entry
|
||||
AdventureDetails e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(adventure_details_entry.id));
|
||||
insert_values.push_back(std::to_string(adventure_details_entry.adventure_id));
|
||||
insert_values.push_back(std::to_string(adventure_details_entry.instance_id));
|
||||
insert_values.push_back(std::to_string(adventure_details_entry.count));
|
||||
insert_values.push_back(std::to_string(adventure_details_entry.assassinate_count));
|
||||
insert_values.push_back(std::to_string(adventure_details_entry.status));
|
||||
insert_values.push_back(std::to_string(adventure_details_entry.time_created));
|
||||
insert_values.push_back(std::to_string(adventure_details_entry.time_zoned));
|
||||
insert_values.push_back(std::to_string(adventure_details_entry.time_completed));
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.adventure_id));
|
||||
v.push_back(std::to_string(e.instance_id));
|
||||
v.push_back(std::to_string(e.count));
|
||||
v.push_back(std::to_string(e.assassinate_count));
|
||||
v.push_back(std::to_string(e.status));
|
||||
v.push_back(std::to_string(e.time_created));
|
||||
v.push_back(std::to_string(e.time_zoned));
|
||||
v.push_back(std::to_string(e.time_completed));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseInsert(),
|
||||
Strings::Implode(",", insert_values)
|
||||
Strings::Implode(",", v)
|
||||
)
|
||||
);
|
||||
|
||||
if (results.Success()) {
|
||||
adventure_details_entry.id = results.LastInsertedID();
|
||||
return adventure_details_entry;
|
||||
e.id = results.LastInsertedID();
|
||||
return e;
|
||||
}
|
||||
|
||||
adventure_details_entry = NewEntity();
|
||||
e = NewEntity();
|
||||
|
||||
return adventure_details_entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
Database& db,
|
||||
std::vector<AdventureDetails> adventure_details_entries
|
||||
const std::vector<AdventureDetails> &entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &adventure_details_entry: adventure_details_entries) {
|
||||
std::vector<std::string> insert_values;
|
||||
for (auto &e: entries) {
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(adventure_details_entry.id));
|
||||
insert_values.push_back(std::to_string(adventure_details_entry.adventure_id));
|
||||
insert_values.push_back(std::to_string(adventure_details_entry.instance_id));
|
||||
insert_values.push_back(std::to_string(adventure_details_entry.count));
|
||||
insert_values.push_back(std::to_string(adventure_details_entry.assassinate_count));
|
||||
insert_values.push_back(std::to_string(adventure_details_entry.status));
|
||||
insert_values.push_back(std::to_string(adventure_details_entry.time_created));
|
||||
insert_values.push_back(std::to_string(adventure_details_entry.time_zoned));
|
||||
insert_values.push_back(std::to_string(adventure_details_entry.time_completed));
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.adventure_id));
|
||||
v.push_back(std::to_string(e.instance_id));
|
||||
v.push_back(std::to_string(e.count));
|
||||
v.push_back(std::to_string(e.assassinate_count));
|
||||
v.push_back(std::to_string(e.status));
|
||||
v.push_back(std::to_string(e.time_created));
|
||||
v.push_back(std::to_string(e.time_zoned));
|
||||
v.push_back(std::to_string(e.time_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(
|
||||
@@ -295,25 +295,25 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
AdventureDetails entry{};
|
||||
AdventureDetails e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.adventure_id = atoi(row[1]);
|
||||
entry.instance_id = atoi(row[2]);
|
||||
entry.count = atoi(row[3]);
|
||||
entry.assassinate_count = atoi(row[4]);
|
||||
entry.status = atoi(row[5]);
|
||||
entry.time_created = atoi(row[6]);
|
||||
entry.time_zoned = atoi(row[7]);
|
||||
entry.time_completed = atoi(row[8]);
|
||||
e.id = atoi(row[0]);
|
||||
e.adventure_id = atoi(row[1]);
|
||||
e.instance_id = atoi(row[2]);
|
||||
e.count = atoi(row[3]);
|
||||
e.assassinate_count = atoi(row[4]);
|
||||
e.status = atoi(row[5]);
|
||||
e.time_created = atoi(row[6]);
|
||||
e.time_zoned = atoi(row[7]);
|
||||
e.time_completed = atoi(row[8]);
|
||||
|
||||
all_entries.push_back(entry);
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<AdventureDetails> GetWhere(Database& db, std::string where_filter)
|
||||
static std::vector<AdventureDetails> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<AdventureDetails> all_entries;
|
||||
|
||||
@@ -328,25 +328,25 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
AdventureDetails entry{};
|
||||
AdventureDetails e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.adventure_id = atoi(row[1]);
|
||||
entry.instance_id = atoi(row[2]);
|
||||
entry.count = atoi(row[3]);
|
||||
entry.assassinate_count = atoi(row[4]);
|
||||
entry.status = atoi(row[5]);
|
||||
entry.time_created = atoi(row[6]);
|
||||
entry.time_zoned = atoi(row[7]);
|
||||
entry.time_completed = atoi(row[8]);
|
||||
e.id = atoi(row[0]);
|
||||
e.adventure_id = atoi(row[1]);
|
||||
e.instance_id = atoi(row[2]);
|
||||
e.count = atoi(row[3]);
|
||||
e.assassinate_count = atoi(row[4]);
|
||||
e.status = atoi(row[5]);
|
||||
e.time_created = atoi(row[6]);
|
||||
e.time_zoned = atoi(row[7]);
|
||||
e.time_completed = atoi(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_ADVENTURE_DETAILS_REPOSITORY_H
|
||||
|
||||
Reference in New Issue
Block a user