diff --git a/include/modules/sql.h b/include/modules/sql.h index 668439972..035901468 100644 --- a/include/modules/sql.h +++ b/include/modules/sql.h @@ -197,7 +197,7 @@ namespace SQL virtual std::vector CreateTable(const Anope::string &table, const Data &data) = 0; - virtual Query BuildInsert(const Anope::string &table, unsigned int id, Data &data) = 0; + virtual Query BuildInsert(const Anope::string &table, Serializable::Id id, Data &data) = 0; virtual Query GetTables(const Anope::string &prefix) = 0; diff --git a/include/serialize.h b/include/serialize.h index b501a62a9..ac9785f5a 100644 --- a/include/serialize.h +++ b/include/serialize.h @@ -118,7 +118,7 @@ public: virtual ~Serializable(); /* Unique ID (per type, not globally) for this object */ - Id id = 0; + Id object_id = 0; /* Only used by redis, to ignore updates */ unsigned short redis_ignore = 0; diff --git a/modules/database/db_flatfile.cpp b/modules/database/db_flatfile.cpp index a56387cfb..f647feb3d 100644 --- a/modules/database/db_flatfile.cpp +++ b/modules/database/db_flatfile.cpp @@ -118,7 +118,7 @@ public: Serializable *obj = stype->Unserialize(NULL, ld); if (obj != NULL) - obj->id = ld.id; + obj->object_id = ld.id; ld.Reset(); } } diff --git a/modules/database/db_json.cpp b/modules/database/db_json.cpp index 35cb13923..f9dfc9df6 100644 --- a/modules/database/db_json.cpp +++ b/modules/database/db_json.cpp @@ -43,8 +43,8 @@ public: // Used when writing data. Data(Serialize::Type *s_type, Serializable *obj) { - if (obj->id) - this->id = obj->id; + if (obj->object_id) + this->id = obj->object_id; s_type->Serialize(obj, *this); } diff --git a/modules/database/db_redis.cpp b/modules/database/db_redis.cpp index 397526d1f..2ce09ead5 100644 --- a/modules/database/db_redis.cpp +++ b/modules/database/db_redis.cpp @@ -146,7 +146,7 @@ public: Serialize::Type *t = obj->GetSerializableType(); /* If there is no id yet for this object, get one */ - if (!obj->id) + if (!obj->object_id) redis->SendCommand(new IDInterface(this, obj), "INCR id:" + t->GetName()); else { @@ -160,10 +160,10 @@ public: std::vector args; args.emplace_back("HGETALL"); - args.push_back("hash:" + t->GetName() + ":" + Anope::ToString(obj->id)); + args.push_back("hash:" + t->GetName() + ":" + Anope::ToString(obj->object_id)); /* Get object attrs to clear before updating */ - redis->SendCommand(new Updater(this, t->GetName(), obj->id), args); + redis->SendCommand(new Updater(this, t->GetName(), obj->object_id), args); } } @@ -246,13 +246,13 @@ public: std::vector args; args.emplace_back("HGETALL"); - args.push_back("hash:" + t->GetName() + ":" + Anope::ToString(obj->id)); + args.push_back("hash:" + t->GetName() + ":" + Anope::ToString(obj->object_id)); /* Get all of the attributes for this object */ - redis->SendCommand(new Deleter(this, t->GetName(), obj->id), args); + redis->SendCommand(new Deleter(this, t->GetName(), obj->object_id), args); this->updated_items.erase(obj); - t->objects.erase(obj->id); + t->objects.erase(obj->object_id); this->Notify(); } @@ -315,7 +315,7 @@ void ObjectLoader::OnResult(const Reply &r) obj = st->Unserialize(obj, data); if (obj) { - obj->id = this->id; + obj->object_id = this->id; obj->UpdateCache(data); } @@ -333,9 +333,9 @@ void IDInterface::OnResult(const Reply &r) Serializable *&obj = o->GetSerializableType()->objects[r.i]; if (obj) /* This shouldn't be possible */ - obj->id = 0; + obj->object_id = 0; - o->id = r.i; + o->object_id = r.i; obj = o; /* Now that we have the id, insert this object for real */ @@ -431,12 +431,12 @@ void Updater::OnResult(const Reply &r) std::vector args; args.emplace_back("SADD"); args.push_back("ids:" + this->type); - args.push_back(Anope::ToString(obj->id)); + args.push_back(Anope::ToString(obj->object_id)); me->redis->SendCommand(NULL, args); args.clear(); args.emplace_back("HMSET"); - args.push_back("hash:" + this->type + ":" + Anope::ToString(obj->id)); + args.push_back("hash:" + this->type + ":" + Anope::ToString(obj->object_id)); for (const auto &[key, value] : data.data) { @@ -447,7 +447,7 @@ void Updater::OnResult(const Reply &r) args2.emplace_back("SADD"); args2.push_back("value:" + this->type + ":" + key + ":" + value->str()); - args2.push_back(Anope::ToString(obj->id)); + args2.push_back(Anope::ToString(obj->object_id)); /* Add to value -> object id set */ me->redis->SendCommand(NULL, args2); @@ -551,7 +551,7 @@ void SubscriptionListener::OnResult(const Reply &r) std::vector args; args.emplace_back("SREM"); args.push_back("ids:" + type); - args.push_back(Anope::ToString(s->id)); + args.push_back(Anope::ToString(s->object_id)); /* Delete object from id set */ me->redis->SendCommand(NULL, args); @@ -610,7 +610,7 @@ void ModifiedObject::OnResult(const Reply &r) obj = st->Unserialize(obj, data); if (obj) { - obj->id = this->id; + obj->object_id = this->id; obj->UpdateCache(data); /* Insert new object values */ @@ -619,7 +619,7 @@ void ModifiedObject::OnResult(const Reply &r) std::vector args; args.emplace_back("SADD"); args.push_back("value:" + st->GetName() + ":" + key + ":" + value->str()); - args.push_back(Anope::ToString(obj->id)); + args.push_back(Anope::ToString(obj->object_id)); /* Add to value -> object id set */ me->redis->SendCommand(NULL, args); @@ -628,7 +628,7 @@ void ModifiedObject::OnResult(const Reply &r) std::vector args; args.emplace_back("SADD"); args.push_back("ids:" + st->GetName()); - args.push_back(Anope::ToString(obj->id)); + args.push_back(Anope::ToString(obj->object_id)); /* Add to type -> id set */ me->redis->SendCommand(NULL, args); diff --git a/modules/database/db_sql.cpp b/modules/database/db_sql.cpp index 727931651..0f40538fe 100644 --- a/modules/database/db_sql.cpp +++ b/modules/database/db_sql.cpp @@ -49,7 +49,7 @@ public: { SQLSQLInterface::OnResult(r); if (r.GetID() > 0 && this->obj) - this->obj->id = r.GetID(); + this->obj->object_id = r.GetID(); delete this; } @@ -136,7 +136,7 @@ public: continue; auto create = this->sql->CreateTable(GetTableName(s_type), data); - auto insert = this->sql->BuildInsert(GetTableName(s_type), obj->id, data); + auto insert = this->sql->BuildInsert(GetTableName(s_type), obj->object_id, data); if (this->imported) { @@ -155,7 +155,7 @@ public: */ Result r = this->sql->RunQuery(insert); if (r.GetID() > 0) - obj->id = r.GetID(); + obj->object_id = r.GetID(); } } } @@ -226,8 +226,8 @@ public: if (this->shutting_down) return; Serialize::Type *s_type = obj->GetSerializableType(); - if (s_type && obj->id > 0) - this->RunBackground("DELETE FROM `" + GetTableName(s_type) + "` WHERE `id` = " + Anope::ToString(obj->id)); + if (s_type && obj->object_id > 0) + this->RunBackground("DELETE FROM `" + GetTableName(s_type) + "` WHERE `id` = " + Anope::ToString(obj->object_id)); this->updated_items.erase(obj); } @@ -235,7 +235,7 @@ public: { if (this->shutting_down || obj->IsTSCached()) return; - if (obj->id == 0) + if (obj->object_id == 0) return; /* object is pending creation */ obj->UpdateTS(); this->updated_items.insert(obj); @@ -262,7 +262,7 @@ public: { auto oid = Anope::TryConvert(res.Get(j, "id")); if (oid.has_value()) - obj->id = oid.value(); + obj->object_id = oid.value(); else Log(this) << "Unable to convert id for object #" << j << " of type " << sb->GetName(); diff --git a/modules/database/db_sql_live.cpp b/modules/database/db_sql_live.cpp index edf80655d..c9104e323 100644 --- a/modules/database/db_sql_live.cpp +++ b/modules/database/db_sql_live.cpp @@ -118,12 +118,12 @@ public: for (const auto &query : create) this->RunQuery(query); - auto res = this->RunQuery(this->SQL->BuildInsert(GetTableName(s_type), obj->id, data)); - if (res.GetID() && obj->id != res.GetID()) + auto res = this->RunQuery(this->SQL->BuildInsert(GetTableName(s_type), obj->object_id, data)); + if (res.GetID() && obj->object_id != res.GetID()) { /* In this case obj is new, so place it into the object map */ - obj->id = res.GetID(); - s_type->objects[obj->id] = obj; + obj->object_id = res.GetID(); + s_type->objects[obj->object_id] = obj; } } } @@ -168,9 +168,9 @@ public: Serialize::Type *s_type = obj->GetSerializableType(); if (s_type) { - if (obj->id > 0) - this->RunQuery("DELETE FROM `" + GetTableName(s_type) + "` WHERE `id` = " + Anope::ToString(obj->id)); - s_type->objects.erase(obj->id); + if (obj->object_id > 0) + this->RunQuery("DELETE FROM `" + GetTableName(s_type) + "` WHERE `id` = " + Anope::ToString(obj->object_id)); + s_type->objects.erase(obj->object_id); } this->updated_items.erase(obj); } @@ -227,10 +227,10 @@ public: Serializable *new_s = obj->Unserialize(s, data); if (new_s) { - // If s == new_s then s->id == new_s->id + // If s == new_s then s->object_id == new_s->object_id if (s != new_s) { - new_s->id = id; + new_s->object_id = id; obj->objects[id] = new_s; /* The Unserialize operation is destructive so rebuild the data for UpdateCache. diff --git a/modules/extra/mysql.cpp b/modules/extra/mysql.cpp index ef4e5e1ca..27c921343 100644 --- a/modules/extra/mysql.cpp +++ b/modules/extra/mysql.cpp @@ -159,7 +159,7 @@ public: std::vector CreateTable(const Anope::string &table, const Data &data) override; - Query BuildInsert(const Anope::string &table, unsigned int id, Data &data) override; + Query BuildInsert(const Anope::string &table, Serializable::Id id, Data &data) override; Query GetTables(const Anope::string &prefix) override; @@ -568,7 +568,7 @@ std::vector MySQLService::CreateTable(const Anope::string &table, const D return queries; } -Query MySQLService::BuildInsert(const Anope::string &table, unsigned int id, Data &data) +Query MySQLService::BuildInsert(const Anope::string &table, Serializable::Id id, Data &data) { /* Empty columns not present in the data set */ for (const auto &known_col : this->active_schema[table]) diff --git a/modules/extra/sqlite.cpp b/modules/extra/sqlite.cpp index 8799401d1..c6d30b668 100644 --- a/modules/extra/sqlite.cpp +++ b/modules/extra/sqlite.cpp @@ -69,7 +69,7 @@ public: std::vector CreateTable(const Anope::string &table, const Data &data) override; - Query BuildInsert(const Anope::string &table, unsigned int id, Data &data) override; + Query BuildInsert(const Anope::string &table, Serializable::Id id, Data &data) override; Query GetTables(const Anope::string &prefix) override; @@ -305,7 +305,7 @@ std::vector SQLiteService::CreateTable(const Anope::string &table, const return queries; } -Query SQLiteService::BuildInsert(const Anope::string &table, unsigned int id, Data &data) +Query SQLiteService::BuildInsert(const Anope::string &table, Serializable::Id id, Data &data) { /* Empty columns not present in the data set */ for (const auto &known_col : this->active_schema[table])