14#if !defined(PQXX_HEADER_PRE)
15# error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
20#include "pqxx/internal/concat.hxx"
21#include "pqxx/internal/statement_parameters.hxx"
22#include "pqxx/types.hxx"
51 template<
typename... Args>
constexpr params(Args &&...args)
53 reserve(
sizeof...(args));
54 append_pack(std::forward<Args>(args)...);
64 void reserve(std::size_t n) &;
68 [[nodiscard]]
auto size() const noexcept {
return m_params.size(); }
92 void append(std::string
const &) &;
95 void append(std::string &&) &;
107 void append(
bytes const &) &;
109#if defined(PQXX_HAVE_CONCEPTS)
114 template<binary DATA>
void append(DATA
const &data) &
116 append(
bytes_view{std::data(data), std::size(data)});
121 void append(bytes &&) &;
127 void append(binarystring
const &value) &;
130 template<
typename IT,
typename ACCESSOR>
133 for (
auto ¶m : value) append(value.access(param));
136 void append(
params const &value) &;
138 void append(
params &&value) &;
142 template<
typename TYPE>
void append(TYPE
const &value) &
148 m_params.emplace_back();
152 m_params.emplace_back();
156 m_params.emplace_back(entry{
to_string(value)});
163#if defined(PQXX_HAVE_CONCEPTS)
164 if constexpr (std::ranges::sized_range<RANGE>)
165 reserve(std::size(*
this) + std::size(
range));
167 for (
auto &value :
range) append(value);
184 template<
typename Arg,
typename... More>
185 void append_pack(Arg &&arg, More &&...args)
187 this->append(std::forward<Arg>(arg));
189 append_pack(std::forward<More>(args)...);
193 constexpr void append_pack() noexcept {}
199 std::variant<std::nullptr_t, zview, std::string, bytes_view, bytes>;
200 std::vector<entry> m_params;
202 static constexpr std::string_view s_overflow{
203 "Statement parameter length overflow."sv};
223 (std::numeric_limits<COUNTER>::max)()};
227 static constexpr auto initial{
"$1\0"sv};
228 initial.copy(std::data(m_buf), std::size(initial));
237 return zview{std::data(m_buf), m_len};
246 std::string
get()
const {
return std::string(std::data(m_buf), m_len); }
253 "Too many parameters in one statement: limit is ",
max_params,
".")};
254 PQXX_ASSUME(m_current > 0);
256 if (m_current % 10 == 0)
261 char *
const data{std::data(m_buf)};
263 data + 1, data + std::size(m_buf), m_current)};
265 m_len = check_cast<COUNTER>(end - data,
"placeholders counter") - 1;
276 COUNTER
count() const noexcept {
return m_current; }
280 COUNTER m_current = 1;
293 std::array<char, std::numeric_limits<COUNTER>::digits10 + 3> m_buf;
320[[deprecated(
"Use the params class instead.")]]
constexpr inline auto
345[[deprecated(
"Use the params class instead.")]]
constexpr inline auto
348 using IT =
typename C::const_iterator;
349#include "pqxx/internal/ignore-deprecated-pre.hxx"
351#include "pqxx/internal/ignore-deprecated-post.hxx"
373template<
typename C,
typename ACCESSOR>
374[[deprecated(
"Use the params class instead.")]]
constexpr inline auto
377 using IT =
decltype(std::begin(container));
378#include "pqxx/internal/ignore-deprecated-pre.hxx"
380#include "pqxx/internal/ignore-deprecated-post.hxx"
Marker type: pass a dynamically-determined number of statement parameters.
Definition statement_parameters.hxx:54
Build a parameter list for a parameterised or prepared statement.
Definition params.hxx:46
auto size() const noexcept
Get the number of parameters currently in this params.
Definition params.hxx:68
void append_multi(RANGE const &range) &
Append all elements of range as parameters.
Definition params.hxx:161
void append(TYPE const &value) &
Definition params.hxx:142
auto ssize() const
Get the number of parameters (signed).
Definition params.hxx:77
void append(pqxx::internal::dynamic_params< IT, ACCESSOR > const &value) &
Append all parameters from value.
Definition params.hxx:131
constexpr params(Args &&...args)
Pre-populate a params with args. Feel free to add more later.
Definition params.hxx:51
Generate parameter placeholders for use in an SQL statement.
Definition params.hxx:219
static constexpr unsigned int max_params
Maximum number of parameters we support.
Definition params.hxx:222
COUNTER count() const noexcept
Return the current placeholder number. The initial placeholder is 1.
Definition params.hxx:276
std::string get() const
Read the current placeholder text, as a std::string.
Definition params.hxx:246
constexpr zview view() const &noexcept
Read an ephemeral version of the current placeholder text.
Definition params.hxx:235
void next() &
Move on to the next parameter.
Definition params.hxx:249
A C++ equivalent to PostgreSQL's range types.
Definition range.hxx:240
Marker-type wrapper: zero-terminated std::string_view.
Definition zview.hxx:38
Something is out of range, similar to std::out_of_range.
Definition except.hxx:326
std::string concat(TYPE... item)
Efficiently combine a bunch of items into one big string.
Definition concat.hxx:31
auto ssize(T const &c)
Transitional: std::ssize(), or custom implementation if not available.
Definition util.hxx:555
Definition params.hxx:300
constexpr auto make_dynamic_params(IT begin, IT end)
Pass a number of statement parameters only known at runtime.
Definition params.hxx:321
The home of all libpqxx classes, functions, templates, etc.
Definition array.cxx:27
constexpr void ignore_unused(T &&...) noexcept
Suppress compiler warning about an unused item.
Definition util.hxx:144
constexpr bool is_null(TYPE const &value) noexcept
Is value null?
Definition strconv.hxx:514
std::conditional< has_generic_bytes_char_traits, std::basic_string< std::byte >, std::basic_string< std::byte, byte_char_traits > >::type bytes
Type alias for a container containing bytes.
Definition util.hxx:375
PQXX_LIBEXPORT std::string to_string(field const &value)
Convert a field to a string.
Definition result.cxx:566
std::conditional< has_generic_bytes_char_traits, std::basic_string_view< std::byte >, std::basic_string_view< std::byte, byte_char_traits > >::type bytes_view
Type alias for a view of bytes.
Definition util.hxx:385
Internal type: encode statement parameters.
Definition statement_parameters.hxx:113
Traits describing a type's "null value," if any.
Definition strconv.hxx:91
static char * into_buf(char *begin, char *end, TYPE const &value)
Write value's string representation into buffer at begin.