libpqxx 3.1.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

prepared_statement.hxx
1 /*-------------------------------------------------------------------------
2 *
3 * FILE
4 * pqxx/prepared_statement.hxx
5 *
6 * DESCRIPTION
7 * Helper classes for defining and executing prepared statements
8 * See the connection_base hierarchy for more about prepared statements
9 *
10 * Copyright (c) 2006-2009, Jeroen T. Vermeulen <jtv@xs4all.nl>
11 *
12 * See COPYING for copyright license. If you did not receive a file called
13 * COPYING with this source code, please notify the distributor of this mistake,
14 * or contact the author.
15 *
16 *-------------------------------------------------------------------------
17 */
18 #ifndef PQXX_H_PREPARED_STATEMENT
19 #define PQXX_H_PREPARED_STATEMENT
20
21 #include "pqxx/compiler-public.hxx"
22 #include "pqxx/compiler-internal-pre.hxx"
23
24 #include "pqxx/internal/statement_parameters.hxx"
25
26
27 namespace pqxx
28 {
29 class connection_base;
30 class transaction_base;
31 class result;
32
34 namespace prepare
35 {
123
124
141 enum param_treatment
142 {
144 treat_binary,
146 treat_string,
148 treat_bool,
150 treat_direct
151 };
152
153
155
163 class PQXX_LIBEXPORT declaration
164 {
165 public:
166 declaration(connection_base &, const PGSTD::string &statement);
167
169 const declaration &
170 operator()(const PGSTD::string &sqltype, param_treatment=treat_direct) const;
171
173
180 const declaration &etc(param_treatment=treat_direct) const;
181
182 private:
184 declaration &operator=(const declaration &);
185
186 connection_base &m_home;
187 const PGSTD::string m_statement;
188 };
189
190
192 class PQXX_LIBEXPORT invocation : internal::statement_parameters
193 {
194 public:
195 invocation(transaction_base &, const PGSTD::string &statement);
196
198 result exec() const;
199
201 bool exists() const;
202
204 invocation &operator()() { add_param(); return *this; }
205
207
210 template<typename T> invocation &operator()(const T &v)
211 { add_param(v); return *this; }
212
214
218 template<typename T> invocation &operator()(const T &v, bool nonnull)
219 { add_param(v, nonnull); return *this; }
220
222
240 template<typename T> invocation &operator()(T *v, bool nonnull=true)
241 { add_param(v, nonnull); return *this; }
242
244
248 invocation &operator()(const char *v, bool nonnull=true)
249 { add_param(v, nonnull); return *this; }
250
251 private:
253 invocation &operator=(const invocation &);
254
255 transaction_base &m_home;
256 const PGSTD::string m_statement;
257 PGSTD::vector<PGSTD::string> m_values;
258 PGSTD::vector<bool> m_nonnull;
259
260 invocation &setparam(const PGSTD::string &, bool nonnull);
261 };
262
263
264 namespace internal
265 {
267 struct PQXX_LIBEXPORT prepared_def
268 {
270 struct param
271 {
272 PGSTD::string sqltype;
273 param_treatment treatment;
274
275 param(const PGSTD::string &SQLtype, param_treatment);
276 };
277
279 PGSTD::string definition;
281 PGSTD::vector<param> parameters;
283 bool registered;
285 bool complete;
286
288 bool varargs;
289
291 param_treatment varargs_treatment;
292
293 prepared_def();
294 explicit prepared_def(const PGSTD::string &);
295
296 void addparam(const PGSTD::string &sqltype, param_treatment);
297 };
298
300 struct PQXX_PRIVATE get_sqltype
301 {
302 template<typename IT> const PGSTD::string &operator()(IT i)
303 {
304 return i->sqltype;
305 }
306 };
307
308 } // namespace pqxx::prepare::internal
309 } // namespace pqxx::prepare
310 } // namespace pqxx
311
312 #include "pqxx/compiler-internal-post.hxx"
313
314 #endif
315