New string conversion API
The string conversion API is changing in libpqxx 8.0.
In include/pqxx/strconv.hxx
you'll see a new API definition for the string
conversion template, string_traits
. It has the same function names, but the
signatures have changed.
When building new string conversions, please implement the new function signatures. If you already have string conversion code, please update it to the new API. The old API will eventually disappear.
These changes are on a per-function basis. So if you define your own string
conversions for a custom type, you don't need to rewrite all your conversion
functions at once. You can change to_buf()
in one release, from_buf()
in
the next, and into_buf()
later.
There are now generic versions of each of these, which will detect which API
version the conversion implements: pqxx::to_buf()
, pqxx::into_buf()
, and
pqxx::from_buf()
. These operate on the new API, but they know how to call
the old-style functions if needed.
The new API removes the raw pointers into buffers and replaces them with
std::span
. I hope this will make it easier for humans to avoid mistakes, and
for static analysis tools to check for memory safety.
The new API also introduces std::sourcec_location
parameters, so that libpqxx
can trace any exceptions it needs to throw back to where you originally called
into the library's code.