Subject | Re: [firebird-support] Get the value of generated primary key after an insert |
---|---|
Author | Radu Sky |
Post date | 2006-05-20T21:43:43Z |
Adriano wrote:
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
> Radu,When you do GEN_ID(GEN_PRATICHE_IDPRATICA, 1) you increment the generator.
> 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 ?
>
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