rem rem $Header: L:\\\\model\\repman40\\api\\RCS\\citrg.hpb 1.1 1998/05/28 16:53:41 mfrobins Exp $ rem Rem Copyright (c) 1994 by Oracle Corporation Rem NAME Rem citrg.hpb - Rem DESCRIPTION Rem Rem RETURNS Rem Rem NOTES Rem Rem MODIFIED (MM/DD/YY) Rem jwetherb 09/08/94 - substr -> substrb Rem aheath 07/08/94 - Creation REM *************************************************************************** REM Hand-carved package body for DATABASE TRIGGER created on 21-JUL-94 REM *************************************************************************** CREATE OR REPLACE PACKAGE BODY cihtrg IS -- Type-specific post-process routines plm_ref number; --ID of the PL/SQL module associated with the trigger (used by pre and post-delete) sac_type constant varchar2(6) := 'TRG'; --======================== PRE-PROCESS (INS,UPD) ============================-- PROCEDURE pre_process(operation varchar2,id rm.reference, pl in out NOCOPY ciodatabase_trigger.data) IS pac_type varchar2(6); pac_reference number; lang_id rm.reference; module_type varchar2(10); md cioplsql_module.data; BEGIN -- USBug 526006 -- pac_reference := nvl(pl.v.table_definition_reference, -- pl.v.view_definition_reference); -- pac_type := ciiutl.short_type(pac_reference); -- Access rights for database trigger derive from the table definition -- Access rights checking performed by triggers in config 4.0.9 -- ciiacc.check_access_rights(pac_reference, pac_type, 'UPD','SHR'); -- Validate user-defined properties if cieval.is_extended then cieval.check_element(id,pl.v.types,(operation='UPD') ,pl.v.user_defined_property_0,pl.i.user_defined_property_0 ,pl.v.user_defined_property_1,pl.i.user_defined_property_1 ,pl.v.user_defined_property_2,pl.i.user_defined_property_2 ,pl.v.user_defined_property_3,pl.i.user_defined_property_3 ,pl.v.user_defined_property_4,pl.i.user_defined_property_4 ,pl.v.user_defined_property_5,pl.i.user_defined_property_5 ,pl.v.user_defined_property_6,pl.i.user_defined_property_6 ,pl.v.user_defined_property_7,pl.i.user_defined_property_7 ,pl.v.user_defined_property_8,pl.i.user_defined_property_8 ,pl.v.user_defined_property_9,pl.i.user_defined_property_9 ,pl.v.user_defined_property_10,pl.i.user_defined_property_10 ,pl.v.user_defined_property_11,pl.i.user_defined_property_11 ,pl.v.user_defined_property_12,pl.i.user_defined_property_12 ,pl.v.user_defined_property_13,pl.i.user_defined_property_13 ,pl.v.user_defined_property_14,pl.i.user_defined_property_14 ,pl.v.user_defined_property_15,pl.i.user_defined_property_15 ,pl.v.user_defined_property_16,pl.i.user_defined_property_16 ,pl.v.user_defined_property_17,pl.i.user_defined_property_17 ,pl.v.user_defined_property_18,pl.i.user_defined_property_18 ,pl.v.user_defined_property_19,pl.i.user_defined_property_19 ); end if; -- Initialize unassigned properties with default values on INSERT if operation = 'INS' then pl.v.element_type_name := sac_type; pl.i.element_type_name := true; if pl.i.table_definition_reference then pl.v.database_trigger_for := 'TBL'; else pl.v.database_trigger_for := 'VW'; end if; end if; if operation = 'INS' and not cdapi.load_mode and (pl.i.plsql_module_reference = false or pl.v.plsql_module_reference is null) then -- Need to create a module that implements the trigger and get -- the trigger to refer to the created module md.v.name := pl.v.name; md.v.short_name := substrb(pl.v.name,1,20); md.v.purpose := substrb(cdapi.instantiate_mess('CDA',2054,pl.v.name), 1, 70); md.v.plsql_module_type := 'TRG-LOGIC'; md.i.name := true; md.i.short_name := true; md.i.purpose := true; md.i.plsql_module_type := true; cioplsql_module.ins(null,md); ciiutl.name_mangle(md.v.id, md.v.types); -- Force the name of the PLM to be unique. pl.v.plsql_module_reference := md.v.id; pl.i.plsql_module_reference := md.i.id; end if; -- Only allow TRG-LOGIC PL/SQL modules to be assigned to trigger if operation = 'UPD' and pl.i.plsql_module_reference then select max(plm.plsql_module_type) into module_type from ci_plsql_modules plm where plm.id = pl.v.plsql_module_reference; if module_type != 'TRG-LOGIC' then ciierr.fatal(1058,ciiutl.identify(id, pl.v.types)); end if; end if; END; --======================== PRE-PROCESS (DEL,SEL) ============================-- PROCEDURE pre_process(operation varchar2,id rm.reference) IS BEGIN -- Access rights for database trigger derive from the table definition -- Access rights checking performed by triggers in config 4.0.9 -- ciiacc.check_access_rights(id,sac_type,operation,'SAC'); -- No delete check -- Before deleting trigger, want to get the id for the PL/SQL module associated with it. -- The PL/SQL module will be deleted in post-process. Can't do it here as deletion of -- PLMs is blocked if they have triggers connected to them, so do delete once the trigger -- is out of the way. -- Bug 849403 requests this behavior is removed in Release 6.5 -- if operation='DEL' then -- select trg.plsql_module_reference -- into plm_ref -- from ci_database_triggers trg -- where trg.id=pre_process.id; -- end if; null; END; --===================== POST-PROCESS (INS,UPD,SEL) ==========================-- PROCEDURE post_process(operation varchar2,id rm.reference, pl ciodatabase_trigger.data) IS trg ciodatabase_trigger.data; cursor c1 is select tc.id from ci_trigger_column_usages tc where tc.database_trigger_reference = post_process.id; BEGIN if pl.i.name then -- check name is a valid ORACLE name if cihtbl.is_name_valid(pl.v.name) then ciierr.fatal(1003,ciiutl.identify(pl.v.id, pl.v.types),pl.v.name); end if; end if; if operation = 'INS' or (operation = 'UPD' and pl.i.name = true) then -- Need to do a UID check on database trigger rmman.log_change('CIHTRGU1',pl.v.id); end if; if operation = 'UPD' and pl.i.trigger_on_update = true and nvl(pl.v.trigger_on_update,'N') = 'N' then -- delete all associated trigger column usages for trgcol in c1 loop ciotrigger_column_usage.del(trgcol.id); end loop; end if; END; --========================= POST PROCESS (DEL) ==============================-- PROCEDURE post_process(operation varchar2,id rm.reference) IS BEGIN -- Delete the trigger and any trigger column usages ciiutl.delete_element(id,'TRG',cdapi.app_sys_ref,'APP'); -- And delete the PL/SQL module created for the trigger (plm_ref determined in pre-process) -- Bug 849403 requests this behavior is removed in Release 6.5 -- cioplsql_module.del(plm_ref); END; --============================= TRIGGER COUNT ===============================-- FUNCTION trigger_count(table_id rm.reference,create_status varchar2) RETURN number IS trg_count number; BEGIN select count(*) into trg_count from ci_database_triggers trg where trg.table_definition_reference = trigger_count.table_id and trg.complete_flag = 'Y'; return(trg_count); END; --============================= IS UNIQUE TYPE ==============================-- FUNCTION is_uniq_type(id rm.reference, table_id rm.reference, execute_time varchar2, trigger_level varchar2, trigger_on_delete varchar2, trigger_on_insert varchar2, trigger_on_update varchar2) RETURN boolean IS trg_count number; BEGIN return(true); END; --================================== END ====================================-- -- -- Package instantiation block -- BEGIN is_installed := true; END; /