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
babdc32e
Unverified
Commit
babdc32e
authored
Jun 29, 2020
by
Sergei Morozov
Committed by
GitHub
Jun 29, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4129 from morozov/remove-exception-converter-driver
Remove ExceptionConverterDriver
parents
d72223be
53e5a090
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
52 additions
and
58 deletions
+52
-58
UPGRADE.md
UPGRADE.md
+4
-0
DBALException.php
src/DBALException.php
+1
-2
Driver.php
src/Driver.php
+14
-0
AbstractDB2Driver.php
src/Driver/AbstractDB2Driver.php
+1
-2
AbstractMySQLDriver.php
src/Driver/AbstractMySQLDriver.php
+2
-3
AbstractOracleDriver.php
src/Driver/AbstractOracleDriver.php
+2
-3
AbstractPostgreSQLDriver.php
src/Driver/AbstractPostgreSQLDriver.php
+2
-3
AbstractSQLServerDriver.php
src/Driver/AbstractSQLServerDriver.php
+1
-2
AbstractSQLiteDriver.php
src/Driver/AbstractSQLiteDriver.php
+2
-3
ExceptionConverterDriver.php
src/Driver/ExceptionConverterDriver.php
+0
-28
AbstractDriverTest.php
tests/Driver/AbstractDriverTest.php
+13
-9
ExceptionTest.php
tests/Functional/ExceptionTest.php
+10
-3
No files found.
UPGRADE.md
View file @
babdc32e
# Upgrade to 3.0
## The `ExceptionConverterDriver` interface is removed
All drivers must implement the
`convertException()`
method which is now part of the
`Driver`
interface.
## The `PingableConnection` interface is removed
The functionality of pinging the server is no longer supported.
...
...
src/DBALException.php
View file @
babdc32e
...
...
@@ -3,7 +3,6 @@
namespace
Doctrine\DBAL
;
use
Doctrine\DBAL\Driver\Exception
as
TheDriverException
;
use
Doctrine\DBAL\Driver\ExceptionConverterDriver
;
use
Doctrine\DBAL\Exception\DriverException
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Types\Type
;
...
...
@@ -169,7 +168,7 @@ class DBALException extends Exception
return
$driverEx
;
}
if
(
$driver
instanceof
ExceptionConverterDriver
&&
$driver
Ex
instanceof
TheDriverException
)
{
if
(
$driverEx
instanceof
TheDriverException
)
{
return
$driver
->
convertException
(
$msg
,
$driverEx
);
}
...
...
src/Driver.php
View file @
babdc32e
...
...
@@ -4,6 +4,7 @@ namespace Doctrine\DBAL;
use
Doctrine\DBAL\Driver\Connection
as
DriverConnection
;
use
Doctrine\DBAL\Driver\Exception
;
use
Doctrine\DBAL\Exception\DriverException
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Schema\AbstractSchemaManager
;
...
...
@@ -39,4 +40,17 @@ interface Driver
* @return AbstractSchemaManager
*/
public
function
getSchemaManager
(
Connection
$conn
);
/**
* Converts a given driver-level exception into a DBAL-level driver exception.
*
* Implementors should use the vendor-specific error code and SQLSTATE of the exception
* and instantiate the most appropriate specialized {@link DriverException} subclass.
*
* @param string $message The exception message to use.
* @param Exception $exception The driver exception to convert.
*
* @return DriverException An instance of {@link DriverException} or one of its subclasses.
*/
public
function
convertException
(
$message
,
Exception
$exception
);
}
src/Driver/AbstractDB2Driver.php
View file @
babdc32e
...
...
@@ -4,7 +4,6 @@ namespace Doctrine\DBAL\Driver;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver\Exception
as
TheDriverException
;
use
Doctrine\DBAL\Exception\DriverException
;
use
Doctrine\DBAL\Platforms\DB2Platform
;
use
Doctrine\DBAL\Schema\DB2SchemaManager
;
...
...
@@ -35,7 +34,7 @@ abstract class AbstractDB2Driver implements Driver
*
* @return DriverException
*/
public
function
convertException
(
$message
,
TheDriver
Exception
$exception
)
public
function
convertException
(
$message
,
Exception
$exception
)
{
return
new
DriverException
(
$message
,
$exception
);
}
...
...
src/Driver/AbstractMySQLDriver.php
View file @
babdc32e
...
...
@@ -4,7 +4,6 @@ namespace Doctrine\DBAL\Driver;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Driver\Exception
as
TheDriverException
;
use
Doctrine\DBAL\Exception\ConnectionException
;
use
Doctrine\DBAL\Exception\ConnectionLost
;
use
Doctrine\DBAL\Exception\DeadlockException
;
...
...
@@ -32,7 +31,7 @@ use function version_compare;
/**
* Abstract base implementation of the {@link Driver} interface for MySQL based drivers.
*/
abstract
class
AbstractMySQLDriver
implements
ExceptionConverterDriver
,
VersionAwarePlatformDriver
abstract
class
AbstractMySQLDriver
implements
VersionAwarePlatformDriver
{
/**
* {@inheritdoc}
...
...
@@ -40,7 +39,7 @@ abstract class AbstractMySQLDriver implements ExceptionConverterDriver, VersionA
* @link https://dev.mysql.com/doc/refman/8.0/en/client-error-reference.html
* @link https://dev.mysql.com/doc/refman/8.0/en/server-error-reference.html
*/
public
function
convertException
(
$message
,
TheDriver
Exception
$exception
)
public
function
convertException
(
$message
,
Exception
$exception
)
{
switch
(
$exception
->
getCode
())
{
case
1213
:
...
...
src/Driver/AbstractOracleDriver.php
View file @
babdc32e
...
...
@@ -5,7 +5,6 @@ namespace Doctrine\DBAL\Driver;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver\AbstractOracleDriver\EasyConnectString
;
use
Doctrine\DBAL\Driver\Exception
as
TheDriverException
;
use
Doctrine\DBAL\Exception\ConnectionException
;
use
Doctrine\DBAL\Exception\DriverException
;
use
Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException
;
...
...
@@ -22,12 +21,12 @@ use Doctrine\DBAL\Schema\OracleSchemaManager;
/**
* Abstract base implementation of the {@link Driver} interface for Oracle based drivers.
*/
abstract
class
AbstractOracleDriver
implements
Driver
,
ExceptionConverterDriver
abstract
class
AbstractOracleDriver
implements
Driver
{
/**
* {@inheritdoc}
*/
public
function
convertException
(
$message
,
TheDriver
Exception
$exception
)
public
function
convertException
(
$message
,
Exception
$exception
)
{
switch
(
$exception
->
getCode
())
{
case
1
:
...
...
src/Driver/AbstractPostgreSQLDriver.php
View file @
babdc32e
...
...
@@ -4,7 +4,6 @@ namespace Doctrine\DBAL\Driver;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Driver\Exception
as
TheDriverException
;
use
Doctrine\DBAL\Exception\ConnectionException
;
use
Doctrine\DBAL\Exception\DeadlockException
;
use
Doctrine\DBAL\Exception\DriverException
;
...
...
@@ -28,14 +27,14 @@ use function version_compare;
/**
* Abstract base implementation of the {@link Driver} interface for PostgreSQL based drivers.
*/
abstract
class
AbstractPostgreSQLDriver
implements
ExceptionConverterDriver
,
VersionAwarePlatformDriver
abstract
class
AbstractPostgreSQLDriver
implements
VersionAwarePlatformDriver
{
/**
* {@inheritdoc}
*
* @link http://www.postgresql.org/docs/9.4/static/errcodes-appendix.html
*/
public
function
convertException
(
$message
,
TheDriver
Exception
$exception
)
public
function
convertException
(
$message
,
Exception
$exception
)
{
switch
(
$exception
->
getSQLState
())
{
case
'40001'
:
...
...
src/Driver/AbstractSQLServerDriver.php
View file @
babdc32e
...
...
@@ -4,7 +4,6 @@ namespace Doctrine\DBAL\Driver;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver\Exception
as
TheDriverException
;
use
Doctrine\DBAL\Exception\DriverException
;
use
Doctrine\DBAL\Platforms\SQLServer2012Platform
;
use
Doctrine\DBAL\Schema\SQLServerSchemaManager
;
...
...
@@ -35,7 +34,7 @@ abstract class AbstractSQLServerDriver implements Driver
*
* @return DriverException
*/
public
function
convertException
(
$message
,
TheDriver
Exception
$exception
)
public
function
convertException
(
$message
,
Exception
$exception
)
{
return
new
DriverException
(
$message
,
$exception
);
}
...
...
src/Driver/AbstractSQLiteDriver.php
View file @
babdc32e
...
...
@@ -4,7 +4,6 @@ namespace Doctrine\DBAL\Driver;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver\Exception
as
TheDriverException
;
use
Doctrine\DBAL\Exception\ConnectionException
;
use
Doctrine\DBAL\Exception\DriverException
;
use
Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException
;
...
...
@@ -25,14 +24,14 @@ use function strpos;
/**
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for SQLite based drivers.
*/
abstract
class
AbstractSQLiteDriver
implements
Driver
,
ExceptionConverterDriver
abstract
class
AbstractSQLiteDriver
implements
Driver
{
/**
* {@inheritdoc}
*
* @link http://www.sqlite.org/c3ref/c_abort.html
*/
public
function
convertException
(
$message
,
TheDriver
Exception
$exception
)
public
function
convertException
(
$message
,
Exception
$exception
)
{
if
(
strpos
(
$exception
->
getMessage
(),
'database is locked'
)
!==
false
)
{
return
new
LockWaitTimeoutException
(
$message
,
$exception
);
...
...
src/Driver/ExceptionConverterDriver.php
deleted
100644 → 0
View file @
d72223be
<?php
namespace
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver\Exception
as
TheDriverException
;
use
Doctrine\DBAL\Exception\DriverException
;
/**
* Contract for a driver that is capable of converting DBAL driver exceptions into standardized DBAL driver exceptions.
*
* @deprecated All implementors of the {@link Driver} interface will have to implement this API.
*/
interface
ExceptionConverterDriver
{
/**
* Converts a given DBAL driver exception into a standardized DBAL driver exception.
*
* It evaluates the vendor specific error code and SQLSTATE and transforms
* it into a unified {@link DriverException} subclass.
*
* @param string $message The DBAL exception message to use.
* @param TheDriverException $exception The DBAL driver exception to convert.
*
* @return DriverException An instance of one of the DriverException subclasses.
*/
public
function
convertException
(
$message
,
TheDriverException
$exception
);
}
tests/Driver/AbstractDriverTest.php
View file @
babdc32e
...
...
@@ -5,8 +5,9 @@ namespace Doctrine\DBAL\Tests\Driver;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver\Exception
as
DriverExceptionInterface
;
use
Doctrine\DBAL\Driver\ExceptionConverterDriver
;
use
Doctrine\DBAL\Driver\AbstractException
;
use
Doctrine\DBAL\Driver\AbstractSQLServerDriver
;
use
Doctrine\DBAL\Driver\IBMDB2
;
use
Doctrine\DBAL\Exception\ConnectionException
;
use
Doctrine\DBAL\Exception\ConstraintViolationException
;
use
Doctrine\DBAL\Exception\DatabaseObjectExistsException
;
...
...
@@ -78,15 +79,18 @@ abstract class AbstractDriverTest extends TestCase
?
string
$sqlState
=
null
,
string
$message
=
''
)
:
void
{
if
(
!
$this
->
driver
instanceof
ExceptionConverter
Driver
)
{
self
::
markTestSkipped
(
'This test is only intended for exception converter drivers.'
);
if
(
$this
->
driver
instanceof
IBMDB2\
Driver
)
{
self
::
markTestSkipped
(
"The IBM DB2 driver currently doesn't instantiate specialized exceptions"
);
}
$driverException
=
$this
->
getMockBuilder
(
DriverExceptionInterface
::
class
)
->
setConstructorArgs
([
$message
,
$errorCode
])
->
getMock
();
$driverException
->
method
(
'getSQLState'
)
->
willReturn
(
$sqlState
);
if
(
$this
->
driver
instanceof
AbstractSQLServerDriver
)
{
self
::
markTestSkipped
(
"The SQL Server drivers currently don't instantiate specialized exceptions"
);
}
$driverException
=
$this
->
getMockForAbstractClass
(
AbstractException
::
class
,
[
$message
,
$sqlState
,
$errorCode
]
);
$dbalMessage
=
'DBAL exception message'
;
$dbalException
=
$this
->
driver
->
convertException
(
$dbalMessage
,
$driverException
);
...
...
tests/Functional/ExceptionTest.php
View file @
babdc32e
...
...
@@ -2,7 +2,8 @@
namespace
Doctrine\DBAL\Tests\Functional
;
use
Doctrine\DBAL\Driver\ExceptionConverterDriver
;
use
Doctrine\DBAL\Driver\AbstractSQLServerDriver
;
use
Doctrine\DBAL\Driver\IBMDB2
;
use
Doctrine\DBAL\Driver\ServerInfoAwareConnection
;
use
Doctrine\DBAL\DriverManager
;
use
Doctrine\DBAL\Exception
;
...
...
@@ -35,11 +36,17 @@ class ExceptionTest extends FunctionalTestCase
{
parent
::
setUp
();
if
(
$this
->
connection
->
getDriver
()
instanceof
ExceptionConverterDriver
)
{
$driver
=
$this
->
connection
->
getDriver
();
if
(
$driver
instanceof
IBMDB2\Driver
)
{
self
::
markTestSkipped
(
"The IBM DB2 driver currently doesn't instantiate specialized exceptions"
);
}
if
(
!
$driver
instanceof
AbstractSQLServerDriver
)
{
return
;
}
self
::
markTestSkipped
(
'Driver does not support special exception handling.'
);
self
::
markTestSkipped
(
"The SQL Server drivers currently don't instantiate specialized exceptions"
);
}
public
function
testPrimaryConstraintViolationException
()
:
void
...
...
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