Subject Re: [firebird-support] ID of latest record just inserted
Author Hans
Is it possible you also have an on insert trigger active setting on
tmp_some_table
using the same generator ?

----- Original Message -----
From: "rebel_rob_98" <rebel_rob_98@...>
To: <firebird-support@yahoogroups.com>
Sent: Thursday, September 08, 2005 9:19 PM
Subject: [firebird-support] ID of latest record just inserted


> Hello All,
>
> This is probably an easy questions, so please be forgiving :)
>
> I have a stored procedure that takes in info, inserts it into the DB
> and I want to return the ID of the record that was just inserted.
> Here is a sample chunk of code:
>
> SELECT gen_id(TMP_SOME_GEN, 1) as Result
> FROM RDB$Database
> INTO :tcbid;
> INSERT INTO tmp_some_table
> (field1,
> field2,...
>
> This code works and does not throw an error however the ID (tcbid)
> does not match that of the one just inserted (it's one digit behind).
> So, my solution was this:
>
> ...
> decalre variable finalid integer;
> ...
> SELECT gen_id(TMP_SOME_GEN, 0) as Result
> FROM RDB$Database
> INTO :tcbid;
>
> finalid = tcbid + 1;
>
> INSERT INTO tmp_some_table
> (field1,
> field2,...
>
> The method listed above gets me the correct ID of the record being
> inserted, however I am not sure this is the best course of action.
>
> Any tips or suggestions are greatly appreciated.
>
> Thank you for your time,
>
> Robert
>
>
>
>
>
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://firebird.sourceforge.net and click the Resources item
> on the main (top) menu. Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Yahoo! Groups Links
>
>
>
>
>
>