/*****************************************************************************
*
* Filename         - $Workfile:   carrier_lookup_triggers.sql  $
*
*                     Name              Date      Version     CR Number
* Author           - See revision history below.
* Last Update      - See revision history below.
*
* Project Name     - TAGTRAK(Oracle Database)
*
* Source Code
* Identifier       - 0/3/300/8010/112
*
* Design Spec
* Section          - 
*
* Contents         -  Live Schema: triggers for carrier_lookup table
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 1997
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   carrier_lookup_triggers.sql  $  $Revision:   1.5  $
*
* Revision History
*
* Note that user tagtrak is many users. For these users the user
* name is entered as the last line in the change description.
*
* $Log:   /pvcsarch/db_ora/db/source/live/triggers/carrier_lookup_triggers.svl  $
* 
*    Rev 1.5   21 Jun 2001 15:03:46   tagtrak
* OR:
* CR:
* Re-baseline version 4.0.0 to include patches.
* 
*    Rev 1.4   12 Oct 1998 16:44:08   tagtrak
* OR: 12682 12683 12678 12654 12419 12265 12805 12285
* CR: 12682 12683 12678 12654 12419 12265 12805
* REV:
* Vienna enhancements/fixes for database V0.4.1E
* branch ATS revision moved to trunk.
* Andrew Walker
* 
*    Rev 1.3.1.0   25 Sep 1998 12:32:54   tagtrak
* OR: 12682 12683 12678 12654 12419 12265 12285
* CR: 12682 12683 12678 12654 12419 12265
* REV:
* Vienna enhancements for Database 0.4.1
* Andrew Walker
* 
*    Rev 1.3   02 Apr 1998 19:45:56   tagtrak
* OR:
* CR:
* REV:
* Initial Issue
* See label for concession
* 
*    Rev 1.2   26 Feb 1998 11:52:10   tagtrak
* OR:
* CR:
* REV:
* Initial core product version
* 
*    Rev 1.1   15 Jan 1998 13:38:50   tagtrak
* OR: OR11101, TN13, TN15
* CR:
* REV:
* Phase 2C to Phase 3 upgrade plus code review actions and resolving some technical issues.
* 
* 
*    Rev 1.0   22 Oct 1997 16:38:24   tagtrak
* OR:
* CR:
* REV:
* Initial check-in
*
****************************************************************************/



create or replace trigger ti_carrier_lookup
before insert on carrier_lookup
for each row
begin

		/*
		 * If the carrier bar code is NULL, assign the default
		 * value if configured.
		 */
		if ( :new.bar_code is NULL ) then
			:new.bar_code := substr(config.get_value('UNKNOWN_BARCODE'),1,3);
		end if;

		/*
		 * Add a record to the log table to record the addition
		 * of a new carrier lookup record.
		 */
    
    insert into log_table
			( user_id, reason, log_time)
		values
			( :new.last_user,
			'Carrier ' || :new.carrier || ', ' || :new.alpha_code
			|| ' ' || :new.bar_code || ' added',
			SYSDATE );
end;
/
create or replace trigger tu_carrier_lookup
before update on carrier_lookup
for each row
begin
    
		/*
		 * Raises exceptions which differ according to which
		 * columns were modified. Note that this effectively
		 * disallows updates to this table.
		 */
		
		if (:old.alpha_code != :new.alpha_code) then
			raise_application_error(-20018, 'non modifiable column cannot be modified.');
		end if;

		/*
		 * Logging a record is pointless as we will only get to this
		 * point if no fields were altered!
		 */
		/*
    insert into log_table
			( user_id, reason, log_time )
    values
			( :new.last_user,
			'Carrier ' || :new.carrier || ', ' || :new.alpha_code
			|| ' ' || :new.bar_code || ' changed',
			SYSDATE );
		*/
end;
/
