[ library(dbi) | Reference Manual | Alphabetic Index ]

session_rollback(++Session)

rollback transactional changes made to the database.
Session
A session handle

Description

This undoes all transactional changes made to the database since the last commit for this session. Note some DBMS can operate non-transactionally (for example, non-transactional tables in MySQL), such operations cannot be undone. Also, even for transactions, not all changes can be undone. See DBMS's manual for details.

Outside a transaction this predicate will either succeed if rollback was successful, or raise an error otherwise.

When executed within the scope of a session_transaction/2 goal, this predicate will simply abort the complete outer transaction.

NOTE: This predicate behaves very differently, depending on whether it is in a transaction or not. It is always advisable not to rely on it succeeding, but rather to fail or abort immediately after it adopting a coding style that causes a Prolog failure whenever a transaction cannot be completed.

Exceptions

(5) type error
Session is not a valid session handle
(dbi_error)
Problems from DBMS during rollback.

Examples

    session_sql(Session, "insert into mytable values ('a')", _),
    session_commit(Session), % committing the insert of a to table mytable 
    session_sql(Session, "insert into mytable values ('b')", _),
    session_sql(Session, "insert into mytable values ('c')", _),
    % undo the inserting of b and c into table mytable (if tranactional)
    session_rollback(Session), 

See Also

session_commit / 1, session_transaction / 2