mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-23 20:58:21 +00:00
[Repository] Add null integer column support, instance_list notes migration, regenerate repositories (#3969)
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
* Any modifications to base repositories are to be made by the generator only
|
||||
*
|
||||
* @generator ./utils/scripts/generators/repository-generator.pl
|
||||
* @docs https://eqemu.gitbook.io/server/in-development/developer-area/repositories
|
||||
* @docs https://docs.eqemu.io/developer/repositories
|
||||
*/
|
||||
|
||||
#ifndef EQEMU_BASE_SHARED_TASKS_REPOSITORY_H
|
||||
@@ -124,8 +124,9 @@ public:
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} WHERE id = {} LIMIT 1",
|
||||
"{} WHERE {} = {} LIMIT 1",
|
||||
BaseSelect(),
|
||||
PrimaryKey(),
|
||||
shared_tasks_id
|
||||
)
|
||||
);
|
||||
@@ -134,7 +135,7 @@ public:
|
||||
if (results.RowCount() == 1) {
|
||||
SharedTasks e{};
|
||||
|
||||
e.id = strtoll(row[0], nullptr, 10);
|
||||
e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0;
|
||||
e.task_id = static_cast<int32_t>(atoi(row[1]));
|
||||
e.accepted_time = strtoll(row[2] ? row[2] : "-1", nullptr, 10);
|
||||
e.expire_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10);
|
||||
@@ -273,7 +274,7 @@ public:
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
SharedTasks e{};
|
||||
|
||||
e.id = strtoll(row[0], nullptr, 10);
|
||||
e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0;
|
||||
e.task_id = static_cast<int32_t>(atoi(row[1]));
|
||||
e.accepted_time = strtoll(row[2] ? row[2] : "-1", nullptr, 10);
|
||||
e.expire_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10);
|
||||
@@ -303,7 +304,7 @@ public:
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
SharedTasks e{};
|
||||
|
||||
e.id = strtoll(row[0], nullptr, 10);
|
||||
e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0;
|
||||
e.task_id = static_cast<int32_t>(atoi(row[1]));
|
||||
e.accepted_time = strtoll(row[2] ? row[2] : "-1", nullptr, 10);
|
||||
e.expire_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10);
|
||||
@@ -367,6 +368,72 @@ public:
|
||||
return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0);
|
||||
}
|
||||
|
||||
static std::string BaseReplace()
|
||||
{
|
||||
return fmt::format(
|
||||
"REPLACE INTO {} ({}) ",
|
||||
TableName(),
|
||||
ColumnsRaw()
|
||||
);
|
||||
}
|
||||
|
||||
static int ReplaceOne(
|
||||
Database& db,
|
||||
const SharedTasks &e
|
||||
)
|
||||
{
|
||||
std::vector<std::string> v;
|
||||
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.task_id));
|
||||
v.push_back("FROM_UNIXTIME(" + (e.accepted_time > 0 ? std::to_string(e.accepted_time) : "null") + ")");
|
||||
v.push_back("FROM_UNIXTIME(" + (e.expire_time > 0 ? std::to_string(e.expire_time) : "null") + ")");
|
||||
v.push_back("FROM_UNIXTIME(" + (e.completion_time > 0 ? std::to_string(e.completion_time) : "null") + ")");
|
||||
v.push_back(std::to_string(e.is_locked));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseReplace(),
|
||||
Strings::Implode(",", v)
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static int ReplaceMany(
|
||||
Database& db,
|
||||
const std::vector<SharedTasks> &entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &e: entries) {
|
||||
std::vector<std::string> v;
|
||||
|
||||
v.push_back(std::to_string(e.id));
|
||||
v.push_back(std::to_string(e.task_id));
|
||||
v.push_back("FROM_UNIXTIME(" + (e.accepted_time > 0 ? std::to_string(e.accepted_time) : "null") + ")");
|
||||
v.push_back("FROM_UNIXTIME(" + (e.expire_time > 0 ? std::to_string(e.expire_time) : "null") + ")");
|
||||
v.push_back("FROM_UNIXTIME(" + (e.completion_time > 0 ? std::to_string(e.completion_time) : "null") + ")");
|
||||
v.push_back(std::to_string(e.is_locked));
|
||||
|
||||
insert_chunks.push_back("(" + Strings::Implode(",", v) + ")");
|
||||
}
|
||||
|
||||
std::vector<std::string> v;
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES {}",
|
||||
BaseReplace(),
|
||||
Strings::Implode(",", insert_chunks)
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EQEMU_BASE_SHARED_TASKS_REPOSITORY_H
|
||||
|
||||
Reference in New Issue
Block a user