CREATE TABLE TBERROR_LOG_ESTOQUE (
    ID INTEGER NOT NULL,
    TABELA VARCHAR(500),
    TABELA_ID INTEGER,
    MENSAGEM VARCHAR(500),
    DATAHORA TIMESTAMP DEFAULT 'NOW' NOT NULL);

ALTER TABLE TBERROR_LOG_ESTOQUE
ADD CONSTRAINT PK_TBERROR_LOG_ESTOQUE
PRIMARY KEY (ID);

CREATE SEQUENCE GTBERROR_LOG_ESTOQUE;

CREATE INDEX ITBERROR_LOG_ESTOQUE_01
ON TBERROR_LOG_ESTOQUE (TABELA);

CREATE INDEX ITBERROR_LOG_ESTOQUE_02
ON TBERROR_LOG_ESTOQUE (TABELA_ID);


SET TERM ^ ;

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

SET TERM ; ^


SET TERM ^ ;

create or alter procedure SPI_ERROR_LOG_ESTOQUE (
    TABELA varchar(500),
    TABELA_ID integer,
    MENSAGEM varchar(500))
as
BEGIN

    IN AUTONOMOUS TRANSACTION DO
    BEGIN
        
        INSERT INTO TBERROR_LOG_ESTOQUE (TABELA, TABELA_ID, MENSAGEM)
        VALUES (:TABELA, :TABELA_ID, :MENSAGEM);

    END
END^

SET TERM ; ^

