dmlite  0.6
MySqlWrapper.h
Go to the documentation of this file.
1 /// @file MySqlWrapper.h
2 /// @brief MySQL Wrapper.
3 /// @author Alejandro Álvarez Ayllón <aalvarez@cern.ch>
4 #ifndef MYSQLWRAPPER_H
5 #define MYSQLWRAPPER_H
6 
8 #include <mysql/mysql.h>
9 #include <stdint.h>
10 #include <map>
11 #include <vector>
12 
13 #include "utils/logger.h"
14 
15 namespace dmlite {
16 
17 
20 
21 /// Prepared statement wrapper.
22 class Statement {
23 public:
24  Statement(MYSQL* conn, const std::string& db, const char* query) ;
25  ~Statement() throw ();
26 
27  void bindParam(unsigned index, int64_t) ;
28  void bindParam(unsigned index, const std::string& value) ;
29  void bindParam(unsigned index, const char* value, size_t size) ;
30 
31  unsigned long execute(void) ;
32 
33  void bindResult(unsigned index, short* destination) ;
34  void bindResult(unsigned index, unsigned short* destination) ;
35  void bindResult(unsigned index, signed int* destination) ;
36  void bindResult(unsigned index, unsigned int* destination) ;
37  void bindResult(unsigned index, signed long* destination) ;
38  void bindResult(unsigned index, unsigned long* destination) ;
39  void bindResult(unsigned index, signed long long* destination) ;
40  void bindResult(unsigned index, unsigned long long* destination) ;
41  void bindResult(unsigned index, char* destination, size_t size) ;
42  void bindResult(unsigned index, char* destination, size_t size, int) ; // For blobs
43 
44  unsigned long count(void);
45 
46  bool fetch(void) ;
47 
48 protected:
49 private:
53 
54  MYSQL_STMT* stmt_;
55  unsigned long nParams_;
56  unsigned long nFields_;
57  MYSQL_BIND* params_;
58  MYSQL_BIND* result_;
59  my_bool* result_null_;
61  char* query_;
62 
63  /// Throws the proper exception
64  void throwException() ;
65  void zeroNullResults();
66 };
67 
68 };
69 
70 #endif // MYSQLWRAPPER_H
Definition: MySqlWrapper.h:50
Definition: MySqlWrapper.h:52
Definition: MySqlWrapper.h:51
Logger::bitmask mysqllogmask
bool fetch(void)
Definition: MySqlWrapper.h:50
MYSQL_STMT * stmt_
Definition: MySqlWrapper.h:54
unsigned long count(void)
Statement(MYSQL *conn, const std::string &db, const char *query)
unsigned long nParams_
Definition: MySqlWrapper.h:55
Logger::component mysqllogname
Prepared statement wrapper.
Definition: MySqlWrapper.h:22
void bindParam(unsigned index, int64_t)
MYSQL_BIND * result_
Definition: MySqlWrapper.h:58
unsigned long long bitmask
typedef for a bitmask (long long)
Definition: logger.h:79
Exceptions used by the API.
unsigned long execute(void)
Definition: MySqlWrapper.h:51
std::string component
typedef for a component name (std:string)
Definition: logger.h:81
Step
Definition: MySqlWrapper.h:50
Definition: MySqlWrapper.h:52
void throwException()
Throws the proper exception.
char * query_
Definition: MySqlWrapper.h:61
MYSQL_BIND * params_
Definition: MySqlWrapper.h:57
Step status_
Definition: MySqlWrapper.h:60
void bindResult(unsigned index, short *destination)
my_bool * result_null_
Definition: MySqlWrapper.h:59
unsigned long nFields_
Definition: MySqlWrapper.h:56