summaryrefslogtreecommitdiff
path: root/mg_database.h
blob: d974a337ae9411c7e420bcebcfb884e7264698c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*! 
 * \file   mg_database.h
 * \brief  A capsule around MySql database access
 *
 * \version $Revision: 1.2 $
 * \date    $Date$
 * \author  Ralf Klueber, Lars von Wedel, Andreas Kellner
 * \author  Responsible author: $Author$
 */

#ifndef __MG_DATABASE_H
#define __MG_DATABASE_H

#include <string>
#include <mysql/mysql.h>

/*!
 * \brief an abstract database class
 * 
 */
class mgDB
{
 public:

  /*! \brief default constructor 
   */
  mgDB( );

  /*! \brief constructor 
   *
   *  \param host
   *  \param name
   *  \param user
   *  \param pass
   *  \param port
   */
  mgDB( std::string host, std::string name,
	std::string user="", std::string pass="",
	int port = 0 );

  // add constructor for sockets
  
  /*! \brief constructor */
  ~mgDB();

  /*! 
   * \brief obtain database handle
   */
  MYSQL getDBHandle();

  /*! 
   * \brief database initialization
   */
  // int initialize();

  /*! 
   * \brief helper function to execute read queries
   *
   * \todo Could be a member of mgDatabase?
   */
  MYSQL_RES* read_query( const char *fmt, ... );

  /*! 
   * \brief helper function to execute write queries
   *
   * \todo Could be a member of mgDatabase?
   */
  void write_query( const char *fmt, ... );  

  /*!
   * \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;
};

#endif