summaryrefslogtreecommitdiff
path: root/modules/database/db_sql_live.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/database/db_sql_live.cpp')
-rw-r--r--modules/database/db_sql_live.cpp55
1 files changed, 27 insertions, 28 deletions
diff --git a/modules/database/db_sql_live.cpp b/modules/database/db_sql_live.cpp
index 407ad6cd2..ea1fb1a27 100644
--- a/modules/database/db_sql_live.cpp
+++ b/modules/database/db_sql_live.cpp
@@ -11,9 +11,11 @@
using namespace SQL;
-class DBMySQL : public Module, public Pipe
+class DBMySQL final
+ : public Module
+ , public Pipe
{
- private:
+private:
Anope::string prefix;
ServiceReference<Provider> SQL;
time_t lastwarn;
@@ -35,7 +37,7 @@ class DBMySQL : public Module, public Pipe
}
else
{
- if (Anope::CurTime - Config->GetBlock("options")->Get<time_t>("updatetimeout", "5m") > lastwarn)
+ if (Anope::CurTime - Config->GetBlock("options")->Get<time_t>("updatetimeout", "2m") > lastwarn)
{
Log() << "Unable to locate SQL reference, going to readonly...";
Anope::ReadOnly = this->ro = true;
@@ -71,7 +73,7 @@ class DBMySQL : public Module, public Pipe
throw SQL::Exception("No SQL!");
}
- public:
+public:
DBMySQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE | VENDOR), SQL("", "")
{
this->lastwarn = 0;
@@ -83,15 +85,13 @@ class DBMySQL : public Module, public Pipe
throw ModuleException("If db_sql_live is loaded it must be the first database module loaded.");
}
- void OnNotify() anope_override
+ void OnNotify() override
{
if (!this->CheckInit())
return;
- for (std::set<Serializable *>::iterator it = this->updated_items.begin(), it_end = this->updated_items.end(); it != it_end; ++it)
+ for (auto *obj : this->updated_items)
{
- Serializable *obj = *it;
-
if (obj && this->SQL)
{
Data data;
@@ -107,8 +107,8 @@ class DBMySQL : public Module, public Pipe
continue;
std::vector<Query> create = this->SQL->CreateTable(this->prefix + s_type->GetName(), data);
- for (unsigned i = 0; i < create.size(); ++i)
- this->RunQueryResult(create[i]);
+ for (const auto &query : create)
+ this->RunQueryResult(query);
Result res = this->RunQueryResult(this->SQL->BuildInsert(this->prefix + s_type->GetName(), obj->id, data));
if (res.GetID() && obj->id != res.GetID())
@@ -123,30 +123,30 @@ class DBMySQL : public Module, public Pipe
this->updated_items.clear();
}
- EventReturn OnLoadDatabase() anope_override
+ EventReturn OnLoadDatabase() override
{
init = true;
return EVENT_STOP;
}
- void OnShutdown() anope_override
+ void OnShutdown() override
{
init = false;
}
- void OnRestart() anope_override
+ void OnRestart() override
{
init = false;
}
- void OnReload(Configuration::Conf *conf) anope_override
+ void OnReload(Configuration::Conf *conf) override
{
Configuration::Block *block = conf->GetModule(this);
this->SQL = ServiceReference<Provider>("SQL::Provider", block->Get<const Anope::string>("engine"));
this->prefix = block->Get<const Anope::string>("prefix", "anope_db_");
}
- void OnSerializableConstruct(Serializable *obj) anope_override
+ void OnSerializableConstruct(Serializable *obj) override
{
if (!this->CheckInit())
return;
@@ -155,7 +155,7 @@ class DBMySQL : public Module, public Pipe
this->Notify();
}
- void OnSerializableDestruct(Serializable *obj) anope_override
+ void OnSerializableDestruct(Serializable *obj) override
{
if (!this->CheckInit())
return;
@@ -163,13 +163,13 @@ class DBMySQL : public Module, public Pipe
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);
}
- void OnSerializeCheck(Serialize::Type *obj) anope_override
+ void OnSerializeCheck(Serialize::Type *obj) override
{
if (!this->CheckInit() || obj->GetTimestamp() == Anope::CurTime)
return;
@@ -185,17 +185,16 @@ class DBMySQL : public Module, public Pipe
{
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;
@@ -207,8 +206,8 @@ class DBMySQL : public Module, public Pipe
{
Data data;
- for (std::map<Anope::string, Anope::string>::const_iterator it = row.begin(), it_end = row.end(); it != it_end; ++it)
- data[it->first] << it->second;
+ for (const auto &[key, value] : row)
+ data[key] << value;
Serializable *s = NULL;
std::map<uint64_t, Serializable *>::iterator it = obj->objects.find(id);
@@ -237,7 +236,7 @@ class DBMySQL : public Module, public Pipe
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;
}
@@ -251,7 +250,7 @@ class DBMySQL : public Module, public Pipe
}
}
- void OnSerializableUpdate(Serializable *obj) anope_override
+ void OnSerializableUpdate(Serializable *obj) override
{
if (!this->CheckInit() || obj->IsTSCached())
return;