summaryrefslogtreecommitdiff
path: root/src/modules/sql.h
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2010-03-06 19:23:44 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2010-03-06 19:23:44 +0000
commit4e0997924d4052dede401fa1c0a1a91ae81c9aa3 (patch)
treea788236c8fe31ef66a7aa040910129bc17c67bb8 /src/modules/sql.h
parentbee75f416868a1041e8853a6a5a7e818f0300acb (diff)
Add column names to SQLv3, allow sqloper to specify its own query string
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12606 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/sql.h')
-rw-r--r--src/modules/sql.h34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/modules/sql.h b/src/modules/sql.h
index 9114bea88..ffe95a9cb 100644
--- a/src/modules/sql.h
+++ b/src/modules/sql.h
@@ -24,6 +24,18 @@ typedef std::vector<std::string> ParamL;
typedef std::map<std::string, std::string> ParamM;
+class SQLEntry
+{
+ public:
+ std::string value;
+ bool nul;
+ SQLEntry() : nul(true) {}
+ SQLEntry(const std::string& v) : value(v), nul(false) {}
+ inline operator std::string&() { return value; }
+};
+
+typedef std::vector<SQLEntry> SQLEntries;
+
/**
* Result of an SQL query. Only valid inside OnResult
*/
@@ -49,7 +61,11 @@ class SQLResult : public interfacebase
* @returns true if there was a row, false if no row exists (end of
* iteration)
*/
- virtual bool GetRow(std::vector<std::string>& result) = 0;
+ virtual bool GetRow(SQLEntries& result) = 0;
+
+ /** Returns column names for the items in this row
+ */
+ virtual void GetCols(std::vector<std::string>& result) = 0;
};
/** SQLerror holds the error state of a request.
@@ -143,13 +159,25 @@ class SQLProvider : public DataProvider
* @param q The query string, with '?' parameters
* @param p The parameters to fill in in the '?' slots
*/
- virtual std::string FormatQuery(std::string q, ParamL p) = 0;
+ virtual std::string FormatQuery(const std::string& q, const ParamL& p) = 0;
/** Format a parameterized query string using proper SQL escaping.
* @param q The query string, with '$foo' parameters
* @param p The map to look up parameters in
*/
- virtual std::string FormatQuery(std::string q, ParamM p) = 0;
+ virtual std::string FormatQuery(const std::string& q, const ParamM& p) = 0;
+
+ /** Convenience function */
+ void PopulateUserInfo(User* user, ParamM& userinfo)
+ {
+ userinfo["nick"] = user->nick;
+ userinfo["host"] = user->host;
+ userinfo["ip"] = user->GetIPString();
+ userinfo["gecos"] = user->fullname;
+ userinfo["ident"] = user->ident;
+ userinfo["server"] = user->server;
+ userinfo["uuid"] = user->uuid;
+ }
};
#endif