I want to execute a SQL query with libpq in a non-blocking fashion. Thus I want to be notified when my query has finished executing.
As I understand this is supported by libpq if I use the asynchronous api.
With the PQsendQuery
function I can send the query to the backend and with the PQgetResult
function I can retrieve the result.
I call the PQsendQuery
function multiple times without waiting for
the previous one to finish.
Now I have the following questions:
- How can I associate the results that I am going to pull later with
PQgetResult
to the corresponding query? - Is there a method of using a callback instead of PQgetResult?
- Is there a way to run this in an event loop (e.g. libevent)?