Subject | Re: [firebird-support] Calling stored procedure in a trigger |
---|---|
Author | Michael Ludwig |
Post date | 2010-10-01T23:45:54Z |
Helen Borrie schrieb am 02.10.2010 um 10:09 (+1300):
51 (61) ff) does not readily yield the answer to the OP's question.
I think you meant to be referring to something else. Anyhow, calling a
selectable stored procedure from inside the trigger and using the return
values works. Here's an example:
\,,,/
(o o)
------oOOo-(_)-oOOo------
drop trigger trig1;
commit;
drop procedure pp1;
commit;
drop table tt2;
commit;
drop table tt1;
commit;
create table tt1 (a int);
commit;
create table tt2 (b int);
commit;
set term ^ ;
create procedure pp1 ( i int )
returns ( o int )
as
declare a int;
declare b int;
begin
a = :i + :i;
b = :i * :I;
insert into tt2 (b) values (:a);
insert into tt2 (b) values (:b);
o = a - b;
suspend;
end
^
create trigger trig1 for tt1
active before insert
as
declare o int;
declare r int;
begin
select o from pp1(new.a) into :r;
insert into tt2 (b) values (:r);
end
^
set term ;
^
insert into tt1 (a) values (3);
commit;
select * from tt2;
commit;
--
Michael Ludwig
> At 09:47 AM 2/10/2010, Michael Ludwig wrote:Travelling is even more fun than mailing lists. ;-)
> >vladman992000 schrieb am 21.09.2010 um 12:01 (-0000):
> >
> >> Does Firebird allow for the calling of stored procedures to return
> >> values in a Trigger, or do I have to enclose the entire logic of
> >> the SP into the trigger itself in order for this to work?
> >
> >An interesting question, which I'm just bumping here as it has
> >remained unanswered.
>
> You chose a bad week! with two Firebird conferences on and people in
> transit between their homes and one or both conferences..
> Study the PSQL section of the v.2.0.6 release notes for the answer onThat section (Chapter 7, "Stored Proecedure Language (PSQL)", PDF page
> this.
51 (61) ff) does not readily yield the answer to the OP's question.
I think you meant to be referring to something else. Anyhow, calling a
selectable stored procedure from inside the trigger and using the return
values works. Here's an example:
\,,,/
(o o)
------oOOo-(_)-oOOo------
drop trigger trig1;
commit;
drop procedure pp1;
commit;
drop table tt2;
commit;
drop table tt1;
commit;
create table tt1 (a int);
commit;
create table tt2 (b int);
commit;
set term ^ ;
create procedure pp1 ( i int )
returns ( o int )
as
declare a int;
declare b int;
begin
a = :i + :i;
b = :i * :I;
insert into tt2 (b) values (:a);
insert into tt2 (b) values (:b);
o = a - b;
suspend;
end
^
create trigger trig1 for tt1
active before insert
as
declare o int;
declare r int;
begin
select o from pp1(new.a) into :r;
insert into tt2 (b) values (:r);
end
^
set term ;
^
insert into tt1 (a) values (3);
commit;
select * from tt2;
commit;
--
Michael Ludwig