|
libpqxx
The C++ client library for PostgreSQL
|
Traits class for use in string conversions. More...
#include <strconv.hxx>
Static Public Member Functions | |
| static std::size_t | size_buffer (TYPE const &value) noexcept |
| Estimate how much buffer space is needed to represent value as SQL text. More... | |
| static std::string_view | to_buf (std::span< char > buf, TYPE const &value, ctx={}) |
Return a string_view representing value in SQL text. More... | |
| static TYPE | from_string (std::string_view text, ctx={}) |
Parse a string representation of a TYPE value. More... | |
Traits class for use in string conversions.
Specialize this template for a type for which you wish to add to_string and from_string support.
String conversions are not meant to work for nulls. Check for null before converting a value of TYPE to a string, or vice versa, and handle them separately.
|
inlinestatic |
Parse a string representation of a TYPE value.
Throws conversion_error if value does not meet the expected format for a value of this type.
std::string_view, you're basically just getting a pointer into the original buffer. So, the string_view will become invalid when the original string's lifetime ends, or when it gets overwritten. Do not access the string_view after that!If there is no support for converting from an SQL string to this type, simply leave this function out of the struct.
|
inlinestaticnoexcept |
Estimate how much buffer space is needed to represent value as SQL text.
The estimate may be a little pessimistic, if it saves time.
|
inlinestatic |
Return a string_view representing value in SQL text.
Produces a view on a PostgreSQL string representation for value.
Uses buf to store string contents, if needed. The returned string view may point somewhere inside that buffer, or to a compile-time constant, or just directly to value. Even if the string does live in buf, it may not start at the exact beginning of buf.
The resulting view stays valid for as long as both the buffer space to which buf points, and value, remain accessible and unmodified.
| pqxx::conversion_overrun | if buf is not large enough. For maximum performance, this is a conservative estimate. It may complain about a buffer which is actually large enough for your value, if an exact check would be too expensive. |
If there is no support for converting this type to an SQL string, simply leave this function out of the struct.