diff options
-rw-r--r-- | mg_database.c | 16 | ||||
-rw-r--r-- | mg_database.h | 16 |
2 files changed, 28 insertions, 4 deletions
diff --git a/mg_database.c b/mg_database.c index eabff6d..b25ee23 100644 --- a/mg_database.c +++ b/mg_database.c @@ -3,9 +3,9 @@ * \brief A capsule around MySql database access ******************************************************************** * \version $Revision: 1.2 $ - * \date $Date: 2004/05/28 15:29:18 $ + * \date $Date$ * \author Ralf Klueber, Lars von Wedel, Andreas Kellner - * \author file owner: $Author: lvw $ + * \author file owner: $Author$ */ /*******************************************************************/ @@ -27,6 +27,18 @@ mgDB::~mgDB() { } +string mgDB::escape_string( MYSQL *db, string s ) +{ + char *escbuf = (char *) malloc( 2*s.length() + 1 ); + + int len = mysql_real_escape_string( db, escbuf, s.c_str(), s.length() ); + + string res( escbuf ); + free( resbuf ); + + return res; +} + MYSQL mgDB::getDBHandle() { diff --git a/mg_database.h b/mg_database.h index 4e00826..3f2c323 100644 --- a/mg_database.h +++ b/mg_database.h @@ -3,9 +3,9 @@ * \brief A capsule around MySql database access * * \version $Revision: 1.2 $ - * \date $Date: 2004/05/28 15:29:18 $ + * \date $Date$ * \author Ralf Klueber, Lars von Wedel, Andreas Kellner - * \author Responsible author: $Author: lvw $ + * \author Responsible author: $Author$ */ #ifndef __MG_DATABASE_H @@ -14,6 +14,11 @@ #include <string> #include <mysql/mysql.h> +/*! + * \brief an abstract database class + * + * \todo Currently unused. This class could abstract database connection and query handling, but this will be tedious as an abstract representation of results would be needed. + */ class mgDB { public: @@ -39,6 +44,13 @@ class mgDB /*! \brief obtain database handle*/ MYSQL getDBHandle(); + + /*! + * \brief escape arguments to be contained in a query + * + * \todo use m_dbase member of this class + */ + static std::string escape_string( MYSQL *db, std::string s ); private: MYSQL m_dbase; |