Difference between the command APPLYUPDATES and COMMITUPDATE

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
doidopb
Fresh Boarder
Fresh Boarder
Posts: 9
Joined: 01.12.2012, 19:52

Difference between the command APPLYUPDATES and COMMITUPDATE

Post 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
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post 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.
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
doidopb
Fresh Boarder
Fresh Boarder
Posts: 9
Joined: 01.12.2012, 19:52

Post 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.
doidopb
Fresh Boarder
Fresh Boarder
Posts: 9
Joined: 01.12.2012, 19:52

Post 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??
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

doidopb,

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

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
Post Reply