[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
+192 -166
View File
@@ -133,33 +133,33 @@ public:
static Spawn2 NewEntity()
{
Spawn2 entry{};
Spawn2 e{};
entry.id = 0;
entry.spawngroupID = 0;
entry.zone = "";
entry.version = 0;
entry.x = 0.000000;
entry.y = 0.000000;
entry.z = 0.000000;
entry.heading = 0.000000;
entry.respawntime = 0;
entry.variance = 0;
entry.pathgrid = 0;
entry.path_when_zone_idle = 0;
entry._condition = 0;
entry.cond_value = 1;
entry.enabled = 1;
entry.animation = 0;
entry.min_expansion = -1;
entry.max_expansion = -1;
entry.content_flags = "";
entry.content_flags_disabled = "";
e.id = 0;
e.spawngroupID = 0;
e.zone = "";
e.version = 0;
e.x = 0.000000;
e.y = 0.000000;
e.z = 0.000000;
e.heading = 0.000000;
e.respawntime = 0;
e.variance = 0;
e.pathgrid = 0;
e.path_when_zone_idle = 0;
e._condition = 0;
e.cond_value = 1;
e.enabled = 1;
e.animation = 0;
e.min_expansion = -1;
e.max_expansion = -1;
e.content_flags = "";
e.content_flags_disabled = "";
return entry;
return e;
}
static Spawn2 GetSpawn2Entry(
static Spawn2 GetSpawn2(
const std::vector<Spawn2> &spawn2s,
int spawn2_id
)
@@ -188,30 +188,30 @@ public:
auto row = results.begin();
if (results.RowCount() == 1) {
Spawn2 entry{};
Spawn2 e{};
entry.id = atoi(row[0]);
entry.spawngroupID = atoi(row[1]);
entry.zone = row[2] ? row[2] : "";
entry.version = atoi(row[3]);
entry.x = static_cast<float>(atof(row[4]));
entry.y = static_cast<float>(atof(row[5]));
entry.z = static_cast<float>(atof(row[6]));
entry.heading = static_cast<float>(atof(row[7]));
entry.respawntime = atoi(row[8]);
entry.variance = atoi(row[9]);
entry.pathgrid = atoi(row[10]);
entry.path_when_zone_idle = atoi(row[11]);
entry._condition = atoi(row[12]);
entry.cond_value = atoi(row[13]);
entry.enabled = atoi(row[14]);
entry.animation = atoi(row[15]);
entry.min_expansion = atoi(row[16]);
entry.max_expansion = atoi(row[17]);
entry.content_flags = row[18] ? row[18] : "";
entry.content_flags_disabled = row[19] ? row[19] : "";
e.id = atoi(row[0]);
e.spawngroupID = atoi(row[1]);
e.zone = row[2] ? row[2] : "";
e.version = atoi(row[3]);
e.x = static_cast<float>(atof(row[4]));
e.y = static_cast<float>(atof(row[5]));
e.z = static_cast<float>(atof(row[6]));
e.heading = static_cast<float>(atof(row[7]));
e.respawntime = atoi(row[8]);
e.variance = atoi(row[9]);
e.pathgrid = atoi(row[10]);
e.path_when_zone_idle = atoi(row[11]);
e._condition = atoi(row[12]);
e.cond_value = atoi(row[13]);
e.enabled = atoi(row[14]);
e.animation = atoi(row[15]);
e.min_expansion = atoi(row[16]);
e.max_expansion = atoi(row[17]);
e.content_flags = row[18] ? row[18] : "";
e.content_flags_disabled = row[19] ? row[19] : "";
return entry;
return e;
}
return NewEntity();
@@ -236,40 +236,40 @@ public:
static int UpdateOne(
Database& db,
Spawn2 spawn2_entry
const Spawn2 &e
)
{
std::vector<std::string> update_values;
std::vector<std::string> v;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(spawn2_entry.spawngroupID));
update_values.push_back(columns[2] + " = '" + Strings::Escape(spawn2_entry.zone) + "'");
update_values.push_back(columns[3] + " = " + std::to_string(spawn2_entry.version));
update_values.push_back(columns[4] + " = " + std::to_string(spawn2_entry.x));
update_values.push_back(columns[5] + " = " + std::to_string(spawn2_entry.y));
update_values.push_back(columns[6] + " = " + std::to_string(spawn2_entry.z));
update_values.push_back(columns[7] + " = " + std::to_string(spawn2_entry.heading));
update_values.push_back(columns[8] + " = " + std::to_string(spawn2_entry.respawntime));
update_values.push_back(columns[9] + " = " + std::to_string(spawn2_entry.variance));
update_values.push_back(columns[10] + " = " + std::to_string(spawn2_entry.pathgrid));
update_values.push_back(columns[11] + " = " + std::to_string(spawn2_entry.path_when_zone_idle));
update_values.push_back(columns[12] + " = " + std::to_string(spawn2_entry._condition));
update_values.push_back(columns[13] + " = " + std::to_string(spawn2_entry.cond_value));
update_values.push_back(columns[14] + " = " + std::to_string(spawn2_entry.enabled));
update_values.push_back(columns[15] + " = " + std::to_string(spawn2_entry.animation));
update_values.push_back(columns[16] + " = " + std::to_string(spawn2_entry.min_expansion));
update_values.push_back(columns[17] + " = " + std::to_string(spawn2_entry.max_expansion));
update_values.push_back(columns[18] + " = '" + Strings::Escape(spawn2_entry.content_flags) + "'");
update_values.push_back(columns[19] + " = '" + Strings::Escape(spawn2_entry.content_flags_disabled) + "'");
v.push_back(columns[1] + " = " + std::to_string(e.spawngroupID));
v.push_back(columns[2] + " = '" + Strings::Escape(e.zone) + "'");
v.push_back(columns[3] + " = " + std::to_string(e.version));
v.push_back(columns[4] + " = " + std::to_string(e.x));
v.push_back(columns[5] + " = " + std::to_string(e.y));
v.push_back(columns[6] + " = " + std::to_string(e.z));
v.push_back(columns[7] + " = " + std::to_string(e.heading));
v.push_back(columns[8] + " = " + std::to_string(e.respawntime));
v.push_back(columns[9] + " = " + std::to_string(e.variance));
v.push_back(columns[10] + " = " + std::to_string(e.pathgrid));
v.push_back(columns[11] + " = " + std::to_string(e.path_when_zone_idle));
v.push_back(columns[12] + " = " + std::to_string(e._condition));
v.push_back(columns[13] + " = " + std::to_string(e.cond_value));
v.push_back(columns[14] + " = " + std::to_string(e.enabled));
v.push_back(columns[15] + " = " + std::to_string(e.animation));
v.push_back(columns[16] + " = " + std::to_string(e.min_expansion));
v.push_back(columns[17] + " = " + std::to_string(e.max_expansion));
v.push_back(columns[18] + " = '" + Strings::Escape(e.content_flags) + "'");
v.push_back(columns[19] + " = '" + Strings::Escape(e.content_flags_disabled) + "'");
auto results = db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
Strings::Implode(", ", update_values),
Strings::Implode(", ", v),
PrimaryKey(),
spawn2_entry.id
e.id
)
);
@@ -278,85 +278,85 @@ public:
static Spawn2 InsertOne(
Database& db,
Spawn2 spawn2_entry
Spawn2 e
)
{
std::vector<std::string> insert_values;
std::vector<std::string> v;
insert_values.push_back(std::to_string(spawn2_entry.id));
insert_values.push_back(std::to_string(spawn2_entry.spawngroupID));
insert_values.push_back("'" + Strings::Escape(spawn2_entry.zone) + "'");
insert_values.push_back(std::to_string(spawn2_entry.version));
insert_values.push_back(std::to_string(spawn2_entry.x));
insert_values.push_back(std::to_string(spawn2_entry.y));
insert_values.push_back(std::to_string(spawn2_entry.z));
insert_values.push_back(std::to_string(spawn2_entry.heading));
insert_values.push_back(std::to_string(spawn2_entry.respawntime));
insert_values.push_back(std::to_string(spawn2_entry.variance));
insert_values.push_back(std::to_string(spawn2_entry.pathgrid));
insert_values.push_back(std::to_string(spawn2_entry.path_when_zone_idle));
insert_values.push_back(std::to_string(spawn2_entry._condition));
insert_values.push_back(std::to_string(spawn2_entry.cond_value));
insert_values.push_back(std::to_string(spawn2_entry.enabled));
insert_values.push_back(std::to_string(spawn2_entry.animation));
insert_values.push_back(std::to_string(spawn2_entry.min_expansion));
insert_values.push_back(std::to_string(spawn2_entry.max_expansion));
insert_values.push_back("'" + Strings::Escape(spawn2_entry.content_flags) + "'");
insert_values.push_back("'" + Strings::Escape(spawn2_entry.content_flags_disabled) + "'");
v.push_back(std::to_string(e.id));
v.push_back(std::to_string(e.spawngroupID));
v.push_back("'" + Strings::Escape(e.zone) + "'");
v.push_back(std::to_string(e.version));
v.push_back(std::to_string(e.x));
v.push_back(std::to_string(e.y));
v.push_back(std::to_string(e.z));
v.push_back(std::to_string(e.heading));
v.push_back(std::to_string(e.respawntime));
v.push_back(std::to_string(e.variance));
v.push_back(std::to_string(e.pathgrid));
v.push_back(std::to_string(e.path_when_zone_idle));
v.push_back(std::to_string(e._condition));
v.push_back(std::to_string(e.cond_value));
v.push_back(std::to_string(e.enabled));
v.push_back(std::to_string(e.animation));
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()) {
spawn2_entry.id = results.LastInsertedID();
return spawn2_entry;
e.id = results.LastInsertedID();
return e;
}
spawn2_entry = NewEntity();
e = NewEntity();
return spawn2_entry;
return e;
}
static int InsertMany(
Database& db,
std::vector<Spawn2> spawn2_entries
const std::vector<Spawn2> &entries
)
{
std::vector<std::string> insert_chunks;
for (auto &spawn2_entry: spawn2_entries) {
std::vector<std::string> insert_values;
for (auto &e: entries) {
std::vector<std::string> v;
insert_values.push_back(std::to_string(spawn2_entry.id));
insert_values.push_back(std::to_string(spawn2_entry.spawngroupID));
insert_values.push_back("'" + Strings::Escape(spawn2_entry.zone) + "'");
insert_values.push_back(std::to_string(spawn2_entry.version));
insert_values.push_back(std::to_string(spawn2_entry.x));
insert_values.push_back(std::to_string(spawn2_entry.y));
insert_values.push_back(std::to_string(spawn2_entry.z));
insert_values.push_back(std::to_string(spawn2_entry.heading));
insert_values.push_back(std::to_string(spawn2_entry.respawntime));
insert_values.push_back(std::to_string(spawn2_entry.variance));
insert_values.push_back(std::to_string(spawn2_entry.pathgrid));
insert_values.push_back(std::to_string(spawn2_entry.path_when_zone_idle));
insert_values.push_back(std::to_string(spawn2_entry._condition));
insert_values.push_back(std::to_string(spawn2_entry.cond_value));
insert_values.push_back(std::to_string(spawn2_entry.enabled));
insert_values.push_back(std::to_string(spawn2_entry.animation));
insert_values.push_back(std::to_string(spawn2_entry.min_expansion));
insert_values.push_back(std::to_string(spawn2_entry.max_expansion));
insert_values.push_back("'" + Strings::Escape(spawn2_entry.content_flags) + "'");
insert_values.push_back("'" + Strings::Escape(spawn2_entry.content_flags_disabled) + "'");
v.push_back(std::to_string(e.id));
v.push_back(std::to_string(e.spawngroupID));
v.push_back("'" + Strings::Escape(e.zone) + "'");
v.push_back(std::to_string(e.version));
v.push_back(std::to_string(e.x));
v.push_back(std::to_string(e.y));
v.push_back(std::to_string(e.z));
v.push_back(std::to_string(e.heading));
v.push_back(std::to_string(e.respawntime));
v.push_back(std::to_string(e.variance));
v.push_back(std::to_string(e.pathgrid));
v.push_back(std::to_string(e.path_when_zone_idle));
v.push_back(std::to_string(e._condition));
v.push_back(std::to_string(e.cond_value));
v.push_back(std::to_string(e.enabled));
v.push_back(std::to_string(e.animation));
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(
@@ -383,36 +383,36 @@ public:
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Spawn2 entry{};
Spawn2 e{};
entry.id = atoi(row[0]);
entry.spawngroupID = atoi(row[1]);
entry.zone = row[2] ? row[2] : "";
entry.version = atoi(row[3]);
entry.x = static_cast<float>(atof(row[4]));
entry.y = static_cast<float>(atof(row[5]));
entry.z = static_cast<float>(atof(row[6]));
entry.heading = static_cast<float>(atof(row[7]));
entry.respawntime = atoi(row[8]);
entry.variance = atoi(row[9]);
entry.pathgrid = atoi(row[10]);
entry.path_when_zone_idle = atoi(row[11]);
entry._condition = atoi(row[12]);
entry.cond_value = atoi(row[13]);
entry.enabled = atoi(row[14]);
entry.animation = atoi(row[15]);
entry.min_expansion = atoi(row[16]);
entry.max_expansion = atoi(row[17]);
entry.content_flags = row[18] ? row[18] : "";
entry.content_flags_disabled = row[19] ? row[19] : "";
e.id = atoi(row[0]);
e.spawngroupID = atoi(row[1]);
e.zone = row[2] ? row[2] : "";
e.version = atoi(row[3]);
e.x = static_cast<float>(atof(row[4]));
e.y = static_cast<float>(atof(row[5]));
e.z = static_cast<float>(atof(row[6]));
e.heading = static_cast<float>(atof(row[7]));
e.respawntime = atoi(row[8]);
e.variance = atoi(row[9]);
e.pathgrid = atoi(row[10]);
e.path_when_zone_idle = atoi(row[11]);
e._condition = atoi(row[12]);
e.cond_value = atoi(row[13]);
e.enabled = atoi(row[14]);
e.animation = atoi(row[15]);
e.min_expansion = atoi(row[16]);
e.max_expansion = atoi(row[17]);
e.content_flags = row[18] ? row[18] : "";
e.content_flags_disabled = row[19] ? row[19] : "";
all_entries.push_back(entry);
all_entries.push_back(e);
}
return all_entries;
}
static std::vector<Spawn2> GetWhere(Database& db, std::string where_filter)
static std::vector<Spawn2> GetWhere(Database& db, const std::string &where_filter)
{
std::vector<Spawn2> all_entries;
@@ -427,36 +427,36 @@ public:
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Spawn2 entry{};
Spawn2 e{};
entry.id = atoi(row[0]);
entry.spawngroupID = atoi(row[1]);
entry.zone = row[2] ? row[2] : "";
entry.version = atoi(row[3]);
entry.x = static_cast<float>(atof(row[4]));
entry.y = static_cast<float>(atof(row[5]));
entry.z = static_cast<float>(atof(row[6]));
entry.heading = static_cast<float>(atof(row[7]));
entry.respawntime = atoi(row[8]);
entry.variance = atoi(row[9]);
entry.pathgrid = atoi(row[10]);
entry.path_when_zone_idle = atoi(row[11]);
entry._condition = atoi(row[12]);
entry.cond_value = atoi(row[13]);
entry.enabled = atoi(row[14]);
entry.animation = atoi(row[15]);
entry.min_expansion = atoi(row[16]);
entry.max_expansion = atoi(row[17]);
entry.content_flags = row[18] ? row[18] : "";
entry.content_flags_disabled = row[19] ? row[19] : "";
e.id = atoi(row[0]);
e.spawngroupID = atoi(row[1]);
e.zone = row[2] ? row[2] : "";
e.version = atoi(row[3]);
e.x = static_cast<float>(atof(row[4]));
e.y = static_cast<float>(atof(row[5]));
e.z = static_cast<float>(atof(row[6]));
e.heading = static_cast<float>(atof(row[7]));
e.respawntime = atoi(row[8]);
e.variance = atoi(row[9]);
e.pathgrid = atoi(row[10]);
e.path_when_zone_idle = atoi(row[11]);
e._condition = atoi(row[12]);
e.cond_value = atoi(row[13]);
e.enabled = atoi(row[14]);
e.animation = atoi(row[15]);
e.min_expansion = atoi(row[16]);
e.max_expansion = atoi(row[17]);
e.content_flags = row[18] ? row[18] : "";
e.content_flags_disabled = row[19] ? row[19] : "";
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(
@@ -481,6 +481,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_SPAWN2_REPOSITORY_H