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 | 11f256059600e71a2e20f727d8d5e1600de35a1d (patch) | |
tree | d87b386279b1ac16ec725bfbd1f1fb68b9c007b4 | |
parent | cae0381ec6de30ac7e31b3be0f703894b44722f4 (diff) | |
download | vdr-plugin-muggle-11f256059600e71a2e20f727d8d5e1600de35a1d.tar.gz vdr-plugin-muggle-11f256059600e71a2e20f727d8d5e1600de35a1d.tar.bz2 |
Added function to escape query strings
git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/trunk/muggle-plugin@188 e10066b5-e1e2-0310-b819-94efdf66514b
-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; |