[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
@@ -112,26 +112,26 @@ public:
static StartingItems NewEntity()
{
StartingItems entry{};
StartingItems e{};
entry.id = 0;
entry.race = 0;
entry.class_ = 0;
entry.deityid = 0;
entry.zoneid = 0;
entry.itemid = 0;
entry.item_charges = 1;
entry.gm = 0;
entry.slot = -1;
entry.min_expansion = -1;
entry.max_expansion = -1;
entry.content_flags = "";
entry.content_flags_disabled = "";
e.id = 0;
e.race = 0;
e.class_ = 0;
e.deityid = 0;
e.zoneid = 0;
e.itemid = 0;
e.item_charges = 1;
e.gm = 0;
e.slot = -1;
e.min_expansion = -1;
e.max_expansion = -1;
e.content_flags = "";
e.content_flags_disabled = "";
return entry;
return e;
}
static StartingItems GetStartingItemsEntry(
static StartingItems GetStartingItems(
const std::vector<StartingItems> &starting_itemss,
int starting_items_id
)
@@ -160,23 +160,23 @@ public:
auto row = results.begin();
if (results.RowCount() == 1) {
StartingItems entry{};
StartingItems e{};
entry.id = atoi(row[0]);
entry.race = atoi(row[1]);
entry.class_ = atoi(row[2]);
entry.deityid = atoi(row[3]);
entry.zoneid = atoi(row[4]);
entry.itemid = atoi(row[5]);
entry.item_charges = atoi(row[6]);
entry.gm = atoi(row[7]);
entry.slot = atoi(row[8]);
entry.min_expansion = atoi(row[9]);
entry.max_expansion = atoi(row[10]);
entry.content_flags = row[11] ? row[11] : "";
entry.content_flags_disabled = row[12] ? row[12] : "";
e.id = atoi(row[0]);
e.race = atoi(row[1]);
e.class_ = atoi(row[2]);
e.deityid = atoi(row[3]);
e.zoneid = atoi(row[4]);
e.itemid = atoi(row[5]);
e.item_charges = atoi(row[6]);
e.gm = atoi(row[7]);
e.slot = atoi(row[8]);
e.min_expansion = atoi(row[9]);
e.max_expansion = atoi(row[10]);
e.content_flags = row[11] ? row[11] : "";
e.content_flags_disabled = row[12] ? row[12] : "";
return entry;
return e;
}
return NewEntity();
@@ -201,33 +201,33 @@ public:
static int UpdateOne(
Database& db,
StartingItems starting_items_entry
const StartingItems &e
)
{
std::vector<std::string> update_values;
std::vector<std::string> v;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(starting_items_entry.race));
update_values.push_back(columns[2] + " = " + std::to_string(starting_items_entry.class_));
update_values.push_back(columns[3] + " = " + std::to_string(starting_items_entry.deityid));
update_values.push_back(columns[4] + " = " + std::to_string(starting_items_entry.zoneid));
update_values.push_back(columns[5] + " = " + std::to_string(starting_items_entry.itemid));
update_values.push_back(columns[6] + " = " + std::to_string(starting_items_entry.item_charges));
update_values.push_back(columns[7] + " = " + std::to_string(starting_items_entry.gm));
update_values.push_back(columns[8] + " = " + std::to_string(starting_items_entry.slot));
update_values.push_back(columns[9] + " = " + std::to_string(starting_items_entry.min_expansion));
update_values.push_back(columns[10] + " = " + std::to_string(starting_items_entry.max_expansion));
update_values.push_back(columns[11] + " = '" + Strings::Escape(starting_items_entry.content_flags) + "'");
update_values.push_back(columns[12] + " = '" + Strings::Escape(starting_items_entry.content_flags_disabled) + "'");
v.push_back(columns[1] + " = " + std::to_string(e.race));
v.push_back(columns[2] + " = " + std::to_string(e.class_));
v.push_back(columns[3] + " = " + std::to_string(e.deityid));
v.push_back(columns[4] + " = " + std::to_string(e.zoneid));
v.push_back(columns[5] + " = " + std::to_string(e.itemid));
v.push_back(columns[6] + " = " + std::to_string(e.item_charges));
v.push_back(columns[7] + " = " + std::to_string(e.gm));
v.push_back(columns[8] + " = " + std::to_string(e.slot));
v.push_back(columns[9] + " = " + std::to_string(e.min_expansion));
v.push_back(columns[10] + " = " + std::to_string(e.max_expansion));
v.push_back(columns[11] + " = '" + Strings::Escape(e.content_flags) + "'");
v.push_back(columns[12] + " = '" + Strings::Escape(e.content_flags_disabled) + "'");
auto results = db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
Strings::Implode(", ", update_values),
Strings::Implode(", ", v),
PrimaryKey(),
starting_items_entry.id
e.id
)
);
@@ -236,71 +236,71 @@ public:
static StartingItems InsertOne(
Database& db,
StartingItems starting_items_entry
StartingItems e
)
{
std::vector<std::string> insert_values;
std::vector<std::string> v;
insert_values.push_back(std::to_string(starting_items_entry.id));
insert_values.push_back(std::to_string(starting_items_entry.race));
insert_values.push_back(std::to_string(starting_items_entry.class_));
insert_values.push_back(std::to_string(starting_items_entry.deityid));
insert_values.push_back(std::to_string(starting_items_entry.zoneid));
insert_values.push_back(std::to_string(starting_items_entry.itemid));
insert_values.push_back(std::to_string(starting_items_entry.item_charges));
insert_values.push_back(std::to_string(starting_items_entry.gm));
insert_values.push_back(std::to_string(starting_items_entry.slot));
insert_values.push_back(std::to_string(starting_items_entry.min_expansion));
insert_values.push_back(std::to_string(starting_items_entry.max_expansion));
insert_values.push_back("'" + Strings::Escape(starting_items_entry.content_flags) + "'");
insert_values.push_back("'" + Strings::Escape(starting_items_entry.content_flags_disabled) + "'");
v.push_back(std::to_string(e.id));
v.push_back(std::to_string(e.race));
v.push_back(std::to_string(e.class_));
v.push_back(std::to_string(e.deityid));
v.push_back(std::to_string(e.zoneid));
v.push_back(std::to_string(e.itemid));
v.push_back(std::to_string(e.item_charges));
v.push_back(std::to_string(e.gm));
v.push_back(std::to_string(e.slot));
v.push_back(std::to_string(e.min_expansion));
v.push_back(std::to_string(e.max_expansion));
v.push_back("'" + Strings::Escape(e.content_flags) + "'");
v.push_back("'" + Strings::Escape(e.content_flags_disabled) + "'");
auto results = db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
Strings::Implode(",", insert_values)
Strings::Implode(",", v)
)
);
if (results.Success()) {
starting_items_entry.id = results.LastInsertedID();
return starting_items_entry;
e.id = results.LastInsertedID();
return e;
}
starting_items_entry = NewEntity();
e = NewEntity();
return starting_items_entry;
return e;
}
static int InsertMany(
Database& db,
std::vector<StartingItems> starting_items_entries
const std::vector<StartingItems> &entries
)
{
std::vector<std::string> insert_chunks;
for (auto &starting_items_entry: starting_items_entries) {
std::vector<std::string> insert_values;
for (auto &e: entries) {
std::vector<std::string> v;
insert_values.push_back(std::to_string(starting_items_entry.id));
insert_values.push_back(std::to_string(starting_items_entry.race));
insert_values.push_back(std::to_string(starting_items_entry.class_));
insert_values.push_back(std::to_string(starting_items_entry.deityid));
insert_values.push_back(std::to_string(starting_items_entry.zoneid));
insert_values.push_back(std::to_string(starting_items_entry.itemid));
insert_values.push_back(std::to_string(starting_items_entry.item_charges));
insert_values.push_back(std::to_string(starting_items_entry.gm));
insert_values.push_back(std::to_string(starting_items_entry.slot));
insert_values.push_back(std::to_string(starting_items_entry.min_expansion));
insert_values.push_back(std::to_string(starting_items_entry.max_expansion));
insert_values.push_back("'" + Strings::Escape(starting_items_entry.content_flags) + "'");
insert_values.push_back("'" + Strings::Escape(starting_items_entry.content_flags_disabled) + "'");
v.push_back(std::to_string(e.id));
v.push_back(std::to_string(e.race));
v.push_back(std::to_string(e.class_));
v.push_back(std::to_string(e.deityid));
v.push_back(std::to_string(e.zoneid));
v.push_back(std::to_string(e.itemid));
v.push_back(std::to_string(e.item_charges));
v.push_back(std::to_string(e.gm));
v.push_back(std::to_string(e.slot));
v.push_back(std::to_string(e.min_expansion));
v.push_back(std::to_string(e.max_expansion));
v.push_back("'" + Strings::Escape(e.content_flags) + "'");
v.push_back("'" + Strings::Escape(e.content_flags_disabled) + "'");
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(
@@ -327,29 +327,29 @@ public:
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
StartingItems entry{};
StartingItems e{};
entry.id = atoi(row[0]);
entry.race = atoi(row[1]);
entry.class_ = atoi(row[2]);
entry.deityid = atoi(row[3]);
entry.zoneid = atoi(row[4]);
entry.itemid = atoi(row[5]);
entry.item_charges = atoi(row[6]);
entry.gm = atoi(row[7]);
entry.slot = atoi(row[8]);
entry.min_expansion = atoi(row[9]);
entry.max_expansion = atoi(row[10]);
entry.content_flags = row[11] ? row[11] : "";
entry.content_flags_disabled = row[12] ? row[12] : "";
e.id = atoi(row[0]);
e.race = atoi(row[1]);
e.class_ = atoi(row[2]);
e.deityid = atoi(row[3]);
e.zoneid = atoi(row[4]);
e.itemid = atoi(row[5]);
e.item_charges = atoi(row[6]);
e.gm = atoi(row[7]);
e.slot = atoi(row[8]);
e.min_expansion = atoi(row[9]);
e.max_expansion = atoi(row[10]);
e.content_flags = row[11] ? row[11] : "";
e.content_flags_disabled = row[12] ? row[12] : "";
all_entries.push_back(entry);
all_entries.push_back(e);
}
return all_entries;
}
static std::vector<StartingItems> GetWhere(Database& db, std::string where_filter)
static std::vector<StartingItems> GetWhere(Database& db, const std::string &where_filter)
{
std::vector<StartingItems> all_entries;
@@ -364,29 +364,29 @@ public:
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
StartingItems entry{};
StartingItems e{};
entry.id = atoi(row[0]);
entry.race = atoi(row[1]);
entry.class_ = atoi(row[2]);
entry.deityid = atoi(row[3]);
entry.zoneid = atoi(row[4]);
entry.itemid = atoi(row[5]);
entry.item_charges = atoi(row[6]);
entry.gm = atoi(row[7]);
entry.slot = atoi(row[8]);
entry.min_expansion = atoi(row[9]);
entry.max_expansion = atoi(row[10]);
entry.content_flags = row[11] ? row[11] : "";
entry.content_flags_disabled = row[12] ? row[12] : "";
e.id = atoi(row[0]);
e.race = atoi(row[1]);
e.class_ = atoi(row[2]);
e.deityid = atoi(row[3]);
e.zoneid = atoi(row[4]);
e.itemid = atoi(row[5]);
e.item_charges = atoi(row[6]);
e.gm = atoi(row[7]);
e.slot = atoi(row[8]);
e.min_expansion = atoi(row[9]);
e.max_expansion = atoi(row[10]);
e.content_flags = row[11] ? row[11] : "";
e.content_flags_disabled = row[12] ? 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(
@@ -411,6 +411,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_STARTING_ITEMS_REPOSITORY_H