Unverified Commit a9b7bf85 authored by Konstantin Kalinin's avatar Konstantin Kalinin Committed by Sergei Morozov

Reset transaction nesting level on connection loss.

When the connection is lost or is closed, subsequent transaction will no longer be nested because they started in a brand new session. Our internal representation of the nesting shold take this into account
parent a2bfa40b
...@@ -356,6 +356,8 @@ class Connection implements DriverConnection ...@@ -356,6 +356,8 @@ class Connection implements DriverConnection
$this->_conn = $this->_driver->connect($this->params, $user, $password, $driverOptions); $this->_conn = $this->_driver->connect($this->params, $user, $password, $driverOptions);
$this->isConnected = true; $this->isConnected = true;
$this->transactionNestingLevel = 0;
if ($this->autoCommit === false) { if ($this->autoCommit === false) {
$this->beginTransaction(); $this->beginTransaction();
} }
......
...@@ -69,6 +69,40 @@ class ConnectionTest extends DbalFunctionalTestCase ...@@ -69,6 +69,40 @@ class ConnectionTest extends DbalFunctionalTestCase
$this->connection->rollBack(); $this->connection->rollBack();
self::assertEquals(0, $this->connection->getTransactionNestingLevel()); self::assertEquals(0, $this->connection->getTransactionNestingLevel());
} }
$this->connection->beginTransaction();
$this->connection->close();
$this->connection->beginTransaction();
self::assertEquals(1, $this->connection->getTransactionNestingLevel());
}
public function testTransactionNestingLevelIsResetOnReconnect() : void
{
if ($this->connection->getDatabasePlatform()->getName() === 'sqlite') {
$params = $this->connection->getParams();
$params['memory'] = false;
$params['path'] = '/tmp/test_nesting.sqlite';
$connection = DriverManager::getConnection(
$params,
$this->connection->getConfiguration(),
$this->connection->getEventManager()
);
} else {
$connection = $this->connection;
}
$connection->executeQuery('CREATE TABLE test_nesting(test int not null)');
$this->connection->beginTransaction();
$this->connection->beginTransaction();
$connection->close(); // connection closed in runtime (for example if lost or another application logic)
$connection->beginTransaction();
$connection->executeQuery('insert into test_nesting values (33)');
$connection->rollback();
self::assertEquals(0, $connection->fetchColumn('select count(*) from test_nesting'));
} }
public function testTransactionNestingBehaviorWithSavepoints() public function testTransactionNestingBehaviorWithSavepoints()
......
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