libpqxx
The C++ client library for PostgreSQL
Loading...
Searching...
No Matches
pqxx::internal::stream_query< TYPE > Class Template Reference

Stream query results from the database. Used by transaction_base::stream. More...

Inheritance diagram for pqxx::internal::stream_query< TYPE >:

Public Types

using line_handle = std::unique_ptr<char, void (*)(void const *)>

Public Member Functions

 stream_query (transaction_base &tx, std::string_view query)
 Execute query on tx, stream results.
 stream_query (transaction_base &tx, std::string_view query, params const &)
 Execute query on tx, stream results.
 stream_query (stream_query &&)=delete
stream_queryoperator= (stream_query &&)=delete
 ~stream_query () noexcept
bool done () const &noexcept
 Has this stream reached the end of its data?
auto begin () &
 Begin iterator. Only for use by "range for.".
auto end () const &
 End iterator. Only for use by "range for.".
std::tuple< TYPE... > parse_line (zview line) &
 Parse and convert the latest line of data we received.
std::pair< line_handle, std::size_t > read_line () &
 Read a COPY line from the server.

Detailed Description

template<typename... TYPE>
class pqxx::internal::stream_query< TYPE >

Stream query results from the database. Used by transaction_base::stream.

For larger data sets, retrieving data this way is likely to be faster than executing a query and then iterating and converting the rows' fields. You will also be able to start processing before all of the data has come in. (For smaller result sets though, a stream is likely to be a bit slower.)

A stream_query stream is strongly typed. You specify the columns' types while instantiating the stream_query template.

Not all kinds of query will work in a stream. But straightforward SELECT and UPDATE ... RETURNING queries should work. The class uses PostgreSQL's COPY command, so see the documentation for that command to get the full details.

There are other downsides. If the stream encounters an error, it may leave the entire connection in an unusable state, so you'll have to give the whole thing up. Finally, opening a stream puts the connection in a special state, so you won't be able to do many other things with the connection or the transaction while the stream is open.

Usually you'll want the stream convenience wrapper in transaction_base, so you don't need to deal with this class directly.

Warning
While a stream is active, you cannot execute queries, open a pipeline, etc. on the same transaction. A transaction can have at most one object of a type derived from pqxx::transaction_focus active on it at a time.

Member Typedef Documentation

◆ line_handle

template<typename... TYPE>
using pqxx::internal::stream_query< TYPE >::line_handle = std::unique_ptr<char, void (*)(void const *)>

Constructor & Destructor Documentation

◆ stream_query() [1/3]

template<typename... TYPE>
pqxx::internal::stream_query< TYPE >::stream_query ( transaction_base & tx,
std::string_view query )
inline

Execute query on tx, stream results.

◆ stream_query() [2/3]

template<typename... TYPE>
pqxx::internal::stream_query< TYPE >::stream_query ( transaction_base & tx,
std::string_view query,
params const &  )
inline

Execute query on tx, stream results.

◆ stream_query() [3/3]

template<typename... TYPE>
pqxx::internal::stream_query< TYPE >::stream_query ( stream_query< TYPE > && )
delete

◆ ~stream_query()

template<typename... TYPE>
pqxx::internal::stream_query< TYPE >::~stream_query ( )
inlinenoexcept

Member Function Documentation

◆ begin()

template<typename... TYPE>
auto pqxx::internal::stream_query< TYPE >::begin ( ) &
inline

Begin iterator. Only for use by "range for.".

◆ done()

template<typename... TYPE>
bool pqxx::internal::stream_query< TYPE >::done ( ) const &
inlinenoexcept

Has this stream reached the end of its data?

◆ end()

template<typename... TYPE>
auto pqxx::internal::stream_query< TYPE >::end ( ) const &
inline

End iterator. Only for use by "range for.".

The end iterator is a different type than the regular iterator. It simplifies the comparisons: we know at compile time that we're comparing to the end pointer.

◆ operator=()

template<typename... TYPE>
stream_query & pqxx::internal::stream_query< TYPE >::operator= ( stream_query< TYPE > && )
delete

◆ parse_line()

template<typename... TYPE>
std::tuple< TYPE... > pqxx::internal::stream_query< TYPE >::parse_line ( zview line) &
inline

Parse and convert the latest line of data we received.

◆ read_line()

template<typename... TYPE>
std::pair< typename stream_query< TYPE... >::line_handle, std::size_t > pqxx::internal::stream_query< TYPE >::read_line ( ) &
inline

Read a COPY line from the server.


The documentation for this class was generated from the following files:
  • /builddir/build/BUILD/libpqxx-7.10.5-build/libpqxx-7.10.5/redhat-linux-build/include/pqxx/internal/stream_query.hxx
  • /builddir/build/BUILD/libpqxx-7.10.5-build/libpqxx-7.10.5/redhat-linux-build/include/pqxx/internal/stream_query_impl.hxx