Progress
Embedded SQL-92
Guide and Reference
Transaction Management Statements
When the SQL engine executes an SQL statement, it does so in the context of a transaction. A transaction defines a logical unit of work consisting of a set of database changes that must be executed completely or not at all. The execution of the first SQL executable statement in an ESQL program starts a transaction. All subsequent SQL statements are executed as part of this transaction until you explicitly terminate the transaction or execution terminates.
The primary statements that are used for transaction management are COMMIT and ROLLBACK. Use the COMMIT statement to signal the end of a transaction, and to make permanent the changes made in the database for that transaction. After a COMMIT or ROLLBACK, the first execution of an SQL statement starts a new transaction.
The successful termination of a transaction occurs with the execution of a COMMIT statement. In contrast, the ROLLBACK statement means abnormal termination of a transaction. If a transaction executes the ROLLBACK statement, all changes made to the database in that transaction are canceled.
Good programming practice places the evaluation of the SQLCA in a subroutine, which the program invokes after the execution of an SQL statement or transaction. Fetch operations with SELECT statements require a different subroutine, for evaluation of the SQL_NOT_FOUND condition.
EXAMPLEThis code fragment shows an UPDATE transaction in an ESQL statement. After executing the INSERT, the program logic examines the SQLCA to determine if the operation succeeded or failed. The program issues the appropriate COMMIT or ROLLBACK statement:
NOTE: For more information on transaction management statements see Transaction Management in ESQL-92."
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |