soci-mysql.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton
3 // MySQL backend copyright (C) 2006 Pawel Aleksander Fedorynski
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 
9 #ifndef SOCI_MYSQL_H_INCLUDED
10 #define SOCI_MYSQL_H_INCLUDED
11 
12 #ifdef _WIN32
13 # ifdef SOCI_DLL
14 # ifdef SOCI_MYSQL_SOURCE
15 # define SOCI_MYSQL_DECL __declspec(dllexport)
16 # else
17 # define SOCI_MYSQL_DECL __declspec(dllimport)
18 # endif // SOCI_DLL
19 # endif // SOCI_MYSQL_SOURCE
20 #endif // _WIN32
21 //
22 // If SOCI_MYSQL_DECL isn't defined yet define it now
23 #ifndef SOCI_MYSQL_DECL
24 # define SOCI_MYSQL_DECL
25 #endif
26 
27 #include "soci-backend.h"
28 #ifdef _WIN32
29 #include <winsock.h> // SOCKET
30 #endif // _WIN32
31 #include <mysql.h> // MySQL Client
32 #include <vector>
33 
34 
35 namespace soci
36 {
37 
39 {
40 public:
41  mysql_soci_error(std::string const & msg, int errNum)
42  : soci_error(msg), err_num_(errNum) {}
43 
44  unsigned int err_num_;
45 };
46 
49 {
51  : statement_(st) {}
52 
53  virtual void define_by_pos(int &position,
54  void *data, details::exchange_type type);
55 
56  virtual void pre_fetch();
57  virtual void post_fetch(bool gotData, bool calledFromFetch,
58  indicator *ind);
59 
60  virtual void clean_up();
61 
63 
64  void *data_;
66  int position_;
67 };
68 
70 {
72  : statement_(st) {}
73 
74  virtual void define_by_pos(int &position,
75  void *data, details::exchange_type type);
76 
77  virtual void pre_fetch();
78  virtual void post_fetch(bool gotData, indicator *ind);
79 
80  virtual void resize(std::size_t sz);
81  virtual std::size_t size();
82 
83  virtual void clean_up();
84 
86 
87  void *data_;
89  int position_;
90 };
91 
93 {
95  : statement_(st), position_(0), buf_(NULL) {}
96 
97  virtual void bind_by_pos(int &position,
98  void *data, details::exchange_type type, bool readOnly);
99  virtual void bind_by_name(std::string const &name,
100  void *data, details::exchange_type type, bool readOnly);
101 
102  virtual void pre_use(indicator const *ind);
103  virtual void post_use(bool gotData, indicator *ind);
104 
105  virtual void clean_up();
106 
108 
109  void *data_;
112  std::string name_;
113  char *buf_;
114 };
115 
117 {
119  : statement_(st), position_(0) {}
120 
121  virtual void bind_by_pos(int &position,
122  void *data, details::exchange_type type);
123  virtual void bind_by_name(std::string const &name,
124  void *data, details::exchange_type type);
125 
126  virtual void pre_use(indicator const *ind);
127 
128  virtual std::size_t size();
129 
130  virtual void clean_up();
131 
133 
134  void *data_;
137  std::string name_;
138  std::vector<char *> buffers_;
139 };
140 
141 struct mysql_session_backend;
143 {
145 
146  virtual void alloc();
147  virtual void clean_up();
148  virtual void prepare(std::string const &query,
150 
151  virtual exec_fetch_result execute(int number);
152  virtual exec_fetch_result fetch(int number);
153 
154  virtual long long get_affected_rows();
155  virtual int get_number_of_rows();
156 
157  virtual std::string rewrite_for_procedure_call(std::string const &query);
158 
159  virtual int prepare_for_describe();
160  virtual void describe_column(int colNum, data_type &dtype,
161  std::string &columnName);
162 
163  virtual mysql_standard_into_type_backend * make_into_type_backend();
164  virtual mysql_standard_use_type_backend * make_use_type_backend();
165  virtual mysql_vector_into_type_backend * make_vector_into_type_backend();
166  virtual mysql_vector_use_type_backend * make_vector_use_type_backend();
167 
169 
170  MYSQL_RES *result_;
171 
172  // The query is split into chunks, separated by the named parameters;
173  // e.g. for "SELECT id FROM ttt WHERE name = :foo AND gender = :bar"
174  // we will have query chunks "SELECT id FROM ttt WHERE name = ",
175  // "AND gender = " and names "foo", "bar".
176  std::vector<std::string> queryChunks_;
177  std::vector<std::string> names_; // list of names for named binds
178 
179  long long rowsAffectedBulk_; // number of rows affected by the last bulk operation
180 
181  int numberOfRows_; // number of rows retrieved from the server
182  int currentRow_; // "current" row number to consume in postFetch
183  int rowsToConsume_; // number of rows to be consumed in postFetch
184 
185  bool justDescribed_; // to optimize row description with immediately
186  // following actual statement execution
187 
188  // Prefetch the row offsets in order to use mysql_row_seek() for
189  // random access to rows, since mysql_data_seek() is expensive.
190  std::vector<MYSQL_ROW_OFFSET> resultRowOffsets_;
191 
196 
197  // the following maps are used for finding data buffers according to
198  // use elements specified by the user
199 
200  typedef std::map<int, char **> UseByPosBuffersMap;
201  UseByPosBuffersMap useByPosBuffers_;
202 
203  typedef std::map<std::string, char **> UseByNameBuffersMap;
204  UseByNameBuffersMap useByNameBuffers_;
205 };
206 
208 {
210 
212 };
213 
215 {
217 
219 
220  virtual std::size_t get_len();
221  virtual std::size_t read(std::size_t offset, char *buf,
222  std::size_t toRead);
223  virtual std::size_t write(std::size_t offset, char const *buf,
224  std::size_t toWrite);
225  virtual std::size_t append(char const *buf, std::size_t toWrite);
226  virtual void trim(std::size_t newLen);
227 
229 };
230 
232 {
234 
236 
237  virtual void begin();
238  virtual void commit();
239  virtual void rollback();
240 
241  virtual std::string get_backend_name() const { return "mysql"; }
242 
243  void clean_up();
244 
245  virtual mysql_statement_backend * make_statement_backend();
246  virtual mysql_rowid_backend * make_rowid_backend();
247  virtual mysql_blob_backend * make_blob_backend();
248 
249  MYSQL *conn_;
250 };
251 
252 
254 {
256  virtual mysql_session_backend * make_session(
257  connection_parameters const & parameters) const;
258 };
259 
261 
262 extern "C"
263 {
264 
265 // for dynamic backend loading
268 
269 } // extern "C"
270 
271 } // namespace soci
272 
273 #endif // SOCI_MYSQL_H_INCLUDED
virtual std::string get_backend_name() const
Definition: soci-mysql.h:241
mysql_statement_backend & statement_
Definition: soci-mysql.h:132
mysql_session_backend & session_
Definition: soci-mysql.h:228
mysql_statement_backend & statement_
Definition: soci-mysql.h:107
details::exchange_type type_
Definition: soci-mysql.h:65
std::vector< MYSQL_ROW_OFFSET > resultRowOffsets_
Definition: soci-mysql.h:190
details::exchange_type type_
Definition: soci-mysql.h:88
details::exchange_type type_
Definition: soci-mysql.h:135
mysql_session_backend & session_
Definition: soci-mysql.h:168
std::vector< std::string > names_
Definition: soci-mysql.h:177
details::exchange_type type_
Definition: soci-mysql.h:110
SOCI_MYSQL_DECL backend_factory const * factory_mysql()
#define SOCI_MYSQL_DECL
Definition: soci-mysql.h:24
std::map< std::string, char ** > UseByNameBuffersMap
Definition: soci-mysql.h:203
mysql_standard_use_type_backend(mysql_statement_backend &st)
Definition: soci-mysql.h:94
mysql_standard_into_type_backend(mysql_statement_backend &st)
Definition: soci-mysql.h:50
mysql_soci_error(std::string const &msg, int errNum)
Definition: soci-mysql.h:41
std::map< int, char ** > UseByPosBuffersMap
Definition: soci-mysql.h:200
UseByNameBuffersMap useByNameBuffers_
Definition: soci-mysql.h:204
SOCI_MYSQL_DECL mysql_backend_factory const mysql
std::vector< char * > buffers_
Definition: soci-mysql.h:138
mysql_statement_backend & statement_
Definition: soci-mysql.h:62
std::vector< std::string > queryChunks_
Definition: soci-mysql.h:176
mysql_vector_use_type_backend(mysql_statement_backend &st)
Definition: soci-mysql.h:118
mysql_vector_into_type_backend(mysql_statement_backend &st)
Definition: soci-mysql.h:71
SOCI_MYSQL_DECL void register_factory_mysql()
std::vector< ISM::CombinatorialTrainerParameters > parameters
UseByPosBuffersMap useByPosBuffers_
Definition: soci-mysql.h:201
mysql_statement_backend & statement_
Definition: soci-mysql.h:85
unsigned int err_num_
Definition: soci-mysql.h:44


asr_lib_ism
Author(s): Hanselmann Fabian, Heller Florian, Heizmann Heinrich, Kübler Marcel, Mehlhaus Jonas, Meißner Pascal, Qattan Mohamad, Reckling Reno, Stroh Daniel
autogenerated on Wed Jan 8 2020 04:02:41