Commit 65de5221 authored by Benjamin Nolan's avatar Benjamin Nolan

Merge branch 'master' of https://github.com/doctrine/dbal into hotfix-2313-infinite-loop

parents 5ecab7c5 7dd848b7
...@@ -48,4 +48,4 @@ object is closed: ...@@ -48,4 +48,4 @@ object is closed:
.. warning:: .. warning::
When using the cache layer not all fetch modes are supported. See the code of the `ResultCacheStatement <https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php#L156>`_ for details. When using the cache layer not all fetch modes are supported. See the code of the `ResultCacheStatement <https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php>`_ for details.
...@@ -32,6 +32,7 @@ use Doctrine\DBAL\Cache\QueryCacheProfile; ...@@ -32,6 +32,7 @@ use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\Cache\ArrayStatement; use Doctrine\DBAL\Cache\ArrayStatement;
use Doctrine\DBAL\Cache\CacheException; use Doctrine\DBAL\Cache\CacheException;
use Doctrine\DBAL\Driver\PingableConnection; use Doctrine\DBAL\Driver\PingableConnection;
use Throwable;
/** /**
* A wrapper around a Doctrine\DBAL\Driver\Connection that adds features like * A wrapper around a Doctrine\DBAL\Driver\Connection that adds features like
...@@ -773,7 +774,7 @@ class Connection implements DriverConnection ...@@ -773,7 +774,7 @@ class Connection implements DriverConnection
{ {
try { try {
$stmt = new Statement($statement, $this); $stmt = new Statement($statement, $this);
} catch (\Exception $ex) { } catch (Exception $ex) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $statement); throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $statement);
} }
...@@ -824,7 +825,7 @@ class Connection implements DriverConnection ...@@ -824,7 +825,7 @@ class Connection implements DriverConnection
} else { } else {
$stmt = $this->_conn->query($query); $stmt = $this->_conn->query($query);
} }
} catch (\Exception $ex) { } catch (Exception $ex) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $query, $this->resolveParams($params, $types)); throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $query, $this->resolveParams($params, $types));
} }
...@@ -933,7 +934,7 @@ class Connection implements DriverConnection ...@@ -933,7 +934,7 @@ class Connection implements DriverConnection
$statement = call_user_func_array(array($this->_conn, 'query'), $args); $statement = call_user_func_array(array($this->_conn, 'query'), $args);
break; break;
} }
} catch (\Exception $ex) { } catch (Exception $ex) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $args[0]); throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $args[0]);
} }
...@@ -984,7 +985,7 @@ class Connection implements DriverConnection ...@@ -984,7 +985,7 @@ class Connection implements DriverConnection
} else { } else {
$result = $this->_conn->exec($query); $result = $this->_conn->exec($query);
} }
} catch (\Exception $ex) { } catch (Exception $ex) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $query, $this->resolveParams($params, $types)); throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $query, $this->resolveParams($params, $types));
} }
...@@ -1015,7 +1016,7 @@ class Connection implements DriverConnection ...@@ -1015,7 +1016,7 @@ class Connection implements DriverConnection
try { try {
$result = $this->_conn->exec($statement); $result = $this->_conn->exec($statement);
} catch (\Exception $ex) { } catch (Exception $ex) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $statement); throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $statement);
} }
...@@ -1103,6 +1104,9 @@ class Connection implements DriverConnection ...@@ -1103,6 +1104,9 @@ class Connection implements DriverConnection
} catch (Exception $e) { } catch (Exception $e) {
$this->rollBack(); $this->rollBack();
throw $e; throw $e;
} catch (Throwable $e) {
$this->rollBack();
throw $e;
} }
} }
......
...@@ -214,7 +214,7 @@ class DBALException extends \Exception ...@@ -214,7 +214,7 @@ class DBALException extends \Exception
*/ */
public static function limitOffsetInvalid() public static function limitOffsetInvalid()
{ {
return new self("Invalid Offset in Limit Query, it has to be larger or equal to 0."); return new self("Invalid Offset in Limit Query, it has to be larger than or equal to 0.");
} }
/** /**
...@@ -237,7 +237,7 @@ class DBALException extends \Exception ...@@ -237,7 +237,7 @@ class DBALException extends \Exception
return new self('Unknown column type "'.$name.'" requested. Any Doctrine type that you use has ' . return new self('Unknown column type "'.$name.'" requested. Any Doctrine type that you use has ' .
'to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the ' . 'to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the ' .
'known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database ' . 'known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database ' .
'introspection then you might have forgot to register all database types for a Doctrine Type. Use ' . 'introspection then you might have forgotten to register all database types for a Doctrine Type. Use ' .
'AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement ' . 'AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement ' .
'Type#getMappedDatabaseTypes(). If the type name is empty you might ' . 'Type#getMappedDatabaseTypes(). If the type name is empty you might ' .
'have a problem with the cache or forgot some mapping information.' 'have a problem with the cache or forgot some mapping information.'
......
...@@ -266,7 +266,7 @@ class QueryBuilder ...@@ -266,7 +266,7 @@ class QueryBuilder
* @param mixed $value The parameter value. * @param mixed $value The parameter value.
* @param string|null $type One of the PDO::PARAM_* constants. * @param string|null $type One of the PDO::PARAM_* constants.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function setParameter($key, $value, $type = null) public function setParameter($key, $value, $type = null)
{ {
...@@ -296,7 +296,7 @@ class QueryBuilder ...@@ -296,7 +296,7 @@ class QueryBuilder
* @param array $params The query parameters to set. * @param array $params The query parameters to set.
* @param array $types The query parameters types to set. * @param array $types The query parameters types to set.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function setParameters(array $params, array $types = array()) public function setParameters(array $params, array $types = array())
{ {
...@@ -355,7 +355,7 @@ class QueryBuilder ...@@ -355,7 +355,7 @@ class QueryBuilder
* *
* @param integer $firstResult The first result to return. * @param integer $firstResult The first result to return.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function setFirstResult($firstResult) public function setFirstResult($firstResult)
{ {
...@@ -381,7 +381,7 @@ class QueryBuilder ...@@ -381,7 +381,7 @@ class QueryBuilder
* *
* @param integer $maxResults The maximum number of results to retrieve. * @param integer $maxResults The maximum number of results to retrieve.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function setMaxResults($maxResults) public function setMaxResults($maxResults)
{ {
...@@ -412,7 +412,7 @@ class QueryBuilder ...@@ -412,7 +412,7 @@ class QueryBuilder
* @param string $sqlPart * @param string $sqlPart
* @param boolean $append * @param boolean $append
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function add($sqlPartName, $sqlPart, $append = false) public function add($sqlPartName, $sqlPart, $append = false)
{ {
...@@ -460,7 +460,7 @@ class QueryBuilder ...@@ -460,7 +460,7 @@ class QueryBuilder
* *
* @param mixed $select The selection expressions. * @param mixed $select The selection expressions.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function select($select = null) public function select($select = null)
{ {
...@@ -488,7 +488,7 @@ class QueryBuilder ...@@ -488,7 +488,7 @@ class QueryBuilder
* *
* @param mixed $select The selection expression. * @param mixed $select The selection expression.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function addSelect($select = null) public function addSelect($select = null)
{ {
...@@ -517,7 +517,7 @@ class QueryBuilder ...@@ -517,7 +517,7 @@ class QueryBuilder
* @param string $delete The table whose rows are subject to the deletion. * @param string $delete The table whose rows are subject to the deletion.
* @param string $alias The table alias used in the constructed query. * @param string $alias The table alias used in the constructed query.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function delete($delete = null, $alias = null) public function delete($delete = null, $alias = null)
{ {
...@@ -547,7 +547,7 @@ class QueryBuilder ...@@ -547,7 +547,7 @@ class QueryBuilder
* @param string $update The table whose rows are subject to the update. * @param string $update The table whose rows are subject to the update.
* @param string $alias The table alias used in the constructed query. * @param string $alias The table alias used in the constructed query.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function update($update = null, $alias = null) public function update($update = null, $alias = null)
{ {
...@@ -580,7 +580,7 @@ class QueryBuilder ...@@ -580,7 +580,7 @@ class QueryBuilder
* *
* @param string $insert The table into which the rows should be inserted. * @param string $insert The table into which the rows should be inserted.
* *
* @return QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function insert($insert = null) public function insert($insert = null)
{ {
...@@ -608,7 +608,7 @@ class QueryBuilder ...@@ -608,7 +608,7 @@ class QueryBuilder
* @param string $from The table. * @param string $from The table.
* @param string|null $alias The alias of the table. * @param string|null $alias The alias of the table.
* *
* @return QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function from($from, $alias = null) public function from($from, $alias = null)
{ {
...@@ -633,7 +633,7 @@ class QueryBuilder ...@@ -633,7 +633,7 @@ class QueryBuilder
* @param string $alias The alias of the join table. * @param string $alias The alias of the join table.
* @param string $condition The condition for the join. * @param string $condition The condition for the join.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function join($fromAlias, $join, $alias, $condition = null) public function join($fromAlias, $join, $alias, $condition = null)
{ {
...@@ -655,7 +655,7 @@ class QueryBuilder ...@@ -655,7 +655,7 @@ class QueryBuilder
* @param string $alias The alias of the join table. * @param string $alias The alias of the join table.
* @param string $condition The condition for the join. * @param string $condition The condition for the join.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function innerJoin($fromAlias, $join, $alias, $condition = null) public function innerJoin($fromAlias, $join, $alias, $condition = null)
{ {
...@@ -684,7 +684,7 @@ class QueryBuilder ...@@ -684,7 +684,7 @@ class QueryBuilder
* @param string $alias The alias of the join table. * @param string $alias The alias of the join table.
* @param string $condition The condition for the join. * @param string $condition The condition for the join.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function leftJoin($fromAlias, $join, $alias, $condition = null) public function leftJoin($fromAlias, $join, $alias, $condition = null)
{ {
...@@ -713,7 +713,7 @@ class QueryBuilder ...@@ -713,7 +713,7 @@ class QueryBuilder
* @param string $alias The alias of the join table. * @param string $alias The alias of the join table.
* @param string $condition The condition for the join. * @param string $condition The condition for the join.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function rightJoin($fromAlias, $join, $alias, $condition = null) public function rightJoin($fromAlias, $join, $alias, $condition = null)
{ {
...@@ -740,7 +740,7 @@ class QueryBuilder ...@@ -740,7 +740,7 @@ class QueryBuilder
* @param string $key The column to set. * @param string $key The column to set.
* @param string $value The value, expression, placeholder, etc. * @param string $value The value, expression, placeholder, etc.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function set($key, $value) public function set($key, $value)
{ {
...@@ -771,7 +771,7 @@ class QueryBuilder ...@@ -771,7 +771,7 @@ class QueryBuilder
* *
* @param mixed $predicates The restriction predicates. * @param mixed $predicates The restriction predicates.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function where($predicates) public function where($predicates)
{ {
...@@ -796,7 +796,7 @@ class QueryBuilder ...@@ -796,7 +796,7 @@ class QueryBuilder
* *
* @param mixed $where The query restrictions. * @param mixed $where The query restrictions.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
* *
* @see where() * @see where()
*/ */
...@@ -829,7 +829,7 @@ class QueryBuilder ...@@ -829,7 +829,7 @@ class QueryBuilder
* *
* @param mixed $where The WHERE statement. * @param mixed $where The WHERE statement.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
* *
* @see where() * @see where()
*/ */
...@@ -861,7 +861,7 @@ class QueryBuilder ...@@ -861,7 +861,7 @@ class QueryBuilder
* *
* @param mixed $groupBy The grouping expression. * @param mixed $groupBy The grouping expression.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function groupBy($groupBy) public function groupBy($groupBy)
{ {
...@@ -888,7 +888,7 @@ class QueryBuilder ...@@ -888,7 +888,7 @@ class QueryBuilder
* *
* @param mixed $groupBy The grouping expression. * @param mixed $groupBy The grouping expression.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function addGroupBy($groupBy) public function addGroupBy($groupBy)
{ {
...@@ -918,7 +918,7 @@ class QueryBuilder ...@@ -918,7 +918,7 @@ class QueryBuilder
* @param string $column The column into which the value should be inserted. * @param string $column The column into which the value should be inserted.
* @param string $value The value that should be inserted into the column. * @param string $value The value that should be inserted into the column.
* *
* @return QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function setValue($column, $value) public function setValue($column, $value)
{ {
...@@ -944,7 +944,7 @@ class QueryBuilder ...@@ -944,7 +944,7 @@ class QueryBuilder
* *
* @param array $values The values to specify for the insert query indexed by column names. * @param array $values The values to specify for the insert query indexed by column names.
* *
* @return QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function values(array $values) public function values(array $values)
{ {
...@@ -957,7 +957,7 @@ class QueryBuilder ...@@ -957,7 +957,7 @@ class QueryBuilder
* *
* @param mixed $having The restriction over the groups. * @param mixed $having The restriction over the groups.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function having($having) public function having($having)
{ {
...@@ -974,7 +974,7 @@ class QueryBuilder ...@@ -974,7 +974,7 @@ class QueryBuilder
* *
* @param mixed $having The restriction to append. * @param mixed $having The restriction to append.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function andHaving($having) public function andHaving($having)
{ {
...@@ -997,7 +997,7 @@ class QueryBuilder ...@@ -997,7 +997,7 @@ class QueryBuilder
* *
* @param mixed $having The restriction to add. * @param mixed $having The restriction to add.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function orHaving($having) public function orHaving($having)
{ {
...@@ -1021,7 +1021,7 @@ class QueryBuilder ...@@ -1021,7 +1021,7 @@ class QueryBuilder
* @param string $sort The ordering expression. * @param string $sort The ordering expression.
* @param string $order The ordering direction. * @param string $order The ordering direction.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function orderBy($sort, $order = null) public function orderBy($sort, $order = null)
{ {
...@@ -1034,7 +1034,7 @@ class QueryBuilder ...@@ -1034,7 +1034,7 @@ class QueryBuilder
* @param string $sort The ordering expression. * @param string $sort The ordering expression.
* @param string $order The ordering direction. * @param string $order The ordering direction.
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function addOrderBy($sort, $order = null) public function addOrderBy($sort, $order = null)
{ {
...@@ -1068,7 +1068,7 @@ class QueryBuilder ...@@ -1068,7 +1068,7 @@ class QueryBuilder
* *
* @param array|null $queryPartNames * @param array|null $queryPartNames
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function resetQueryParts($queryPartNames = null) public function resetQueryParts($queryPartNames = null)
{ {
...@@ -1088,7 +1088,7 @@ class QueryBuilder ...@@ -1088,7 +1088,7 @@ class QueryBuilder
* *
* @param string $queryPartName * @param string $queryPartName
* *
* @return \Doctrine\DBAL\Query\QueryBuilder This QueryBuilder instance. * @return $this This QueryBuilder instance.
*/ */
public function resetQueryPart($queryPartName) public function resetQueryPart($queryPartName)
{ {
......
...@@ -87,7 +87,7 @@ and SQL Anywhere keywords are checked: ...@@ -87,7 +87,7 @@ and SQL Anywhere keywords are checked:
If you want to check against specific dialects you can If you want to check against specific dialects you can
pass them to the command: pass them to the command:
<info>%command.full_name% mysql pgsql</info> <info>%command.full_name% -l mysql -l pgsql</info>
The following keyword lists are currently shipped with Doctrine: The following keyword lists are currently shipped with Doctrine:
......
...@@ -48,7 +48,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase ...@@ -48,7 +48,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalTestCase
public function testRollbackWithNoActiveTransaction_ThrowsException() public function testRollbackWithNoActiveTransaction_ThrowsException()
{ {
$this->setExpectedException('Doctrine\DBAL\ConnectionException'); $this->setExpectedException('Doctrine\DBAL\ConnectionException');
$this->_conn->rollback(); $this->_conn->rollBack();
} }
public function testSetRollbackOnlyNoActiveTransaction_ThrowsException() public function testSetRollbackOnlyNoActiveTransaction_ThrowsException()
......
...@@ -45,7 +45,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -45,7 +45,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
throw new \Exception; throw new \Exception;
$this->_conn->commit(); // never reached $this->_conn->commit(); // never reached
} catch (\Exception $e) { } catch (\Exception $e) {
$this->_conn->rollback(); $this->_conn->rollBack();
$this->assertEquals(1, $this->_conn->getTransactionNestingLevel()); $this->assertEquals(1, $this->_conn->getTransactionNestingLevel());
//no rethrow //no rethrow
} }
...@@ -55,7 +55,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -55,7 +55,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->fail('Transaction commit after failed nested transaction should fail.'); $this->fail('Transaction commit after failed nested transaction should fail.');
} catch (ConnectionException $e) { } catch (ConnectionException $e) {
$this->assertEquals(1, $this->_conn->getTransactionNestingLevel()); $this->assertEquals(1, $this->_conn->getTransactionNestingLevel());
$this->_conn->rollback(); $this->_conn->rollBack();
$this->assertEquals(0, $this->_conn->getTransactionNestingLevel()); $this->assertEquals(0, $this->_conn->getTransactionNestingLevel());
} }
} }
...@@ -81,7 +81,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -81,7 +81,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
throw new \Exception; throw new \Exception;
$this->_conn->commit(); // never reached $this->_conn->commit(); // never reached
} catch (\Exception $e) { } catch (\Exception $e) {
$this->_conn->rollback(); $this->_conn->rollBack();
$this->assertEquals(1, $this->_conn->getTransactionNestingLevel()); $this->assertEquals(1, $this->_conn->getTransactionNestingLevel());
//no rethrow //no rethrow
} }
...@@ -95,7 +95,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -95,7 +95,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$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.');
$this->_conn->rollback(); $this->_conn->rollBack();
} }
} }
...@@ -169,7 +169,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -169,7 +169,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->_conn->commit(); // never reached $this->_conn->commit(); // never reached
} catch (\Exception $e) { } catch (\Exception $e) {
$this->assertEquals(1, $this->_conn->getTransactionNestingLevel()); $this->assertEquals(1, $this->_conn->getTransactionNestingLevel());
$this->_conn->rollback(); $this->_conn->rollBack();
$this->assertEquals(0, $this->_conn->getTransactionNestingLevel()); $this->assertEquals(0, $this->_conn->getTransactionNestingLevel());
} }
} }
...@@ -181,7 +181,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -181,7 +181,7 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->assertEquals(1, $this->_conn->getTransactionNestingLevel()); $this->assertEquals(1, $this->_conn->getTransactionNestingLevel());
$this->_conn->commit(); $this->_conn->commit();
} catch (\Exception $e) { } catch (\Exception $e) {
$this->_conn->rollback(); $this->_conn->rollBack();
$this->assertEquals(0, $this->_conn->getTransactionNestingLevel()); $this->assertEquals(0, $this->_conn->getTransactionNestingLevel());
} }
...@@ -196,11 +196,30 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -196,11 +196,30 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL()); $conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL());
throw new \RuntimeException("Ooops!"); throw new \RuntimeException("Ooops!");
}); });
$this->fail('Expected exception');
} catch (\RuntimeException $expected) { } catch (\RuntimeException $expected) {
$this->assertEquals(0, $this->_conn->getTransactionNestingLevel()); $this->assertEquals(0, $this->_conn->getTransactionNestingLevel());
} }
} }
public function testTransactionalWithThrowable()
{
if (version_compare(PHP_VERSION, '7.0', '<')) {
$this->markTestSkipped('Only for PHP 7.0 and above.');
}
try {
$this->_conn->transactional(function($conn) {
/* @var $conn \Doctrine\DBAL\Connection */
$conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL());
throw new \Error("Ooops!");
});
$this->fail('Expected exception');
} catch (\Error $expected) {
$this->assertEquals(0, $this->_conn->getTransactionNestingLevel());
}
}
public function testTransactional() public function testTransactional()
{ {
$this->_conn->transactional(function($conn) { $this->_conn->transactional(function($conn) {
......
...@@ -59,7 +59,7 @@ class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -59,7 +59,7 @@ class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable)); $this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable));
$this->_conn->insert("nontemporary", array("id" => 2)); $this->_conn->insert("nontemporary", array("id" => 2));
$this->_conn->rollback(); $this->_conn->rollBack();
$rows = $this->_conn->fetchAll('SELECT * FROM nontemporary'); $rows = $this->_conn->fetchAll('SELECT * FROM nontemporary');
$this->assertEquals(array(), $rows, "In an event of an error this result has one row, because of an implicit commit."); $this->assertEquals(array(), $rows, "In an event of an error this result has one row, because of an implicit commit.");
...@@ -97,7 +97,7 @@ class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -97,7 +97,7 @@ class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->_conn->exec($createTempTableSQL); $this->_conn->exec($createTempTableSQL);
$this->_conn->insert("nontemporary", array("id" => 2)); $this->_conn->insert("nontemporary", array("id" => 2));
$this->_conn->rollback(); $this->_conn->rollBack();
try { try {
$this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable)); $this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable));
......
...@@ -31,7 +31,7 @@ class DBAL202Test extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -31,7 +31,7 @@ class DBAL202Test extends \Doctrine\Tests\DbalFunctionalTestCase
$stmt = $this->_conn->prepare('INSERT INTO DBAL202 VALUES (8)'); $stmt = $this->_conn->prepare('INSERT INTO DBAL202 VALUES (8)');
$this->_conn->beginTransaction(); $this->_conn->beginTransaction();
$stmt->execute(); $stmt->execute();
$this->_conn->rollback(); $this->_conn->rollBack();
$this->assertEquals(0, $this->_conn->query('SELECT COUNT(1) FROM DBAL202')->fetchColumn()); $this->assertEquals(0, $this->_conn->query('SELECT COUNT(1) FROM DBAL202')->fetchColumn());
} }
......
...@@ -50,8 +50,16 @@ class DbalFunctionalTestCase extends DbalTestCase ...@@ -50,8 +50,16 @@ class DbalFunctionalTestCase extends DbalTestCase
$queries = ""; $queries = "";
$i = count($this->_sqlLoggerStack->queries); $i = count($this->_sqlLoggerStack->queries);
foreach (array_reverse($this->_sqlLoggerStack->queries) as $query) { foreach (array_reverse($this->_sqlLoggerStack->queries) as $query) {
$params = array_map(function($p) { if (is_object($p)) return get_class($p); else return "'".$p."'"; }, $query['params'] ?: array()); $params = array_map(function($p) {
$queries .= ($i+1).". SQL: '".$query['sql']."' Params: ".implode(", ", $params).PHP_EOL; if (is_object($p)) {
return get_class($p);
} elseif (is_scalar($p)) {
return "'".$p."'";
} else {
return var_export($p, true);
}
}, $query['params'] ?: array());
$queries .= $i.". SQL: '".$query['sql']."' Params: ".implode(", ", $params).PHP_EOL;
$i--; $i--;
} }
......
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