libpqxx
prepared_statement.hxx
1 
11 #ifndef PQXX_H_PREPARED_STATEMENT
12 #define PQXX_H_PREPARED_STATEMENT
13 
14 #include "pqxx/compiler-public.hxx"
15 #include "pqxx/compiler-internal-pre.hxx"
16 
17 #include "pqxx/types.hxx"
18 #include "pqxx/internal/statement_parameters.hxx"
19 
20 
21 
22 namespace pqxx
23 {
25 namespace prepare
26 {
28 
43 template<typename IT> inline pqxx::internal::dynamic_params<IT>
44 make_dynamic_params(IT begin, IT end)
45 {
46  return pqxx::internal::dynamic_params<IT>(begin, end);
47 }
48 
49 
51 
65 template<typename C>
66 inline pqxx::internal::dynamic_params<typename C::const_iterator>
67 make_dynamic_params(const C &container)
68 {
69  return pqxx::internal::dynamic_params<typename C::const_iterator>(container);
70 }
71 } // namespace prepare
72 } // namespace pqxx
73 
74 namespace pqxx
75 {
76 namespace prepare
77 {
79 
81 class PQXX_LIBEXPORT invocation : internal::statement_parameters
82 {
83 public:
84  PQXX_DEPRECATED invocation(transaction_base &, const std::string &statement);
85  invocation &operator=(const invocation &) =delete;
86 
88  result exec() const;
89 
91  bool exists() const;
92 
94  invocation &operator()() { add_param(); return *this; }
95 
97 
100  template<typename T> invocation &operator()(const T &v)
101  { add_param(v, true); return *this; }
102 
104 
107  invocation &operator()(const binarystring &v)
108  { add_binary_param(v, true); return *this; }
109 
111 
115  template<typename T> invocation &operator()(const T &v, bool nonnull)
116  { add_param(v, nonnull); return *this; }
117 
119 
123  invocation &operator()(const binarystring &v, bool nonnull)
124  { add_binary_param(v, nonnull); return *this; }
125 
127 
134  template<typename T> invocation &operator()(T *v, bool nonnull=true)
135  { add_param(v, nonnull); return *this; }
136 
138 
142  invocation &operator()(const char *v, bool nonnull=true)
143  { add_param(v, nonnull); return *this; }
144 
145 private:
146  transaction_base &m_home;
147  const std::string m_statement;
148 
149  invocation &setparam(const std::string &, bool nonnull);
150 };
151 
152 
153 namespace internal
154 {
156 struct PQXX_LIBEXPORT prepared_def
157 {
159  std::string definition;
161  bool registered = false;
162 
163  prepared_def() =default;
164  explicit prepared_def(const std::string &);
165 };
166 
167 } // namespace pqxx::prepare::internal
168 } // namespace pqxx::prepare
169 } // namespace pqxx
170 
171 #include "pqxx/compiler-internal-post.hxx"
172 #endif
Helper class for passing parameters to, and executing, prepared statements.
Definition: prepared_statement.hxx:81
invocation & operator()(const T &v, bool nonnull)
Pass parameter value.
Definition: prepared_statement.hxx:115
Result set containing data returned by a query or command.
Definition: result.hxx:69
invocation & operator()(const T &v)
Pass parameter value.
Definition: prepared_statement.hxx:100
Interface definition (and common code) for "transaction" classes.
Definition: transaction_base.hxx:136
Binary data corresponding to PostgreSQL&#39;s "BYTEA" binary-string type.
Definition: binarystring.hxx:53
Internal representation of a prepared statement definition.
Definition: prepared_statement.hxx:156
invocation & operator()(const char *v, bool nonnull=true)
Pass C-style string parameter, or null if pointer is null.
Definition: prepared_statement.hxx:142
invocation & operator()(const binarystring &v, bool nonnull)
Pass binary parameter value for a BYTEA field.
Definition: prepared_statement.hxx:123
invocation & operator()(T *v, bool nonnull=true)
Pass C-style parameter string, or null if pointer is null.
Definition: prepared_statement.hxx:134
std::string definition
Text of prepared query.
Definition: prepared_statement.hxx:159
invocation & operator()(const binarystring &v)
Pass binary parameter value for a BYTEA field.
Definition: prepared_statement.hxx:107
invocation & operator()()
Pass null parameter.
Definition: prepared_statement.hxx:94
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
pqxx::internal::dynamic_params< IT > make_dynamic_params(IT begin, IT end)
Pass a number of statement parameters only known at runtime.
Definition: prepared_statement.hxx:44