Recent

Author Topic: rollback applyupdates?  (Read 4483 times)

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
rollback applyupdates?
« on: February 16, 2017, 04:54:54 pm »
For capturing the errormessage I use these lines of codes:
Code: Pascal  [Select][+][-]
  1. procedure TDMNAW.SQLnawAfterDelete(DataSet: TDataSet);
  2. var MyQuery : TSQLQuery;
  3. begin
  4.   try
  5.     MyQuery := TSQLQuery(dataset);
  6.     MyQuery.ApplyUpdates;
  7.     TSQLtransaction(TsqlQuery(Dataset).Transaction).CommitRetaining
  8.   except
  9.     showmessage('Record can not removed. Is related to another table');
  10.   end;
  11. end;                
  12.  
But when I refresh my records in dataset, my applications complains about the changes that have to applied with procedure applyupdates(). But applyUpdates() to to delete the record which is impossible by relation.

Is there a way to rollback the applyupdates() so a refresh can be done?

Application is build on lazarus 1.6.2 / FPC 3.0 Windows
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: rollback applyupdates?
« Reply #1 on: February 16, 2017, 05:04:09 pm »
This works:
Code: Pascal  [Select][+][-]
  1.     MyQuery.Close;
  2.     MyQuery.Open;
  3.  
But is this not the same as Myquery.refresh?
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

balazsszekely

  • Guest
Re: rollback applyupdates?
« Reply #2 on: February 16, 2017, 05:08:26 pm »
Use the RollbackRetaining method.
Code: Pascal  [Select][+][-]
  1. procedure TDMNAW.SQLnawAfterDelete(DataSet: TDataSet);
  2. var MyQuery : TSQLQuery;
  3. begin
  4.   try
  5.     MyQuery := TSQLQuery(dataset);
  6.     MyQuery.ApplyUpdates;
  7.     TSQLtransaction(TsqlQuery(Dataset).Transaction).CommitRetaining
  8.    except
  9.     TSQLtransaction(TsqlQuery(Dataset).Transaction).RollbackRetaining;
  10.     showmessage('Record can not removed. Is related to another table');
  11.   end;
  12. end;      
     

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: rollback applyupdates?
« Reply #3 on: February 17, 2017, 03:59:01 pm »
Getmem, I allready tried, but doesn't work. It comes with message
Quote
Must apply updates before refreshing data.
It's logical. Internally the dataprovider of SQLdb has still a flag that notice a change in the dataset. That's the problem.
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

balazsszekely

  • Guest
Re: rollback applyupdates?
« Reply #4 on: February 17, 2017, 04:19:09 pm »
Quote
Getmem, I allready tried, but doesn't work. It comes with message
Then just before RollbackRetaining do a MyQuery.Cancel or MyQuery.CancelUpdates.

kapibara

  • Hero Member
  • *****
  • Posts: 610
Re: rollback applyupdates?
« Reply #5 on: February 20, 2017, 05:53:29 pm »
Have had the same question, why you have to open/close to refresh. Now I got this idea that TSQLQuery has a property called RefreshSQL and if its empty, maybe thats why it doesn't work just calling refresh. Haven't tested, but you could try add some code to RefreshSQL and see if a plain call to Refresh works after that.

This works:
Code: Pascal  [Select][+][-]
  1.     MyQuery.Close;
  2.     MyQuery.Open;
  3.  
But is this not the same as Myquery.refresh?
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

LacaK

  • Hero Member
  • *****
  • Posts: 691
Re: rollback applyupdates?
« Reply #6 on: February 21, 2017, 06:39:31 pm »
Intention of RefreshSQL is update local buffered record after update of record has been applied to database (ukInsert or ukModify). If database table has some generated columns (as default or auto-increment or set by triggfer) then these new values are re-fetched and local record is refreshed.
RefreshSQL has no relation to TSQLQuery.Refresh but to TSQLQuery.ApplyUpdates

 

TinyPortal © 2005-2018