Show: Delphi C++
Display Preferences

Applying BDE-based Cached Updates

From RAD Studio
Jump to: navigation, search

Go Up to Using the BDE to cache updates Index

Note: The Borland Database Engine (BDE) has been deprecated, so it will not be enhanced. For instance, BDE will never have Unicode support. You should not undertake new development with BDE. Consider migrating your existing database applications from BDE to dbExpress.

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:

  1. A database transaction starts.
  2. 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.
  3. The transaction is committed if writes are successful or rolled back if they are not.
Write Status Transaction

Successful

Database changes are committed, ending the database transaction.Cached updates are committed, clearing the internal cache buffer (phase 2).

Unsuccessful

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.

Note: Applying cached updates is particularly tricky when you are working with multiple datasets linked in a master/detail relationship because the order in which you apply updates to each dataset is significant. Usually, you must update master tables before detail tables, except when handling deleted records, where this order must be reversed. Because of this difficulty, it is strongly recommended that you use client datasets when caching updates in a master/detail form. Client datasets automatically handle all ordering issues with master/detail relationships.

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.
Warning: To apply updates from a stored procedure or an SQL query that does not return a live result set, you must use TUpdateSQL to specify how to perform updates. For updates to joins (queries involving two or more tables), you must provide one TUpdateSQL object for each table involved, and you must use the OnUpdateRecord event handler to invoke these objects to perform the updates. See Using update objects to update a dataset for details.

See Also

Personal tools
RAD Studio 10.2 Tokyo
In other languages
Previous Versions
Assistance