mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-31 13:16:39 +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:
@@ -109,25 +109,25 @@ public:
|
||||
|
||||
static ObjectContents NewEntity()
|
||||
{
|
||||
ObjectContents entry{};
|
||||
ObjectContents e{};
|
||||
|
||||
entry.zoneid = 0;
|
||||
entry.parentid = 0;
|
||||
entry.bagidx = 0;
|
||||
entry.itemid = 0;
|
||||
entry.charges = 0;
|
||||
entry.droptime = 0;
|
||||
entry.augslot1 = 0;
|
||||
entry.augslot2 = 0;
|
||||
entry.augslot3 = 0;
|
||||
entry.augslot4 = 0;
|
||||
entry.augslot5 = 0;
|
||||
entry.augslot6 = 0;
|
||||
e.zoneid = 0;
|
||||
e.parentid = 0;
|
||||
e.bagidx = 0;
|
||||
e.itemid = 0;
|
||||
e.charges = 0;
|
||||
e.droptime = 0;
|
||||
e.augslot1 = 0;
|
||||
e.augslot2 = 0;
|
||||
e.augslot3 = 0;
|
||||
e.augslot4 = 0;
|
||||
e.augslot5 = 0;
|
||||
e.augslot6 = 0;
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static ObjectContents GetObjectContentsEntry(
|
||||
static ObjectContents GetObjectContents(
|
||||
const std::vector<ObjectContents> &object_contentss,
|
||||
int object_contents_id
|
||||
)
|
||||
@@ -156,22 +156,22 @@ public:
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
ObjectContents entry{};
|
||||
ObjectContents e{};
|
||||
|
||||
entry.zoneid = atoi(row[0]);
|
||||
entry.parentid = atoi(row[1]);
|
||||
entry.bagidx = atoi(row[2]);
|
||||
entry.itemid = atoi(row[3]);
|
||||
entry.charges = atoi(row[4]);
|
||||
entry.droptime = strtoll(row[5] ? row[5] : "-1", nullptr, 10);
|
||||
entry.augslot1 = atoi(row[6]);
|
||||
entry.augslot2 = atoi(row[7]);
|
||||
entry.augslot3 = atoi(row[8]);
|
||||
entry.augslot4 = atoi(row[9]);
|
||||
entry.augslot5 = atoi(row[10]);
|
||||
entry.augslot6 = atoi(row[11]);
|
||||
e.zoneid = atoi(row[0]);
|
||||
e.parentid = atoi(row[1]);
|
||||
e.bagidx = atoi(row[2]);
|
||||
e.itemid = atoi(row[3]);
|
||||
e.charges = atoi(row[4]);
|
||||
e.droptime = strtoll(row[5] ? row[5] : "-1", nullptr, 10);
|
||||
e.augslot1 = atoi(row[6]);
|
||||
e.augslot2 = atoi(row[7]);
|
||||
e.augslot3 = atoi(row[8]);
|
||||
e.augslot4 = atoi(row[9]);
|
||||
e.augslot5 = atoi(row[10]);
|
||||
e.augslot6 = atoi(row[11]);
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
@@ -196,33 +196,33 @@ public:
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
ObjectContents object_contents_entry
|
||||
const ObjectContents &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> update_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
update_values.push_back(columns[0] + " = " + std::to_string(object_contents_entry.zoneid));
|
||||
update_values.push_back(columns[1] + " = " + std::to_string(object_contents_entry.parentid));
|
||||
update_values.push_back(columns[2] + " = " + std::to_string(object_contents_entry.bagidx));
|
||||
update_values.push_back(columns[3] + " = " + std::to_string(object_contents_entry.itemid));
|
||||
update_values.push_back(columns[4] + " = " + std::to_string(object_contents_entry.charges));
|
||||
update_values.push_back(columns[5] + " = FROM_UNIXTIME(" + (object_contents_entry.droptime > 0 ? std::to_string(object_contents_entry.droptime) : "null") + ")");
|
||||
update_values.push_back(columns[6] + " = " + std::to_string(object_contents_entry.augslot1));
|
||||
update_values.push_back(columns[7] + " = " + std::to_string(object_contents_entry.augslot2));
|
||||
update_values.push_back(columns[8] + " = " + std::to_string(object_contents_entry.augslot3));
|
||||
update_values.push_back(columns[9] + " = " + std::to_string(object_contents_entry.augslot4));
|
||||
update_values.push_back(columns[10] + " = " + std::to_string(object_contents_entry.augslot5));
|
||||
update_values.push_back(columns[11] + " = " + std::to_string(object_contents_entry.augslot6));
|
||||
v.push_back(columns[0] + " = " + std::to_string(e.zoneid));
|
||||
v.push_back(columns[1] + " = " + std::to_string(e.parentid));
|
||||
v.push_back(columns[2] + " = " + std::to_string(e.bagidx));
|
||||
v.push_back(columns[3] + " = " + std::to_string(e.itemid));
|
||||
v.push_back(columns[4] + " = " + std::to_string(e.charges));
|
||||
v.push_back(columns[5] + " = FROM_UNIXTIME(" + (e.droptime > 0 ? std::to_string(e.droptime) : "null") + ")");
|
||||
v.push_back(columns[6] + " = " + std::to_string(e.augslot1));
|
||||
v.push_back(columns[7] + " = " + std::to_string(e.augslot2));
|
||||
v.push_back(columns[8] + " = " + std::to_string(e.augslot3));
|
||||
v.push_back(columns[9] + " = " + std::to_string(e.augslot4));
|
||||
v.push_back(columns[10] + " = " + std::to_string(e.augslot5));
|
||||
v.push_back(columns[11] + " = " + std::to_string(e.augslot6));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", update_values),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
object_contents_entry.parentid
|
||||
e.parentid
|
||||
)
|
||||
);
|
||||
|
||||
@@ -231,69 +231,69 @@ public:
|
||||
|
||||
static ObjectContents InsertOne(
|
||||
Database& db,
|
||||
ObjectContents object_contents_entry
|
||||
ObjectContents e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(object_contents_entry.zoneid));
|
||||
insert_values.push_back(std::to_string(object_contents_entry.parentid));
|
||||
insert_values.push_back(std::to_string(object_contents_entry.bagidx));
|
||||
insert_values.push_back(std::to_string(object_contents_entry.itemid));
|
||||
insert_values.push_back(std::to_string(object_contents_entry.charges));
|
||||
insert_values.push_back("FROM_UNIXTIME(" + (object_contents_entry.droptime > 0 ? std::to_string(object_contents_entry.droptime) : "null") + ")");
|
||||
insert_values.push_back(std::to_string(object_contents_entry.augslot1));
|
||||
insert_values.push_back(std::to_string(object_contents_entry.augslot2));
|
||||
insert_values.push_back(std::to_string(object_contents_entry.augslot3));
|
||||
insert_values.push_back(std::to_string(object_contents_entry.augslot4));
|
||||
insert_values.push_back(std::to_string(object_contents_entry.augslot5));
|
||||
insert_values.push_back(std::to_string(object_contents_entry.augslot6));
|
||||
v.push_back(std::to_string(e.zoneid));
|
||||
v.push_back(std::to_string(e.parentid));
|
||||
v.push_back(std::to_string(e.bagidx));
|
||||
v.push_back(std::to_string(e.itemid));
|
||||
v.push_back(std::to_string(e.charges));
|
||||
v.push_back("FROM_UNIXTIME(" + (e.droptime > 0 ? std::to_string(e.droptime) : "null") + ")");
|
||||
v.push_back(std::to_string(e.augslot1));
|
||||
v.push_back(std::to_string(e.augslot2));
|
||||
v.push_back(std::to_string(e.augslot3));
|
||||
v.push_back(std::to_string(e.augslot4));
|
||||
v.push_back(std::to_string(e.augslot5));
|
||||
v.push_back(std::to_string(e.augslot6));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseInsert(),
|
||||
Strings::Implode(",", insert_values)
|
||||
Strings::Implode(",", v)
|
||||
)
|
||||
);
|
||||
|
||||
if (results.Success()) {
|
||||
object_contents_entry.parentid = results.LastInsertedID();
|
||||
return object_contents_entry;
|
||||
e.parentid = results.LastInsertedID();
|
||||
return e;
|
||||
}
|
||||
|
||||
object_contents_entry = NewEntity();
|
||||
e = NewEntity();
|
||||
|
||||
return object_contents_entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
Database& db,
|
||||
std::vector<ObjectContents> object_contents_entries
|
||||
const std::vector<ObjectContents> &entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &object_contents_entry: object_contents_entries) {
|
||||
std::vector<std::string> insert_values;
|
||||
for (auto &e: entries) {
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(object_contents_entry.zoneid));
|
||||
insert_values.push_back(std::to_string(object_contents_entry.parentid));
|
||||
insert_values.push_back(std::to_string(object_contents_entry.bagidx));
|
||||
insert_values.push_back(std::to_string(object_contents_entry.itemid));
|
||||
insert_values.push_back(std::to_string(object_contents_entry.charges));
|
||||
insert_values.push_back("FROM_UNIXTIME(" + (object_contents_entry.droptime > 0 ? std::to_string(object_contents_entry.droptime) : "null") + ")");
|
||||
insert_values.push_back(std::to_string(object_contents_entry.augslot1));
|
||||
insert_values.push_back(std::to_string(object_contents_entry.augslot2));
|
||||
insert_values.push_back(std::to_string(object_contents_entry.augslot3));
|
||||
insert_values.push_back(std::to_string(object_contents_entry.augslot4));
|
||||
insert_values.push_back(std::to_string(object_contents_entry.augslot5));
|
||||
insert_values.push_back(std::to_string(object_contents_entry.augslot6));
|
||||
v.push_back(std::to_string(e.zoneid));
|
||||
v.push_back(std::to_string(e.parentid));
|
||||
v.push_back(std::to_string(e.bagidx));
|
||||
v.push_back(std::to_string(e.itemid));
|
||||
v.push_back(std::to_string(e.charges));
|
||||
v.push_back("FROM_UNIXTIME(" + (e.droptime > 0 ? std::to_string(e.droptime) : "null") + ")");
|
||||
v.push_back(std::to_string(e.augslot1));
|
||||
v.push_back(std::to_string(e.augslot2));
|
||||
v.push_back(std::to_string(e.augslot3));
|
||||
v.push_back(std::to_string(e.augslot4));
|
||||
v.push_back(std::to_string(e.augslot5));
|
||||
v.push_back(std::to_string(e.augslot6));
|
||||
|
||||
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(
|
||||
@@ -320,28 +320,28 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
ObjectContents entry{};
|
||||
ObjectContents e{};
|
||||
|
||||
entry.zoneid = atoi(row[0]);
|
||||
entry.parentid = atoi(row[1]);
|
||||
entry.bagidx = atoi(row[2]);
|
||||
entry.itemid = atoi(row[3]);
|
||||
entry.charges = atoi(row[4]);
|
||||
entry.droptime = strtoll(row[5] ? row[5] : "-1", nullptr, 10);
|
||||
entry.augslot1 = atoi(row[6]);
|
||||
entry.augslot2 = atoi(row[7]);
|
||||
entry.augslot3 = atoi(row[8]);
|
||||
entry.augslot4 = atoi(row[9]);
|
||||
entry.augslot5 = atoi(row[10]);
|
||||
entry.augslot6 = atoi(row[11]);
|
||||
e.zoneid = atoi(row[0]);
|
||||
e.parentid = atoi(row[1]);
|
||||
e.bagidx = atoi(row[2]);
|
||||
e.itemid = atoi(row[3]);
|
||||
e.charges = atoi(row[4]);
|
||||
e.droptime = strtoll(row[5] ? row[5] : "-1", nullptr, 10);
|
||||
e.augslot1 = atoi(row[6]);
|
||||
e.augslot2 = atoi(row[7]);
|
||||
e.augslot3 = atoi(row[8]);
|
||||
e.augslot4 = atoi(row[9]);
|
||||
e.augslot5 = atoi(row[10]);
|
||||
e.augslot6 = atoi(row[11]);
|
||||
|
||||
all_entries.push_back(entry);
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<ObjectContents> GetWhere(Database& db, std::string where_filter)
|
||||
static std::vector<ObjectContents> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<ObjectContents> all_entries;
|
||||
|
||||
@@ -356,28 +356,28 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
ObjectContents entry{};
|
||||
ObjectContents e{};
|
||||
|
||||
entry.zoneid = atoi(row[0]);
|
||||
entry.parentid = atoi(row[1]);
|
||||
entry.bagidx = atoi(row[2]);
|
||||
entry.itemid = atoi(row[3]);
|
||||
entry.charges = atoi(row[4]);
|
||||
entry.droptime = strtoll(row[5] ? row[5] : "-1", nullptr, 10);
|
||||
entry.augslot1 = atoi(row[6]);
|
||||
entry.augslot2 = atoi(row[7]);
|
||||
entry.augslot3 = atoi(row[8]);
|
||||
entry.augslot4 = atoi(row[9]);
|
||||
entry.augslot5 = atoi(row[10]);
|
||||
entry.augslot6 = atoi(row[11]);
|
||||
e.zoneid = atoi(row[0]);
|
||||
e.parentid = atoi(row[1]);
|
||||
e.bagidx = atoi(row[2]);
|
||||
e.itemid = atoi(row[3]);
|
||||
e.charges = atoi(row[4]);
|
||||
e.droptime = strtoll(row[5] ? row[5] : "-1", nullptr, 10);
|
||||
e.augslot1 = atoi(row[6]);
|
||||
e.augslot2 = atoi(row[7]);
|
||||
e.augslot3 = atoi(row[8]);
|
||||
e.augslot4 = atoi(row[9]);
|
||||
e.augslot5 = atoi(row[10]);
|
||||
e.augslot6 = atoi(row[11]);
|
||||
|
||||
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(
|
||||
@@ -402,6 +402,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_OBJECT_CONTENTS_REPOSITORY_H
|
||||
|
||||
Reference in New Issue
Block a user