[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
+150 -124
View File
@@ -115,27 +115,27 @@ public:
static Titles NewEntity()
{
Titles entry{};
Titles e{};
entry.id = 0;
entry.skill_id = -1;
entry.min_skill_value = -1;
entry.max_skill_value = -1;
entry.min_aa_points = -1;
entry.max_aa_points = -1;
entry.class_ = -1;
entry.gender = -1;
entry.char_id = -1;
entry.status = -1;
entry.item_id = -1;
entry.prefix = "";
entry.suffix = "";
entry.title_set = 0;
e.id = 0;
e.skill_id = -1;
e.min_skill_value = -1;
e.max_skill_value = -1;
e.min_aa_points = -1;
e.max_aa_points = -1;
e.class_ = -1;
e.gender = -1;
e.char_id = -1;
e.status = -1;
e.item_id = -1;
e.prefix = "";
e.suffix = "";
e.title_set = 0;
return entry;
return e;
}
static Titles GetTitlesEntry(
static Titles GetTitles(
const std::vector<Titles> &titless,
int titles_id
)
@@ -164,24 +164,24 @@ public:
auto row = results.begin();
if (results.RowCount() == 1) {
Titles entry{};
Titles e{};
entry.id = atoi(row[0]);
entry.skill_id = atoi(row[1]);
entry.min_skill_value = atoi(row[2]);
entry.max_skill_value = atoi(row[3]);
entry.min_aa_points = atoi(row[4]);
entry.max_aa_points = atoi(row[5]);
entry.class_ = atoi(row[6]);
entry.gender = atoi(row[7]);
entry.char_id = atoi(row[8]);
entry.status = atoi(row[9]);
entry.item_id = atoi(row[10]);
entry.prefix = row[11] ? row[11] : "";
entry.suffix = row[12] ? row[12] : "";
entry.title_set = atoi(row[13]);
e.id = atoi(row[0]);
e.skill_id = atoi(row[1]);
e.min_skill_value = atoi(row[2]);
e.max_skill_value = atoi(row[3]);
e.min_aa_points = atoi(row[4]);
e.max_aa_points = atoi(row[5]);
e.class_ = atoi(row[6]);
e.gender = atoi(row[7]);
e.char_id = atoi(row[8]);
e.status = atoi(row[9]);
e.item_id = atoi(row[10]);
e.prefix = row[11] ? row[11] : "";
e.suffix = row[12] ? row[12] : "";
e.title_set = atoi(row[13]);
return entry;
return e;
}
return NewEntity();
@@ -206,34 +206,34 @@ public:
static int UpdateOne(
Database& db,
Titles titles_entry
const Titles &e
)
{
std::vector<std::string> update_values;
std::vector<std::string> v;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(titles_entry.skill_id));
update_values.push_back(columns[2] + " = " + std::to_string(titles_entry.min_skill_value));
update_values.push_back(columns[3] + " = " + std::to_string(titles_entry.max_skill_value));
update_values.push_back(columns[4] + " = " + std::to_string(titles_entry.min_aa_points));
update_values.push_back(columns[5] + " = " + std::to_string(titles_entry.max_aa_points));
update_values.push_back(columns[6] + " = " + std::to_string(titles_entry.class_));
update_values.push_back(columns[7] + " = " + std::to_string(titles_entry.gender));
update_values.push_back(columns[8] + " = " + std::to_string(titles_entry.char_id));
update_values.push_back(columns[9] + " = " + std::to_string(titles_entry.status));
update_values.push_back(columns[10] + " = " + std::to_string(titles_entry.item_id));
update_values.push_back(columns[11] + " = '" + Strings::Escape(titles_entry.prefix) + "'");
update_values.push_back(columns[12] + " = '" + Strings::Escape(titles_entry.suffix) + "'");
update_values.push_back(columns[13] + " = " + std::to_string(titles_entry.title_set));
v.push_back(columns[1] + " = " + std::to_string(e.skill_id));
v.push_back(columns[2] + " = " + std::to_string(e.min_skill_value));
v.push_back(columns[3] + " = " + std::to_string(e.max_skill_value));
v.push_back(columns[4] + " = " + std::to_string(e.min_aa_points));
v.push_back(columns[5] + " = " + std::to_string(e.max_aa_points));
v.push_back(columns[6] + " = " + std::to_string(e.class_));
v.push_back(columns[7] + " = " + std::to_string(e.gender));
v.push_back(columns[8] + " = " + std::to_string(e.char_id));
v.push_back(columns[9] + " = " + std::to_string(e.status));
v.push_back(columns[10] + " = " + std::to_string(e.item_id));
v.push_back(columns[11] + " = '" + Strings::Escape(e.prefix) + "'");
v.push_back(columns[12] + " = '" + Strings::Escape(e.suffix) + "'");
v.push_back(columns[13] + " = " + std::to_string(e.title_set));
auto results = db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
Strings::Implode(", ", update_values),
Strings::Implode(", ", v),
PrimaryKey(),
titles_entry.id
e.id
)
);
@@ -242,73 +242,73 @@ public:
static Titles InsertOne(
Database& db,
Titles titles_entry
Titles e
)
{
std::vector<std::string> insert_values;
std::vector<std::string> v;
insert_values.push_back(std::to_string(titles_entry.id));
insert_values.push_back(std::to_string(titles_entry.skill_id));
insert_values.push_back(std::to_string(titles_entry.min_skill_value));
insert_values.push_back(std::to_string(titles_entry.max_skill_value));
insert_values.push_back(std::to_string(titles_entry.min_aa_points));
insert_values.push_back(std::to_string(titles_entry.max_aa_points));
insert_values.push_back(std::to_string(titles_entry.class_));
insert_values.push_back(std::to_string(titles_entry.gender));
insert_values.push_back(std::to_string(titles_entry.char_id));
insert_values.push_back(std::to_string(titles_entry.status));
insert_values.push_back(std::to_string(titles_entry.item_id));
insert_values.push_back("'" + Strings::Escape(titles_entry.prefix) + "'");
insert_values.push_back("'" + Strings::Escape(titles_entry.suffix) + "'");
insert_values.push_back(std::to_string(titles_entry.title_set));
v.push_back(std::to_string(e.id));
v.push_back(std::to_string(e.skill_id));
v.push_back(std::to_string(e.min_skill_value));
v.push_back(std::to_string(e.max_skill_value));
v.push_back(std::to_string(e.min_aa_points));
v.push_back(std::to_string(e.max_aa_points));
v.push_back(std::to_string(e.class_));
v.push_back(std::to_string(e.gender));
v.push_back(std::to_string(e.char_id));
v.push_back(std::to_string(e.status));
v.push_back(std::to_string(e.item_id));
v.push_back("'" + Strings::Escape(e.prefix) + "'");
v.push_back("'" + Strings::Escape(e.suffix) + "'");
v.push_back(std::to_string(e.title_set));
auto results = db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
Strings::Implode(",", insert_values)
Strings::Implode(",", v)
)
);
if (results.Success()) {
titles_entry.id = results.LastInsertedID();
return titles_entry;
e.id = results.LastInsertedID();
return e;
}
titles_entry = NewEntity();
e = NewEntity();
return titles_entry;
return e;
}
static int InsertMany(
Database& db,
std::vector<Titles> titles_entries
const std::vector<Titles> &entries
)
{
std::vector<std::string> insert_chunks;
for (auto &titles_entry: titles_entries) {
std::vector<std::string> insert_values;
for (auto &e: entries) {
std::vector<std::string> v;
insert_values.push_back(std::to_string(titles_entry.id));
insert_values.push_back(std::to_string(titles_entry.skill_id));
insert_values.push_back(std::to_string(titles_entry.min_skill_value));
insert_values.push_back(std::to_string(titles_entry.max_skill_value));
insert_values.push_back(std::to_string(titles_entry.min_aa_points));
insert_values.push_back(std::to_string(titles_entry.max_aa_points));
insert_values.push_back(std::to_string(titles_entry.class_));
insert_values.push_back(std::to_string(titles_entry.gender));
insert_values.push_back(std::to_string(titles_entry.char_id));
insert_values.push_back(std::to_string(titles_entry.status));
insert_values.push_back(std::to_string(titles_entry.item_id));
insert_values.push_back("'" + Strings::Escape(titles_entry.prefix) + "'");
insert_values.push_back("'" + Strings::Escape(titles_entry.suffix) + "'");
insert_values.push_back(std::to_string(titles_entry.title_set));
v.push_back(std::to_string(e.id));
v.push_back(std::to_string(e.skill_id));
v.push_back(std::to_string(e.min_skill_value));
v.push_back(std::to_string(e.max_skill_value));
v.push_back(std::to_string(e.min_aa_points));
v.push_back(std::to_string(e.max_aa_points));
v.push_back(std::to_string(e.class_));
v.push_back(std::to_string(e.gender));
v.push_back(std::to_string(e.char_id));
v.push_back(std::to_string(e.status));
v.push_back(std::to_string(e.item_id));
v.push_back("'" + Strings::Escape(e.prefix) + "'");
v.push_back("'" + Strings::Escape(e.suffix) + "'");
v.push_back(std::to_string(e.title_set));
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(
@@ -335,30 +335,30 @@ public:
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Titles entry{};
Titles e{};
entry.id = atoi(row[0]);
entry.skill_id = atoi(row[1]);
entry.min_skill_value = atoi(row[2]);
entry.max_skill_value = atoi(row[3]);
entry.min_aa_points = atoi(row[4]);
entry.max_aa_points = atoi(row[5]);
entry.class_ = atoi(row[6]);
entry.gender = atoi(row[7]);
entry.char_id = atoi(row[8]);
entry.status = atoi(row[9]);
entry.item_id = atoi(row[10]);
entry.prefix = row[11] ? row[11] : "";
entry.suffix = row[12] ? row[12] : "";
entry.title_set = atoi(row[13]);
e.id = atoi(row[0]);
e.skill_id = atoi(row[1]);
e.min_skill_value = atoi(row[2]);
e.max_skill_value = atoi(row[3]);
e.min_aa_points = atoi(row[4]);
e.max_aa_points = atoi(row[5]);
e.class_ = atoi(row[6]);
e.gender = atoi(row[7]);
e.char_id = atoi(row[8]);
e.status = atoi(row[9]);
e.item_id = atoi(row[10]);
e.prefix = row[11] ? row[11] : "";
e.suffix = row[12] ? row[12] : "";
e.title_set = atoi(row[13]);
all_entries.push_back(entry);
all_entries.push_back(e);
}
return all_entries;
}
static std::vector<Titles> GetWhere(Database& db, std::string where_filter)
static std::vector<Titles> GetWhere(Database& db, const std::string &where_filter)
{
std::vector<Titles> all_entries;
@@ -373,30 +373,30 @@ public:
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Titles entry{};
Titles e{};
entry.id = atoi(row[0]);
entry.skill_id = atoi(row[1]);
entry.min_skill_value = atoi(row[2]);
entry.max_skill_value = atoi(row[3]);
entry.min_aa_points = atoi(row[4]);
entry.max_aa_points = atoi(row[5]);
entry.class_ = atoi(row[6]);
entry.gender = atoi(row[7]);
entry.char_id = atoi(row[8]);
entry.status = atoi(row[9]);
entry.item_id = atoi(row[10]);
entry.prefix = row[11] ? row[11] : "";
entry.suffix = row[12] ? row[12] : "";
entry.title_set = atoi(row[13]);
e.id = atoi(row[0]);
e.skill_id = atoi(row[1]);
e.min_skill_value = atoi(row[2]);
e.max_skill_value = atoi(row[3]);
e.min_aa_points = atoi(row[4]);
e.max_aa_points = atoi(row[5]);
e.class_ = atoi(row[6]);
e.gender = atoi(row[7]);
e.char_id = atoi(row[8]);
e.status = atoi(row[9]);
e.item_id = atoi(row[10]);
e.prefix = row[11] ? row[11] : "";
e.suffix = row[12] ? row[12] : "";
e.title_set = atoi(row[13]);
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(
@@ -421,6 +421,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_TITLES_REPOSITORY_H