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" 19 #include "pqxx/separated_list.hxx" 20 #include "pqxx/transaction_base.hxx" 30 template<
typename Columns>
33 template<
typename Iter>
40 [[nodiscard]]
operator bool() const noexcept {
return not m_finished; }
41 [[nodiscard]]
bool operator!() const noexcept {
return m_finished; }
52 bool get_raw_line(std::string &);
53 template<
typename Tuple>
stream_from &operator>>(Tuple &);
56 internal::encoding_group m_copy_encoding =
57 internal::encoding_group::MONOBYTE;
58 std::string m_current_line;
59 bool m_finished =
false;
60 bool m_retry_line =
false;
65 std::string
const &columns);
70 std::string
const &, std::string::size_type &, std::string &)
const;
72 template<
typename Tuple, std::
size_t I>
74 std::string
const &, Tuple &, std::string::size_type, std::string &)
const 75 ->
typename std::enable_if<(std::tuple_size<Tuple>::value > I)>::type;
76 template<
typename Tuple, std::
size_t I>
78 std::string
const &, Tuple &, std::string::size_type, std::string &)
const 79 ->
typename std::enable_if<(std::tuple_size<Tuple>::value <= I)>::type;
83 std::string
const &line, T &t, std::string::size_type &here,
84 std::string &workspace)
const;
88 template<
typename Columns>
91 stream_from{tb, table_name, std::begin(columns), std::end(columns)}
95 template<
typename Iter>
102 set_up(tb, table_name,
separated_list(
",", columns_begin, columns_end));
110 std::string workspace;
113 tokenize_ith<Tuple, 0>(m_current_line, t, 0, workspace);
114 m_retry_line =
false;
126 template<
typename Tuple, std::
size_t I>
127 auto stream_from::tokenize_ith(
128 std::string
const &line, Tuple &t, std::string::size_type here,
129 std::string &workspace)
const ->
130 typename std::enable_if<(std::tuple_size<Tuple>::value > I)>::type
132 if (here >= line.size())
133 throw usage_error{
"Too few fields to extract from stream_from line."};
135 extract_value(line, std::get<I>(t), here, workspace);
136 tokenize_ith<Tuple, I + 1>(line, t, here, workspace);
140 template<
typename Tuple, std::
size_t I>
141 auto stream_from::tokenize_ith(
142 std::string
const &line, Tuple & , std::string::size_type here,
145 typename std::enable_if<(std::tuple_size<Tuple>::value <= I)>::type
149 here < line.size() and not(here == line.size() - 1 and line[here] ==
'\n'))
150 throw usage_error{
"Not all fields extracted from stream_from line"};
155 void stream_from::extract_value(
156 std::string
const &line, T &t, std::string::size_type &here,
157 std::string &workspace)
const 159 if (extract_field(line, here, workspace))
160 t = from_string<T>(workspace);
168 void PQXX_LIBEXPORT stream_from::extract_value<std::nullptr_t>(
169 std::string
const &line, std::nullptr_t &, std::string::size_type &here,
170 std::string &workspace)
const;
173 #include "pqxx/internal/compiler-internal-post.hxx" transactionfocus()=delete
Efficiently pull data directly out of a table.
Definition: stream_from.hxx:26
bool get_raw_line(std::string &)
Definition: stream_from.cxx:80
bool operator!() const noexcept
Definition: stream_from.hxx:41
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
namedclass(std::string_view classname)
Definition: util.hxx:211
stream_from & operator>>(Tuple &)
Definition: stream_from.hxx:106
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
Interface definition (and common code) for "transaction" classes.
Definition: transaction_base.hxx:97
Traits describing a type's "null value," if any.
Definition: strconv.hxx:86
static TYPE null()
Return a null value.
void throw_null_conversion(std::string const &type)
Definition: strconv.cxx:241
Definition: transaction_base.hxx:42
stream_from(transaction_base &, std::string_view table_name)
Definition: stream_from.cxx:58
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:156