Skip to content
Browse files

[DDC-2224] convertToDatabaseValueSQL() is not honored for DQL query p…

…arameters

Fix + test
  • Loading branch information...
1 parent f0674ea commit 620bb213e1e7de22db6a71260a0983ebab218b9e @mnapoli mnapoli committed Feb 8, 2013
View
2 lib/Doctrine/ORM/AbstractQuery.php
@@ -179,7 +179,7 @@ public function getParameters()
*
* @param mixed $key The key (index or name) of the bound parameter.
*
- * @return mixed The value of the bound parameter.
+ * @return Query\Parameter|null The value of the bound parameter.
*/
public function getParameter($key)
{
View
6 lib/Doctrine/ORM/Query/SqlWalker.php
@@ -2072,6 +2072,12 @@ public function walkInputParameter($inputParam)
{
$this->parserResult->addParameterMapping($inputParam->name, $this->sqlParamIndex++);
+ $parameter = $this->query->getParameter($inputParam->name);
+ if ($parameter && Type::hasType($parameter->getType())) {
+ $parameterType = Type::getType($parameter->getType());
+ return $parameterType->convertToDatabaseValueSQL('?', $this->platform);
+ }
+
return '?';
}
View
76 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2224Test.php
@@ -0,0 +1,76 @@
+<?php
+
+namespace Doctrine\Tests\ORM\Functional\Ticket;
+
+use Doctrine\DBAL\Types\Type;
+use Doctrine\DBAL\Platforms\AbstractPlatform;
+
+/**
+ * @group DDC-2224
+ */
+class DDC2224Test extends \Doctrine\Tests\OrmFunctionalTestCase
+{
+ public static function setUpBeforeClass()
+ {
+ parent::setUpBeforeClass();
+
+ \Doctrine\DBAL\Types\Type::addType('DDC2224Type', __NAMESPACE__ . '\DDC2224Type');
+ }
+
+ public function testIssue()
+ {
+ $dql = 'SELECT e FROM ' . __NAMESPACE__ . '\DDC2224Entity e WHERE e.field = :field';
+ $query = $this->_em->createQuery($dql);
+ $query->setParameter('field', 'test', 'DDC2224Type');
+
+ $this->assertStringEndsWith('.field = FUNCTION(?)', $query->getSQL());
+ }
+}
+
+class DDC2224Type extends Type
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
+ {
+ return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
+ }
+
+ public function getName()
+ {
+ return 'DDC2224Type';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function canRequireSQLConversion()
+ {
+ return true;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform)
+ {
+ return sprintf('FUNCTION(%s)', $sqlExpr);
+ }
+}
+
+/**
+ * @Entity
+ */
+class DDC2224Entity
+{
+ /**
+ * @Id @GeneratedValue @Column(type="integer")
+ */
+ public $id;
+
+ /**
+ * @Column(type="DDC2224Type")
+ */
+ public $field;
+}

0 comments on commit 620bb21

Please sign in to comment.
Something went wrong with that request. Please try again.