statement.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2008 Maciej Sobczak, Stephen Hutton
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 //
7 
8 #ifndef SOCI_STATEMENT_H_INCLUDED
9 #define SOCI_STATEMENT_H_INCLUDED
10 
11 #include "bind-values.h"
12 #include "into-type.h"
13 #include "into.h"
14 #include "use-type.h"
15 #include "use.h"
16 #include "soci-backend.h"
17 #include "row.h"
18 // std
19 #include <cstddef>
20 #include <string>
21 #include <map>
22 #include <vector>
23 
24 namespace soci
25 {
26 
27 class session;
28 class values;
29 
30 namespace details
31 {
32 
33 class into_type_base;
34 class use_type_base;
35 class prepare_temp_type;
36 
38 {
39 public:
40  explicit statement_impl(session & s);
41  explicit statement_impl(prepare_temp_type const & prep);
42  ~statement_impl();
43 
44  void alloc();
45  void bind(values & v);
46 
47  void exchange(into_type_ptr const & i) { intos_.exchange(i); }
48  template <typename T, typename Indicator>
50  { intos_.exchange(ic); }
51 
52  void exchange(use_type_ptr const & u) { uses_.exchange(u); }
53  template <typename T, typename Indicator>
55  { uses_.exchange(uc); }
56 
57  void clean_up();
58 
59  void prepare(std::string const & query,
61  void define_and_bind();
62  void undefine_and_bind();
63  bool execute(bool withDataExchange = false);
64  long long get_affected_rows();
65  bool fetch();
66  void describe();
67  void set_row(row * r);
68  void exchange_for_rowset(into_type_ptr const & i) { exchange_for_rowset_(i); }
69  template<typename T, typename Indicator>
71  { exchange_for_rowset_(ic); }
72 
73  // for diagnostics and advanced users
74  // (downcast it to expected back-end statement class)
75  statement_backend * get_backend() { return backEnd_; }
76 
77  standard_into_type_backend * make_into_type_backend();
78  standard_use_type_backend * make_use_type_backend();
79  vector_into_type_backend * make_vector_into_type_backend();
80  vector_use_type_backend * make_vector_use_type_backend();
81 
82  void inc_ref();
83  void dec_ref();
84 
86 
87  std::string rewrite_for_procedure_call(std::string const & query);
88 
89 protected:
92  std::vector<indicator *> indicators_;
93 
94 private:
95 
96  int refCount_;
97 
98  row * row_;
99  std::size_t fetchSize_;
100  std::size_t initialFetchSize_;
101  std::string query_;
102  std::map<std::string, use_type_base *> namedUses_;
103 
106 
107  template <typename Into>
108  void exchange_for_rowset_(Into const &i)
109  {
110  if (intos_.empty() == false)
111  {
112  throw soci_error("Explicit into elements not allowed with rowset.");
113  }
114 
115  intos_.exchange(i);
116 
117  int definePosition = 1;
118  for(into_type_vector::iterator iter = intos_.begin(),
119  end = intos_.end();
120  iter != end; iter++)
121  { (*iter)->define(*this, definePosition); }
122  definePositionForRow_ = definePosition;
123  }
124 
125 
126  template <typename T, typename Indicator>
128  { intosForRow_.exchange(ic); }
129  void exchange_for_row(into_type_ptr const & i) { intosForRow_.exchange(i); }
130  void define_for_row();
131 
132  template<typename T>
133  void into_row()
134  {
135  T * t = new T();
136  indicator * ind = new indicator(i_ok);
137  row_->add_holder(t, ind);
138  exchange_for_row(into(*t, *ind));
139  }
140 
141  template<data_type>
142  void bind_into();
143 
145 
146  std::size_t intos_size();
147  std::size_t uses_size();
148  void pre_fetch();
149  void pre_use();
150  void post_fetch(bool gotData, bool calledFromFetch);
151  void post_use(bool gotData);
152  bool resize_intos(std::size_t upperBound = 0);
153  void truncate_intos();
154 
156 
157  // The type is noncopyable.
159  statement_impl& operator=(statement_impl const &);
160 
161 };
162 
163 } // namespace details
164 
165 // Statement is a handle class for statement_impl
166 // (this provides copyability to otherwise non-copyable type)
168 {
169 public:
171  : impl_(new details::statement_impl(s)) {}
173  : impl_(new details::statement_impl(prep)) {}
174  ~statement() { impl_->dec_ref(); }
175 
176  // copy is supported for this handle class
177  statement(statement const & other)
178  : impl_(other.impl_)
179  {
180  impl_->inc_ref();
181  }
182 
183  void operator=(statement const & other)
184  {
185  other.impl_->inc_ref();
186  impl_->dec_ref();
187  impl_ = other.impl_;
188  }
189 
190  void alloc() { impl_->alloc(); }
191  void bind(values & v) { impl_->bind(v); }
192  void exchange(details::into_type_ptr const & i) { impl_->exchange(i); }
193  template <typename T, typename Indicator>
194  void exchange(details::into_container<T, Indicator> const &ic) { impl_->exchange(ic); }
195  void exchange(details::use_type_ptr const & u) { impl_->exchange(u); }
196  template <typename T, typename Indicator>
197  void exchange(details::use_container<T, Indicator> const &uc) { impl_->exchange(uc); }
198  void clean_up() { impl_->clean_up(); }
199 
200  void prepare(std::string const & query,
202  {
203  impl_->prepare(query, eType);
204  }
205 
206  void define_and_bind() { impl_->define_and_bind(); }
207  void undefine_and_bind() { impl_->undefine_and_bind(); }
208  bool execute(bool withDataExchange = false)
209  {
210  gotData_ = impl_->execute(withDataExchange);
211  return gotData_;
212  }
213 
214  long long get_affected_rows()
215  {
216  return impl_->get_affected_rows();
217  }
218 
219  bool fetch()
220  {
221  gotData_ = impl_->fetch();
222  return gotData_;
223  }
224 
225  bool got_data() const { return gotData_; }
226 
227  void describe() { impl_->describe(); }
228  void set_row(row * r) { impl_->set_row(r); }
229 
230  template <typename T, typename Indicator>
232  {
233  impl_->exchange_for_rowset(ic);
234  }
235 
237  {
238  impl_->exchange_for_rowset(i);
239  }
240 
241  // for diagnostics and advanced users
242  // (downcast it to expected back-end statement class)
244  {
245  return impl_->get_backend();
246  }
247 
249  {
250  return impl_->make_into_type_backend();
251  }
252 
254  {
255  return impl_->make_use_type_backend();
256  }
257 
259  {
260  return impl_->make_vector_into_type_backend();
261  }
262 
264  {
265  return impl_->make_vector_use_type_backend();
266  }
267 
268  std::string rewrite_for_procedure_call(std::string const & query)
269  {
270  return impl_->rewrite_for_procedure_call(query);
271  }
272 
273 private:
275  bool gotData_;
276 };
277 
278 namespace details
279 {
280 // exchange_traits for statement
281 
282 template <>
284 {
286  enum { x_type = x_statement };
287 };
288 
289 // into and use types for Statement (for nested statements and cursors)
290 
291 template <>
293 {
294 public:
297  : standard_into_type(&s, x_statement, ind) {}
298 };
299 
300 template <>
302 {
303 public:
304  use_type(statement & s, std::string const & name = std::string())
305  : standard_use_type(&s, x_statement, false, name) {}
307  std::string const & name = std::string())
308  : standard_use_type(&s, x_statement, ind, false, name) {}
309 
310  // Note: there is no const version of use for statement,
311  // because most likely it would not make much sense anyway.
312 };
313 
314 } // namespace details
315 
316 } // namespace soci
317 
318 #endif // SOCI_STATEMENT_H_INCLUDED
void exchange_for_rowset(into_type_ptr const &i)
Definition: statement.h:68
into_type(statement &s, indicator &ind)
Definition: statement.h:296
void exchange(into_type_ptr const &i)
Definition: statement.h:47
details::into_container< T, details::no_indicator > into(T &t)
Definition: into.h:51
void describe()
Definition: statement.h:227
std::vector< indicator * > indicators_
Definition: statement.h:92
void bind(values &v)
Definition: statement.h:191
std::string rewrite_for_procedure_call(std::string const &query)
Definition: statement.h:268
use_type(statement &s, std::string const &name=std::string())
Definition: statement.h:304
into_type_vector intosForRow_
Definition: statement.h:104
Definition: row.h:41
statement(session &s)
Definition: statement.h:170
details::statement_backend * get_backend()
Definition: statement.h:243
void exchange(details::use_type_ptr const &u)
Definition: statement.h:195
void undefine_and_bind()
Definition: statement.h:207
void exchange(use_type_ptr const &u)
Definition: statement.h:52
void exchange(into_container< T, Indicator > const &ic)
Definition: statement.h:49
details::vector_use_type_backend * make_vector_use_type_backend()
Definition: statement.h:263
#define SOCI_DECL
Definition: soci-config.h:31
details::standard_use_type_backend * make_use_type_backend()
Definition: statement.h:253
void prepare(std::string const &query, details::statement_type eType=details::st_repeatable_query)
Definition: statement.h:200
void exchange(use_container< T, Indicator > const &uc)
Definition: statement.h:54
use_type(statement &s, indicator &ind, std::string const &name=std::string())
Definition: statement.h:306
std::map< std::string, use_type_base * > namedUses_
Definition: statement.h:102
long long get_affected_rows()
Definition: statement.h:214
void exchange_for_rowset(details::into_container< T, Indicator > const &ic)
Definition: statement.h:231
void exchange(details::into_container< T, Indicator > const &ic)
Definition: statement.h:194
void exchange_for_rowset(details::into_type_ptr const &i)
Definition: statement.h:236
soci::details::statement_backend * backEnd_
Definition: statement.h:155
void set_row(row *r)
Definition: statement.h:228
void exchange_for_row(into_type_ptr const &i)
Definition: statement.h:129
details::standard_into_type_backend * make_into_type_backend()
Definition: statement.h:248
void define_and_bind()
Definition: statement.h:206
details::vector_into_type_backend * make_vector_into_type_backend()
Definition: statement.h:258
void add_holder(T *t, indicator *ind)
Definition: row.h:56
into_type_vector intos_
Definition: statement.h:90
void exchange_for_rowset_(Into const &i)
Definition: statement.h:108
void exchange_for_rowset(into_container< T, Indicator > const &ic)
Definition: statement.h:70
void clean_up()
Definition: statement.h:198
void exchange_for_row(into_container< T, Indicator > const &ic)
Definition: statement.h:127
void operator=(statement const &other)
Definition: statement.h:183
void exchange(details::use_container< T, Indicator > const &uc)
Definition: statement.h:197
bool got_data() const
Definition: statement.h:225
void exchange(into_type_ptr const &i)
Definition: bind-values.h:119
void exchange(details::into_type_ptr const &i)
Definition: statement.h:192
statement_backend * get_backend()
Definition: statement.h:75
statement(statement const &other)
Definition: statement.h:177
details::statement_impl * impl_
Definition: statement.h:274
statement(details::prepare_temp_type const &prep)
Definition: statement.h:172
bool execute(bool withDataExchange=false)
Definition: statement.h:208


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