I want to send binary data in an asynchronous way to PostgreSQL via libpg's method
int PQsendQueryPrepared(PGconn *conn,
const char *stmtName,
int nParams,
const char * const *paramValues,
const int *paramLengths,
const int *paramFormats,
int resultFormat);
However, I was not able to find any information about the memory management of passed parameters.
I run this command, and the code continues in a non-blocking manner. When can I free (or rewrite) paramValues
data? Do I need to wait until PQgetResult
returns NULL
or is data internally copied by libpg?
PQsendQueryPrepared()
callsPQsendQueryGuts()
which in turn serializesparamValues
withpqPutnchar()
topqPutMsgBytes()
tomemcpy()
. To me it looks like you are free to do what you want with arguments once the function returns.While
PQsendQueryPrepared()
starts the transfer it may not be done till you callPQgetResult()
which does an implicit flush.