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/concat.hxx" 25 #include "pqxx/internal/encoding_group.hxx" 26 #include "pqxx/internal/stream_iterator.hxx" 27 #include "pqxx/separated_list.hxx" 28 #include "pqxx/transaction_base.hxx" 29 #include "pqxx/transaction_focus.hxx" 73 std::pair<std::unique_ptr<char, std::function<void(char *)>>, std::size_t>;
87 #include "pqxx/internal/ignore-deprecated-pre.hxx" 89 #include "pqxx/internal/ignore-deprecated-post.hxx" 122 std::string_view columns =
""sv);
129 std::initializer_list<std::string_view> columns = {});
135 PQXX_DEPRECATED(
"Use query() factory instead.")
141 PQXX_DEPRECATED("Use table() or raw_table() factory instead.")
147 template<typename Iter>
148 PQXX_DEPRECATED("Use table() or raw_table() factory instead.")
150 transaction_base &, from_table_t,
std::string_view table,
151 Iter columns_begin, Iter columns_end);
156 template<typename Columns>
157 PQXX_DEPRECATED("Use table() or raw_table() factory instead.")
159 transaction_base &tx, from_table_t,
std::string_view table,
160 Columns const &columns);
162 #include "pqxx/internal/ignore-deprecated-pre.hxx" 163 PQXX_DEPRECATED(
"Use the from_table_t overload instead.")
168 #include "pqxx/internal/ignore-deprecated-post.hxx" 171 template<
typename Columns>
172 PQXX_DEPRECATED(
"Use the from_table_t overload instead.")
174 transaction_base &tx,
std::string_view table, Columns const &columns) :
179 template<
typename Iter>
180 PQXX_DEPRECATED(
"Use the from_table_t overload instead.")
188 [[nodiscard]]
operator bool() const noexcept {
return not m_finished; }
190 [[nodiscard]]
bool operator!() const noexcept {
return m_finished; }
209 template<
typename Tuple>
stream_from &operator>>(Tuple &);
212 template<
typename... Vs>
213 stream_from &operator>>(std::variant<Vs...> &) =
delete;
220 template<
typename... TYPE> [[nodiscard]]
auto iter()
222 return pqxx::internal::stream_input_iteration<TYPE...>{*
this};
242 std::vector<zview>
const *read_row();
261 template<
typename Tuple, std::size_t... indexes>
262 void extract_fields(Tuple &t, std::index_sequence<indexes...>)
const 264 (extract_value<Tuple, indexes>(t), ...);
267 pqxx::internal::glyph_scanner_func *m_glyph_scanner;
273 std::vector<zview> m_fields;
275 bool m_finished =
false;
279 template<
typename Tuple, std::
size_t index>
280 void extract_value(Tuple &)
const;
287 template<
typename Columns>
290 Columns
const &columns) :
292 tx,
from_table, table_name, std::begin(columns), std::end(columns)}
296 template<
typename Iter>
310 constexpr
auto tup_size{std::tuple_size_v<Tuple>};
311 m_fields.reserve(tup_size);
316 if (std::size(m_fields) != tup_size)
318 "Tried to extract ", tup_size,
" field(s) from a stream of ",
319 std::size(m_fields),
".")};
321 extract_fields(t, std::make_index_sequence<tup_size>{});
326 template<
typename Tuple, std::
size_t index>
327 inline void stream_from::extract_value(Tuple &t)
const 331 assert(index < std::size(m_fields));
332 if constexpr (nullity::always_null)
334 if (m_fields[index].data() !=
nullptr)
337 else if (m_fields[index].data() ==
nullptr)
339 if constexpr (nullity::has_null)
340 std::get<index>(t) = nullity::null();
347 std::get<index>(t) = from_string<field_type>(m_fields[index]);
352 #include "pqxx/internal/compiler-internal-post.hxx" Value conversion failed, e.g. when converting "Hello" to int.
Definition: except.hxx:178
bool operator!() const noexcept
Has this stream produced all the data it is going to produce?
Definition: stream_from.hxx:190
std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition: util.hxx:147
std::pair< std::unique_ptr< char, std::function< void(char *)> >, std::size_t > raw_line
Definition: stream_from.hxx:73
auto iter()
Iterate over this stream. Supports range-based "for" loops.
Definition: stream_from.hxx:220
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
Use std::string_view Iter columns_begin
Definition: stream_from.hxx:150
Marker for stream_from constructors: "stream from table.".
Definition: types.hxx:57
Use std::string_view Iter Iter columns_end
Definition: stream_from.hxx:150
void throw_null_conversion(std::string const &type)
Definition: strconv.cxx:242
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:42
Traits describing a type's "null value," if any.
Definition: strconv.hxx:86
Base class for things that monopolise a transaction's attention.
Definition: transaction_focus.hxx:27
Stream data from the database.
Definition: stream_from.hxx:69
Use the from_table_t overload instead stream_from(transaction_base &tx, std::string_view table)
Definition: stream_from.hxx:165
constexpr from_table_t from_table
Pass this to a stream_from constructor to stream table contents.
Definition: stream_from.hxx:37
Marker for stream_from constructors: "stream from query.".
Definition: types.hxx:63
constexpr from_query_t from_query
Pass this to a stream_from constructor to stream query results.
Definition: stream_from.hxx:41
Interface definition (and common code) for "transaction" classes.
Definition: transaction_base.hxx:74
std::initializer_list< std::string_view > table_path
Representation of a PostgreSQL table path.
Definition: connection.hxx:120
stream_from & operator>>(Tuple &)
Read one row into a tuple.
Definition: stream_from.hxx:306
static stream_from query(transaction_base &tx, std::string_view q)
Factory: Execute query, and stream the results.
Definition: stream_from.hxx:85
Use std::string_view table
Definition: stream_from.hxx:142
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:164