rem rem $Header: L:\\\\model\\repman40\\api\\RCS\\cifco.hpb 1.7 1998/12/18 09:01:53 cvanes Exp $ rem Rem Copyright (c) 1994 by Oracle Corporation Rem NAME Rem cifco.hpb - Rem DESCRIPTION Rem Rem RETURNS Rem Rem NOTES Rem Rem MODIFIED (MM/DD/YY) Rem aheath 07/08/94 - Creation REM *************************************************************************** REM Hand-carved package body for FOREIGN KEY CONSTRAINT created on 06-SEP-94 REM *************************************************************************** CREATE OR REPLACE PACKAGE BODY cihfco IS -- Type-specific post-process routines PROCEDURE check_delete(id rm.reference); sac_type constant varchar2(6) := 'OCO'; pac_type constant varchar2(6) := 'TAB'; --======================== PRE-PROCESS (INS,UPD) ============================-- PROCEDURE pre_process(operation varchar2,id number, pl in out NOCOPY cioforeign_key_constraint.data) IS CURSOR c1 IS select column_reference from ci_key_components where oky_arc1_for = 'COL' and constraint_reference = pre_process.id; BEGIN -- Access rights for foreign key constraint derive from the table -- Access rights checking performed by triggers in config 4.0.9 -- ciiacc.check_access_rights(pl.v.table_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; pl.v.constraint_type := 'FOREIGN'; pl.i.constraint_type := true; end if; --#BEGIN if pl.i.exception_table then -- replace spaces with underscores pl.v.exception_table := translate(pl.v.exception_table,' ','_'); end if; if pl.i.name then -- replace spaces with underscores cihtbl.remove_spaces(pl.v.name); --B631806 end if; if operation='UPD' then if pl.i.mandatory_flag and pl.v.mandatory_flag='Y' then FOR oky IN c1 LOOP update ci_columns col set col.null_indicator = 'NOT NULL' where col.id = oky.column_reference; END LOOP; end if; end if; -- set the disciminator value for the optional arc if operation = 'INS' then if pl.v.primary_key_reference is not null then pl.v.for_joining_to := 'PCO'; pl.i.for_joining_to := true; elsif pl.v.unique_key_reference is not null then pl.v.for_joining_to := 'UCO'; pl.i.for_joining_to := true; end if; else -- operation = 'UPD' if pl.i.primary_key_reference = false and pl.i.unique_key_reference = false then null; elsif pl.i.primary_key_reference and pl.v.primary_key_reference is not null then pl.v.for_joining_to := 'PCO'; pl.i.for_joining_to := true; elsif pl.i.unique_key_reference and pl.v.unique_key_reference is not null then pl.v.for_joining_to := 'UCO'; pl.i.for_joining_to := true; else pl.v.for_joining_to := null; pl.i.for_joining_to := true; end if; end if; --#END END; --======================== PRE-PROCESS (DEL,SEL) ============================-- PROCEDURE pre_process(operation varchar2,id number) IS BEGIN -- Access rights for foreign key constraint derive from the table -- Access rights checking performed by triggers in config 4.0.9 -- ciiacc.check_access_rights(id,sac_type,operation,'SAC'); null; END; --===================== POST-PROCESS (INS,UPD,SEL) ==========================-- PROCEDURE post_process(operation varchar2,id number, pl cioforeign_key_constraint.data) IS cursor get_okys(fco_id number) is select oky.id oky_id from ci_key_components oky where oky.constraint_reference = get_okys.fco_id; BEGIN if operation = 'INS' or (operation = 'UPD' and pl.i.name = true) then -- Need to do a UID check on constraints rmman.log_change('CIHFCOU1',pl.v.id); end if; 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 = 'UPD' then -- see if a number of KEY constraints need to be logged for rec in get_okys(pl.v.id) loop if pl.i.mandatory_flag then rmman.log_change('CIHOKYE_NULLS', rec.oky_id); end if; if pl.i.foreign_table_reference then rmman.log_change('CIHOKYE_JOIN', rec.oky_id); end if; if pl.i.arc_number then rmman.log_change('CIHOKYE_ARC_COL', rec.oky_id); end if; if pl.i.fk_cascade_delete or pl.i.fk_cascade_update then rmman.log_change('CIHOKYE_CASCADE', rec.oky_id); end if; end loop; end if; if operation = 'INS' then cihpco.create_cnus(pl.v.id, pl.v.table_reference); end if; END; --========================= POST PROCESS (DEL) ==============================-- PROCEDURE post_process(operation varchar2,id number) IS BEGIN if operation = 'DEL' then -- Delete the constraint and all it's related sub-bits ciiutl.delete_element(id,sac_type); end if; END; --============================= CHECK DELETE ================================-- PROCEDURE check_delete(id rm.reference) IS dummy number; error_count number := 0; BEGIN null; -- 4.0.12 Removed all simple delete checking -- Fortunatly there is no isssue for tables cascading FCOs circumventing -- this code as MTIs stop table deletion too. -- Check if any MTIs are connected to me END; --#begin --========================= IS COLUMN UPDATEABLE ============================-- -- This determines as far as foreign key constraints whether or not a -- module can update the value of a column. FUNCTION is_column_updateable(column_id number) RETURN boolean IS cnt number; BEGIN select count(*) into cnt from ci_foreign_key_constraints fco, ci_key_components oky where oky.column_reference = is_column_updateable.column_id and oky.constraint_reference = fco.id and fco.fk_transferable = 'N'; if cnt = 0 then return(true); else return(false); end if; END; --========================= COUNT KEY COMPONENTS ============================-- -- count how many key components are defined against this foreign key -- constraint. There are some constraints that require at least one -- key_component and other constraints that require one and only one -- key component. FUNCTION count_key_components(id number) RETURN number IS cnt number; BEGIN select count(*) into cnt from ci_key_components where CONSTRAINT_REFERENCE = count_key_components.id; return(cnt); END; --========================= GET SUB PROPERTY =================================-- -- Retrun the value of the named property. These are not accessable to the -- constraint scripts, as they appear on sub-types of Constraint FUNCTION get_sub_property(id number, column_spec varchar2) RETURN varchar2 IS ret_val varchar2(40); BEGIN select decode(column_spec, 'ARC_NUMBER', to_char(arc_number) , 'FK_CASCADE_DELETE' ,fk_cascade_delete , 'FK_CASCADE_UPDATE' ,fk_cascade_update , 'FOREIGN_TABLE_REFERENCE' ,to_char(foreign_table_reference) , 'MANDATORY_FLAG' ,mandatory_flag) into ret_val from ci_foreign_key_constraints where id = get_sub_property.id; return(ret_val); END; --#end --================================== END ====================================-- -- -- Package instantiation block -- BEGIN is_installed := true; END; /