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
a6bc5a8a
Commit
a6bc5a8a
authored
Nov 14, 2013
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Exception converting into a non-BC change.
parent
d2a1d2a0
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
55 additions
and
39 deletions
+55
-39
UPGRADE.md
UPGRADE.md
+1
-29
DBALException.php
lib/Doctrine/DBAL/DBALException.php
+7
-1
Driver.php
lib/Doctrine/DBAL/Driver.php
+0
-1
ExceptionConverterDriver.php
lib/Doctrine/DBAL/Driver/ExceptionConverterDriver.php
+37
-0
Driver.php
lib/Doctrine/DBAL/Driver/Mysqli/Driver.php
+2
-1
Driver.php
lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php
+2
-1
Driver.php
lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php
+2
-1
Driver.php
lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php
+2
-1
ExceptionTest.php
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
+2
-4
No files found.
UPGRADE.md
View file @
a6bc5a8a
# Upgrade to 2.5
A new method was added to
`Doctrine\DBAL\Driver`
interface that you need to implement
if your project contains custom drivers.
```
php
/**
* @param \Exception $exception
*
* @return int
*/
public
function
convertExceptionCode
(
\Exception
$exception
);
```
The most basic implementation for this method just returns 0:
```
php
/**
* @param \Exception $exception
*
* @return int
*/
public
function
convertExceptionCode
(
\Exception
$exception
)
{
return
0
;
}
```
You can see the MySQL, SQLite and PostgreSQL drivers for sample implementations with
the new feature and take a look at
`tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php`
for testing this functionality.
No BC breaks yet.
# Upgrade to 2.4
...
...
lib/Doctrine/DBAL/DBALException.php
View file @
a6bc5a8a
...
...
@@ -19,6 +19,8 @@
namespace
Doctrine\DBAL
;
use
Doctrine\DBAL\Driver\ExceptionConverterDriver
;
class
DBALException
extends
\Exception
{
const
ERROR_DUPLICATE_KEY
=
1
;
...
...
@@ -101,7 +103,11 @@ class DBALException extends \Exception
}
$msg
.=
":
\n\n
"
.
$driverEx
->
getMessage
();
return
new
self
(
$msg
,
$driver
->
convertExceptionCode
(
$driverEx
),
$driverEx
);
$code
=
(
$driver
instanceof
ExceptionConverterDriver
)
?
$driver
->
convertExceptionCode
(
$driverEx
)
:
0
;
return
new
self
(
$msg
,
$code
,
$driverEx
);
}
/**
...
...
lib/Doctrine/DBAL/Driver.php
View file @
a6bc5a8a
...
...
@@ -73,7 +73,6 @@ interface Driver
*/
public
function
getDatabase
(
Connection
$conn
);
/**
* @param \Exception $exception
*
...
...
lib/Doctrine/DBAL/Driver/ExceptionConverterDriver.php
0 → 100644
View file @
a6bc5a8a
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace
Doctrine\DBAL\Driver
;
use
Exception
;
/**
* Drivers marked as ExceptionConverters can convert to standardized codes.
*
* @since 2.5
*/
interface
ExceptionConverterDriver
{
/**
* @param \Exception $exception
*
* @return int
*/
public
function
convertExceptionCode
(
Exception
$exception
);
}
lib/Doctrine/DBAL/Driver/Mysqli/Driver.php
View file @
a6bc5a8a
...
...
@@ -22,11 +22,12 @@ namespace Doctrine\DBAL\Driver\Mysqli;
use
Doctrine\DBAL\Driver
as
DriverInterface
;
use
Doctrine\DBAL\Driver\Mysqli\MysqliException
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Driver\ExceptionConverterDriver
;
/**
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
*/
class
Driver
implements
DriverInterface
class
Driver
implements
DriverInterface
,
ExceptionConverterDriver
{
/**
* {@inheritdoc}
...
...
lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php
View file @
a6bc5a8a
...
...
@@ -21,6 +21,7 @@ namespace Doctrine\DBAL\Driver\PDOMySql;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Driver\ExceptionConverterDriver
;
use
PDOException
;
/**
...
...
@@ -28,7 +29,7 @@ use PDOException;
*
* @since 2.0
*/
class
Driver
implements
\Doctrine\DBAL\Driver
class
Driver
implements
\Doctrine\DBAL\Driver
,
ExceptionConverterDriver
{
/**
* {@inheritdoc}
...
...
lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php
View file @
a6bc5a8a
...
...
@@ -22,13 +22,14 @@ namespace Doctrine\DBAL\Driver\PDOPgSql;
use
Doctrine\DBAL\Platforms
;
use
Doctrine\DBAL\DBALException
;
use
PDOException
;
use
Doctrine\DBAL\Driver\ExceptionConverterDriver
;
/**
* Driver that connects through pdo_pgsql.
*
* @since 2.0
*/
class
Driver
implements
\Doctrine\DBAL\Driver
class
Driver
implements
\Doctrine\DBAL\Driver
,
ExceptionConverterDriver
{
/**
* {@inheritdoc}
...
...
lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php
View file @
a6bc5a8a
...
...
@@ -20,6 +20,7 @@
namespace
Doctrine\DBAL\Driver\PDOSqlite
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Driver\ExceptionConverterDriver
;
use
PDOException
;
/**
...
...
@@ -27,7 +28,7 @@ use PDOException;
*
* @since 2.0
*/
class
Driver
implements
\Doctrine\DBAL\Driver
class
Driver
implements
\Doctrine\DBAL\Driver
,
ExceptionConverterDriver
{
/**
* @var array
...
...
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
View file @
a6bc5a8a
...
...
@@ -2,6 +2,7 @@
namespace
Doctrine\Tests\DBAL\Functional
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Driver\ExceptionConverterDriver
;
class
ExceptionTest
extends
\Doctrine\Tests\DbalFunctionalTestCase
{
...
...
@@ -9,10 +10,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
parent
::
setUp
();
$supportExceptions
=
array
(
'pdo_sqlite'
,
'pdo_mysql'
,
'pdo_pgsql'
,
'mysqli'
);
$params
=
$this
->
_conn
->
getParams
();
if
(
!
in_array
(
$params
[
'driver'
],
$supportExceptions
))
{
if
(
!
(
$this
->
_conn
->
getDriver
()
instanceof
ExceptionConverterDriver
))
{
$this
->
markTestSkipped
(
'Driver does not support special exception handling.'
);
}
}
...
...
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