1
0
mirror of https://github.com/anope/anope.git synced 2026-06-12 19:34:48 +02:00

Add a helper function to db_sql(_live) for getting a table name.

This commit is contained in:
Sadie Powell
2024-11-11 10:42:57 +00:00
parent aa32f7c926
commit 9411dac991
2 changed files with 20 additions and 10 deletions
+9 -4
View File
@@ -72,6 +72,11 @@ class DBSQL final
bool loaded = false;
bool imported = false;
Anope::string GetTableName(Serialize::Type *s_type)
{
return this->prefix + s_type->GetName();
}
void RunBackground(const Query &q, Interface *iface = NULL)
{
if (!this->sql)
@@ -124,8 +129,8 @@ public:
if (!s_type)
continue;
std::vector<Query> create = this->sql->CreateTable(this->prefix + s_type->GetName(), data);
Query insert = this->sql->BuildInsert(this->prefix + s_type->GetName(), obj->id, data);
auto create = this->sql->CreateTable(GetTableName(s_type), data);
auto insert = this->sql->BuildInsert(GetTableName(s_type), obj->id, data);
if (this->imported)
{
@@ -209,7 +214,7 @@ public:
return;
Serialize::Type *s_type = obj->GetSerializableType();
if (s_type && obj->id > 0)
this->RunBackground("DELETE FROM `" + this->prefix + s_type->GetName() + "` WHERE `id` = " + Anope::ToString(obj->id));
this->RunBackground("DELETE FROM `" + GetTableName(s_type) + "` WHERE `id` = " + Anope::ToString(obj->id));
this->updated_items.erase(obj);
}
@@ -229,7 +234,7 @@ public:
if (!this->loading_databases && !this->loaded)
return;
Query query("SELECT * FROM `" + this->prefix + sb->GetName() + "`");
Query query("SELECT * FROM `" + GetTableName(sb) + "`");
Result res = this->sql->RunQuery(query);
for (int j = 0; j < res.Rows(); ++j)