SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Transaction Management
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
14-8
Committing Database Changes if No Errors Occur
However, the diagnostics area provides more information than the SQLSTATE variable
because condition information is stored for each exception condition that occurs during
execution of an SQL statement.
Committing Database Changes if No Errors Occur
The COMMIT WORK statement permanently commits changes made to the database
within the current transaction and ends the transaction. It frees resources held by the
transaction, such as row or table locks.
EXEC SQL COMMIT WORK;
If the program changes the database, either issue a COMMIT WORK statement at the
end of your transaction or turn on autocommit. If you quit a program without committing
a transaction, database changes are automatically rolled back.
For the syntax of the COMMIT WORK statement, see the SQL/MX Reference Manual.
Undoing Database Changes if an Error Occurs
The ROLLBACK WORK statement undoes changes made to the database within the
current transaction and ends the transaction. It frees resources held by the transaction,
such as row or table locks.
EXEC SQL ROLLBACK WORK;
For the syntax of the ROLLBACK WORK statement and more information on
transaction management, see the SQL/MX Reference Manual.
Note. The results of executing an SQL statement overlay the results of the previous SQL
statement in the diagnostics area. Therefore, test for exception conditions after the execution
of each statement within your transaction.