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
15namespace dmlite {
16
17
20
21/// Prepared statement wrapper.
22class Statement {
23public:
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
48protected:
49private:
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
66};
67
68};
69
70#endif // MYSQLWRAPPER_H
unsigned long long bitmask
typedef for a bitmask (long long)
Definition logger.h:79
std::string component
typedef for a component name (std:string)
Definition logger.h:81
Prepared statement wrapper.
Definition MySqlWrapper.h:22
unsigned long nFields_
Definition MySqlWrapper.h:56
Statement(MYSQL *conn, const std::string &db, const char *query)
unsigned long count(void)
void throwException()
Throws the proper exception.
MYSQL_BIND * params_
Definition MySqlWrapper.h:57
MYSQL_BIND * result_
Definition MySqlWrapper.h:58
bool fetch(void)
void bindResult(unsigned index, short *destination)
Step status_
Definition MySqlWrapper.h:60
unsigned long execute(void)
char * query_
Definition MySqlWrapper.h:61
unsigned long nParams_
Definition MySqlWrapper.h:55
my_bool * result_null_
Definition MySqlWrapper.h:59
Step
Definition MySqlWrapper.h:50
@ STMT_CREATED
Definition MySqlWrapper.h:50
@ STMT_RESULTS_UNBOUND
Definition MySqlWrapper.h:51
@ STMT_EXECUTED
Definition MySqlWrapper.h:50
@ STMT_DONE
Definition MySqlWrapper.h:52
@ STMT_RESULTS_BOUND
Definition MySqlWrapper.h:51
@ STMT_FAILED
Definition MySqlWrapper.h:52
void bindParam(unsigned index, int64_t)
MYSQL_STMT * stmt_
Definition MySqlWrapper.h:54
Exceptions used by the API.
Namespace for the dmlite C++ API.
Definition authn.h:16
Logger::component mysqllogname
Logger::bitmask mysqllogmask