This comes as a patch update, but it's a pretty big thing: libpqxx 7.7.4 comes with new, more convenient ways to query data.
In many cases you can simply forget about the pqxx::result
class. Instead, use a transaction's "query" functions (query()
, query1()
, query01()
, query_n()
, query_value()
) to execute an SQL query and go straight to the result data, converted into the C++ types of your choice. Or use for_query()
to execute a query and on each row, invoke a callback you provide.
As a high-performance alternative, you can stream()
your query. This works much like query()
, except it starts iterating rows as soon as they come in (where query()
waits for the full result first) and the rows come faster. Initial startup is a bit slower than with query()
, but when you're expecting a lot of rows, it's likely to be faster and use less memory.
And then there's the classic "exec" functions (exec()
, exec0()
, exec1()
, exec_n()
). These return pqxx::result
objects, apart from exec1()
which returns a pqxx::row
for convenience. Use these only when you expect no data rows, or when you need the result's metadata, such as the number of rows affected by an UPDATE statement.
I'd be interested to hear about your experiences! Do you still need pqxx::result
at all in your application? Feel free to file a bug giving me some feedback.