Commit b2f10894 authored by Lukas Kahwe Smith's avatar Lukas Kahwe Smith Committed by Juozas Kaziukenas

prevent changing savepoint behavior inside an open transaction

parent 55c630a8
......@@ -754,6 +754,10 @@ class Connection implements DriverConnection
*/
public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints)
{
if ($this->_transactionNestingLevel > 0) {
throw ConnectionException::mayNotAlterNestedTransactionWithSavepointsInTransaction();
}
if ($nestTransactionsWithSavepoints && !$this->_platform->supportsSavepoints()) {
ConnectionException::savepointsNotSupported();
}
......
......@@ -46,4 +46,9 @@ class ConnectionException extends DBALException
{
return new self("Savepoints are not supported transaction.");
}
public static function mayNotAlterNestedTransactionWithSavepointsInTransaction()
{
return new self("May not alter the nested transaction with savepoints behavior while a transaction is open.");
}
}
\ No newline at end of file
......@@ -77,6 +77,12 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
//no rethrow
}
$this->assertFalse($this->_conn->isRollbackOnly());
try {
$this->_conn->setNestTransactionsWithSavepoints(false);
$this->fail('Should not be able to disable savepoints in usage for nested transactions inside an open transaction.');
} catch (ConnectionException $e) {
$this->assertTrue($this->_conn->getNestTransactionsWithSavepoints());
}
$this->_conn->commit(); // should not throw exception
} catch (ConnectionException $e) {
$this->fail('Transaction commit after failed nested transaction should not fail when using savepoints.');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment