/*****************************************************************************
*
* Filename         - $Workfile:   label_trace_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 label_trace table
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 1997
*
*****************************************************************************/
/****************************************************************************
* @(#)$Workfile:   label_trace_triggers.sql  $  $Revision:   1.2  $
*
* 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:   /shared/pvcs/tagtarch/db_ora/db/source/live/triggers/label_trace_triggers.svl  $
* 
*    Rev 1.2   26 Feb 1998 11:42:30   tagtrak
* OR:
* CR:
* REV:
* Initial core product version
* 
*    Rev 1.1   15 Jan 1998 13:39:02   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:32   tagtrak
* OR:
* CR:
* REV:
* Initial check-in
*
****************************************************************************/



create or replace trigger ti_label_trace
before insert on label_trace
for each row
declare
	numrows integer;
begin
    
	/*
	 * - Get the next sequential value for the record_id
	*/
	
	select
		label_trace_id.nextval
	into
		:new.record_id
	from
		dual;
end;
/

create or replace trigger tu_label_trace
before update on label_trace
for each row
declare
	numrows integer;
begin

	/*
	 * - Check the label_no, label_type, location_code, label_trace_time
	 *	 and user_id, and if they are different than the old version,
	 *	 then error
	*/

	if (:old.label_no != :new.label_no) then
		raise_application_error( -20018, 'non modifiable column cannot be modified.');
	end if;
	
	if (:old.label_type != :new.label_type) then
		raise_application_error( -20018, 'non modifiable column cannot be modified.');
	end if;
	
	if (:old.location_code != :new.location_code) then
		raise_application_error( -20018, 'non modifiable column cannot be modified.');
	end if;
	
	if (:old.label_trace_time != :new.label_trace_time) then
		raise_application_error( -20018, 'non modifiable column cannot be modified.');
	end if;
	
	
	if (:old.location_code != :new.location_code) then
		 raise_application_error( -20019, 'cannot modify parent code in child table.');
	end if;
	
	if (:old.user_id != :new.user_id) then
		 raise_application_error( -20019, 'cannot modify parent code in child table.');
	end if;
end;
/
