Subject | Re: [firebird-support] Get the value of generated primary key after |
---|---|
Author | Radu Sky |
Post date | 2006-05-20T22:26:56Z |
Radu Sky wrote:
generator.Somebody else already got it, maybe it wasn't you.
elsewhere and put the variable value that you used to store it into the
INSERT statement.
other users could also increment it.
> Adriano wrote:GEN_ID(Generator_name, 0) retrieve the present value of the
>> Radu,
>> sorry i'm a bit confused.
>> I read on FB FAQ that:
>>
>> Firebird doesn't currently return values from insert statements and, in
>> multi-user, it isn't safe to query the generator afterwards
>> (GEN_ID(Generator_name, 0) because you have no way to know whether the
>> current "latest" value was yours or someone else's. The trick is to get the
>> generator value into your application as a variable *before* you post your
>> insert. This way, you make it available not just for your insert but for any
>> dependent rows you need to create for it inside the same transaction.
>>
>> So can you explain a bit more about that ?
>>
generator.Somebody else already got it, maybe it wasn't you.
>>> When you do GEN_ID(GEN_PRATICHE_IDPRATICA, 1) you increment the generator.Yes
>> why if i use a SELECT i increment the generator ?
>>> If you just want to retrieve the generator value useRemove the autoincrement trigger if you need the generator value
>>> GEN_ID(GEN_PRATICHE_IDPRATICA, 0)
>> But if i put BEFORE of the insert as said on faq and then use a INSERT query
>> the value isn't good (i use autoincrement trigger for master key).
elsewhere and put the variable value that you used to store it into the
INSERT statement.
>>> Generator are transaction independent so it is guaranteed that theNo, when you will retrieve GEN_ID(Generator_name, 0) after insert, some
>>> returned value is unique (of course, unless you reset it, but that is
>>> off topic)
>> But the faq above do not said the opposite ?
other users could also increment it.
>> Sorry but i'm really a novice.
>>
>> Thanks
>> Adriano