Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
d1ba2d6a
Commit
d1ba2d6a
authored
Oct 23, 2014
by
Steve Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wrap PDOException for exec() method and cleanup unnecessary try catch blocks
parent
1b35a53e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
11 deletions
+65
-11
PDOConnection.php
lib/Doctrine/DBAL/Driver/PDOConnection.php
+14
-10
PDOConnectionTest.php
...ctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php
+51
-1
No files found.
lib/Doctrine/DBAL/Driver/PDOConnection.php
View file @
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
);
}
}
/**
...
...
@@ -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
);
}
}
/**
...
...
tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php
View file @
d1ba2d6a
...
...
@@ -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'
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment