Applying BDE-based Cached Updates
Go Up to Using the BDE to cache updates Index
Applying updates is a two-phase process that should occur in the context of a database component's transaction so that your application can recover gracefully from errors. For information about transaction handling with database components, see Managing Transactions.
When applying updates under database transaction control, the following events take place:
- A database transaction starts.
- Cached updates are written to the database (phase 1). If you provide it, an OnUpdateRecord event is triggered once for each record written to the database. If an error occurs when a record is applied to the database, the OnUpdateError event is triggered if you provide one.
- The transaction is committed if writes are successful or rolled back if they are not.
Database changes are committed, ending the database transaction.Cached updates are committed, clearing the internal cache buffer (phase 2).
Database changes are rolled back, ending the database transaction.Cached updates are not committed, remaining intact in the internal cache.
For information about creating and using an OnUpdateRecord event handler, see Handling Cached Update errors.
There are two ways to apply BDE-based updates:
- You can apply updates using a database component by calling its ApplyUpdates method. This method is the simplest approach, because the database handles all details of managing a transaction for the update process and of clearing the dataset's cache when updating is complete.
- You can apply updates for a single dataset by calling the dataset's ApplyUpdates and CommitUpdates methods. When applying updates at the dataset level, you must explicitly code the transaction that wraps the update process as well as explicitly call CommitUpdates to commit updates from the cache.