HPlogo ALLBASE/SQL FORTRAN Application Programming Guide: HP 3000 MPE/iX Computer Systems > Chapter 3 Embedding SQL Commands

Defining Transactions

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

You define transactions in a program unit to control what changes get committed to a DBEnvironment and when they get committed.

A transaction consists of all the SQL commands that are executed between a BEGIN WORK command and either a COMMIT WORK command or a ROLLBACK WORK command. When a COMMIT WORK command is successfully executed, all operations performed by the transaction it ends have a permanent effect on the DBEnvironment. The opposite is true for a ROLLBACK WORK command; no operations performed by the transaction it ends have a permanent effect on the DBEnvironment.

The number and duration of transactions in an application program depend on such factors as:

  • Concurrency: Concurrent DBE sessions may compete for data and index locks and buffers.

  • Update activities: Applications that are update-intensive should issue COMMIT WORK commands more frequently to avoid data re-entry in the event of a failure.

  • Data consistency: Program changes to a table that are meaningful only if changes are made to another table should be committed or undone at the same time to ensure the data remains consistent.

The commands at 4 and 5 in subroutines BeginTransaction and EndTransaction in Figure 3-1 start and end a transaction that consists of a single execution of the SELECT command at 8 in subroutine QueryTable.

The BEGIN WORK command in subprogram unit BeginTransaction is optional but recommended. If you omit a BEGIN WORK command, ALLBASE/SQL automatically issues a BEGIN WORK on your behalf before executing the first SQL command that requires that a transaction be in progress.

The COMMIT WORK command in subprogram unit EndTransaction terminates the transaction after each execution of the SELECT command. Because the program does no DBEnvironment updates, this command is used to terminate the transaction even if an error is encountered. In programs that update data in a DBEnvironment, a ROLLBACK WORK command could be used to undo the effects of any database changes that occurred during a transaction before the error occurred.

Feedback to webmaster