@@ -205,7 +205,8 @@ class pg_conn_t
205205 }
206206
207207 /* *
208- * Run the named prepared SQL statement and return the results.
208+ * Run the named prepared SQL statement and return the results in text
209+ * format.
209210 *
210211 * \param stmt The name of the prepared statement.
211212 * \param params Any number of arguments (will be converted to strings
@@ -215,25 +216,24 @@ class pg_conn_t
215216 template <typename ... TArgs>
216217 pg_result_t exec_prepared (char const *stmt, TArgs... params) const
217218 {
218- // We have to convert all non-string parameters into strings and
219- // store them somewhere. We use the exec_params vector for this.
220- // It needs to be large enough to hold all parameters without resizing
221- // so that pointers into the strings in that vector remain valid
222- // after new parameters have been added.
223- constexpr auto const total_buffers_needed =
224- (0 + ... + detail::exec_arg<TArgs>::buffers_needed);
225- std::vector<std::string> exec_params;
226- exec_params.reserve (total_buffers_needed);
227-
228- // This array holds the pointers to all parameter strings, either
229- // to the original string parameters or to the recently converted
230- // in the exec_params vector.
231- std::array<char const *, sizeof ...(params)> param_ptrs = {
232- detail::exec_arg<TArgs>::to_str (&exec_params,
233- std::forward<TArgs>(params))...};
219+ return exec_prepared_with_result_format (stmt, false ,
220+ std::forward<TArgs>(params)...);
221+ }
234222
235- return exec_prepared_internal (stmt, sizeof ...(params),
236- param_ptrs.data (), nullptr , nullptr , 0 );
223+ /* *
224+ * Run the named prepared SQL statement and return the results in binary
225+ * format.
226+ *
227+ * \param stmt The name of the prepared statement.
228+ * \param params Any number of arguments (will be converted to strings
229+ * if necessary).
230+ * \throws exception if the command failed.
231+ */
232+ template <typename ... TArgs>
233+ pg_result_t exec_prepared_as_binary (char const *stmt, TArgs... params) const
234+ {
235+ return exec_prepared_with_result_format (stmt, true ,
236+ std::forward<TArgs>(params)...);
237237 }
238238
239239 /* *
@@ -258,6 +258,43 @@ class pg_conn_t
258258 int *param_lengths, int *param_formats,
259259 int result_format) const ;
260260
261+ /* *
262+ * Run the named prepared SQL statement and return the results.
263+ *
264+ * \param stmt The name of the prepared statement.
265+ * \param result_as_binary Ask for the resuls to be returned in binary
266+ * format.
267+ * \param params Any number of arguments (will be converted to strings
268+ * if necessary).
269+ * \throws exception if the command failed.
270+ */
271+ template <typename ... TArgs>
272+ pg_result_t exec_prepared_with_result_format (char const *stmt,
273+ bool result_as_binary,
274+ TArgs... params) const
275+ {
276+ // We have to convert all non-string parameters into strings and
277+ // store them somewhere. We use the exec_params vector for this.
278+ // It needs to be large enough to hold all parameters without resizing
279+ // so that pointers into the strings in that vector remain valid
280+ // after new parameters have been added.
281+ constexpr auto const total_buffers_needed =
282+ (0 + ... + detail::exec_arg<TArgs>::buffers_needed);
283+ std::vector<std::string> exec_params;
284+ exec_params.reserve (total_buffers_needed);
285+
286+ // This array holds the pointers to all parameter strings, either
287+ // to the original string parameters or to the recently converted
288+ // in the exec_params vector.
289+ std::array<char const *, sizeof ...(params)> param_ptrs = {
290+ detail::exec_arg<TArgs>::to_str (&exec_params,
291+ std::forward<TArgs>(params))...};
292+
293+ return exec_prepared_internal (stmt, sizeof ...(params),
294+ param_ptrs.data (), nullptr , nullptr ,
295+ result_as_binary ? 1 : 0 );
296+ }
297+
261298 struct pg_conn_deleter_t
262299 {
263300 void operator ()(PGconn *p) const noexcept { PQfinish (p); }
0 commit comments