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) throw (DmException);
25  ~Statement() throw ();
26 
27  void bindParam(unsigned index, int64_t) throw (DmException);
28  void bindParam(unsigned index, const std::string& value) throw (DmException);
29  void bindParam(unsigned index, const char* value, size_t size) throw (DmException);
30 
31  unsigned long execute(void) throw (DmException);
32 
33  void bindResult(unsigned index, short* destination) throw (DmException);
34  void bindResult(unsigned index, unsigned short* destination) throw (DmException);
35  void bindResult(unsigned index, signed int* destination) throw (DmException);
36  void bindResult(unsigned index, unsigned int* destination) throw (DmException);
37  void bindResult(unsigned index, signed long* destination) throw (DmException);
38  void bindResult(unsigned index, unsigned long* destination) throw (DmException);
39  void bindResult(unsigned index, signed long long* destination) throw (DmException);
40  void bindResult(unsigned index, unsigned long long* destination) throw (DmException);
41  void bindResult(unsigned index, char* destination, size_t size) throw (DmException);
42  void bindResult(unsigned index, char* destination, size_t size, int) throw (DmException); // For blobs
43 
44  unsigned long count(void) throw ();
45 
46  bool fetch(void) throw (DmException);
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 
62  /// Throws the proper exception
63  void throwException() throw (DmException);
64  void zeroNullResults();
65 };
66 
67 };
68 
69 #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
Base exception class.
Definition: exceptions.h:17
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:40
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:42
Step
Definition: MySqlWrapper.h:50
Definition: MySqlWrapper.h:52
void throwException()
Throws the proper exception.
MYSQL_BIND * params_
Definition: MySqlWrapper.h:57
Step status_
Definition: MySqlWrapper.h:60
Namespace for the dmlite C++ API.
Definition: authn.h:15
void bindResult(unsigned index, short *destination)
my_bool * result_null_
Definition: MySqlWrapper.h:59
unsigned long nFields_
Definition: MySqlWrapper.h:56