CREATE TABLE TBMINUTA_COLETA (
    ID INTEGER,
    DESCRICAO VARCHAR(50));
	
CREATE SEQUENCE GTBMINUTA_COLETA;

SET TERM ^ ;

create trigger ttbminuta_coleta_b01i for tbminuta_coleta
active before insert position 0
as
begin
  if (new.id is null) then
    new.id = gen_id(gtbminuta_coleta,1);
end
^

SET TERM ; ^

SET TERM ^ ;

CREATE trigger ttbminuta_coleta_b09i for tbminuta_coleta
active before insert position 9
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
begin
    HISTORICO = '';

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

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

SET TERM ; ^

SET TERM ^ ;

CREATE trigger ttbminuta_coleta_b01d for tbminuta_coleta
active before delete position 0
AS
declare variable HISTORICO VARCHAR(500);
begin
    HISTORICO = '';

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

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

SET TERM ; ^