Unverified Commit 80122862 authored by Sergei Morozov's avatar Sergei Morozov Committed by GitHub

Merge pull request #3679 from kalinin-k-a/fix_begin_transaction_after_reconnect

fix begin trasaction after reconnect
parents 7241a651 b5508798
...@@ -354,6 +354,8 @@ class Connection implements DriverConnection ...@@ -354,6 +354,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();
} }
......
...@@ -70,6 +70,40 @@ class ConnectionTest extends DbalFunctionalTestCase ...@@ -70,6 +70,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() : void public function testTransactionNestingBehaviorWithSavepoints() : void
......
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