/*****************************************************************************
*
* Filename         - $flight_info_triggers$
*
*                     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         - Triggers for agents table.
*
* Language         - Oracle SQL*Plus script
*
* Classification   - Commercial In Confidence
*
*          (c) Ultra Electronics Limited, 2003
*
*****************************************************************************/

/*
 * Before each insert into the flight_info table
 */

create or replace trigger ti_flight_info
before insert on flight_info
for each row
declare
   populate db_config.db_item%type;
begin
 IF :new.airport_code IS NULL THEN 
  :new.airport_code := trim (config.get_value ('FIDS_IF_' || :new.interface_id));
 END IF;

 BEGIN

    SELECT trim(db_value) INTO populate FROM db_config WHERE
       trim(db_item) = 'EXPECTED_FLOW_RATE';

 EXCEPTION

    WHEN OTHERS THEN
       null;
 END;
 
 IF populate = 'Y' THEN

    :new.terminal := rtrim(ltrim(:new.gate));

 END IF;

end;

/

create or replace trigger tu_flight_info
before update on flight_info
for each row
declare
   populate db_config.db_item%type;
begin

 BEGIN

    SELECT trim(db_value) INTO populate FROM db_config WHERE
       trim(db_item) = 'EXPECTED_FLOW_RATE';

 EXCEPTION

    WHEN OTHERS THEN
       null;
 END;

 IF populate = 'Y' THEN

    :new.terminal := rtrim(ltrim(:new.gate));

 END IF;

end;

/
