PQsendQueryPrepared - send values and memory management

48 Views Asked by At

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?

1

There are 1 best solutions below

2
On BEST ANSWER

PQsendQueryPrepared() calls PQsendQueryGuts() which in turn serializes paramValues with pqPutnchar() to pqPutMsgBytes() to memcpy(). 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 call PQgetResult() which does an implicit flush.