libpqxx: New `exec_prepared` and `exec_params` don't support runtime variable argument lists

Unless I’m missing something, the old prepared followed by exec methods (as we use here and here) no longer support the case where we don’t know how many parameters we need until runtime.

I’m looking at the APIs at these two locations:

What’s the intended method for doing this now? I’m looking at current HEAD of master. (ah, found something, see below)

We’ve been used prepared statements for this, but actually for most of our use cases it’d probably be better to use exec_params method.

What I think I really need is something with a function signature like this:

template<typename Iter, typename Func>
result exec_params(std::string_view query, Iter begin, Iter end, Func transform);

template<typename Iter, typename Func>
result exec_prepared(std::string_view query, Iter begin, Iter end, Func transform);

Hopefully it’s possible to do something with string_view rather than c_str for the return type from the transform, but for that to work I believe you’ll actually need to expect transform to return std::optional<std::string_view>.

I’ve just found #75 which also talks about this, so I’ll have a go at that solution. The only way I found out about dynamic_params was to look at the commit referenced in the issue 😃 Without the transform function it’s going to cost several allocations to do the data transform I need 😦

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 47 (47 by maintainers)

Commits related to this issue

Most upvoted comments

@KayEss I’ve prototyped a new class template, str, for representing values as std::string_view and avoiding buffer allocation. Actually it starts with a kind of generalised version of to_chars which returns a std::string_view — which may or may not point to text inside the buffer you give it. Will try to get it into master soon, so you can have a look.