Database Independent Abstraction Layer for C: libdbi Programmer's Guide
Prev | Chapter 5. Transactions and Savepoints | Next

# 5.2. Savepoints

Most database engines which support transactions also support the concept of savepoints. To find out at runtime whether or not the driver associated with the current connection supports savepoints, use the function dbi_conn_cap_get to query if the "savepoint_support" capability is nonzero. Savepoints are essentially named markers within a transaction where you can jump back in case of an error. In this case, all commands that were issued after the savepoint are dismissed. The changes caused by the commands after a savepoint are committed as soon as the entire transaction is committed. Usually several markers may be used at a time within the same transaction. libdbi provides the following commands to manage savepoints:

Set a savepoint

  To set a named savepoint within a transaction, use the function dbi_conn_savepoint. You need to keep track of the name of savepoints in order to be able to revert the changes.

Rollback to a savepoint

  To dismiss any changes during an open transaction which occurred after a particular savepoint, use the function dbi_conn_rollback_to_savepoint.

Release a savepoint

  Some database engines allow to clear savepoints if they are no longer needed. This is important only within lengthy transactions as savepoints are automatically cleared when a transaction is committed or rolled back. Releasing a savepoint does not affect the commands that occurred after the savepoint was set. It merely makes it impossible to jump back to that savepoint and releases all system resources which were needed to maintain that savepoint. To release a savepoint, use the command dbi_conn_release_savepoint.

Prev | Home | Next
Transactions | Up | Library and Interface Versions