mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-22 03:18:22 +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:
@@ -100,22 +100,22 @@ public:
|
||||
|
||||
static Guilds NewEntity()
|
||||
{
|
||||
Guilds entry{};
|
||||
Guilds e{};
|
||||
|
||||
entry.id = 0;
|
||||
entry.name = "";
|
||||
entry.leader = 0;
|
||||
entry.minstatus = 0;
|
||||
entry.motd = "";
|
||||
entry.tribute = 0;
|
||||
entry.motd_setter = "";
|
||||
entry.channel = "";
|
||||
entry.url = "";
|
||||
e.id = 0;
|
||||
e.name = "";
|
||||
e.leader = 0;
|
||||
e.minstatus = 0;
|
||||
e.motd = "";
|
||||
e.tribute = 0;
|
||||
e.motd_setter = "";
|
||||
e.channel = "";
|
||||
e.url = "";
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static Guilds GetGuildsEntry(
|
||||
static Guilds GetGuilds(
|
||||
const std::vector<Guilds> &guildss,
|
||||
int guilds_id
|
||||
)
|
||||
@@ -144,19 +144,19 @@ public:
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
Guilds entry{};
|
||||
Guilds e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.name = row[1] ? row[1] : "";
|
||||
entry.leader = atoi(row[2]);
|
||||
entry.minstatus = atoi(row[3]);
|
||||
entry.motd = row[4] ? row[4] : "";
|
||||
entry.tribute = atoi(row[5]);
|
||||
entry.motd_setter = row[6] ? row[6] : "";
|
||||
entry.channel = row[7] ? row[7] : "";
|
||||
entry.url = row[8] ? row[8] : "";
|
||||
e.id = atoi(row[0]);
|
||||
e.name = row[1] ? row[1] : "";
|
||||
e.leader = atoi(row[2]);
|
||||
e.minstatus = atoi(row[3]);
|
||||
e.motd = row[4] ? row[4] : "";
|
||||
e.tribute = atoi(row[5]);
|
||||
e.motd_setter = row[6] ? row[6] : "";
|
||||
e.channel = row[7] ? row[7] : "";
|
||||
e.url = row[8] ? row[8] : "";
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
@@ -181,29 +181,29 @@ public:
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
Guilds guilds_entry
|
||||
const Guilds &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> update_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
update_values.push_back(columns[1] + " = '" + Strings::Escape(guilds_entry.name) + "'");
|
||||
update_values.push_back(columns[2] + " = " + std::to_string(guilds_entry.leader));
|
||||
update_values.push_back(columns[3] + " = " + std::to_string(guilds_entry.minstatus));
|
||||
update_values.push_back(columns[4] + " = '" + Strings::Escape(guilds_entry.motd) + "'");
|
||||
update_values.push_back(columns[5] + " = " + std::to_string(guilds_entry.tribute));
|
||||
update_values.push_back(columns[6] + " = '" + Strings::Escape(guilds_entry.motd_setter) + "'");
|
||||
update_values.push_back(columns[7] + " = '" + Strings::Escape(guilds_entry.channel) + "'");
|
||||
update_values.push_back(columns[8] + " = '" + Strings::Escape(guilds_entry.url) + "'");
|
||||
v.push_back(columns[1] + " = '" + Strings::Escape(e.name) + "'");
|
||||
v.push_back(columns[2] + " = " + std::to_string(e.leader));
|
||||
v.push_back(columns[3] + " = " + std::to_string(e.minstatus));
|
||||
v.push_back(columns[4] + " = '" + Strings::Escape(e.motd) + "'");
|
||||
v.push_back(columns[5] + " = " + std::to_string(e.tribute));
|
||||
v.push_back(columns[6] + " = '" + Strings::Escape(e.motd_setter) + "'");
|
||||
v.push_back(columns[7] + " = '" + Strings::Escape(e.channel) + "'");
|
||||
v.push_back(columns[8] + " = '" + Strings::Escape(e.url) + "'");
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", update_values),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
guilds_entry.id
|
||||
e.id
|
||||
)
|
||||
);
|
||||
|
||||
@@ -212,63 +212,63 @@ public:
|
||||
|
||||
static Guilds InsertOne(
|
||||
Database& db,
|
||||
Guilds guilds_entry
|
||||
Guilds e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(guilds_entry.id));
|
||||
insert_values.push_back("'" + Strings::Escape(guilds_entry.name) + "'");
|
||||
insert_values.push_back(std::to_string(guilds_entry.leader));
|
||||
insert_values.push_back(std::to_string(guilds_entry.minstatus));
|
||||
insert_values.push_back("'" + Strings::Escape(guilds_entry.motd) + "'");
|
||||
insert_values.push_back(std::to_string(guilds_entry.tribute));
|
||||
insert_values.push_back("'" + Strings::Escape(guilds_entry.motd_setter) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(guilds_entry.channel) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(guilds_entry.url) + "'");
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back("'" + Strings::Escape(e.name) + "'");
|
||||
v.push_back(std::to_string(e.leader));
|
||||
v.push_back(std::to_string(e.minstatus));
|
||||
v.push_back("'" + Strings::Escape(e.motd) + "'");
|
||||
v.push_back(std::to_string(e.tribute));
|
||||
v.push_back("'" + Strings::Escape(e.motd_setter) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.channel) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.url) + "'");
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseInsert(),
|
||||
Strings::Implode(",", insert_values)
|
||||
Strings::Implode(",", v)
|
||||
)
|
||||
);
|
||||
|
||||
if (results.Success()) {
|
||||
guilds_entry.id = results.LastInsertedID();
|
||||
return guilds_entry;
|
||||
e.id = results.LastInsertedID();
|
||||
return e;
|
||||
}
|
||||
|
||||
guilds_entry = NewEntity();
|
||||
e = NewEntity();
|
||||
|
||||
return guilds_entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
Database& db,
|
||||
std::vector<Guilds> guilds_entries
|
||||
const std::vector<Guilds> &entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &guilds_entry: guilds_entries) {
|
||||
std::vector<std::string> insert_values;
|
||||
for (auto &e: entries) {
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(guilds_entry.id));
|
||||
insert_values.push_back("'" + Strings::Escape(guilds_entry.name) + "'");
|
||||
insert_values.push_back(std::to_string(guilds_entry.leader));
|
||||
insert_values.push_back(std::to_string(guilds_entry.minstatus));
|
||||
insert_values.push_back("'" + Strings::Escape(guilds_entry.motd) + "'");
|
||||
insert_values.push_back(std::to_string(guilds_entry.tribute));
|
||||
insert_values.push_back("'" + Strings::Escape(guilds_entry.motd_setter) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(guilds_entry.channel) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(guilds_entry.url) + "'");
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back("'" + Strings::Escape(e.name) + "'");
|
||||
v.push_back(std::to_string(e.leader));
|
||||
v.push_back(std::to_string(e.minstatus));
|
||||
v.push_back("'" + Strings::Escape(e.motd) + "'");
|
||||
v.push_back(std::to_string(e.tribute));
|
||||
v.push_back("'" + Strings::Escape(e.motd_setter) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.channel) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.url) + "'");
|
||||
|
||||
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(
|
||||
@@ -295,25 +295,25 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
Guilds entry{};
|
||||
Guilds e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.name = row[1] ? row[1] : "";
|
||||
entry.leader = atoi(row[2]);
|
||||
entry.minstatus = atoi(row[3]);
|
||||
entry.motd = row[4] ? row[4] : "";
|
||||
entry.tribute = atoi(row[5]);
|
||||
entry.motd_setter = row[6] ? row[6] : "";
|
||||
entry.channel = row[7] ? row[7] : "";
|
||||
entry.url = row[8] ? row[8] : "";
|
||||
e.id = atoi(row[0]);
|
||||
e.name = row[1] ? row[1] : "";
|
||||
e.leader = atoi(row[2]);
|
||||
e.minstatus = atoi(row[3]);
|
||||
e.motd = row[4] ? row[4] : "";
|
||||
e.tribute = atoi(row[5]);
|
||||
e.motd_setter = row[6] ? row[6] : "";
|
||||
e.channel = row[7] ? row[7] : "";
|
||||
e.url = row[8] ? row[8] : "";
|
||||
|
||||
all_entries.push_back(entry);
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<Guilds> GetWhere(Database& db, std::string where_filter)
|
||||
static std::vector<Guilds> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<Guilds> all_entries;
|
||||
|
||||
@@ -328,25 +328,25 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
Guilds entry{};
|
||||
Guilds e{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.name = row[1] ? row[1] : "";
|
||||
entry.leader = atoi(row[2]);
|
||||
entry.minstatus = atoi(row[3]);
|
||||
entry.motd = row[4] ? row[4] : "";
|
||||
entry.tribute = atoi(row[5]);
|
||||
entry.motd_setter = row[6] ? row[6] : "";
|
||||
entry.channel = row[7] ? row[7] : "";
|
||||
entry.url = row[8] ? row[8] : "";
|
||||
e.id = atoi(row[0]);
|
||||
e.name = row[1] ? row[1] : "";
|
||||
e.leader = atoi(row[2]);
|
||||
e.minstatus = atoi(row[3]);
|
||||
e.motd = row[4] ? row[4] : "";
|
||||
e.tribute = atoi(row[5]);
|
||||
e.motd_setter = row[6] ? row[6] : "";
|
||||
e.channel = row[7] ? row[7] : "";
|
||||
e.url = row[8] ? row[8] : "";
|
||||
|
||||
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(
|
||||
@@ -371,6 +371,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_GUILDS_REPOSITORY_H
|
||||
|
||||
Reference in New Issue
Block a user