Need some help understanding how to tie together a trigger and a
procedure together. I want to do a certain procedure if an insert
occurs on TABLE1:
TABLE1 contains COL1, COL2, COL3, COL4
CREATE TRIGGER trigger100 NO CASCADE BEFORE INSERT ON table1
REFERENCING NEW AS newdata FOR EACH ROW MODE DB2ROW
BEGIN
CALL procedure1(?, ?) handle RETURN here??
Then I have the procedure:
CREATE PROCEDURE procedure1(??)
RESULT SET 1
LANGUAGE SQL
BEGIN
....some code.....
IF newdata.COL1 < 7 is THEN
UPDATE an existing record using information from newdata
RETURN 2;
ELSEIF newdata.COL1 = 0 and an existing_record.COL1 = 0 THEN
UPDATE existing record.....
RETURN 1;
ELSEIF newdata.COL1 4 and newdata.COL2 8 THEN
INSERT the original request
RETURN 0;
END
The orignal request was:
INSERT INTO table1 (COL1, COL2, COL3, COL4) VALUES ( 4, 24, 'xxx',
'yyy')
so the questions are:
1) how does the procedure get the data from the original INSERT
statement since it is needed to determine if it should insert or
update a record? can this be passed in as a parameter?
2) How can I get the trigger to handle the various RETURN codes from
the procedure? I could add an IN rc INT to the parameter but I
noticed the RETURN option and was wondering how the caller gets this
info. I want to use the RETURN values to make the trigger SIGNAL an
sqlstate depending on the outcome.
I am sure I will have more questions but that will get me started in
the right direction I hope.