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
f4635a9b
Commit
f4635a9b
authored
Nov 13, 2013
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fully implement MySQL support for Exception handling
parent
89592347
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
15 deletions
+46
-15
DBALException.php
lib/Doctrine/DBAL/DBALException.php
+0
-1
Driver.php
lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php
+43
-11
Driver.php
lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php
+1
-1
ExceptionTest.php
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
+2
-2
No files found.
lib/Doctrine/DBAL/DBALException.php
View file @
f4635a9b
...
...
@@ -28,7 +28,6 @@ class DBALException extends \Exception
const
ERROR_NOT_NULL
=
5
;
const
ERROR_BAD_FIELD_NAME
=
6
;
const
ERROR_NON_UNIQUE_FIELD_NAME
=
7
;
const
ERROR_NOT_UNIQUE
=
8
;
const
ERROR_SYNTAX
=
9
;
const
ERROR_UNABLE_TO_OPEN
=
10
;
const
ERROR_WRITE_READONLY
=
11
;
...
...
lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php
View file @
f4635a9b
...
...
@@ -21,6 +21,7 @@ namespace Doctrine\DBAL\Driver\PDOMySql;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\DBALException
;
use
PDOException
;
/**
* PDO MySql driver.
...
...
@@ -34,12 +35,16 @@ class Driver implements \Doctrine\DBAL\Driver
*/
public
function
connect
(
array
$params
,
$username
=
null
,
$password
=
null
,
array
$driverOptions
=
array
())
{
$conn
=
new
\Doctrine\DBAL\Driver\PDOConnection
(
$this
->
_constructPdoDsn
(
$params
),
$username
,
$password
,
$driverOptions
);
try
{
$conn
=
new
\Doctrine\DBAL\Driver\PDOConnection
(
$this
->
_constructPdoDsn
(
$params
),
$username
,
$password
,
$driverOptions
);
}
catch
(
PDOException
$e
)
{
throw
DBALException
::
driverException
(
$this
,
$e
);
}
return
$conn
;
}
...
...
@@ -116,17 +121,44 @@ class Driver implements \Doctrine\DBAL\Driver
public
function
convertExceptionCode
(
\Exception
$exception
)
{
switch
(
$exception
->
getCode
())
{
case
23000
:
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
;
}
case
'42S02'
:
return
DBALException
::
ERROR_UNKNOWN_TABLE
;
case
'42S01'
:
return
DBALException
::
ERROR_TABLE_ALREADY_EXISTS
;
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
;
}
if
(
strpos
(
$exception
->
getMessage
(),
' cannot be null'
))
{
return
DBALException
::
ERROR_NOT_NULL
;
}
}
return
0
;
...
...
lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php
View file @
f4635a9b
...
...
@@ -134,7 +134,7 @@ class Driver implements \Doctrine\DBAL\Driver
}
if
(
strpos
(
$exception
->
getMessage
(),
'is not unique'
)
!==
false
)
{
return
DBALException
::
ERROR_
NOT_UNIQUE
;
return
DBALException
::
ERROR_
DUPLICATE_KEY
;
}
if
(
strpos
(
$exception
->
getMessage
(),
'no such table:'
)
!==
false
)
{
...
...
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
View file @
f4635a9b
...
...
@@ -87,7 +87,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
}
$this
->
setExpectedException
(
'\Doctrine\DBAL\DBALException'
,
null
,
DBALException
::
ERROR_NOT_NULL
);
$this
->
_conn
->
insert
(
"notnull_table"
,
array
(
'id'
=>
1
));
$this
->
_conn
->
insert
(
"notnull_table"
,
array
(
'id'
=>
1
,
'value'
=>
null
));
}
public
function
testBadFieldNameException
()
...
...
@@ -137,7 +137,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
}
$this
->
_conn
->
insert
(
"unique_field_table"
,
array
(
'id'
=>
5
));
$this
->
setExpectedException
(
'\Doctrine\DBAL\DBALException'
,
null
,
DBALException
::
ERROR_
NOT_UNIQUE
);
$this
->
setExpectedException
(
'\Doctrine\DBAL\DBALException'
,
null
,
DBALException
::
ERROR_
DUPLICATE_KEY
);
$this
->
_conn
->
insert
(
"unique_field_table"
,
array
(
'id'
=>
5
));
}
...
...
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