diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-07-07 21:41:35 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-07-07 21:41:35 +0200 |
commit | 16904a791b67b8486afabf467719d6900a1b77d2 (patch) | |
tree | 92b05f16471ba290e1d72d9f86c20ac26b4da707 /src/modules/UserBackendMysql/UserBackendMysql.h | |
parent | c4cbe4a94fd63e0da6e291a481b9a9ccc71e7843 (diff) | |
download | mad-16904a791b67b8486afabf467719d6900a1b77d2.tar mad-16904a791b67b8486afabf467719d6900a1b77d2.zip |
UserBackendMysql: query-Methode hinzugefügt
Diffstat (limited to 'src/modules/UserBackendMysql/UserBackendMysql.h')
-rw-r--r-- | src/modules/UserBackendMysql/UserBackendMysql.h | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/modules/UserBackendMysql/UserBackendMysql.h b/src/modules/UserBackendMysql/UserBackendMysql.h index 25c3837..5c62072 100644 --- a/src/modules/UserBackendMysql/UserBackendMysql.h +++ b/src/modules/UserBackendMysql/UserBackendMysql.h @@ -29,6 +29,7 @@ #include <mysql/mysql.h> #include <boost/thread/mutex.hpp> +#include <boost/variant.hpp> namespace Mad { namespace Modules { @@ -36,27 +37,28 @@ namespace UserBackendMysql { class UserBackendMysql : public Common::UserBackend, private Core::Configurable, private boost::noncopyable { private: - class Result : private boost::noncopyable { + typedef std::map<std::string, boost::variant<std::string, unsigned long> > ArgumentMap; + + class Result; + Result query(const std::string &query, const ArgumentMap &args = ArgumentMap()) throw(Core::Exception); + + class Result { private: - MYSQL_RES *result; + friend Result UserBackendMysql::query(const std::string &query, const ArgumentMap &args) throw(Core::Exception); + + boost::shared_ptr<MYSQL_RES> result; unsigned int mysqlErrno; const char *error; - public: Result(MYSQL *mysql) { - result = mysql_store_result(mysql); + result = boost::shared_ptr<MYSQL_RES>(mysql_store_result(mysql), mysql_free_result); mysqlErrno = mysql_errno(mysql); error = mysql_error(mysql); } - ~Result() { - if(result) { - mysql_free_result(result); - } - } - + public: operator bool() const { return result; } @@ -70,15 +72,15 @@ class UserBackendMysql : public Common::UserBackend, private Core::Configurable, } unsigned int getFieldNumber() const { - return mysql_num_fields(result); + return mysql_num_fields(result.get()); } my_ulonglong getRowNumber() const { - return mysql_num_rows(result); + return mysql_num_rows(result.get()); } MYSQL_ROW getNextRow() { - return mysql_fetch_row(result); + return mysql_fetch_row(result.get()); } }; |