From 4e0997924d4052dede401fa1c0a1a91ae81c9aa3 Mon Sep 17 00:00:00 2001 From: danieldg Date: Sat, 6 Mar 2010 19:23:44 +0000 Subject: 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 --- src/modules/sql.h | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'src/modules/sql.h') 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 ParamL; typedef std::map 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 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& result) = 0; + virtual bool GetRow(SQLEntries& result) = 0; + + /** Returns column names for the items in this row + */ + virtual void GetCols(std::vector& 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 -- cgit v1.3.1-10-gc9f91