Subject RE: [firebird-support] Find Generator Value Used after Insert Trigger
Author Nigel Weeks
Use a stored procedure to insert - sounds weird, but it keeps
database->application round-trips down to one cycle, saving you, and your
app, valuable time.
If you use a 64bit integer as a pkey, you won't have to worry about skipping
values...zillions of records;-)

You most likely know how to write a stored procedure, but I'll put one in
for the next person who needs this info, and searches for it


set term !! ;
CREATE PROCEDURE sp_ins_tablename(
F1 integer,
F2 VARCHAR(20),
F3 VARCHAR(20)
) RETURNS (
int_newkey NUMERIC(18,0)
)
AS BEGIN
/* Get a new generator value */
int_newkey = gen_id(generator_name,1);
/* Insert it into the table */
insert into table (pkeyfield, F1, F2, F3)
values (:int_newkey,:F1, :F2, :F3);
SUSPEND;
END !!
SET TERM ; !!

N.



> -----Original Message-----
> From: garthtissington [mailto:GarthTissington@...]
> Sent: Friday, 28 May 2004 9:27 AM
> To: firebird-support@yahoogroups.com
> Subject: [firebird-support] Find Generator Value Used after Insert
> Trigger
>
>
> I gave a Generator and it is used in a trigger to automatically
> populate a primary key field. Let's say the primary key is KEY_ID
>
> When I execute a statement like
>
> INSERT (F1,F2,F3) values (1,2,3);
>
> KEY_ID is automatically generator correctly. Great.
>
> How can I find out which Generator ID value was used? I know if
> Could get the current generator value but it may not be accurate as
> there may have been an insert from another process between my insert
> and my retrieval of teh current GEN_ID.
>
> Incidentally, I'm Using Delphi and IBObjects.
>
> Thank you
>
> p.s. I know I could also get the gen ID and include it in the INSERT
> statement. This has a different problem in that I chew through a
> lot of ID numbers when proposed inserts are cancelled or aborted
>
>
>
>
>
>
>
>
>
>
>
>
> ------------------------ Yahoo! Groups Sponsor
> --------------------~-->
> Yahoo! Domains - Claim yours for only $14.70
> http://us.click.yahoo.com/Z1wmxD/DREIAA/yQLSAA/67folB/TM
> --------------------------------------------------------------
> ------~->
>
>
> Yahoo! Groups Links
>
>
>
>
>
>