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
e83c2d00
Commit
e83c2d00
authored
Dec 30, 2013
by
Steve Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement ExceptionConverterDriver in Oracle drivers
parent
9ec63e25
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
16 deletions
+101
-16
Driver.php
lib/Doctrine/DBAL/Driver/OCI8/Driver.php
+48
-9
Driver.php
lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php
+53
-7
No files found.
lib/Doctrine/DBAL/Driver/OCI8/Driver.php
View file @
e83c2d00
...
...
@@ -20,6 +20,8 @@
namespace
Doctrine\DBAL\Driver\OCI8
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Driver\ExceptionConverterDriver
;
use
Doctrine\DBAL\Platforms\OraclePlatform
;
use
Doctrine\DBAL\Schema\OracleSchemaManager
;
...
...
@@ -29,21 +31,25 @@ use Doctrine\DBAL\Schema\OracleSchemaManager;
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
class
Driver
implements
\Doctrine\DBAL\Driver
class
Driver
implements
\Doctrine\DBAL\Driver
,
ExceptionConverterDriver
{
/**
* {@inheritdoc}
*/
public
function
connect
(
array
$params
,
$username
=
null
,
$password
=
null
,
array
$driverOptions
=
array
())
{
return
new
OCI8Connection
(
$username
,
$password
,
$this
->
_constructDsn
(
$params
),
isset
(
$params
[
'charset'
])
?
$params
[
'charset'
]
:
null
,
isset
(
$params
[
'sessionMode'
])
?
$params
[
'sessionMode'
]
:
OCI_DEFAULT
,
isset
(
$params
[
'persistent'
])
?
$params
[
'persistent'
]
:
false
);
try
{
return
new
OCI8Connection
(
$username
,
$password
,
$this
->
_constructDsn
(
$params
),
isset
(
$params
[
'charset'
])
?
$params
[
'charset'
]
:
null
,
isset
(
$params
[
'sessionMode'
])
?
$params
[
'sessionMode'
]
:
OCI_DEFAULT
,
isset
(
$params
[
'persistent'
])
?
$params
[
'persistent'
]
:
false
);
}
catch
(
OCI8Exception
$e
)
{
throw
DBALException
::
driverException
(
$this
,
$e
);
}
}
/**
...
...
@@ -130,6 +136,39 @@ class Driver implements \Doctrine\DBAL\Driver
*/
public
function
convertExceptionCode
(
\Exception
$exception
)
{
switch
(
$exception
->
getCode
())
{
case
'1'
:
case
'2299'
:
case
'38911'
:
return
DBALException
::
ERROR_DUPLICATE_KEY
;
case
'904'
:
return
DBALException
::
ERROR_BAD_FIELD_NAME
;
case
'918'
:
case
'960'
:
return
DBALException
::
ERROR_NON_UNIQUE_FIELD_NAME
;
case
'923'
:
return
DBALException
::
ERROR_SYNTAX
;
case
'942'
:
return
DBALException
::
ERROR_UNKNOWN_TABLE
;
case
'955'
:
return
DBALException
::
ERROR_TABLE_ALREADY_EXISTS
;
case
'1017'
:
case
'12545'
:
return
DBALException
::
ERROR_ACCESS_DENIED
;
case
'1400'
:
return
DBALException
::
ERROR_NOT_NULL
;
case
'2292'
:
return
DBALException
::
ERROR_FOREIGN_KEY_CONSTRAINT
;
}
return
0
;
}
}
lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php
View file @
e83c2d00
...
...
@@ -20,6 +20,8 @@
namespace
Doctrine\DBAL\Driver\PDOOracle
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Driver\ExceptionConverterDriver
;
use
Doctrine\DBAL\Driver\PDOConnection
;
use
Doctrine\DBAL\Platforms\OraclePlatform
;
use
Doctrine\DBAL\Schema\OracleSchemaManager
;
...
...
@@ -32,19 +34,23 @@ use Doctrine\DBAL\Schema\OracleSchemaManager;
* which leads us to the recommendation to use the "oci8" driver to connect
* to Oracle instead.
*/
class
Driver
implements
\Doctrine\DBAL\Driver
class
Driver
implements
\Doctrine\DBAL\Driver
,
ExceptionConverterDriver
{
/**
* {@inheritdoc}
*/
public
function
connect
(
array
$params
,
$username
=
null
,
$password
=
null
,
array
$driverOptions
=
array
())
{
return
new
PDOConnection
(
$this
->
_constructPdoDsn
(
$params
),
$username
,
$password
,
$driverOptions
);
try
{
return
new
PDOConnection
(
$this
->
_constructPdoDsn
(
$params
),
$username
,
$password
,
$driverOptions
);
}
catch
(
\PDOException
$e
)
{
throw
DBALException
::
driverException
(
$this
,
$e
);
}
}
/**
...
...
@@ -136,6 +142,46 @@ class Driver implements \Doctrine\DBAL\Driver
*/
public
function
convertExceptionCode
(
\Exception
$exception
)
{
$errorCode
=
$exception
->
getCode
();
// 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
];
}
switch
(
$errorCode
)
{
case
'1'
:
case
'2299'
:
case
'38911'
:
return
DBALException
::
ERROR_DUPLICATE_KEY
;
case
'904'
:
return
DBALException
::
ERROR_BAD_FIELD_NAME
;
case
'918'
:
case
'960'
:
return
DBALException
::
ERROR_NON_UNIQUE_FIELD_NAME
;
case
'923'
:
return
DBALException
::
ERROR_SYNTAX
;
case
'942'
:
return
DBALException
::
ERROR_UNKNOWN_TABLE
;
case
'955'
:
return
DBALException
::
ERROR_TABLE_ALREADY_EXISTS
;
case
'1017'
:
case
'12545'
:
return
DBALException
::
ERROR_ACCESS_DENIED
;
case
'1400'
:
return
DBALException
::
ERROR_NOT_NULL
;
case
'2292'
:
return
DBALException
::
ERROR_FOREIGN_KEY_CONSTRAINT
;
}
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