mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-31 04:56:20 +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:
@@ -82,16 +82,16 @@ public:
|
||||
|
||||
static AccountFlags NewEntity()
|
||||
{
|
||||
AccountFlags entry{};
|
||||
AccountFlags e{};
|
||||
|
||||
entry.p_accid = 0;
|
||||
entry.p_flag = "";
|
||||
entry.p_value = "";
|
||||
e.p_accid = 0;
|
||||
e.p_flag = "";
|
||||
e.p_value = "";
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static AccountFlags GetAccountFlagsEntry(
|
||||
static AccountFlags GetAccountFlags(
|
||||
const std::vector<AccountFlags> &account_flagss,
|
||||
int account_flags_id
|
||||
)
|
||||
@@ -120,13 +120,13 @@ public:
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
AccountFlags entry{};
|
||||
AccountFlags e{};
|
||||
|
||||
entry.p_accid = atoi(row[0]);
|
||||
entry.p_flag = row[1] ? row[1] : "";
|
||||
entry.p_value = row[2] ? row[2] : "";
|
||||
e.p_accid = atoi(row[0]);
|
||||
e.p_flag = row[1] ? row[1] : "";
|
||||
e.p_value = row[2] ? row[2] : "";
|
||||
|
||||
return entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
@@ -151,24 +151,24 @@ public:
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
AccountFlags account_flags_entry
|
||||
const AccountFlags &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> update_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
update_values.push_back(columns[0] + " = " + std::to_string(account_flags_entry.p_accid));
|
||||
update_values.push_back(columns[1] + " = '" + Strings::Escape(account_flags_entry.p_flag) + "'");
|
||||
update_values.push_back(columns[2] + " = '" + Strings::Escape(account_flags_entry.p_value) + "'");
|
||||
v.push_back(columns[0] + " = " + std::to_string(e.p_accid));
|
||||
v.push_back(columns[1] + " = '" + Strings::Escape(e.p_flag) + "'");
|
||||
v.push_back(columns[2] + " = '" + Strings::Escape(e.p_value) + "'");
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
Strings::Implode(", ", update_values),
|
||||
Strings::Implode(", ", v),
|
||||
PrimaryKey(),
|
||||
account_flags_entry.p_accid
|
||||
e.p_accid
|
||||
)
|
||||
);
|
||||
|
||||
@@ -177,51 +177,51 @@ public:
|
||||
|
||||
static AccountFlags InsertOne(
|
||||
Database& db,
|
||||
AccountFlags account_flags_entry
|
||||
AccountFlags e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_values;
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(account_flags_entry.p_accid));
|
||||
insert_values.push_back("'" + Strings::Escape(account_flags_entry.p_flag) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(account_flags_entry.p_value) + "'");
|
||||
v.push_back(std::to_string(e.p_accid));
|
||||
v.push_back("'" + Strings::Escape(e.p_flag) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.p_value) + "'");
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseInsert(),
|
||||
Strings::Implode(",", insert_values)
|
||||
Strings::Implode(",", v)
|
||||
)
|
||||
);
|
||||
|
||||
if (results.Success()) {
|
||||
account_flags_entry.p_accid = results.LastInsertedID();
|
||||
return account_flags_entry;
|
||||
e.p_accid = results.LastInsertedID();
|
||||
return e;
|
||||
}
|
||||
|
||||
account_flags_entry = NewEntity();
|
||||
e = NewEntity();
|
||||
|
||||
return account_flags_entry;
|
||||
return e;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
Database& db,
|
||||
std::vector<AccountFlags> account_flags_entries
|
||||
const std::vector<AccountFlags> &entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &account_flags_entry: account_flags_entries) {
|
||||
std::vector<std::string> insert_values;
|
||||
for (auto &e: entries) {
|
||||
std::vector<std::string> v;
|
||||
|
||||
insert_values.push_back(std::to_string(account_flags_entry.p_accid));
|
||||
insert_values.push_back("'" + Strings::Escape(account_flags_entry.p_flag) + "'");
|
||||
insert_values.push_back("'" + Strings::Escape(account_flags_entry.p_value) + "'");
|
||||
v.push_back(std::to_string(e.p_accid));
|
||||
v.push_back("'" + Strings::Escape(e.p_flag) + "'");
|
||||
v.push_back("'" + Strings::Escape(e.p_value) + "'");
|
||||
|
||||
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(
|
||||
@@ -248,19 +248,19 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
AccountFlags entry{};
|
||||
AccountFlags e{};
|
||||
|
||||
entry.p_accid = atoi(row[0]);
|
||||
entry.p_flag = row[1] ? row[1] : "";
|
||||
entry.p_value = row[2] ? row[2] : "";
|
||||
e.p_accid = atoi(row[0]);
|
||||
e.p_flag = row[1] ? row[1] : "";
|
||||
e.p_value = row[2] ? row[2] : "";
|
||||
|
||||
all_entries.push_back(entry);
|
||||
all_entries.push_back(e);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<AccountFlags> GetWhere(Database& db, std::string where_filter)
|
||||
static std::vector<AccountFlags> GetWhere(Database& db, const std::string &where_filter)
|
||||
{
|
||||
std::vector<AccountFlags> all_entries;
|
||||
|
||||
@@ -275,19 +275,19 @@ public:
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
AccountFlags entry{};
|
||||
AccountFlags e{};
|
||||
|
||||
entry.p_accid = atoi(row[0]);
|
||||
entry.p_flag = row[1] ? row[1] : "";
|
||||
entry.p_value = row[2] ? row[2] : "";
|
||||
e.p_accid = atoi(row[0]);
|
||||
e.p_flag = row[1] ? row[1] : "";
|
||||
e.p_value = row[2] ? row[2] : "";
|
||||
|
||||
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(
|
||||
@@ -312,6 +312,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_ACCOUNT_FLAGS_REPOSITORY_H
|
||||
|
||||
Reference in New Issue
Block a user