[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:
Chris Miles
2022-08-13 18:40:56 -05:00
committed by GitHub
parent b79e1947f1
commit 79285b1002
374 changed files with 26837 additions and 26020 deletions
@@ -100,22 +100,22 @@ public:
static Lfguild NewEntity()
{
Lfguild entry{};
Lfguild e{};
entry.type = 0;
entry.name = "";
entry.comment = "";
entry.fromlevel = 0;
entry.tolevel = 0;
entry.classes = 0;
entry.aacount = 0;
entry.timezone = 0;
entry.timeposted = 0;
e.type = 0;
e.name = "";
e.comment = "";
e.fromlevel = 0;
e.tolevel = 0;
e.classes = 0;
e.aacount = 0;
e.timezone = 0;
e.timeposted = 0;
return entry;
return e;
}
static Lfguild GetLfguildEntry(
static Lfguild GetLfguild(
const std::vector<Lfguild> &lfguilds,
int lfguild_id
)
@@ -144,19 +144,19 @@ public:
auto row = results.begin();
if (results.RowCount() == 1) {
Lfguild entry{};
Lfguild e{};
entry.type = atoi(row[0]);
entry.name = row[1] ? row[1] : "";
entry.comment = row[2] ? row[2] : "";
entry.fromlevel = atoi(row[3]);
entry.tolevel = atoi(row[4]);
entry.classes = atoi(row[5]);
entry.aacount = atoi(row[6]);
entry.timezone = atoi(row[7]);
entry.timeposted = atoi(row[8]);
e.type = atoi(row[0]);
e.name = row[1] ? row[1] : "";
e.comment = row[2] ? row[2] : "";
e.fromlevel = atoi(row[3]);
e.tolevel = atoi(row[4]);
e.classes = atoi(row[5]);
e.aacount = atoi(row[6]);
e.timezone = atoi(row[7]);
e.timeposted = atoi(row[8]);
return entry;
return e;
}
return NewEntity();
@@ -181,30 +181,30 @@ public:
static int UpdateOne(
Database& db,
Lfguild lfguild_entry
const Lfguild &e
)
{
std::vector<std::string> update_values;
std::vector<std::string> v;
auto columns = Columns();
update_values.push_back(columns[0] + " = " + std::to_string(lfguild_entry.type));
update_values.push_back(columns[1] + " = '" + Strings::Escape(lfguild_entry.name) + "'");
update_values.push_back(columns[2] + " = '" + Strings::Escape(lfguild_entry.comment) + "'");
update_values.push_back(columns[3] + " = " + std::to_string(lfguild_entry.fromlevel));
update_values.push_back(columns[4] + " = " + std::to_string(lfguild_entry.tolevel));
update_values.push_back(columns[5] + " = " + std::to_string(lfguild_entry.classes));
update_values.push_back(columns[6] + " = " + std::to_string(lfguild_entry.aacount));
update_values.push_back(columns[7] + " = " + std::to_string(lfguild_entry.timezone));
update_values.push_back(columns[8] + " = " + std::to_string(lfguild_entry.timeposted));
v.push_back(columns[0] + " = " + std::to_string(e.type));
v.push_back(columns[1] + " = '" + Strings::Escape(e.name) + "'");
v.push_back(columns[2] + " = '" + Strings::Escape(e.comment) + "'");
v.push_back(columns[3] + " = " + std::to_string(e.fromlevel));
v.push_back(columns[4] + " = " + std::to_string(e.tolevel));
v.push_back(columns[5] + " = " + std::to_string(e.classes));
v.push_back(columns[6] + " = " + std::to_string(e.aacount));
v.push_back(columns[7] + " = " + std::to_string(e.timezone));
v.push_back(columns[8] + " = " + std::to_string(e.timeposted));
auto results = db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
Strings::Implode(", ", update_values),
Strings::Implode(", ", v),
PrimaryKey(),
lfguild_entry.type
e.type
)
);
@@ -213,63 +213,63 @@ public:
static Lfguild InsertOne(
Database& db,
Lfguild lfguild_entry
Lfguild e
)
{
std::vector<std::string> insert_values;
std::vector<std::string> v;
insert_values.push_back(std::to_string(lfguild_entry.type));
insert_values.push_back("'" + Strings::Escape(lfguild_entry.name) + "'");
insert_values.push_back("'" + Strings::Escape(lfguild_entry.comment) + "'");
insert_values.push_back(std::to_string(lfguild_entry.fromlevel));
insert_values.push_back(std::to_string(lfguild_entry.tolevel));
insert_values.push_back(std::to_string(lfguild_entry.classes));
insert_values.push_back(std::to_string(lfguild_entry.aacount));
insert_values.push_back(std::to_string(lfguild_entry.timezone));
insert_values.push_back(std::to_string(lfguild_entry.timeposted));
v.push_back(std::to_string(e.type));
v.push_back("'" + Strings::Escape(e.name) + "'");
v.push_back("'" + Strings::Escape(e.comment) + "'");
v.push_back(std::to_string(e.fromlevel));
v.push_back(std::to_string(e.tolevel));
v.push_back(std::to_string(e.classes));
v.push_back(std::to_string(e.aacount));
v.push_back(std::to_string(e.timezone));
v.push_back(std::to_string(e.timeposted));
auto results = db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
Strings::Implode(",", insert_values)
Strings::Implode(",", v)
)
);
if (results.Success()) {
lfguild_entry.type = results.LastInsertedID();
return lfguild_entry;
e.type = results.LastInsertedID();
return e;
}
lfguild_entry = NewEntity();
e = NewEntity();
return lfguild_entry;
return e;
}
static int InsertMany(
Database& db,
std::vector<Lfguild> lfguild_entries
const std::vector<Lfguild> &entries
)
{
std::vector<std::string> insert_chunks;
for (auto &lfguild_entry: lfguild_entries) {
std::vector<std::string> insert_values;
for (auto &e: entries) {
std::vector<std::string> v;
insert_values.push_back(std::to_string(lfguild_entry.type));
insert_values.push_back("'" + Strings::Escape(lfguild_entry.name) + "'");
insert_values.push_back("'" + Strings::Escape(lfguild_entry.comment) + "'");
insert_values.push_back(std::to_string(lfguild_entry.fromlevel));
insert_values.push_back(std::to_string(lfguild_entry.tolevel));
insert_values.push_back(std::to_string(lfguild_entry.classes));
insert_values.push_back(std::to_string(lfguild_entry.aacount));
insert_values.push_back(std::to_string(lfguild_entry.timezone));
insert_values.push_back(std::to_string(lfguild_entry.timeposted));
v.push_back(std::to_string(e.type));
v.push_back("'" + Strings::Escape(e.name) + "'");
v.push_back("'" + Strings::Escape(e.comment) + "'");
v.push_back(std::to_string(e.fromlevel));
v.push_back(std::to_string(e.tolevel));
v.push_back(std::to_string(e.classes));
v.push_back(std::to_string(e.aacount));
v.push_back(std::to_string(e.timezone));
v.push_back(std::to_string(e.timeposted));
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(
@@ -296,25 +296,25 @@ public:
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Lfguild entry{};
Lfguild e{};
entry.type = atoi(row[0]);
entry.name = row[1] ? row[1] : "";
entry.comment = row[2] ? row[2] : "";
entry.fromlevel = atoi(row[3]);
entry.tolevel = atoi(row[4]);
entry.classes = atoi(row[5]);
entry.aacount = atoi(row[6]);
entry.timezone = atoi(row[7]);
entry.timeposted = atoi(row[8]);
e.type = atoi(row[0]);
e.name = row[1] ? row[1] : "";
e.comment = row[2] ? row[2] : "";
e.fromlevel = atoi(row[3]);
e.tolevel = atoi(row[4]);
e.classes = atoi(row[5]);
e.aacount = atoi(row[6]);
e.timezone = atoi(row[7]);
e.timeposted = atoi(row[8]);
all_entries.push_back(entry);
all_entries.push_back(e);
}
return all_entries;
}
static std::vector<Lfguild> GetWhere(Database& db, std::string where_filter)
static std::vector<Lfguild> GetWhere(Database& db, const std::string &where_filter)
{
std::vector<Lfguild> all_entries;
@@ -329,25 +329,25 @@ public:
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Lfguild entry{};
Lfguild e{};
entry.type = atoi(row[0]);
entry.name = row[1] ? row[1] : "";
entry.comment = row[2] ? row[2] : "";
entry.fromlevel = atoi(row[3]);
entry.tolevel = atoi(row[4]);
entry.classes = atoi(row[5]);
entry.aacount = atoi(row[6]);
entry.timezone = atoi(row[7]);
entry.timeposted = atoi(row[8]);
e.type = atoi(row[0]);
e.name = row[1] ? row[1] : "";
e.comment = row[2] ? row[2] : "";
e.fromlevel = atoi(row[3]);
e.tolevel = atoi(row[4]);
e.classes = atoi(row[5]);
e.aacount = atoi(row[6]);
e.timezone = atoi(row[7]);
e.timeposted = 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(
@@ -372,6 +372,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_LFGUILD_REPOSITORY_H