diff options
| author | lvw <lvw@e10066b5-e1e2-0310-b819-94efdf66514b> | 2004-09-28 13:06:36 +0000 |
|---|---|---|
| committer | lvw <lvw@e10066b5-e1e2-0310-b819-94efdf66514b> | 2004-09-28 13:06:36 +0000 |
| commit | 3f5c7146afae5ebad6dd3b8613a70e5f0358ad3f (patch) | |
| tree | e9e57fb7639e62e08910cb9bad775dc44c967c47 | |
| parent | a9f79ae0a1344e965426c0c4e4885bebb6eb3129 (diff) | |
| download | vdr-plugin-muggle-3f5c7146afae5ebad6dd3b8613a70e5f0358ad3f.tar.gz vdr-plugin-muggle-3f5c7146afae5ebad6dd3b8613a70e5f0358ad3f.tar.bz2 | |
Added function to escape query strings
git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/trunk@188 e10066b5-e1e2-0310-b819-94efdf66514b
| -rw-r--r-- | muggle-plugin/mg_database.c | 16 | ||||
| -rw-r--r-- | muggle-plugin/mg_database.h | 16 |
2 files changed, 28 insertions, 4 deletions
diff --git a/muggle-plugin/mg_database.c b/muggle-plugin/mg_database.c index eabff6d..b25ee23 100644 --- a/muggle-plugin/mg_database.c +++ b/muggle-plugin/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/muggle-plugin/mg_database.h b/muggle-plugin/mg_database.h index 4e00826..3f2c323 100644 --- a/muggle-plugin/mg_database.h +++ b/muggle-plugin/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; |
