RefLib

Reference library for AI

Back

postgresql_16:5.1.14.3 Event Support Functions

PostgreSQL 16 > Client Interfaces > libpq — C Library > Event System > Event Support Functions

PQregisterEventProc

Registers an event callback procedure with libpq. int PQregisterEventProc(PGconn *conn, PGEventProc proc, const char *name, void *passThrough);

An event procedure must be registered once on each PGconn you want to receive events about. There is no limit, other than memory, on the number of event procedures that can be registered with a connection. The function returns a non-zero value if it succeeds and zero if it fails.

The proc argument will be called when a libpq event is fired. Its memory address is also used to lookup instanceData. The name argument is used to refer to the event procedure in error messages. This value cannot be NULL or a zero-length string. The name string is copied into the PGconn, so what is passed need not be long-lived. The passThrough pointer is passed to the proc whenever an event occurs. This argument can be NULL.

PQsetInstanceData

Sets the connection conn's instanceData for procedure proc to data. This returns non-zero for success and zero for failure. (Failure is only possible if proc has not been properly registered in conn.) int PQsetInstanceData(PGconn *conn, PGEventProc proc, void *data);

PQinstanceData

Returns the connection conn's instanceData associated with procedure proc, or NULL if there is none. void *PQinstanceData(const PGconn *conn, PGEventProc proc);

PQresultSetInstanceData

Sets the result's instanceData for proc to data. This returns non-zero for success and zero for failure. (Failure is only possible if proc has not been properly registered in the result.) int PQresultSetInstanceData(PGresult *res, PGEventProc proc, void *data);

Beware that any storage represented by data will not be accounted for by (see libpq-PQresultMemorySize), unless it is allocated using (see libpq-PQresultAlloc). (Doing so is recommendable because it eliminates the need to free such storage explicitly when the result is destroyed.)

PQresultInstanceData

Returns the result's instanceData associated with proc, or NULL if there is none. void *PQresultInstanceData(const PGresult *res, PGEventProc proc);

Back