Skip to content

Commit

Permalink
Merge branch 'bpo/2.9/#3679' into 2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Oct 14, 2019
2 parents a2bfa40 + a9b7bf8 commit 24170d3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ public function connect()
$this->_conn = $this->_driver->connect($this->params, $user, $password, $driverOptions);
$this->isConnected = true;

$this->transactionNestingLevel = 0;

if ($this->autoCommit === false) {
$this->beginTransaction();
}
Expand Down
34 changes: 34 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,40 @@ public function testTransactionNestingBehavior()
$this->connection->rollBack();
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()
Expand Down

0 comments on commit 24170d3

Please sign in to comment.