[Lazarus] TSQLQuery: Getting autoincremented ID value after insert (MySQL)
Marco van de Voort
marcov at stack.nl
Sat Nov 15 00:32:56 CET 2014
On Fri, Nov 14, 2014 at 03:11:30PM +0100, Michael Van Canneyt wrote:
>
> By the very nature of the problem: GetLastAutoIncValue simply cannot be implemented in general.
>
> In firebird, postgres,
(and Oracle afaik)
> these values are generated using a generator/sequence.
> You don't know the name of the generator, and even if you did, it is impossible
> to retrieve the value that was used to fill your particular record because the
> sequence/generator may have been updated several thousands of times by the time
> your second statement arrives.
IIRC the currval from a sequence is per session, so if you didn't insert
again in the same transaction that is ok too.
Moverover there is lastval to avoid knowing the sequence name
from http://www.postgresql.org/docs/8.4/static/functions-sequence.html
lastval
Return the value most recently returned by nextval in the current
session. This function is identical to currval, except that instead of
taking the sequence name as an argument it fetches the value of the last
sequence used by nextval in the current session. It is an error to call
lastval if nextval has not yet been called in the current session.
More information about the Lazarus
mailing list