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"
21 #include "pqxx/except.hxx"
22 #include "pqxx/internal/stream_iterator.hxx"
23 #include "pqxx/separated_list.hxx"
24 #include "pqxx/transaction_base.hxx"
34 template<
typename Columns>
37 template<
typename Iter>
44 [[nodiscard]]
operator bool() const noexcept {
return not m_finished; }
45 [[nodiscard]]
bool operator!() const noexcept {
return m_finished; }
56 bool get_raw_line(std::string &);
57 template<
typename Tuple>
stream_from &operator>>(Tuple &);
60 template<
typename... Vs>
61 stream_from &operator>>(std::variant<Vs...> &) =
delete;
68 template<
typename... TYPE>[[nodiscard]]
auto iter()
70 return pqxx::internal::stream_input_iteration<TYPE...>{*
this};
74 internal::encoding_group m_copy_encoding =
75 internal::encoding_group::MONOBYTE;
76 std::string m_current_line;
77 bool m_finished =
false;
78 bool m_retry_line =
false;
83 std::string
const &columns);
88 std::string
const &, std::string::size_type &, std::string &)
const;
92 std::string
const &line, T &t, std::string::size_type &here,
93 std::string &workspace)
const;
95 template<
typename Tuple, std::size_t... I>
97 const std::string &line, Tuple &t, std::string &workspace,
98 std::index_sequence<I...>)
100 std::string::size_type here{};
101 (extract_value(line, std::get<I>(t), here, workspace), ...);
103 here < line.size() and
104 not(here == line.size() - 1 and line[here] ==
'\n'))
105 throw usage_error{
"Not all fields extracted from stream_from line"};
110 template<
typename Columns>
112 transaction_base &tb, std::string_view table_name, Columns
const &columns) :
113 stream_from{tb, table_name, std::begin(columns), std::end(columns)}
117 template<
typename Iter>
121 namedclass{
"stream_from", table_name},
124 set_up(tb, table_name,
separated_list(
",", columns_begin, columns_end));
135 std::string workspace;
138 constexpr
auto tsize = std::tuple_size_v<Tuple>;
139 using indexes = std::make_index_sequence<tsize>;
140 do_extract(m_current_line, t, workspace, indexes{});
141 m_retry_line =
false;
154 void stream_from::extract_value(
155 std::string
const &line, T &t, std::string::size_type &here,
156 std::string &workspace)
const
158 if (extract_field(line, here, workspace))
159 t = from_string<T>(workspace);
167 void PQXX_LIBEXPORT stream_from::extract_value<std::nullptr_t>(
168 std::string
const &line, std::nullptr_t &, std::string::size_type &here,
169 std::string &workspace)
const;
172 #include "pqxx/internal/compiler-internal-post.hxx"