16 #include "pqxx/internal/concat.hxx" 17 #include "pqxx/internal/statement_parameters.hxx" 18 #include "pqxx/types.hxx" 43 [[deprecated(
"Use the params class instead.")]] constexpr
inline auto 46 return pqxx::internal::dynamic_params(begin, end);
68 [[deprecated(
"Use the params class instead.")]] constexpr
inline auto 71 using IT =
typename C::const_iterator;
72 #include "pqxx/internal/ignore-deprecated-pre.hxx" 73 return pqxx::internal::dynamic_params<IT>{container};
74 #include "pqxx/internal/ignore-deprecated-post.hxx" 96 template<
typename C,
typename ACCESSOR>
97 [[deprecated(
"Use the params class instead.")]] constexpr
inline auto 100 using IT = decltype(std::begin(container));
101 #include "pqxx/internal/ignore-deprecated-pre.hxx" 102 return pqxx::internal::dynamic_params<IT, ACCESSOR>{container, accessor};
103 #include "pqxx/internal/ignore-deprecated-post.hxx" 126 (std::numeric_limits<COUNTER>::max)()};
131 static constexpr
auto initial{
"$1\0"sv};
132 initial.copy(std::data(m_buf), std::size(initial));
147 std::string
get()
const {
return std::string(std::data(m_buf), m_len); }
154 "Too many parameters in one statement: limit is ",
max_params,
".")};
156 if (m_current % 10 == 0)
161 char *
const data{std::data(m_buf)};
163 data + 1, data + std::size(m_buf), m_current)};
165 m_len =
check_cast<COUNTER>(end - data,
"placeholders counter") - 1;
176 COUNTER
count() const noexcept {
return m_current; }
180 COUNTER m_current = 1;
193 std::array<char, std::numeric_limits<COUNTER>::digits10 + 3> m_buf;
219 template<
typename... Args> constexpr
params(Args &&...args)
221 reserve(
sizeof...(args));
222 append_pack(std::forward<Args>(args)...);
232 void reserve(std::size_t n) &;
235 [[nodiscard]]
auto size() const noexcept {
return m_params.size(); }
253 void append(
zview) &;
259 void append(std::string
const &) &;
262 void append(std::string &&) &;
268 void append(std::basic_string_view<std::byte>) &;
275 void append(std::basic_string<std::byte>
const &) &;
277 #if defined(PQXX_HAVE_CONCEPTS) 282 template<binary DATA>
void append(DATA
const &data) &
285 std::basic_string_view<std::byte>{std::data(data), std::size(data)});
287 #endif // PQXX_HAVE_CONCEPTS 290 void append(std::basic_string<std::byte> &&) &;
296 void append(binarystring
const &value) &;
299 template<
typename IT,
typename ACCESSOR>
300 void append(pqxx::internal::dynamic_params<IT, ACCESSOR>
const &value) &
302 for (
auto ¶m : value) append(value.access(param));
305 void append(
params const &value) &;
307 void append(
params &&value) &;
311 template<
typename TYPE>
void append(TYPE
const &value) &
317 m_params.emplace_back();
321 m_params.emplace_back();
325 m_params.emplace_back(entry{
to_string(value)});
332 #if defined(PQXX_HAVE_CONCEPTS) 333 if constexpr (std::ranges::sized_range<RANGE>)
334 reserve(std::size(*
this) + std::size(
range));
336 for (
auto &value :
range) append(value);
349 pqxx::internal::c_params make_c_params()
const;
353 template<
typename Arg,
typename... More>
354 void append_pack(Arg &&arg, More &&...args)
356 this->append(std::forward<Arg>(arg));
358 append_pack(std::forward<More>(args)...);
362 void append_pack() {}
367 using entry = std::variant<
368 std::nullptr_t, zview, std::string, std::basic_string_view<std::byte>,
369 std::basic_string<std::byte>>;
370 std::vector<entry> m_params;
373 static constexpr std::string_view s_overflow{
374 "Statement parameter length overflow."sv};
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:189
zview view() const &noexcept
Read an ephemeral version of the current placeholder text.
Definition: params.hxx:139
A C++ equivalent to PostgreSQL's range types.
Definition: range.hxx:198
Definition: params.hxx:22
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:37
auto ssize() const
Get the number of parameters (signed).
Definition: params.hxx:244
std::string to_string(field const &value)
Convert a field to a string.
Definition: result.cxx:528
Generate parameter placeholders for use in an SQL statement.
Definition: params.hxx:121
void next() &
Move on to the next parameter.
Definition: params.hxx:150
void append_multi(RANGE const &range) &
Append all elements of range as parameters.
Definition: params.hxx:330
bool is_null(TYPE const &value) noexcept
Is value null?
Definition: strconv.hxx:364
void ignore_unused(T &&...)
Suppress compiler warning about an unused item.
Definition: util.hxx:128
static char * into_buf(char *begin, char *end, TYPE const &value)
Write value's string representation into buffer at begin.
TO check_cast(FROM value, std::string_view description)
Cast a numeric value to another type, or throw if it underflows/overflows.
Definition: util.hxx:136
static constexpr unsigned int max_params
Maximum number of parameters we support.
Definition: params.hxx:125
Build a parameter list for a parameterised or prepared statement.
Definition: params.hxx:213
COUNTER count() const noexcept
Return the current placeholder number. The initial placeholder is 1.
Definition: params.hxx:176
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:22
std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition: types.hxx:87
placeholders()
Definition: params.hxx:128
auto ssize(T const &c)
Transitional: std::ssize(), or custom implementation if not available.
Definition: util.hxx:439
constexpr params(Args &&...args)
Pre-populate a params with args. Feel free to add more later.
Definition: params.hxx:219
void append(pqxx::internal::dynamic_params< IT, ACCESSOR > const &value) &
Append all parameters from value.
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:44
void append(TYPE const &value) &
Definition: params.hxx:311
auto size() const noexcept
Get the number of parameters currently in this params.
Definition: params.hxx:235
Traits describing a type's "null value," if any.
Definition: strconv.hxx:88