<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Wed Jun 19 16:05:16 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/DC-972/DC-972.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>[DC-972] MySQL field aliases with triple ticks</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-972</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;In revision 7691 something has happened. Ever since I updated my Doctrine to that revision all my queries having &quot; ... fieldname AS aliasname ... &quot; go crazy and make the PHP to throw an exception, like this:&lt;/p&gt;

&lt;p&gt;&apos;Doctrine_Connection_Mysql_Exception&apos; with message &apos;SQLSTATE&lt;span class=&quot;error&quot;&gt;&amp;#91;42S22&amp;#93;&lt;/span&gt;: Column not found: 1054 Unknown column &apos;t.`id`&apos; in &apos;field list&apos;.  Failing Query:&lt;br/&gt;
&quot;SELECT `t`.`id` AS `t_&lt;em&gt;id`, `t`.```id``` AS `t&lt;/em&gt;&lt;em&gt;0`, `t`.```name``` AS `t&lt;/em&gt;&lt;em&gt;1`, `t`.`id` AS `t&lt;/em&gt;&lt;em&gt;0`, `t`.`name` AS `t&lt;/em&gt;_1` FROM `territoryCombined` `t` ORDER BY `t`.`name` asc&quot;&apos;&lt;br/&gt;
in ...path here.../doctrine/lib/Doctrine/Connection.php:1082&lt;/p&gt;

&lt;p&gt;The problem is that the DQL parser somewhere along the process encapsualtes aliases in ticks, but then it does it again in lib/Doctrine/Formatter.php : quoteIdentifier() , which is called in lib/Doctrine/Connection : quoteIdentifier() , which is called in lib/Doctrine/Query.php : processPendingFields() @ between lines 485 and 512. The problem is that by the time the alias name gets to line 507 it is already encapsualted in ticks, but it does it again. At the end we end up with ```alias``` , which is not good.&lt;/p&gt;

&lt;p&gt;It only happens to aliases. If I say select(&apos;*&apos;) or select(&quot;t.id, t.name&quot;) then it executes properly. Only the aliases couse problems.&lt;/p&gt;

&lt;p&gt;A test query:&lt;/p&gt;

&lt;p&gt;$vTerritories = Doctrine_Query::create()&lt;br/&gt;
                    -&amp;gt;select(&quot;t.id as territory_id, t.name as territory_name&quot;)&lt;br/&gt;
                    -&amp;gt;from(&apos;TerritoryCombined t&apos;)&lt;br/&gt;
                    -&amp;gt;orderBy(&apos;t.name asc&apos;)&lt;br/&gt;
                    -&amp;gt;fetchArray();&lt;/p&gt;


&lt;p&gt;MY PROPOSED PATCH:&lt;/p&gt;

&lt;p&gt;If I change the Formatter::quoteIdentifier() to this:&lt;/p&gt;

&lt;p&gt;    public function quoteIdentifier($str, $checkOption = true)&lt;/p&gt;
    {
        $tmp = $this-&amp;gt;conn-&amp;gt;identifier_quoting; // I move up this line to here because I need it

        if ( (substr($str, 0, 1) == $tmp[&apos;start&apos;]) &amp;amp;&amp;amp; (substr($str, -1) == $tmp[&apos;end&apos;]) ) return $str; // new line; is it already quoted? if yes, then don&apos;t do it again

        // the rest is unchanged
    }

&lt;p&gt;then it works correctly. Please note I only tested that in MySQL, as we use MySQL in all our projects.&lt;/p&gt;</description>
                <environment>MySQL 5, PHP 5</environment>
            <key id="12396">DC-972</key>
            <summary>MySQL field aliases with triple ticks</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/blocker.png">Blocker</priority>
                    <status id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/open.png">Open</status>
                    <resolution id="-1">Unresolved</resolution>
                                <assignee username="guilhermeblanco">Guilherme Blanco</assignee>
                                <reporter username="hroland">Roland Huszti</reporter>
                        <labels>
                    </labels>
                <created>Wed, 16 Feb 2011 11:14:24 +0000</created>
                <updated>Wed, 16 Feb 2011 11:14:24 +0000</updated>
                                    <version>1.2.3</version>
                                                <component>Query</component>
                        <due></due>
                    <votes>1</votes>
                        <watches>1</watches>
                                <attachments>
                    <attachment id="10941" name="BaseTerritoryCombined.php" size="2337" author="hroland" created="Wed, 16 Feb 2011 11:14:24 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>