/** Defines the error types which SQLerror may be set to
*/
-enum SQLerrorNum { SQL_BAD_DBID, SQL_BAD_CONN, SQL_QSEND_FAIL, SQL_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.
*/
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
*/
-class SQLResult : public interfacebase
+class SQLResult : public classbase
{
public:
/**
* @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.
{
public:
ModuleRef creator;
- const std::string dbid;
- const std::string query;
- SQLQuery(Module* Creator, const std::string& db, const std::string& q)
- : creator(Creator), dbid(db), query(q) {}
+ SQLQuery(Module* Creator) : creator(Creator) {}
virtual ~SQLQuery() {}
virtual void OnResult(SQLResult& result) = 0;
public:
SQLProvider(Module* Creator, const std::string& Name) : DataProvider(Creator, Name) {}
/** Submit an asynchronous SQL request
- * @param dbid The database ID to apply the request to
- * @param query The query string
- * @param callback The callback that the result is sent to
+ * @param callback The result reporting point
+ * @param query The hardcoded query string. If you have parameters to substitute, see below.
*/
- virtual void submit(SQLQuery* query) = 0;
+ virtual void submit(SQLQuery* callback, const std::string& query) = 0;
- /** Format a parameterized query string using proper SQL escaping.
- * @param q The query string, with '?' parameters
- * @param p The parameters to fill in in the '?' slots
+ /** Submit an asynchronous SQL request
+ * @param callback The result reporting point
+ * @param format The simple parameterized query string ('?' parameters)
+ * @param p Parameters to fill in for the '?' entries
*/
- virtual std::string FormatQuery(std::string q, ParamL p) = 0;
+ virtual void submit(SQLQuery* callback, const std::string& format, 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
+ /** Submit an asynchronous SQL request.
+ * @param callback The result reporting point
+ * @param format The parameterized query string ('$name' parameters)
+ * @param p Parameters to fill in for the '$name' entries
*/
- virtual std::string FormatQuery(std::string q, ParamM p) = 0;
+ virtual void submit(SQLQuery* callback, const std::string& format, const ParamM& p) = 0;
+
+ /** Convenience function to prepare a map from a User* */
+ 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