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
19776904
Commit
19776904
authored
Jul 25, 2011
by
Alexander
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DBAL-138] Connection::quote now supports both DBAL and PDO types
parent
d096f0aa
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
23 deletions
+38
-23
Connection.php
lib/Doctrine/DBAL/Connection.php
+28
-22
ConnectionTest.php
tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
+10
-1
No files found.
lib/Doctrine/DBAL/Connection.php
View file @
19776904
...
@@ -556,7 +556,8 @@ class Connection implements DriverConnection
...
@@ -556,7 +556,8 @@ class Connection implements DriverConnection
{
{
$this
->
connect
();
$this
->
connect
();
return
$this
->
_conn
->
quote
(
$input
,
$type
);
list
(
$value
,
$bindingType
)
=
$this
->
getBindingInfo
(
$input
,
$type
);
return
$this
->
_conn
->
quote
(
$input
,
$bindingType
);
}
}
/**
/**
...
@@ -1069,15 +1070,7 @@ class Connection implements DriverConnection
...
@@ -1069,15 +1070,7 @@ class Connection implements DriverConnection
$typeIndex
=
$bindIndex
+
$typeOffset
;
$typeIndex
=
$bindIndex
+
$typeOffset
;
if
(
isset
(
$types
[
$typeIndex
]))
{
if
(
isset
(
$types
[
$typeIndex
]))
{
$type
=
$types
[
$typeIndex
];
$type
=
$types
[
$typeIndex
];
if
(
is_string
(
$type
))
{
list
(
$value
,
$bindingType
)
=
$this
->
getBindingInfo
(
$value
,
$type
);
$type
=
Type
::
getType
(
$type
);
}
if
(
$type
instanceof
Type
)
{
$value
=
$type
->
convertToDatabaseValue
(
$value
,
$this
->
_platform
);
$bindingType
=
$type
->
getBindingType
();
}
else
{
$bindingType
=
$type
;
// PDO::PARAM_* constants
}
$stmt
->
bindValue
(
$bindIndex
,
$value
,
$bindingType
);
$stmt
->
bindValue
(
$bindIndex
,
$value
,
$bindingType
);
}
else
{
}
else
{
$stmt
->
bindValue
(
$bindIndex
,
$value
);
$stmt
->
bindValue
(
$bindIndex
,
$value
);
...
@@ -1089,6 +1082,24 @@ class Connection implements DriverConnection
...
@@ -1089,6 +1082,24 @@ class Connection implements DriverConnection
foreach
(
$params
as
$name
=>
$value
)
{
foreach
(
$params
as
$name
=>
$value
)
{
if
(
isset
(
$types
[
$name
]))
{
if
(
isset
(
$types
[
$name
]))
{
$type
=
$types
[
$name
];
$type
=
$types
[
$name
];
list
(
$value
,
$bindingType
)
=
$this
->
getBindingInfo
(
$value
,
$type
);
$stmt
->
bindValue
(
$name
,
$value
,
$bindingType
);
}
else
{
$stmt
->
bindValue
(
$name
,
$value
);
}
}
}
}
/**
* Gets the binding type of a given type. The given type can be a PDO or DBAL mapping type.
*
* @param mixed $value The value to bind
* @param mixed $type The type to bind (PDO or DBAL)
* @return array [0] => the (escaped) value, [1] => the binding type
*/
private
function
getBindingInfo
(
$value
,
$type
)
{
if
(
is_string
(
$type
))
{
if
(
is_string
(
$type
))
{
$type
=
Type
::
getType
(
$type
);
$type
=
Type
::
getType
(
$type
);
}
}
...
@@ -1098,12 +1109,7 @@ class Connection implements DriverConnection
...
@@ -1098,12 +1109,7 @@ class Connection implements DriverConnection
}
else
{
}
else
{
$bindingType
=
$type
;
// PDO::PARAM_* constants
$bindingType
=
$type
;
// PDO::PARAM_* constants
}
}
$stmt
->
bindValue
(
$name
,
$value
,
$bindingType
);
return
array
(
$value
,
$bindingType
);
}
else
{
$stmt
->
bindValue
(
$name
,
$value
);
}
}
}
}
}
/**
/**
...
...
tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php
View file @
19776904
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
Doctrine\Tests\DBAL\Functional
;
namespace
Doctrine\Tests\DBAL\Functional
;
use
Doctrine\DBAL\ConnectionException
;
use
Doctrine\DBAL\ConnectionException
;
use
Doctrine\DBAL\Types\Type
;
require_once
__DIR__
.
'/../../TestInit.php'
;
require_once
__DIR__
.
'/../../TestInit.php'
;
...
@@ -207,4 +208,12 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
...
@@ -207,4 +208,12 @@ class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$conn
->
executeQuery
(
$conn
->
getDatabasePlatform
()
->
getDummySelectSQL
());
$conn
->
executeQuery
(
$conn
->
getDatabasePlatform
()
->
getDummySelectSQL
());
});
});
}
}
/**
* Tests that the quote function accepts DBAL and PDO types.
*/
public
function
testQuote
()
{
$this
->
assertEquals
(
$this
->
_conn
->
quote
(
"foo"
,
Type
::
STRING
),
$this
->
_conn
->
quote
(
"foo"
,
\PDO
::
PARAM_STR
));
}
}
}
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