libpqxx
The C++ client library for PostgreSQL
 
Loading...
Searching...
No Matches
statement_parameters.hxx
1
13#ifndef PQXX_H_STATEMENT_PARAMETER
14#define PQXX_H_STATEMENT_PARAMETER
15
16#include <cstring>
17#include <iterator>
18#include <string>
19#include <vector>
20
21#include "pqxx/binarystring.hxx"
22#include "pqxx/strconv.hxx"
23#include "pqxx/util.hxx"
24
25
26namespace pqxx::internal
27{
28template<typename ITERATOR>
29constexpr inline auto const iterator_identity{
30 [](decltype(*std::declval<ITERATOR>()) x) { return x; }};
31
32
34template<typename IT, typename ACCESSOR = decltype(iterator_identity<IT>)>
36{
37public:
39 constexpr dynamic_params(IT begin, IT end) :
40 m_begin(begin), m_end(end), m_accessor(iterator_identity<IT>)
41 {}
42
44
48 constexpr dynamic_params(IT begin, IT end, ACCESSOR &acc) :
49 m_begin(begin), m_end(end), m_accessor(acc)
50 {}
51
53 template<typename C>
54 explicit constexpr dynamic_params(C &container) :
55 dynamic_params(std::begin(container), std::end(container))
56 {}
57
59
63 template<typename C>
64 explicit constexpr dynamic_params(C &container, ACCESSOR &acc) :
65 dynamic_params(std::begin(container), std::end(container), acc)
66 {}
67
68 constexpr IT begin() const noexcept { return m_begin; }
69 constexpr IT end() const noexcept { return m_end; }
70
71 constexpr auto access(decltype(*std::declval<IT>()) value) const
72 -> decltype(std::declval<ACCESSOR>()(value))
73 {
74 return m_accessor(value);
75 }
76
77private:
78 IT const m_begin, m_end;
79 ACCESSOR m_accessor = iterator_identity<IT>;
80};
81
82
84
94struct PQXX_LIBEXPORT c_params
95{
96 c_params() = default;
98 c_params(c_params const &) = delete;
99 c_params(c_params &&) = default;
100
102 void reserve(std::size_t n) &;
103
105 std::vector<char const *> values;
107 std::vector<int> lengths;
109 std::vector<format> formats;
110};
111} // namespace pqxx::internal
112#endif
constexpr dynamic_params(C &container)
Wrap a container.
Definition statement_parameters.hxx:54
constexpr dynamic_params(IT begin, IT end)
Wrap a sequence of pointers or iterators.
Definition statement_parameters.hxx:39
constexpr dynamic_params(C &container, ACCESSOR &acc)
Wrap a container.
Definition statement_parameters.hxx:64
constexpr dynamic_params(IT begin, IT end, ACCESSOR &acc)
Wrap a sequence of pointers or iterators.
Definition statement_parameters.hxx:48
Internal items for libpqxx' own use. Do not use these yourself.
Definition encodings.cxx:33
c_params(c_params const &)=delete
Copying these objects is pointless and expensive. Don't do it.
std::vector< int > lengths
As used by libpq: lengths of non-null arguments, in bytes.
Definition statement_parameters.hxx:107
std::vector< format > formats
As used by libpq: effectively boolean "is this a binary parameter?".
Definition statement_parameters.hxx:109
void reserve(std::size_t n) &
Pre-allocate storage for n parameters.
Definition params.cxx:18
std::vector< char const * > values
As used by libpq: pointers to parameter values.
Definition statement_parameters.hxx:105