]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_sqlite3.cpp
Change allocation of InspIRCd::Timers to be physically part of the object containing it
[user/henk/code/inspircd.git] / src / modules / extra / m_sqlite3.cpp
index b3bb5a51b1476aaf1afe5e7dad3f7df2a47f1c45..1c213e8e074550ca2b8d1b2d8287eb1fb1845109 100644 (file)
@@ -1,24 +1,35 @@
-/*              +------------------------------------+
- *              | Inspire Internet Relay Chat Daemon |
- *              +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
  *
- *     InspIRCd: (C) 2002-2010 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2007-2009 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2007, 2009 Craig Edwards <craigedwards@brainbox.cc>
+ *   Copyright (C) 2008 Pippijn van Steenhoven <pip88nl@gmail.com>
  *
- * This program is free but copyrighted software; see
- *                       the file COPYING for details.
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
  *
- * ---------------------------------------------------
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+
 #include "inspircd.h"
 #include <sqlite3.h>
-#include "sql.h"
+#include "modules/sql.h"
 
-/* $ModDesc: sqlite3 provider */
-/* $CompileFlags: pkgconfversion("sqlite3","3.3") pkgconfincludes("sqlite3","/sqlite3.h","") */
+#ifdef _WIN32
+# pragma comment(lib, "sqlite3.lib")
+#endif
+
+/* $CompileFlags: pkgconfversion("sqlite3","3.3") pkgconfincludes("sqlite3","/sqlite3.h","") -Wno-pedantic */
 /* $LinkerFlags: pkgconflibs("sqlite3","/libsqlite3.so","-lsqlite3") */
-/* $NoPedantic */
 
 class SQLConn;
 typedef std::map<std::string, SQLConn*> ConnMap;
@@ -35,16 +46,12 @@ class SQLite3Result : public SQLResult
        {
        }
 
-       ~SQLite3Result()
-       {
-       }
-
-       virtual int Rows()
+       int Rows()
        {
                return rows;
        }
 
-       virtual bool GetRow(SQLEntries& result)
+       bool GetRow(SQLEntries& result)
        {
                if (currentrow < rows)
                {
@@ -59,7 +66,7 @@ class SQLite3Result : public SQLResult
                }
        }
 
-       virtual void GetCols(std::vector<std::string>& result)
+       void GetCols(std::vector<std::string>& result)
        {
                result.assign(columns.begin(), columns.end());
        }
@@ -67,7 +74,6 @@ class SQLite3Result : public SQLResult
 
 class SQLConn : public SQLProvider
 {
- private:
        sqlite3* conn;
        reference<ConfigTag> config;
 
@@ -77,7 +83,7 @@ class SQLConn : public SQLProvider
                std::string host = tag->getString("hostname");
                if (sqlite3_open_v2(host.c_str(), &conn, SQLITE_OPEN_READWRITE, 0) != SQLITE_OK)
                {
-                       ServerInstance->Logs->Log("m_sqlite3",DEFAULT, "WARNING: Could not open DB with id: " + tag->getString("id"));
+                       ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "WARNING: Could not open DB with id: " + tag->getString("id"));
                        conn = NULL;
                }
        }
@@ -136,13 +142,13 @@ class SQLConn : public SQLProvider
                sqlite3_finalize(stmt);
        }
 
-       virtual void submit(SQLQuery* query, const std::string& q)
+       void submit(SQLQuery* query, const std::string& q)
        {
                Query(query, q);
                delete query;
        }
 
-       virtual void submit(SQLQuery* query, const std::string& q, const ParamL& p)
+       void submit(SQLQuery* query, const std::string& q, const ParamL& p)
        {
                std::string res;
                unsigned int param = 0;
@@ -163,7 +169,7 @@ class SQLConn : public SQLProvider
                submit(query, res);
        }
 
-       virtual void submit(SQLQuery* query, const std::string& q, const ParamM& p)
+       void submit(SQLQuery* query, const std::string& q, const ParamM& p)
        {
                std::string res;
                for(std::string::size_type i = 0; i < q.length(); i++)
@@ -174,7 +180,7 @@ class SQLConn : public SQLProvider
                        {
                                std::string field;
                                i++;
-                               while (i < q.length() && isalpha(q[i]))
+                               while (i < q.length() && isalnum(q[i]))
                                        field.push_back(q[i++]);
                                i--;
 
@@ -193,23 +199,10 @@ class SQLConn : public SQLProvider
 
 class ModuleSQLite3 : public Module
 {
- private:
        ConnMap conns;
 
  public:
-       ModuleSQLite3()
-       {
-       }
-
-       void init()
-       {
-               ReadConf();
-
-               Implementation eventlist[] = { I_OnRehash };
-               ServerInstance->Modules->Attach(eventlist, this, 1);
-       }
-
-       virtual ~ModuleSQLite3()
+       ~ModuleSQLite3()
        {
                ClearConns();
        }
@@ -225,7 +218,7 @@ class ModuleSQLite3 : public Module
                conns.clear();
        }
 
-       void ReadConf()
+       void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
                ClearConns();
                ConfigTagList tags = ServerInstance->Config->ConfTags("database");
@@ -239,12 +232,7 @@ class ModuleSQLite3 : public Module
                }
        }
 
-       void OnRehash(User* user)
-       {
-               ReadConf();
-       }
-
-       Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
                return Version("sqlite3 provider", VF_VENDOR);
        }