#include <Pt/Db/Transaction.h>
Unit of work on a database connection. More...
Inherits NonCopyable.
Inherited by SqliteTransaction.
Public Member Functions | |
| Transaction (Connection &conn, bool starttransaction=true) | |
| Creates a transaction on conn. | |
| ~Transaction () | |
| Rolls back an active transaction and destroys the object. | |
| const Connection & | getConnection () const |
| Returns the connection this transaction uses. | |
| void | begin () |
| Begins a deferred transaction. | |
| void | commit () |
| Commits the active transaction. | |
| void | rollback () |
| Rolls back the active transaction. | |
| void | beginStart () |
| Starts an asynchronous begin-transaction. | |
| void | endStart () |
| Completes an asynchronous begin-transaction. | |
| Pt::Signal & | startFinished () |
| Signal emitted when an asynchronous begin completes. | |
| void | beginCommit () |
| Starts an asynchronous commit. | |
| void | endCommit () |
| Completes an asynchronous commit. | |
| Pt::Signal & | commitFinished () |
| Signal emitted when an asynchronous commit completes. | |
| void | beginRollback () |
| Starts an asynchronous rollback. | |
| void | endRollback () |
| Completes an asynchronous rollback. | |
| Pt::Signal & | rollbackFinished () |
| Signal emitted when an asynchronous rollback completes. | |
Transaction is the unit of work the group described. The constructor begins a deferred transaction unless starttransaction is false. The object is not copyable and does not own the connection.
begin() starts a transaction; if one is already active it is rolled back first. commit() keeps the changes. rollback() discards them. If the object is destroyed while still active, the destructor rolls back and swallows any error from that rollback.
Asynchronous begin, commit and rollback need setActive() on the connection. beginStart() / endStart() / startFinished() begin the transaction; endStart() is the call that marks it active. beginCommit() / endCommit() / commitFinished() commit. beginRollback() / endRollback() / rollbackFinished() roll back.
Override onGetBeginSql(), onGetCommitSql() and onGetRollbackSql() to supply backend-specific SQL. A null return lets the backend use its default.
| Transaction | ( | Connection & | conn, |
| bool | starttransaction = true ) |
Begins the transaction unless starttransaction is false.
| void begin | ( | ) |
Rolls back an already active transaction first.
| void commit | ( | ) |
Does nothing if no transaction is active.
| void rollback | ( | ) |
Does nothing if no transaction is active.