Page 1 of 1

Difference between the command APPLYUPDATES and COMMITUPDATE

Posted: 30.06.2013, 17:39
by doidopb
Hi...

I use version 6.6.2-RC Zeos with MYSQL 5.0.45. I have a TZQuery with the property Cached Updates = True.

It is recommended to use the command COMMITUPDATES after the command APPLYUPDATES, as shown below:

ZQuery1.ApplyUpdates;
ZQuery1.CommitUpdates;

If using only the command APPLYUPDATES the changes are recorded in the table.

So what is the function of the command COMMITUPDATES, after using the APPLYUPDATES????

Thanks

Posted: 30.06.2013, 17:58
by EgonHugeist
doidopb,

COMMITUPDATES clears the CachedUpdates buffer without applying the changes to the DataBase, AFAIK.

ApplyUpdates updates the edited rows and finally needs a Commit.

Posted: 30.06.2013, 18:17
by doidopb
I'm from Brazil, I'm sorry for bad English.

What I understood is that CommitUpdates only clears the buffer, without applying the changes.

Already ApplyUpdates writes the changes to the base and clears the buffer cachedupdates. That??
EgonHugeist wrote:doidopb,

COMMITUPDATES clears the CachedUpdates buffer without applying the changes to the DataBase, AFAIK.

ApplyUpdates updates the edited rows and finally needs a Commit.

Posted: 30.06.2013, 19:27
by doidopb
My code is:

Code: Select all

procedure StartTransacao;
begin
  dtm_banco.z_transacao.SQL.Clear;
  dtm_banco.z_transacao.SQL.Text := 'START TRANSACTION';
  dtm_banco.z_transacao.ExecSQL;
end;

procedure CommitTransacao;
begin
  dtm_banco.z_transacao.SQL.Clear;
  dtm_banco.z_transacao.SQL.Text := 'COMMIT';
  dtm_banco.z_transacao.ExecSQL;
end;

procedure RollBackTransacao;
begin
  dtm_banco.z_transacao.SQL.Clear;
  dtm_banco.z_transacao.SQL.Text := 'ROLLBACK';
  dtm_banco.z_transacao.ExecSQL;
end;

procedure Tfrm_saidas.spb_confirmarClick(Sender: TObject);
begin
  ActiveControl := nil;
  if trim(edt_requisicao.Text) = '' Then
    begin
      ShowMessage('Preencha a requisicao');
      edt_requisicao.SetFocus;
    end
  else
  if edt_data.Text = '  /  /    ' Then
    begin
      ShowMessage('Preencha a data');
      edt_data.SetFocus
    end
   else
   if dtm_banco.z_sce1_saidas.RecordCount = 0 Then
    begin
      ShowMessage('Coloque ao menos 1 item nessa sa?da');
      edt_codigo.SetFocus;
    end
  else
   //--------------------------------------------------//
      begin
        StartTransacao;
        try
          dtm_banco.z_sce1_reqsaida.Post;
          dtm_banco.z_sce1_saidas.ApplyUpdates;
          dtm_banco.z_sce1_saidas.CommitUpdates;

          //atualizar o estoque @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
          dtm_banco.z_sce1_saidas.First;
          while not(dtm_banco.z_sce1_saidas.Eof) do
            begin
              //atualiza o estoque que est? em SCE1_ESTRECEP, diminuindo o mesmo, dado a saida
              dtm_banco.z_formulas.SQL.Text := 'UPDATE SCE1_ESTRECEP SET quant_nf = quant_nf - '+dtm_banco.z_sce1_saidasquantidade.AsString+','+
                                               'dt_ult_sai = CASE WHEN "'+FormatDateTime('yyyy/mm/dd',Date)+'" > dt_ult_sai THEN "'+
                                               FormatDateTime('yyyy/mm/dd',Date)+'" WHEN dt_ult_sai IS NULL THEN "'+
                                               FormatDateTime('yyyy/mm/dd',Date)+'" ELSE dt_ult_sai END WHERE codigo = "'+
                                               dtm_banco.z_sce1_saidascod_prod.AsString+'"';
              dtm_banco.z_formulas.ExecSQL;
              //**********************************************************

              //atualiza o estoque que est? em ESTOQRC, diminuindo o mesmo, dado a saida
              dtm_banco.z_formulas.SQL.Text := 'UPDATE ESTOQRC SET quant_nf = quant_nf - '+dtm_banco.z_sce1_saidasquantidade.AsString+
                                               ',dt_ult_sai = CASE WHEN "'+FormatDateTime('yyyy/mm/dd',Date)+'" > dt_ult_sai THEN "'+
                                               FormatDateTime('yyyy/mm/dd',Date)+'" WHEN dt_ult_sai IS NULL THEN "'+
                                               FormatDateTime('yyyy/mm/dd',Date)+'" ELSE dt_ult_sai END WHERE codigo = "'+
                                               dtm_banco.z_sce1_saidascod_prod.AsString+'"';
              dtm_banco.z_formulas.ExecSQL;
              //**********************************************************
              
              dtm_banco.z_sce1_saidas.Next;
            end;
          //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

          EstadoNormal;
          CommitTransacao;

          if op = 'i' Then
            begin
              dtm_banco.z_sce1_reqsaida.SQL.Text := 'SELECT * FROM SCE1_REQSAIDA WHERE requisicao = "'+dtm_banco.z_sce1_reqsaidarequisicao.AsString+'"';
              dtm_banco.z_sce1_reqsaida.Close; dtm_banco.z_sce1_reqsaida.Open;
           end;
          AtualizaItens;
        except;
          RollbackTransacao;
          ShowMessage('Erro ao gravar os dados');
          Close;
        end;
      end;
end;
It is currently used the COMMIT UPDATES as i did??? Or is it not necessary??

Posted: 03.07.2013, 06:28
by EgonHugeist
doidopb,

the code seems to be right. Hint: have no clue about 6.6.x series.