From a434baed9154d90ad0dfd31c71a463fb8300bfd8 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 1 Oct 2012 18:50:29 -0400 Subject: Allow modules to store data in their own databases. --- modules/database/db_sql_live.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'modules/database/db_sql_live.cpp') diff --git a/modules/database/db_sql_live.cpp b/modules/database/db_sql_live.cpp index 4dca16d26..2aa3b73e6 100644 --- a/modules/database/db_sql_live.cpp +++ b/modules/database/db_sql_live.cpp @@ -95,18 +95,20 @@ class DBMySQL : public Module, public Pipe continue; obj->UpdateCache(); + SerializeType *s_type = obj->GetSerializableType(); + if (!s_type) + continue; + Serialize::Data data = obj->serialize(); - std::vector create = this->SQL->CreateTable(this->prefix + obj->serialize_name(), data); + std::vector create = this->SQL->CreateTable(this->prefix + s_type->GetName(), data); for (unsigned i = 0; i < create.size(); ++i) this->RunQueryResult(create[i]); - SQLResult res = this->RunQueryResult(this->SQL->BuildInsert(this->prefix + obj->serialize_name(), obj->id, data)); + SQLResult res = this->RunQueryResult(this->SQL->BuildInsert(this->prefix + s_type->GetName(), obj->id, data)); if (res.GetID() > 0) obj->id = res.GetID(); - SerializeType *stype = SerializeType::Find(obj->serialize_name()); - if (stype) - stype->objects.erase(obj->id); + s_type->objects.erase(obj->id); } } @@ -144,15 +146,16 @@ class DBMySQL : public Module, public Pipe { if (!this->CheckInit()) return; - this->RunQuery("DELETE FROM `" + this->prefix + obj->serialize_name() + "` WHERE `id` = " + stringify(obj->id)); - SerializeType *stype = SerializeType::Find(obj->serialize_name()); - if (stype) - stype->objects.erase(obj->id); + SerializeType *s_type = obj->GetSerializableType(); + if (!s_type) + return; + this->RunQuery("DELETE FROM `" + this->prefix + s_type->GetName() + "` WHERE `id` = " + stringify(obj->id)); + s_type->objects.erase(obj->id); } void OnSerializePtrAssign(Serializable *obj) anope_override { - SerializeType *stype = SerializeType::Find(obj->serialize_name()); + SerializeType *stype = obj->GetSerializableType(); if (stype == NULL || !this->CheckInit() || stype->GetTimestamp() == Anope::CurTime) return; @@ -160,7 +163,7 @@ class DBMySQL : public Module, public Pipe return; obj->UpdateCache(); - SQLResult res = this->RunQueryResult("SELECT * FROM `" + this->prefix + obj->serialize_name() + "` WHERE `id` = " + stringify(obj->id)); + SQLResult res = this->RunQueryResult("SELECT * FROM `" + this->prefix + stype->GetName() + "` WHERE `id` = " + stringify(obj->id)); if (res.Rows() == 0) obj->destroy(); -- cgit