diff options
Diffstat (limited to 'modules/database')
| -rw-r--r-- | modules/database/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | modules/database/flatfile.cpp | 7 | ||||
| -rw-r--r-- | modules/database/old.cpp | 140 | ||||
| -rw-r--r-- | modules/database/redis.cpp | 28 | ||||
| -rw-r--r-- | modules/database/sql.cpp | 100 |
5 files changed, 182 insertions, 94 deletions
diff --git a/modules/database/CMakeLists.txt b/modules/database/CMakeLists.txt index cd225a94d..9a236d6d0 100644 --- a/modules/database/CMakeLists.txt +++ b/modules/database/CMakeLists.txt @@ -1 +1,2 @@ build_modules(${CMAKE_CURRENT_SOURCE_DIR}) +build_modules_dependencies(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/modules/database/flatfile.cpp b/modules/database/flatfile.cpp index 122134960..b250be294 100644 --- a/modules/database/flatfile.cpp +++ b/modules/database/flatfile.cpp @@ -80,6 +80,8 @@ class DBFlatFile : public Module public: DBFlatFile(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR) + , EventHook<Event::LoadDatabase>(this) + , EventHook<Event::SaveDatabase>(this) , last_day(0) , loaded(false) { @@ -182,8 +184,9 @@ class DBFlatFile : public Module f << "OBJECT " << s_type->GetName() << "\n"; f << "ID " << object->id << "\n"; - for (Serialize::FieldBase *field : s_type->fields) - f << "DATA " << field->GetName() << " " << field->SerializeToString(object) << "\n"; + for (Serialize::FieldBase *field : s_type->GetFields()) + if (field->HasFieldS(object)) // for ext + f << "DATA " << field->serialize_name << " " << field->SerializeToString(object) << "\n"; f << "END\n"; } } diff --git a/modules/database/old.cpp b/modules/database/old.cpp index 27fb3565d..5e94cde02 100644 --- a/modules/database/old.cpp +++ b/modules/database/old.cpp @@ -8,6 +8,8 @@ * Based on the original code of Services by Andy Church. */ +/* Dependencies: anope_chanserv.access */ + #include "module.h" #include "modules/operserv/session.h" #include "modules/botserv/kick.h" @@ -159,6 +161,8 @@ enum static void process_mlock(ChanServ::Channel *ci, uint32_t lock, bool status, uint32_t *limit, Anope::string *key) { + ServiceReference<ModeLocks> mlocks; + if (!mlocks) return; @@ -463,7 +467,7 @@ static void LoadNicks() READ(read_string(buffer, f)); - NickServ::Account *nc = NickServ::account.Create(); + NickServ::Account *nc = Serialize::New<NickServ::Account *>(); nc->SetDisplay(buffer); const Anope::string settings[] = { "killprotect", "kill_quick", "ns_secure", "ns_private", "hide_email", @@ -532,9 +536,9 @@ static void LoadNicks() nc->SetS<bool>("HIDE_STATUS", true); if (u32 & OLD_NI_SUSPENDED) { - if (nssuspendinfo) + NSSuspendInfo *si = Serialize::New<NSSuspendInfo *>(); + if (si) { - NSSuspendInfo *si = nssuspendinfo.Create(); si->SetAccount(nc); } } @@ -594,9 +598,9 @@ static void LoadNicks() { READ(read_string(buffer, f)); - if (nsaccess) + NickAccess *a = Serialize::New<NickAccess *>(); + if (a) { - NickAccess *a = nsaccess.Create(); a->SetAccount(nc); a->SetMask(buffer); } @@ -610,7 +614,7 @@ static void LoadNicks() mi->SetMemoMax(i16); for (int16_t j = 0; j < i16; ++j) { - MemoServ::Memo *m = MemoServ::service ? MemoServ::service->CreateMemo() : nullptr; + MemoServ::Memo *m = Serialize::New<MemoServ::Memo *>(); READ(read_uint32(&u32, f)); uint16_t flags; READ(read_uint16(&flags, f)); @@ -664,28 +668,26 @@ static void LoadNicks() if (tmpu16 & OLD_NS_VERBOTEN) { - if (!forbiddata) + if (nc->GetDisplay().find_first_of("?*") != Anope::string::npos) { delete nc; continue; } - if (nc->GetDisplay().find_first_of("?*") != Anope::string::npos) + ForbidData *d = Serialize::New<ForbidData *>(); + if (d) { - delete nc; - continue; + d->SetMask(nc->GetDisplay()); + d->SetCreator(last_usermask); + d->SetReason(last_realname); + d->SetType(FT_NICK); } - - ForbidData *d = forbiddata.Create(); - d->SetMask(nc->GetDisplay()); - d->SetCreator(last_usermask); - d->SetReason(last_realname); - d->SetType(FT_NICK); + delete nc; continue; } - NickServ::Nick *na = NickServ::nick.Create(); + NickServ::Nick *na = Serialize::New<NickServ::Nick *>(); na->SetNick(nick); na->SetAccount(nc); na->SetLastUsermask(last_usermask); @@ -756,9 +758,8 @@ static void LoadBots() READ(read_int16(&chancount, f)); ServiceBot *bi = ServiceBot::Find(nick, true); - //XXX - // if (!bi) - // bi = new ServiceBot(nick, user, host, real); + if (!bi) + bi = new ServiceBot(nick, user, host, real); bi->bi->SetCreated(created); if (flags & OLD_BI_PRIVATE) @@ -772,10 +773,13 @@ static void LoadBots() static void LoadChannels() { - if (!ChanServ::service) + ServiceReference<BadWords> badwords; + ServiceReference<ChanServ::ChanServService> chanserv; + + if (!chanserv) return; - ServiceReference<ForbidService> forbid("ForbidService", "forbid"); + ServiceReference<ForbidService> forbid; dbFILE *f = open_db_read("ChanServ", "chan.db", 16); if (f == NULL) return; @@ -786,7 +790,7 @@ static void LoadChannels() Anope::string buffer; char namebuf[64]; READ(read_buffer(namebuf, f)); - ChanServ::Channel *ci = ChanServ::channel.Create(); + ChanServ::Channel *ci = Serialize::New<ChanServ::Channel *>(); ci->SetName(namebuf); const Anope::string settings[] = { "keeptopic", "peace", "cs_private", "restricted", "cs_secure", "secureops", "securefounder", @@ -860,9 +864,9 @@ static void LoadChannels() READ(read_string(forbidreason, f)); if (tmpu32 & OLD_CI_SUSPENDED) { - if (cssuspendinfo) + CSSuspendInfo *si = Serialize::New<CSSuspendInfo *>(); + if (si) { - CSSuspendInfo *si = cssuspendinfo.Create(); si->SetChannel(ci); si->SetBy(forbidby); } @@ -903,13 +907,11 @@ static void LoadChannels() if (xop) { - if (xopchanaccess) - access = xopchanaccess.Create(); + access = Serialize::New<XOPChanAccess *>(); } else { - if (accesschanaccess) - access = accesschanaccess.Create(); + access = Serialize::New<AccessChanAccess *>(); } if (access) @@ -998,7 +1000,7 @@ static void LoadChannels() { READ(read_uint32(&tmpu32, f)); READ(read_uint16(&tmpu16, f)); - MemoServ::Memo *m = MemoServ::service ? MemoServ::service->CreateMemo() : nullptr; + MemoServ::Memo *m = Serialize::New<MemoServ::Memo *>(); READ(read_int32(&tmp32, f)); if (m) m->SetTime(tmp32); @@ -1015,9 +1017,9 @@ static void LoadChannels() READ(read_string(buffer, f)); if (!buffer.empty()) { - if (entrymsg) + EntryMsg *e = Serialize::New<EntryMsg *>(); + if (e) { - EntryMsg *e = entrymsg.Create(); e->SetChannel(ci); e->SetCreator("Unknown"); e->SetMessage(buffer); @@ -1129,23 +1131,21 @@ static void LoadChannels() if (forbid_chan) { - if (!forbiddata) + if (ci->GetName().find_first_of("?*") != Anope::string::npos) { delete ci; continue; } - if (ci->GetName().find_first_of("?*") != Anope::string::npos) + ForbidData *d = Serialize::New<ForbidData *>(); + if (d) { - delete ci; - continue; + d->SetMask(ci->GetName()); + d->SetCreator(forbidby); + d->SetReason(forbidreason); + d->SetType(FT_CHAN); } - - ForbidData *d = forbiddata.Create(); - d->SetMask(ci->GetName()); - d->SetCreator(forbidby); - d->SetReason(forbidreason); - d->SetType(FT_CHAN); + delete ci; continue; } @@ -1198,8 +1198,14 @@ static void LoadOper() if (!akill) continue; - XLine *x = new XLine(user + "@" + host, by, expires, reason, XLineManager::GenerateUID()); + XLine *x = Serialize::New<XLine *>(); + x->SetMask(user + "@" + host); + x->SetBy(by); + x->SetExpires(expires); + x->SetReason(reason); + x->SetID(XLineManager::GenerateUID()); x->SetCreated(seton); + akill->AddXLine(x); } @@ -1218,8 +1224,14 @@ static void LoadOper() if (!snline) continue; - XLine *x = new XLine(mask, by, expires, reason, XLineManager::GenerateUID()); + XLine *x = Serialize::New<XLine *>(); + x->SetMask(mask); + x->SetBy(by); + x->SetExpires(expires); + x->SetReason(reason); + x->SetID(XLineManager::GenerateUID()); x->SetCreated(seton); + snline->AddXLine(x); } @@ -1238,8 +1250,14 @@ static void LoadOper() if (!sqline) continue; - XLine *x = new XLine(mask, by, expires, reason, XLineManager::GenerateUID()); + XLine *x = Serialize::New<XLine *>(); + x->SetMask(mask); + x->SetBy(by); + x->SetExpires(expires); + x->SetReason(reason); + x->SetID(XLineManager::GenerateUID()); x->SetCreated(seton); + sqline->AddXLine(x); } @@ -1258,8 +1276,14 @@ static void LoadOper() if (!szline) continue; - XLine *x = new XLine(mask, by, expires, reason, XLineManager::GenerateUID()); + XLine *x = Serialize::New<XLine *>(); + x->SetMask(mask); + x->SetBy(by); + x->SetExpires(expires); + x->SetReason(reason); + x->SetID(XLineManager::GenerateUID()); x->SetCreated(seton); + szline->AddXLine(x); } @@ -1268,9 +1292,6 @@ static void LoadOper() static void LoadExceptions() { - if (!session_service) - return; - dbFILE *f = open_db_read("OperServ", "exception.db", 9); if (f == NULL) return; @@ -1291,9 +1312,9 @@ static void LoadExceptions() READ(read_int32(&time, f)); READ(read_int32(&expires, f)); - if (exception && session_service) + Exception *e = Serialize::New<Exception *>(); + if (e) { - Exception *e = exception.Create(); e->SetMask(mask); e->SetLimit(limit); e->SetWho(who); @@ -1308,9 +1329,6 @@ static void LoadExceptions() static void LoadNews() { - if (!newsitem) - return; - dbFILE *f = open_db_read("OperServ", "news.db", 9); if (f == NULL) @@ -1322,7 +1340,10 @@ static void LoadNews() for (int16_t i = 0; i < n; i++) { int16_t type; - NewsItem *ni = newsitem.Create(); + NewsItem *ni = Serialize::New<NewsItem *>(); + + if (!ni) + break; READ(read_int16(&type, f)); @@ -1362,11 +1383,13 @@ class DBOld : public Module , public EventHook<Event::LoadDatabase> , public EventHook<Event::UplinkSync> { - ExtensibleItem<uint32_t> mlock_on, mlock_off, mlock_limit; + ExtensibleItem<uint32_t> mlock_on, mlock_off, mlock_limit; // XXX these are no longer required because of confmodes ExtensibleItem<Anope::string> mlock_key; public: DBOld(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR) + , EventHook<Event::LoadDatabase>(this) + , EventHook<Event::UplinkSync>(this) , mlock_on(this, "mlock_on") , mlock_off(this, "mlock_off") , mlock_limit(this, "mlock_limit") @@ -1424,5 +1447,10 @@ class DBOld : public Module } }; +template<> void ModuleInfo<DBOld>(ModuleDef *def) +{ + def->Depends("chanserv.access"); +} + MODULE_INIT(DBOld) diff --git a/modules/database/redis.cpp b/modules/database/redis.cpp index 72f25a16e..bb5103b4c 100644 --- a/modules/database/redis.cpp +++ b/modules/database/redis.cpp @@ -65,6 +65,8 @@ class DatabaseRedis : public Module ServiceReference<Provider> redis; DatabaseRedis(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR) + , EventHook<Event::LoadDatabase>(this) + , EventHook<Event::SerializeEvents>(this) , sl(this) { me = this; @@ -73,7 +75,7 @@ class DatabaseRedis : public Module void OnReload(Configuration::Conf *conf) override { Configuration::Block *block = conf->GetModule(this); - this->redis = ServiceReference<Provider>("Redis::Provider", block->Get<Anope::string>("engine", "redis/main")); + this->redis = ServiceReference<Provider>(block->Get<Anope::string>("engine", "redis/main")); } EventReturn OnLoadDatabase() override @@ -136,7 +138,7 @@ class DatabaseRedis : public Module redis->StartTransaction(); const Anope::string &old = field->SerializeToString(object); - args = { "SREM", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->GetName() + ":" + old, stringify(object->id) }; + args = { "SREM", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->serialize_name + ":" + old, stringify(object->id) }; redis->SendCommand(nullptr, args); // add object to type set @@ -144,15 +146,15 @@ class DatabaseRedis : public Module redis->SendCommand(nullptr, args); // add key to key set - args = { "SADD", "keys:" + stringify(object->id), field->GetName() }; + args = { "SADD", "keys:" + stringify(object->id), field->serialize_name }; redis->SendCommand(nullptr, args); // set value - args = { "SET", "values:" + stringify(object->id) + ":" + field->GetName(), value }; + args = { "SET", "values:" + stringify(object->id) + ":" + field->serialize_name, value }; redis->SendCommand(nullptr, args); // lookup - args = { "SADD", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->GetName() + ":" + value, stringify(object->id) }; + args = { "SADD", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->serialize_name + ":" + value, stringify(object->id) }; redis->SendCommand(nullptr, args); redis->CommitTransaction(); @@ -172,11 +174,11 @@ class DatabaseRedis : public Module redis->StartTransaction(); const Anope::string &old = field->SerializeToString(object); - args = { "SREM", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->GetName() + ":" + old, stringify(object->id) }; + args = { "SREM", "lookup:" + object->GetSerializableType()->GetName() + ":" + field->serialize_name + ":" + old, stringify(object->id) }; redis->SendCommand(nullptr, args); // remove field from set - args = { "SREM", "keys:" + stringify(object->id), field->GetName() }; + args = { "SREM", "keys:" + stringify(object->id), field->serialize_name }; redis->SendCommand(nullptr, args); redis->CommitTransaction(); @@ -219,17 +221,17 @@ class DatabaseRedis : public Module redis->StartTransaction(); - for (Serialize::FieldBase *field : obj->GetSerializableType()->fields) + for (Serialize::FieldBase *field : obj->GetSerializableType()->GetFields()) { Anope::string value = field->SerializeToString(obj); - args = { "SREM", "lookup:" + obj->GetSerializableType()->GetName() + ":" + field->GetName() + ":" + value, stringify(obj->id) }; + args = { "SREM", "lookup:" + obj->GetSerializableType()->GetName() + ":" + field->serialize_name + ":" + value, stringify(obj->id) }; redis->SendCommand(nullptr, args); - args = { "DEL", "values:" + stringify(obj->id) + ":" + field->GetName() }; + args = { "DEL", "values:" + stringify(obj->id) + ":" + field->serialize_name }; redis->SendCommand(nullptr, args); - args = { "SREM", "keys:" + stringify(obj->id), field->GetName() }; + args = { "SREM", "keys:" + stringify(obj->id), field->serialize_name }; redis->SendCommand(nullptr, args); } @@ -308,7 +310,7 @@ void ObjectLoader::OnResult(const Reply &r) void FieldLoader::OnResult(const Reply &r) { - Log(LOG_DEBUG_2) << "redis: Setting field " << field->GetName() << " of object #" << obj->id << " of type " << obj->GetSerializableType()->GetName() << " to " << r.bulk; + Log(LOG_DEBUG_2) << "redis: Setting field " << field->serialize_name << " of object #" << obj->id << " of type " << obj->GetSerializableType()->GetName() << " to " << r.bulk; field->UnserializeFromString(obj, r.bulk); delete this; @@ -366,7 +368,7 @@ void SubscriptionListener::OnResult(const Reply &r) return; } - Log(LOG_DEBUG_2) << "redis: Setting field " << field->GetName() << " of object #" << obj->id << " of type " << obj->GetSerializableType()->GetName() << " to " << value; + Log(LOG_DEBUG_2) << "redis: Setting field " << field->serialize_name << " of object #" << obj->id << " of type " << obj->GetSerializableType()->GetName() << " to " << value; field->UnserializeFromString(obj, value); } else if (command == "create") diff --git a/modules/database/sql.cpp b/modules/database/sql.cpp index fed0050e4..2d1a61afa 100644 --- a/modules/database/sql.cpp +++ b/modules/database/sql.cpp @@ -11,11 +11,26 @@ class DBMySQL : public Module, public Pipe bool inited = false; Anope::string prefix; ServiceReference<Provider> SQL; + std::unordered_multimap<Serialize::Object *, Serialize::FieldBase *> cache; + + void CacheMiss(Serialize::Object *object, Serialize::FieldBase *field) + { + cache.insert(std::make_pair(object, field)); + } + + bool IsCacheMiss(Serialize::Object *object, Serialize::FieldBase *field) + { + auto range = cache.equal_range(object); + for (auto it = range.first; it != range.second; ++it) + if (it->second == field) + return true; + return false; + } Result Run(const Query &query) { if (!SQL) - ;//XXX + return Result(); if (!inited) { @@ -24,6 +39,8 @@ class DBMySQL : public Module, public Pipe SQL->RunQuery(q); } + Log(LOG_DEBUG_2) << query.Unsafe(); + return SQL->RunQuery(query); } @@ -50,6 +67,7 @@ class DBMySQL : public Module, public Pipe public: DBMySQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR) + , EventHook<Event::SerializeEvents>(this) { } @@ -57,12 +75,13 @@ class DBMySQL : public Module, public Pipe { Commit(); Serialize::Clear(); + cache.clear(); } void OnReload(Configuration::Conf *conf) override { Configuration::Block *block = conf->GetModule(this); - this->SQL = ServiceReference<Provider>("SQL::Provider", block->Get<Anope::string>("engine")); + this->SQL = ServiceReference<Provider>(block->Get<Anope::string>("engine")); this->prefix = block->Get<Anope::string>("prefix", "anope_db_"); inited = false; } @@ -94,13 +113,13 @@ class DBMySQL : public Module, public Pipe for (Query &q : SQL->CreateTable(prefix, type->GetName())) Run(q); - for (Query &q : SQL->AlterTable(prefix, type->GetName(), field->GetName(), false)) + for (Query &q : SQL->AlterTable(prefix, type->GetName(), field->serialize_name, false)) Run(q); - for (const Query &q : SQL->CreateIndex(prefix + type->GetName(), field->GetName())) + for (const Query &q : SQL->CreateIndex(prefix + type->GetName(), field->serialize_name)) Run(q); - Query query("SELECT `id` FROM `" + prefix + type->GetName() + "` WHERE `" + field->GetName() + "` = @value@"); + Query query("SELECT `id` FROM `" + prefix + type->GetName() + "` WHERE `" + field->serialize_name + "` = @value@"); query.SetValue("value", value); Result res = Run(query); if (res.Rows()) @@ -120,14 +139,14 @@ class DBMySQL : public Module, public Pipe { StartTransaction(); - Query query = "SELECT `" + field->GetName() + "` FROM `" + prefix + object->GetSerializableType()->GetName() + "` WHERE `id` = @id@"; + Query query = "SELECT `" + field->serialize_name + "` FROM `" + prefix + object->GetSerializableType()->GetName() + "` WHERE `id` = @id@"; query.SetValue("id", object->id); Result res = Run(query); if (res.Rows() == 0) return false; - v = res.GetValue(0, field->GetName()); + v = res.GetValue(0, field->serialize_name); return true; } @@ -136,9 +155,12 @@ class DBMySQL : public Module, public Pipe { SQL::Result::Value v; + if (IsCacheMiss(object, field)) + return EVENT_CONTINUE; + if (!GetValue(object, field, v)) { - field->CacheMiss(object); + CacheMiss(object, field); return EVENT_CONTINUE; } @@ -175,7 +197,7 @@ class DBMySQL : public Module, public Pipe Result res = Run(query); for (int i = 0; i < res.Rows(); ++i) { - Serialize::ID id = convertTo<Serialize::ID>(res.Get(i, "id")); + Serialize::ID id = convertTo<Serialize::ID>(res.Get(i, "id")); // object edge is on if (id == object->id) { @@ -184,11 +206,26 @@ class DBMySQL : public Module, public Pipe Anope::string f = res.Get(i, "field"); id = convertTo<Serialize::ID>(res.Get(i, "other_id")); - //XXX sanity checks Serialize::FieldBase *obj_field = object->GetSerializableType()->GetField(f); + if (obj_field == nullptr) + { + Log(LOG_DEBUG) << "Unable to find field " << f << " on " << object->GetSerializableType()->GetName(); + continue; + } Serialize::TypeBase *obj_type = Serialize::TypeBase::Find(t); + if (obj_type == nullptr) + { + Log(LOG_DEBUG) << "Unable to find type " << t; + continue; + } + Serialize::Object *other = obj_type->Require(id); + if (other == nullptr) + { + Log(LOG_DEBUG) << "Unable to require id " << id << " type " << obj_type->GetName(); + continue; + } edges.emplace_back(other, obj_field, true); } @@ -198,10 +235,26 @@ class DBMySQL : public Module, public Pipe Anope::string t = res.Get(i, "type"); Anope::string f = res.Get(i, "field"); - //XXX sanity checks Serialize::TypeBase *obj_type = Serialize::TypeBase::Find(t); + if (obj_type == nullptr) + { + Log(LOG_DEBUG) << "Unable to find type " << t; + continue; + } + Serialize::FieldBase *obj_field = obj_type->GetField(f); + if (obj_field == nullptr) + { + Log(LOG_DEBUG) << "Unable to find field " << f << " on " << obj_type->GetName(); + continue; + } + Serialize::Object *other = obj_type->Require(id); + if (other == nullptr) + { + Log(LOG_DEBUG) << "Unable to require id " << id << " type " << obj_type->GetName(); + continue; + } // other type, other field, edges.emplace_back(other, obj_field, false); @@ -227,8 +280,8 @@ class DBMySQL : public Module, public Pipe { StartTransaction(); - Query query = "SELECT `" + field->GetName() + "`,j1.type AS " + field->GetName() + "_type FROM `" + prefix + object->GetSerializableType()->GetName() + "` " - "JOIN `" + prefix + "objects` AS j1 ON " + prefix + object->GetSerializableType()->GetName() + "." + field->GetName() + " = j1.id " + Query query = "SELECT `" + field->serialize_name + "`,j1.type AS " + field->serialize_name + "_type FROM `" + prefix + object->GetSerializableType()->GetName() + "` " + "JOIN `" + prefix + "objects` AS j1 ON " + prefix + object->GetSerializableType()->GetName() + "." + field->serialize_name + " = j1.id " "WHERE " + prefix + object->GetSerializableType()->GetName() + ".id = @id@"; query.SetValue("id", object->id); Result res = Run(query); @@ -236,10 +289,10 @@ class DBMySQL : public Module, public Pipe if (res.Rows() == 0) return EVENT_CONTINUE; - type = res.Get(0, field->GetName() + "_type"); + type = res.Get(0, field->serialize_name + "_type"); try { - value = convertTo<Serialize::ID>(res.Get(0, field->GetName())); + value = convertTo<Serialize::ID>(res.Get(0, field->serialize_name)); } catch (const ConvertException &ex) { @@ -260,15 +313,15 @@ class DBMySQL : public Module, public Pipe for (Query &q : SQL->CreateTable(prefix, object->GetSerializableType()->GetName())) Run(q); - for (Query &q : SQL->AlterTable(prefix, object->GetSerializableType()->GetName(), field->GetName(), is_object)) + for (Query &q : SQL->AlterTable(prefix, object->GetSerializableType()->GetName(), field->serialize_name, is_object)) Run(q); Query q; q.SetValue("id", object->id); if (value) - q.SetValue(field->GetName(), *value); + q.SetValue(field->serialize_name, *value); else - q.SetNull(field->GetName()); + q.SetNull(field->serialize_name); for (Query &q2 : SQL->Replace(prefix + object->GetSerializableType()->GetName(), q, { "id" })) Run(q2); @@ -294,7 +347,7 @@ class DBMySQL : public Module, public Pipe DoSet(object, field, true, &v); Query query; - query.SetValue("field", field->GetName()); + query.SetValue("field", field->serialize_name); query.SetValue("id", object->id); query.SetValue("other_id", value->id); @@ -307,7 +360,7 @@ class DBMySQL : public Module, public Pipe Query query("DELETE FROM `" + prefix + "edges` WHERE `id` = @id@ AND `field` = @field@"); query.SetValue("id", object->id); - query.SetValue("field", field->GetName()); + query.SetValue("field", field->serialize_name); Run(query); } @@ -317,18 +370,16 @@ class DBMySQL : public Module, public Pipe EventReturn OnSerializeUnset(Serialize::Object *object, Serialize::FieldBase *field) override { DoSet(object, field, false, nullptr); - field->CacheMiss(object); return EVENT_STOP; } EventReturn OnSerializeUnsetSerializable(Serialize::Object *object, Serialize::FieldBase *field) override { DoSet(object, field, true, nullptr); - field->CacheMiss(object); Query query("DELETE FROM `" + prefix + "edges` WHERE `id` = @id@ AND `field` = @field@"); query.SetValue("id", object->id); - query.SetValue("field", field->GetName()); + query.SetValue("field", field->serialize_name); Run(query); return EVENT_STOP; @@ -343,6 +394,9 @@ class DBMySQL : public Module, public Pipe EventReturn OnSerializableGetId(Serialize::ID &id) override { + if (!SQL) + return EVENT_CONTINUE; + StartTransaction(); id = SQL->GetID(prefix); |
