* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
- * InspIRCd: (C) 2002-2007 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
+ * InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ * See: http://wiki.inspircd.org/Credits
*
* This program is free but copyrighted software; see
* the file COPYING for details.
#include <map>
#include "modules.h"
-/** SQLreq define.
- * This is the voodoo magic which lets us pass multiple
- * parameters to the SQLrequest constructor... voodoo...
- */
-#define SQLreq(a, b, c, d, e...) SQLrequest(a, b, c, (SQLquery(d), ##e))
-
/** Identifiers used to identify Request types
*/
#define SQLREQID "SQLv2 Request"
/** Defines the error types which SQLerror may be set to
*/
-enum SQLerrorNum { NO_ERROR, BAD_DBID, BAD_CONN, QSEND_FAIL, QREPLY_FAIL };
+enum SQLerrorNum { SQL_NO_ERROR, SQL_BAD_DBID, SQL_BAD_CONN, SQL_QSEND_FAIL, SQL_QREPLY_FAIL };
/** A list of format parameters for an SQLquery object.
*/
* @param i The error ID to set
* @param s The (optional) error string to set
*/
- SQLerror(SQLerrorNum i = NO_ERROR, const std::string &s = "")
+ SQLerror(SQLerrorNum i = SQL_NO_ERROR, const std::string &s = "")
: id(i), str(s)
{
}
switch(id)
{
- case NO_ERROR:
+ case SQL_NO_ERROR:
return "No error";
- case BAD_DBID:
+ case SQL_BAD_DBID:
return "Invalid database ID";
- case BAD_CONN:
+ case SQL_BAD_CONN:
return "Invalid connection";
- case QSEND_FAIL:
+ case SQL_QSEND_FAIL:
return "Sending query failed";
- case QREPLY_FAIL:
+ case SQL_QREPLY_FAIL:
return "Getting query result failed";
default:
return "Unknown error";
* the workaround for this isn't easy to describe simply, but in a nutshell what's really
* happening when - from the above example - you do this:
*
- * SQLrequest foo = SQLreq(this, target, "databaseid", "SELECT (foo, bar) FROM rawr WHERE foo = '?' AND bar = ?", "Hello", "42");
+ * SQLrequest foo = SQLrequest(this, target, "databaseid", SQLquery("SELECT (foo, bar) FROM rawr WHERE foo = '?' AND bar = ?", "Hello", "42"));
*
* what's actually happening is functionally this:
*
- * SQLrequest foo = SQLreq(this, target, "databaseid", query("SELECT (foo, bar) FROM rawr WHERE foo = '?' AND bar = ?").addparam("Hello").addparam("42"));
+ * SQLrequest foo = SQLrequest(this, target, "databaseid", query("SELECT (foo, bar) FROM rawr WHERE foo = '?' AND bar = ?").addparam("Hello").addparam("42"));
*
* with 'query()' returning a reference to an object with a 'addparam()' member function which
* in turn returns a reference to that object. There are actually four ways you can create a
* except in the case of an error.
*/
unsigned long id;
- /** If an error occured, error.id will be any other value than NO_ERROR.
+ /** If an error occured, error.id will be any other value than SQL_NO_ERROR.
*/
SQLerror error;
/** Initialize an SQLrequest.
* For example:
*
- * SQLrequest req = SQLreq(MyMod, SQLModule, dbid, "INSERT INTO ircd_log_actors VALUES('','?')", nick);
+ * SQLrequest req = SQLrequest(MyMod, SQLModule, dbid, SQLquery("INSERT INTO ircd_log_actors VALUES('','?')" % nick));
*
* @param s A pointer to the sending module, where the result should be routed
* @param d A pointer to the receiving module, identified as implementing the 'SQL' feature
/**
* The error (if any) which occured.
* If an error occured the value of error.id will be any
- * other value than NO_ERROR.
+ * other value than SQL_NO_ERROR.
*/
SQLerror error;
/**
bool ssl; /* If we should require SSL */
SQLhost()
+ : id(""), host(""), ip(""), port(0), name(""), user(""), pass(""), ssl(0)
{
}
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)
+ : id(i), host(h), ip(""), port(p), name(n), user(u), pass(pa), ssl(s)
{
}
*/
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);
+ return (l.id == r.id && l.host == r.host && l.port == r.port && l.name == r.name && l.user == r.user && l.pass == r.pass && l.ssl == r.ssl);
+}
+/** 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 != r.user || l.pass != r.pass || l.ssl != r.ssl);
}