Re: Basic questions about PQprepare() - Mailing list pgsql-general

From Tom Lane
Subject Re: Basic questions about PQprepare()
Date
Msg-id 11738.1138462965@sss.pgh.pa.us
Whole thread Raw
In response to Basic questions about PQprepare()  (Alexander Farber <alexander.farber@gmail.com>)
Responses Re: Basic questions about PQprepare()
List pgsql-general
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

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: My very first PL/pgSQL procedure...
Next
From: Tom Lane
Date:
Subject: Re: creating users per database