You are on page 1of 3

## Enable Foreign Key constraints

PRINT('*** Enabling Foreign Key Constraints - Start');

BF_EnableAllForeignKeys( 'EDW');

PRINT('*** Enabling Foreign Key Constraints - End');

------***----------

## Function: BF_EnableAllForeignKeys
## Purpose: Set all user foreign keys to enabled for an environment
## Parameters: $PV_Environment - ODS or EDW
## Returns: none
## Notes:
##
## History: 14.Jan.2013 Guidewire Initial Version
## 05.Feb.2013 JRL added SQL case

IF (NOT $PV_Environment IN('ODS', 'EDW'))


BF_LogError('BF_EnableAllForeignKeys: $PV_Environment not found.', 1001);

IF (upper(BF_GetDatabaseTypeDW( )) = 'ORACLE')
BEGIN
$LV_SQL = 'BEGIN
for i in (select constraint_name, table_name
from user_constraints
where CONSTRAINT_TYPE = \'R\' and status = \'DISABLED\')
LOOP
execute immediate \'alter table \' || i.table_name ||
\' enable constraint \' || i.constraint_name;
end loop;
end; ';

## You MUST cleanse the string because ORACLE gives error if there are carriage
returns
$LV_SQL = replace_substr_ext(replace_substr_ext($LV_SQL, '/n', ' ', null, null),
'/r', ' ', null, null);

IF ($PV_Environment = 'ODS')
sql('ODS_DS', $LV_SQL);
ELSE
sql('EDW_DS', $LV_SQL);
END
ELSE IF (upper(BF_GetDatabaseTypeDW( )) = 'SQL')
BEGIN
$LV_SQL = 'DECLARE @table_name nvarchar(50);
DECLARE all_tables CURSOR
FOR SELECT name FROM sys.objects WHERE type = \'U\'
OPEN all_tables
FETCH NEXT FROM all_tables INTO @table_name
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC(\'ALTER TABLE \' + @table_name + \' CHECK CONSTRAINT
ALL\')
FETCH NEXT FROM all_tables into @table_name
END
CLOSE all_tables;
DEALLOCATE all_tables; ';

IF ($PV_Environment = 'ODS')
sql('ODS_DS', $LV_SQL);
ELSE
sql('EDW_DS', $LV_SQL);

END
else
BF_LogError('BF_EnableAllForeignKeys: Database type not found.', 1001);

RETURN 1;

## Function: BF_LogError
## Purpose: ETL Error...
## IF Abort = 'Y Abort on Failure
## IF Email = 'Y Send Email on Failure
## Parameters: $ErrorMessage, $ErrorNumber
## Returns: 0
## Notes:

### Email the the following

PRINT( '********** ETL Message (BF_LogError) -- ' || $ErrorMessage);

$LV_MailList =
lookup_ext([ODS_DS.ODS.ETL_USER_EMAIL_CONFIG,'PRE_LOAD_CACHE','MAX'],
[EMAIL_ON_FAILURE],[NULL],[CONFIG,'=',current_system_configuration()])
SET ("run_as_separate_process"='no', "output_cols_info"='<?xml version="1.0"
encoding="UTF-8"?><output_cols_info><col index="1" expression="no"/>
</output_cols_info>' );

$LV_Subject_Line = 'FAILURE - '


|| current_system_configuration()
|| ' - '
|| job_name()
||' - '
|| host_name();

if(BF_GetEmailFailureFlag() = 'Y')
begin
print('BF_LogError - $LV_MailList='||$LV_MailList);
smtp_to($LV_MailList, $LV_Subject_Line, $ErrorMessage , 500, 500);
end
### Raise exception if the Abort flag = 'Y' or Error Number >= 90000
if (( BF_GetAuditAbortFlag() = 'Y') or ($ErrorNumber >= 90000))
begin
raise_exception_ext($ErrorMessage, $ErrorNumber );
end

RETURN 0;

## Function: BF_GetEmailFlag
## Purpose: Get Email Flag from ETL_CONTROL file
## Parameters: none
## Returns: 'Y' or 'N'
## Notes:
##
## History: 15.Dec.2012 Millbrook Base Version (Initial Comment)
$EmailFlag =
upper(lookup_ext([ODS_DS.ODS.ETL_USER_ETL_CONFIG,'PRE_LOAD_CACHE','MAX'],
[EMAIL_ON_ERR_FL],[NULL],[CONFIG,'=',current_system_configuration()])
SET ("run_as_separate_process"='no', "output_cols_info"='<?xml version="1.0"
encoding="UTF-8"?><output_cols_info><col index="1" expression="no"/>
</output_cols_info>' ));

RETURN
$EmailFlag;

## Function: BF_GetAuditAbortFlag
## Purpose: Get ABORT_ON_FAILED_AUDIT_FL from ETL_CONTROL file
## Parameters: none
## Returns: 'Y' or 'N'
## Notes:
##
## History: 15.Dec.2012 Millbrook Base Version (Initial Comment)

$AbortFlag = upper(
lookup_ext([ODS_DS.ODS.ETL_USER_ETL_CONFIG,'PRE_LOAD_CACHE','MAX'],
[ABORT_ON_ERR_FL],[NULL],[CONFIG,'=',current_system_configuration()])
SET ("run_as_separate_process"='no', "output_cols_info"='<?xml
version="1.0"
encoding="UTF-8"?><output_cols_info><col index="1" expression="no"/>
</output_cols_info>' ));

RETURN
$AbortFlag;

You might also like