Subject Re: [firebird-support] How to return generated value in TRIGGER ?
Author Martijn Tonies
Hi,

> I have a trigger on a table :
>
> CREATE TRIGGER TRIG_GS_PR_BI FOR GS_PR
> ACTIVE BEFORE INSERT POSITION 0
> AS
> BEGIN
> IF ((NEW.ID IS NULL) OR (NEW.ID =0)) THEN
> NEW.ID =NEXT VALUE FOR GEN_GS_PR_ID;
> END
>
> In my application I use a stored procedure to insert data,for ID I send 0
as the trigger to use generator.My problem is how to get the value written
in ID, I need it in my app after I call INSERT.Is there a simple way or a
have to query table for max(ID).
> Thanks !
>

If you don't supply "0" or "null" for the ID column, the trigger won't
do it's new value.

So, why not get a new value from the generator in the Stored Procedure
and return that to the client?

Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Oracle &
MS SQL Server
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com