13 #ifndef PQXX_H_STREAM_FROM 14 #define PQXX_H_STREAM_FROM 16 #include "pqxx/compiler-public.hxx" 17 #include "pqxx/internal/compiler-internal-pre.hxx" 23 #include "pqxx/except.hxx" 24 #include "pqxx/internal/encoding_group.hxx" 25 #include "pqxx/internal/stream_iterator.hxx" 26 #include "pqxx/internal/transaction_focus.hxx" 27 #include "pqxx/separated_list.hxx" 28 #include "pqxx/transaction_base.hxx" 64 std::pair<std::unique_ptr<char, std::function<void(char *)>>, std::size_t>;
88 template<
typename Iter>
91 Iter columns_begin, Iter columns_end);
97 template<
typename Columns>
100 Columns
const &columns);
108 template<
typename Columns>
115 template<
typename Iter>
117 transaction_base &, std::string_view table, Iter columns_begin,
120 ~stream_from() noexcept;
122 [[nodiscard]] operator
bool() const noexcept {
return not m_finished; }
123 [[nodiscard]]
bool operator!() const noexcept {
return m_finished; }
142 template<
typename Tuple>
stream_from &operator>>(Tuple &);
145 template<
typename... Vs>
146 stream_from &operator>>(std::variant<Vs...> &) =
delete;
153 template<
typename... TYPE>[[nodiscard]]
auto iter()
155 return pqxx::internal::stream_input_iteration<TYPE...>{*
this};
175 std::vector<zview>
const *read_row();
179 raw_line get_raw_line();
186 template<
typename Tuple, std::size_t... indexes>
187 void extract_fields(Tuple &t, std::index_sequence<indexes...>)
const 189 (extract_value<Tuple, indexes>(t), ...);
192 static std::string compose_query(
193 transaction_base
const &tx, std::string_view table,
194 std::string
const &columns);
196 pqxx::internal::glyph_scanner_func *m_glyph_scanner;
202 std::vector<zview> m_fields;
204 bool m_finished =
false;
208 template<
typename Tuple, std::
size_t index>
209 void extract_value(Tuple &)
const;
216 template<
typename Columns>
219 Columns
const &columns) :
221 tb,
from_table, table_name, std::begin(columns), std::end(columns)}
225 template<
typename Iter>
228 Iter columns_begin, Iter columns_end) :
239 constexpr
auto tup_size{std::tuple_size_v<Tuple>};
240 m_fields.reserve(tup_size);
245 if (std::size(m_fields) != tup_size)
247 "Tried to extract " +
to_string(tup_size) +
248 " field(s) from a stream of " +
to_string(std::size(m_fields)) +
"."};
250 extract_fields(t, std::make_index_sequence<tup_size>{});
255 template<
typename Tuple, std::
size_t index>
256 inline void stream_from::extract_value(Tuple &t)
const 260 assert(index < std::size(m_fields));
261 if constexpr (nullity::always_null)
263 if (m_fields[index].data() !=
nullptr)
266 else if (m_fields[index].data() ==
nullptr)
268 if constexpr (nullity::has_null)
269 std::get<index>(t) = nullity::null();
276 std::get<index>(t) = from_string<field_type>(m_fields[index]);
281 #include "pqxx/internal/compiler-internal-post.hxx" Interface definition (and common code) for "transaction" classes.
Definition: transaction_base.hxx:67
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:164
Value conversion failed, e.g. when converting "Hello" to int.
Definition: except.hxx:178
std::string to_string(field const &value)
Convert a field to a string.
Definition: result.cxx:498
std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition: util.hxx:120
Traits describing a type's "null value," if any.
Definition: strconv.hxx:86
bool operator!() const noexcept
Definition: stream_from.hxx:123
stream_from(transaction_base &, from_query_t, std::string_view query)
Execute query, and stream over the results.
Definition: stream_from.cxx:56
Stream data from the database.
Definition: stream_from.hxx:60
auto iter()
Iterate over this stream. Supports range-based "for" loops.
Definition: stream_from.hxx:153
std::string separated_list(std::string_view sep, ITER begin, ITER end, ACCESS access)
Represent sequence of values as a string, joined by a given separator.
Definition: separated_list.hxx:40
void throw_null_conversion(std::string const &type)
Definition: strconv.cxx:243
Marker for stream_from constructors: "stream from query.".
Definition: types.hxx:59
stream_from & operator>>(Tuple &)
Read one row into a tuple.
Definition: stream_from.hxx:235
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
std::pair< std::unique_ptr< char, std::function< void(char *)> >, std::size_t > raw_line
Definition: stream_from.hxx:64
constexpr from_query_t from_query
Pass this to a stream_from constructor to stream query results.
Definition: stream_from.hxx:36
constexpr from_table_t from_table
Pass this to a stream_from constructor to stream table contents.
Definition: stream_from.hxx:34
Marker for stream_from constructors: "stream from table.".
Definition: types.hxx:55
stream_from(transaction_base &tx, std::string_view table)
Definition: stream_from.hxx:103
stream_from(transaction_base &tx, std::string_view table, Columns const &columns)
Definition: stream_from.hxx:109