Connection_lastRowId on postgresql
Paul J Stevens
paul at nfg.nl
Fri Apr 25 14:34:37 CEST 2008
Following up because my work-around fails for sqlite.
The work-around entails using the 'RETURNING id' clause for postgres, using
executeQuery for INSERTs on tables with auto_increment primary keys, and using
the returned ResultSet to retrieve the new id if Connection_lastRowId fails
(with postgres).
This does the job for postgres and mysql, but alas, sqlite fails.
test program attached, as always.
Any ideas?
Jan-Henrik Haukeland wrote:
> I'll see if we can come up with something better, that is, more
> general to be used in Connection_lastRowId() for postgres, since this
> method works fine for mysql and sqlite it should so for postgres as
> well. If you should come over anything for postgres also, please let
> me know as well.
>
>
> On 29. feb.. 2008, at 09.35, Paul J Stevens wrote:
>
>> Jan-Henrik Haukeland wrote:
>>> What command did you use in dbmail to get last insert row id in
>>> postgres?
>> Well, until now we were using a sequence and called "select
>> curval('sequence_identifier')" after each insert if a last inserted
>> row
>> id was required.
>>
>> But I've decided to switch to using the 'RETURNING id' instead to
>> avoid
>> the additional roundtrip for the extra query. I use executeQuery for
>> the
>> INSERTs involved, passing the connector and result pointer to my
>> facade
>> for lastRowId. That call then tries to retrieve the id from the
>> resultset if lastRowId returns 0 and the resultset is not null.
>> Appears
>> to work just fine.
>>
>> Of course 'RETURNING x' is a postgresql construct but I have a
>> framework
>> in place for dealing with backend specific dialect fragments.
>>
>>> On 28. feb.. 2008, at 21.55, Paul J Stevens wrote:
>>>
>>>> Jan-Henrik,
>>>>
>>>> This call always returns 0 on a postgresql connection. I assume this
>>>> is
>>>> because my tables are without OIDs. Is that intentional? I can work
>>>> around it. But perhaps a small note in the api docs would be in
>>>> order?
> --
> To unsubscribe:
> http://www.tildeslash.com/mailman/listinfo/libzdb-general
>
--
________________________________________________________________
Paul Stevens paul at nfg.nl
NET FACILITIES GROUP GPG/PGP: 1024D/11F8CD31
The Netherlands________________________________http://www.nfg.nl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testzdb.c
Type: text/x-csrc
Size: 2989 bytes
Desc: not available
Url : http://www.tildeslash.com/pipermail/libzdb-general/attachments/20080425/7184e274/attachment.bin
More information about the libzdb-general
mailing list