Subject Re: [firebird-support] Re: Maintaining proper generator values
Author Doug Chamberlin
At 11/11/2003 03:01 PM (Tuesday), Alexander V.Nevsky wrote:
> Doug, you surprize me. Generators are multy-users safe namely
>because they are outside transaction control. Look (your approach)
>
>App 1 starts
>App 1 re-set generators - OK, it is lonely
>App 1 makes insert and move generator but don't commit yet
>App 2 starts
>App 2 select max which is less than generator value because insert
>is'nt commited
>App 2 set generator backwards
>
>next insert will fail. If you don't touch generators and let them live
>their life outside of transactions, it can fail on corrupted database
>only.

The problem here is that you have misrepresented my approach. I would NEVER
reset a generator to less than it was already set to. So your final step
above, which created the problem in your scenario, would never be done.

What I do is check if the current generator value is less than the highest
value already used. If so it is a guaranteed problem, so resetting it
upward so it is above the existing values in the database is always the
right thing to do.