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/internal/transaction_focus.hxx"
28 #include "pqxx/separated_list.hxx"
29 #include "pqxx/transaction_base.hxx"
65 std::pair<std::unique_ptr<char, std::function<void(
char *)>>, std::size_t>;
89 template<
typename Iter>
92 Iter columns_begin, Iter columns_end);
98 template<
typename Columns>
101 Columns
const &columns);
109 template<
typename Columns>
116 template<
typename Iter>
123 [[nodiscard]] operator
bool() const noexcept {
return not m_finished; }
124 [[nodiscard]]
bool operator!() const noexcept {
return m_finished; }
143 template<
typename Tuple>
stream_from &operator>>(Tuple &);
146 template<
typename... Vs>
154 template<
typename... TYPE> [[nodiscard]]
auto iter()
156 return pqxx::internal::stream_input_iteration<TYPE...>{*
this};
176 std::vector<zview>
const *read_row();
180 raw_line get_raw_line();
187 template<
typename Tuple, std::size_t... indexes>
188 void extract_fields(Tuple &t, std::index_sequence<indexes...>)
const
190 (extract_value<Tuple, indexes>(t), ...);
193 pqxx::internal::glyph_scanner_func *m_glyph_scanner;
199 std::vector<zview> m_fields;
201 bool m_finished =
false;
205 template<
typename Tuple, std::
size_t index>
206 void extract_value(Tuple &)
const;
213 template<
typename Columns>
216 Columns
const &columns) :
218 tb,
from_table, table_name, std::begin(columns), std::end(columns)}
222 template<
typename Iter>
225 Iter columns_begin, Iter columns_end) :
236 constexpr
auto tup_size{std::tuple_size_v<Tuple>};
237 m_fields.reserve(tup_size);
242 if (std::size(m_fields) != tup_size)
244 "Tried to extract ", tup_size,
" field(s) from a stream of ",
245 std::size(m_fields),
".")};
247 extract_fields(t, std::make_index_sequence<tup_size>{});
252 template<
typename Tuple, std::
size_t index>
253 inline void stream_from::extract_value(Tuple &t)
const
257 assert(index < std::size(m_fields));
258 if constexpr (nullity::always_null)
260 if (m_fields[index].data() !=
nullptr)
263 else if (m_fields[index].data() ==
nullptr)
265 if constexpr (nullity::has_null)
266 std::get<index>(t) = nullity::null();
273 std::get<index>(t) = from_string<field_type>(m_fields[index]);
278 #include "pqxx/internal/compiler-internal-post.hxx"
std::pair< std::unique_ptr< char, std::function< void(char *)> >, std::size_t > raw_line
Definition: stream_from.hxx:65
Marker for stream_from constructors: "stream from table.".
Definition: types.hxx:56
Traits describing a type's "null value," if any.
Definition: strconv.hxx:87
Value conversion failed, e.g. when converting "Hello" to int.
Definition: except.hxx:179
stream_from(transaction_base &, std::string_view table, Iter columns_begin, Iter columns_end)
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:26
~stream_from() noexcept
Definition: stream_from.cxx:67
stream_from(transaction_base &tx, std::string_view table, Columns const &columns)
Definition: stream_from.hxx:110
bool operator!() const noexcept
Definition: stream_from.hxx:124
encoding_group enc_group(int libpq_enc_id)
Definition: encodings.cxx:571
void throw_null_conversion(std::string const &type)
Definition: strconv.cxx:242
raw_line get_raw_line()
Read a raw line of text from the COPY command.
Definition: stream_from.cxx:80
int encoding_id() const
Get the connection's encoding, as a PostgreSQL-defined code.
Definition: connection.cxx:1071
void complete()
Finish this stream. Call this before continuing to use the connection.
Definition: stream_from.cxx:115
std::vector< zview > const * read_row()
Read a row. Return fields as views, valid until you read the next row.
Definition: stream_from.cxx:285
stream_from & operator>>(Tuple &)
Read one row into a tuple.
Definition: stream_from.hxx:232
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:165
stream_from(transaction_base &tx, std::string_view table)
Definition: stream_from.hxx:104
PQXX_PURE glyph_scanner_func * get_glyph_scanner(encoding_group enc)
Definition: encodings.cxx:670
Exception class for lost or failed backend connection.
Definition: except.hxx:68
Interface definition (and common code) for "transaction" classes.
Definition: transaction_base.hxx:72
connection & conn() const
The connection in which this transaction lives.
Definition: transaction_base.hxx:451
auto iter()
Iterate over this stream. Supports range-based "for" loops.
Definition: stream_from.hxx:154
constexpr from_query_t from_query
Pass this to a stream_from constructor to stream query results.
Definition: stream_from.hxx:37
result exec0(zview query, std::string_view desc=std::string_view{})
Execute query, which should zero rows of data.
Definition: transaction_base.hxx:221
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
constexpr from_table_t from_table
Pass this to a stream_from constructor to stream table contents.
Definition: stream_from.hxx:35
Marker for stream_from constructors: "stream from query.".
Definition: types.hxx:60
stream_from(transaction_base &, from_query_t, std::string_view query)
Execute query, and stream over the results.
Definition: stream_from.cxx:36
Stream data from the database.
Definition: stream_from.hxx:62
stream_from & operator>>(std::variant< Vs... > &)=delete
Doing this with a std::variant is going to be horrifically borked.
void ignore_unused(T &&...)
Suppress compiler warning about an unused item.
Definition: util.hxx:67
std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition: util.hxx:143