SET TERM ^ ;



/******************************************************************************/
/****                         Triggers for tables                          ****/
/******************************************************************************/



/* Trigger: TTBCARRETA_DIMENSOES_B01D */
CREATE OR ALTER TRIGGER TTBCARRETA_DIMENSOES_B01D FOR TBCARRETA_DIMENSOES
ACTIVE BEFORE DELETE POSITION 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

    HISTORICO = '';

    IF ( OLD.ID > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||'REGISTRO EXCLUIDO';
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBCARRETA_DIMENSOES', OLD.ID, HISTORICO);
    END
END
^


/* Trigger: TTBCARRETA_DIMENSOES_B01I */
CREATE OR ALTER TRIGGER TTBCARRETA_DIMENSOES_B01I FOR TBCARRETA_DIMENSOES
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
  IF (NEW.ID IS NULL) THEN
    NEW.ID = GEN_ID(GTBCARRETA_DIMENSOES,1);
END
^


/* Trigger: TTBCARRETA_DIMENSOES_B01U */
CREATE OR ALTER TRIGGER TTBCARRETA_DIMENSOES_B01U FOR TBCARRETA_DIMENSOES
ACTIVE BEFORE UPDATE POSITION 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

    HISTORICO = '';

    IF(OLD.DESCRICAO <> NEW.DESCRICAO)THEN
    BEGIN
        HISTORICO = HISTORICO||' DESC:'||OLD.DESCRICAO||'->'||NEW.DESCRICAO;
    END
    
    IF(OLD.STATUS <> NEW.STATUS)THEN
    BEGIN
        HISTORICO = HISTORICO||' STATUS:'||OLD.STATUS||'->'||NEW.STATUS;
    END
    
    IF(OLD.ALTURA <> NEW.ALTURA)THEN
    BEGIN
        HISTORICO = HISTORICO||' ALTURA:'||OLD.ALTURA||'->'||NEW.ALTURA;
    END

    IF(OLD.LARGURA <> NEW.LARGURA)THEN
    BEGIN
        HISTORICO = HISTORICO||' LARGURA:'||OLD.LARGURA||'->'||NEW.LARGURA;
    END

    IF(OLD.COMPRIMENTO <> NEW.COMPRIMENTO)THEN
    BEGIN
        HISTORICO = HISTORICO||' COMPRIMENTO:'||OLD.COMPRIMENTO||'->'||NEW.COMPRIMENTO;
    END

    IF(HISTORICO <> '') THEN
    BEGIN
        HISTORICO = 'REGISTRO ALTERADO:'||HISTORICO;
        EXECUTE PROCEDURE SPI_HISTORICO('TBTESTE_NOVOCRIAR', OLD.ID, HISTORICO);
    END
END
^


/* Trigger: TTBCARRETA_DIMENSOES_B02I */
CREATE OR ALTER TRIGGER TTBCARRETA_DIMENSOES_B02I FOR TBCARRETA_DIMENSOES
ACTIVE BEFORE INSERT POSITION 1
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

    HISTORICO = '';

    IF ( NEW.ID > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||'REGISTRO INCLUIDO';
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBCARRETA_DIMENSOES', NEW.ID, HISTORICO);
    END
END
^

SET TERM ; ^