mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-24 09:28:21 +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:
@@ -112,26 +112,26 @@ public:
|
||||
|
||||
static AaRanks NewEntity()
|
||||
{
|
||||
AaRanks entry{};
|
||||
AaRanks e{};
|
||||
|
||||
entry.id = 0;
|
||||
entry.upper_hotkey_sid = -1;
|
||||
entry.lower_hotkey_sid = -1;
|
||||
entry.title_sid = -1;
|
||||
entry.desc_sid = -1;
|
||||
entry.cost = 1;
|
||||
entry.level_req = 51;
|
||||
entry.spell = -1;
|
||||
entry.spell_type = 0;
|
||||
entry.recast_time = 0;
|
||||
entry.expansion = 0;
|
||||
entry.prev_id = -1;
|
||||
entry.next_id = -1;
|
||||
e.id = 0;
|
||||
e.upper_hotkey_sid = -1;
|
||||
e.lower_hotkey_sid = -1;
|
||||
e.title_sid = -1;
|
||||
e.desc_sid = -1;
|
||||
e.cost = 1;
|
||||
e.level_req = 51;
|
||||
e.spell = -1;
|
||||
e.spell_type = 0;
|
||||
e.recast_time = 0;
|
||||
e.expansion = 0;
|
||||
e.prev_id = -1;
|
||||
e.next_id = -1;
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static AaRanks GetAaRanksEntry(
|
||||
static AaRanks GetAaRanks(
|
||||
const std::vector<AaRanks> &aa_rankss,
|
||||
int aa_ranks_id
|
||||
)
|
||||
@@ -160,23 +160,23 @@ public:
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
AaRanks entry{};
|
||||
AaRanks e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.upper_hotkey_sid = atoi(row[1]);
|
||||
entry.lower_hotkey_sid = atoi(row[2]);
|
||||
entry.title_sid = atoi(row[3]);
|
||||
entry.desc_sid = atoi(row[4]);
|
||||
entry.cost = atoi(row[5]);
|
||||
entry.level_req = atoi(row[6]);
|
||||
entry.spell = atoi(row[7]);
|
||||
entry.spell_type = atoi(row[8]);
|
||||
entry.recast_time = atoi(row[9]);
|
||||
entry.expansion = atoi(row[10]);
|
||||
entry.prev_id = atoi(row[11]);
|
||||
entry.next_id = atoi(row[12]);
|
||||
e.id = atoi(row[0]);
|
||||
e.upper_hotkey_sid = atoi(row[1]);
|
||||
e.lower_hotkey_sid = atoi(row[2]);
|
||||
e.title_sid = atoi(row[3]);
|
||||
e.desc_sid = atoi(row[4]);
|
||||
e.cost = atoi(row[5]);
|
||||
e.level_req = atoi(row[6]);
|
||||
e.spell = atoi(row[7]);
|
||||
e.spell_type = atoi(row[8]);
|
||||
e.recast_time = atoi(row[9]);
|
||||
e.expansion = atoi(row[10]);
|
||||
e.prev_id = atoi(row[11]);
|
||||
e.next_id = atoi(row[12]);
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
@@ -201,34 +201,34 @@ public:
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
AaRanks aa_ranks_entry
|
||||
const AaRanks &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> update_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
update_values.push_back(columns[0] + " = " + std::to_string(aa_ranks_entry.id));
|
||||
update_values.push_back(columns[1] + " = " + std::to_string(aa_ranks_entry.upper_hotkey_sid));
|
||||
update_values.push_back(columns[2] + " = " + std::to_string(aa_ranks_entry.lower_hotkey_sid));
|
||||
update_values.push_back(columns[3] + " = " + std::to_string(aa_ranks_entry.title_sid));
|
||||
update_values.push_back(columns[4] + " = " + std::to_string(aa_ranks_entry.desc_sid));
|
||||
update_values.push_back(columns[5] + " = " + std::to_string(aa_ranks_entry.cost));
|
||||
update_values.push_back(columns[6] + " = " + std::to_string(aa_ranks_entry.level_req));
|
||||
update_values.push_back(columns[7] + " = " + std::to_string(aa_ranks_entry.spell));
|
||||
update_values.push_back(columns[8] + " = " + std::to_string(aa_ranks_entry.spell_type));
|
||||
update_values.push_back(columns[9] + " = " + std::to_string(aa_ranks_entry.recast_time));
|
||||
update_values.push_back(columns[10] + " = " + std::to_string(aa_ranks_entry.expansion));
|
||||
update_values.push_back(columns[11] + " = " + std::to_string(aa_ranks_entry.prev_id));
|
||||
update_values.push_back(columns[12] + " = " + std::to_string(aa_ranks_entry.next_id));
|
||||
v.push_back(columns[0] + " = " + std::to_string(e.id));
|
||||
v.push_back(columns[1] + " = " + std::to_string(e.upper_hotkey_sid));
|
||||
v.push_back(columns[2] + " = " + std::to_string(e.lower_hotkey_sid));
|
||||
v.push_back(columns[3] + " = " + std::to_string(e.title_sid));
|
||||
v.push_back(columns[4] + " = " + std::to_string(e.desc_sid));
|
||||
v.push_back(columns[5] + " = " + std::to_string(e.cost));
|
||||
v.push_back(columns[6] + " = " + std::to_string(e.level_req));
|
||||
v.push_back(columns[7] + " = " + std::to_string(e.spell));
|
||||
v.push_back(columns[8] + " = " + std::to_string(e.spell_type));
|
||||
v.push_back(columns[9] + " = " + std::to_string(e.recast_time));
|
||||
v.push_back(columns[10] + " = " + std::to_string(e.expansion));
|
||||
v.push_back(columns[11] + " = " + std::to_string(e.prev_id));
|
||||
v.push_back(columns[12] + " = " + std::to_string(e.next_id));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", update_values),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
aa_ranks_entry.id
|
||||
e.id
|
||||
)
|
||||
);
|
||||
|
||||
@@ -237,71 +237,71 @@ public:
|
||||
|
||||
static AaRanks InsertOne(
|
||||
Database& db,
|
||||
AaRanks aa_ranks_entry
|
||||
AaRanks e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.id));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.upper_hotkey_sid));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.lower_hotkey_sid));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.title_sid));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.desc_sid));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.cost));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.level_req));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.spell));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.spell_type));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.recast_time));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.expansion));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.prev_id));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.next_id));
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.upper_hotkey_sid));
|
||||
v.push_back(std::to_string(e.lower_hotkey_sid));
|
||||
v.push_back(std::to_string(e.title_sid));
|
||||
v.push_back(std::to_string(e.desc_sid));
|
||||
v.push_back(std::to_string(e.cost));
|
||||
v.push_back(std::to_string(e.level_req));
|
||||
v.push_back(std::to_string(e.spell));
|
||||
v.push_back(std::to_string(e.spell_type));
|
||||
v.push_back(std::to_string(e.recast_time));
|
||||
v.push_back(std::to_string(e.expansion));
|
||||
v.push_back(std::to_string(e.prev_id));
|
||||
v.push_back(std::to_string(e.next_id));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseInsert(),
|
||||
Strings::Implode(",", insert_values)
|
||||
Strings::Implode(",", v)
|
||||
)
|
||||
);
|
||||
|
||||
if (results.Success()) {
|
||||
aa_ranks_entry.id = results.LastInsertedID();
|
||||
return aa_ranks_entry;
|
||||
e.id = results.LastInsertedID();
|
||||
return e;
|
||||
}
|
||||
|
||||
aa_ranks_entry = NewEntity();
|
||||
e = NewEntity();
|
||||
|
||||
return aa_ranks_entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
Database& db,
|
||||
std::vector<AaRanks> aa_ranks_entries
|
||||
const std::vector<AaRanks> &entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &aa_ranks_entry: aa_ranks_entries) {
|
||||
std::vector<std::string> insert_values;
|
||||
for (auto &e: entries) {
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.id));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.upper_hotkey_sid));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.lower_hotkey_sid));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.title_sid));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.desc_sid));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.cost));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.level_req));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.spell));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.spell_type));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.recast_time));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.expansion));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.prev_id));
|
||||
insert_values.push_back(std::to_string(aa_ranks_entry.next_id));
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.upper_hotkey_sid));
|
||||
v.push_back(std::to_string(e.lower_hotkey_sid));
|
||||
v.push_back(std::to_string(e.title_sid));
|
||||
v.push_back(std::to_string(e.desc_sid));
|
||||
v.push_back(std::to_string(e.cost));
|
||||
v.push_back(std::to_string(e.level_req));
|
||||
v.push_back(std::to_string(e.spell));
|
||||
v.push_back(std::to_string(e.spell_type));
|
||||
v.push_back(std::to_string(e.recast_time));
|
||||
v.push_back(std::to_string(e.expansion));
|
||||
v.push_back(std::to_string(e.prev_id));
|
||||
v.push_back(std::to_string(e.next_id));
|
||||
|
||||
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(
|
||||
@@ -328,29 +328,29 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
AaRanks entry{};
|
||||
AaRanks e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.upper_hotkey_sid = atoi(row[1]);
|
||||
entry.lower_hotkey_sid = atoi(row[2]);
|
||||
entry.title_sid = atoi(row[3]);
|
||||
entry.desc_sid = atoi(row[4]);
|
||||
entry.cost = atoi(row[5]);
|
||||
entry.level_req = atoi(row[6]);
|
||||
entry.spell = atoi(row[7]);
|
||||
entry.spell_type = atoi(row[8]);
|
||||
entry.recast_time = atoi(row[9]);
|
||||
entry.expansion = atoi(row[10]);
|
||||
entry.prev_id = atoi(row[11]);
|
||||
entry.next_id = atoi(row[12]);
|
||||
e.id = atoi(row[0]);
|
||||
e.upper_hotkey_sid = atoi(row[1]);
|
||||
e.lower_hotkey_sid = atoi(row[2]);
|
||||
e.title_sid = atoi(row[3]);
|
||||
e.desc_sid = atoi(row[4]);
|
||||
e.cost = atoi(row[5]);
|
||||
e.level_req = atoi(row[6]);
|
||||
e.spell = atoi(row[7]);
|
||||
e.spell_type = atoi(row[8]);
|
||||
e.recast_time = atoi(row[9]);
|
||||
e.expansion = atoi(row[10]);
|
||||
e.prev_id = atoi(row[11]);
|
||||
e.next_id = atoi(row[12]);
|
||||
|
||||
all_entries.push_back(entry);
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<AaRanks> GetWhere(Database& db, std::string where_filter)
|
||||
static std::vector<AaRanks> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<AaRanks> all_entries;
|
||||
|
||||
@@ -365,29 +365,29 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
AaRanks entry{};
|
||||
AaRanks e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.upper_hotkey_sid = atoi(row[1]);
|
||||
entry.lower_hotkey_sid = atoi(row[2]);
|
||||
entry.title_sid = atoi(row[3]);
|
||||
entry.desc_sid = atoi(row[4]);
|
||||
entry.cost = atoi(row[5]);
|
||||
entry.level_req = atoi(row[6]);
|
||||
entry.spell = atoi(row[7]);
|
||||
entry.spell_type = atoi(row[8]);
|
||||
entry.recast_time = atoi(row[9]);
|
||||
entry.expansion = atoi(row[10]);
|
||||
entry.prev_id = atoi(row[11]);
|
||||
entry.next_id = atoi(row[12]);
|
||||
e.id = atoi(row[0]);
|
||||
e.upper_hotkey_sid = atoi(row[1]);
|
||||
e.lower_hotkey_sid = atoi(row[2]);
|
||||
e.title_sid = atoi(row[3]);
|
||||
e.desc_sid = atoi(row[4]);
|
||||
e.cost = atoi(row[5]);
|
||||
e.level_req = atoi(row[6]);
|
||||
e.spell = atoi(row[7]);
|
||||
e.spell_type = atoi(row[8]);
|
||||
e.recast_time = atoi(row[9]);
|
||||
e.expansion = atoi(row[10]);
|
||||
e.prev_id = atoi(row[11]);
|
||||
e.next_id = atoi(row[12]);
|
||||
|
||||
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(
|
||||
@@ -412,6 +412,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_AA_RANKS_REPOSITORY_H
|
||||
|
||||
Reference in New Issue
Block a user