Subject | Re: [ib-support] Re: Getting id of last inserted record |
---|---|
Author | Doug Chamberlin |
Post date | 2003-04-28T21:33:34Z |
At 4/28/2003 05:19 PM (Monday), hay77772000 wrote:
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.
>To migrate easily, therefore, I'd like to find a way that allows meRather than call the SELECT GEN... immediately after the INSERT, call
>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!!).
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.