1
0
mirror of synced 2024-12-14 23:26:04 +03:00
doctrine2/manual/new/docs/en/transactions/savepoints.txt
jepso 5329c3827c * Converted most of the docs to the new format.
* Fixed a few layout bugs in new documentation
* Fixed documentation table of contents indentation bug in IE6 (fixes #344)
* Fixed a parser bug in Sensei_Doc_Section
* Restructrured a bit some files of the documentation.
2007-06-13 21:30:32 +00:00

51 lines
1.7 KiB
Plaintext

Doctrine supports transaction savepoints. This means you can set named transactions and have them nested.
The {{Doctrine_Transaction::beginTransaction($savepoint)}} sets a named transaction savepoint with a name of {{$savepoint}}. If the current transaction has a savepoint with the same name, the old savepoint is deleted and a new one is set.
<code type="php">
try {
$conn->beginTransaction();
// do some operations here
// creates a new savepoint called mysavepoint
$conn->beginTransaction('mysavepoint');
try {
// do some operations here
$conn->commit('mysavepoint');
} catch(Exception $e) {
$conn->rollback('mysavepoint');
}
$conn->commit();
} catch(Exception $e) {
$conn->rollback();
}
</code>
The {{Doctrine_Transaction::rollback($savepoint)}} rolls back a transaction to the named savepoint. Modifications that the current transaction made to rows after the savepoint was set are undone in the rollback.
NOTE: Mysql, for example, does not release the row locks that were stored in memory after the savepoint.
Savepoints that were set at a later time than the named savepoint are deleted.
The {{Doctrine_Transaction::commit($savepoint)}} removes the named savepoint from the set of savepoints of the current transaction.
All savepoints of the current transaction are deleted if you execute a commit or rollback is being called without savepoint name parameter.
<code type="php">
try {
$conn->beginTransaction();
// do some operations here
// creates a new savepoint called mysavepoint
$conn->beginTransaction('mysavepoint');
// do some operations here
$conn->commit(); // deletes all savepoints
} catch(Exception $e) {
$conn->rollback(); // deletes all savepoints
}
</code>