Thread: Can connection pointer be obtained from PGresult?

Can connection pointer be obtained from PGresult?

From
reina_ga@hotmail.com (Tony Reina)
Date:
I inherited some C code that works as a series of libraries using
libpq. One of the libraries has an input to it of a PGresult pointer,
but not of a PGconnect pointer. Within the library, the code tries to
determine the host name of the connection by doing the following
trick:

 strcpy (host,PQhost(((PGresult*)*pgresult)->xconn));

This worked fine in the past (v. 7.0) despite being warned against in
the documentation since directly accessing the structures in PGresult
seems to be off limits (I suppose in case its structure changes with
PG version).

I'm trying to think of a workaround that would do things right without
having to explicitly pass PGconn pointer into the code. Perhaps this
can't be done, but I thought I'd throw out the question and wait for
the verbal abuse.

-Tony