Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\Cache\ResultCacheStatement;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver\PDOException;
use Doctrine\DBAL\Driver\PingableConnection;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
Expand Down Expand Up @@ -1671,7 +1672,7 @@ public function ping()
$this->query($this->getDatabasePlatform()->getDummySelectSQL());

return true;
} catch (DBALException $e) {
} catch (PDOException | DBALException $e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When does a PDOException occur? I believe we upcast those, so this is fixing a symptom

Copy link
Contributor Author

@sidz sidz Oct 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may stay with DBALException only for case when we will catch Throwable and convert them to the DBALException in the query methods.

https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Connection.php#L1011-L1015

return false;
}
}
Expand Down
8 changes: 7 additions & 1 deletion lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events;
use InvalidArgumentException;
use Throwable;
use function array_rand;
use function count;
use function func_get_args;
Expand Down Expand Up @@ -352,7 +354,11 @@ public function query()
$logger->startQuery($args[0]);
}

$statement = $this->_conn->query(...$args);
try {
$statement = $this->_conn->query(...$args);
} catch (Throwable $e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: we upcast these, so if we need to further wrap it there's something else going on

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw DBALException::driverExceptionDuringQuery($this->_driver, $e, $args[0]);
}

if ($logger) {
$logger->stopQuery();
Expand Down
10 changes: 10 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,14 @@ public function testMasterSlaveConnectionCloseAndReconnect()
$conn->connect('master');
self::assertTrue($conn->isConnectedToMaster());
}

public function testPingDoesTriggersConnect()
{
$conn = $this->createMasterSlaveConnection();

$conn->connect('master');

self::assertTrue($conn->ping());
self::assertTrue($conn->isConnectedToMaster());
}
}