From b6f57c0f06f4905b04de6ec2069522d2263626c4 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Fri, 22 Dec 2017 02:47:54 +0000 Subject: Improve and modernize the SQL system API. - Move everything into the SQL namespace and drop the SQL prefix. - Move SQLProvider::PopulateUserInfo to SQL::PopulateUserInfo. - Rename SQLEntry to SQL::Field and clean up. - Rename SQLEntries to SQL::Row. - Rename SQLerror to SQL::Error and clean up. - Rename SQLerrorNum to SQL::ErrorCode and drop the SQL_ prefix. - Rename ParamL to SQL::ParamList. - Rename ParamM to SQL::ParamMap; - Make implementing SQLQuery::OnError mandatory. - Redo most of the documentation in the sql header. --- src/modules/m_sqloper.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/modules/m_sqloper.cpp') diff --git a/src/modules/m_sqloper.cpp b/src/modules/m_sqloper.cpp index b6aa90f49..d4baae7d2 100644 --- a/src/modules/m_sqloper.cpp +++ b/src/modules/m_sqloper.cpp @@ -21,16 +21,19 @@ #include "modules/sql.h" #include "modules/hash.h" -class OpMeQuery : public SQLQuery +class OperQuery : public SQL::Query { public: const std::string uid, username, password; - OpMeQuery(Module* me, const std::string& u, const std::string& un, const std::string& pw) - : SQLQuery(me), uid(u), username(un), password(pw) + OperQuery(Module* me, const std::string& u, const std::string& un, const std::string& pw) + : SQL::Query(me) + , uid(u) + , username(un) + , password(pw) { } - void OnResult(SQLResult& res) CXX11_OVERRIDE + void OnResult(SQL::Result& res) CXX11_OVERRIDE { ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "result for %s", uid.c_str()); User* user = ServerInstance->FindNick(uid); @@ -38,7 +41,7 @@ class OpMeQuery : public SQLQuery return; // multiple rows may exist - SQLEntries row; + SQL::Row row; while (res.GetRow(row)) { if (OperUser(user, row[0], row[1])) @@ -49,9 +52,9 @@ class OpMeQuery : public SQLQuery fallback(); } - void OnError(SQLerror& error) CXX11_OVERRIDE + void OnError(SQL::Error& error) CXX11_OVERRIDE { - ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "query failed (%s)", error.Str()); + ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "query failed (%s)", error.ToString()); fallback(); } @@ -106,7 +109,7 @@ class ModuleSQLOper : public Module { std::string query; std::string hashtype; - dynamic_reference SQL; + dynamic_reference SQL; public: ModuleSQLOper() : SQL(this, "SQL") {} @@ -144,12 +147,12 @@ public: { HashProvider* hash = ServerInstance->Modules->FindDataService("hash/" + hashtype); - ParamM userinfo; - SQL->PopulateUserInfo(user, userinfo); + SQL::ParamMap userinfo; + SQL::PopulateUserInfo(user, userinfo); userinfo["username"] = username; userinfo["password"] = hash ? hash->Generate(password) : password; - SQL->submit(new OpMeQuery(this, user->uuid, username, password), query, userinfo); + SQL->Submit(new OperQuery(this, user->uuid, username, password), query, userinfo); } Version GetVersion() CXX11_OVERRIDE -- cgit v1.3.1-10-gc9f91