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
6ce265d1
Commit
6ce265d1
authored
Dec 22, 2013
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #458 from doctrine/DBAL-722
[DBAL-722] Introduce subclasses for runtime relevant exceptions
parents
7fc6b420
21b68939
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
124 additions
and
5 deletions
+124
-5
DBALException.php
lib/Doctrine/DBAL/DBALException.php
+28
-2
DuplicateKeyException.php
lib/Doctrine/DBAL/Exception/DuplicateKeyException.php
+31
-0
ForeignKeyConstraintViolationException.php
...DBAL/Exception/ForeignKeyConstraintViolationException.php
+31
-0
NotNullableException.php
lib/Doctrine/DBAL/Exception/NotNullableException.php
+31
-0
ExceptionTest.php
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
+3
-3
No files found.
lib/Doctrine/DBAL/DBALException.php
View file @
6ce265d1
...
...
@@ -107,7 +107,7 @@ class DBALException extends \Exception
?
$driver
->
convertExceptionCode
(
$driverEx
)
:
0
;
return
new
self
(
$msg
,
$code
,
$driverEx
);
return
self
::
createDriverException
(
$msg
,
$code
,
$driverEx
);
}
/**
...
...
@@ -120,7 +120,33 @@ class DBALException extends \Exception
{
$msg
=
"An exception occured in driver: "
.
$driverEx
->
getMessage
();
return
new
self
(
$msg
,
$driver
->
convertExceptionCode
(
$driverEx
),
$driverEx
);
$code
=
(
$driver
instanceof
ExceptionConverterDriver
)
?
$driver
->
convertExceptionCode
(
$driverEx
)
:
0
;
return
self
::
createDriverException
(
$msg
,
$code
,
$driverEx
);
}
/**
* Factory method for subclasses of DBALException based on exception code.
*
* @return \Doctrine\DBAL\DBALException
*/
private
static
function
createDriverException
(
$msg
,
$code
,
$driverEx
)
{
switch
(
$code
)
{
case
self
::
ERROR_NOT_NULL
:
return
new
Exception\NotNullableException
(
$msg
,
$code
,
$driverEx
);
case
self
::
ERROR_DUPLICATE_KEY
:
return
new
Exception\DuplicateKeyException
(
$msg
,
$code
,
$driverEx
);
case
self
::
ERROR_FOREIGN_KEY_CONSTRAINT
:
return
new
Exception\ForeignKeyConstraintViolationException
(
$msg
,
$code
,
$driverEx
);
default
:
return
new
self
(
$msg
,
$code
,
$driverEx
);
}
}
/**
...
...
lib/Doctrine/DBAL/Exception/DuplicateKeyException.php
0 → 100644
View file @
6ce265d1
<?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\Exception
;
use
Doctrine\DBAL\DBALException
;
/**
* Thrown when {@link DBALException::ERROR_DUPLICATE_KEY} is detected in driver
*
* @since 2.5
*/
class
DuplicateKeyException
extends
DBALException
{
}
lib/Doctrine/DBAL/Exception/ForeignKeyConstraintViolationException.php
0 → 100644
View file @
6ce265d1
<?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\Exception
;
use
Doctrine\DBAL\DBALException
;
/**
* Thrown when {@link DBALException::ERROR_FOREIGN_KEY_CONSTRAINT} is detected in driver
*
* @since 2.5
*/
class
ForeignKeyConstraintViolationException
extends
DBALException
{
}
lib/Doctrine/DBAL/Exception/NotNullableException.php
0 → 100644
View file @
6ce265d1
<?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\Exception
;
use
Doctrine\DBAL\DBALException
;
/**
* Thrown when {@link DBALException::ERROR_NOT_NULL} is detected in driver
*
* @since 2.5
*/
class
NotNullableException
extends
DBALException
{
}
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
View file @
6ce265d1
...
...
@@ -27,7 +27,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this
->
_conn
->
insert
(
"duplicatekey_table"
,
array
(
'id'
=>
1
));
$this
->
setExpectedException
(
'\Doctrine\DBAL\
DBAL
Exception'
,
null
,
DBALException
::
ERROR_DUPLICATE_KEY
);
$this
->
setExpectedException
(
'\Doctrine\DBAL\
Exception\DuplicateKey
Exception'
,
null
,
DBALException
::
ERROR_DUPLICATE_KEY
);
$this
->
_conn
->
insert
(
"duplicatekey_table"
,
array
(
'id'
=>
1
));
}
...
...
@@ -79,7 +79,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this
->
_conn
->
insert
(
"constraint_error_table"
,
array
(
'id'
=>
1
));
$this
->
_conn
->
insert
(
"owning_table"
,
array
(
'id'
=>
1
,
'constraint_id'
=>
1
));
$this
->
setExpectedException
(
'\Doctrine\DBAL\
DBAL
Exception'
,
null
,
DBALException
::
ERROR_FOREIGN_KEY_CONSTRAINT
);
$this
->
setExpectedException
(
'\Doctrine\DBAL\
Exception\ForeignKeyConstraintViolation
Exception'
,
null
,
DBALException
::
ERROR_FOREIGN_KEY_CONSTRAINT
);
$this
->
_conn
->
delete
(
'constraint_error_table'
,
array
(
'id'
=>
1
));
}
...
...
@@ -96,7 +96,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this
->
_conn
->
executeQuery
(
$sql
);
}
$this
->
setExpectedException
(
'\Doctrine\DBAL\
DBAL
Exception'
,
null
,
DBALException
::
ERROR_NOT_NULL
);
$this
->
setExpectedException
(
'\Doctrine\DBAL\
Exception\NotNullable
Exception'
,
null
,
DBALException
::
ERROR_NOT_NULL
);
$this
->
_conn
->
insert
(
"notnull_table"
,
array
(
'id'
=>
1
,
'value'
=>
null
));
}
...
...
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