[Repository] Add null integer column support, instance_list notes migration, regenerate repositories (#3969)

This commit is contained in:
Chris Miles
2024-01-12 22:23:55 -06:00
committed by GitHub
parent 1238a6ca68
commit 818f833d04
189 changed files with 17218 additions and 3604 deletions
@@ -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_SPAWNGROUP_REPOSITORY_H
@@ -152,8 +152,9 @@ public:
{
auto results = db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
"{} WHERE {} = {} LIMIT 1",
BaseSelect(),
PrimaryKey(),
spawngroup_id
)
);
@@ -165,16 +166,16 @@ public:
e.id = static_cast<int32_t>(atoi(row[0]));
e.name = row[1] ? row[1] : "";
e.spawn_limit = static_cast<int8_t>(atoi(row[2]));
e.dist = strtof(row[3], nullptr);
e.max_x = strtof(row[4], nullptr);
e.min_x = strtof(row[5], nullptr);
e.max_y = strtof(row[6], nullptr);
e.min_y = strtof(row[7], nullptr);
e.dist = row[3] ? strtof(row[3], nullptr) : 0;
e.max_x = row[4] ? strtof(row[4], nullptr) : 0;
e.min_x = row[5] ? strtof(row[5], nullptr) : 0;
e.max_y = row[6] ? strtof(row[6], nullptr) : 0;
e.min_y = row[7] ? strtof(row[7], nullptr) : 0;
e.delay = static_cast<int32_t>(atoi(row[8]));
e.mindelay = static_cast<int32_t>(atoi(row[9]));
e.despawn = static_cast<int8_t>(atoi(row[10]));
e.despawn_timer = static_cast<int32_t>(atoi(row[11]));
e.wp_spawns = static_cast<uint8_t>(strtoul(row[12], nullptr, 10));
e.wp_spawns = row[12] ? static_cast<uint8_t>(strtoul(row[12], nullptr, 10)) : 0;
return e;
}
@@ -332,16 +333,16 @@ public:
e.id = static_cast<int32_t>(atoi(row[0]));
e.name = row[1] ? row[1] : "";
e.spawn_limit = static_cast<int8_t>(atoi(row[2]));
e.dist = strtof(row[3], nullptr);
e.max_x = strtof(row[4], nullptr);
e.min_x = strtof(row[5], nullptr);
e.max_y = strtof(row[6], nullptr);
e.min_y = strtof(row[7], nullptr);
e.dist = row[3] ? strtof(row[3], nullptr) : 0;
e.max_x = row[4] ? strtof(row[4], nullptr) : 0;
e.min_x = row[5] ? strtof(row[5], nullptr) : 0;
e.max_y = row[6] ? strtof(row[6], nullptr) : 0;
e.min_y = row[7] ? strtof(row[7], nullptr) : 0;
e.delay = static_cast<int32_t>(atoi(row[8]));
e.mindelay = static_cast<int32_t>(atoi(row[9]));
e.despawn = static_cast<int8_t>(atoi(row[10]));
e.despawn_timer = static_cast<int32_t>(atoi(row[11]));
e.wp_spawns = static_cast<uint8_t>(strtoul(row[12], nullptr, 10));
e.wp_spawns = row[12] ? static_cast<uint8_t>(strtoul(row[12], nullptr, 10)) : 0;
all_entries.push_back(e);
}
@@ -369,16 +370,16 @@ public:
e.id = static_cast<int32_t>(atoi(row[0]));
e.name = row[1] ? row[1] : "";
e.spawn_limit = static_cast<int8_t>(atoi(row[2]));
e.dist = strtof(row[3], nullptr);
e.max_x = strtof(row[4], nullptr);
e.min_x = strtof(row[5], nullptr);
e.max_y = strtof(row[6], nullptr);
e.min_y = strtof(row[7], nullptr);
e.dist = row[3] ? strtof(row[3], nullptr) : 0;
e.max_x = row[4] ? strtof(row[4], nullptr) : 0;
e.min_x = row[5] ? strtof(row[5], nullptr) : 0;
e.max_y = row[6] ? strtof(row[6], nullptr) : 0;
e.min_y = row[7] ? strtof(row[7], nullptr) : 0;
e.delay = static_cast<int32_t>(atoi(row[8]));
e.mindelay = static_cast<int32_t>(atoi(row[9]));
e.despawn = static_cast<int8_t>(atoi(row[10]));
e.despawn_timer = static_cast<int32_t>(atoi(row[11]));
e.wp_spawns = static_cast<uint8_t>(strtoul(row[12], nullptr, 10));
e.wp_spawns = row[12] ? static_cast<uint8_t>(strtoul(row[12], nullptr, 10)) : 0;
all_entries.push_back(e);
}
@@ -437,6 +438,86 @@ 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 Spawngroup &e
)
{
std::vector<std::string> v;
v.push_back(std::to_string(e.id));
v.push_back("'" + Strings::Escape(e.name) + "'");
v.push_back(std::to_string(e.spawn_limit));
v.push_back(std::to_string(e.dist));
v.push_back(std::to_string(e.max_x));
v.push_back(std::to_string(e.min_x));
v.push_back(std::to_string(e.max_y));
v.push_back(std::to_string(e.min_y));
v.push_back(std::to_string(e.delay));
v.push_back(std::to_string(e.mindelay));
v.push_back(std::to_string(e.despawn));
v.push_back(std::to_string(e.despawn_timer));
v.push_back(std::to_string(e.wp_spawns));
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<Spawngroup> &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("'" + Strings::Escape(e.name) + "'");
v.push_back(std::to_string(e.spawn_limit));
v.push_back(std::to_string(e.dist));
v.push_back(std::to_string(e.max_x));
v.push_back(std::to_string(e.min_x));
v.push_back(std::to_string(e.max_y));
v.push_back(std::to_string(e.min_y));
v.push_back(std::to_string(e.delay));
v.push_back(std::to_string(e.mindelay));
v.push_back(std::to_string(e.despawn));
v.push_back(std::to_string(e.despawn_timer));
v.push_back(std::to_string(e.wp_spawns));
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_SPAWNGROUP_REPOSITORY_H