On 2009-08-12, Jim Michaels <jmichae3@yahoo.com> wrote:
> --0-1559521671-1250064688=:25681
> Content-Type: text/plain; charset=us-ascii
>
> I am struggling to learn libpq.
>
> for some reason, I could not get an INSERT to produce an Oid. actually, what I am looking for, is to get the ID of
thelast record inserted or to verify that I inserted a record successfully. I think you use PQresultStatus() for
that.(?)
>
> Isn't PQoidValue() for getting the last INSERT id? or am I misunderstanding it?
since 8.0 (iirc) you must specify "WITH OIDS" when you create the
table or you won't get them, you can instead use "RETURNING
someprimarykey" at the end of the insert query (for apropriate
values of someprimarykey) and get a different sort of handle
on the new row
> Oid oid = PQoidValue(pgr);
> if (0 == oid) {
> printf("ERROR: INSERT operation failed!\n");
You should be printing the result from PQlastError() here too.