Subject Re: [firebird-support] Get the value of generated primary key after an insert
Author Adriano
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 ?

>When you do GEN_ID(GEN_PRATICHE_IDPRATICA, 1) you increment the generator.
why if i use a SELECT i increment the generator ?

>If you just want to retrieve the generator value use
>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).

>Generator are transaction independent so it is guaranteed that the
>returned value is unique (of course, unless you reset it, but that is
>off topic)
But the faq above do not said the opposite ?

Sorry but i'm really a novice.

Thanks
Adriano


[Non-text portions of this message have been removed]