Insertion through instead off trigger
Posted in 2011
Topics: Data Types & Schema Design, Triggers, Constraints & Referential Integrity
Hi,
I am inserting a row into view using instead off trigger . Table contains the
serial column. When I try to retrieve the last inserted serial in session
using the query select dbinfo('sqlca.sqlerrd1') from systables where tabid=1
result is always zero but correct serial no is inserted in table. I believe
query is returning incorrect answer.
Can any body help ?
Sample code :
CREATE
TABLE data_codes (code_no VARCHAR(32), code_id VARCHAR(128),
name VARCHAR(10) ,code_srno serial, PRIMARY KEY(code_no)
);
CREATE VIEW data_codes_view (code_no ,code_id,name,code_srno) AS
SELECT x0.code_no , x0.code_id, x0.name , x0.code_srno FROM data_codes x0 ;
CREATE TRIGGER data_code_cardsi INSTEAD OF
INSERT ON data_codes_view REFERENCING NEW AS NEW FOR EACH ROW
( INSERT INTO data_codes (code_no, code_id, NAME )
VALUES
(
NEW.code_NO,NEW.code_id,NEW.NAME
)
);
--Testing Script
insert into data_codes_view (code_no ,code_id,name )values (1,2,'abc') --- onview
select dbinfo('sqlca.sqlerrd1') from systables where tabid=1 --- incorrect
answer
insert into data_codes (code_no ,code_id,name )values (2,2,'abc') -- on actualtable
select dbinfo('sqlca.sqlerrd1') from systables where tabid=1 --- correct answer
--
Regards,
Anees Ahmad
Hi Anees, What you are seeing is an expected behavior and it is documented in IDS manual. Since SQLCA structure does not record serial values that are inserted by triggers, you cannot call the DBINFO function with the 'sqlca.sqlerrd1', 'bigserial', or 'serial8' options to return a serial value that a triggered action inserts. Regards, Ken