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
47b0aec4
Commit
47b0aec4
authored
Nov 21, 2013
by
Steve Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve driver exception code conversion
parent
25a1cced
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
153 additions
and
112 deletions
+153
-112
Driver.php
lib/Doctrine/DBAL/Driver/Mysqli/Driver.php
+61
-42
Driver.php
lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php
+67
-35
Driver.php
lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php
+25
-35
No files found.
lib/Doctrine/DBAL/Driver/Mysqli/Driver.php
View file @
47b0aec4
...
...
@@ -20,7 +20,6 @@
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
;
...
...
@@ -80,50 +79,70 @@ class Driver implements DriverInterface, ExceptionConverterDriver
*/
public
function
convertExceptionCode
(
\Exception
$exception
)
{
if
(
strpos
(
$exception
->
getMessage
(),
'Table'
)
===
0
)
{
if
(
strpos
(
$exception
->
getMessage
(),
'doesn\'t exist'
)
!==
false
)
{
return
DBALException
::
ERROR_UNKNOWN_TABLE
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'already exists'
)
!==
false
)
{
switch
(
$exception
->
getCode
())
{
case
'1050'
:
return
DBALException
::
ERROR_TABLE_ALREADY_EXISTS
;
}
}
if
(
strpos
(
$exception
->
getMessage
(),
'Unknown column'
)
===
0
)
{
return
DBALException
::
ERROR_BAD_FIELD_NAME
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'Cannot delete or update a parent row: a foreign key constraint fails'
)
!==
false
)
{
return
DBALException
::
ERROR_FOREIGN_KEY_CONSTRAINT
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'Duplicate entry'
)
!==
false
)
{
return
DBALException
::
ERROR_DUPLICATE_KEY
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'Column not found: 1054 Unknown column'
)
!==
false
)
{
return
DBALException
::
ERROR_BAD_FIELD_NAME
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'in field list is ambiguous'
)
!==
falsE
)
{
return
DBALException
::
ERROR_NON_UNIQUE_FIELD_NAME
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'You have an error in your SQL syntax; check the manual'
)
!==
false
)
{
return
DBALException
::
ERROR_SYNTAX
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'Access denied for user'
)
!==
false
)
{
return
DBALException
::
ERROR_ACCESS_DENIED
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'getaddrinfo failed: Name or service not known'
)
!==
false
)
{
return
DBALException
::
ERROR_ACCESS_DENIED
;
}
case
'1051'
:
case
'1146'
:
return
DBALException
::
ERROR_UNKNOWN_TABLE
;
if
(
strpos
(
$exception
->
getMessage
(),
' cannot be null'
))
{
return
DBALException
::
ERROR_NOT_NULL
;
case
'1216'
:
case
'1217'
:
case
'1451'
:
case
'1452'
:
return
DBALException
::
ERROR_FOREIGN_KEY_CONSTRAINT
;
case
'1062'
:
case
'1557'
:
case
'1569'
:
case
'1586'
:
return
DBALException
::
ERROR_DUPLICATE_KEY
;
case
'1054'
:
case
'1166'
:
case
'1611'
:
return
DBALException
::
ERROR_BAD_FIELD_NAME
;
case
'1052'
:
case
'1060'
:
case
'1110'
:
return
DBALException
::
ERROR_NON_UNIQUE_FIELD_NAME
;
case
'1064'
:
case
'1149'
:
case
'1287'
:
case
'1341'
:
case
'1342'
:
case
'1343'
:
case
'1344'
:
case
'1382'
:
case
'1479'
:
case
'1541'
:
case
'1554'
:
case
'1626'
:
return
DBALException
::
ERROR_SYNTAX
;
case
'1044'
:
case
'1045'
:
case
'1046'
:
case
'1049'
:
case
'1095'
:
case
'1142'
:
case
'1143'
:
case
'1227'
:
case
'1370'
:
case
'2005'
:
return
DBALException
::
ERROR_ACCESS_DENIED
;
case
'1048'
:
case
'1121'
:
case
'1138'
:
case
'1171'
:
case
'1252'
:
case
'1263'
:
case
'1566'
:
return
DBALException
::
ERROR_NOT_NULL
;
}
return
0
;
...
...
lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php
View file @
47b0aec4
...
...
@@ -121,45 +121,77 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver
*/
public
function
convertExceptionCode
(
\Exception
$exception
)
{
switch
(
$exception
->
getCode
())
{
case
'42S02'
:
return
DBALException
::
ERROR_UNKNOWN_TABLE
;
case
'42S01'
:
return
DBALException
::
ERROR_TABLE_ALREADY_EXISTS
;
default
:
if
(
strpos
(
$exception
->
getMessage
(),
'Cannot delete or update a parent row: a foreign key constraint fails'
)
!==
false
)
{
return
DBALException
::
ERROR_FOREIGN_KEY_CONSTRAINT
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'Duplicate entry'
)
!==
false
)
{
return
DBALException
::
ERROR_DUPLICATE_KEY
;
}
$errorCode
=
$exception
->
getCode
();
if
(
strpos
(
$exception
->
getMessage
(),
'Column not found: 1054 Unknown column'
)
!==
false
)
{
return
DBALException
::
ERROR_BAD_FIELD_NAME
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'in field list is ambiguous'
)
!==
falsE
)
{
return
DBALException
::
ERROR_NON_UNIQUE_FIELD_NAME
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'You have an error in your SQL syntax; check the manual'
)
!==
false
)
{
return
DBALException
::
ERROR_SYNTAX
;
}
// Use driver-specific error code instead of SQLSTATE for PDO exceptions if available.
if
(
$exception
instanceof
\PDOException
&&
null
!==
$exception
->
errorInfo
[
1
])
{
$errorCode
=
$exception
->
errorInfo
[
1
];
}
if
(
strpos
(
$exception
->
getMessage
(),
'Access denied for user'
)
!==
fals
e
)
{
return
DBALException
::
ERROR_ACCESS_DENIED
;
}
switch
(
$errorCod
e
)
{
case
'1050'
:
return
DBALException
::
ERROR_TABLE_ALREADY_EXISTS
;
if
(
strpos
(
$exception
->
getMessage
(),
'getaddrinfo failed: Name or service not known'
)
!==
false
)
{
return
DBALException
::
ERROR_ACCESS_DENIED
;
}
case
'1051'
:
case
'1146'
:
return
DBALException
::
ERROR_UNKNOWN_TABLE
;
if
(
strpos
(
$exception
->
getMessage
(),
' cannot be null'
))
{
return
DBALException
::
ERROR_NOT_NULL
;
}
case
'1216'
:
case
'1217'
:
case
'1451'
:
case
'1452'
:
return
DBALException
::
ERROR_FOREIGN_KEY_CONSTRAINT
;
case
'1062'
:
case
'1557'
:
case
'1569'
:
case
'1586'
:
return
DBALException
::
ERROR_DUPLICATE_KEY
;
case
'1054'
:
case
'1166'
:
case
'1611'
:
return
DBALException
::
ERROR_BAD_FIELD_NAME
;
case
'1052'
:
case
'1060'
:
case
'1110'
:
return
DBALException
::
ERROR_NON_UNIQUE_FIELD_NAME
;
case
'1064'
:
case
'1149'
:
case
'1287'
:
case
'1341'
:
case
'1342'
:
case
'1343'
:
case
'1344'
:
case
'1382'
:
case
'1479'
:
case
'1541'
:
case
'1554'
:
case
'1626'
:
return
DBALException
::
ERROR_SYNTAX
;
case
'1044'
:
case
'1045'
:
case
'1046'
:
case
'1049'
:
case
'1095'
:
case
'1142'
:
case
'1143'
:
case
'1227'
:
case
'1370'
:
case
'2005'
:
return
DBALException
::
ERROR_ACCESS_DENIED
;
case
'1048'
:
case
'1121'
:
case
'1138'
:
case
'1171'
:
case
'1252'
:
case
'1263'
:
case
'1566'
:
return
DBALException
::
ERROR_NOT_NULL
;
}
return
0
;
...
...
lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php
View file @
47b0aec4
...
...
@@ -112,51 +112,41 @@ class Driver implements \Doctrine\DBAL\Driver, ExceptionConverterDriver
*/
public
function
convertExceptionCode
(
\Exception
$exception
)
{
if
(
strpos
(
$exception
->
getMessage
(),
'duplicate key value violates unique constraint'
)
!==
false
)
{
return
DBALException
::
ERROR_DUPLICATE_KEY
;
}
switch
(
$exception
->
getCode
()
)
{
case
'23502'
:
return
DBALException
::
ERROR_NOT_NULL
;
if
(
$exception
->
getCode
()
===
"42P01"
)
{
return
DBALException
::
ERROR_UNKNOWN_TABLE
;
}
case
'23503'
:
return
DBALException
::
ERROR_FOREIGN_KEY_CONSTRAINT
;
if
(
$exception
->
getCode
()
===
"42P07"
)
{
return
DBALException
::
ERROR_TABLE_ALREADY_EXISTS
;
}
case
'23505'
:
return
DBALException
::
ERROR_DUPLICATE_KEY
;
if
(
$exception
->
getCode
()
===
"23503"
)
{
return
DBALException
::
ERROR_FOREIGN_KEY_CONSTRAINT
;
}
case
'42601'
:
return
DBALException
::
ERROR_SYNTAX
;
if
(
$exception
->
getCode
()
===
"23502"
)
{
return
DBALException
::
ERROR_NOT_NULL
;
}
case
'42702'
:
return
DBALException
::
ERROR_NON_UNIQUE_FIELD_NAME
;
if
(
$exception
->
getCode
()
===
"42703"
)
{
return
DBALException
::
ERROR_BAD_FIELD_NAME
;
}
case
'42703'
:
return
DBALException
::
ERROR_BAD_FIELD_NAME
;
if
(
$exception
->
getCode
()
===
"42702"
)
{
return
DBALException
::
ERROR_NON_UNIQUE_FIELD_NAME
;
}
case
'42P01'
:
return
DBALException
::
ERROR_UNKNOWN_TABLE
;
if
(
$exception
->
getCode
()
===
"42601"
)
{
return
DBALException
::
ERROR_SYNTAX
;
}
if
(
stripos
(
$exception
->
getMessage
(),
'password authentication failed for user'
)
!==
false
)
{
return
DBALException
::
ERROR_ACCESS_DENIED
;
}
case
'42P07'
:
return
DBALException
::
ERROR_TABLE_ALREADY_EXISTS
;
if
(
stripos
(
$exception
->
getMessage
(),
'Name or service not known'
)
!==
false
)
{
return
DBALException
::
ERROR_ACCESS_DENIED
;
}
if
(
stripos
(
$exception
->
getMessage
(),
'does not exist'
)
!==
false
)
{
return
DBALException
::
ERROR_ACCESS_DENIED
;
case
'7'
:
// In some case (mainly connection errors) the PDO exception does not provide a SQLSTATE via its code.
// The exception code is always set to 7 here.
// We have to match against the SQLSTATE in the error message in these cases.
if
(
strpos
(
$exception
->
getMessage
(),
'SQLSTATE[08006]'
)
!==
false
)
{
return
DBALException
::
ERROR_ACCESS_DENIED
;
}
break
;
}
return
0
;
}
}
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