X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fextra%2Fm_sqlv2.h;h=f9da56c89d242171b1c30ddcd17898374618a9a5;hb=5adff9af1b71adb9ebaaa09159821b1947f7f625;hp=336fc89035b11fb5e41f763fcb1ba7e34cc09ad7;hpb=acb8786c19bc26a95ae68817cf5f8ec932e67b88;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/extra/m_sqlv2.h b/src/modules/extra/m_sqlv2.h index 336fc8903..f9da56c89 100644 --- a/src/modules/extra/m_sqlv2.h +++ b/src/modules/extra/m_sqlv2.h @@ -1,3 +1,16 @@ +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * InspIRCd: (C) 2002-2007 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits + * + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- + */ + #ifndef INSPIRCD_SQLAPI_2 #define INSPIRCD_SQLAPI_2 @@ -30,6 +43,14 @@ typedef std::deque ParamL; */ class SQLexception : public ModuleException { + public: + SQLexception(const std::string &reason) : ModuleException(reason) + { + } + + SQLexception() : ModuleException("SQLv2: Undefined exception") + { + } }; /** An exception thrown when a bad column or row name or id is requested @@ -37,7 +58,9 @@ class SQLexception : public ModuleException class SQLbadColName : public SQLexception { public: - SQLbadColName() { } + SQLbadColName() : SQLexception("SQLv2: Bad column name") + { + } }; /** SQLerror holds the error state of any SQLrequest or SQLresult. @@ -149,7 +172,6 @@ public: SQLquery(const std::string &query) : q(query) { - log(DEBUG, "SQLquery constructor: %s", q.c_str()); } /** Initialize an SQLquery with a format string and parameters. @@ -159,23 +181,22 @@ public: SQLquery(const std::string &query, const ParamL ¶ms) : q(query), p(params) { - log(DEBUG, "SQLquery constructor with %d params: %s", p.size(), q.c_str()); } /** An overloaded operator for pushing parameters onto the parameter list */ - SQLquery& operator,(const std::string &foo) + template SQLquery& operator,(const T &foo) { - p.push_back(foo); + p.push_back(ConvToStr(foo)); return *this; } /** An overloaded operator for pushing parameters onto the parameter list. * This has higher precedence than 'operator,' and can save on parenthesis. */ - SQLquery& operator%(const std::string &foo) + template SQLquery& operator%(const T &foo) { - p.push_back(foo); + p.push_back(ConvToStr(foo)); return *this; } }; @@ -221,7 +242,7 @@ public: * @param q A properly initialized SQLquery object. */ SQLrequest(Module* s, Module* d, const std::string &databaseid, const SQLquery &q) - : Request(SQLREQID, s, d), query(q), dbid(databaseid), pri(false), id(0) + : Request(s, d, SQLREQID), query(q), dbid(databaseid), pri(false), id(0) { } @@ -259,7 +280,7 @@ public: /** Initialize an SQLfield */ - SQLfield(const std::string &data, bool n) + SQLfield(const std::string &data = "", bool n = false) : d(data), null(n) { @@ -307,7 +328,7 @@ public: /** Used by the SQL API to instantiate an SQLrequest */ SQLresult(Module* s, Module* d, unsigned long i) - : Request(SQLRESID, s, d), id(i) + : Request(s, d, SQLRESID), id(i) { } @@ -315,16 +336,19 @@ public: * Return the number of rows in the result * Note that if you have perfomed an INSERT * or UPDATE query or other query which will - * not return rows, this value will NOT be - * the number of affected rows, as this would - * then indicate there are rows in the set, - * which there are not. + * not return rows, this will return the + * number of affected rows, and SQLresult::Cols() + * will contain 0. In this case you SHOULD NEVER + * access any of the result set rows, as there arent any! * @returns Number of rows in the result set. */ virtual int Rows() = 0; /** - * Return the number of columns in the result + * Return the number of columns in the result. + * If you performed an UPDATE or INSERT which + * does not return a dataset, this value will + * be 0. * @returns Number of columns in the result set. */ virtual int Cols() = 0; @@ -404,4 +428,43 @@ public: virtual void Free(SQLfieldList* fl) = 0; }; + +/** SQLHost represents a config line and is useful + * for storing in a map and iterating on rehash to see which + * tags was added/removed/unchanged. + */ +class SQLhost +{ + public: + std::string id; /* Database handle id */ + std::string host; /* Database server hostname */ + std::string ip; /* resolved IP, needed for at least pgsql.so */ + unsigned int port; /* Database server port */ + std::string name; /* Database name */ + std::string user; /* Database username */ + std::string pass; /* Database password */ + bool ssl; /* If we should require SSL */ + + SQLhost() + { + } + + SQLhost(const std::string& i, const std::string& h, unsigned int p, const std::string& n, const std::string& u, const std::string& pa, bool s) + : id(i), host(h), port(p), name(n), user(u), pass(pa), ssl(s) + { + } + + /** Overload this to return a correct Data source Name (DSN) for + * the current SQL module. + */ + std::string GetDSN(); +}; + +/** Overload operator== for two SQLhost objects for easy comparison. + */ +bool operator== (const SQLhost& l, const SQLhost& r) +{ + return (l.id == r.id && l.host == r.host && l.port == r.port && l.name == r.name && l.user == l.user && l.pass == r.pass && l.ssl == r.ssl); +} + #endif