Chapter 5: Working with Transactions

From InterBase
Jump to: navigation, search

This chapter describes how to perform the following actions:

  • Set up a transaction parameter buffer (TPB) that contains parameters
  • Set up and initialize transaction handles
  • Use the API functions that control transactions
  • Retrieve a transaction ID

Each data definition and data manipulation in an application takes place in the context of a transaction: one or more statements that work together to complete a specific set of actions that must be treated as an atomic unit of work.

InterBase allows a connection to open more than one transaction at a time. These simultaneous transactions are independent of each other, and can conflict. Multiple concurrent transactions within a connection are useful for applications that use a database in several independent ways.

The following table summarizes the API functions most commonly used when working with transactions. Functions are listed in the order they typically appear in an application.

Table 5.1 API Transaction Functions

Function Purpose
isc_start_transaction() Starts a new transaction against one or more databases.; use a previously declared and populated TPB
isc_commit_retaining() Commits a transaction’s changes, and preserves the transaction context for further transaction processing
isc_commit_transaction() Commits a transaction’s changes, and ends the transaction
isc_rollback_transaction() Rolls back a transaction’s changes, and ends the transaction

In addition to these functions, the following table lists less frequently used API transaction functions in the order they typically appear when used:

Table 5.2 Additional API Transaction Functions

Function Purpose
isc_start_multiple() Starts a new transaction against one or more databases; used instead of isc_start_transaction() for programming languages such as FORTRAN, that do not support variable numbers of arguments to functions
isc_prepare_transaction() Performs the first phase of a two-phase commit, prior to calling isc_commit_transaction(); used to coordinate a twophase commit with some external event
isc_prepare_transaction2() Performs the first phase of a two-phase commit, prior to calling isc_commit_transaction(); used to coordinate a twophase commit with some external event. This call accepts a message describing the external event
isc_rollback_retaining() Rolls back a transaction’s changes but maintains transaction context

Topics Covered in this Chapter