Subject Re: [ib-support] How can I set a generator value inside a procedure?
Author Svein Erling Tysvaer
At 12:50 07.11.2002 +0000, you wrote:
> > > GEN_ID (GENERATOR, NEWVALUE - GEN_ID (GENERATOR,0) );
> >
> > Right, but this isn't safe in a multi user environment.
>
>Is not safe the expression ? If this is the case can you give more info?
>And yes, I agree that setting a GEN_ID after creation does not make sense IMHO

Generators are outside transaction control. I would assume that the inner
GEN_ID is called before the outer GEN_ID, but there is nothing preventing
anyone else from calling GEN_ID between those calls.

Say you call
GEN_ID (GENERATOR, 1 - GEN_ID (GENERATOR,0) );
you would expect the generator afterwards to be 1. Let's see what I assume
could happen if this call is made twice simultaneously:

Lets say that GENERATOR has the value of 100:

First, both of them issue the inner call to GEN_ID(GENERATOR,0) - which
returns 100 in both cases.

Then, one of them sets the GENERATOR to (100, 1-100) =1 and then the other
one sets the generator to (1,1-100) = -98

An unlikely event, but theoretically possible, so it ought to be avoided.

I know nothing about the internals of Firebird and may be wrong in my
reasoning, but this is what I expect could happen in the worst case.

Set