Subject Re: using Gen_id from a stored proc
Author dianeb77@hotmail.com
--- In ib-support@y..., Jörg Schiemann <schimmi@s...> wrote:
> > I am trying to write a simple stored proc that returns the results
of
> > running Gen_Id. I am trying to use this code:
> >
> > Create Procedure GeneratePrimaryKey
> > Returns ("PK" Integer )
> > As Begin
> > "PK" = Gen_Id( PrimaryKeyGenerator, 1 );
> > End !!
> > Set Term ; !!
> >
<...>
> Try
>
> DECLARE VARIABLE GEN_NO INTEGER;
> DECLARE VARIABLE GEN_NEXT_NO INTEGER;
>
> SELECT GEN_ID(GEN_YOUR_GENERATOR, 0) FROM RDB$DATABASE INTO
:GEN_NO;
> GEN_NEXT_NO = GEN_NO + 1;

I must be missing something.

Since this doesn't cause the generator value to change, every use will
return the same value for GEN_NO, so every user will assign
identical GEN_NO + 1 as his or her PK value ... Of course, if these
are really PKs, then second try will fail, but even if they are not,
there has got to be an easier way to assign a constant value to a
field.

db