]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_sqlite3.cpp
Attach to events and register services in init()
[user/henk/code/inspircd.git] / src / modules / extra / m_sqlite3.cpp
index e4b1e7266cf8e4e02eac6622b6f53ef5343fab11..c10f62bd257179eac90076898a1dc37378cae958 100644 (file)
@@ -1,20 +1,33 @@
-/*              +------------------------------------+
- *              | 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"
 
+#ifdef _WIN32
+# pragma comment(lib, "sqlite3.lib")
+#endif
+
 /* $ModDesc: sqlite3 provider */
 /* $CompileFlags: pkgconfversion("sqlite3","3.3") pkgconfincludes("sqlite3","/sqlite3.h","") */
 /* $LinkerFlags: pkgconflibs("sqlite3","/libsqlite3.so","-lsqlite3") */
@@ -58,6 +71,7 @@ class SQLite3Result : public SQLResult
                        return false;
                }
        }
+
        virtual void GetCols(std::vector<std::string>& result)
        {
                result.assign(columns.begin(), columns.end());
@@ -87,11 +101,11 @@ class SQLConn : public SQLProvider
                sqlite3_close(conn);
        }
 
-       void Query(SQLQuery* query)
+       void Query(SQLQuery* query, const std::string& q)
        {
                SQLite3Result res;
                sqlite3_stmt *stmt;
-               int err = sqlite3_prepare_v2(conn, query->query.c_str(), query->query.length(), &stmt, NULL);
+               int err = sqlite3_prepare_v2(conn, q.c_str(), q.length(), &stmt, NULL);
                if (err != SQLITE_OK)
                {
                        SQLerror error(SQL_QSEND_FAIL, sqlite3_errmsg(conn));
@@ -135,7 +149,13 @@ class SQLConn : public SQLProvider
                sqlite3_finalize(stmt);
        }
 
-       std::string FormatQuery(const std::string& q, const ParamL& p)
+       virtual 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)
        {
                std::string res;
                unsigned int param = 0;
@@ -145,7 +165,6 @@ class SQLConn : public SQLProvider
                                res.push_back(q[i]);
                        else
                        {
-                               // TODO numbered parameter support ('?1')
                                if (param < p.size())
                                {
                                        char* escaped = sqlite3_mprintf("%q", p[param++].c_str());
@@ -154,10 +173,10 @@ class SQLConn : public SQLProvider
                                }
                        }
                }
-               return res;
+               submit(query, res);
        }
 
-       std::string FormatQuery(const std::string& q, const ParamM& p)
+       virtual 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++)
@@ -168,7 +187,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--;
 
@@ -181,13 +200,7 @@ class SQLConn : public SQLProvider
                                }
                        }
                }
-               return res;
-       }
-       
-       virtual void submit(SQLQuery* query)
-       {
-               Query(query);
-               delete query;
+               submit(query, res);
        }
 };