HPlogo ALLBASE/SQL Pascal Application Programming Guide: HP 9000 Computer Systems > Chapter 3 Embedding SQL Commands

Defining Transactions

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

You define transactions in an executable section to control what changes are committed to a DBEnvironment and when they are 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 within the transaction are permanent in the DBEnvironment. When a ROLLBACK WORK command is executed, none of the changes remain in the DBEnvironment.

The number and duration of transactions in an application program depend on the following factors:

  • 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.

For detailed information regarding transaction management, see the document, "Performance Guidelines".

The commands at 4 and 5 in Figure 3-1 start and end a transaction that consists of a single execution of the SELECT command in procedure SelectData.

The BEGIN WORK command in procedure 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. However, such an implicit BEGIN WORK always has the default isolation level of Repeatable Read (RR). If you need to increase concurrency with a different isolation level, use an explicit BEGIN WORK command.

The COMMIT WORK command in procedure 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