1 #ifndef PQXX_H_COMPOSITE 2 #define PQXX_H_COMPOSITE 4 #include "pqxx/internal/array-composite.hxx" 5 #include "pqxx/internal/concat.hxx" 6 #include "pqxx/util.hxx" 30 template<
typename... T>
32 pqxx::internal::encoding_group enc, std::string_view text, T &...fields)
34 static_assert(
sizeof...(fields) > 0);
37 auto const data{std::data(
text)};
38 auto const size{std::size(
text)};
42 std::size_t here{0}, next{scan(data, size, here)};
43 if (next != 1 or data[here] !=
'(')
45 internal::concat(
"Invalid composite value string: ",
text)};
50 constexpr
auto num_fields{
sizeof...(fields)};
52 (pqxx::internal::parse_composite_field(
53 index,
text, here, fields, scan, num_fields - 1),
55 if (here != std::size(
text))
57 "Composite value did not end at the closing parenthesis: '",
text,
59 if (
text[here - 1] !=
')')
61 "Composive value did not end in parenthesis: '",
text,
"'")};
71 template<
typename... T>
91 template<
typename... T>
92 [[nodiscard]]
inline std::size_t
96 constexpr
auto num{
sizeof...(fields)};
106 if constexpr (num == 0)
109 return 1 + (pqxx::internal::size_composite_field_buffer(fields) + ...) +
120 template<
typename... T>
125 "Buffer space may not be enough to represent composite value."};
128 constexpr
auto num_fields{
sizeof...(fields)};
129 if constexpr (num_fields == 0)
132 constexpr
char empty[]{
"()"};
133 std::memcpy(begin, empty, std::size(empty));
134 return begin + std::size(empty);
140 (pqxx::internal::write_composite_field<T>(pos, end, fields), ...);
143 if constexpr (num_fields > 1)
void parse_composite(pqxx::internal::encoding_group enc, std::string_view text, T &...fields)
Parse a string representation of a value of a composite type.
Definition: composite.hxx:31
PQXX_PURE glyph_scanner_func * get_glyph_scanner(encoding_group enc)
Definition: encodings.cxx:785
std::size_t composite_size_buffer(T const &...fields) noexcept
Estimate the buffer size needed to represent a value of a composite type.
Definition: composite.hxx:93
char * composite_into_buf(char *begin, char *end, T const &...fields)
Render a series of values as a single composite SQL value.
Definition: composite.hxx:121
Value conversion failed, e.g. when converting "Hello" to int.
Definition: except.hxx:175
constexpr char empty_composite_str[]
Definition: composite.hxx:82
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:22
Internal items for libpqxx' own use. Do not use these yourself.
Definition: composite.hxx:79