3.8.1. The Read-only Transaction

The trRead read transaction is started when the dataset form is displayed (the OnActivate event) and is ended when the form is closed. READ COMMITTED isolation level (Options.Isolation = xiReadCommitted) is usually used to show data in grids because it allows the transaction to see changes committed in the database by other users by just repeating queries (rereading data) without the transaction being restarted.

Since this transaction is used only to read data, we set the Options.ReadOnly property to True. Thus, our transaction will have the following parameters: read read_committed rec_version.

Why?

A transaction with exactly these parameters can remain open in Firebird as long as necessary (days, weeks, months) without locking other transactions or affecting the accumulation of garbage in the database because, with these parameters, a transaction is started on the server as committed.

We set the property Options.DisconnectAction to xdCommit, which perfectly fits a read-only transaction. Finally, the read transaction will have the following properties:

  1. Options.AutoStart = False
  2. Options.AutoCommit = False
  3. Options.AutoStop = False
  4. Options.DisconnectAction = xdCommit
  5. Options.Isolations = xiReadCommitted
  6. Options.ReadOnly = True

Although we do not discuss reporting in this manual, be aware that you should not use such a transaction for reports, especially if they use several queries in sequence. A transaction with READ COMMITTED isolation will see all new committed changes when rereading data. The recommended configuration for reports is a short read-only transaction with SNAPSHOT isolation (Options.Isolation = xiSnapshot and Options.ReadOnly= True).