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:
@@ -88,18 +88,18 @@ public:
|
||||
|
||||
static NpcEmotes NewEntity()
|
||||
{
|
||||
NpcEmotes entry{};
|
||||
NpcEmotes e{};
|
||||
|
||||
entry.id = 0;
|
||||
entry.emoteid = 0;
|
||||
entry.event_ = 0;
|
||||
entry.type = 0;
|
||||
entry.text = "";
|
||||
e.id = 0;
|
||||
e.emoteid = 0;
|
||||
e.event_ = 0;
|
||||
e.type = 0;
|
||||
e.text = "";
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static NpcEmotes GetNpcEmotesEntry(
|
||||
static NpcEmotes GetNpcEmotes(
|
||||
const std::vector<NpcEmotes> &npc_emotess,
|
||||
int npc_emotes_id
|
||||
)
|
||||
@@ -128,15 +128,15 @@ public:
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
NpcEmotes entry{};
|
||||
NpcEmotes e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.emoteid = atoi(row[1]);
|
||||
entry.event_ = atoi(row[2]);
|
||||
entry.type = atoi(row[3]);
|
||||
entry.text = row[4] ? row[4] : "";
|
||||
e.id = atoi(row[0]);
|
||||
e.emoteid = atoi(row[1]);
|
||||
e.event_ = atoi(row[2]);
|
||||
e.type = atoi(row[3]);
|
||||
e.text = row[4] ? row[4] : "";
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
@@ -161,25 +161,25 @@ public:
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
NpcEmotes npc_emotes_entry
|
||||
const NpcEmotes &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> update_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
update_values.push_back(columns[1] + " = " + std::to_string(npc_emotes_entry.emoteid));
|
||||
update_values.push_back(columns[2] + " = " + std::to_string(npc_emotes_entry.event_));
|
||||
update_values.push_back(columns[3] + " = " + std::to_string(npc_emotes_entry.type));
|
||||
update_values.push_back(columns[4] + " = '" + Strings::Escape(npc_emotes_entry.text) + "'");
|
||||
v.push_back(columns[1] + " = " + std::to_string(e.emoteid));
|
||||
v.push_back(columns[2] + " = " + std::to_string(e.event_));
|
||||
v.push_back(columns[3] + " = " + std::to_string(e.type));
|
||||
v.push_back(columns[4] + " = '" + Strings::Escape(e.text) + "'");
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", update_values),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
npc_emotes_entry.id
|
||||
e.id
|
||||
)
|
||||
);
|
||||
|
||||
@@ -188,55 +188,55 @@ public:
|
||||
|
||||
static NpcEmotes InsertOne(
|
||||
Database& db,
|
||||
NpcEmotes npc_emotes_entry
|
||||
NpcEmotes e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(npc_emotes_entry.id));
|
||||
insert_values.push_back(std::to_string(npc_emotes_entry.emoteid));
|
||||
insert_values.push_back(std::to_string(npc_emotes_entry.event_));
|
||||
insert_values.push_back(std::to_string(npc_emotes_entry.type));
|
||||
insert_values.push_back("'" + Strings::Escape(npc_emotes_entry.text) + "'");
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.emoteid));
|
||||
v.push_back(std::to_string(e.event_));
|
||||
v.push_back(std::to_string(e.type));
|
||||
v.push_back("'" + Strings::Escape(e.text) + "'");
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseInsert(),
|
||||
Strings::Implode(",", insert_values)
|
||||
Strings::Implode(",", v)
|
||||
)
|
||||
);
|
||||
|
||||
if (results.Success()) {
|
||||
npc_emotes_entry.id = results.LastInsertedID();
|
||||
return npc_emotes_entry;
|
||||
e.id = results.LastInsertedID();
|
||||
return e;
|
||||
}
|
||||
|
||||
npc_emotes_entry = NewEntity();
|
||||
e = NewEntity();
|
||||
|
||||
return npc_emotes_entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
Database& db,
|
||||
std::vector<NpcEmotes> npc_emotes_entries
|
||||
const std::vector<NpcEmotes> &entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &npc_emotes_entry: npc_emotes_entries) {
|
||||
std::vector<std::string> insert_values;
|
||||
for (auto &e: entries) {
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(npc_emotes_entry.id));
|
||||
insert_values.push_back(std::to_string(npc_emotes_entry.emoteid));
|
||||
insert_values.push_back(std::to_string(npc_emotes_entry.event_));
|
||||
insert_values.push_back(std::to_string(npc_emotes_entry.type));
|
||||
insert_values.push_back("'" + Strings::Escape(npc_emotes_entry.text) + "'");
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.emoteid));
|
||||
v.push_back(std::to_string(e.event_));
|
||||
v.push_back(std::to_string(e.type));
|
||||
v.push_back("'" + Strings::Escape(e.text) + "'");
|
||||
|
||||
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(
|
||||
@@ -263,21 +263,21 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
NpcEmotes entry{};
|
||||
NpcEmotes e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.emoteid = atoi(row[1]);
|
||||
entry.event_ = atoi(row[2]);
|
||||
entry.type = atoi(row[3]);
|
||||
entry.text = row[4] ? row[4] : "";
|
||||
e.id = atoi(row[0]);
|
||||
e.emoteid = atoi(row[1]);
|
||||
e.event_ = atoi(row[2]);
|
||||
e.type = atoi(row[3]);
|
||||
e.text = row[4] ? row[4] : "";
|
||||
|
||||
all_entries.push_back(entry);
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<NpcEmotes> GetWhere(Database& db, std::string where_filter)
|
||||
static std::vector<NpcEmotes> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<NpcEmotes> all_entries;
|
||||
|
||||
@@ -292,21 +292,21 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
NpcEmotes entry{};
|
||||
NpcEmotes e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.emoteid = atoi(row[1]);
|
||||
entry.event_ = atoi(row[2]);
|
||||
entry.type = atoi(row[3]);
|
||||
entry.text = row[4] ? row[4] : "";
|
||||
e.id = atoi(row[0]);
|
||||
e.emoteid = atoi(row[1]);
|
||||
e.event_ = atoi(row[2]);
|
||||
e.type = atoi(row[3]);
|
||||
e.text = row[4] ? row[4] : "";
|
||||
|
||||
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(
|
||||
@@ -331,6 +331,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_NPC_EMOTES_REPOSITORY_H
|
||||
|
||||
Reference in New Issue
Block a user