Applying Cached Updates with a Dataset Component Methods

From InterBase

Go Up to Applying Cached Updates


You can apply updates for individual datasets directly using the dataset’s ApplyUpdates method. Applying updates at the dataset level gives you control over the order in which updates are applied to individual datasets. Order of update application is especially critical for handling master/detail relationships. To ensure the correct ordering of updates for master/detail tables, you should always apply updates at the dataset level. For more information see Applying Updates for Master/detail Tables.

The following code illustrates how you apply updates within a transaction for the CustomerQuery dataset previously used to illustrate updates through a database method:

IBTransaction1.StartTransaction;
try
  CustomerQuery.ApplyUpdates; {try to write the updates to the database }
  IBTransaction1.Commit; { on success, commit the changes }
except
  IBTransaction1.Rollback; { on failure, undo any changes }
  raise;
end;

If an exception is raised during the ApplyUpdates call, the database transaction is rolled back. Rolling back the transaction ensures that the underlying database table is not changed. The raise statement inside the try...except block re-raises the exception, thereby preventing the call to CommitUpdates. Because CommitUpdates is not called, the internal cache of updates is not cleared so that you can handle error conditions and possibly retry the update.

Advance To: