summaryrefslogtreecommitdiff
path: root/modules/database/db_sql_live.cpp
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2024-03-11 13:53:05 +0000
committerSadie Powell <sadie@witchery.services>2024-03-11 19:17:29 +0000
commit29e7674e56bf2b829bba22def2760d034a76e788 (patch)
treef40049ba995b03dd7c510d88f9f19db2d2e65a2e /modules/database/db_sql_live.cpp
parente2df7d4d01f8fdb41c49ce8efc462cab005e7d5c (diff)
Replace convertTo/stringify with non-throwing alternatives.
Having these throw is terrible for ergonomics and there are loads of places where the exception was either silently ignored or not handled at all. Having a function which returns an optional and another that returns a default works a lot better imo.
Diffstat (limited to 'modules/database/db_sql_live.cpp')
-rw-r--r--modules/database/db_sql_live.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/modules/database/db_sql_live.cpp b/modules/database/db_sql_live.cpp
index d97fe6683..839126d41 100644
--- a/modules/database/db_sql_live.cpp
+++ b/modules/database/db_sql_live.cpp
@@ -163,7 +163,7 @@ public:
if (s_type)
{
if (obj->id > 0)
- this->RunQuery("DELETE FROM `" + this->prefix + s_type->GetName() + "` WHERE `id` = " + stringify(obj->id));
+ this->RunQuery("DELETE FROM `" + this->prefix + s_type->GetName() + "` WHERE `id` = " + Anope::ToString(obj->id));
s_type->objects.erase(obj->id);
}
this->updated_items.erase(obj);
@@ -185,17 +185,16 @@ public:
{
const std::map<Anope::string, Anope::string> &row = res.Row(i);
- unsigned int id;
- try
- {
- id = convertTo<unsigned int>(res.Get(i, "id"));
- }
- catch (const ConvertException &)
+
+
+ auto oid = Anope::TryConvert<unsigned int>(res.Get(i, "id"));
+ if (!oid.has_value())
{
Log(LOG_DEBUG) << "Unable to convert id from " << obj->GetName();
continue;
}
+ auto id = oid.value();
if (res.Get(i, "timestamp").empty())
{
clear_null = true;
@@ -237,7 +236,7 @@ public:
else
{
if (!s)
- this->RunQuery("UPDATE `" + prefix + obj->GetName() + "` SET `timestamp` = " + this->SQL->FromUnixtime(obj->GetTimestamp()) + " WHERE `id` = " + stringify(id));
+ this->RunQuery("UPDATE `" + prefix + obj->GetName() + "` SET `timestamp` = " + this->SQL->FromUnixtime(obj->GetTimestamp()) + " WHERE `id` = " + Anope::ToString(id));
else
delete s;
}