soci-db2.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2011-2013 Denis Chapligin
3 // Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton
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_DB2_H_INCLUDED
10 #define SOCI_DB2_H_INCLUDED
11 
12 #ifdef _WIN32
13 # ifdef SOCI_DLL
14 # ifdef SOCI_DB2_SOURCE
15 # define SOCI_DB2_DECL __declspec(dllexport)
16 # else
17 # define SOCI_DB2_DECL __declspec(dllimport)
18 # endif // SOCI_DB2_SOURCE
19 # endif // SOCI_DLL
20 #endif // _WIN32
21 //
22 // If SOCI_DB2_DECL isn't defined yet define it now
23 #ifndef SOCI_DB2_DECL
24 # define SOCI_DB2_DECL
25 #endif
26 
27 #include "soci-backend.h"
28 
29 #include <cstddef>
30 #include <string>
31 #include <vector>
32 #include <iostream>
33 #include <sstream>
34 #include <string>
35 #include <cstring>
36 
37 #include <sqlcli1.h>
38 
39 namespace soci
40 {
41  namespace details { namespace db2
42  {
44  {
48  };
49  }}
50 
51  static const std::size_t maxBuffer = 1024 * 1024 * 1024; //CLI limit is about 3 GB, but 1GB should be enough
52 
53 class db2_soci_error : public soci_error {
54 public:
55  db2_soci_error(std::string const & msg, SQLRETURN rc) : soci_error(msg),errorCode(rc) {};
56  ~db2_soci_error() throw() { };
57 
58  //We have to extract error information before exception throwing, cause CLI handles could be broken at the construction time
59  static const std::string sqlState(std::string const & msg,const SQLSMALLINT htype,const SQLHANDLE hndl);
60 
61  SQLRETURN errorCode;
62 };
63 
65 
67 {
69  : statement_(st),buf(NULL)
70  {}
71 
72  void define_by_pos(int& position, void* data, details::exchange_type type);
73 
74  void pre_fetch();
75  void post_fetch(bool gotData, bool calledFromFetch, indicator* ind);
76 
77  void clean_up();
78 
80 
81  char* buf;
82  void *data;
84  int position;
85  SQLSMALLINT cType;
86  SQLLEN valueLen;
87 };
88 
90 {
92  : statement_(st),buf(NULL)
93  {}
94 
95  void define_by_pos(int& position, void* data, details::exchange_type type);
96 
97  void pre_fetch();
98  void post_fetch(bool gotData, indicator* ind);
99 
100  void resize(std::size_t sz);
101  std::size_t size();
102 
103  void clean_up();
104 
106 
107  void prepare_indicators(std::size_t size);
108 
109  SQLLEN *indptr;
110  std::vector<SQLLEN> indVec;
111  void *data;
112  char *buf;
115  SQLSMALLINT cType;
116  std::size_t colSize;
117 };
118 
120 {
122  : statement_(st),buf(NULL),ind(0)
123  {}
124 
125  void bind_by_pos(int& position, void* data, details::exchange_type type, bool readOnly);
126  void bind_by_name(std::string const& name, void* data, details::exchange_type type, bool readOnly);
127 
128  void pre_use(indicator const* ind);
129  void post_use(bool gotData, indicator* ind);
130 
131  void clean_up();
132 
134 
135  void *prepare_for_bind(void *data, SQLLEN &size, SQLSMALLINT &sqlType, SQLSMALLINT &cType);
136 
137  void *data;
139  int position;
140  std::string name;
141  char* buf;
142  SQLLEN ind;
143 };
144 
146 {
148  : statement_(st),buf(NULL) {}
149 
150  void bind_by_pos(int& position, void* data, details::exchange_type type);
151  void bind_by_name(std::string const& name, void* data, details::exchange_type type);
152 
153  void pre_use(indicator const* ind);
154 
155  std::size_t size();
156 
157  void clean_up();
158 
160 
161  void prepare_indicators(std::size_t size);
162  void prepare_for_bind(void *&data, SQLUINTEGER &size,SQLSMALLINT &sqlType, SQLSMALLINT &cType);
163  void bind_helper(int &position, void *data, details::exchange_type type);
164 
165  SQLLEN *indptr;
166  std::vector<SQLLEN> indVec;
167  void *data;
168  char *buf;
170  std::size_t colSize;
171 };
172 
173 struct db2_session_backend;
175 {
177 
178  void alloc();
179  void clean_up();
180  void prepare(std::string const& query, details::statement_type eType);
181 
182  exec_fetch_result execute(int number);
183  exec_fetch_result fetch(int number);
184 
185  long long get_affected_rows();
186  int get_number_of_rows();
187 
188  std::string rewrite_for_procedure_call(std::string const& query);
189 
190  int prepare_for_describe();
191  void describe_column(int colNum, data_type& dtype, std::string& columnName);
192  std::size_t column_size(int col);
193 
194  db2_standard_into_type_backend* make_into_type_backend();
195  db2_standard_use_type_backend* make_use_type_backend();
196  db2_vector_into_type_backend* make_vector_into_type_backend();
197  db2_vector_use_type_backend* make_vector_use_type_backend();
198 
200 
201  SQLHANDLE hStmt;
202  std::string query_;
203  std::vector<std::string> names;
205  SQLUINTEGER numRowsFetched;
207 };
208 
210 {
212 
214 };
215 
217 {
219 
220  ~db2_blob_backend();
221 
222  std::size_t get_len();
223  std::size_t read(std::size_t offset, char* buf, std::size_t toRead);
224  std::size_t write(std::size_t offset, char const* buf, std::size_t toWrite);
225  std::size_t append(char const* buf, std::size_t toWrite);
226  void trim(std::size_t newLen);
227 
229 };
230 
232 {
234 
236 
237  void begin();
238  void commit();
239  void rollback();
240 
241  std::string get_backend_name() const { return "DB2"; }
242 
243  void clean_up();
244 
245  db2_statement_backend* make_statement_backend();
246  db2_rowid_backend* make_rowid_backend();
247  db2_blob_backend* make_blob_backend();
248 
249  void parseConnectString(std::string const &);
250  void parseKeyVal(std::string const &);
251 
252  std::string dsn;
253  std::string username;
254  std::string password;
257 
258  SQLHANDLE hEnv; /* Environment handle */
259  SQLHANDLE hDbc; /* Connection handle */
260 };
261 
263 {
265  db2_session_backend* make_session(
266  connection_parameters const & parameters) const;
267 };
268 
270 
271 extern "C"
272 {
273 
274 // for dynamic backend loading
277 
278 } // extern "C"
279 
280 } // namespace soci
281 
282 #endif // SOCI_DB2_H_INCLUDED
db2_session_backend & session_
Definition: soci-db2.h:228
std::vector< SQLLEN > indVec
Definition: soci-db2.h:166
#define SOCI_DB2_DECL
Definition: soci-db2.h:24
details::exchange_type type
Definition: soci-db2.h:83
std::vector< SQLLEN > indVec
Definition: soci-db2.h:110
db2_session_backend & session_
Definition: soci-db2.h:199
details::exchange_type type
Definition: soci-db2.h:138
db2_vector_use_type_backend(db2_statement_backend &st)
Definition: soci-db2.h:147
details::db2::binding_method use_binding_method_
Definition: soci-db2.h:206
db2_statement_backend & statement_
Definition: soci-db2.h:159
db2_standard_use_type_backend(db2_statement_backend &st)
Definition: soci-db2.h:121
db2_vector_into_type_backend(db2_statement_backend &st)
Definition: soci-db2.h:91
details::exchange_type type
Definition: soci-db2.h:114
std::string get_backend_name() const
Definition: soci-db2.h:241
SOCI_DB2_DECL void register_factory_db2()
Definition: db2/factory.cpp:35
db2_statement_backend & statement_
Definition: soci-db2.h:105
db2_soci_error(std::string const &msg, SQLRETURN rc)
Definition: soci-db2.h:55
details::exchange_type type
Definition: soci-db2.h:169
SQLUINTEGER numRowsFetched
Definition: soci-db2.h:205
std::vector< std::string > names
Definition: soci-db2.h:203
static const std::size_t maxBuffer
Definition: soci-db2.h:51
SOCI_DB2_DECL backend_factory const * factory_db2()
Definition: db2/factory.cpp:30
SOCI_DB2_DECL db2_backend_factory const db2
Definition: db2/factory.cpp:24
std::vector< ISM::CombinatorialTrainerParameters > parameters
db2_statement_backend & statement_
Definition: soci-db2.h:79
db2_standard_into_type_backend(db2_statement_backend &st)
Definition: soci-db2.h:68
db2_statement_backend & statement_
Definition: soci-db2.h:133
SQLRETURN errorCode
Definition: soci-db2.h:61


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