14 #include "pqxx/compiler-public.hxx"
15 #include "pqxx/internal/compiler-internal-pre.hxx"
17 #include "pqxx/internal/concat.hxx"
18 #include "pqxx/internal/statement_parameters.hxx"
19 #include "pqxx/types.hxx"
44 [[deprecated(
"Use the params class instead.")]] constexpr
inline auto
47 return pqxx::internal::dynamic_params(begin, end);
69 [[deprecated(
"Use the params class instead.")]] constexpr
inline auto
72 using IT =
typename C::const_iterator;
73 #include "pqxx/internal/ignore-deprecated-pre.hxx"
74 return pqxx::internal::dynamic_params<IT>{container};
75 #include "pqxx/internal/ignore-deprecated-post.hxx"
97 template<
typename C,
typename ACCESSOR>
98 [[deprecated(
"Use the params class instead.")]] constexpr
inline auto
101 using IT = decltype(std::begin(container));
102 #include "pqxx/internal/ignore-deprecated-pre.hxx"
103 return pqxx::internal::dynamic_params<IT, ACCESSOR>{container, accessor};
104 #include "pqxx/internal/ignore-deprecated-post.hxx"
127 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;
220 template<
typename... Args> constexpr
params(Args &&...args)
222 reserve(
sizeof...(args));
223 append_pack(std::forward<Args>(args)...);
233 void reserve(std::size_t n);
236 auto size() const noexcept {
return m_params.size(); }
260 void append(std::string
const &);
263 void append(std::string &&);
269 void append(std::basic_string_view<std::byte>);
276 void append(std::basic_string<std::byte>
const &);
278 #if defined(PQXX_HAVE_CONCEPTS)
283 template<binary DATA>
void append(DATA
const &data)
286 std::basic_string_view<std::byte>{std::data(data), std::size(data)});
291 void append(std::basic_string<std::byte> &&);
297 void append(binarystring
const &value);
300 template<
typename IT,
typename ACCESSOR>
301 void append(pqxx::internal::dynamic_params<IT, ACCESSOR>
const &value)
303 for (
auto ¶m : value) append(value.access(param));
306 void append(
params const &value);
308 void append(
params &&value);
312 template<
typename TYPE>
void append(TYPE
const &value)
318 m_params.emplace_back();
322 m_params.emplace_back();
326 m_params.emplace_back(entry{
to_string(value)});
333 #if defined(PQXX_HAVE_CONCEPTS)
334 if constexpr (std::ranges::sized_range<RANGE>)
335 reserve(std::size(*
this) + std::size(range));
337 for (
auto &value : range) append(value);
350 pqxx::internal::c_params make_c_params()
const;
354 template<
typename Arg,
typename... More>
355 void append_pack(Arg &&arg, More &&...args)
357 this->append(std::forward<Arg>(arg));
359 append_pack(std::forward<More>(args)...);
363 void append_pack() {}
368 using entry = std::variant<
369 std::nullptr_t, zview, std::string, std::basic_string_view<std::byte>,
370 std::basic_string<std::byte>>;
371 std::vector<entry> m_params;
373 static constexpr std::string_view s_overflow{
374 "Statement parameter length overflow."sv};
378 #include "pqxx/internal/compiler-internal-post.hxx"
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:26
void ignore_unused(T &&...)
Suppress compiler warning about an unused item.
Definition: util.hxx:71
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
std::string to_string(field const &value)
Convert a field to a string.
Definition: result.cxx:507
bool is_null(TYPE const &value) noexcept
Is value null?
Definition: strconv.hxx:357
auto ssize(T const &c)
Transitional: std::ssize(), or custom implementation if not available.
Definition: util.hxx:368
Definition: params.hxx:24
constexpr auto make_dynamic_params(IT begin, IT end)
Pass a number of statement parameters only known at runtime.
Definition: params.hxx:45
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:193
Generate parameter placeholders for use in an SQL statement.
Definition: params.hxx:123
static constexpr unsigned int max_params
Maximum number of parameters we support.
Definition: params.hxx:126
zview view() const noexcept
Read an ephemeral version of the current placeholder text.
Definition: params.hxx:139
void next()
Move on to the next parameter.
Definition: params.hxx:150
COUNTER count() const noexcept
Return the current placeholder number. The initial placeholder is 1.
Definition: params.hxx:176
std::string get() const
Read the current placeholder text, as a std::string.
Definition: params.hxx:147
placeholders()
Definition: params.hxx:129
Build a parameter list for a parameterised or prepared statement.
Definition: params.hxx:214
auto size() const noexcept
Get the number of parameters currently in this params.
Definition: params.hxx:236
void append(TYPE const &value)
Definition: params.hxx:312
void append_multi(RANGE const &range)
Append all elements of range as parameters.
Definition: params.hxx:331
auto ssize() const
Get the number of parameters (signed).
Definition: params.hxx:245
constexpr params(Args &&...args)
Definition: params.hxx:220
void append(pqxx::internal::dynamic_params< IT, ACCESSOR > const &value)
Append all parameters from value.
Definition: params.hxx:301
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.
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:40