Subject Re: [ib-support] Re: Getting id of last inserted record
Author Doug Chamberlin
At 4/28/2003 05:19 PM (Monday), hay77772000 wrote:
>To migrate easily, therefore, I'd like to find a way that allows me
>to still issue that call into the database, and get the id back. So
>far, I don't think any of the solutions proposed allow me to do so
>(but I could be wrong!!).

Rather than call the SELECT GEN... immediately after the INSERT, call
SELECT GEN immediately before the insert and use the value you get back in
the insert itself.

In your DatabaseBean InsertSQL method,
- Issue a SELECT GEN_ID(GEN_ATABLE,1) FROM RDB$DATABASE to increment the
generator and
return the value into a local variable, genID.
- Issue an INSERT INTO Table1 (PK, col2, col3) VALUES (genID, col2Val,
col3Val);

The caller of the DatabaseBean.InsertSQL method can pass in the SQL to be
used but it needs to be modified to include the PK field if it does not
already include it.