Subject | Re: [IBO] How to get the record id that was just stored with a query |
---|---|
Author | Antti Kurenniemi |
Post date | 2005-06-30T19:23:29Z |
[snip]
Is it maybe because my Transaction component is set to autocommit, and so in
my code I only call Query.Execute? The record is inserted and everything
otherwise seems to work ok.
Antti Kurenniemi
>>Is that a good approach?Thanks, I think I'm getting it now (finally ;-).
>
> It's not a "bad" approach, given that you are separating your insert
> operation from any dataset. It's not a tidy approach otherwise. By the
> way, avoid AsInt64. Use AsInteger.
>
>>What I'm still not clear with is, is the generated
>>id somehow "reserved" when Gen_ID is called, because (especially when
>>working over a slow network connection) there still is a small time gap
>>between that and Execute, and if this was, say, and app that generates a
>>lot
>>of inserts automatically very quickly, there could still be a possibility
>>of
>>two clients getting same id's, no?
>
> No chance. A generator returns a unique number each time GEN_ID() is
> invoked on the server and it happens outside all transaction contexts
> except its own. (It's the only operation on the server that behaves this
> way.)
>>I tried using GeneratorLinks, and it works otherwise except that IBeforePost for that query doesn't fire, what could be the reason for that?
>>couldn't
>>figure out how to read the id back. Anyone up for a wee little piece of
>>sample code? ;-)
>
> Sample code not needed! All you have to do is read it in any Delphi event
> *after* IBO's AfterInsert has fired. BeforePost is a good place. Pull
> FieldByName('id').AsInteger into a variable or, better still, set a
> property.
Is it maybe because my Transaction component is set to autocommit, and so in
my code I only call Query.Execute? The record is inserted and everything
otherwise seems to work ok.
Antti Kurenniemi