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
78790d5c
Commit
78790d5c
authored
Nov 13, 2013
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add exception handling for PostgreSQL
parent
f4635a9b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
6 deletions
+52
-6
Driver.php
lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php
+52
-6
No files found.
lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php
View file @
78790d5c
...
@@ -20,6 +20,8 @@
...
@@ -20,6 +20,8 @@
namespace
Doctrine\DBAL\Driver\PDOPgSql
;
namespace
Doctrine\DBAL\Driver\PDOPgSql
;
use
Doctrine\DBAL\Platforms
;
use
Doctrine\DBAL\Platforms
;
use
Doctrine\DBAL\DBALException
;
use
PDOException
;
/**
/**
* Driver that connects through pdo_pgsql.
* Driver that connects through pdo_pgsql.
...
@@ -33,12 +35,16 @@ class Driver implements \Doctrine\DBAL\Driver
...
@@ -33,12 +35,16 @@ class Driver implements \Doctrine\DBAL\Driver
*/
*/
public
function
connect
(
array
$params
,
$username
=
null
,
$password
=
null
,
array
$driverOptions
=
array
())
public
function
connect
(
array
$params
,
$username
=
null
,
$password
=
null
,
array
$driverOptions
=
array
())
{
{
try
{
return
new
\Doctrine\DBAL\Driver\PDOConnection
(
return
new
\Doctrine\DBAL\Driver\PDOConnection
(
$this
->
_constructPdoDsn
(
$params
),
$this
->
_constructPdoDsn
(
$params
),
$username
,
$username
,
$password
,
$password
,
$driverOptions
$driverOptions
);
);
}
catch
(
PDOException
$e
)
{
throw
DBALException
::
driverException
(
$this
,
$e
);
}
}
}
/**
/**
...
@@ -105,6 +111,46 @@ class Driver implements \Doctrine\DBAL\Driver
...
@@ -105,6 +111,46 @@ class Driver implements \Doctrine\DBAL\Driver
*/
*/
public
function
convertExceptionCode
(
\Exception
$exception
)
public
function
convertExceptionCode
(
\Exception
$exception
)
{
{
if
(
strpos
(
$exception
->
getMessage
(),
'duplicate key value violates unique constraint'
)
!==
false
)
{
return
DBALException
::
ERROR_DUPLICATE_KEY
;
}
if
(
$exception
->
getCode
()
===
"42P01"
)
{
return
DBALException
::
ERROR_UNKNOWN_TABLE
;
}
if
(
$exception
->
getCode
()
===
"42P07"
)
{
return
DBALException
::
ERROR_TABLE_ALREADY_EXISTS
;
}
if
(
$exception
->
getCode
()
===
"23503"
)
{
return
DBALException
::
ERROR_FOREIGN_KEY_CONSTRAINT
;
}
if
(
$exception
->
getCode
()
===
"23502"
)
{
return
DBALException
::
ERROR_NOT_NULL
;
}
if
(
$exception
->
getCode
()
===
"42703"
)
{
return
DBALException
::
ERROR_BAD_FIELD_NAME
;
}
if
(
$exception
->
getCode
()
===
"42702"
)
{
return
DBALException
::
ERROR_NON_UNIQUE_FIELD_NAME
;
}
if
(
$exception
->
getCode
()
===
"42601"
)
{
return
DBALException
::
ERROR_SYNTAX
;
}
if
(
stripos
(
$exception
->
getMessage
(),
'password authentication failed for user'
)
!==
false
)
{
return
DBALException
::
ERROR_ACCESS_DENIED
;
}
if
(
stripos
(
$exception
->
getMessage
(),
'Name or service not known'
)
!==
false
)
{
return
DBALException
::
ERROR_ACCESS_DENIED
;
}
return
0
;
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