firebird procedure insert with return values not commit
Posted: Mon 23 May 2016 22:39
I have the following situation:
1 - a procedure in which I insert and returns me a sequential number.
2 - uniconnection settings are to autocommit = true, I'm not using
UNITRANSACTION no object for explicit transactions.
3 - Using latest version of unidac.
the procedure is as follows:
create or alter procedure SP_INSERT_ORCAMENTO (
DATA date,
CODCLI integer,
CODTPV integer,
CODEMP integer,
CODVEND integer,
CAIXA integer,
NOMECLIENTE varchar(40),
CNPJ varchar(14),
ENDERECO varchar(40),
BAIRRO varchar(40),
CIDADE varchar(40),
ESTADO varchar(2),
TELEFONE varchar(10))
returns (
CODIGO integer,
SEQUENCIA bigint)
as
BEGIN
CODIGO = GEN_ID(GNT_COD_ORCAMENTO, 1);
SEQUENCIA = GEN_ID(GNT_SEQUENCIA_DAV, 1);
IF (SEQUENCIA > 9999999999) THEN
BEGIN
EXECUTE STATEMENT 'SET GENERATOR GNT_SEQUENCIA_DAV TO 0';
SEQUENCIA = GEN_ID(GNT_SEQUENCIA_DAV, 1);
END
if (:codcli IS NULL) then
BEGIN
INSERT INTO ORCAMENTO (CODIGO, DATA, COD_TPV, COD_VEND, TOTAL, SEQUENCIA_DAV,
COD_EMP, STATUS, COD_CAI, NOME_CLIENTE, CPF_CNPJ, STATUS_EXPORTA,
ENDERECO, BAIRRO, CIDADE, ESTADO, FONE )
VALUES(:CODIGO, :DATA, :CODTPV, :CODVEND, 0, :SEQUENCIA,
:CODEMP, 0, :CAIXA, :NOMECLIENTE, :CNPJ, 0, :ENDERECO, :BAIRRO,
:CIDADE, :ESTADO, :TELEFONE );
END
ELSE
BEGIN
INSERT INTO ORCAMENTO (CODIGO, DATA, COD_CLI, COD_TPV, COD_VEND, TOTAL, SEQUENCIA_DAV,
COD_EMP, STATUS, COD_CAI, NOME_CLIENTE, CPF_CNPJ, STATUS_EXPORTA,
ENDERECO, BAIRRO, CIDADE, ESTADO, FONE )
VALUES(:CODIGO, :DATA, :CODCLI, :CODTPV, :CODVEND, 0, :SEQUENCIA,
:CODEMP, 0, :CAIXA, :NOMECLIENTE, :CNPJ, 0, :ENDERECO, :BAIRRO,
:CIDADE, :ESTADO, :TELEFONE );
END
SUSPEND;
END;
4 - uniQuery use with select statement as it is a procedure return, something like:
uniquery.close;
uniquery.parambyname......
uniquery.prepare;
uniquery.open;
edtCodigo.Text:. = uniquery.fieldbyname ('CODIGO') AsInteger (. I have set the value of the code field and if is not in this bank recorded);
this table is master, there is throw any detail record and is in the bank already listed there. or if you uniconnection.commitretaining (recorded in the bd).
I did tests with firedac and this does not happen (I migrated from firedac to unidac).
I wonder what I can do for this autocommit = true commit it to the bank after making the query open, as is the insertion procedure
and not use cached updates
1 - a procedure in which I insert and returns me a sequential number.
2 - uniconnection settings are to autocommit = true, I'm not using
UNITRANSACTION no object for explicit transactions.
3 - Using latest version of unidac.
the procedure is as follows:
create or alter procedure SP_INSERT_ORCAMENTO (
DATA date,
CODCLI integer,
CODTPV integer,
CODEMP integer,
CODVEND integer,
CAIXA integer,
NOMECLIENTE varchar(40),
CNPJ varchar(14),
ENDERECO varchar(40),
BAIRRO varchar(40),
CIDADE varchar(40),
ESTADO varchar(2),
TELEFONE varchar(10))
returns (
CODIGO integer,
SEQUENCIA bigint)
as
BEGIN
CODIGO = GEN_ID(GNT_COD_ORCAMENTO, 1);
SEQUENCIA = GEN_ID(GNT_SEQUENCIA_DAV, 1);
IF (SEQUENCIA > 9999999999) THEN
BEGIN
EXECUTE STATEMENT 'SET GENERATOR GNT_SEQUENCIA_DAV TO 0';
SEQUENCIA = GEN_ID(GNT_SEQUENCIA_DAV, 1);
END
if (:codcli IS NULL) then
BEGIN
INSERT INTO ORCAMENTO (CODIGO, DATA, COD_TPV, COD_VEND, TOTAL, SEQUENCIA_DAV,
COD_EMP, STATUS, COD_CAI, NOME_CLIENTE, CPF_CNPJ, STATUS_EXPORTA,
ENDERECO, BAIRRO, CIDADE, ESTADO, FONE )
VALUES(:CODIGO, :DATA, :CODTPV, :CODVEND, 0, :SEQUENCIA,
:CODEMP, 0, :CAIXA, :NOMECLIENTE, :CNPJ, 0, :ENDERECO, :BAIRRO,
:CIDADE, :ESTADO, :TELEFONE );
END
ELSE
BEGIN
INSERT INTO ORCAMENTO (CODIGO, DATA, COD_CLI, COD_TPV, COD_VEND, TOTAL, SEQUENCIA_DAV,
COD_EMP, STATUS, COD_CAI, NOME_CLIENTE, CPF_CNPJ, STATUS_EXPORTA,
ENDERECO, BAIRRO, CIDADE, ESTADO, FONE )
VALUES(:CODIGO, :DATA, :CODCLI, :CODTPV, :CODVEND, 0, :SEQUENCIA,
:CODEMP, 0, :CAIXA, :NOMECLIENTE, :CNPJ, 0, :ENDERECO, :BAIRRO,
:CIDADE, :ESTADO, :TELEFONE );
END
SUSPEND;
END;
4 - uniQuery use with select statement as it is a procedure return, something like:
uniquery.close;
uniquery.parambyname......
uniquery.prepare;
uniquery.open;
edtCodigo.Text:. = uniquery.fieldbyname ('CODIGO') AsInteger (. I have set the value of the code field and if is not in this bank recorded);
this table is master, there is throw any detail record and is in the bank already listed there. or if you uniconnection.commitretaining (recorded in the bd).
I did tests with firedac and this does not happen (I migrated from firedac to unidac).
I wonder what I can do for this autocommit = true commit it to the bank after making the query open, as is the insertion procedure
and not use cached updates