diff options
author | Sadie Powell <sadie@witchery.services> | 2024-08-14 02:40:48 +0100 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2024-08-14 05:47:55 +0100 |
commit | 528b5938ec71abed396248cf5e00f346e685aaea (patch) | |
tree | e923fed32be3fb62f946d44c633cd85ce855550b /src | |
parent | 03bee1706383d2766923e5d8edbb90d7ad1948b6 (diff) |
Automatically determine SQL column type from the field.
Also add more column types to ensure we are storing data in the
best format in the database.
Diffstat (limited to 'src')
-rw-r--r-- | src/access.cpp | 16 | ||||
-rw-r--r-- | src/bots.cpp | 12 | ||||
-rw-r--r-- | src/memos.cpp | 12 | ||||
-rw-r--r-- | src/nickalias.cpp | 24 | ||||
-rw-r--r-- | src/nickcore.cpp | 23 | ||||
-rw-r--r-- | src/regchannel.cpp | 47 | ||||
-rw-r--r-- | src/xline.cpp | 14 |
7 files changed, 77 insertions, 71 deletions
diff --git a/src/access.cpp b/src/access.cpp index f5d4d784b..95ecb5385 100644 --- a/src/access.cpp +++ b/src/access.cpp @@ -160,14 +160,14 @@ NickCore *ChanAccess::GetAccount() const void ChanAccess::Serialize(Serialize::Data &data) const { - data["provider"] << this->provider->name; - data["ci"] << this->ci->name; - data["mask"] << this->Mask(); - data["creator"] << this->creator; - data["description"] << this->description; - data.SetType("last_seen", Serialize::Data::DT_INT); data["last_seen"] << this->last_seen; - data.SetType("created", Serialize::Data::DT_INT); data["created"] << this->created; - data["data"] << this->AccessSerialize(); + data.Store("provider", this->provider->name); + data.Store("ci", this->ci->name); + data.Store("mask", this->Mask()); + data.Store("creator", this->creator); + data.Store("description", this->description); + data.Store("last_seen", this->last_seen); + data.Store("created", this->created); + data.Store("data", this->AccessSerialize()); } Serializable *ChanAccess::Unserialize(Serializable *obj, Serialize::Data &data) diff --git a/src/bots.cpp b/src/bots.cpp index 32b0546e6..0fb5c682d 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -75,12 +75,12 @@ BotInfo::~BotInfo() void BotInfo::Serialize(Serialize::Data &data) const { - data["nick"] << this->nick; - data["user"] << this->ident; - data["host"] << this->host; - data["realname"] << this->realname; - data["created"] << this->created; - data["oper_only"] << this->oper_only; + data.Store("nick", this->nick); + data.Store("user", this->ident); + data.Store("host", this->host); + data.Store("realname", this->realname); + data.Store("created", this->created); + data.Store("oper_only", this->oper_only); Extensible::ExtensibleSerialize(this, this, data); } diff --git a/src/memos.cpp b/src/memos.cpp index 2e9f10db1..3aaded57d 100644 --- a/src/memos.cpp +++ b/src/memos.cpp @@ -36,12 +36,12 @@ Memo::~Memo() void Memo::Serialize(Serialize::Data &data) const { - data["owner"] << this->owner; - data.SetType("time", Serialize::Data::DT_INT); data["time"] << this->time; - data["sender"] << this->sender; - data["text"] << this->text; - data["unread"] << this->unread; - data["receipt"] << this->receipt; + data.Store("owner", this->owner); + data.Store("time", this->time); + data.Store("sender", this->sender); + data.Store("text", this->text); + data.Store("unread", this->unread); + data.Store("receipt", this->receipt); } Serializable *Memo::Unserialize(Serializable *obj, Serialize::Data &data) diff --git a/src/nickalias.cpp b/src/nickalias.cpp index f7c6a79e2..1afa596b6 100644 --- a/src/nickalias.cpp +++ b/src/nickalias.cpp @@ -141,21 +141,21 @@ NickAlias *NickAlias::Find(const Anope::string &nick) void NickAlias::Serialize(Serialize::Data &data) const { - data["nick"] << this->nick; - data["last_quit"] << this->last_quit; - data["last_realname"] << this->last_realname; - data["last_usermask"] << this->last_usermask; - data["last_realhost"] << this->last_realhost; - data.SetType("time_registered", Serialize::Data::DT_INT); data["time_registered"] << this->time_registered; - data.SetType("last_seen", Serialize::Data::DT_INT); data["last_seen"] << this->last_seen; - data["nc"] << this->nc->display; + data.Store("nick", this->nick); + data.Store("last_quit", this->last_quit); + data.Store("last_realname", this->last_realname); + data.Store("last_usermask", this->last_usermask); + data.Store("last_realhost", this->last_realhost); + data.Store("time_registered", this->time_registered); + data.Store("last_seen", this->last_seen); + data.Store("nc", this->nc->display); if (this->HasVHost()) { - data["vhost_ident"] << this->GetVHostIdent(); - data["vhost_host"] << this->GetVHostHost(); - data["vhost_creator"] << this->GetVHostCreator(); - data["vhost_time"] << this->GetVHostCreated(); + data.Store("vhost_ident", this->GetVHostIdent()); + data.Store("vhost_host", this->GetVHostHost()); + data.Store("vhost_creator", this->GetVHostCreator()); + data.Store("vhost_time", this->GetVHostCreated()); } Extensible::ExtensibleSerialize(this, this, data); diff --git a/src/nickcore.cpp b/src/nickcore.cpp index 0fa721f8d..190a026bd 100644 --- a/src/nickcore.cpp +++ b/src/nickcore.cpp @@ -68,17 +68,20 @@ NickCore::~NickCore() void NickCore::Serialize(Serialize::Data &data) const { - data["display"] << this->display; - data["uniqueid"] << this->id; - data["pass"] << this->pass; - data["email"] << this->email; - data["language"] << this->language; - data.SetType("lastmail", Serialize::Data::DT_INT); data["lastmail"] << this->lastmail; - data.SetType("time_registered", Serialize::Data::DT_INT); data["time_registered"] << this->time_registered; - - data["memomax"] << this->memos.memomax; + data.Store("display", this->display); + data.Store("uniqueid", this->id); + data.Store("pass", this->pass); + data.Store("email", this->email); + data.Store("language", this->language); + data.Store("lastmail", this->lastmail); + data.Store("time_registered", this->time_registered); + data.Store("memomax", this->memos.memomax); + + std::ostringstream oss; for (const auto &ignore : this->memos.ignores) - data["memoignores"] << ignore << " "; + oss << ignore << " "; + data.Store("memoignores", oss.str()); + Extensible::ExtensibleSerialize(this, this, data); } diff --git a/src/regchannel.cpp b/src/regchannel.cpp index f01b31f3e..1a68b537f 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -40,15 +40,15 @@ AutoKick::~AutoKick() void AutoKick::Serialize(Serialize::Data &data) const { - data["ci"] << this->ci->name; + data.Store("ci", this->ci->name); if (this->nc) - data["nc"] << this->nc->display; + data.Store("nc", this->nc->display); else - data["mask"] << this->mask; - data["reason"] << this->reason; - data["creator"] << this->creator; - data.SetType("addtime", Serialize::Data::DT_INT); data["addtime"] << this->addtime; - data.SetType("last_used", Serialize::Data::DT_INT); data["last_used"] << this->last_used; + data.Store("mask", this->mask); + data.Store("reason", this->reason); + data.Store("creator", this->creator); + data.Store("addtime", this->addtime); + data.Store("last_used", this->last_used); } Serializable *AutoKick::Unserialize(Serializable *obj, Serialize::Data &data) @@ -180,30 +180,33 @@ ChannelInfo::~ChannelInfo() void ChannelInfo::Serialize(Serialize::Data &data) const { - data["name"] << this->name; + data.Store("name", this->name); if (this->founder) - data["founder"] << this->founder->display; + data.Store("founder", this->founder->display); if (this->successor) - data["successor"] << this->successor->display; - data["description"] << this->desc; - data.SetType("time_registered", Serialize::Data::DT_INT); data["time_registered"] << this->time_registered; - data.SetType("last_used", Serialize::Data::DT_INT); data["last_used"] << this->last_used; - data["last_topic"] << this->last_topic; - data["last_topic_setter"] << this->last_topic_setter; - data.SetType("last_topic_time", Serialize::Data::DT_INT); data["last_topic_time"] << this->last_topic_time; - data.SetType("bantype", Serialize::Data::DT_INT); data["bantype"] << this->bantype; + data.Store("successor", this->successor->display); + data.Store("description", this->desc); + data.Store("time_registered", this->time_registered); + data.Store("last_used", this->last_used); + data.Store("last_topic", this->last_topic); + data.Store("last_topic_setter", this->last_topic_setter); + data.Store("last_topic_time", this->last_topic_time); + data.Store("bantype", this->bantype); { Anope::string levels_buffer; for (const auto &[name, level] : this->levels) levels_buffer += name + " " + Anope::ToString(level) + " "; - data["levels"] << levels_buffer; + data.Store("levels", levels_buffer); } if (this->bi) - data["bi"] << this->bi->nick; - data.SetType("banexpire", Serialize::Data::DT_INT); data["banexpire"] << this->banexpire; - data["memomax"] << this->memos.memomax; + data.Store("bi", this->bi->nick); + data.Store("banexpire", this->banexpire); + data.Store("memomax", this->memos.memomax); + + std::ostringstream oss; for (const auto &ignore : this->memos.ignores) - data["memoignores"] << ignore << " "; + oss << ignore << " "; + data.Store("memoignores", oss.str()); Extensible::ExtensibleSerialize(this, this, data); } diff --git a/src/xline.cpp b/src/xline.cpp index 41f130b47..fcd2eb45d 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -153,14 +153,14 @@ bool XLine::IsRegex() const void XLine::Serialize(Serialize::Data &data) const { - data["mask"] << this->mask; - data["by"] << this->by; - data["created"] << this->created; - data["expires"] << this->expires; - data["reason"] << this->reason; - data["uid"] << this->id; + data.Store("mask", this->mask); + data.Store("by", this->by); + data.Store("created", this->created); + data.Store("expires", this->expires); + data.Store("reason", this->reason); + data.Store("uid", this->id); if (this->manager) - data["manager"] << this->manager->name; + data.Store("manager", this->manager->name); } Serializable *XLine::Unserialize(Serializable *obj, Serialize::Data &data) |