Subject Re: [firebird-support] Get the value of generated primary key after an insert
Author Radu Sky
Adriano wrote:
> Radu,
> Thanks, i've got it!
>
> Dim Counter as Integer
> query =3D "SELECT GEN_ID(GEN_PRATICHE_IDPRATICA, 1) AS MyVar FROM
> RDB$DATABASE;"
> Set rs =3D cn.Execute(query, , adCmdText)
> Counter =3D rs!MyVar
> MsgBox Counter
>
> i wonder: it's secure this method? I'm sure to receive THE exact GEN_ID of
> the user if after that he executes an INSERT query ?
> If there are other users (on other pc) in the meantime could be take that
> GEN_ID value ?
>
When you do GEN_ID(GEN_PRATICHE_IDPRATICA, 1) you increment the generator.
If you just want to retrieve the generator value use
GEN_ID(GEN_PRATICHE_IDPRATICA, 0)
Generator are transaction independent so it is guaranteed that the
returned value is unique (of course, unless you reset it, but that is
off topic)

HTH
Radu