Alexander Farber <alexander.farber@gmail.com> writes:
> 1) If PQconnectdb fails, do I still need to PQfinish the returned pointer?
Yes, if you don't want to leak memory.
> 2) Similar, if PQprepare fails, do I still need to PQclear its result?
Yes, if you don't want to leak memory.
> 3) Do I have to PQclear(res) inbetween if I want to prepare another query?
They are not comparable actions --- you can do them in either order. In
practice though I don't see why you wouldn't PQclear the result of a
PREPARE as soon as you'd checked that it wasn't conveying an error.
> 4) How do I set the last PQprepare argument, the const Oid *paramTypes?
You'd need to look up the OIDs of the parameter types. In practice it's
usally a lot easier to write the queries so that the parameter types can
be inferred by the backend.
regards, tom lane