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 >:
+ Collaboration 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
 
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 Function Documentation

◆ 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.


The documentation for this class was generated from the following files: