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
4c805843
Unverified
Commit
4c805843
authored
Dec 31, 2017
by
Sergei Morozov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added conversion of DBAL constants to PDO ones for PDOStatement
parent
b24fe977
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
0 deletions
+69
-0
PDOStatement.php
lib/Doctrine/DBAL/Driver/PDOStatement.php
+69
-0
No files found.
lib/Doctrine/DBAL/Driver/PDOStatement.php
View file @
4c805843
...
...
@@ -19,7 +19,9 @@
namespace
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\FetchMode
;
use
Doctrine\DBAL\ParameterType
;
use
PDO
;
/**
* The PDO implementation of the Statement interface.
...
...
@@ -29,6 +31,29 @@ use Doctrine\DBAL\ParameterType;
*/
class
PDOStatement
extends
\PDOStatement
implements
Statement
{
/**
* @var int[]
*/
private
const
PARAM_TYPE_MAP
=
[
ParameterType
::
NULL
=>
PDO
::
PARAM_NULL
,
ParameterType
::
INTEGER
=>
PDO
::
PARAM_INT
,
ParameterType
::
STRING
=>
PDO
::
PARAM_STR
,
ParameterType
::
LARGE_OBJECT
=>
PDO
::
PARAM_LOB
,
ParameterType
::
BOOLEAN
=>
PDO
::
PARAM_BOOL
,
];
/**
* @var int[]
*/
private
const
FETCH_MODE_MAP
=
[
FetchMode
::
ASSOCIATIVE
=>
PDO
::
FETCH_ASSOC
,
FetchMode
::
NUMERIC
=>
PDO
::
FETCH_NUM
,
FetchMode
::
MIXED
=>
PDO
::
FETCH_BOTH
,
FetchMode
::
STANDARD_OBJECT
=>
PDO
::
FETCH_OBJ
,
FetchMode
::
COLUMN
=>
PDO
::
FETCH_COLUMN
,
FetchMode
::
CUSTOM_OBJECT
=>
PDO
::
FETCH_CLASS
,
];
/**
* Protected constructor.
*/
...
...
@@ -41,6 +66,8 @@ class PDOStatement extends \PDOStatement implements Statement
*/
public
function
setFetchMode
(
$fetchMode
,
$arg2
=
null
,
$arg3
=
null
)
{
$fetchMode
=
$this
->
convertFetchMode
(
$fetchMode
);
// This thin wrapper is necessary to shield against the weird signature
// of PDOStatement::setFetchMode(): even if the second and third
// parameters are optional, PHP will not let us remove it from this
...
...
@@ -65,6 +92,8 @@ class PDOStatement extends \PDOStatement implements Statement
*/
public
function
bindValue
(
$param
,
$value
,
$type
=
ParameterType
::
STRING
)
{
$type
=
$this
->
convertParamType
(
$type
);
try
{
return
parent
::
bindValue
(
$param
,
$value
,
$type
);
}
catch
(
\PDOException
$exception
)
{
...
...
@@ -77,6 +106,8 @@ class PDOStatement extends \PDOStatement implements Statement
*/
public
function
bindParam
(
$column
,
&
$variable
,
$type
=
ParameterType
::
STRING
,
$length
=
null
,
$driverOptions
=
null
)
{
$type
=
$this
->
convertParamType
(
$type
);
try
{
return
parent
::
bindParam
(
$column
,
$variable
,
$type
,
$length
,
$driverOptions
);
}
catch
(
\PDOException
$exception
)
{
...
...
@@ -115,6 +146,8 @@ class PDOStatement extends \PDOStatement implements Statement
*/
public
function
fetch
(
$fetchMode
=
null
,
$cursorOrientation
=
\PDO
::
FETCH_ORI_NEXT
,
$cursorOffset
=
0
)
{
$fetchMode
=
$this
->
convertFetchMode
(
$fetchMode
);
try
{
if
(
$fetchMode
===
null
&&
\PDO
::
FETCH_ORI_NEXT
===
$cursorOrientation
&&
0
===
$cursorOffset
)
{
return
parent
::
fetch
();
...
...
@@ -139,6 +172,8 @@ class PDOStatement extends \PDOStatement implements Statement
*/
public
function
fetchAll
(
$fetchMode
=
null
,
$fetchArgument
=
null
,
$ctorArgs
=
null
)
{
$fetchMode
=
$this
->
convertFetchMode
(
$fetchMode
);
try
{
if
(
$fetchMode
===
null
&&
null
===
$fetchArgument
&&
null
===
$ctorArgs
)
{
return
parent
::
fetchAll
();
...
...
@@ -169,4 +204,38 @@ class PDOStatement extends \PDOStatement implements Statement
throw
new
PDOException
(
$exception
);
}
}
/**
* Converts DBAL parameter type to PDO parameter type
*
* @param int $type Parameter type
* @return int
*/
private
function
convertParamType
(
int
$type
)
:
int
{
if
(
!
isset
(
self
::
PARAM_TYPE_MAP
[
$type
]))
{
throw
new
\InvalidArgumentException
(
'Invalid parameter type: '
.
$type
);
}
return
self
::
PARAM_TYPE_MAP
[
$type
];
}
/**
* Converts DBAL fetch mode to PDO fetch mode
*
* @param int|null $fetchMode Fetch mode
* @return int|null
*/
private
function
convertFetchMode
(
?
int
$fetchMode
)
:
?
int
{
if
(
$fetchMode
===
null
)
{
return
null
;
}
if
(
!
isset
(
self
::
FETCH_MODE_MAP
[
$fetchMode
]))
{
throw
new
\InvalidArgumentException
(
'Invalid fetch mode: '
.
$fetchMode
);
}
return
self
::
FETCH_MODE_MAP
[
$fetchMode
];
}
}
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