views:

137

answers:

1

The Delphi XE dbExpress tutorial in the online documentation uses ApplyUpdates(-1):

  // Client data set has provider do update.
  ClientDataSet1.ApplyUpdates(-1);

Some online sources however say it would have advantages to use ApplyUpdates(0), and it would be a widespread mistake or bad practice to use -1. Is this true? And when and why should I prefer 0 over -1 as the value for MaxErrors?

+7  A: 

-1 Allows for unlimited errors to be reported, so every update in the ClientDataSet's delta will be tried.

0 Allows for no errors at all, which means that no effort is wasted on trying updates after a first failure.

-1 could be appropriate if you have many unrelated changes to pump through to the database. For example when pumping back changes from off-line use in the briefcase model. In this type of scenario, updates may fail because records have in the mean time been updated by other users, but having one update fail will say little or nothing about the chances of the other updates failing. It would then probably be more convenient to let every update be tried and receive back a report of the ones that failed so they can be addressed by the user.

0 probably is better suited in situations where it is fairly predictable that if one update fails, all or many of the other updates in the delta will also fail. It would be "foolhardy" to have the ClientDataSet try the other updates when the likelyhood of them failing as well is high. Must admit though that I have a hard time thinking up a scenario in which this would be the case.

Marjan Venema
Thanks for the detailed answer! One thing comes back to mind while I am reading it: iirc there is also a difference in 'rollback', while 0 will not commit any changes to the database so that the client can be sure nothing bad happened with the database, -1 will commit 'as much as possible' - or something like that. (I am still searching for the online resources which contained a better description for this difference.)
mjustin
@mjustin: -1 committing as much as possible is a fairly safe bet. 0 not committing anything upon failure I am less sure about, but it is what I would expect... :)
Marjan Venema