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
d8a96fcf
Commit
d8a96fcf
authored
Oct 24, 2014
by
Marco Pivetta
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #703 from deeky666/DBAL-1022
[DBAL-1022] Wrap PDOException in PDOConnection::exec()
parents
1b35a53e
d1ba2d6a
Changes
2
Hide 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 @
d8a96fcf
...
...
@@ -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
);
}
/**
...
...
tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php
View file @
d8a96fcf
...
...
@@ -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