Commit d8a96fcf authored by Marco Pivetta's avatar Marco Pivetta

Merge pull request #703 from deeky666/DBAL-1022

[DBAL-1022] Wrap PDOException in PDOConnection::exec()
parents 1b35a53e d1ba2d6a
......@@ -48,6 +48,18 @@ class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection
}
}
/**
* {@inheritdoc}
*/
public function exec($statement)
{
try {
return parent::exec($statement);
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
}
/**
* {@inheritdoc}
*/
......@@ -100,11 +112,7 @@ class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection
*/
public function quote($input, $type = \PDO::PARAM_STR)
{
try {
return parent::quote($input, $type);
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
return parent::quote($input, $type);
}
/**
......@@ -112,11 +120,7 @@ class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection
*/
public function lastInsertId($name = null)
{
try {
return parent::lastInsertId($name);
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
return parent::lastInsertId($name);
}
/**
......
......@@ -24,7 +24,7 @@ class PDOConnectionTest extends DbalFunctionalTestCase
$this->driverConnection = $this->_conn->getWrappedConnection();
if ( ! $this->_conn->getWrappedConnection() instanceof PDOConnection) {
if ( ! $this->driverConnection instanceof PDOConnection) {
$this->markTestSkipped('PDO connection only test.');
}
}
......@@ -33,4 +33,54 @@ class PDOConnectionTest extends DbalFunctionalTestCase
{
$this->assertFalse($this->driverConnection->requiresQueryForServerVersion());
}
/**
* @expectedException \Doctrine\DBAL\Driver\PDOException
*/
public function testThrowsWrappedExceptionOnConstruct()
{
new PDOConnection('foo');
}
/**
* @group DBAL-1022
*
* @expectedException \Doctrine\DBAL\Driver\PDOException
*/
public function testThrowsWrappedExceptionOnExec()
{
$this->driverConnection->exec('foo');
}
/**
* @expectedException \Doctrine\DBAL\Driver\PDOException
*/
public function testThrowsWrappedExceptionOnPrepare()
{
// Emulated prepared statements have to be disabled for this test
// so that PDO actually communicates with the database server to check the query.
$this->driverConnection->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
$this->driverConnection->prepare('foo');
// Some PDO adapters like PostgreSQL do not check the query server-side
// even though emulated prepared statements are disabled,
// so an exception is thrown only eventually.
// Skip the test otherwise.
$this->markTestSkipped(
sprintf(
'The PDO adapter %s does not check the query to be prepared server-side, ' .
'so no assertions can be made.',
$this->_conn->getDriver()->getName()
)
);
}
/**
* @expectedException \Doctrine\DBAL\Driver\PDOException
*/
public function testThrowsWrappedExceptionOnQuery()
{
$this->driverConnection->query('foo');
}
}
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