mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-23 12:38:21 +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:
@@ -91,19 +91,19 @@ public:
|
||||
|
||||
static QuestGlobals NewEntity()
|
||||
{
|
||||
QuestGlobals entry{};
|
||||
QuestGlobals e{};
|
||||
|
||||
entry.charid = 0;
|
||||
entry.npcid = 0;
|
||||
entry.zoneid = 0;
|
||||
entry.name = "";
|
||||
entry.value = "?";
|
||||
entry.expdate = 0;
|
||||
e.charid = 0;
|
||||
e.npcid = 0;
|
||||
e.zoneid = 0;
|
||||
e.name = "";
|
||||
e.value = "?";
|
||||
e.expdate = 0;
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static QuestGlobals GetQuestGlobalsEntry(
|
||||
static QuestGlobals GetQuestGlobals(
|
||||
const std::vector<QuestGlobals> &quest_globalss,
|
||||
int quest_globals_id
|
||||
)
|
||||
@@ -132,16 +132,16 @@ public:
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
QuestGlobals entry{};
|
||||
QuestGlobals e{};
|
||||
|
||||
entry.charid = atoi(row[0]);
|
||||
entry.npcid = atoi(row[1]);
|
||||
entry.zoneid = atoi(row[2]);
|
||||
entry.name = row[3] ? row[3] : "";
|
||||
entry.value = row[4] ? row[4] : "";
|
||||
entry.expdate = atoi(row[5]);
|
||||
e.charid = atoi(row[0]);
|
||||
e.npcid = atoi(row[1]);
|
||||
e.zoneid = atoi(row[2]);
|
||||
e.name = row[3] ? row[3] : "";
|
||||
e.value = row[4] ? row[4] : "";
|
||||
e.expdate = atoi(row[5]);
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
@@ -166,27 +166,27 @@ public:
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
QuestGlobals quest_globals_entry
|
||||
const QuestGlobals &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> update_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
update_values.push_back(columns[0] + " = " + std::to_string(quest_globals_entry.charid));
|
||||
update_values.push_back(columns[1] + " = " + std::to_string(quest_globals_entry.npcid));
|
||||
update_values.push_back(columns[2] + " = " + std::to_string(quest_globals_entry.zoneid));
|
||||
update_values.push_back(columns[3] + " = '" + Strings::Escape(quest_globals_entry.name) + "'");
|
||||
update_values.push_back(columns[4] + " = '" + Strings::Escape(quest_globals_entry.value) + "'");
|
||||
update_values.push_back(columns[5] + " = " + std::to_string(quest_globals_entry.expdate));
|
||||
v.push_back(columns[0] + " = " + std::to_string(e.charid));
|
||||
v.push_back(columns[1] + " = " + std::to_string(e.npcid));
|
||||
v.push_back(columns[2] + " = " + std::to_string(e.zoneid));
|
||||
v.push_back(columns[3] + " = '" + Strings::Escape(e.name) + "'");
|
||||
v.push_back(columns[4] + " = '" + Strings::Escape(e.value) + "'");
|
||||
v.push_back(columns[5] + " = " + std::to_string(e.expdate));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", update_values),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
quest_globals_entry.charid
|
||||
e.charid
|
||||
)
|
||||
);
|
||||
|
||||
@@ -195,57 +195,57 @@ public:
|
||||
|
||||
static QuestGlobals InsertOne(
|
||||
Database& db,
|
||||
QuestGlobals quest_globals_entry
|
||||
QuestGlobals e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(quest_globals_entry.charid));
|
||||
insert_values.push_back(std::to_string(quest_globals_entry.npcid));
|
||||
insert_values.push_back(std::to_string(quest_globals_entry.zoneid));
|
||||
insert_values.push_back("'" + Strings::Escape(quest_globals_entry.name) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(quest_globals_entry.value) + "'");
|
||||
insert_values.push_back(std::to_string(quest_globals_entry.expdate));
|
||||
v.push_back(std::to_string(e.charid));
|
||||
v.push_back(std::to_string(e.npcid));
|
||||
v.push_back(std::to_string(e.zoneid));
|
||||
v.push_back("'" + Strings::Escape(e.name) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.value) + "'");
|
||||
v.push_back(std::to_string(e.expdate));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseInsert(),
|
||||
Strings::Implode(",", insert_values)
|
||||
Strings::Implode(",", v)
|
||||
)
|
||||
);
|
||||
|
||||
if (results.Success()) {
|
||||
quest_globals_entry.charid = results.LastInsertedID();
|
||||
return quest_globals_entry;
|
||||
e.charid = results.LastInsertedID();
|
||||
return e;
|
||||
}
|
||||
|
||||
quest_globals_entry = NewEntity();
|
||||
e = NewEntity();
|
||||
|
||||
return quest_globals_entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
Database& db,
|
||||
std::vector<QuestGlobals> quest_globals_entries
|
||||
const std::vector<QuestGlobals> &entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &quest_globals_entry: quest_globals_entries) {
|
||||
std::vector<std::string> insert_values;
|
||||
for (auto &e: entries) {
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(quest_globals_entry.charid));
|
||||
insert_values.push_back(std::to_string(quest_globals_entry.npcid));
|
||||
insert_values.push_back(std::to_string(quest_globals_entry.zoneid));
|
||||
insert_values.push_back("'" + Strings::Escape(quest_globals_entry.name) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(quest_globals_entry.value) + "'");
|
||||
insert_values.push_back(std::to_string(quest_globals_entry.expdate));
|
||||
v.push_back(std::to_string(e.charid));
|
||||
v.push_back(std::to_string(e.npcid));
|
||||
v.push_back(std::to_string(e.zoneid));
|
||||
v.push_back("'" + Strings::Escape(e.name) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.value) + "'");
|
||||
v.push_back(std::to_string(e.expdate));
|
||||
|
||||
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(
|
||||
@@ -272,22 +272,22 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
QuestGlobals entry{};
|
||||
QuestGlobals e{};
|
||||
|
||||
entry.charid = atoi(row[0]);
|
||||
entry.npcid = atoi(row[1]);
|
||||
entry.zoneid = atoi(row[2]);
|
||||
entry.name = row[3] ? row[3] : "";
|
||||
entry.value = row[4] ? row[4] : "";
|
||||
entry.expdate = atoi(row[5]);
|
||||
e.charid = atoi(row[0]);
|
||||
e.npcid = atoi(row[1]);
|
||||
e.zoneid = atoi(row[2]);
|
||||
e.name = row[3] ? row[3] : "";
|
||||
e.value = row[4] ? row[4] : "";
|
||||
e.expdate = atoi(row[5]);
|
||||
|
||||
all_entries.push_back(entry);
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<QuestGlobals> GetWhere(Database& db, std::string where_filter)
|
||||
static std::vector<QuestGlobals> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<QuestGlobals> all_entries;
|
||||
|
||||
@@ -302,22 +302,22 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
QuestGlobals entry{};
|
||||
QuestGlobals e{};
|
||||
|
||||
entry.charid = atoi(row[0]);
|
||||
entry.npcid = atoi(row[1]);
|
||||
entry.zoneid = atoi(row[2]);
|
||||
entry.name = row[3] ? row[3] : "";
|
||||
entry.value = row[4] ? row[4] : "";
|
||||
entry.expdate = atoi(row[5]);
|
||||
e.charid = atoi(row[0]);
|
||||
e.npcid = atoi(row[1]);
|
||||
e.zoneid = atoi(row[2]);
|
||||
e.name = row[3] ? row[3] : "";
|
||||
e.value = row[4] ? row[4] : "";
|
||||
e.expdate = atoi(row[5]);
|
||||
|
||||
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(
|
||||
@@ -342,6 +342,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_QUEST_GLOBALS_REPOSITORY_H
|
||||
|
||||
Reference in New Issue
Block a user