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 ...@@ -754,6 +754,10 @@ class Connection implements DriverConnection
*/ */
public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints) public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints)
{ {
if ($this->_transactionNestingLevel > 0) {
throw ConnectionException::mayNotAlterNestedTransactionWithSavepointsInTransaction();
}
if ($nestTransactionsWithSavepoints && !$this->_platform->supportsSavepoints()) { if ($nestTransactionsWithSavepoints && !$this->_platform->supportsSavepoints()) {
ConnectionException::savepointsNotSupported(); ConnectionException::savepointsNotSupported();
} }
......
...@@ -46,4 +46,9 @@ class ConnectionException extends DBALException ...@@ -46,4 +46,9 @@ class ConnectionException extends DBALException
{ {
return new self("Savepoints are not supported transaction."); 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 ...@@ -77,6 +77,12 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
//no rethrow //no rethrow
} }
$this->assertFalse($this->_conn->isRollbackOnly()); $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 $this->_conn->commit(); // should not throw exception
} catch (ConnectionException $e) { } catch (ConnectionException $e) {
$this->fail('Transaction commit after failed nested transaction should not fail when using savepoints.'); $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