Subject | Re: Last insert id ? |
---|---|
Author | Svein Erling Tysvær |
Post date | 2006-03-10T23:21:46Z |
Concurrency is the reason generators are outside transaction control.
Here's my 'plain English' translation of a few gen_id calls:
'select gen_id(generator_name, 1) from rdb$database;'
Get me one number that I can use like I please.
'select gen_id(generator_name, 0) from rdb$database;'
Get me the last given generator value. I promise I won't use it for
inserting anything, I'm just curious about the current state.
'select gen_id(generator_name, 10) from rdb$database;'
Get me one number that I can use like I please, and I want to be able
to use the next 9 numbers as I please as well.
(this latter one can also be used if you e.g. have 10 branches and
want unique numbers throughout the organisation. By having different
starting points, you could make it so that every number ending on 1
came from one particular branch, 2 for another etc.)
It is up to your programs to ascertain that you do not break the above
rules. And never expect two subsequent calls to a generator to contain
two consecutive numbers - as you said, another process may do
something in between.
HTH,
Set
Here's my 'plain English' translation of a few gen_id calls:
'select gen_id(generator_name, 1) from rdb$database;'
Get me one number that I can use like I please.
'select gen_id(generator_name, 0) from rdb$database;'
Get me the last given generator value. I promise I won't use it for
inserting anything, I'm just curious about the current state.
'select gen_id(generator_name, 10) from rdb$database;'
Get me one number that I can use like I please, and I want to be able
to use the next 9 numbers as I please as well.
(this latter one can also be used if you e.g. have 10 branches and
want unique numbers throughout the organisation. By having different
starting points, you could make it so that every number ending on 1
came from one particular branch, 2 for another etc.)
It is up to your programs to ascertain that you do not break the above
rules. And never expect two subsequent calls to a generator to contain
two consecutive numbers - as you said, another process may do
something in between.
HTH,
Set
--- In firebird-support@yahoogroups.com, "Velja Radenkovic" wrote:
> Thank you. What about concurrency? For example other process adds
> new item while first is between fetching next incremented field and
> adding an item?
>
> Velja
>
> On 3/10/06, Uwe Grauer wrote:
> >
> > No there isn't. Not in 1.5.x.
> > Get the id before you insert your record. with
> > something like 'select gen_id(generator_name, 1) from
> > rdb$database;'
> >
> > Uwe