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:
@@ -121,29 +121,29 @@ public:
|
||||
|
||||
static Petitions NewEntity()
|
||||
{
|
||||
Petitions entry{};
|
||||
Petitions e{};
|
||||
|
||||
entry.dib = 0;
|
||||
entry.petid = 0;
|
||||
entry.charname = "";
|
||||
entry.accountname = "";
|
||||
entry.lastgm = "";
|
||||
entry.petitiontext = "";
|
||||
entry.gmtext = "";
|
||||
entry.zone = "";
|
||||
entry.urgency = 0;
|
||||
entry.charclass = 0;
|
||||
entry.charrace = 0;
|
||||
entry.charlevel = 0;
|
||||
entry.checkouts = 0;
|
||||
entry.unavailables = 0;
|
||||
entry.ischeckedout = 0;
|
||||
entry.senttime = 0;
|
||||
e.dib = 0;
|
||||
e.petid = 0;
|
||||
e.charname = "";
|
||||
e.accountname = "";
|
||||
e.lastgm = "";
|
||||
e.petitiontext = "";
|
||||
e.gmtext = "";
|
||||
e.zone = "";
|
||||
e.urgency = 0;
|
||||
e.charclass = 0;
|
||||
e.charrace = 0;
|
||||
e.charlevel = 0;
|
||||
e.checkouts = 0;
|
||||
e.unavailables = 0;
|
||||
e.ischeckedout = 0;
|
||||
e.senttime = 0;
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static Petitions GetPetitionsEntry(
|
||||
static Petitions GetPetitions(
|
||||
const std::vector<Petitions> &petitionss,
|
||||
int petitions_id
|
||||
)
|
||||
@@ -172,26 +172,26 @@ public:
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
Petitions entry{};
|
||||
Petitions e{};
|
||||
|
||||
entry.dib = atoi(row[0]);
|
||||
entry.petid = atoi(row[1]);
|
||||
entry.charname = row[2] ? row[2] : "";
|
||||
entry.accountname = row[3] ? row[3] : "";
|
||||
entry.lastgm = row[4] ? row[4] : "";
|
||||
entry.petitiontext = row[5] ? row[5] : "";
|
||||
entry.gmtext = row[6] ? row[6] : "";
|
||||
entry.zone = row[7] ? row[7] : "";
|
||||
entry.urgency = atoi(row[8]);
|
||||
entry.charclass = atoi(row[9]);
|
||||
entry.charrace = atoi(row[10]);
|
||||
entry.charlevel = atoi(row[11]);
|
||||
entry.checkouts = atoi(row[12]);
|
||||
entry.unavailables = atoi(row[13]);
|
||||
entry.ischeckedout = atoi(row[14]);
|
||||
entry.senttime = strtoll(row[15], nullptr, 10);
|
||||
e.dib = atoi(row[0]);
|
||||
e.petid = atoi(row[1]);
|
||||
e.charname = row[2] ? row[2] : "";
|
||||
e.accountname = row[3] ? row[3] : "";
|
||||
e.lastgm = row[4] ? row[4] : "";
|
||||
e.petitiontext = row[5] ? row[5] : "";
|
||||
e.gmtext = row[6] ? row[6] : "";
|
||||
e.zone = row[7] ? row[7] : "";
|
||||
e.urgency = atoi(row[8]);
|
||||
e.charclass = atoi(row[9]);
|
||||
e.charrace = atoi(row[10]);
|
||||
e.charlevel = atoi(row[11]);
|
||||
e.checkouts = atoi(row[12]);
|
||||
e.unavailables = atoi(row[13]);
|
||||
e.ischeckedout = atoi(row[14]);
|
||||
e.senttime = strtoll(row[15], nullptr, 10);
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
@@ -216,36 +216,36 @@ public:
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
Petitions petitions_entry
|
||||
const Petitions &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> update_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
update_values.push_back(columns[1] + " = " + std::to_string(petitions_entry.petid));
|
||||
update_values.push_back(columns[2] + " = '" + Strings::Escape(petitions_entry.charname) + "'");
|
||||
update_values.push_back(columns[3] + " = '" + Strings::Escape(petitions_entry.accountname) + "'");
|
||||
update_values.push_back(columns[4] + " = '" + Strings::Escape(petitions_entry.lastgm) + "'");
|
||||
update_values.push_back(columns[5] + " = '" + Strings::Escape(petitions_entry.petitiontext) + "'");
|
||||
update_values.push_back(columns[6] + " = '" + Strings::Escape(petitions_entry.gmtext) + "'");
|
||||
update_values.push_back(columns[7] + " = '" + Strings::Escape(petitions_entry.zone) + "'");
|
||||
update_values.push_back(columns[8] + " = " + std::to_string(petitions_entry.urgency));
|
||||
update_values.push_back(columns[9] + " = " + std::to_string(petitions_entry.charclass));
|
||||
update_values.push_back(columns[10] + " = " + std::to_string(petitions_entry.charrace));
|
||||
update_values.push_back(columns[11] + " = " + std::to_string(petitions_entry.charlevel));
|
||||
update_values.push_back(columns[12] + " = " + std::to_string(petitions_entry.checkouts));
|
||||
update_values.push_back(columns[13] + " = " + std::to_string(petitions_entry.unavailables));
|
||||
update_values.push_back(columns[14] + " = " + std::to_string(petitions_entry.ischeckedout));
|
||||
update_values.push_back(columns[15] + " = " + std::to_string(petitions_entry.senttime));
|
||||
v.push_back(columns[1] + " = " + std::to_string(e.petid));
|
||||
v.push_back(columns[2] + " = '" + Strings::Escape(e.charname) + "'");
|
||||
v.push_back(columns[3] + " = '" + Strings::Escape(e.accountname) + "'");
|
||||
v.push_back(columns[4] + " = '" + Strings::Escape(e.lastgm) + "'");
|
||||
v.push_back(columns[5] + " = '" + Strings::Escape(e.petitiontext) + "'");
|
||||
v.push_back(columns[6] + " = '" + Strings::Escape(e.gmtext) + "'");
|
||||
v.push_back(columns[7] + " = '" + Strings::Escape(e.zone) + "'");
|
||||
v.push_back(columns[8] + " = " + std::to_string(e.urgency));
|
||||
v.push_back(columns[9] + " = " + std::to_string(e.charclass));
|
||||
v.push_back(columns[10] + " = " + std::to_string(e.charrace));
|
||||
v.push_back(columns[11] + " = " + std::to_string(e.charlevel));
|
||||
v.push_back(columns[12] + " = " + std::to_string(e.checkouts));
|
||||
v.push_back(columns[13] + " = " + std::to_string(e.unavailables));
|
||||
v.push_back(columns[14] + " = " + std::to_string(e.ischeckedout));
|
||||
v.push_back(columns[15] + " = " + std::to_string(e.senttime));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", update_values),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
petitions_entry.dib
|
||||
e.dib
|
||||
)
|
||||
);
|
||||
|
||||
@@ -254,77 +254,77 @@ public:
|
||||
|
||||
static Petitions InsertOne(
|
||||
Database& db,
|
||||
Petitions petitions_entry
|
||||
Petitions e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(petitions_entry.dib));
|
||||
insert_values.push_back(std::to_string(petitions_entry.petid));
|
||||
insert_values.push_back("'" + Strings::Escape(petitions_entry.charname) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(petitions_entry.accountname) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(petitions_entry.lastgm) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(petitions_entry.petitiontext) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(petitions_entry.gmtext) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(petitions_entry.zone) + "'");
|
||||
insert_values.push_back(std::to_string(petitions_entry.urgency));
|
||||
insert_values.push_back(std::to_string(petitions_entry.charclass));
|
||||
insert_values.push_back(std::to_string(petitions_entry.charrace));
|
||||
insert_values.push_back(std::to_string(petitions_entry.charlevel));
|
||||
insert_values.push_back(std::to_string(petitions_entry.checkouts));
|
||||
insert_values.push_back(std::to_string(petitions_entry.unavailables));
|
||||
insert_values.push_back(std::to_string(petitions_entry.ischeckedout));
|
||||
insert_values.push_back(std::to_string(petitions_entry.senttime));
|
||||
v.push_back(std::to_string(e.dib));
|
||||
v.push_back(std::to_string(e.petid));
|
||||
v.push_back("'" + Strings::Escape(e.charname) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.accountname) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.lastgm) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.petitiontext) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.gmtext) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.zone) + "'");
|
||||
v.push_back(std::to_string(e.urgency));
|
||||
v.push_back(std::to_string(e.charclass));
|
||||
v.push_back(std::to_string(e.charrace));
|
||||
v.push_back(std::to_string(e.charlevel));
|
||||
v.push_back(std::to_string(e.checkouts));
|
||||
v.push_back(std::to_string(e.unavailables));
|
||||
v.push_back(std::to_string(e.ischeckedout));
|
||||
v.push_back(std::to_string(e.senttime));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseInsert(),
|
||||
Strings::Implode(",", insert_values)
|
||||
Strings::Implode(",", v)
|
||||
)
|
||||
);
|
||||
|
||||
if (results.Success()) {
|
||||
petitions_entry.dib = results.LastInsertedID();
|
||||
return petitions_entry;
|
||||
e.dib = results.LastInsertedID();
|
||||
return e;
|
||||
}
|
||||
|
||||
petitions_entry = NewEntity();
|
||||
e = NewEntity();
|
||||
|
||||
return petitions_entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
Database& db,
|
||||
std::vector<Petitions> petitions_entries
|
||||
const std::vector<Petitions> &entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &petitions_entry: petitions_entries) {
|
||||
std::vector<std::string> insert_values;
|
||||
for (auto &e: entries) {
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(petitions_entry.dib));
|
||||
insert_values.push_back(std::to_string(petitions_entry.petid));
|
||||
insert_values.push_back("'" + Strings::Escape(petitions_entry.charname) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(petitions_entry.accountname) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(petitions_entry.lastgm) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(petitions_entry.petitiontext) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(petitions_entry.gmtext) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(petitions_entry.zone) + "'");
|
||||
insert_values.push_back(std::to_string(petitions_entry.urgency));
|
||||
insert_values.push_back(std::to_string(petitions_entry.charclass));
|
||||
insert_values.push_back(std::to_string(petitions_entry.charrace));
|
||||
insert_values.push_back(std::to_string(petitions_entry.charlevel));
|
||||
insert_values.push_back(std::to_string(petitions_entry.checkouts));
|
||||
insert_values.push_back(std::to_string(petitions_entry.unavailables));
|
||||
insert_values.push_back(std::to_string(petitions_entry.ischeckedout));
|
||||
insert_values.push_back(std::to_string(petitions_entry.senttime));
|
||||
v.push_back(std::to_string(e.dib));
|
||||
v.push_back(std::to_string(e.petid));
|
||||
v.push_back("'" + Strings::Escape(e.charname) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.accountname) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.lastgm) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.petitiontext) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.gmtext) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.zone) + "'");
|
||||
v.push_back(std::to_string(e.urgency));
|
||||
v.push_back(std::to_string(e.charclass));
|
||||
v.push_back(std::to_string(e.charrace));
|
||||
v.push_back(std::to_string(e.charlevel));
|
||||
v.push_back(std::to_string(e.checkouts));
|
||||
v.push_back(std::to_string(e.unavailables));
|
||||
v.push_back(std::to_string(e.ischeckedout));
|
||||
v.push_back(std::to_string(e.senttime));
|
||||
|
||||
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(
|
||||
@@ -351,32 +351,32 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
Petitions entry{};
|
||||
Petitions e{};
|
||||
|
||||
entry.dib = atoi(row[0]);
|
||||
entry.petid = atoi(row[1]);
|
||||
entry.charname = row[2] ? row[2] : "";
|
||||
entry.accountname = row[3] ? row[3] : "";
|
||||
entry.lastgm = row[4] ? row[4] : "";
|
||||
entry.petitiontext = row[5] ? row[5] : "";
|
||||
entry.gmtext = row[6] ? row[6] : "";
|
||||
entry.zone = row[7] ? row[7] : "";
|
||||
entry.urgency = atoi(row[8]);
|
||||
entry.charclass = atoi(row[9]);
|
||||
entry.charrace = atoi(row[10]);
|
||||
entry.charlevel = atoi(row[11]);
|
||||
entry.checkouts = atoi(row[12]);
|
||||
entry.unavailables = atoi(row[13]);
|
||||
entry.ischeckedout = atoi(row[14]);
|
||||
entry.senttime = strtoll(row[15], nullptr, 10);
|
||||
e.dib = atoi(row[0]);
|
||||
e.petid = atoi(row[1]);
|
||||
e.charname = row[2] ? row[2] : "";
|
||||
e.accountname = row[3] ? row[3] : "";
|
||||
e.lastgm = row[4] ? row[4] : "";
|
||||
e.petitiontext = row[5] ? row[5] : "";
|
||||
e.gmtext = row[6] ? row[6] : "";
|
||||
e.zone = row[7] ? row[7] : "";
|
||||
e.urgency = atoi(row[8]);
|
||||
e.charclass = atoi(row[9]);
|
||||
e.charrace = atoi(row[10]);
|
||||
e.charlevel = atoi(row[11]);
|
||||
e.checkouts = atoi(row[12]);
|
||||
e.unavailables = atoi(row[13]);
|
||||
e.ischeckedout = atoi(row[14]);
|
||||
e.senttime = strtoll(row[15], nullptr, 10);
|
||||
|
||||
all_entries.push_back(entry);
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<Petitions> GetWhere(Database& db, std::string where_filter)
|
||||
static std::vector<Petitions> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<Petitions> all_entries;
|
||||
|
||||
@@ -391,32 +391,32 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
Petitions entry{};
|
||||
Petitions e{};
|
||||
|
||||
entry.dib = atoi(row[0]);
|
||||
entry.petid = atoi(row[1]);
|
||||
entry.charname = row[2] ? row[2] : "";
|
||||
entry.accountname = row[3] ? row[3] : "";
|
||||
entry.lastgm = row[4] ? row[4] : "";
|
||||
entry.petitiontext = row[5] ? row[5] : "";
|
||||
entry.gmtext = row[6] ? row[6] : "";
|
||||
entry.zone = row[7] ? row[7] : "";
|
||||
entry.urgency = atoi(row[8]);
|
||||
entry.charclass = atoi(row[9]);
|
||||
entry.charrace = atoi(row[10]);
|
||||
entry.charlevel = atoi(row[11]);
|
||||
entry.checkouts = atoi(row[12]);
|
||||
entry.unavailables = atoi(row[13]);
|
||||
entry.ischeckedout = atoi(row[14]);
|
||||
entry.senttime = strtoll(row[15], nullptr, 10);
|
||||
e.dib = atoi(row[0]);
|
||||
e.petid = atoi(row[1]);
|
||||
e.charname = row[2] ? row[2] : "";
|
||||
e.accountname = row[3] ? row[3] : "";
|
||||
e.lastgm = row[4] ? row[4] : "";
|
||||
e.petitiontext = row[5] ? row[5] : "";
|
||||
e.gmtext = row[6] ? row[6] : "";
|
||||
e.zone = row[7] ? row[7] : "";
|
||||
e.urgency = atoi(row[8]);
|
||||
e.charclass = atoi(row[9]);
|
||||
e.charrace = atoi(row[10]);
|
||||
e.charlevel = atoi(row[11]);
|
||||
e.checkouts = atoi(row[12]);
|
||||
e.unavailables = atoi(row[13]);
|
||||
e.ischeckedout = atoi(row[14]);
|
||||
e.senttime = strtoll(row[15], nullptr, 10);
|
||||
|
||||
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(
|
||||
@@ -441,6 +441,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_PETITIONS_REPOSITORY_H
|
||||
|
||||
Reference in New Issue
Block a user