<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Fri May 24 14:45:05 UTC 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://www.doctrine-project.org/jira/si/jira.issueviews:issue-xml/DDC-2224/DDC-2224.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Doctrine Project</title>
    <link>http://www.doctrine-project.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>5.2.7</version>
        <build-number>850</build-number>
        <build-date>21-02-2013</build-date>
    </build-info>

<item>
            <title>[DDC-2224] convertToDatabaseValueSQL() is not honored for DQL query parameters</title>
                <link>http://www.doctrine-project.org/jira/browse/DDC-2224</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;Following discussion on Google Groups:&lt;br/&gt;
&lt;a href=&quot;https://groups.google.com/d/msg/doctrine-dev/-/gG-VGiAGQiMJ&quot; class=&quot;external-link&quot;&gt;https://groups.google.com/d/msg/doctrine-dev/-/gG-VGiAGQiMJ&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When using a mapping type which declares &lt;tt&gt;convertToDatabaseValueSQL()&lt;/tt&gt;, this method is not invoked when passing a value as parameter to a DQL query.&lt;/p&gt;

&lt;p&gt;For example, if I declare a mapping type &lt;tt&gt;MyType&lt;/tt&gt;:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
class MyType &lt;span class=&quot;code-keyword&quot;&gt;extends&lt;/span&gt; \Doctrine\DBAL\Types\Type
{
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function canRequireSQLConversion()
    {
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;
    }

    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; sprintf(&apos;FUNCTION(%s)&apos;, $sqlExpr);
    }

    &lt;span class=&quot;code-comment&quot;&gt;// ...
&lt;/span&gt;}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And pass a parameter with this type to a DQL query:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
$query = $em-&amp;gt;createQuery(&apos;SELECT e FROM Entity e WHERE e.field = :field&apos;);
$query-&amp;gt;setParameter(&apos;field&apos;, $value, &apos;MyType&apos;);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I would expect the following SQL to be generated:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
SELECT ... WHERE ... = FUNCTION(?)
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;But the current SQL generated is the following:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
SELECT ... WHERE ... = ?
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</description>
                <environment></environment>
            <key id="14350">DDC-2224</key>
            <summary>convertToDatabaseValueSQL() is not honored for DQL query parameters</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="2" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/critical.png">Critical</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="6">Invalid</resolution>
                    <security id="10000">All</security>
                        <assignee username="beberlei">Benjamin Eberlei</assignee>
                                <reporter username="benjamin">Benjamin Morel</reporter>
                        <labels>
                    </labels>
                <created>Sat, 5 Jan 2013 14:01:07 +0000</created>
                <updated>Thu, 4 Apr 2013 17:51:22 +0000</updated>
                    <resolved>Thu, 4 Apr 2013 17:51:22 +0000</resolved>
                            <version>Git Master</version>
                <version>2.3.1</version>
                                                <component>ORM</component>
                        <due></due>
                    <votes>1</votes>
                        <watches>2</watches>
                        <comments>
                    <comment id="19488" author="mnapoli" created="Fri, 8 Feb 2013 10:00:44 +0000"  >&lt;p&gt;Fix proposal: &lt;a href=&quot;https://github.com/doctrine/doctrine2/pull/574&quot; class=&quot;external-link&quot;&gt;https://github.com/doctrine/doctrine2/pull/574&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="19489" author="mnapoli" created="Fri, 8 Feb 2013 10:16:49 +0000"  >&lt;p&gt;It turns out convertToDatabaseValue() is not called as well.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
class MyType &lt;span class=&quot;code-keyword&quot;&gt;extends&lt;/span&gt; \Doctrine\DBAL\Types\Type
{
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; serialize($value);
    }

    &lt;span class=&quot;code-comment&quot;&gt;// ...
&lt;/span&gt;}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The SQL generated should not change, but the parameter should go through &quot;convertToDatabaseValue&quot;, which is not the case.&lt;/p&gt;</comment>
                    <comment id="19490" author="benjamin" created="Fri, 8 Feb 2013 10:25:09 +0000"  >&lt;p&gt;Have you passed the type as the third parameter to setParameter() ?&lt;br/&gt;
Because this works fine for me!&lt;/p&gt;</comment>
                    <comment id="19491" author="mnapoli" created="Fri, 8 Feb 2013 10:29:16 +0000"  >&lt;p&gt;You are right!&lt;/p&gt;

&lt;p&gt;But shouldn&apos;t the Type mapping be taken into account anyway? I makes sense to me at least (a column has a type, when I specify a parameter for this column, it is for this type), but maybe that was just designed that way?&lt;/p&gt;</comment>
                    <comment id="19492" author="benjamin" created="Fri, 8 Feb 2013 10:49:23 +0000"  >&lt;p&gt;That would make sense, but I think that because of the flexibility of DQL, it&apos;s not always obvious what type you want to use.&lt;br/&gt;
Say you have some complex expression like:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
WHERE entity.field = SomeDQLFunction(:value, entity.otherField)
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then we can&apos;t be sure what mapping type to use here (unless we can infer it from &lt;tt&gt;SomeDQLFunction&lt;/tt&gt;, but this is yet another story).&lt;br/&gt;
Though I do agree that would be great to have the type inferred automatically when you do a simple:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
WHERE entity.field = :value
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Here, there&apos;s no ambiguity, and if &lt;tt&gt;entity.field&lt;/tt&gt; has a custom mapping type, then I can&apos;t see a reason why it shouldn&apos;t be applied to the parameter by default.&lt;/p&gt;</comment>
                    <comment id="19493" author="mnapoli" created="Fri, 8 Feb 2013 11:27:10 +0000"  >&lt;p&gt;I made a failing test case, I&apos;ll see if I can work on that.&lt;/p&gt;

&lt;p&gt;I will open a separate ticket for this.&lt;/p&gt;

&lt;p&gt;Edit: &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DDC-2290&quot; class=&quot;external-link&quot;&gt;http://www.doctrine-project.org/jira/browse/DDC-2290&lt;/a&gt;&lt;/p&gt;</comment>
                </comments>
                <issuelinks>
                        <issuelinktype id="10000">
                <name>Duplicate</name>
                                <outwardlinks description="duplicates">
                            <issuelink>
            <issuekey id="14380">DDC-2240</issuekey>
        </issuelink>
                    </outwardlinks>
                                            </issuelinktype>
                    </issuelinks>
                <attachments>
                    <attachment id="11369" name="DDC2224Test.php" size="1539" author="benjamin" created="Fri, 11 Jan 2013 16:24:51 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>