Subject RE: [firebird-support] Re: Generators for auto-increment - with override
Author Alan McDonald
> Pierre wrote:
>
> >> GEN_VALUE = gen_id(GEN_TEST_ID,0);
> >> if (new.TEST_ID > GEN_VALUE) then
> >> GEN_VALUE = gen_id(GEN_TEST_ID,new.TEST_ID - GEN_VALUE);
>
> Alan McDonald wrote:
>
> > if you use this under heavy load you'll ruin your database
>
> I don't think so. The way to screw up generators is to try to set them
> backward. Since the amount added to the generator (new.TEST_ID -
> GEN_VALUE) is always positive, having two users run it at once shouldn't
> be a problem. If new.TEST_ID is less than GEN_VALUE, there's a chance
> that it will duplicate an existing key value, but that is the
> application's problem.
>
>
> Regards,
>
>
> Ann

between this line
> >> GEN_VALUE = gen_id(GEN_TEST_ID,0);
> >> if (new.TEST_ID > GEN_VALUE) then
and this line
> >> GEN_VALUE = gen_id(GEN_TEST_ID,new.TEST_ID - GEN_VALUE);

the generator counld be fired by someone else and thus GEN_VALUE would be
larger than expected at the third line
Alan