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.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'modules/database/db_sql.cpp') diff --git a/modules/database/db_sql.cpp b/modules/database/db_sql.cpp index c07bdaa59..acc59b668 100644 --- a/modules/database/db_sql.cpp +++ b/modules/database/db_sql.cpp @@ -105,13 +105,17 @@ class DBSQL : 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->RunBackground(create[i]); - SQLQuery insert = this->sql->BuildInsert(this->prefix + obj->serialize_name(), obj->id, data); + SQLQuery insert = this->sql->BuildInsert(this->prefix + s_type->GetName(), obj->id, data); this->RunBackground(insert, new ResultSQLSQLInterface(this, obj)); } } @@ -188,7 +192,9 @@ class DBSQL : public Module, public Pipe void OnSerializableDestruct(Serializable *obj) anope_override { - this->RunBackground("DELETE FROM `" + this->prefix + obj->serialize_name() + "` WHERE `id` = " + stringify(obj->id)); + SerializeType *s_type = obj->GetSerializableType(); + if (s_type) + this->RunBackground("DELETE FROM `" + this->prefix + s_type->GetName() + "` WHERE `id` = " + stringify(obj->id)); } void OnSerializableUpdate(Serializable *obj) anope_override -- cgit