* * *

Author Topic: rollback applyupdates?  (Read 496 times)

mangakissa

  • Hero Member
  • *****
  • Posts: 645
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 1.6 (32b) / FPC 3.0
Windows Vista /  10

mangakissa

  • Hero Member
  • *****
  • Posts: 645
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 1.6 (32b) / FPC 3.0
Windows Vista /  10

GetMem

  • Hero Member
  • *****
  • Posts: 1946
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: 645
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 1.6 (32b) / FPC 3.0
Windows Vista /  10

GetMem

  • Hero Member
  • *****
  • Posts: 1946
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

  • Sr. Member
  • ****
  • Posts: 430
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.0 / Debian Stretch 64-bit

LacaK

  • Hero Member
  • *****
  • Posts: 523
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

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus