2

Is it possible to call Applyupdates on a FireDAC Query on cached updates mode without clearing its Delta ?.

The reason to do so is because I have 4 FDQuerys that I want to save together or cancel together if any of them raises on error. I could use a single transaction to rollback all changes if any problem happens, but that would leave the Delta empty for every FDQuery where its ApplyUpdates were successful.

So I would like to call some kind of ApplyUpdates that doesn't clear the Delta, and only if all the FDQuerys ApplyUpdates are successful then I would Commit the Transaction and call CommitUpdates on every FDQuery to clear their Deltas. But if one of them fails the changes of every FDQuery would still remain in their Deltas, so I Rollback the transaction and the user can still fix the data and try to save them again.

Update: As @Brian has commented, setting the property UpdateOptions.AutoCommitUpdates to False does the trick and doesn't clear the Delta.

Marc Guillot
  • 6,090
  • 1
  • 15
  • 42
  • 2
    Looks like setting AutoCommitUpdates to false will accomplish that. Docs are a bit hard to read - but it looks like clearing the delta = committing changes to the TFDCustomMemTable descendants. Looks correct since another topic says to call CommitUpdates to clear the dataset changes log. – Brian Sep 28 '20 at 14:26
  • 1
    Have you tried using [`TFDSchemaAdapter`](http://docwiki.embarcadero.com/Libraries/en/FireDAC.Comp.Client.TFDSchemaAdapter) for [Centralized Cached Updates](http://docwiki.embarcadero.com/RADStudio/en/Caching_Updates_(FireDAC))? – Peter Wolf Sep 30 '20 at 06:32
  • Yes, thanks @PeterWolf. It works very well for master-detail relationships, but in this case they are unrelated. – Marc Guillot Sep 30 '20 at 07:56
  • 1
    Yes, the example in the documentation demonstrates usage in master-detail scenario, but I think `TFDSchemaAdapter` can be used as a single point to apply updates from multiple unrelated data sets. – Peter Wolf Sep 30 '20 at 08:54

1 Answers1

2

Setting UpdateOptions.AutoCommitUpdates to false will leave the deltas alone when ApplyUpdates is called. The current help for AutoCommitUpdates is lacking however and describes the False setting incorrectly in a confusing way. It should be by more like:

AutoCommitUpdates controls the automatic committing of cached updates.

Specifies whether the automatic committing of updates is enabled or disabled.

  • If AutoCommitUpdates is True, then all the successfully updated records applied by the call to ApplyUpdates are automatically marked as unchanged. You do not need to explicitly call CommitUpdates.
  • If AutoCommitUpdates is False, then your application must explicitly call CommitUpdates to mark all changed records as unchanged.

I put in a ticket to fix the help: RSP-31141

Brian
  • 6,717
  • 2
  • 23
  • 31
  • 1
    It's also worth noting that the default value of that property seems to be False (unchecked) when in fact it's undefined, so FireDAC applies AutoCommitUpdates by default. You need to check and clear the checkbox to really set it to false. :-( – Marc Guillot Sep 28 '20 at 20:50