How do you return a value from a Firebird 2.5 Execute Block fin the Insert SQL?
Posted: Mon 01 Oct 2012 12:52
I have Firebird 2.5 with a table
My TUniQuery has the SQL field set to
and the insert sql set to
but when doing an insert I can't seem to figure out how to retrieve the FIELD01. Ideally I would like this to with like the DMLRefresh so I could use the table in a dbgrid and see the FIELD01 value immediately when inserting a record. Any help would be appreciated
Code: Select all
CREATE TABLE TABLE01 (
FIELD01 INTEGER,
FIELD02 INTEGER
);
CREATE SEQUENCE GEN_TABLE01_ID;
ALTER SEQUENCE GEN_TABLE01_ID RESTART WITH 0;
SET TERM ^ ;
CREATE TRIGGER TABLE01_BI FOR TABLE01
ACTIVE BEFORE POSITION 0
AS
BEGIN
if (NEW.FIELD01 is NULL) then BEGIN
NEW.FIELD01 = NEXT VALUE FOR GEN_TABLE01_ID;
END END^
SET TERM ; ^
Code: Select all
select * from TABLE01
Code: Select all
execute block( FIELD02 Integer = :FIELD02 )
returns ( FIELD01 Integer )
as
begin
insert into table01 ( FIELD02 ) VALUES ( :FIELD02 ) RETURNING FIELD01 INTO :FIELD01;
SUSPEND;
END