<!--
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Tue Jun 18 07:31:02 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/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?jqlQuery=project+%3D+DC+AND+fixVersion+%3D+%221.2.3%22&tempMax=1000&field=key&field=summary
-->
<!-- If you wish to do custom client-side styling of RSS, uncomment this:
<?xml-stylesheet href="http://www.doctrine-project.org/jira/styles/jiraxml2html.xsl" type="text/xsl"?>
-->
<rss version="0.92">
    <channel>
        <title>Doctrine Project</title>
        <link>http://www.doctrine-project.org/jira/secure/IssueNavigator.jspa?reset=true&amp;jqlQuery=project+%3D+DC+AND+fixVersion+%3D+%221.2.3%22</link>
        <description>An XML representation of a search request</description>
                <language>en-us</language>
                        <issue start="0" end="66" total="66"/>
                <build-info>
            <version>5.2.7</version>
            <build-number>850</build-number>
            <build-date>21-02-2013</build-date>
        </build-info>
<item>
            <title>[DC-1040] allow queries with table joins across different databases</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-1040</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;I&apos;m currently working on a project which relies upon several databases declared in databases.yml in symfony 1.4.8.&lt;/p&gt;

&lt;p&gt;I was facing an issue that has already been raised by other people, namely that you can&apos;t join tables which reference each other among different mysql databases.&lt;/p&gt;

&lt;p&gt;I&apos;ve dug a bit in the Doctrine_Query class and came to a solution that is acceptable for us, and allows now to make joins accross databases. Description follows :&lt;/p&gt;

&lt;p&gt;first change is in the Doctrine_Core class, that gets stuffed with a new constant :&lt;br/&gt;
const ATTR_DATABASE_NAME                = 0x1DB;&lt;/p&gt;

&lt;p&gt;this constant allows us to add a new attribute to the databases.yml file as in :&lt;br/&gt;
  gesdoc:&lt;br/&gt;
    class: sfDoctrineDatabase&lt;br/&gt;
    param:&lt;br/&gt;
      dsn:      mysql:host=127.0.0.1;dbname=gesdoc&lt;br/&gt;
      username: root&lt;br/&gt;
      password: &lt;br/&gt;
      attributes:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;************* NEW ATTRIBUTE BELOW ************&lt;br/&gt;
        database_name: gesdoc&lt;br/&gt;
        default_table_collate: utf8_general_ci&lt;br/&gt;
        default_table_charset: utf8&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;after that, a few changes have been done in the Doctrine_Query class which is attached to this issue for the sake of readability.&lt;/p&gt;

&lt;p&gt;This may not be optimal, and probably need some regression testing, but it is currently working fine on our test server.&lt;/p&gt;

&lt;p&gt;after this is done, I was able to issue queries like the following :&lt;br/&gt;
    $x = DocumentTable::getInstance()-&amp;gt;createQuery(&apos;d&apos;)&lt;br/&gt;
                                     -&amp;gt;distinct()&lt;br/&gt;
                                     -&amp;gt;leftJoin(&apos;d.Travail t&apos;)&lt;br/&gt;
                                     -&amp;gt;leftJoin(&apos;t.CdcIndInt ci&apos;)&lt;br/&gt;
                                     -&amp;gt;leftJoin(&apos;ci.CdcIndExt ce&apos;)&lt;br/&gt;
                                     -&amp;gt;leftJoin(&apos;ce.Cahierdescharge cdc&apos;)&lt;br/&gt;
                                     -&amp;gt;where(&apos;cdc.cdc_chro = ?&apos;, $cdc_chro)&lt;br/&gt;
                                    -&amp;gt;addWhere(&apos;d.id != ?&apos;, $document_id)&lt;br/&gt;
                                    -&amp;gt;execute();&lt;/p&gt;

&lt;p&gt;where the referenced tables are in different databases. The necessary object binding has been done in every model class following the paradigm :&lt;/p&gt;

&lt;p&gt;Doctrine_Manager::getInstance()-&amp;gt;bindComponent(&apos;CdcIndInt &apos;, &apos;gescdc&apos;);&lt;br/&gt;
abstract class BaseCdcIndInt extends sfDoctrineRecord&lt;br/&gt;
{&lt;br/&gt;
...&lt;br/&gt;
}&lt;/p&gt;


&lt;p&gt;I don&apos;t know if this description is clear enough, so let me know if something is missing/wrong.&lt;/p&gt;</description>
                <environment>Windows XP SP3, Apache 2, PHP 5.3, MySQL 5.1.36, Symfony 1.4.8, Doctrine 1.2.3</environment>
            <key id="13198">DC-1040</key>
            <summary>allow queries with table joins across different databases</summary>
                <type id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/improvement.png">Improvement</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="jwage">Jonathan H. Wage</assignee>
                                <reporter username="fabrice.agnello">Fabrice Agnello</reporter>
                        <labels>
                    </labels>
                <created>Thu, 17 Nov 2011 14:42:03 +0000</created>
                <updated>Thu, 17 Nov 2011 14:42:03 +0000</updated>
                                    <version>1.2.3</version>
                                <fixVersion>1.2.3</fixVersion>
                                        <due></due>
                    <votes>0</votes>
                        <watches>1</watches>
                                <attachments>
                    <attachment id="11111" name="Query.php" size="86043" author="fabrice.agnello" created="Thu, 17 Nov 2011 14:42:03 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-1031] CLONE -Multiple connections and i18n (raised as unresolved - original ticket marked as resolved)</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-1031</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;I used to work with a single database named &quot;doctrine&quot;. The query was working properly.&lt;/p&gt;

&lt;p&gt;I then decided to use 2 databases so I got my schema like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;connection: doctrine&lt;/p&gt;

&lt;p&gt;Category:&lt;br/&gt;
  actAs:&lt;br/&gt;
    I18n:&lt;br/&gt;
      actAs:&lt;br/&gt;
        Sluggable:&lt;br/&gt;
          fields: &lt;span class=&quot;error&quot;&gt;&amp;#91;name&amp;#93;&lt;/span&gt;&lt;br/&gt;
        Timestampable: ~&lt;br/&gt;
      fields: &lt;span class=&quot;error&quot;&gt;&amp;#91;name, description&amp;#93;&lt;/span&gt;&lt;br/&gt;
  columns:&lt;br/&gt;
    id: ~&lt;br/&gt;
    name:&lt;br/&gt;
      type: string(255)&lt;br/&gt;
      notnull: true&lt;br/&gt;
    description: string&lt;/p&gt;

&lt;p&gt;User:&lt;br/&gt;
  connection: second&lt;br/&gt;
  columns:&lt;br/&gt;
    id: ~&lt;br/&gt;
    name:&lt;br/&gt;
      type: string(255)&lt;br/&gt;
      notnull: true&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;I did setup my connections in config/databases.yml this way:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;all:&lt;br/&gt;
  doctrine:&lt;br/&gt;
   // ....&lt;br/&gt;
  second:&lt;br/&gt;
   // ....&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;build-model, build-forms, build-filters and cc got ran. But now, I got an exception saying the &quot;Translation&quot; relation doesn&apos;t exist. The Base Models include correctly the bindComponent line:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Doctrine_Manager::getInstance()-&amp;gt;bindComponent(&apos;Category&apos;, &apos;doctrine&apos;);&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;For now, I managed to kind of fixing it with simply swapping the databases order in my config/databases.yml and it&apos;s now working again perfectly.&lt;/p&gt;

&lt;p&gt;I forgot to mention that in the CategoryTable when i call $this-&amp;gt;getConnection()-&amp;gt;getName(), it outputs &quot;second&quot;&lt;/p&gt;</description>
                <environment>MySQL 5.1.37&lt;br/&gt;
PHP 5.2.11&lt;br/&gt;
symfony 1.2.11 DEV&lt;br/&gt;
&lt;br/&gt;
symfony 1.4.13&lt;br/&gt;
PHP 5.3.6 &lt;br/&gt;
Postgres 8.4.8&lt;br/&gt;
</environment>
            <key id="12962">DC-1031</key>
            <summary>CLONE -Multiple connections and i18n (raised as unresolved - original ticket marked as resolved)</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="jwage">Jonathan H. Wage</assignee>
                                <reporter username="sarcas">James Bell</reporter>
                        <labels>
                    </labels>
                <created>Tue, 23 Aug 2011 14:26:27 +0000</created>
                <updated>Wed, 28 Mar 2012 08:20:53 +0000</updated>
                                    <version>1.2.2</version>
                <version>1.2.3</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Connection</component>
                <component>I18n</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="16370" author="sarcas" created="Tue, 23 Aug 2011 14:28:15 +0000"  >&lt;p&gt;Original issue: &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-363&quot; title=&quot;Multiple connections and i18n&quot;&gt;&lt;del&gt;DC-363&lt;/del&gt;&lt;/a&gt; (&lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-363&quot; class=&quot;external-link&quot;&gt;http://www.doctrine-project.org/jira/browse/DC-363&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;There are some additional comments in there that explain the issue as currently being seen in released versions of Doctrine 1.2. Can I help verify that this is the same ticket? &lt;/p&gt;

&lt;p&gt;What is needed to help with debug (in addition to the extra information already provided)?&lt;/p&gt;
</comment>
                    <comment id="17664" author="lvqingan" created="Wed, 28 Mar 2012 08:20:53 +0000"  >&lt;p&gt;meet the same issue and it really blocked my project, seems no one will maintain 1.x. I&apos;m considering whether to replace symfony 1.4 with 2.0.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-1004] ATTR_TBLNAME_FORMAT not used when creating models from database</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-1004</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;if you set prefix to &quot;xyz_%s&quot; and have the model &quot;BackgroundColor&quot; it will become the table =&amp;gt; &quot;xyz_background_color&quot;&lt;br/&gt;
if you have the table &quot;xyz_background_color&quot; with unknown model and create the the model from the table, you will get =&amp;gt; &quot;XyzBackgroundColor&quot;.&lt;/p&gt;

&lt;p&gt;The fix (diff):&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;368a369,370&lt;br/&gt;
&amp;gt;         $tablePrefix = $manager-&amp;gt;getAttribute(Doctrine_Core::ATTR_TBLNAME_FORMAT);&lt;br/&gt;
&amp;gt;         &lt;br/&gt;
381d382&lt;br/&gt;
&amp;lt; &lt;br/&gt;
385c386&lt;br/&gt;
&amp;lt;               $definition&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;className&amp;#39;&amp;#93;&lt;/span&gt; = Doctrine_Inflector::classify(Doctrine_Inflector::tableize($table));&lt;br/&gt;
&amp;#8212;&lt;br/&gt;
&amp;gt;               $definition&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;className&amp;#39;&amp;#93;&lt;/span&gt; = Doctrine_Inflector::classify(Doctrine_Inflector::tableize(preg_replace(sprintf(&apos;/\A%s\z/&apos;, str_replace(&apos;%s&apos;, &apos;(.*?)&apos;, $tablePrefix)), &apos;$1&apos;, $table)));&lt;br/&gt;
396c397&lt;br/&gt;
&amp;lt;                       $class = Doctrine_Inflector::classify(Doctrine_Inflector::tableize($table));&lt;br/&gt;
&amp;#8212;&lt;br/&gt;
&amp;gt;                       $class = Doctrine_Inflector::classify(Doctrine_Inflector::tableize(preg_replace(sprintf(&apos;/\A%s\z/&apos;, str_replace(&apos;%s&apos;, &apos;(.*?)&apos;, $tablePrefix)), &apos;$1&apos;, $table)));&lt;/p&gt;&lt;/blockquote&gt;</description>
                <environment></environment>
            <key id="12621">DC-1004</key>
            <summary>ATTR_TBLNAME_FORMAT not used when creating models from database</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</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="jwage">Jonathan H. Wage</assignee>
                                <reporter username="to-rparker">Robin Parker</reporter>
                        <labels>
                    </labels>
                <created>Sun, 8 May 2011 04:34:20 +0000</created>
                <updated>Sun, 8 May 2011 04:34:52 +0000</updated>
                                    <version>1.2.3</version>
                                <fixVersion>1.2.3</fixVersion>
                <fixVersion>1.2.4</fixVersion>
                                <component>Import/Export</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="15814" author="to-rparker" created="Sun, 8 May 2011 04:34:52 +0000"  >&lt;p&gt;The diff output as .diff&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10990" name="doctrine_bug_diff.diff" size="746" author="to-rparker" created="Sun, 8 May 2011 04:34:52 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-941] Spatial index type for mysql</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-941</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;I&apos;m using doctrine and some of mysql&apos;s spatial functions. I need to specify spatial index for my tables.&lt;br/&gt;
My declaration looks like:&lt;/p&gt;

&lt;p&gt;Geometry:&lt;br/&gt;
  tableName: geometry&lt;br/&gt;
  options:&lt;br/&gt;
    type:    MyISAM&lt;br/&gt;
    collate: utf8_unicode_ci&lt;br/&gt;
    charset: utf8&lt;br/&gt;
  columns:&lt;br/&gt;
    id: &lt;br/&gt;
      type: integer(4)&lt;br/&gt;
      primary: true&lt;br/&gt;
      autoincrement: true&lt;br/&gt;
    geometry:&lt;br/&gt;
      type: geometry&lt;br/&gt;
      notnull: true&lt;br/&gt;
   indexes:&lt;br/&gt;
    geometry:&lt;br/&gt;
      fields:&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;geometry&lt;br/&gt;
      type: spatial&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Exporting this definitions throws an exception: Unknown type spatial for index geometry_idx&lt;/p&gt;

</description>
                <environment></environment>
            <key id="12178">DC-941</key>
            <summary>Spatial index type for mysql</summary>
                <type id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/improvement.png">Improvement</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</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="jwage">Jonathan H. Wage</assignee>
                                <reporter username="mishal">Mishal</reporter>
                        <labels>
                    </labels>
                <created>Mon, 29 Nov 2010 14:43:57 +0000</created>
                <updated>Mon, 29 Nov 2010 14:43:57 +0000</updated>
                                    <version>1.2.3</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Import/Export</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                    <attachment id="10880" name="patch.patch" size="736" author="mishal" created="Mon, 29 Nov 2010 14:43:57 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-924] type mismatch for keyfield in column aggregation</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-924</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;This is the doc exemple on column aggregation inheritance :&lt;/p&gt;

&lt;p&gt;Entity:&lt;br/&gt;
  columns:&lt;br/&gt;
    username: string(20)&lt;br/&gt;
    password: string(16)&lt;br/&gt;
    created_at: timestamp&lt;br/&gt;
    updated_at: timestamp&lt;/p&gt;

&lt;p&gt;User:&lt;br/&gt;
  inheritance:&lt;br/&gt;
    extends: Entity&lt;br/&gt;
    type: column_aggregation&lt;br/&gt;
    keyField: type&lt;br/&gt;
    keyValue: 1&lt;/p&gt;

&lt;p&gt;Group:&lt;br/&gt;
  inheritance:&lt;br/&gt;
    extends: Entity&lt;br/&gt;
    type: column_aggregation&lt;br/&gt;
    keyField: type&lt;br/&gt;
    keyValue: 2&lt;/p&gt;

&lt;p&gt;But the keyField (type) is created as VARCHAR(255) so PostgreSQL return an error on applying inheritance condition :&lt;/p&gt;

&lt;p&gt;SQLSTATE&lt;span class=&quot;error&quot;&gt;&amp;#91;42883&amp;#93;&lt;/span&gt;: Undefined function: 7 ERROR:  operator does not exist: character varying = integer         &lt;br/&gt;
  LINE 1: ...D s.application = &apos;frontend&apos; AND s.lft = 1) AND (s.type = 2)                                     &lt;br/&gt;
                                                                     ^                                        &lt;br/&gt;
  HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.&lt;/p&gt;

&lt;p&gt;I found this with symfony sfFilebasePlugin on sfFilebase:create-root task.&lt;/p&gt;</description>
                <environment>PostgreSQL</environment>
            <key id="12095">DC-924</key>
            <summary>type mismatch for keyfield in column aggregation</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</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="romanb">Roman S. Borschel</assignee>
                                <reporter username="nono">Arnaud Morvan</reporter>
                        <labels>
                    </labels>
                <created>Thu, 11 Nov 2010 12:02:12 +0000</created>
                <updated>Thu, 11 Nov 2010 12:02:12 +0000</updated>
                                    <version>1.2.3</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Inheritance</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-895] [I18n] Defining languages with locality (eg. en_GB) breaks functionality with SQL Integrity error - fix included</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-895</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;When defining languages as language_COUNTRY codes (supported by symfony by default), the functionality to work with I18n records breaks, resulting in &quot;SQLSTATE&lt;span class=&quot;error&quot;&gt;&amp;#91;23000&amp;#93;&lt;/span&gt;: Integrity constraint violation: 1062 Duplicate entry&quot; errors.&lt;/p&gt;

&lt;p&gt;The reason is very simple: Doctrine&apos;s I18n language column is defined as a CHAR(2), thus shortening eg. &quot;en_GB&quot; value to &quot;en&quot;, thus causing the above SQL error when a &quot;en&quot; translation for a record already exists.&lt;/p&gt;

&lt;p&gt;The solution is even simpler: change the column&apos;s length to 7 in the Doctrine_I18n class&apos;s options: I&apos;ve tested this and all runs great: the correct SQL is being generated, the models behave correct, ...&lt;/p&gt;</description>
                <environment>all</environment>
            <key id="12019">DC-895</key>
            <summary>[I18n] Defining languages with locality (eg. en_GB) breaks functionality with SQL Integrity error - fix included</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>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="4levels">Erik Van Kelst</reporter>
                        <labels>
                    </labels>
                <created>Wed, 20 Oct 2010 04:21:59 +0000</created>
                <updated>Wed, 20 Oct 2010 04:42:40 +0000</updated>
                    <resolved>Wed, 20 Oct 2010 04:42:40 +0000</resolved>
                            <version>1.2.0</version>
                <version>1.2.1</version>
                <version>1.2.2</version>
                <version>1.2.3</version>
                                <fixVersion>1.2.0</fixVersion>
                <fixVersion>1.2.1</fixVersion>
                <fixVersion>1.2.2</fixVersion>
                <fixVersion>1.2.3</fixVersion>
                                <component>I18n</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="14583" author="4levels" created="Wed, 20 Oct 2010 04:42:40 +0000"  >&lt;p&gt;Length of the i18n column is configurable...&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-832] PostgreSQL - lastInsertId fails because sequence name on table with column alias on primary key does not work [+patch]</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-832</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;PostgreSQL - lastInsertId fails because sequence name on table with column alias on primary key does not work.&lt;/p&gt;

&lt;p&gt;DDL created sequence name: &amp;lt;table&amp;gt;_&amp;lt;column name&amp;gt;&lt;br/&gt;
Last Insert ID sequence name: &amp;lt;table&amp;gt;_&amp;lt;identifier&amp;gt; (identifer is the field name which can be different to the column name)&lt;/p&gt;</description>
                <environment></environment>
            <key id="11794">DC-832</key>
            <summary>PostgreSQL - lastInsertId fails because sequence name on table with column alias on primary key does not work [+patch]</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="1">Fixed</resolution>
                                <assignee username="guilhermeblanco">Guilherme Blanco</assignee>
                                <reporter username="enrico">Enrico Stahn</reporter>
                        <labels>
                    </labels>
                <created>Wed, 18 Aug 2010 07:15:06 +0000</created>
                <updated>Tue, 24 Aug 2010 12:34:55 +0000</updated>
                    <resolved>Tue, 24 Aug 2010 12:34:55 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Query</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="13997" author="enrico" created="Wed, 18 Aug 2010 07:20:56 +0000"  >&lt;p&gt;Patch:&lt;br/&gt;
&lt;a href=&quot;http://github.com/estahn/doctrine1/tree/DC-832&quot; class=&quot;external-link&quot;&gt;http://github.com/estahn/doctrine1/tree/DC-832&lt;/a&gt;&lt;br/&gt;
&lt;a href=&quot;http://github.com/estahn/doctrine1/commit/5921da9fe159844e354fd280dca8cc156a8680a7&quot; class=&quot;external-link&quot;&gt;http://github.com/estahn/doctrine1/commit/5921da9fe159844e354fd280dca8cc156a8680a7&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="14054" author="jwage" created="Tue, 24 Aug 2010 12:34:55 +0000"  >&lt;p&gt;Thanks, fixed by &lt;a href=&quot;http://trac.doctrine-project.org/changeset/7684&quot; class=&quot;external-link&quot;&gt;http://trac.doctrine-project.org/changeset/7684&lt;/a&gt;&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-826] Doctrine_Collection::replace() EASY PATCH!</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-826</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Record::replace() exists already.&lt;/p&gt;

&lt;p&gt;but Doctrine_Collection::replace() does not exist.&lt;/p&gt;

&lt;p&gt;I just copied the Doctrine_Collection::save() function, renamed it to replace and replaced&lt;br/&gt;
$record-&amp;gt;save($conn);&lt;br/&gt;
with&lt;br/&gt;
$record-&amp;gt;replace($conn);&lt;/p&gt;

&lt;p&gt;WORKS GREAT!&lt;br/&gt;
Please include a replace for Doctrine_Collection.&lt;br/&gt;
Its really an easy patch!&lt;/p&gt;

&lt;p&gt;By the way ... why is there no component for collection in the above select-field?&lt;/p&gt;</description>
                <environment>linux, symfony-framework. I dont know the Version but Revision is 7490  </environment>
            <key id="11769">DC-826</key>
            <summary>Doctrine_Collection::replace() EASY PATCH!</summary>
                <type id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/improvement.png">Improvement</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="zevero">Severin Puschkarski</reporter>
                        <labels>
                    </labels>
                <created>Fri, 13 Aug 2010 09:00:53 +0000</created>
                <updated>Tue, 24 Aug 2010 12:54:55 +0000</updated>
                    <resolved>Tue, 24 Aug 2010 12:54:55 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Record</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="14057" author="jwage" created="Tue, 24 Aug 2010 12:54:55 +0000"  >&lt;p&gt;Fixed in &lt;a href=&quot;http://trac.doctrine-project.org/changeset/7686&quot; class=&quot;external-link&quot;&gt;http://trac.doctrine-project.org/changeset/7686&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks, Jon&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-813] Add ability to register a custom hydrator as a class instance instead of a class name</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-813</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Currently its only possible to register a custom hydrator as a string name. However in order to inject additional attributes it would be beneficial to be able to register an instance of the custom hydrator class.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.doctrine-project.org/documentation/manual/1_2/en/data-hydrators#writing-hydration-method&quot; class=&quot;external-link&quot;&gt;http://www.doctrine-project.org/documentation/manual/1_2/en/data-hydrators#writing-hydration-method&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So instead of:&lt;br/&gt;
$manager-&amp;gt;registerHydrator(&apos;my_hydrator&apos;, &apos;Doctrine_Hydrator_MyHydrator&apos;);&lt;/p&gt;

&lt;p&gt;One could do:&lt;br/&gt;
$manager-&amp;gt;registerHydrator(&apos;my_hydrator&apos;,  new Doctrine_Hydrator_MyHydrator());&lt;/p&gt;</description>
                <environment></environment>
            <key id="11743">DC-813</key>
            <summary>Add ability to register a custom hydrator as a class instance instead of a class name</summary>
                <type id="2" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/newfeature.png">New Feature</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="6" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/closed.png">Closed</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="guilhermeblanco">Guilherme Blanco</assignee>
                                <reporter username="lsmith">Lukas Kahwe</reporter>
                        <labels>
                    </labels>
                <created>Mon, 9 Aug 2010 08:11:59 +0000</created>
                <updated>Wed, 11 Aug 2010 14:50:23 +0000</updated>
                    <resolved>Wed, 11 Aug 2010 14:50:23 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Query</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="13875" author="lsmith" created="Mon, 9 Aug 2010 08:13:32 +0000"  >&lt;p&gt;patch with tests is in the works&lt;/p&gt;</comment>
                    <comment id="13877" author="lsmith" created="Mon, 9 Aug 2010 13:56:55 +0000"  >&lt;p&gt;patch&lt;/p&gt;</comment>
                    <comment id="13878" author="lsmith" created="Mon, 9 Aug 2010 13:57:12 +0000"  >&lt;p&gt;tests&lt;/p&gt;</comment>
                    <comment id="13918" author="guilhermeblanco" created="Wed, 11 Aug 2010 14:50:23 +0000"  >&lt;p&gt;Fixed&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10731" name="DC-813.diff" size="3095" author="lsmith" created="Mon, 9 Aug 2010 13:56:55 +0000" />
                    <attachment id="10732" name="DC-813_test.diff" size="1974" author="lsmith" created="Mon, 9 Aug 2010 13:57:12 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-800] PostgreSQL does not have LOCATE expressions</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-800</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;h2&gt;&lt;a name=&quot;Introduction&quot;&gt;&lt;/a&gt;Introduction &lt;/h2&gt;

&lt;p&gt;As it&apos;s described in Doctrine documentation: &lt;a href=&quot;http://www.doctrine-project.org/projects/orm/1.2/docs/manual/dql-doctrine-query-language/en#functional-expressions&quot; class=&quot;external-link&quot;&gt;http://www.doctrine-project.org/projects/orm/1.2/docs/manual/dql-doctrine-query-language/en#functional-expressions&lt;/a&gt;. In case I have correctly understood this documentation, I can use registered expressions (CONCAT,TRIM,LOCATE etc.) with supported database drivers. &lt;/p&gt;

&lt;h3&gt;&lt;a name=&quot;Issue&quot;&gt;&lt;/a&gt;Issue&lt;/h3&gt;

&lt;p&gt;The problem is with PostgreSQL, - it does not have the string function &quot;LOCATE&quot; since v7.4 (i have no info about previous version)&lt;/p&gt;

&lt;p&gt;Here is my example:&lt;/p&gt;
&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;  $q = PortalTable::getInstance()
      -&amp;gt;createQuery()
      -&amp;gt;addSelect(
        &apos;(1 &amp;lt;= LOCATE(host, ?) as is_host_matched)&apos;,
        array(&apos;.google.com&apos;)
  );

  $q-&amp;gt;execute();
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And this code dies with an error:&lt;br/&gt;
&lt;font color=&quot;red&quot;&gt;&lt;br/&gt;
Doctrine_Connection_Pgsql_Exception: SQLSTATE&lt;span class=&quot;error&quot;&gt;&amp;#91;42601&amp;#93;&lt;/span&gt;: Syntax error: 7 ERROR: syntax error at or near &quot;as&quot; LINE 1: SELECT (1 &amp;lt;= LOCATE(&quot;p&quot;.&quot;host&quot;, $1) as is_host_matched) AS &quot;... ^. Failing Query: &quot;SELECT (1 &amp;lt;= LOCATE(&quot;p&quot;.&quot;host&quot;, ?) as is_host_matched) AS &quot;p__0&quot; FROM &quot;portal&quot; &quot;p&quot;&quot; in /web/vendor/symfony/1.4-svn/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php on line 1082&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;In PgSQL you can use POSITION for this needs (I want to mention, MySQL has this function too as an alias for LOCATE)&lt;/p&gt;

&lt;p&gt;btw, POSITION is SQL-92 standard &lt;a href=&quot;http://owen.sj.ca.us/~rk/howto/sql92.html&quot; class=&quot;external-link&quot;&gt;http://owen.sj.ca.us/~rk/howto/sql92.html&lt;/a&gt;  - maybe it is better to rename LOCATE with POSITION?&lt;/p&gt;

&lt;h3&gt;&lt;a name=&quot;Patch&quot;&gt;&lt;/a&gt;Patch&lt;/h3&gt;


&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;Index: Doctrine/Expression/Pgsql.php
===================================================================
--- Doctrine/Expression/Pgsql.php	(revision 7678)
+++ Doctrine/Expression/Pgsql.php	(working copy)
@@ -230,4 +230,31 @@
     	$translate = &apos;TRANSLATE(&apos; . $string . &apos;, &apos; . $from . &apos;, &apos; . $to . &apos;)&apos;;
     	return $translate;
     }
-}
\ No newline at end of file
+
+    /**
+     * transform locate to position
+     *
+     * @param string $substr string to find
+     * @param string $str to find where
+     * @return string
+     */
+    public function locate($substr, $str)
+    {
+        return $this-&amp;gt;position($substr, $str);
+    }
+
+    /**
+     * position
+     *
+     * @param string $substr string to find
+     * @param string $str to find where
+     * @return string
+     */
+    public function position($substr, $str)
+    {
+        $substr = $this-&amp;gt;getIdentifier($substr);
+        $str = $this-&amp;gt;getIdentifier($str);
+        
+        return sprintf(&apos;POSITION(%s IN %s)&apos;, $substr, $str);
+    }
+}

&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;h3&gt;&lt;a name=&quot;Solutionwithoutpatch%3A&quot;&gt;&lt;/a&gt;Solution without patch:&lt;/h3&gt;


&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;  # will work with PgSQL and MySQL (tested)
  $exp = new Doctrine_Expression(&apos;POSITION(host IN ?)&apos;);

  $q = PortalTable::getInstance()
      -&amp;gt;createQuery()
      -&amp;gt;addSelect(
        &quot;(1 &amp;lt;= {$exp} as is_host_matched)&quot;,
        array(&apos;.google.com&apos;)
  );

  $q-&amp;gt;execute();
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</description>
                <environment>PHP: v5.2.13 (cli) (built: May  6 2010 01:51:58) Zend Engine v2.2.0, Xdebug v2.0.5&lt;br/&gt;
&lt;br/&gt;
OS: FreeBSD x 8.0-RELEASE-p2 FreeBSD 8.0-RELEASE-p2 #0: Thu May  6 03:37:19 EEST 2010 &lt;a href=&apos;mailto:x@y.z&apos;&gt;x@y.z&lt;/a&gt;:/usr/obj/usr/src/sys/CUSTOM_8_0  amd64&lt;br/&gt;
&lt;br/&gt;
Database: postgres (PostgreSQL) 8.4.3&lt;br/&gt;
&lt;br/&gt;
Symfony: 1.4.7-DEV (/web/vendor/symfony/1.4-svn/lib)&lt;br/&gt;
&lt;br/&gt;
Web-server: nginx/0.7.65</environment>
            <key id="11687">DC-800</key>
            <summary>PostgreSQL does not have LOCATE expressions</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="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="fruit">Ilya Sabelnikov</reporter>
                        <labels>
                    </labels>
                <created>Wed, 28 Jul 2010 06:38:56 +0000</created>
                <updated>Tue, 24 Aug 2010 12:43:52 +0000</updated>
                    <resolved>Tue, 24 Aug 2010 12:43:52 +0000</resolved>
                                            <fixVersion>1.2.3</fixVersion>
                                <component>Native SQL</component>
                <component>Query</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="14055" author="jwage" created="Tue, 24 Aug 2010 12:43:52 +0000"  >&lt;p&gt;Fixed in &lt;a href=&quot;http://trac.doctrine-project.org/changeset/7685&quot; class=&quot;external-link&quot;&gt;http://trac.doctrine-project.org/changeset/7685&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks, Jon&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-794] findBy issue with field names containing &quot;Or&quot;</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-794</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;The problem is in Doctrine_Table::buildFindByWhere, line 2715. I put the code here for clarity:&lt;/p&gt;

&lt;p&gt;    public function buildFindByWhere($fieldName)&lt;br/&gt;
    {&lt;br/&gt;
        $ands = array();&lt;br/&gt;
        $e = explode(&apos;And&apos;, $fieldName);&lt;br/&gt;
        foreach ($e as $k =&amp;gt; $v) {&lt;br/&gt;
            $and = &apos;&apos;;&lt;br/&gt;
            $e2 = explode(&apos;Or&apos;, $v);&amp;lt;- LINE 2715&lt;br/&gt;
            $ors = array();&lt;br/&gt;
            foreach ($e2 as $k2 =&amp;gt; $v2) {&lt;br/&gt;
                if ($v2 = $this-&amp;gt;_resolveFindByFieldName($v2)) &lt;/p&gt;
{
                    $ors[] = &apos;dctrn_find.&apos; . $v2 . &apos; = ?&apos;;
                }
&lt;p&gt; else &lt;/p&gt;
{
                    throw new Doctrine_Table_Exception(&apos;Invalid field name to find by: &apos; . $v2);
                }
&lt;p&gt;            }&lt;br/&gt;
            $and .= implode(&apos; OR &apos;, $ors);&lt;br/&gt;
            $and = count($ors) &amp;gt; 1 ? &apos;(&apos; . $and . &apos;)&apos;:$and;&lt;br/&gt;
            $ands[] = $and;&lt;br/&gt;
        }&lt;br/&gt;
        $where = implode(&apos; AND &apos;, $ands);&lt;br/&gt;
        return $where;&lt;br/&gt;
    }&lt;/p&gt;

&lt;p&gt;In my proyect I have a table called OrigenesOportunidadCliente, which id field name is idOrigenOportunidadCliente. As you have probably noticed, the name contains Or: idOrigenOportunidadCliente. And there is where it fails, it gets as if there where an OR statement, not finding a valid field name in the below foreach as the field is &quot;OrigenOportunidad&quot;.&lt;/p&gt;</description>
                <environment>Tested with Windows Vista / Ubuntu 10.4, PHP 5.2.10, MySQL 5.</environment>
            <key id="11655">DC-794</key>
            <summary>findBy issue with field names containing &quot;Or&quot;</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="egulias">Eduardo Gulias Davis</reporter>
                        <labels>
                    </labels>
                <created>Tue, 20 Jul 2010 10:46:37 +0000</created>
                <updated>Wed, 29 Sep 2010 05:35:32 +0000</updated>
                    <resolved>Tue, 24 Aug 2010 11:56:43 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Record</component>
                        <due></due>
                    <votes>1</votes>
                        <watches>1</watches>
                        <comments>
                    <comment id="14024" author="enrico" created="Sun, 22 Aug 2010 06:51:42 +0000"  >&lt;p&gt;fixed &lt;a href=&quot;http://github.com/estahn/doctrine1/compare/master...DC-794&quot; class=&quot;external-link&quot;&gt;http://github.com/estahn/doctrine1/compare/master...DC-794&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="14048" author="jwage" created="Tue, 24 Aug 2010 11:56:43 +0000"  >&lt;p&gt;Fixed in &lt;a href=&quot;http://trac.doctrine-project.org/changeset/7681&quot; class=&quot;external-link&quot;&gt;http://trac.doctrine-project.org/changeset/7681&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;</comment>
                    <comment id="14490" author="egulias" created="Wed, 29 Sep 2010 05:35:32 +0000"  >&lt;p&gt;Sorry for the delay in posting this comment!!&lt;/p&gt;

&lt;p&gt;thank you very very much for the quick response on this issue.&lt;/p&gt;

&lt;p&gt;Great work!&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-764] Major-&gt;please.....Value of Primary key from sequence in Postgres table NOT being set (although sequence gets incremented)</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-764</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;In the ERD/schema that I have set up, a couple levels down in hierarchal order, a table has 3 composite foreign keys, and one sequence of its own. That sequence does not get get set into the &apos;Table-&amp;gt;sequence variable&apos;. That means when the file &apos;UnitOfWork&apos; executes the function &apos;_assignSequence()&apos;, it finds no sequence name, and skips the assignment of the sequence value. &lt;/p&gt;

&lt;p&gt;This of course blows up my inserts.&lt;/p&gt;

&lt;p&gt;I have included the following documentation:&lt;/p&gt;

&lt;p&gt;A/ An installation and further description README.tx file.&lt;br/&gt;
B/ SQL script to generate a anonymous version of my ERD - I.E. the table names and column names have been changed to protect the guilty (and proprietary)&lt;br/&gt;
C/ A fixture file to load some data.&lt;br/&gt;
D/ A *.png file showing a graphical view of the ERD.&lt;br/&gt;
E/ The generated schema.yml file from ./symfony doctrine:build-schema&lt;br/&gt;
F/ A modifiled (has certain echo statements for troubleshooting purposes) UnitOfWork.php file.&lt;br/&gt;
G/ A task file to run that tries to load the schema with valid values.&lt;br/&gt;
H/ An output file from running the Task and modified UnitOfWork.php file showing the exact point of error during insert.&lt;/p&gt;

&lt;p&gt;Please let me know what I can do to help get this troubleshot quicly. Thx&lt;br/&gt;
E/ &lt;/p&gt;</description>
                <environment>Ubuntu9.10 / PHP 5.2.6-3ubuntu4.5 with Suhosin-Patch 0.9.6.2 / Postgres-8.4 / Symfony 1.4.1 </environment>
            <key id="11550">DC-764</key>
            <summary>Major-&gt;please.....Value of Primary key from sequence in Postgres table NOT being set (although sequence gets incremented)</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="6">Invalid</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="gearond">Dennis Gearon</reporter>
                        <labels>
                    </labels>
                <created>Thu, 24 Jun 2010 20:51:13 +0000</created>
                <updated>Fri, 25 Jun 2010 18:00:37 +0000</updated>
                    <resolved>Fri, 25 Jun 2010 18:00:37 +0000</resolved>
                            <version>1.2.1</version>
                                <fixVersion>1.2.0</fixVersion>
                <fixVersion>1.2.1</fixVersion>
                <fixVersion>1.2.2</fixVersion>
                <fixVersion>1.2.3</fixVersion>
                                <component>Connection</component>
                <component>Record</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="13414" author="gearond" created="Fri, 25 Jun 2010 13:27:20 +0000"  >&lt;p&gt;Don&apos;t know if it&apos;s related, but I ran:&lt;/p&gt;

&lt;p&gt;./symfony doctrine:build-sql&lt;/p&gt;

&lt;p&gt;on the database in this bug report, and none of the tables got sequences assigned to them, nor default values set coming from a sequence.&lt;/p&gt;

&lt;p&gt;This is Postgres.&lt;/p&gt;</comment>
                    <comment id="13415" author="gearond" created="Fri, 25 Jun 2010 13:54:31 +0000"  >&lt;p&gt;So much for getting around this problem easily, &lt;img class=&quot;emoticon&quot; src=&quot;http://www.doctrine-project.org/jira/images/icons/emoticons/sad.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;

&lt;p&gt;I tried doing this:&lt;/p&gt;

&lt;p&gt;$e_table=Doctrine::getTable(&apos;E&apos;);&lt;br/&gt;
$e_table-&amp;gt;setOption(&apos;sequenceName&apos;, &apos;e_id&apos;);&lt;br/&gt;
$e_options=$e_table-&amp;gt;getOptions();&lt;br/&gt;
var_dump($e_options);&lt;/p&gt;

&lt;p&gt;before inserting a record into the &apos;E&apos; table. The option value &apos;sequenceName&apos; is in the option array and returns correctly. However, when doing an insert immediatley after the above code, I get:&lt;/p&gt;

&lt;p&gt;   &apos;sequence name was Array&apos; (from my troubleshooting &apos;echo&apos; statements in the modified UnitOfWork.php file)&lt;/p&gt;

&lt;p&gt;and the following errors: (you have to be using my modified UOW.php file to get the same line number there.)&lt;/p&gt;

&lt;p&gt;Warning: Illegal offset type in /home/bugreport/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php on line 917&lt;/p&gt;

&lt;p&gt;Warning: Illegal offset type in /home/bugreport/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php on line 2222&lt;/p&gt;

&lt;p&gt;Warning: Illegal offset type in /home/bugreport/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php on line 2223&lt;br/&gt;
PREVIOUS line was processingSingleInsert&lt;/p&gt;

&lt;p&gt;Warning: Invalid argument supplied for foreach() in /home/bugreport/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php on line 1151&lt;/p&gt;

&lt;p&gt;So I am wondering, does the public function table-&amp;gt;setOption();   even work, correclty that is?&lt;/p&gt;
</comment>
                    <comment id="13416" author="gearond" created="Fri, 25 Jun 2010 14:06:09 +0000"  >&lt;p&gt;If I instead just retrieve the next val of the sequence manually, change &apos;id&apos; column manually, then it works. But It then fails on the insert into the &apos;J&apos; table.&lt;/p&gt;

&lt;p&gt;Apparently, Doctrine does not like composite primary foreign keys with a sequence also part of the foreign key. I wonder if my file would work on the Oracle version?&lt;/p&gt;</comment>
                    <comment id="13417" author="gearond" created="Fri, 25 Jun 2010 17:57:39 +0000"  >&lt;p&gt;Showing simpler version of ERD/Schema converting Primary Foreign Keys to Foreign keys. The then required unique index on the former Primary Foreign Keys has not yet been coded. Just create it on all the keys in tables E and J, that were listed as primary in the first version in the zip file&lt;/p&gt;</comment>
                    <comment id="13418" author="gearond" created="Fri, 25 Jun 2010 18:00:37 +0000"  >&lt;p&gt;See last comment, but the short answer is . . . at this date, 2010-06-25, even Doctrine 2.0-DBAL can&apos;t do what I&apos;m trying to get verson 1.2.1 to do.&lt;/p&gt;

&lt;p&gt;So I got around it by converting primary foreign keys to foreign keys and then putting a unique index on the formerly primary keys.&lt;/p&gt;

&lt;p&gt;However, the child of the table treated that way, E(parent), J(child), now only has one foreign key, for E. To get all the ancestors, I will have to do subselects and joins. Oh well.&lt;/p&gt;
</comment>
                </comments>
                    <attachments>
                    <attachment id="10679" name="bugreport.zip" size="52298" author="gearond" created="Thu, 24 Jun 2010 20:51:13 +0000" />
                    <attachment id="10681" name="bug_report_create_postgresql.sql" size="7103" author="gearond" created="Fri, 25 Jun 2010 17:57:39 +0000" />
                    <attachment id="10680" name="schema.yml" size="5469" author="gearond" created="Fri, 25 Jun 2010 17:57:39 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-745] Exported foreign keys names are not formatted with attribute FKNAME_FORMAT</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-745</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Class &lt;em&gt;Doctrine_Formatter&lt;/em&gt; formats index names using Doctrine_Core::ATTR_IDXNAME_FORMAT&lt;br/&gt;
but for now it does &lt;em&gt;not&lt;/em&gt; format foreign key names with Doctrine_Core::ATTR_FKNAME_FORMAT (in function &lt;em&gt;getForeignKeyName&lt;/em&gt;).&lt;/p&gt;

&lt;p&gt;Attached simple patch (copied from function &lt;em&gt;getIndexName&lt;/em&gt;) &lt;img class=&quot;emoticon&quot; src=&quot;http://www.doctrine-project.org/jira/images/icons/emoticons/smile.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</description>
                <environment>Doctrine SVN 1.2 r7676</environment>
            <key id="11510">DC-745</key>
            <summary>Exported foreign keys names are not formatted with attribute FKNAME_FORMAT</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="gx">Guilliam X</reporter>
                        <labels>
                    </labels>
                <created>Wed, 16 Jun 2010 16:57:16 +0000</created>
                <updated>Tue, 24 Aug 2010 12:08:28 +0000</updated>
                    <resolved>Tue, 24 Aug 2010 12:08:28 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Import/Export</component>
                <component>Query</component>
                <component>Record</component>
                <component>Relations</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="14052" author="jwage" created="Tue, 24 Aug 2010 12:08:28 +0000"  >&lt;p&gt;Fixed in &lt;a href=&quot;http://trac.doctrine-project.org/changeset/7682&quot; class=&quot;external-link&quot;&gt;http://trac.doctrine-project.org/changeset/7682&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks, Jon&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10662" name="DC-745.patch" size="501" author="gx" created="Wed, 16 Jun 2010 16:57:16 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-715] Doctrine_Tree_NestedSet::fetchRoots does not return roots with no branches.</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-715</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Doctrine_Tree_NestedSet::fetchRoots does not return roots with no branches.&lt;/p&gt;</description>
                <environment>any</environment>
            <key id="11445">DC-715</key>
            <summary>Doctrine_Tree_NestedSet::fetchRoots does not return roots with no branches.</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="rishta">Jacek Krysztofik</reporter>
                        <labels>
                    </labels>
                <created>Fri, 4 Jun 2010 05:19:48 +0000</created>
                <updated>Tue, 8 Jun 2010 10:49:31 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 08:55:41 +0000</resolved>
                            <version>1.2.2</version>
                <version>1.2.3</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Behaviors</component>
                <component>Nested Set</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="13138" author="jwage" created="Tue, 8 Jun 2010 08:55:41 +0000"  >&lt;p&gt;This patch breaks our test suite:&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;Doctrine_PessimisticLocking_TestCase............................................passed
Doctrine_NestedSet_SingleRoot_TestCase..........................................failed


Unexpected Doctrine_Query_Exception thrown in [Doctrine_NestedSet_SingleRoot_TestCase] with message [Unknown column ] in /Users/jwage/Sites/doctrine12/lib/Doctrine/Query.php on line 729

Trace
-------------

#0 /Users/jwage/Sites/doctrine12/lib/Doctrine/Query/Where.php(93): Doctrine_Query-&amp;gt;parseClause(&apos;base.&apos;)
#1 /Users/jwage/Sites/doctrine12/lib/Doctrine/Query/Where.php(81): Doctrine_Query_Where-&amp;gt;_buildSql(&apos;base.&apos;, &apos;IS&apos;, &apos;NULL&apos;)
#2 /Users/jwage/Sites/doctrine12/lib/Doctrine/Query/Condition.php(92): Doctrine_Query_Where-&amp;gt;load(&apos;base. IS NULL&apos;)
#3 /Users/jwage/Sites/doctrine12/lib/Doctrine/Query/Abstract.php(2077): Doctrine_Query_Condition-&amp;gt;parse(&apos;base. IS NULL&apos;)
#4 /Users/jwage/Sites/doctrine12/lib/Doctrine/Query.php(1160): Doctrine_Query_Abstract-&amp;gt;_processDqlQueryPart(&apos;where&apos;, Array)
#5 /Users/jwage/Sites/doctrine12/lib/Doctrine/Query.php(1126): Doctrine_Query-&amp;gt;buildSqlQuery(&lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;)
#6 /Users/jwage/Sites/doctrine12/lib/Doctrine/Query/Abstract.php(945): Doctrine_Query-&amp;gt;getSqlQuery(Array)
#7 /Users/jwage/Sites/doctrine12/lib/Doctrine/Query/Abstract.php(1026): Doctrine_Query_Abstract-&amp;gt;_execute(Array)
#8 /Users/jwage/Sites/doctrine12/lib/Doctrine/Tree/NestedSet.php(132): Doctrine_Query_Abstract-&amp;gt;execute()
#9 /Users/jwage/Sites/doctrine12/tests/NestedSet/SingleRootTestCase.php(60): Doctrine_Tree_NestedSet-&amp;gt;fetchRoot()
#10 /Users/jwage/Sites/doctrine12/tests/DoctrineTest/UnitTestCase.php(158): Doctrine_NestedSet_SingleRoot_TestCase-&amp;gt;testLftRgtValues()
#11 /Users/jwage/Sites/doctrine12/tests/DoctrineTest/GroupTest.php(75): UnitTestCase-&amp;gt;run()
#12 /Users/jwage/Sites/doctrine12/tests/DoctrineTest.php(183): GroupTest-&amp;gt;run(&lt;span class=&quot;code-object&quot;&gt;Object&lt;/span&gt;(DoctrineTest_Reporter_Cli), &apos;&apos;)
#13 /Users/jwage/Sites/doctrine12/tests/run.php(320): DoctrineTest-&amp;gt;run()
#14 {main}



Fatal error: Call to a member function getNode() on a non-object in /Users/jwage/Sites/doctrine12/tests/NestedSet/MultiRootTestCase.php on line 151

Call Stack:
    0.0047     521504   1. {main}() /Users/jwage/Sites/doctrine12/tests/run.php:0
    0.7401   50855368   2. DoctrineTest-&amp;gt;run() /Users/jwage/Sites/doctrine12/tests/run.php:320
    0.7410   50872656   3. GroupTest-&amp;gt;run() /Users/jwage/Sites/doctrine12/tests/DoctrineTest.php:183
   55.2363  158425064   4. UnitTestCase-&amp;gt;run() /Users/jwage/Sites/doctrine12/tests/DoctrineTest/GroupTest.php:75
   55.3227  158747088   5. Doctrine_NestedSet_MultiRoot_TestCase-&amp;gt;testSaveMultipleRootsWithChildren() /Users/jwage/Sites/doctrine12/tests/DoctrineTest/UnitTestCase.php:158


&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                    <comment id="13148" author="rishta" created="Tue, 8 Jun 2010 10:10:37 +0000"  >&lt;p&gt;Works for me (doctrine1-git):&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;code&amp;#93;&lt;/span&gt;&lt;br/&gt;
...&lt;br/&gt;
Doctrine_NestedSet_SingleRoot_TestCase..........................................passed&lt;br/&gt;
Doctrine_NestedSet_MultiRoot_TestCase...........................................passed&lt;br/&gt;
Doctrine_NestedSet_TimestampableMultiRoot_TestCase..............................passed&lt;br/&gt;
Doctrine_NestedSet_Hydration_TestCase...........................................passed&lt;/p&gt;

&lt;p&gt;Tested: 440 test cases.&lt;br/&gt;
Successes: 0 passes.&lt;br/&gt;
Failures: 0 fails.&lt;br/&gt;
Number of new Failures: 0 &lt;br/&gt;
Number of fixed Failures: 0 &lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;/code&amp;#93;&lt;/span&gt;&lt;/p&gt;</comment>
                    <comment id="13151" author="jwage" created="Tue, 8 Jun 2010 10:23:54 +0000"  >&lt;p&gt;I apply your patch cleanly to a fresh checkout from SVN and it fails for me. I tried on my laptop and the CI server. Hmm&lt;/p&gt;</comment>
                    <comment id="13157" author="rishta" created="Tue, 8 Jun 2010 10:36:18 +0000"  >&lt;p&gt;Your failure log shows&lt;/p&gt;

&lt;p&gt;#3 /Users/jwage/Sites/doctrine12/lib/Doctrine/Query/Abstract.php(2077): Doctrine_Query_Condition-&amp;gt;parse(&apos;base. IS NULL&apos;)&lt;/p&gt;

&lt;p&gt;which means the $this-&amp;gt;getAttribute(&apos;rootColumnName&apos;) returns nothing. I think the problem is not in the patch but I cannot reproduce it, so I can&apos;t help.&lt;/p&gt;</comment>
                    <comment id="13158" author="jwage" created="Tue, 8 Jun 2010 10:49:31 +0000"  >&lt;p&gt;rootColumnName can be empty in some cases, no? when you don&apos;t have multiple roots.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10625" name="Doctrine_Tree_NestedSet.patch" size="516" author="rishta" created="Fri, 4 Jun 2010 05:19:48 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-714] Fatal error(Call to a member function quoteIdentifier() on a non-object),  on batchUpdateIndex(), file search.php on line 246</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-714</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;I am creating a search in such a way that&apos;s: &lt;br/&gt;
$tenders = Doctrine::getTable(&apos;TableTenders&apos;);&lt;br/&gt;
$tenders-&amp;gt;batchUpdateIndex();&lt;/p&gt;

&lt;p&gt;after excute i have fatal error: Fatal error: Call to a member function quoteIdentifier() on a non-object in E:\home\tender.loc\www\engine\class\Doctrine\Doctrine\Search.php on line 246&lt;/p&gt;

&lt;p&gt;When i am opened Search.php on 246 line, i saw :  $conn-&amp;gt;quoteIdentifier($this-&amp;gt;_table-&amp;gt;getTableName())&lt;/p&gt;

&lt;p&gt;var_dump($conn) return NULL&lt;/p&gt;

&lt;p&gt;I climbed up the code and saw the error: $conn      = $this-&amp;gt;_options&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;connection&amp;#39;&amp;#93;&lt;/span&gt;; (line 228)&lt;br/&gt;
i change this on $conn      = $this-&amp;gt;_options&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;table&amp;#39;&amp;#93;&lt;/span&gt;-&amp;gt;getConnection();&lt;/p&gt;

&lt;p&gt;now works fine&lt;/p&gt;

&lt;p&gt;Sory for my english&lt;/p&gt;</description>
                <environment>Windows XP, php 5.2.4, Apache 2.0  </environment>
            <key id="11444">DC-714</key>
            <summary>Fatal error(Call to a member function quoteIdentifier() on a non-object),  on batchUpdateIndex(), file search.php on line 246</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="titanium">Alex Kucherenko</reporter>
                        <labels>
                    </labels>
                <created>Fri, 4 Jun 2010 02:42:02 +0000</created>
                <updated>Tue, 8 Jun 2010 09:28:40 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 09:28:40 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Searchable</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>1</watches>
                        <comments>
                    <comment id="13141" author="jwage" created="Tue, 8 Jun 2010 09:28:40 +0000"  >&lt;p&gt;Thanks for the issue and patch! &lt;img class=&quot;emoticon&quot; src=&quot;http://www.doctrine-project.org/jira/images/icons/emoticons/smile.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-712] [pgsql] missing quoteIdentifier() on &quot;alter table&quot; queries</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-712</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;In Doctrine_Export_Pgsql the table name of query like &quot;ALTER TABLE mytable ...&quot; are not quoted even if ATTR_QUOTE_IDENTIFIER is enabled.&lt;br/&gt;
This create failing queries, for example if the table to alter is called &apos;user&apos;.&lt;/p&gt;

&lt;p&gt;Please note in Mysql exporter the table name of ALTER TABLE queries is correctly quoted.&lt;/p&gt;</description>
                <environment>PostgreSQL</environment>
            <key id="11435">DC-712</key>
            <summary>[pgsql] missing quoteIdentifier() on &quot;alter table&quot; queries</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="osvi">Francesco Montefoschi</reporter>
                        <labels>
                    </labels>
                <created>Wed, 2 Jun 2010 04:33:06 +0000</created>
                <updated>Tue, 8 Jun 2010 09:47:12 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 09:47:12 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Import/Export</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="13089" author="osvi" created="Wed, 2 Jun 2010 04:51:01 +0000"  >&lt;p&gt;Proposed test and fix on github: &lt;a href=&quot;http://github.com/fmntf/doctrine1/tree/DC-712&quot; class=&quot;external-link&quot;&gt;http://github.com/fmntf/doctrine1/tree/DC-712&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="13142" author="jwage" created="Tue, 8 Jun 2010 09:47:12 +0000"  >&lt;p&gt;Thanks again for the issue and patch!&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-709] Column comments are not escaped</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-709</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Following schema.yml causes MySQL error because of the first column comment that contains the reserved &apos; char.&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;Client:
  columns:
    serial:    { type: string(50), primary: &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;, comment: &lt;span class=&quot;code-quote&quot;&gt;&quot;Seriale dell&apos;hardware&quot;&lt;/span&gt; }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The following works (note the double &apos;&apos;), but Doctrine schema should be automatically escaped&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;Client:
  columns:
    serial:    { type: string(50), primary: &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;, comment: &lt;span class=&quot;code-quote&quot;&gt;&quot;Seriale dell&apos;&apos;hardware&quot;&lt;/span&gt; }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</description>
                <environment>MySQL 5.1.41</environment>
            <key id="11423">DC-709</key>
            <summary>Column comments are not escaped</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="nicorac">Claudio Nicora</reporter>
                        <labels>
                    </labels>
                <created>Fri, 28 May 2010 09:15:16 +0000</created>
                <updated>Tue, 8 Jun 2010 10:21:29 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 09:56:32 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Schema Files</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>1</watches>
                        <comments>
                    <comment id="13086" author="johnkary" created="Tue, 1 Jun 2010 10:45:44 +0000"  >&lt;p&gt;Confirmed and fixed with test case: &lt;a href=&quot;http://github.com/johnkary/doctrine1/commit/640d2a11866e49b4315419ba665c4069c122e6b5&quot; class=&quot;external-link&quot;&gt;http://github.com/johnkary/doctrine1/commit/640d2a11866e49b4315419ba665c4069c122e6b5&lt;/a&gt;&lt;br/&gt;
Pull request sent.&lt;/p&gt;</comment>
                    <comment id="13144" author="jwage" created="Tue, 8 Jun 2010 09:56:32 +0000"  >&lt;p&gt;Thanks for the issue, test and patch! &lt;img class=&quot;emoticon&quot; src=&quot;http://www.doctrine-project.org/jira/images/icons/emoticons/smile.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</comment>
                    <comment id="13150" author="nicorac" created="Tue, 8 Jun 2010 10:21:29 +0000"  >&lt;p&gt;You&apos;re welcome. Mine was the easiest part &lt;img class=&quot;emoticon&quot; src=&quot;http://www.doctrine-project.org/jira/images/icons/emoticons/wink.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-706] Subqueries do not work in select</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-706</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Hi All&lt;/p&gt;

&lt;p&gt;I have found another bug in Doctrine 1.2.2.&lt;/p&gt;

&lt;p&gt;Subqueries are not working in select statements at the moment.&lt;/p&gt;

&lt;p&gt;The reason for this is that this line (found in the parseSelect function of the class Doctrine_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;$componentAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getExpressionOwner($expression);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Returns an unusable value when passed an $expression which is a subquery.&lt;/p&gt;

&lt;p&gt;To fix this problem I have patched my version of the code to use an existing &quot;$componentAlias&quot; instead of the value that would be returned by this function when a subquery is encountered.&lt;/p&gt;

&lt;p&gt;My code now reads:&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;&lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($pos !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt; &amp;amp;&amp;amp; substr($term[0], 0, 1) !== &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&quot;&lt;/span&gt; &amp;amp;&amp;amp; substr($term[0], 0, $pos) == &apos;&apos;) {
	$_queryComponents = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents;
	reset($components);
	$componentAlias = key($_queryComponents);
} &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
        $componentAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getExpressionOwner($expression);
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I have not rigorously tested this patch yet but it has been working for me in what tests I have done so far.&lt;/p&gt;

&lt;p&gt;I have posted several very large bugs into jira over the past few months and haven&apos;t heard back regarding them. This leads me to believe that the Doctrine team has moved on from Doctrine 1.2.2 and is focusing only on Doctrine 2 issues at this point. I still love version 1 and haven&apos;t had the heart (or the time) to migrate my code over to 2 yet. If this is the case then the job of patching bugs like the ones I have reported in 1.2.2 is probably up to us users at this point. As such I will post my patched version of Doctrine_Query in a comment to this bug (My patched version also fixes another bug I reported: &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-594&quot; title=&quot;When using a combination of: a group by field referencing a table in a relation, a join to a different table via a many type relation and a limit clause, doctrine creates a broken query then throws an exception&quot;&gt;&lt;del&gt;DC-594&lt;/del&gt;&lt;/a&gt;) .&lt;/p&gt;

&lt;p&gt;Best Regards&lt;/p&gt;

&lt;p&gt;Will Ferrer&lt;/p&gt;</description>
                <environment>XP, Xamp</environment>
            <key id="11418">DC-706</key>
            <summary>Subqueries do not work in select</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="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="willf1976">will ferrer</reporter>
                        <labels>
                    </labels>
                <created>Thu, 27 May 2010 03:22:37 +0000</created>
                <updated>Tue, 8 Jun 2010 19:09:33 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 18:59:30 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="13066" author="willf1976" created="Thu, 27 May 2010 03:25:17 +0000"  >&lt;p&gt;Here is the whole of my Doctrine_Query posted for any one who wants to use the bug patches I put into the file (they are both marked with a comment that says: &quot;Patched By Will Ferrer&quot;&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;&amp;lt;?php
/*
 *  $Id: Query.php 7490 2010-03-29 19:53:27Z jwage $
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * &lt;span class=&quot;code-quote&quot;&gt;&quot;AS IS&quot;&lt;/span&gt; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the LGPL. For more information, see
 * &amp;lt;http:&lt;span class=&quot;code-comment&quot;&gt;//www.doctrine-project.org&amp;gt;.
&lt;/span&gt; */

/**
 * Doctrine_Query
 * A Doctrine_Query object represents a DQL query. It is used to query databases &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt;
 * data in an object-oriented fashion. A DQL query understands relations and inheritance
 * and is dbms independant.
 *
 * @&lt;span class=&quot;code-keyword&quot;&gt;package&lt;/span&gt;     Doctrine
 * @subpackage  Query
 * @license     http:&lt;span class=&quot;code-comment&quot;&gt;//www.opensource.org/licenses/lgpl-license.php LGPL
&lt;/span&gt; * @link        www.doctrine-project.org
 * @since       1.0
 * @version     $Revision: 7490 $
 * @author      Konsta Vesterinen &amp;lt;kvesteri@cc.hut.fi&amp;gt;
 * @todo        Proposal: This class does far too much. It should have only 1 task: Collecting
 *              the DQL query parts and the query parameters (the query state and caching options/methods
 *              can remain here, too).
 *              The actual SQL construction could be done by a separate object (Doctrine_Query_SqlBuilder?)
 *              whose task it is to convert DQL into SQL.
 *              Furthermore the SqlBuilder? can then use other objects (Doctrine_Query_Tokenizer?),
 *              (Doctrine_Query_Parser(s)?) to accomplish his work. Doctrine_Query does not need
 *              to know the tokenizer/parsers. There could be extending
 *              implementations of SqlBuilder? that cover the specific SQL dialects.
 *              This would release Doctrine_Connection and the Doctrine_Connection_xxx classes
 *              from &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; tedious task.
 *              This would also largely reduce the currently huge &lt;span class=&quot;code-keyword&quot;&gt;interface&lt;/span&gt; of Doctrine_Query(_Abstract)
 *              and better hide all these transformation internals from the &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; Query API.
 *
 * @internal    The lifecycle of a Query object is the following:
 *              After construction the query object is empty. Through using the fluent
 *              query &lt;span class=&quot;code-keyword&quot;&gt;interface&lt;/span&gt; the user fills the query object with DQL parts and query parameters.
 *              These get collected in {@link $_dqlParts} and {@link $_params}, respectively.
 *              When the query is executed the first time, or when {@link getSqlQuery()}
 *              is called the first time, the collected DQL parts get parsed and the resulting
 *              connection-driver specific SQL is generated. The generated SQL parts are
 *              stored in {@link $_sqlParts} and the &lt;span class=&quot;code-keyword&quot;&gt;final&lt;/span&gt; resulting SQL query is stored in
 *              {@link $_sql}.
 */
class Doctrine_Query &lt;span class=&quot;code-keyword&quot;&gt;extends&lt;/span&gt; Doctrine_Query_Abstract &lt;span class=&quot;code-keyword&quot;&gt;implements&lt;/span&gt; Countable
{
    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; array  The DQL keywords.
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;static&lt;/span&gt; $_keywords  = array(&apos;ALL&apos;,
                                         &apos;AND&apos;,
                                         &apos;ANY&apos;,
                                         &apos;AS&apos;,
                                         &apos;ASC&apos;,
                                         &apos;AVG&apos;,
                                         &apos;BETWEEN&apos;,
                                         &apos;BIT_LENGTH&apos;,
                                         &apos;BY&apos;,
                                         &apos;CHARACTER_LENGTH&apos;,
                                         &apos;CHAR_LENGTH&apos;,
                                         &apos;CURRENT_DATE&apos;,
                                         &apos;CURRENT_TIME&apos;,
                                         &apos;CURRENT_TIMESTAMP&apos;,
                                         &apos;DELETE&apos;,
                                         &apos;DESC&apos;,
                                         &apos;DISTINCT&apos;,
                                         &apos;EMPTY&apos;,
                                         &apos;EXISTS&apos;,
                                         &apos;FALSE&apos;,
                                         &apos;FETCH&apos;,
                                         &apos;FROM&apos;,
                                         &apos;GROUP&apos;,
                                         &apos;HAVING&apos;,
                                         &apos;IN&apos;,
                                         &apos;INDEXBY&apos;,
                                         &apos;INNER&apos;,
                                         &apos;IS&apos;,
                                         &apos;JOIN&apos;,
                                         &apos;LEFT&apos;,
                                         &apos;LIKE&apos;,
                                         &apos;LOWER&apos;,
                                         &apos;MEMBER&apos;,
                                         &apos;MOD&apos;,
                                         &apos;NEW&apos;,
                                         &apos;NOT&apos;,
                                         &apos;NULL&apos;,
                                         &apos;OBJECT&apos;,
                                         &apos;OF&apos;,
                                         &apos;OR&apos;,
                                         &apos;ORDER&apos;,
                                         &apos;OUTER&apos;,
                                         &apos;POSITION&apos;,
                                         &apos;SELECT&apos;,
                                         &apos;SOME&apos;,
                                         &apos;TRIM&apos;,
                                         &apos;TRUE&apos;,
                                         &apos;UNKNOWN&apos;,
                                         &apos;UPDATE&apos;,
                                         &apos;WHERE&apos;);

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; array
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_subqueryAliases = array();

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; array $_aggregateAliasMap       an array containing all aggregate aliases, keys as dql aliases
     *                                      and values as sql aliases
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_aggregateAliasMap      = array();

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; array
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_pendingAggregates = array();

    /**
     * @param &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt; $needsSubquery
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_needsSubquery = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;

    /**
     * @param &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt; $isSubquery           whether or not &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; query object is a subquery of another
     *                                      query object
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_isSubquery;

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; array $_neededTables            an array containing the needed table aliases
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_neededTables = array();

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; array $pendingSubqueries        SELECT part subqueries, these are called pending subqueries since
     *                                      they cannot be parsed directly (some queries might be correlated)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_pendingSubqueries = array();

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; array $_pendingFields           an array of pending fields (fields waiting to be parsed)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_pendingFields = array();

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; array $_parsers                 an array of parser objects, each DQL query part has its own parser
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_parsers = array();

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; array $_pendingJoinConditions    an array containing pending joins
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_pendingJoinConditions = array();

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; array
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_expressionMap = array();

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; string $_sql            cached SQL query
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_sql;

    /**
     * create
     * returns a &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query object
     *
     * @param Doctrine_Connection $conn  optional connection parameter
     * @param string $class              Query class to instantiate
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; Doctrine_Query
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;static&lt;/span&gt; function create($conn = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;, $class = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $class) {
            $class = Doctrine_Manager::getInstance()
                -&amp;gt;getAttribute(Doctrine_Core::ATTR_QUERY_CLASS);
        }
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; $class($conn);
    }

    /**
     * Clears all the sql parts.
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; function clear()
    {
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_preQueried = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingJoinConditions = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_state = self::STATE_DIRTY;
    }

    /**
     * Resets the query to the state just after it has been instantiated.
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function reset()
    {
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_subqueryAliases = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingAggregates = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingSubqueries = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingFields = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_neededTables = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_expressionMap = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_subqueryAliases = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_needsSubquery = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_isLimitSubqueryUsed = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
    }

    /**
     * createSubquery
     * creates a subquery
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; Doctrine_Hydrate
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function createSubquery()
    {
        $class = get_class($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;);
        $obj   = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; $class();

        &lt;span class=&quot;code-comment&quot;&gt;// copy the aliases to the subquery
&lt;/span&gt;        $obj-&amp;gt;copySubqueryInfo($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;);

        &lt;span class=&quot;code-comment&quot;&gt;// &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; prevents the &apos;id&apos; being selected, re ticket #307
&lt;/span&gt;        $obj-&amp;gt;isSubquery(&lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;);

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $obj;
    }

    /**
     * addPendingJoinCondition
     *
     * @param string $componentAlias    component alias
     * @param string $joinCondition     dql join condition
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; Doctrine_Query           &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; object
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function addPendingJoinCondition($componentAlias, $joinCondition)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingJoinConditions[$componentAlias])) {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingJoinConditions[$componentAlias] = array();
        }

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingJoinConditions[$componentAlias][] = $joinCondition;
    }

    /**
     * fetchArray
     * Convenience method to execute using array fetching as hydration mode.
     *
     * @param string $params
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; array
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function fetchArray($params = array())
    {
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;execute($params, Doctrine_Core::HYDRATE_ARRAY);
    }

    /**
     * fetchOne
     * Convenience method to execute the query and &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; the first item
     * of the collection.
     *
     * @param string $params        Query parameters
     * @param &lt;span class=&quot;code-object&quot;&gt;int&lt;/span&gt; $hydrationMode    Hydration mode: see Doctrine_Core::HYDRATE_* constants
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; mixed                Array or Doctrine_Collection, depending on hydration mode. False &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; no result.
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function fetchOne($params = array(), $hydrationMode = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;)
    {
        $collection = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;execute($params, $hydrationMode);

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (is_scalar($collection)) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $collection;
        }

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($collection) === 0) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
        }

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($collection &lt;span class=&quot;code-keyword&quot;&gt;instanceof&lt;/span&gt; Doctrine_Collection) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $collection-&amp;gt;getFirst();
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (is_array($collection)) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; array_shift($collection);
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
    }

    /**
     * isSubquery
     * &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; $bool parameter is set &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; method sets the value of
     * Doctrine_Query::$isSubquery. If &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; value is set to &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;
     * the query object will not load the primary key fields of the selected
     * components.
     *
     * If &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt; is given as the first parameter &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; method retrieves the current
     * value of Doctrine_Query::$isSubquery.
     *
     * @param &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt; $bool     whether or not &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; query acts as a subquery
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; Doctrine_Query|bool
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function isSubquery($bool = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($bool === &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_isSubquery;
        }

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_isSubquery = (bool) $bool;
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;;
    }

    /**
     * getSqlAggregateAlias
     *
     * @param string $dqlAlias      the dql alias of an aggregate value
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getSqlAggregateAlias($dqlAlias)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap[$dqlAlias])) {
            &lt;span class=&quot;code-comment&quot;&gt;// mark the expression as used
&lt;/span&gt;            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_expressionMap[$dqlAlias][1] = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;

            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap[$dqlAlias];
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingAggregates)) {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;processPendingAggregates();

            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlAggregateAlias($dqlAlias);
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt;( ! ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;getAttribute(Doctrine_Core::ATTR_PORTABILITY) &amp;amp; Doctrine_Core::PORTABILITY_EXPR)){
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $dqlAlias;
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&apos;Unknown aggregate alias: &apos; . $dqlAlias);
        }
    }

    /**
     * Check &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; a dql alias has a sql aggregate alias
     *
     * @param string $dqlAlias 
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt;
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function hasSqlAggregateAlias($dqlAlias)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;try&lt;/span&gt; {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlAggregateAlias($dqlAlias);
            &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;catch&lt;/span&gt; (Exception $e) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
        }
    }

    /**
     * Adjust the processed param index &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;code-quote&quot;&gt;&quot;foo.bar IN ?&quot;&lt;/span&gt; support
     *
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function adjustProcessedParam($index)
    {
        &lt;span class=&quot;code-comment&quot;&gt;// Retrieve all params
&lt;/span&gt;        $params = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getInternalParams();

        &lt;span class=&quot;code-comment&quot;&gt;// Retrieve already processed values
&lt;/span&gt;        $first = array_slice($params, 0, $index);
        $last = array_slice($params, $index, count($params) - $index);

        &lt;span class=&quot;code-comment&quot;&gt;// Include array as values splicing the params array
&lt;/span&gt;        array_splice($last, 0, 1, $last[0]);

        &lt;span class=&quot;code-comment&quot;&gt;// Put all param values into a single index
&lt;/span&gt;        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_execParams = array_merge($first, $last);
    }

    /**
     * Retrieves a specific DQL query part.
     *
     * @see Doctrine_Query_Abstract::$_dqlParts
     * &amp;lt;code&amp;gt;
     * var_dump($q-&amp;gt;getDqlPart(&apos;where&apos;));
     * &lt;span class=&quot;code-comment&quot;&gt;// array(2) { [0] =&amp;gt; string(8) &apos;name = ?&apos; [1] =&amp;gt; string(8) &apos;date &amp;gt; ?&apos; }
&lt;/span&gt;     * &amp;lt;/code&amp;gt;
     * @param string $queryPart     the name of the query part; can be:
     *     array from, containing strings;
     *     array select, containg string;
     *     &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt; forUpdate;
     *     array set;
     *     array join;
     *     array where;
     *     array groupby;
     *     array having;
     *     array orderby, containing strings such as &apos;id ASC&apos;;
     *     array limit, containing numerics;
     *     array offset, containing numerics;
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; array
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getDqlPart($queryPart)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_dqlParts[$queryPart])) {
           &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&apos;Unknown query part &apos; . $queryPart);
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_dqlParts[$queryPart];
    }

    /**
     * contains
     *
     * Method to check &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; a arbitrary piece of dql exists
     *
     * @param string $dql Arbitrary piece of dql to check &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt;
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt;
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function contains($dql)
    {
      &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; stripos($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getDql(), $dql) === &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt; ? &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt; : &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;
    }

    /**
     * processPendingFields
     * the fields in SELECT clause cannot be parsed until the components
     * in FROM clause are parsed, hence &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; method is called everytime a
     * specific component is being parsed. For instance, the wildcard &apos;*&apos;
     * is expanded in the list of columns.
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;throws&lt;/span&gt; Doctrine_Query_Exception     &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; unknown component alias has been given
     * @param string $componentAlias        the alias of the component
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string SQL code
     * @todo Description: What is a &apos;pending field&apos; (and are there non-pending fields, too)?
     *       What is &apos;processed&apos;? (Meaning: What information is gathered &amp;amp; stored away)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function processPendingFields($componentAlias)
    {
        $tableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias);
        $table = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;table&apos;];

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingFields[$componentAlias])) {
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_hydrator-&amp;gt;getHydrationMode() != Doctrine_Core::HYDRATE_NONE) {
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_isSubquery &amp;amp;&amp;amp; $componentAlias == $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootAlias()) {
                    &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&lt;span class=&quot;code-quote&quot;&gt;&quot;The root class of the query (alias $componentAlias) &quot;&lt;/span&gt;
                            . &lt;span class=&quot;code-quote&quot;&gt;&quot; must have at least one field selected.&quot;&lt;/span&gt;);
                }
            }
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt;;
        }

        &lt;span class=&quot;code-comment&quot;&gt;// At &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; point we know the component is FETCHED (either it&apos;s the base class of
&lt;/span&gt;        &lt;span class=&quot;code-comment&quot;&gt;// the query (FROM xyz) or its a &lt;span class=&quot;code-quote&quot;&gt;&quot;fetch join&quot;&lt;/span&gt;).
&lt;/span&gt;
        &lt;span class=&quot;code-comment&quot;&gt;// Check that the parent join (&lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; there is one), is a &lt;span class=&quot;code-quote&quot;&gt;&quot;fetch join&quot;&lt;/span&gt;, too.
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;isSubquery() &amp;amp;&amp;amp; isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;parent&apos;])) {
            $parentAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;parent&apos;];
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (is_string($parentAlias) &amp;amp;&amp;amp; ! isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingFields[$parentAlias])
                    &amp;amp;&amp;amp; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_hydrator-&amp;gt;getHydrationMode() != Doctrine_Core::HYDRATE_NONE
                    &amp;amp;&amp;amp; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_hydrator-&amp;gt;getHydrationMode() != Doctrine_Core::HYDRATE_SCALAR
                    &amp;amp;&amp;amp; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_hydrator-&amp;gt;getHydrationMode() != Doctrine_Core::HYDRATE_SINGLE_SCALAR) {
                &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&lt;span class=&quot;code-quote&quot;&gt;&quot;The left side of the join between &quot;&lt;/span&gt;
                        . &lt;span class=&quot;code-quote&quot;&gt;&quot;the aliases &apos;$parentAlias&apos; and &apos;$componentAlias&apos; must have at least&quot;&lt;/span&gt;
                        . &lt;span class=&quot;code-quote&quot;&gt;&quot; the primary key field(s) selected.&quot;&lt;/span&gt;);
            }
        }

        $fields = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingFields[$componentAlias];

        &lt;span class=&quot;code-comment&quot;&gt;// check &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; wildcards
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (in_array(&apos;*&apos;, $fields)) {
            $fields = $table-&amp;gt;getFieldNames();
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            $driverClassName = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_hydrator-&amp;gt;getHydratorDriverClassName();
            &lt;span class=&quot;code-comment&quot;&gt;// only auto-add the primary key fields &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; query object is not
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;// a subquery of another query object or we&apos;re using a child of the &lt;span class=&quot;code-object&quot;&gt;Object&lt;/span&gt; Graph
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;// hydrator
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_isSubquery &amp;amp;&amp;amp; is_subclass_of($driverClassName, &apos;Doctrine_Hydrator_Graph&apos;)) {
                $fields = array_unique(array_merge((array) $table-&amp;gt;getIdentifier(), $fields));
            }
        }

        $sql = array();
        foreach ($fields as $fieldName) {
            $columnName = $table-&amp;gt;getColumnName($fieldName);
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (($owner = $table-&amp;gt;getColumnOwner($columnName)) !== &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt; &amp;amp;&amp;amp;
                    $owner !== $table-&amp;gt;getComponentName()) {

                $parent = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;getTable($owner);
                $columnName = $parent-&amp;gt;getColumnName($fieldName);
                $parentAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias . &apos;.&apos; . $parent-&amp;gt;getComponentName());
                $sql[] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($parentAlias) . &apos;.&apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($columnName)
                       . &apos; AS &apos;
                       . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias . &apos;__&apos; . $columnName);
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                $columnName = $table-&amp;gt;getColumnName($fieldName);
                $sql[] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias) . &apos;.&apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($columnName)
                       . &apos; AS &apos;
                       . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias . &apos;__&apos; . $columnName);
            }
        }

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_neededTables[] = $tableAlias;

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; implode(&apos;, &apos;, $sql);
    }

    /**
     * Parses a nested field
     * &amp;lt;code&amp;gt;
     * $q-&amp;gt;parseSelectField(&apos;u.Phonenumber.value&apos;);
     * &amp;lt;/code&amp;gt;
     *
     * @param string $field
     * @&lt;span class=&quot;code-keyword&quot;&gt;throws&lt;/span&gt; Doctrine_Query_Exception     &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; unknown component alias has been given
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string   SQL fragment
     * @todo Description: Explain what &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; method does. Is there a relation to parseSelect()?
     *       This method is not used from any class or testcase in the Doctrine &lt;span class=&quot;code-keyword&quot;&gt;package&lt;/span&gt;.
     *
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function parseSelectField($field)
    {
        $terms = explode(&apos;.&apos;, $field);

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($terms[1])) {
            $componentAlias = $terms[0];
            $field = $terms[1];
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            reset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents);
            $componentAlias = key($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents);
            $fields = $terms[0];
        }

        $tableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias);
        $table      = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;table&apos;];


        &lt;span class=&quot;code-comment&quot;&gt;// check &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; wildcards
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($field === &apos;*&apos;) {
            $sql = array();

            foreach ($table-&amp;gt;getColumnNames() as $field) {
                $sql[] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;parseSelectField($componentAlias . &apos;.&apos; . $field);
            }

            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; implode(&apos;, &apos;, $sql);
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            $name = $table-&amp;gt;getColumnName($field);

            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_neededTables[] = $tableAlias;

            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias . &apos;.&apos; . $name)
                   . &apos; AS &apos;
                   . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias . &apos;__&apos; . $name);
        }
    }

    /**
     * getExpressionOwner
     * returns the component alias &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; owner of given expression
     *
     * @param string $expr      expression from which to get to owner from
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string           the component alias
     * @todo Description: What does it mean &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; a component is an &apos;owner&apos; of an expression?
     *       What kind of &apos;expression&apos; are we talking about here?
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getExpressionOwner($expr)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strtoupper(substr(trim($expr, &apos;( &apos;), 0, 6)) !== &apos;SELECT&apos;) {
            preg_match_all(&lt;span class=&quot;code-quote&quot;&gt;&quot;/[a-z_][a-z0-9_]*\.[a-z_][a-z0-9_]*[\.[a-z0-9]+]*/i&quot;&lt;/span&gt;, $expr, $matches);

            $match = current($matches);

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($match[0])) {
                $terms = explode(&apos;.&apos;, $match[0]);

                &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $terms[0];
            }
        }
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootAlias();

    }

    /**
     * parseSelect
     * parses the query select part and
     * adds selected fields to pendingFields array
     *
     * @param string $dql
     * @todo Description: What information is extracted (and then stored)?
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function parseSelect($dql)
    {
        $refs = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;sqlExplode($dql, &apos;,&apos;);

        $pos   = strpos(trim($refs[0]), &apos; &apos;);
        $first = substr($refs[0], 0, $pos);

        &lt;span class=&quot;code-comment&quot;&gt;// check &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; DISTINCT keyword
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($first === &apos;DISTINCT&apos;) {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;distinct&apos;] = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;

            $refs[0] = substr($refs[0], ++$pos);
        }

        $parsedComponents = array();

        foreach ($refs as $reference) {
            $reference = trim($reference);

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (empty($reference)) {
                &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
            }

            $terms = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;sqlExplode($reference, &apos; &apos;);
            $pos   = strpos($terms[0], &apos;(&apos;);

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($terms) &amp;gt; 1 || $pos !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                $expression = array_shift($terms);
                $alias = array_pop($terms);

                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $alias) {
                    $alias = substr($expression, 0, $pos);
                }
				
			&lt;span class=&quot;code-comment&quot;&gt;//Patched By Will Ferrer to detect when a subquery was encountered and use an existing componentAlias &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; the expression is a subquery. (not well tested) Fixes Bug -- DC-706
&lt;/span&gt;				&lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($pos !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt; &amp;amp;&amp;amp; substr($term[0], 0, 1) !== &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&quot;&lt;/span&gt; &amp;amp;&amp;amp; substr($term[0], 0, $pos) == &apos;&apos;) {
					$_queryComponents = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents;
					reset($components);
					$componentAlias = key($_queryComponents);
				} &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
               		$componentAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getExpressionOwner($expression);
				}
			&lt;span class=&quot;code-comment&quot;&gt;//End Patch
&lt;/span&gt;			
				$expression = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;parseClause($expression);

                $tableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias);
				
                $index    = count($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap);

                $sqlAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias . &apos;__&apos; . $index);

                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;select&apos;][] = $expression . &apos; AS &apos; . $sqlAlias;

                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap[$alias] = $sqlAlias;
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_expressionMap[$alias][0] = $expression;

                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;agg&apos;][$index] = $alias;
				
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_neededTables[] = $tableAlias;
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                $e = explode(&apos;.&apos;, $terms[0]);

                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($e[1])) {
                    $componentAlias = $e[0];
                    $field = $e[1];
                } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                    reset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents);
                    $componentAlias = key($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents);
                    $field = $e[0];
                }

                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingFields[$componentAlias][] = $field;
            }
        }
    }

    /**
     * parseClause
     * parses given DQL clause
     *
     * &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; method handles five tasks:
     *
     * 1. Converts all DQL functions to their &lt;span class=&quot;code-keyword&quot;&gt;native&lt;/span&gt; SQL equivalents
     * 2. Converts all component references to their table alias equivalents
     * 3. Converts all field names to actual column names
     * 4. Quotes all identifiers
     * 5. Parses nested clauses and subqueries recursively
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string   SQL string
     * @todo Description: What is a &apos;dql clause&apos; (and what not)?
     *       Refactor: Too &lt;span class=&quot;code-object&quot;&gt;long&lt;/span&gt; &amp;amp; nesting level
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function parseClause($clause)
    {
        $clause = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;dataDict-&amp;gt;parseBoolean(trim($clause));

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (is_numeric($clause)) {
           &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $clause;
        }

        $terms = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;clauseExplode($clause, array(&apos; &apos;, &apos;+&apos;, &apos;-&apos;, &apos;*&apos;, &apos;/&apos;, &apos;&amp;lt;&apos;, &apos;&amp;gt;&apos;, &apos;=&apos;, &apos;&amp;gt;=&apos;, &apos;&amp;lt;=&apos;, &apos;&amp;amp;&apos;, &apos;|&apos;));
        $str = &apos;&apos;;

        foreach ($terms as $term) {
            $pos = strpos($term[0], &apos;(&apos;);

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($pos !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt; &amp;amp;&amp;amp; substr($term[0], 0, 1) !== &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&quot;&lt;/span&gt;) {
                $name = substr($term[0], 0, $pos);

                $term[0] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;parseFunctionExpression($term[0]);
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (substr($term[0], 0, 1) !== &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&quot;&lt;/span&gt; &amp;amp;&amp;amp; substr($term[0], -1) !== &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&quot;&lt;/span&gt;) {
                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($term[0], &apos;.&apos;) !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! is_numeric($term[0])) {
                            $e = explode(&apos;.&apos;, $term[0]);

                            $field = array_pop($e);

                            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getType() === Doctrine_Query::SELECT) {
                                $componentAlias = implode(&apos;.&apos;, $e);

                                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (empty($componentAlias)) {
                                    $componentAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootAlias();
                                }

                                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;load($componentAlias);

                                &lt;span class=&quot;code-comment&quot;&gt;// check the existence of the component alias
&lt;/span&gt;                                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias])) {
                                    &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&apos;Unknown component alias &apos; . $componentAlias);
                                }

                                $table = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;table&apos;];

                                $def = $table-&amp;gt;getDefinitionOf($field);

                                &lt;span class=&quot;code-comment&quot;&gt;// get the actual field name from alias
&lt;/span&gt;                                $field = $table-&amp;gt;getColumnName($field);

                                &lt;span class=&quot;code-comment&quot;&gt;// check column existence
&lt;/span&gt;                                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $def) {
                                    &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&apos;Unknown column &apos; . $field);
                                }

                                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($def[&apos;owner&apos;])) {
                                    $componentAlias = $componentAlias . &apos;.&apos; . $def[&apos;owner&apos;];
                                }

                                $tableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias);

                                &lt;span class=&quot;code-comment&quot;&gt;// build sql expression
&lt;/span&gt;                                $term[0] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias)
                                         . &apos;.&apos;
                                         . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($field);
                            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                                &lt;span class=&quot;code-comment&quot;&gt;// build sql expression
&lt;/span&gt;                                $field = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRoot()-&amp;gt;getColumnName($field);
                                $term[0] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($field);
                            }
                        }
                    } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($term[0]) &amp;amp;&amp;amp; ! in_array(strtoupper($term[0]), self::$_keywords) &amp;amp;&amp;amp;
                             ! is_numeric($term[0]) &amp;amp;&amp;amp; $term[0] !== &apos;?&apos; &amp;amp;&amp;amp; substr($term[0], 0, 1) !== &apos;:&apos;) {

                            $componentAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootAlias();

                            $found = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;

                            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($componentAlias !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt; &amp;amp;&amp;amp; $componentAlias !== &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;) {
                                $table = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;table&apos;];

                                &lt;span class=&quot;code-comment&quot;&gt;// check column existence
&lt;/span&gt;                                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($table-&amp;gt;hasField($term[0])) {
                                    $found = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;

                                    $def = $table-&amp;gt;getDefinitionOf($term[0]);

                                    &lt;span class=&quot;code-comment&quot;&gt;// get the actual column name from field name
&lt;/span&gt;                                    $term[0] = $table-&amp;gt;getColumnName($term[0]);


                                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($def[&apos;owner&apos;])) {
                                        $componentAlias = $componentAlias . &apos;.&apos; . $def[&apos;owner&apos;];
                                    }

                                    $tableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias);

                                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getType() === Doctrine_Query::SELECT) {
                                        &lt;span class=&quot;code-comment&quot;&gt;// build sql expression
&lt;/span&gt;                                        $term[0] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias)
                                                 . &apos;.&apos;
                                                 . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($term[0]);
                                    } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                                        &lt;span class=&quot;code-comment&quot;&gt;// build sql expression
&lt;/span&gt;                                        $term[0] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($term[0]);
                                    }
                                } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                                    $found = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
                                }
                            }

                            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $found) {
                                $term[0] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlAggregateAlias($term[0]);
                            }
                        }
                    }
                }
            }

            $str .= $term[0] . $term[1];
        }
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $str;
    }

    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function parseIdentifierReference($expr)
    {

    }

    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function parseFunctionExpression($expr)
    {
        $pos = strpos($expr, &apos;(&apos;);
        $name = substr($expr, 0, $pos);

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($name === &apos;&apos;) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;parseSubquery($expr);
        }

        $argStr = substr($expr, ($pos + 1), -1);
        $args   = array();
        &lt;span class=&quot;code-comment&quot;&gt;// parse args
&lt;/span&gt;
        foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;sqlExplode($argStr, &apos;,&apos;) as $arg) {
           $args[] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;parseClause($arg);
        }

        &lt;span class=&quot;code-comment&quot;&gt;// convert DQL function to its RDBMS specific equivalent
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;try&lt;/span&gt; {
            $expr = call_user_func_array(array($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;expression, $name), $args);
        } &lt;span class=&quot;code-keyword&quot;&gt;catch&lt;/span&gt; (Doctrine_Expression_Exception $e) {
            &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&apos;Unknown function &apos; . $name . &apos;.&apos;);
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $expr;
    }


    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function parseSubquery($subquery)
    {
        $trimmed = trim($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;bracketTrim($subquery));

        &lt;span class=&quot;code-comment&quot;&gt;// check &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; possible subqueries
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (substr($trimmed, 0, 4) == &apos;FROM&apos; || substr($trimmed, 0, 6) == &apos;SELECT&apos;) {
            &lt;span class=&quot;code-comment&quot;&gt;// parse subquery
&lt;/span&gt;            $q = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;createSubquery()-&amp;gt;parseDqlQuery($trimmed);
            $trimmed = $q-&amp;gt;getSqlQuery();
            $q-&amp;gt;free();
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (substr($trimmed, 0, 4) == &apos;SQL:&apos;) {
            $trimmed = substr($trimmed, 4);
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            $e = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;sqlExplode($trimmed, &apos;,&apos;);

            $value = array();
            $index = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;

            foreach ($e as $part) {
                $value[] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;parseClause($part);
            }

            $trimmed = implode(&apos;, &apos;, $value);
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &apos;(&apos; . $trimmed . &apos;)&apos;;
    }


    /**
     * processPendingSubqueries
     * processes pending subqueries
     *
     * subqueries can only be processed when the query is fully constructed
     * since some subqueries may be correlated
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; void
     * @todo Better description. i.e. What is a &apos;pending subquery&apos;? What does &apos;processed&apos; mean?
     *       (parsed? sql is constructed? some information is gathered?)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function processPendingSubqueries()
    {
        foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingSubqueries as $value) {
            list($dql, $alias) = $value;

            $subquery = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;createSubquery();

            $sql = $subquery-&amp;gt;parseDqlQuery($dql, &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;)-&amp;gt;getQuery();
            $subquery-&amp;gt;free();

            reset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents);
            $componentAlias = key($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents);
            $tableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias);

            $sqlAlias = $tableAlias . &apos;__&apos; . count($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap);

            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;select&apos;][] = &apos;(&apos; . $sql . &apos;) AS &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($sqlAlias);

            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap[$alias] = $sqlAlias;
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;agg&apos;][] = $alias;
        }
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingSubqueries = array();
    }

    /**
     * processPendingAggregates
     * processes pending aggregate values &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; given component alias
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; void
     * @todo Better description. i.e. What is a &apos;pending aggregate&apos;? What does &apos;processed&apos; mean?
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function processPendingAggregates()
    {
        &lt;span class=&quot;code-comment&quot;&gt;// iterate trhough all aggregates
&lt;/span&gt;        foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingAggregates as $aggregate) {
            list ($expression, $components, $alias) = $aggregate;

            $tableAliases = array();

            &lt;span class=&quot;code-comment&quot;&gt;// iterate through the component references within the aggregate function
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty ($components)) {
                foreach ($components as $component) {

                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (is_numeric($component)) {
                        &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
                    }

                    $e = explode(&apos;.&apos;, $component);

                    $field = array_pop($e);
                    $componentAlias = implode(&apos;.&apos;, $e);

                    &lt;span class=&quot;code-comment&quot;&gt;// check the existence of the component alias
&lt;/span&gt;                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias])) {
                        &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&apos;Unknown component alias &apos; . $componentAlias);
                    }

                    $table = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;table&apos;];

                    $field = $table-&amp;gt;getColumnName($field);

                    &lt;span class=&quot;code-comment&quot;&gt;// check column existence
&lt;/span&gt;                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $table-&amp;gt;hasColumn($field)) {
                        &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&apos;Unknown column &apos; . $field);
                    }

                    $sqlTableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias);

                    $tableAliases[$sqlTableAlias] = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;

                    &lt;span class=&quot;code-comment&quot;&gt;// build sql expression
&lt;/span&gt;
                    $identifier = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($sqlTableAlias . &apos;.&apos; . $field);
                    $expression = str_replace($component, $identifier, $expression);
                }
            }

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($tableAliases) !== 1) {
                $componentAlias = reset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tableAliasMap);
                $tableAlias = key($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tableAliasMap);
            }

            $index    = count($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap);
            $sqlAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias . &apos;__&apos; . $index);

            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;select&apos;][] = $expression . &apos; AS &apos; . $sqlAlias;

            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap[$alias] = $sqlAlias;
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_expressionMap[$alias][0] = $expression;

            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;agg&apos;][$index] = $alias;

            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_neededTables[] = $tableAlias;
        }
        &lt;span class=&quot;code-comment&quot;&gt;// reset the state
&lt;/span&gt;        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingAggregates = array();
    }

    /**
     * _buildSqlQueryBase
     * returns the base of the generated sql query
     * On mysql driver special strategy has to be used &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; DELETE statements
     * (where is &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; special strategy??)
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string       the base of the generated sql query
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; function _buildSqlQueryBase()
    {
        &lt;span class=&quot;code-keyword&quot;&gt;switch&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_type) {
            &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; self::DELETE:
                $q = &apos;DELETE FROM &apos;;
            &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
            &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; self::UPDATE:
                $q = &apos;UPDATE &apos;;
            &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
            &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; self::SELECT:
                $distinct = ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;distinct&apos;]) ? &apos;DISTINCT &apos; : &apos;&apos;;
                $q = &apos;SELECT &apos; . $distinct . implode(&apos;, &apos;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;select&apos;]) . &apos; FROM &apos;;
            &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
        }
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $q;
    }

    /**
     * _buildSqlFromPart
     * builds the from part of the query and returns it
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string   the query sql from part
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; function _buildSqlFromPart($ignorePending = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;)
    {
        $q = &apos;&apos;;

        foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;from&apos;] as $k =&amp;gt; $part) {
            $e = explode(&apos; &apos;, $part);

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($k === 0) {
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $ignorePending &amp;amp;&amp;amp; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_type == self::SELECT) {
                    &lt;span class=&quot;code-comment&quot;&gt;// We may still have pending conditions
&lt;/span&gt;                    $alias = count($e) &amp;gt; 1
                        ? $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getComponentAlias($e[1])
                        : &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;;
                    $where = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_processPendingJoinConditions($alias);

                    &lt;span class=&quot;code-comment&quot;&gt;// apply inheritance to WHERE part
&lt;/span&gt;                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($where)) {
                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;]) &amp;gt; 0) {
                            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;][] = &apos;AND&apos;;
                        }

                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (substr($where, 0, 1) === &apos;(&apos; &amp;amp;&amp;amp; substr($where, -1) === &apos;)&apos;) {
                            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;][] = $where;
                        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;][] = &apos;(&apos; . $where . &apos;)&apos;;
                        }
                    }
                }

                $q .= $part;

                &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
            }

            &lt;span class=&quot;code-comment&quot;&gt;// preserve LEFT JOINs only &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; needed
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;// Check &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; it&apos;s JOIN, &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; not add a comma separator instead of space
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! preg_match(&apos;/\bJOIN\b/i&apos;, $part) &amp;amp;&amp;amp; ! isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingJoinConditions[$k])) {
                $q .= &apos;, &apos; . $part;
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (substr($part, 0, 9) === &apos;LEFT JOIN&apos;) {
                    $aliases = array_merge($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_subqueryAliases,
                                array_keys($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_neededTables));

                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! in_array($e[3], $aliases) &amp;amp;&amp;amp; ! in_array($e[2], $aliases) &amp;amp;&amp;amp; ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingFields)) {
                        &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
                    }

                }

                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $ignorePending &amp;amp;&amp;amp; isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingJoinConditions[$k])) {
                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($part, &apos; ON &apos;) !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                        $part .= &apos; AND &apos;;
                    } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                        $part .= &apos; ON &apos;;
                    }

                    $part .= $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_processPendingJoinConditions($k);
                }

                $componentAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getComponentAlias($e[3]);
                $string = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getInheritanceCondition($componentAlias);

                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($string) {
                    $part = $part . &apos; AND &apos; . $string;
                }
                $q .= &apos; &apos; . $part;
            }

            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;from&apos;][$k] = $part;
        }
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $q;
    }

    /**
     * Processes the pending join conditions, used &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; dynamically add conditions
     * to root component/joined components without interfering in the main dql
     * handling.
     *
     * @param string $alias Component Alias
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; Processed pending conditions
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; function _processPendingJoinConditions($alias)
    {
        $parts = array();

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($alias !== &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt; &amp;amp;&amp;amp; isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingJoinConditions[$alias])) {
            $parser = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_JoinCondition($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer);

            foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingJoinConditions[$alias] as $joinCondition) {
                $parts[] = $parser-&amp;gt;parse($joinCondition);
            }

            &lt;span class=&quot;code-comment&quot;&gt;// FIX #1860 and #1876: Cannot unset them, otherwise query cannot be reused later
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;//unset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingJoinConditions[$alias]);
&lt;/span&gt;        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; (count($parts) &amp;gt; 0 ? &apos;(&apos; . implode(&apos;) AND (&apos;, $parts) . &apos;)&apos; : &apos;&apos;);
    }

    /**
     * builds the sql query from the given parameters and applies things such as
     * column aggregation inheritance and limit subqueries &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; needed
     *
     * @param array $params             an array of prepared statement params (needed only in mysql driver
     *                                  when limit subquery algorithm is used)
     * @param bool $limitSubquery Whether or not to &lt;span class=&quot;code-keyword&quot;&gt;try&lt;/span&gt; and apply the limit subquery algorithm
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string                   the built sql query
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getSqlQuery($params = array(), $limitSubquery = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;)
    {
        &lt;span class=&quot;code-comment&quot;&gt;// Assign building/execution specific params
&lt;/span&gt;        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_params[&apos;exec&apos;] = $params;

        &lt;span class=&quot;code-comment&quot;&gt;// Initialize prepared parameters array
&lt;/span&gt;        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_execParams = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getFlattenedParams();

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_state !== self::STATE_DIRTY) {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;fixArrayParameterValues($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getInternalParams());

            &lt;span class=&quot;code-comment&quot;&gt;// Return compiled SQL
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sql;
        }
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;buildSqlQuery($limitSubquery);
    }

    /**
     * Build the SQL query from the DQL
     *
     * @param bool $limitSubquery Whether or not to &lt;span class=&quot;code-keyword&quot;&gt;try&lt;/span&gt; and apply the limit subquery algorithm
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string $sql The generated SQL string
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function buildSqlQuery($limitSubquery = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;)
    {
        &lt;span class=&quot;code-comment&quot;&gt;// reset the state
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;isSubquery()) {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents = array();
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingAggregates = array();
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap = array();
        }

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;reset();

        &lt;span class=&quot;code-comment&quot;&gt;// invoke the preQuery hook
&lt;/span&gt;        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_preQuery();

        &lt;span class=&quot;code-comment&quot;&gt;// process the DQL parts =&amp;gt; generate the SQL parts.
&lt;/span&gt;        &lt;span class=&quot;code-comment&quot;&gt;// &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; will also populate the $_queryComponents.
&lt;/span&gt;        foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_dqlParts as $queryPartName =&amp;gt; $queryParts) {
            &lt;span class=&quot;code-comment&quot;&gt;// If we are parsing FROM clause, we&apos;ll need to diff the queryComponents later
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($queryPartName == &apos;from&apos;) {
                &lt;span class=&quot;code-comment&quot;&gt;// Pick queryComponents before processing
&lt;/span&gt;                $queryComponentsBefore = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getQueryComponents();
            }

            &lt;span class=&quot;code-comment&quot;&gt;// FIX #1667: _sqlParts are cleaned inside _processDqlQueryPart.
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($queryPartName != &apos;forUpdate&apos;) {
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_processDqlQueryPart($queryPartName, $queryParts);
            }

            &lt;span class=&quot;code-comment&quot;&gt;// We need to define the root alias
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($queryPartName == &apos;from&apos;) {
                &lt;span class=&quot;code-comment&quot;&gt;// Pick queryComponents aftr processing
&lt;/span&gt;                $queryComponentsAfter = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getQueryComponents();

                &lt;span class=&quot;code-comment&quot;&gt;// Root alias is the key of difference of query components
&lt;/span&gt;                $diffQueryComponents = array_diff_key($queryComponentsAfter, $queryComponentsBefore);
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_rootAlias = key($diffQueryComponents);
            }
        }
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_state = self::STATE_CLEAN;

        &lt;span class=&quot;code-comment&quot;&gt;// Proceed with the generated SQL
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;from&apos;])) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
        }

        $needsSubQuery = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
        $subquery = &apos;&apos;;
        $map = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootDeclaration();
        $table = $map[&apos;table&apos;];
        $rootAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootAlias();

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;limit&apos;]) &amp;amp;&amp;amp; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_needsSubquery &amp;amp;&amp;amp;
                $table-&amp;gt;getAttribute(Doctrine_Core::ATTR_QUERY_LIMIT) == Doctrine_Core::LIMIT_RECORDS) {
            &lt;span class=&quot;code-comment&quot;&gt;// We &lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt; not need a limit-subquery &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; DISTINCT is used
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;// and the selected fields are either from the root component or from a localKey relation (hasOne)
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;// (i.e. DQL: SELECT DISTINCT u.id FROM User u LEFT JOIN u.phonenumbers LIMIT 5).
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt;(!$&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;distinct&apos;]) {
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_isLimitSubqueryUsed = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;
                $needsSubQuery = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                foreach( array_keys($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingFields) as $alias){
                    &lt;span class=&quot;code-comment&quot;&gt;//no subquery &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; root fields
&lt;/span&gt;                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt;($alias == $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootAlias()){
                        &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
                    }

                    &lt;span class=&quot;code-comment&quot;&gt;//no subquery &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; ONE relations
&lt;/span&gt;                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt;(isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$alias][&apos;relation&apos;]) &amp;amp;&amp;amp;
                        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$alias][&apos;relation&apos;]-&amp;gt;getType() == Doctrine_Relation::ONE){
                        &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
                    }

                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_isLimitSubqueryUsed = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;
                    $needsSubQuery = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;
                }
            }
        }

        $sql = array();

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingFields)) {
            foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents as $alias =&amp;gt; $map) {
                $fieldSql = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;processPendingFields($alias);
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($fieldSql)) {
                    $sql[] = $fieldSql;
                }
            }
        }

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($sql)) {
            array_unshift($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;select&apos;], implode(&apos;, &apos;, $sql));
        }

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingFields = array();

        &lt;span class=&quot;code-comment&quot;&gt;// build the basic query
&lt;/span&gt;        $q  = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_buildSqlQueryBase();
        $q .= $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_buildSqlFromPart();

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;set&apos;])) {
            $q .= &apos; SET &apos; . implode(&apos;, &apos;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;set&apos;]);
        }

        $string = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getInheritanceCondition($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootAlias());

        &lt;span class=&quot;code-comment&quot;&gt;// apply inheritance to WHERE part
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($string)) {
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;]) &amp;gt; 0) {
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;][] = &apos;AND&apos;;
            }

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (substr($string, 0, 1) === &apos;(&apos; &amp;amp;&amp;amp; substr($string, -1) === &apos;)&apos;) {
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;][] = $string;
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;][] = &apos;(&apos; . $string . &apos;)&apos;;
            }
        }

        $modifyLimit = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;
        $limitSubquerySql = &apos;&apos;;

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ( ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;limit&apos;]) || ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;offset&apos;])) &amp;amp;&amp;amp; $needsSubQuery &amp;amp;&amp;amp; $limitSubquery) {
            $subquery = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getLimitSubquery();

            &lt;span class=&quot;code-comment&quot;&gt;// what about composite keys?
&lt;/span&gt;            $idColumnName = $table-&amp;gt;getColumnName($table-&amp;gt;getIdentifier());

            &lt;span class=&quot;code-keyword&quot;&gt;switch&lt;/span&gt; (strtolower($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;getDriverName())) {
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;mysql&apos;:
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;useQueryCache(&lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;);

                    &lt;span class=&quot;code-comment&quot;&gt;// mysql doesn&apos;t support LIMIT in subqueries
&lt;/span&gt;                    $list = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;execute($subquery, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_execParams)-&amp;gt;fetchAll(Doctrine_Core::FETCH_COLUMN);
                    $subquery = implode(&apos;, &apos;, array_map(array($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn, &apos;quote&apos;), $list));

                    &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;

                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;pgsql&apos;:
                    $subqueryAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier(&apos;doctrine_subquery_alias&apos;);

                    &lt;span class=&quot;code-comment&quot;&gt;// pgsql needs special nested LIMIT subquery
&lt;/span&gt;                    $subquery = &apos;SELECT &apos; . $subqueryAlias . &apos;.&apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($idColumnName)
                            . &apos; FROM (&apos; . $subquery . &apos;) AS &apos; . $subqueryAlias;

                    &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
            }

            $field = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($rootAlias) . &apos;.&apos; . $idColumnName;

            &lt;span class=&quot;code-comment&quot;&gt;// FIX #1868: If not ID under MySQL is found to be restricted, restrict pk column &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;//            (which will lead to a &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; of 0 items)
&lt;/span&gt;            $limitSubquerySql = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($field)
                              . (( ! empty($subquery)) ? &apos; IN (&apos; . $subquery . &apos;)&apos; : &apos; IS NULL&apos;)
                              . ((count($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;]) &amp;gt; 0) ? &apos; AND &apos; : &apos;&apos;);

            $modifyLimit = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
        }

        &lt;span class=&quot;code-comment&quot;&gt;// FIX #DC-26: Include limitSubquerySql as major relevance in conditions
&lt;/span&gt;        $emptyWhere = empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;]);

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! ($emptyWhere &amp;amp;&amp;amp; $limitSubquerySql == &apos;&apos;)) {
            $where = implode(&apos; &apos;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;]);
            $where = ($where == &apos;&apos; || (substr($where, 0, 1) === &apos;(&apos; &amp;amp;&amp;amp; substr($where, -1) === &apos;)&apos;))
                ? $where : &apos;(&apos; . $where . &apos;)&apos;;

            $q .= &apos; WHERE &apos; . $limitSubquerySql . $where;
            &lt;span class=&quot;code-comment&quot;&gt;//   .  (($limitSubquerySql == &apos;&apos; &amp;amp;&amp;amp; count($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;]) == 1) ? substr($where, 1, -1) : $where);
&lt;/span&gt;        }

        &lt;span class=&quot;code-comment&quot;&gt;// Fix the orderbys so we only have one orderby per value
&lt;/span&gt;        foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;] as $k =&amp;gt; $orderBy) {
            $e = explode(&apos;, &apos;, $orderBy);
            unset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;][$k]);
            foreach ($e as $v) {
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;][] = $v;
            }
        }

        &lt;span class=&quot;code-comment&quot;&gt;// Add the &lt;span class=&quot;code-keyword&quot;&gt;default&lt;/span&gt; orderBy statements defined in the relationships and table classes
&lt;/span&gt;        &lt;span class=&quot;code-comment&quot;&gt;// Only &lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; SELECT queries
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_type === self::SELECT) {
            foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents as $alias =&amp;gt; $map) {
                $sqlAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($alias);
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($map[&apos;relation&apos;])) {
                    $orderBy = $map[&apos;relation&apos;]-&amp;gt;getOrderByStatement($sqlAlias, &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;);
                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($orderBy == $map[&apos;relation&apos;][&apos;orderBy&apos;]) {
                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($map[&apos;ref&apos;])) {
                            $orderBy = $map[&apos;relation&apos;][&apos;refTable&apos;]-&amp;gt;processOrderBy($sqlAlias, $map[&apos;relation&apos;][&apos;orderBy&apos;], &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;);
                        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                            $orderBy = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;;
                        }
                    }
				} &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
					$orderBy = $map[&apos;table&apos;]-&amp;gt;getOrderByStatement($sqlAlias, &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;);
				}

                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($orderBy) {
                    $e = explode(&apos;,&apos;, $orderBy);
                    $e = array_map(&apos;trim&apos;, $e);
                    foreach ($e as $v) {
                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! in_array($v, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;])) {
                            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;][] = $v;
                        }
                    }
                }
            }
        }

        $q .= ( ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;groupby&apos;])) ? &apos; GROUP BY &apos; . implode(&apos;, &apos;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;groupby&apos;])  : &apos;&apos;;
        $q .= ( ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;having&apos;])) ?  &apos; HAVING &apos;   . implode(&apos; AND &apos;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;having&apos;]): &apos;&apos;;
        $q .= ( ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;])) ? &apos; ORDER BY &apos; . implode(&apos;, &apos;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;])  : &apos;&apos;;

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($modifyLimit) {
            $q = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;modifyLimitQuery($q, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;limit&apos;], $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;offset&apos;]);
        }

        $q .= $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;forUpdate&apos;] === &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt; ? &apos; FOR UPDATE &apos; : &apos;&apos;;

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sql = $q;

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;clear();

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $q;
    }

    /**
     * getLimitSubquery
     * &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; is method is used by the record limit algorithm
     *
     * when fetching one-to-many, many-to-many associated data with LIMIT clause
     * an additional subquery is needed &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; limiting the number of returned records instead
     * of limiting the number of sql result set rows
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string       the limit subquery
     * @todo A little refactor to make the method easier to understand &amp;amp; maybe shorter?
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getLimitSubquery()
    {
        $map = reset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents);
        $table = $map[&apos;table&apos;];
        $componentAlias = key($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents);

        &lt;span class=&quot;code-comment&quot;&gt;// get &lt;span class=&quot;code-object&quot;&gt;short&lt;/span&gt; alias
&lt;/span&gt;        $alias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias);
        &lt;span class=&quot;code-comment&quot;&gt;// what about composite keys?
&lt;/span&gt;        $primaryKey = $alias . &apos;.&apos; . $table-&amp;gt;getColumnName($table-&amp;gt;getIdentifier());

        $driverName = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;getAttribute(Doctrine_Core::ATTR_DRIVER_NAME);

        &lt;span class=&quot;code-comment&quot;&gt;// initialize the base of the subquery
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (($driverName == &apos;oracle&apos; || $driverName == &apos;oci&apos;) &amp;amp;&amp;amp; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_isOrderedByJoinedColumn()) {
            $subquery = &apos;SELECT &apos;;
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            $subquery = &apos;SELECT DISTINCT &apos;;
        }
        $subquery .= $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($primaryKey);

        &lt;span class=&quot;code-comment&quot;&gt;// pgsql &amp;amp; oracle need the order by fields to be preserved in select clause
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($driverName == &apos;pgsql&apos; || $driverName == &apos;oracle&apos; || $driverName == &apos;oci&apos; || $driverName == &apos;mssql&apos; || $driverName == &apos;odbc&apos;) {
            foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;] as $part) {
                &lt;span class=&quot;code-comment&quot;&gt;// Remove identifier quoting &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; it exists
&lt;/span&gt;                $e = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;bracketExplode($part, &apos; &apos;);
                foreach ($e as $f) {
                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($f == 0 || $f % 2 == 0) {
                        $partOriginal = str_replace(&apos;,&apos;, &apos;&apos;, trim($f));
                        $callback = create_function(&apos;$e&apos;, &apos;&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; trim($e, \&apos;[]`&quot;\&apos;);&apos;);
                        $part = trim(implode(&apos;.&apos;, array_map($callback, explode(&apos;.&apos;, $partOriginal))));
                
                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($part, &apos;.&apos;) === &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                            &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
                        }
                
                        &lt;span class=&quot;code-comment&quot;&gt;// don&apos;t add functions
&lt;/span&gt;                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($part, &apos;(&apos;) !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                            &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
                        }
                
                        &lt;span class=&quot;code-comment&quot;&gt;// don&apos;t add primarykey column (its already in the select clause)
&lt;/span&gt;                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($part !== $primaryKey) {
                            $subquery .= &apos;, &apos; . $partOriginal;
                        }
                    }
                }
            }
        }

        $orderby = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;];
        $having = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;having&apos;];
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($driverName == &apos;mysql&apos; || $driverName == &apos;pgsql&apos;) {
            foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_expressionMap as $dqlAlias =&amp;gt; $expr) {
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($expr[1])) {
                    $subquery .= &apos;, &apos; . $expr[0] . &apos; AS &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap[$dqlAlias];
                }
            }
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_expressionMap as $dqlAlias =&amp;gt; $expr) {
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($expr[1])) {
                    foreach ($having as $k =&amp;gt; $v) {
                        $having[$k] = str_replace($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap[$dqlAlias], $expr[0], $v);
                    }
                    foreach ($orderby as $k =&amp;gt; $v) {
                        $e = explode(&apos; &apos;, $v);
                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($e[0] == $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap[$dqlAlias]) {
                            $orderby[$k] = $expr[0];
                        }
                    }
                }
            }
        }

        &lt;span class=&quot;code-comment&quot;&gt;// Add having fields that got stripped out of select
&lt;/span&gt;        preg_match_all(&apos;/`[a-z0-9_]+`\.`[a-z0-9_]+`/i&apos;, implode(&apos; &apos;, $having), $matches, PREG_PATTERN_ORDER);
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($matches[0]) &amp;gt; 0) {
            $subquery .= &apos;, &apos; . implode(&apos;, &apos;, array_unique($matches[0]));
        }

        $subquery .= &apos; FROM&apos;;

        foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;from&apos;] as $part) {
            &lt;span class=&quot;code-comment&quot;&gt;// preserve LEFT JOINs only &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; needed
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (substr($part, 0, 9) === &apos;LEFT JOIN&apos;) {
                $e = explode(&apos; &apos;, $part);
			&lt;span class=&quot;code-comment&quot;&gt;//Patched by Will Ferrer to also check &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; groupBys. Fixes Bug -- DC-594
&lt;/span&gt;                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;]) &amp;amp;&amp;amp; empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;]) &amp;amp;&amp;amp; empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;having&apos;]) &amp;amp;&amp;amp; empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;groupby&apos;])) {
             &lt;span class=&quot;code-comment&quot;&gt;//End Patch
&lt;/span&gt;				   &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
                }
            }

            $subquery .= &apos; &apos; . $part;
        }

        &lt;span class=&quot;code-comment&quot;&gt;// all conditions must be preserved in subquery
&lt;/span&gt;        $subquery .= ( ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;]))?   &apos; WHERE &apos;    . implode(&apos; &apos;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;])  : &apos;&apos;;
        $subquery .= ( ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;groupby&apos;]))? &apos; GROUP BY &apos; . implode(&apos;, &apos;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;groupby&apos;])   : &apos;&apos;;
        $subquery .= ( ! empty($having))?  &apos; HAVING &apos;   . implode(&apos; AND &apos;, $having) : &apos;&apos;;
        $subquery .= ( ! empty($orderby))? &apos; ORDER BY &apos; . implode(&apos;, &apos;, $orderby)  : &apos;&apos;;

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (($driverName == &apos;oracle&apos; || $driverName == &apos;oci&apos;) &amp;amp;&amp;amp; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_isOrderedByJoinedColumn()) {
            &lt;span class=&quot;code-comment&quot;&gt;// When using &lt;span class=&quot;code-quote&quot;&gt;&quot;ORDER BY x.foo&quot;&lt;/span&gt; where x.foo is a column of a joined table,
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;// we may get duplicate primary keys because all columns in ORDER BY must appear
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;// in the SELECT list when using DISTINCT. Hence we need to filter out the
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;// primary keys with an additional DISTINCT subquery.
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;// #1038
&lt;/span&gt;            $quotedIdentifierColumnName = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($table-&amp;gt;getColumnName($table-&amp;gt;getIdentifier()));
            $subquery = &apos;SELECT doctrine_subquery_alias.&apos; . $quotedIdentifierColumnName
                    . &apos; FROM (&apos; . $subquery . &apos;) doctrine_subquery_alias&apos;
                    . &apos; GROUP BY doctrine_subquery_alias.&apos; . $quotedIdentifierColumnName
                    . &apos; ORDER BY MIN(ROWNUM)&apos;;
        }

        &lt;span class=&quot;code-comment&quot;&gt;// add driver specific limit clause
&lt;/span&gt;        $subquery = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;modifyLimitSubquery($table, $subquery, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;limit&apos;], $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;offset&apos;]);

        $parts = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;quoteExplode($subquery, &apos; &apos;, &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&quot;&lt;/span&gt;, &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&quot;&lt;/span&gt;);

        foreach ($parts as $k =&amp;gt; $part) {
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($part, &apos; &apos;) !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
            }

            $part = str_replace(array(&apos;&lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;, &quot;&lt;/span&gt;&apos;&lt;span class=&quot;code-quote&quot;&gt;&quot;, &apos;`&apos;), &quot;&lt;/span&gt;&quot;, $part);

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;hasSqlTableAlias($part)) {
                $parts[$k] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;generateNewSqlTableAlias($part));
                &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
            }

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($part, &apos;.&apos;) === &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
            }

            preg_match_all(&lt;span class=&quot;code-quote&quot;&gt;&quot;/[a-zA-Z0-9_]+\.[a-z0-9_]+/i&quot;&lt;/span&gt;, $part, $m);

            foreach ($m[0] as $match) {
                $e = explode(&apos;.&apos;, $match);

                &lt;span class=&quot;code-comment&quot;&gt;// Rebuild the original part without the newly generate alias and with quoting reapplied
&lt;/span&gt;                $e2 = array();
                foreach ($e as $k2 =&amp;gt; $v2) {
                  $e2[$k2] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($v2);
                }
                $match = implode(&apos;.&apos;, $e2);

                &lt;span class=&quot;code-comment&quot;&gt;// Generate &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; table alias
&lt;/span&gt;                $e[0] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;generateNewSqlTableAlias($e[0]);

                &lt;span class=&quot;code-comment&quot;&gt;// Requote the part with the newly generated alias
&lt;/span&gt;                foreach ($e as $k2 =&amp;gt; $v2) {
                  $e[$k2] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($v2);
                }

                $replace = implode(&apos;.&apos; , $e);

                &lt;span class=&quot;code-comment&quot;&gt;// Replace the original part with the &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; part with &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; sql table alias
&lt;/span&gt;                $parts[$k] = str_replace($match, $replace, $parts[$k]);
            }
        }

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($driverName == &apos;mysql&apos; || $driverName == &apos;pgsql&apos;) {
            foreach ($parts as $k =&amp;gt; $part) {
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($part, &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&quot;&lt;/span&gt;) !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                    &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
                }
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($part, &apos;__&apos;) == &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                    &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
                }

                preg_match_all(&lt;span class=&quot;code-quote&quot;&gt;&quot;/[a-zA-Z0-9_]+\_\_[a-z0-9_]+/i&quot;&lt;/span&gt;, $part, $m);

                foreach ($m[0] as $match) {
                    $e = explode(&apos;__&apos;, $match);
                    $e[0] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;generateNewSqlTableAlias($e[0]);

                    $parts[$k] = str_replace($match, implode(&apos;__&apos;, $e), $parts[$k]);
                }
            }
        }

        $subquery = implode(&apos; &apos;, $parts);
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $subquery;
    }

    /**
     * Checks whether the query has an ORDER BY on a column of a joined table.
     * This information is needed in special scenarios like the limit-offset when its
     * used with an Oracle database.
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt;  TRUE &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; the query is ordered by a joined column, FALSE otherwise.
     */
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; function _isOrderedByJoinedColumn() {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents) {
            &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&lt;span class=&quot;code-quote&quot;&gt;&quot;The query is in an invalid state &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; &quot;&lt;/span&gt;
                    . &lt;span class=&quot;code-quote&quot;&gt;&quot;operation. It must have been fully parsed first.&quot;&lt;/span&gt;);
        }
        $componentAlias = key($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents);
        $mainTableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias);
        foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;] as $part) {
            $part = trim($part);
            $e = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;bracketExplode($part, &apos; &apos;);
            $part = trim($e[0]);
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($part, &apos;.&apos;) === &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
            }
            list($tableAlias, $columnName) = explode(&apos;.&apos;, $part);
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($tableAlias != $mainTableAlias) {
                &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;return&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
    }

    /**
     * DQL PARSER
     * parses a DQL query
     * first splits the query in parts and then uses individual
     * parsers &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; each part
     *
     * @param string $query                 DQL query
     * @param &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt; $clear                whether or not to clear the aliases
     * @&lt;span class=&quot;code-keyword&quot;&gt;throws&lt;/span&gt; Doctrine_Query_Exception     &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; some &lt;span class=&quot;code-keyword&quot;&gt;generic&lt;/span&gt; parsing error occurs
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; Doctrine_Query
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function parseDqlQuery($query, $clear = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($clear) {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;clear();
        }

        $query = trim($query);
        $query = str_replace(&lt;span class=&quot;code-quote&quot;&gt;&quot;\r&quot;&lt;/span&gt;, &lt;span class=&quot;code-quote&quot;&gt;&quot;\n&quot;&lt;/span&gt;, str_replace(&lt;span class=&quot;code-quote&quot;&gt;&quot;\r\n&quot;&lt;/span&gt;, &lt;span class=&quot;code-quote&quot;&gt;&quot;\n&quot;&lt;/span&gt;, $query));
        $query = str_replace(&lt;span class=&quot;code-quote&quot;&gt;&quot;\n&quot;&lt;/span&gt;, &apos; &apos;, $query);

        $parts = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;tokenizeQuery($query);

        foreach ($parts as $partName =&amp;gt; $subParts) {
            $subParts = trim($subParts);
            $partName = strtolower($partName);
            &lt;span class=&quot;code-keyword&quot;&gt;switch&lt;/span&gt; ($partName) {
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;create&apos;:
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_type = self::CREATE;
                &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;insert&apos;:
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_type = self::INSERT;
                &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;delete&apos;:
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_type = self::DELETE;
                &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;select&apos;:
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_type = self::SELECT;
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_addDqlQueryPart($partName, $subParts);
                &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;update&apos;:
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_type = self::UPDATE;
                    $partName = &apos;from&apos;;
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;from&apos;:
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_addDqlQueryPart($partName, $subParts);
                &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;set&apos;:
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_addDqlQueryPart($partName, $subParts, &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;);
                &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;group&apos;:
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;order&apos;:
                    $partName .= &apos;by&apos;;
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;where&apos;:
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;having&apos;:
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;limit&apos;:
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;offset&apos;:
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_addDqlQueryPart($partName, $subParts);
                &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
            }
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;;
    }

    /**
     * @todo Describe &amp;amp; refactor... too &lt;span class=&quot;code-object&quot;&gt;long&lt;/span&gt; and nested.
     * @param string $path          component alias
     * @param &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt; $loadFields
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function load($path, $loadFields = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$path])) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$path];
        }

        $e = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;quoteExplode($path, &apos; INDEXBY &apos;);

        $mapWith = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;;
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($e) &amp;gt; 1) {
            $mapWith = trim($e[1]);

            $path = $e[0];
        }

        &lt;span class=&quot;code-comment&quot;&gt;// parse custom join conditions
&lt;/span&gt;        $e = explode(&apos; ON &apos;, str_ireplace(&apos; on &apos;, &apos; ON &apos;, $path));

        $joinCondition = &apos;&apos;;

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($e) &amp;gt; 1) {
            $joinCondition = substr($path, strlen($e[0]) + 4, strlen($e[1]));
            $path = substr($path, 0, strlen($e[0]));

            $overrideJoin = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            $e = explode(&apos; WITH &apos;, str_ireplace(&apos; with &apos;, &apos; WITH &apos;, $path));

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($e) &amp;gt; 1) {
                $joinCondition = substr($path, strlen($e[0]) + 6, strlen($e[1]));
                $path = substr($path, 0, strlen($e[0]));
            }

            $overrideJoin = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
        }

        $tmp            = explode(&apos; &apos;, $path);
        $componentAlias = $originalAlias = (count($tmp) &amp;gt; 1) ? end($tmp) : &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;;

        $e = preg_split(&lt;span class=&quot;code-quote&quot;&gt;&quot;/[.:]/&quot;&lt;/span&gt;, $tmp[0], -1);

        $fullPath = $tmp[0];
        $prevPath = &apos;&apos;;
        $fullLength = strlen($fullPath);

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$e[0]])) {
            $table = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$e[0]][&apos;table&apos;];
            $componentAlias = $e[0];

            $prevPath = $parent = array_shift($e);
        }

        foreach ($e as $key =&amp;gt; $name) {
            &lt;span class=&quot;code-comment&quot;&gt;// get length of the previous path
&lt;/span&gt;            $length = strlen($prevPath);

            &lt;span class=&quot;code-comment&quot;&gt;// build the current component path
&lt;/span&gt;            $prevPath = ($prevPath) ? $prevPath . &apos;.&apos; . $name : $name;

            $delimeter = substr($fullPath, $length, 1);

            &lt;span class=&quot;code-comment&quot;&gt;// &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; an alias is not given use the current path as an alias identifier
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strlen($prevPath) === $fullLength &amp;amp;&amp;amp; isset($originalAlias)) {
                $componentAlias = $originalAlias;
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                $componentAlias = $prevPath;
            }

            &lt;span class=&quot;code-comment&quot;&gt;// &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; the current alias already exists, skip it
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias])) {
                &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&lt;span class=&quot;code-quote&quot;&gt;&quot;Duplicate alias &apos;$componentAlias&apos; in query.&quot;&lt;/span&gt;);
            }

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! isset($table)) {
                &lt;span class=&quot;code-comment&quot;&gt;// process the root of the path
&lt;/span&gt;
                $table = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;loadRoot($name, $componentAlias);
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                $join = ($delimeter == &apos;:&apos;) ? &apos;INNER JOIN &apos; : &apos;LEFT JOIN &apos;;

                $relation = $table-&amp;gt;getRelation($name);
                $localTable = $table;

                $table = $relation-&amp;gt;getTable();
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias] = array(&apos;table&apos; =&amp;gt; $table,
                                                                 &apos;parent&apos;   =&amp;gt; $parent,
                                                                 &apos;relation&apos; =&amp;gt; $relation,
                                                                 &apos;map&apos;      =&amp;gt; &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;);
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $relation-&amp;gt;isOneToOne()) {
                   $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_needsSubquery = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;
                }

                $localAlias   = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($parent, $localTable-&amp;gt;getTableName());
                $foreignAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias, $relation-&amp;gt;getTable()-&amp;gt;getTableName());

                $foreignSql   = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($relation-&amp;gt;getTable()-&amp;gt;getTableName())
                              . &apos; &apos;
                              . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($foreignAlias);

                $map = $relation-&amp;gt;getTable()-&amp;gt;inheritanceMap;

                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $loadFields || ! empty($map) || $joinCondition) {
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_subqueryAliases[] = $foreignAlias;
                }

                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($relation &lt;span class=&quot;code-keyword&quot;&gt;instanceof&lt;/span&gt; Doctrine_Relation_Association) {
                    $asf = $relation-&amp;gt;getAssociationTable();

                    $assocTableName = $asf-&amp;gt;getTableName();

                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $loadFields || ! empty($map) || $joinCondition) {
                        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_subqueryAliases[] = $assocTableName;
                    }

                    $assocPath = $prevPath . &apos;.&apos; . $asf-&amp;gt;getComponentName() . &apos; &apos; . $componentAlias;

                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$assocPath] = array(
                        &apos;parent&apos; =&amp;gt; $prevPath,
                        &apos;relation&apos; =&amp;gt; $relation,
                        &apos;table&apos; =&amp;gt; $asf,
                        &apos;ref&apos; =&amp;gt; &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;);

                    $assocAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($assocPath, $asf-&amp;gt;getTableName());

                    $queryPart = $join
                            . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($assocTableName)
                            . &apos; &apos;
                            . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($assocAlias);

                    $queryPart .= &apos; ON (&apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($localAlias
                                . &apos;.&apos;
                                . $localTable-&amp;gt;getColumnName($localTable-&amp;gt;getIdentifier())) &lt;span class=&quot;code-comment&quot;&gt;// what about composite keys?
&lt;/span&gt;                                . &apos; = &apos;
                                . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($assocAlias . &apos;.&apos; . $relation-&amp;gt;getLocalRefColumnName());

                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($relation-&amp;gt;isEqual()) {
                        &lt;span class=&quot;code-comment&quot;&gt;// equal nest relation needs additional condition
&lt;/span&gt;                        $queryPart .= &apos; OR &apos;
                                    . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($localAlias
                                    . &apos;.&apos;
                                    . $table-&amp;gt;getColumnName($table-&amp;gt;getIdentifier()))
                                    . &apos; = &apos;
                                    . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($assocAlias . &apos;.&apos; . $relation-&amp;gt;getForeignRefColumnName());
                    }

                    $queryPart .= &apos;)&apos;;

                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;from&apos;][] = $queryPart;

                    $queryPart = $join . $foreignSql;

                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $overrideJoin) {
                        $queryPart .= $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;buildAssociativeRelationSql($relation, $assocAlias, $foreignAlias, $localAlias);
                    }
                } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                    $queryPart = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;buildSimpleRelationSql($relation, $foreignAlias, $localAlias, $overrideJoin, $join);
                }

                $queryPart .= $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;buildInheritanceJoinSql($table-&amp;gt;getComponentName(), $componentAlias);
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;from&apos;][$componentAlias] = $queryPart;

                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($joinCondition)) {
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;addPendingJoinCondition($componentAlias, $joinCondition);
                }
            }

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($loadFields) {
                $restoreState = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;

                &lt;span class=&quot;code-comment&quot;&gt;// load fields &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; necessary
&lt;/span&gt;                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($loadFields &amp;amp;&amp;amp; empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_dqlParts[&apos;select&apos;])) {
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingFields[$componentAlias] = array(&apos;*&apos;);
                }
            }

            $parent = $prevPath;
        }

        $table = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;table&apos;];

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;buildIndexBy($componentAlias, $mapWith);
    }

    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; function buildSimpleRelationSql(Doctrine_Relation $relation, $foreignAlias, $localAlias, $overrideJoin, $join)
    {
        $queryPart = $join . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($relation-&amp;gt;getTable()-&amp;gt;getTableName())
                           . &apos; &apos;
                           . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($foreignAlias);

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $overrideJoin) {
            $queryPart .= &apos; ON &apos;
                       . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($localAlias . &apos;.&apos; . $relation-&amp;gt;getLocalColumnName())
                       . &apos; = &apos;
                       . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($foreignAlias . &apos;.&apos; . $relation-&amp;gt;getForeignColumnName());
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $queryPart;
    }

    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; function buildIndexBy($componentAlias, $mapWith = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;)
    {
        $table = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;table&apos;];

        $indexBy = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;;
        $column = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($mapWith)) {
            $terms = explode(&apos;.&apos;, $mapWith);

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($terms) == 1) {
                $indexBy = $terms[0];
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($terms) == 2) {
                $column = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;
                $indexBy = $terms[1];
            }
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($table-&amp;gt;getBoundQueryPart(&apos;indexBy&apos;) !== &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;) {
            $indexBy = $table-&amp;gt;getBoundQueryPart(&apos;indexBy&apos;);
        }

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($indexBy !== &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;) {
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( $column &amp;amp;&amp;amp; ! $table-&amp;gt;hasColumn($table-&amp;gt;getColumnName($indexBy))) {
                &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&lt;span class=&quot;code-quote&quot;&gt;&quot;Couldn&apos;t use key mapping. Column &quot;&lt;/span&gt; . $indexBy . &lt;span class=&quot;code-quote&quot;&gt;&quot; does not exist.&quot;&lt;/span&gt;);
            }

            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;map&apos;] = $indexBy;
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias];
    }


    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; function buildAssociativeRelationSql(Doctrine_Relation $relation, $assocAlias, $foreignAlias, $localAlias)
    {
        $table = $relation-&amp;gt;getTable();

        $queryPart = &apos; ON &apos;;

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($relation-&amp;gt;isEqual()) {
            $queryPart .= &apos;(&apos;;
        }

        $localIdentifier = $table-&amp;gt;getColumnName($table-&amp;gt;getIdentifier());

        $queryPart .= $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($foreignAlias . &apos;.&apos; . $localIdentifier)
                    . &apos; = &apos;
                    . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($assocAlias . &apos;.&apos; . $relation-&amp;gt;getForeignRefColumnName());

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($relation-&amp;gt;isEqual()) {
            $queryPart .= &apos; OR &apos;
                        . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($foreignAlias . &apos;.&apos; . $localIdentifier)
                        . &apos; = &apos;
                        . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($assocAlias . &apos;.&apos; . $relation-&amp;gt;getLocalRefColumnName())
                        . &apos;) AND &apos;
                        . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($foreignAlias . &apos;.&apos; . $localIdentifier)
                        . &apos; != &apos;
                        . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($localAlias . &apos;.&apos; . $localIdentifier);
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $queryPart;
    }

    /**
     * loadRoot
     *
     * @param string $name
     * @param string $componentAlias
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; Doctrine_Table
     * @todo DESCRIBE ME!
     * @todo &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; method is called only in Doctrine_Query class. Shouldn&apos;t be &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; or &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt;?
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function loadRoot($name, $componentAlias)
    {
        &lt;span class=&quot;code-comment&quot;&gt;// get the connection &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; the component
&lt;/span&gt;        $manager = Doctrine_Manager::getInstance();
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_passedConn &amp;amp;&amp;amp; $manager-&amp;gt;hasConnectionForComponent($name)) {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn = $manager-&amp;gt;getConnectionForComponent($name);
        }

        $table = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;getTable($name);
        $tableName = $table-&amp;gt;getTableName();

        &lt;span class=&quot;code-comment&quot;&gt;// get the &lt;span class=&quot;code-object&quot;&gt;short&lt;/span&gt; alias &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; table
&lt;/span&gt;        $tableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias, $tableName);
        &lt;span class=&quot;code-comment&quot;&gt;// quote table name
&lt;/span&gt;        $queryPart = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableName);

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_type === self::SELECT) {
            $queryPart .= &apos; &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias);
        }

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tableAliasMap[$tableAlias] = $componentAlias;

        $queryPart .= $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;buildInheritanceJoinSql($name, $componentAlias);

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;from&apos;][] = $queryPart;

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias] = array(&apos;table&apos; =&amp;gt; $table, &apos;map&apos; =&amp;gt; &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;);

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $table;
    }

    /**
     * @todo DESCRIBE ME!
     * @param string $name              component class name
     * @param string $componentAlias    alias of the component in the dql
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string                   query part
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function buildInheritanceJoinSql($name, $componentAlias)
    {
        &lt;span class=&quot;code-comment&quot;&gt;// get the connection &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; the component
&lt;/span&gt;        $manager = Doctrine_Manager::getInstance();
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_passedConn &amp;amp;&amp;amp; $manager-&amp;gt;hasConnectionForComponent($name)) {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn = $manager-&amp;gt;getConnectionForComponent($name);
        }

        $table = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;getTable($name);
        $tableName = $table-&amp;gt;getTableName();

        &lt;span class=&quot;code-comment&quot;&gt;// get the &lt;span class=&quot;code-object&quot;&gt;short&lt;/span&gt; alias &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; table
&lt;/span&gt;        $tableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias, $tableName);

        $queryPart = &apos;&apos;;

        foreach ($table-&amp;gt;getOption(&apos;joinedParents&apos;) as $parent) {
            $parentTable = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;getTable($parent);

            $parentAlias = $componentAlias . &apos;.&apos; . $parent;

            &lt;span class=&quot;code-comment&quot;&gt;// get the &lt;span class=&quot;code-object&quot;&gt;short&lt;/span&gt; alias &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; the parent table
&lt;/span&gt;            $parentTableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($parentAlias, $parentTable-&amp;gt;getTableName());

            $queryPart .= &apos; LEFT JOIN &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($parentTable-&amp;gt;getTableName())
                        . &apos; &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($parentTableAlias) . &apos; ON &apos;;

            &lt;span class=&quot;code-comment&quot;&gt;//Doctrine_Core::dump($table-&amp;gt;getIdentifier());
&lt;/span&gt;            foreach ((array) $table-&amp;gt;getIdentifier() as $identifier) {
                $column = $table-&amp;gt;getColumnName($identifier);

                $queryPart .= $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias)
                            . &apos;.&apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($column)
                            . &apos; = &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($parentTableAlias)
                            . &apos;.&apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($column);
            }
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $queryPart;
    }

    /**
     * Get count sql query &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; Doctrine_Query instance.
     *
     * This method is used in Doctrine_Query::count() &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; returning an integer
     * &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; the number of records which will be returned when executed.
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string $q
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getCountSqlQuery()
    {
        &lt;span class=&quot;code-comment&quot;&gt;// triggers dql parsing/processing
&lt;/span&gt;        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlQuery(array(), &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;); &lt;span class=&quot;code-comment&quot;&gt;// &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; is ugly
&lt;/span&gt;
        &lt;span class=&quot;code-comment&quot;&gt;// initialize temporary variables
&lt;/span&gt;        $where   = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;];
        $having  = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;having&apos;];
        $groupby = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;groupby&apos;];

        $rootAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootAlias();
        $tableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($rootAlias);

        &lt;span class=&quot;code-comment&quot;&gt;// Build the query base
&lt;/span&gt;        $q = &apos;SELECT COUNT(*) AS &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier(&apos;num_results&apos;) . &apos; FROM &apos;;

        &lt;span class=&quot;code-comment&quot;&gt;// Build the from clause
&lt;/span&gt;        $from = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_buildSqlFromPart(&lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;);

        &lt;span class=&quot;code-comment&quot;&gt;// Build the where clause
&lt;/span&gt;        $where = ( ! empty($where)) ? &apos; WHERE &apos; . implode(&apos; &apos;, $where) : &apos;&apos;;

        &lt;span class=&quot;code-comment&quot;&gt;// Build the group by clause
&lt;/span&gt;        $groupby = ( ! empty($groupby)) ? &apos; GROUP BY &apos; . implode(&apos;, &apos;, $groupby) : &apos;&apos;;

        &lt;span class=&quot;code-comment&quot;&gt;// Build the having clause
&lt;/span&gt;        $having = ( ! empty($having)) ? &apos; HAVING &apos; . implode(&apos; AND &apos;, $having) : &apos;&apos;;

        &lt;span class=&quot;code-comment&quot;&gt;// Building the from clause and finishing query
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents) == 1 &amp;amp;&amp;amp; empty($having)) {
            $q .= $from . $where . $groupby . $having;
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            &lt;span class=&quot;code-comment&quot;&gt;// Subselect fields will contain only the pk of root entity
&lt;/span&gt;            $ta = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias);

            $map = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootDeclaration();
            $idColumnNames = $map[&apos;table&apos;]-&amp;gt;getIdentifierColumnNames();

            $pkFields = $ta . &apos;.&apos; . implode(&apos;, &apos; . $ta . &apos;.&apos;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteMultipleIdentifier($idColumnNames));

            &lt;span class=&quot;code-comment&quot;&gt;// We need to &lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt; some magic in select fields &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; the query contain anything in having clause
&lt;/span&gt;            $selectFields = $pkFields;

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($having)) {
                &lt;span class=&quot;code-comment&quot;&gt;// For each field defined in select clause
&lt;/span&gt;                foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;select&apos;] as $field) {
                    &lt;span class=&quot;code-comment&quot;&gt;// We only include aggregate expressions to count query
&lt;/span&gt;                    &lt;span class=&quot;code-comment&quot;&gt;// This is needed because HAVING clause will use field aliases
&lt;/span&gt;                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($field, &apos;(&apos;) !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                        $selectFields .= &apos;, &apos; . $field;
                    }
                }
                &lt;span class=&quot;code-comment&quot;&gt;// Add having fields that got stripped out of select
&lt;/span&gt;                preg_match_all(&apos;/`[a-z0-9_]+`\.`[a-z0-9_]+`/i&apos;, $having, $matches, PREG_PATTERN_ORDER);
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($matches[0]) &amp;gt; 0) {
                    $selectFields .= &apos;, &apos; . implode(&apos;, &apos;, array_unique($matches[0]));
                }
            }

            &lt;span class=&quot;code-comment&quot;&gt;// If we &lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt; not have a custom group by, apply the &lt;span class=&quot;code-keyword&quot;&gt;default&lt;/span&gt; one
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (empty($groupby)) {
                $groupby = &apos; GROUP BY &apos; . $pkFields;
            }

            $q .= &apos;(SELECT &apos; . $selectFields . &apos; FROM &apos; . $from . $where . $groupby . $having . &apos;) &apos;
                . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier(&apos;dctrn_count_query&apos;);
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $q;
    }

    /**
     * Fetches the count of the query.
     *
     * This method executes the main query without all the
     * selected fields, ORDER BY part, LIMIT part and OFFSET part.
     *
     * Example:
     * Main query:
     *      SELECT u.*, p.phonenumber FROM User u
     *          LEFT JOIN u.Phonenumber p
     *          WHERE p.phonenumber = &apos;123 123&apos; LIMIT 10
     *
     * The modified DQL query:
     *      SELECT COUNT(DISTINCT u.id) FROM User u
     *          LEFT JOIN u.Phonenumber p
     *          WHERE p.phonenumber = &apos;123 123&apos;
     *
     * @param array $params        an array of prepared statement parameters
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; integer             the count of &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; query
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function count($params = array())
    {
        $q = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getCountSqlQuery();
        $params = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getCountQueryParams($params);
        $params = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;convertBooleans($params);

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_resultCache) {
            $conn = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getConnection(); 
            $cacheDriver = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getResultCacheDriver();
            $hash = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getResultCacheHash($params).&apos;_count&apos;;
            $cached = ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_expireResultCache) ? &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt; : $cacheDriver-&amp;gt;fetch($hash);

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($cached === &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                &lt;span class=&quot;code-comment&quot;&gt;// cache miss
&lt;/span&gt;                $results = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getConnection()-&amp;gt;fetchAll($q, $params);
                $cacheDriver-&amp;gt;save($hash, serialize($results), $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getResultCacheLifeSpan());
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                $results = unserialize($cached);
            }
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            $results = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getConnection()-&amp;gt;fetchAll($q, $params);
        }

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($results) &amp;gt; 1) {
            $count = count($results);
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($results[0])) {
                $results[0] = array_change_key_case($results[0], CASE_LOWER);
                $count = $results[0][&apos;num_results&apos;];
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                $count = 0;
            }
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; (&lt;span class=&quot;code-object&quot;&gt;int&lt;/span&gt;) $count;
    }

    /**
     * Queries the database with DQL (Doctrine Query Language).
     *
     * This methods parses a Dql query and builds the query parts.
     *
     * @param string $query      Dql query
     * @param array $params      prepared statement parameters
     * @param &lt;span class=&quot;code-object&quot;&gt;int&lt;/span&gt; $hydrationMode Doctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD
     * @see Doctrine_Core::FETCH_* constants
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; mixed
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function query($query, $params = array(), $hydrationMode = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;)
    {
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;parseDqlQuery($query);
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;execute($params, $hydrationMode);
    }

    /**
     * Copies a Doctrine_Query object.
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; Doctrine_Query  Copy of the Doctrine_Query instance.
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function copy(Doctrine_Query $query = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $query) {
            $query = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;;
        }

        $&lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; = clone $query;

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt;;
    }

    /**
     * Magic method called after cloning process.
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; void
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function __clone()
    {
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_parsers = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_hydrator = clone $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_hydrator;

        &lt;span class=&quot;code-comment&quot;&gt;// Subqueries share some information from the parent so it can intermingle
&lt;/span&gt;        &lt;span class=&quot;code-comment&quot;&gt;// with the dql of the main query. So when a subquery is cloned we need to
&lt;/span&gt;        &lt;span class=&quot;code-comment&quot;&gt;// kill those references or it causes problems
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;isSubquery()) {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_killReference(&apos;_params&apos;);
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_killReference(&apos;_tableAliasMap&apos;);
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_killReference(&apos;_queryComponents&apos;);
        }
    }

    /**
     * Kill the reference &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; the passed class property.
     * This method simply copies the value to a temporary variable and then unsets
     * the reference and re-assigns the old value but not by reference
     *
     * @param string $key
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; function _killReference($key)
    {
        $tmp = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;$key;
        unset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;$key);
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;$key = $tmp;
    }

    /**
     * Frees the resources used by the query object. It especially breaks a
     * cyclic reference between the query object and it&apos;s parsers. This enables
     * PHP&apos;s current GC to reclaim the memory.
     * This method can therefore be used to reduce memory usage when creating
     * a lot of query objects during a request.
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; Doctrine_Query   &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; object
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function free()
    {
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;reset();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_parsers = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_dqlParts = array();
    }
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                    <comment id="13071" author="jwage" created="Thu, 27 May 2010 08:13:30 +0000"  >&lt;p&gt;Do you test your changes against our test suite? We will still be releasing bug fix releases, we&apos;re just not monitoring and fixing bugs on a day to day basis. As I don&apos;t have any help on Doctrine 1 I have to spend a week every 1-2 months just going through issues and closing as many as possible.&lt;/p&gt;</comment>
                    <comment id="13072" author="willf1976" created="Thu, 27 May 2010 22:08:52 +0000"  >&lt;p&gt;Hi Jonathan&lt;/p&gt;

&lt;p&gt;Thanks for the write back.&lt;/p&gt;

&lt;p&gt;I hadn&apos;t been using the test cases but I just tried and this latest patch was causing many of them to fail (I have resolved the issues however &amp;#8211; see below).&lt;/p&gt;

&lt;p&gt;The current problem is that with out my patch the following dql:&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 Charity.id, Charity.id as charity_id, (SQL:SELECT p.id AS p__0 FROM product_customers p LIMIT 1) as custom_subQuery FROM Charity Charity LIMIT 20
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Produces the following exception:&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;{&lt;span class=&quot;code-quote&quot;&gt;&quot;type&quot;&lt;/span&gt;:&lt;span class=&quot;code-quote&quot;&gt;&quot;exception&quot;&lt;/span&gt;,&lt;span class=&quot;code-quote&quot;&gt;&quot;tid&quot;&lt;/span&gt;:3,&lt;span class=&quot;code-quote&quot;&gt;&quot;exception&quot;&lt;/span&gt;:{},&lt;span class=&quot;code-quote&quot;&gt;&quot;message&quot;&lt;/span&gt;:&lt;span class=&quot;code-quote&quot;&gt;&quot;Couldn&apos;t get &lt;span class=&quot;code-object&quot;&gt;short&lt;/span&gt; alias &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; p&quot;&lt;/span&gt;,&lt;span class=&quot;code-quote&quot;&gt;&quot;where&quot;&lt;/span&gt;:&lt;span class=&quot;code-quote&quot;&gt;&quot;#0 C:\\htdocs\\php_library\\Doctrine-1.2.2\\lib\\Doctrine\\Query.php(641): Doctrine_Query_Abstract-&amp;gt;getSqlTableAlias(&apos;p&apos;)\n#1 C:\\htdocs\\php_library\\Doctrine-1.2.2\\lib\\Doctrine\\Query\\Select.php(37): Doctrine_Query-&amp;gt;parseSelect(&apos;(SQL:SELECT p.i...&apos;)\n#2 C:\\htdocs\\php_library\\Doctrine-1.2.2\\lib\\Doctrine\\Query\\Abstract.php(2078): Doctrine_Query_Select-&amp;gt;parse(&apos;(SQL:SELECT p.i...&apos;)\n#3 C:\\htdocs\\php_library\\Doctrine-1.2.2\\lib\\Doctrine\\Query.php(1168): Doctrine_Query_Abstract-&amp;gt;_processDqlQueryPart(&apos;select&apos;, Array)\n#4 C:\\htdocs\\php_library\\Doctrine-1.2.2\\lib\\Doctrine\\Query.php(1134): Doctrine_Query-&amp;gt;buildSqlQuery(&lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;)\n#5 C:\\htdocs\\Root\\modules\\&lt;span class=&quot;code-keyword&quot;&gt;default&lt;/span&gt;\\util\\AnalyticsGrid.php(166): Doctrine_Query-&amp;gt;getSqlQuery()\n#6 C:\\htdocs\\Root\\modules\\&lt;span class=&quot;code-keyword&quot;&gt;default&lt;/span&gt;\\models\\FileInFolders.php(166): Util_AnalyticsGrid-&amp;gt;readAnalyticsGrid(&apos;{\&quot;&lt;/span&gt;select\&lt;span class=&quot;code-quote&quot;&gt;&quot;:{\&quot;&lt;/span&gt;chi...&apos;, 0, 20, Array, Array, Array, Array, Array)\n#7 [internal function]: Models_FileInFolders-&amp;gt;readAnalyticsTableProxy(37, 0, 20, Array, Array, Array, Array, Array)\n#8 C:\\htdocs\\php_library\\Doctrine-1.2.2\\lib\\Doctrine\\Table.php(2808): call_user_func_array(Array, Array)\n#9 [internal function]: Doctrine_Table-&amp;gt;__call(&apos;readAnalytics&apos;, Array)\n#10 C:\\htdocs\\Root\\modules\\event\\controllers\\AnalyticsController.php(96): Doctrine_Table-&amp;gt;readAnalytics(37, 0, 20, Array, Array, Array, Array, Array)\n#11 [internal function]: Event_AnalyticsController-&amp;gt;readAnalyticsAction(&lt;span class=&quot;code-object&quot;&gt;Object&lt;/span&gt;(stdClass))\n#12 C:\\htdocs\\Root\\modules\\&lt;span class=&quot;code-keyword&quot;&gt;default&lt;/span&gt;\\util\\helper\\ZendDirectRouter.php(194): call_user_func_array(Array, Array)\n#13 C:\\htdocs\\Root\\modules\\&lt;span class=&quot;code-keyword&quot;&gt;default&lt;/span&gt;\\util\\helper\\ZendDirectRouter.php(68): Util_Helper_ZendDirectRouter-&amp;gt;rpc(&lt;span class=&quot;code-object&quot;&gt;Object&lt;/span&gt;(stdClass))\n#14 C:\\htdocs\\Root\\modules\\&lt;span class=&quot;code-keyword&quot;&gt;default&lt;/span&gt;\\base\\ActionController.php(80): Util_Helper_ZendDirectRouter-&amp;gt;dispatch()\n#15 C:\\htdocs\\php_library\\zendframework\\library\\Zend\\Controller\\Action.php(513): Base_ActionController-&amp;gt;directAction()\n#16 C:\\htdocs\\php_library\\zendframework\\library\\Zend\\Controller\\Dispatcher\\Standard.php(289): Zend_Controller_Action-&amp;gt;dispatch(&apos;directAction&apos;)\n#17 C:\\htdocs\\php_library\\zendframework\\library\\Zend\\Controller\\Front.php(955): Zend_Controller_Dispatcher_Standard-&amp;gt;dispatch(&lt;span class=&quot;code-object&quot;&gt;Object&lt;/span&gt;(Zend_Controller_Request_Http), &lt;span class=&quot;code-object&quot;&gt;Object&lt;/span&gt;(Zend_Controller_Response_Http))\n#18 C:\\htdocs\\Root\\&lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt;\\index.php(78): Zend_Controller_Front-&amp;gt;dispatch()\n#19 {main}&quot;}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I looked at my code again and saw some very glaring errors in it (I was rushing through bugs and as soon as I thought I had fixed this one I didn&apos;t take the time to read it over &amp;#8211; in the future will be sure to use the tests in order to avoid any such oversights).&lt;/p&gt;

&lt;p&gt;At any rate I have changed my patch to the code and this is both working for my needs and passing all the tests again. Here is the newest version of my patched code:&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;&amp;lt;?php
/*
 *  $Id: Query.php 7490 2010-03-29 19:53:27Z jwage $
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * &lt;span class=&quot;code-quote&quot;&gt;&quot;AS IS&quot;&lt;/span&gt; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the LGPL. For more information, see
 * &amp;lt;http:&lt;span class=&quot;code-comment&quot;&gt;//www.doctrine-project.org&amp;gt;.
&lt;/span&gt; */

/**
 * Doctrine_Query
 * A Doctrine_Query object represents a DQL query. It is used to query databases &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt;
 * data in an object-oriented fashion. A DQL query understands relations and inheritance
 * and is dbms independant.
 *
 * @&lt;span class=&quot;code-keyword&quot;&gt;package&lt;/span&gt;     Doctrine
 * @subpackage  Query
 * @license     http:&lt;span class=&quot;code-comment&quot;&gt;//www.opensource.org/licenses/lgpl-license.php LGPL
&lt;/span&gt; * @link        www.doctrine-project.org
 * @since       1.0
 * @version     $Revision: 7490 $
 * @author      Konsta Vesterinen &amp;lt;kvesteri@cc.hut.fi&amp;gt;
 * @todo        Proposal: This class does far too much. It should have only 1 task: Collecting
 *              the DQL query parts and the query parameters (the query state and caching options/methods
 *              can remain here, too).
 *              The actual SQL construction could be done by a separate object (Doctrine_Query_SqlBuilder?)
 *              whose task it is to convert DQL into SQL.
 *              Furthermore the SqlBuilder? can then use other objects (Doctrine_Query_Tokenizer?),
 *              (Doctrine_Query_Parser(s)?) to accomplish his work. Doctrine_Query does not need
 *              to know the tokenizer/parsers. There could be extending
 *              implementations of SqlBuilder? that cover the specific SQL dialects.
 *              This would release Doctrine_Connection and the Doctrine_Connection_xxx classes
 *              from &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; tedious task.
 *              This would also largely reduce the currently huge &lt;span class=&quot;code-keyword&quot;&gt;interface&lt;/span&gt; of Doctrine_Query(_Abstract)
 *              and better hide all these transformation internals from the &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; Query API.
 *
 * @internal    The lifecycle of a Query object is the following:
 *              After construction the query object is empty. Through using the fluent
 *              query &lt;span class=&quot;code-keyword&quot;&gt;interface&lt;/span&gt; the user fills the query object with DQL parts and query parameters.
 *              These get collected in {@link $_dqlParts} and {@link $_params}, respectively.
 *              When the query is executed the first time, or when {@link getSqlQuery()}
 *              is called the first time, the collected DQL parts get parsed and the resulting
 *              connection-driver specific SQL is generated. The generated SQL parts are
 *              stored in {@link $_sqlParts} and the &lt;span class=&quot;code-keyword&quot;&gt;final&lt;/span&gt; resulting SQL query is stored in
 *              {@link $_sql}.
 */
class Doctrine_Query &lt;span class=&quot;code-keyword&quot;&gt;extends&lt;/span&gt; Doctrine_Query_Abstract &lt;span class=&quot;code-keyword&quot;&gt;implements&lt;/span&gt; Countable
{
    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; array  The DQL keywords.
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;static&lt;/span&gt; $_keywords  = array(&apos;ALL&apos;,
                                         &apos;AND&apos;,
                                         &apos;ANY&apos;,
                                         &apos;AS&apos;,
                                         &apos;ASC&apos;,
                                         &apos;AVG&apos;,
                                         &apos;BETWEEN&apos;,
                                         &apos;BIT_LENGTH&apos;,
                                         &apos;BY&apos;,
                                         &apos;CHARACTER_LENGTH&apos;,
                                         &apos;CHAR_LENGTH&apos;,
                                         &apos;CURRENT_DATE&apos;,
                                         &apos;CURRENT_TIME&apos;,
                                         &apos;CURRENT_TIMESTAMP&apos;,
                                         &apos;DELETE&apos;,
                                         &apos;DESC&apos;,
                                         &apos;DISTINCT&apos;,
                                         &apos;EMPTY&apos;,
                                         &apos;EXISTS&apos;,
                                         &apos;FALSE&apos;,
                                         &apos;FETCH&apos;,
                                         &apos;FROM&apos;,
                                         &apos;GROUP&apos;,
                                         &apos;HAVING&apos;,
                                         &apos;IN&apos;,
                                         &apos;INDEXBY&apos;,
                                         &apos;INNER&apos;,
                                         &apos;IS&apos;,
                                         &apos;JOIN&apos;,
                                         &apos;LEFT&apos;,
                                         &apos;LIKE&apos;,
                                         &apos;LOWER&apos;,
                                         &apos;MEMBER&apos;,
                                         &apos;MOD&apos;,
                                         &apos;NEW&apos;,
                                         &apos;NOT&apos;,
                                         &apos;NULL&apos;,
                                         &apos;OBJECT&apos;,
                                         &apos;OF&apos;,
                                         &apos;OR&apos;,
                                         &apos;ORDER&apos;,
                                         &apos;OUTER&apos;,
                                         &apos;POSITION&apos;,
                                         &apos;SELECT&apos;,
                                         &apos;SOME&apos;,
                                         &apos;TRIM&apos;,
                                         &apos;TRUE&apos;,
                                         &apos;UNKNOWN&apos;,
                                         &apos;UPDATE&apos;,
                                         &apos;WHERE&apos;);

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; array
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_subqueryAliases = array();

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; array $_aggregateAliasMap       an array containing all aggregate aliases, keys as dql aliases
     *                                      and values as sql aliases
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_aggregateAliasMap      = array();

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; array
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_pendingAggregates = array();

    /**
     * @param &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt; $needsSubquery
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_needsSubquery = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;

    /**
     * @param &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt; $isSubquery           whether or not &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; query object is a subquery of another
     *                                      query object
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_isSubquery;

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; array $_neededTables            an array containing the needed table aliases
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_neededTables = array();

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; array $pendingSubqueries        SELECT part subqueries, these are called pending subqueries since
     *                                      they cannot be parsed directly (some queries might be correlated)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_pendingSubqueries = array();

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; array $_pendingFields           an array of pending fields (fields waiting to be parsed)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_pendingFields = array();

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; array $_parsers                 an array of parser objects, each DQL query part has its own parser
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_parsers = array();

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; array $_pendingJoinConditions    an array containing pending joins
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_pendingJoinConditions = array();

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; array
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_expressionMap = array();

    /**
     * @&lt;span class=&quot;code-keyword&quot;&gt;var&lt;/span&gt; string $_sql            cached SQL query
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $_sql;

    /**
     * create
     * returns a &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query object
     *
     * @param Doctrine_Connection $conn  optional connection parameter
     * @param string $class              Query class to instantiate
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; Doctrine_Query
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;static&lt;/span&gt; function create($conn = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;, $class = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $class) {
            $class = Doctrine_Manager::getInstance()
                -&amp;gt;getAttribute(Doctrine_Core::ATTR_QUERY_CLASS);
        }
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; $class($conn);
    }

    /**
     * Clears all the sql parts.
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; function clear()
    {
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_preQueried = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingJoinConditions = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_state = self::STATE_DIRTY;
    }

    /**
     * Resets the query to the state just after it has been instantiated.
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function reset()
    {
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_subqueryAliases = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingAggregates = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingSubqueries = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingFields = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_neededTables = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_expressionMap = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_subqueryAliases = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_needsSubquery = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_isLimitSubqueryUsed = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
    }

    /**
     * createSubquery
     * creates a subquery
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; Doctrine_Hydrate
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function createSubquery()
    {
        $class = get_class($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;);
        $obj   = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; $class();

        &lt;span class=&quot;code-comment&quot;&gt;// copy the aliases to the subquery
&lt;/span&gt;        $obj-&amp;gt;copySubqueryInfo($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;);

        &lt;span class=&quot;code-comment&quot;&gt;// &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; prevents the &apos;id&apos; being selected, re ticket #307
&lt;/span&gt;        $obj-&amp;gt;isSubquery(&lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;);

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $obj;
    }

    /**
     * addPendingJoinCondition
     *
     * @param string $componentAlias    component alias
     * @param string $joinCondition     dql join condition
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; Doctrine_Query           &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; object
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function addPendingJoinCondition($componentAlias, $joinCondition)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingJoinConditions[$componentAlias])) {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingJoinConditions[$componentAlias] = array();
        }

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingJoinConditions[$componentAlias][] = $joinCondition;
    }

    /**
     * fetchArray
     * Convenience method to execute using array fetching as hydration mode.
     *
     * @param string $params
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; array
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function fetchArray($params = array())
    {
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;execute($params, Doctrine_Core::HYDRATE_ARRAY);
    }

    /**
     * fetchOne
     * Convenience method to execute the query and &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; the first item
     * of the collection.
     *
     * @param string $params        Query parameters
     * @param &lt;span class=&quot;code-object&quot;&gt;int&lt;/span&gt; $hydrationMode    Hydration mode: see Doctrine_Core::HYDRATE_* constants
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; mixed                Array or Doctrine_Collection, depending on hydration mode. False &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; no result.
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function fetchOne($params = array(), $hydrationMode = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;)
    {
        $collection = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;execute($params, $hydrationMode);

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (is_scalar($collection)) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $collection;
        }

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($collection) === 0) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
        }

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($collection &lt;span class=&quot;code-keyword&quot;&gt;instanceof&lt;/span&gt; Doctrine_Collection) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $collection-&amp;gt;getFirst();
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (is_array($collection)) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; array_shift($collection);
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
    }

    /**
     * isSubquery
     * &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; $bool parameter is set &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; method sets the value of
     * Doctrine_Query::$isSubquery. If &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; value is set to &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;
     * the query object will not load the primary key fields of the selected
     * components.
     *
     * If &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt; is given as the first parameter &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; method retrieves the current
     * value of Doctrine_Query::$isSubquery.
     *
     * @param &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt; $bool     whether or not &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; query acts as a subquery
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; Doctrine_Query|bool
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function isSubquery($bool = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($bool === &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_isSubquery;
        }

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_isSubquery = (bool) $bool;
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;;
    }

    /**
     * getSqlAggregateAlias
     *
     * @param string $dqlAlias      the dql alias of an aggregate value
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getSqlAggregateAlias($dqlAlias)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap[$dqlAlias])) {
            &lt;span class=&quot;code-comment&quot;&gt;// mark the expression as used
&lt;/span&gt;            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_expressionMap[$dqlAlias][1] = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;

            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap[$dqlAlias];
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingAggregates)) {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;processPendingAggregates();

            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlAggregateAlias($dqlAlias);
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt;( ! ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;getAttribute(Doctrine_Core::ATTR_PORTABILITY) &amp;amp; Doctrine_Core::PORTABILITY_EXPR)){
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $dqlAlias;
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&apos;Unknown aggregate alias: &apos; . $dqlAlias);
        }
    }

    /**
     * Check &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; a dql alias has a sql aggregate alias
     *
     * @param string $dqlAlias 
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt;
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function hasSqlAggregateAlias($dqlAlias)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;try&lt;/span&gt; {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlAggregateAlias($dqlAlias);
            &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;catch&lt;/span&gt; (Exception $e) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
        }
    }

    /**
     * Adjust the processed param index &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;code-quote&quot;&gt;&quot;foo.bar IN ?&quot;&lt;/span&gt; support
     *
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function adjustProcessedParam($index)
    {
        &lt;span class=&quot;code-comment&quot;&gt;// Retrieve all params
&lt;/span&gt;        $params = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getInternalParams();

        &lt;span class=&quot;code-comment&quot;&gt;// Retrieve already processed values
&lt;/span&gt;        $first = array_slice($params, 0, $index);
        $last = array_slice($params, $index, count($params) - $index);

        &lt;span class=&quot;code-comment&quot;&gt;// Include array as values splicing the params array
&lt;/span&gt;        array_splice($last, 0, 1, $last[0]);

        &lt;span class=&quot;code-comment&quot;&gt;// Put all param values into a single index
&lt;/span&gt;        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_execParams = array_merge($first, $last);
    }

    /**
     * Retrieves a specific DQL query part.
     *
     * @see Doctrine_Query_Abstract::$_dqlParts
     * &amp;lt;code&amp;gt;
     * var_dump($q-&amp;gt;getDqlPart(&apos;where&apos;));
     * &lt;span class=&quot;code-comment&quot;&gt;// array(2) { [0] =&amp;gt; string(8) &apos;name = ?&apos; [1] =&amp;gt; string(8) &apos;date &amp;gt; ?&apos; }
&lt;/span&gt;     * &amp;lt;/code&amp;gt;
     * @param string $queryPart     the name of the query part; can be:
     *     array from, containing strings;
     *     array select, containg string;
     *     &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt; forUpdate;
     *     array set;
     *     array join;
     *     array where;
     *     array groupby;
     *     array having;
     *     array orderby, containing strings such as &apos;id ASC&apos;;
     *     array limit, containing numerics;
     *     array offset, containing numerics;
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; array
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getDqlPart($queryPart)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_dqlParts[$queryPart])) {
           &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&apos;Unknown query part &apos; . $queryPart);
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_dqlParts[$queryPart];
    }

    /**
     * contains
     *
     * Method to check &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; a arbitrary piece of dql exists
     *
     * @param string $dql Arbitrary piece of dql to check &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt;
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt;
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function contains($dql)
    {
      &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; stripos($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getDql(), $dql) === &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt; ? &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt; : &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;
    }

    /**
     * processPendingFields
     * the fields in SELECT clause cannot be parsed until the components
     * in FROM clause are parsed, hence &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; method is called everytime a
     * specific component is being parsed. For instance, the wildcard &apos;*&apos;
     * is expanded in the list of columns.
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;throws&lt;/span&gt; Doctrine_Query_Exception     &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; unknown component alias has been given
     * @param string $componentAlias        the alias of the component
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string SQL code
     * @todo Description: What is a &apos;pending field&apos; (and are there non-pending fields, too)?
     *       What is &apos;processed&apos;? (Meaning: What information is gathered &amp;amp; stored away)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function processPendingFields($componentAlias)
    {
        $tableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias);
        $table = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;table&apos;];

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingFields[$componentAlias])) {
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_hydrator-&amp;gt;getHydrationMode() != Doctrine_Core::HYDRATE_NONE) {
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_isSubquery &amp;amp;&amp;amp; $componentAlias == $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootAlias()) {
                    &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&lt;span class=&quot;code-quote&quot;&gt;&quot;The root class of the query (alias $componentAlias) &quot;&lt;/span&gt;
                            . &lt;span class=&quot;code-quote&quot;&gt;&quot; must have at least one field selected.&quot;&lt;/span&gt;);
                }
            }
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt;;
        }

        &lt;span class=&quot;code-comment&quot;&gt;// At &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; point we know the component is FETCHED (either it&apos;s the base class of
&lt;/span&gt;        &lt;span class=&quot;code-comment&quot;&gt;// the query (FROM xyz) or its a &lt;span class=&quot;code-quote&quot;&gt;&quot;fetch join&quot;&lt;/span&gt;).
&lt;/span&gt;
        &lt;span class=&quot;code-comment&quot;&gt;// Check that the parent join (&lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; there is one), is a &lt;span class=&quot;code-quote&quot;&gt;&quot;fetch join&quot;&lt;/span&gt;, too.
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;isSubquery() &amp;amp;&amp;amp; isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;parent&apos;])) {
            $parentAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;parent&apos;];
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (is_string($parentAlias) &amp;amp;&amp;amp; ! isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingFields[$parentAlias])
                    &amp;amp;&amp;amp; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_hydrator-&amp;gt;getHydrationMode() != Doctrine_Core::HYDRATE_NONE
                    &amp;amp;&amp;amp; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_hydrator-&amp;gt;getHydrationMode() != Doctrine_Core::HYDRATE_SCALAR
                    &amp;amp;&amp;amp; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_hydrator-&amp;gt;getHydrationMode() != Doctrine_Core::HYDRATE_SINGLE_SCALAR) {
                &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&lt;span class=&quot;code-quote&quot;&gt;&quot;The left side of the join between &quot;&lt;/span&gt;
                        . &lt;span class=&quot;code-quote&quot;&gt;&quot;the aliases &apos;$parentAlias&apos; and &apos;$componentAlias&apos; must have at least&quot;&lt;/span&gt;
                        . &lt;span class=&quot;code-quote&quot;&gt;&quot; the primary key field(s) selected.&quot;&lt;/span&gt;);
            }
        }

        $fields = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingFields[$componentAlias];

        &lt;span class=&quot;code-comment&quot;&gt;// check &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; wildcards
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (in_array(&apos;*&apos;, $fields)) {
            $fields = $table-&amp;gt;getFieldNames();
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            $driverClassName = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_hydrator-&amp;gt;getHydratorDriverClassName();
            &lt;span class=&quot;code-comment&quot;&gt;// only auto-add the primary key fields &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; query object is not
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;// a subquery of another query object or we&apos;re using a child of the &lt;span class=&quot;code-object&quot;&gt;Object&lt;/span&gt; Graph
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;// hydrator
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_isSubquery &amp;amp;&amp;amp; is_subclass_of($driverClassName, &apos;Doctrine_Hydrator_Graph&apos;)) {
                $fields = array_unique(array_merge((array) $table-&amp;gt;getIdentifier(), $fields));
            }
        }

        $sql = array();
        foreach ($fields as $fieldName) {
            $columnName = $table-&amp;gt;getColumnName($fieldName);
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (($owner = $table-&amp;gt;getColumnOwner($columnName)) !== &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt; &amp;amp;&amp;amp;
                    $owner !== $table-&amp;gt;getComponentName()) {

                $parent = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;getTable($owner);
                $columnName = $parent-&amp;gt;getColumnName($fieldName);
                $parentAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias . &apos;.&apos; . $parent-&amp;gt;getComponentName());
                $sql[] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($parentAlias) . &apos;.&apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($columnName)
                       . &apos; AS &apos;
                       . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias . &apos;__&apos; . $columnName);
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                $columnName = $table-&amp;gt;getColumnName($fieldName);
                $sql[] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias) . &apos;.&apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($columnName)
                       . &apos; AS &apos;
                       . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias . &apos;__&apos; . $columnName);
            }
        }

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_neededTables[] = $tableAlias;

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; implode(&apos;, &apos;, $sql);
    }

    /**
     * Parses a nested field
     * &amp;lt;code&amp;gt;
     * $q-&amp;gt;parseSelectField(&apos;u.Phonenumber.value&apos;);
     * &amp;lt;/code&amp;gt;
     *
     * @param string $field
     * @&lt;span class=&quot;code-keyword&quot;&gt;throws&lt;/span&gt; Doctrine_Query_Exception     &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; unknown component alias has been given
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string   SQL fragment
     * @todo Description: Explain what &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; method does. Is there a relation to parseSelect()?
     *       This method is not used from any class or testcase in the Doctrine &lt;span class=&quot;code-keyword&quot;&gt;package&lt;/span&gt;.
     *
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function parseSelectField($field)
    {
        $terms = explode(&apos;.&apos;, $field);

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($terms[1])) {
            $componentAlias = $terms[0];
            $field = $terms[1];
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            reset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents);
            $componentAlias = key($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents);
            $fields = $terms[0];
        }

        $tableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias);
        $table      = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;table&apos;];


        &lt;span class=&quot;code-comment&quot;&gt;// check &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; wildcards
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($field === &apos;*&apos;) {
            $sql = array();

            foreach ($table-&amp;gt;getColumnNames() as $field) {
                $sql[] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;parseSelectField($componentAlias . &apos;.&apos; . $field);
            }

            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; implode(&apos;, &apos;, $sql);
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            $name = $table-&amp;gt;getColumnName($field);

            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_neededTables[] = $tableAlias;

            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias . &apos;.&apos; . $name)
                   . &apos; AS &apos;
                   . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias . &apos;__&apos; . $name);
        }
    }

    /**
     * getExpressionOwner
     * returns the component alias &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; owner of given expression
     *
     * @param string $expr      expression from which to get to owner from
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string           the component alias
     * @todo Description: What does it mean &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; a component is an &apos;owner&apos; of an expression?
     *       What kind of &apos;expression&apos; are we talking about here?
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getExpressionOwner($expr)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strtoupper(substr(trim($expr, &apos;( &apos;), 0, 6)) !== &apos;SELECT&apos;) {
            preg_match_all(&lt;span class=&quot;code-quote&quot;&gt;&quot;/[a-z_][a-z0-9_]*\.[a-z_][a-z0-9_]*[\.[a-z0-9]+]*/i&quot;&lt;/span&gt;, $expr, $matches);

            $match = current($matches);

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($match[0])) {
                $terms = explode(&apos;.&apos;, $match[0]);

                &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $terms[0];
            }
        }
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootAlias();

    }

    /**
     * parseSelect
     * parses the query select part and
     * adds selected fields to pendingFields array
     *
     * @param string $dql
     * @todo Description: What information is extracted (and then stored)?
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function parseSelect($dql)
    {
        $refs = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;sqlExplode($dql, &apos;,&apos;);

        $pos   = strpos(trim($refs[0]), &apos; &apos;);
        $first = substr($refs[0], 0, $pos);

        &lt;span class=&quot;code-comment&quot;&gt;// check &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; DISTINCT keyword
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($first === &apos;DISTINCT&apos;) {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;distinct&apos;] = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;

            $refs[0] = substr($refs[0], ++$pos);
        }

        $parsedComponents = array();

        foreach ($refs as $reference) {
            $reference = trim($reference);

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (empty($reference)) {
                &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
            }

            $terms = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;sqlExplode($reference, &apos; &apos;);
            $pos   = strpos($terms[0], &apos;(&apos;);

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($terms) &amp;gt; 1 || $pos !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                $expression = array_shift($terms);
                $alias = array_pop($terms);

                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $alias) {
                    $alias = substr($expression, 0, $pos);
                }
				
				
			&lt;span class=&quot;code-comment&quot;&gt;//Patched By Will Ferrer to detect when a subquery was encountered and use an existing componentAlias &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; the expression is a subquery. (not well tested) Fixes Bug -- DC-706
&lt;/span&gt;				&lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($pos !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt; &amp;amp;&amp;amp; substr($expression, 0, 1) !== &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&quot;&lt;/span&gt; &amp;amp;&amp;amp; substr($expression, 0, $pos) == &apos;&apos;) {
					$_queryComponents = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents;
					reset($_queryComponents);
					$componentAlias = key($_queryComponents);
				} &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
               		$componentAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getExpressionOwner($expression);
				}
			&lt;span class=&quot;code-comment&quot;&gt;//End Patch
&lt;/span&gt;			
				$expression = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;parseClause($expression);

                $tableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias);
				
                $index    = count($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap);

                $sqlAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias . &apos;__&apos; . $index);

                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;select&apos;][] = $expression . &apos; AS &apos; . $sqlAlias;

                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap[$alias] = $sqlAlias;
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_expressionMap[$alias][0] = $expression;

                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;agg&apos;][$index] = $alias;
				
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_neededTables[] = $tableAlias;
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                $e = explode(&apos;.&apos;, $terms[0]);

                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($e[1])) {
                    $componentAlias = $e[0];
                    $field = $e[1];
                } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                    reset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents);
                    $componentAlias = key($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents);
                    $field = $e[0];
                }

                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingFields[$componentAlias][] = $field;
            }
        }
    }

    /**
     * parseClause
     * parses given DQL clause
     *
     * &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; method handles five tasks:
     *
     * 1. Converts all DQL functions to their &lt;span class=&quot;code-keyword&quot;&gt;native&lt;/span&gt; SQL equivalents
     * 2. Converts all component references to their table alias equivalents
     * 3. Converts all field names to actual column names
     * 4. Quotes all identifiers
     * 5. Parses nested clauses and subqueries recursively
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string   SQL string
     * @todo Description: What is a &apos;dql clause&apos; (and what not)?
     *       Refactor: Too &lt;span class=&quot;code-object&quot;&gt;long&lt;/span&gt; &amp;amp; nesting level
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function parseClause($clause)
    {
        $clause = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;dataDict-&amp;gt;parseBoolean(trim($clause));

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (is_numeric($clause)) {
           &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $clause;
        }

        $terms = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;clauseExplode($clause, array(&apos; &apos;, &apos;+&apos;, &apos;-&apos;, &apos;*&apos;, &apos;/&apos;, &apos;&amp;lt;&apos;, &apos;&amp;gt;&apos;, &apos;=&apos;, &apos;&amp;gt;=&apos;, &apos;&amp;lt;=&apos;, &apos;&amp;amp;&apos;, &apos;|&apos;));
        $str = &apos;&apos;;

        foreach ($terms as $term) {
            $pos = strpos($term[0], &apos;(&apos;);

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($pos !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt; &amp;amp;&amp;amp; substr($term[0], 0, 1) !== &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&quot;&lt;/span&gt;) {
                $name = substr($term[0], 0, $pos);

                $term[0] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;parseFunctionExpression($term[0]);
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (substr($term[0], 0, 1) !== &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&quot;&lt;/span&gt; &amp;amp;&amp;amp; substr($term[0], -1) !== &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&quot;&lt;/span&gt;) {
                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($term[0], &apos;.&apos;) !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! is_numeric($term[0])) {
                            $e = explode(&apos;.&apos;, $term[0]);

                            $field = array_pop($e);

                            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getType() === Doctrine_Query::SELECT) {
                                $componentAlias = implode(&apos;.&apos;, $e);

                                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (empty($componentAlias)) {
                                    $componentAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootAlias();
                                }

                                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;load($componentAlias);

                                &lt;span class=&quot;code-comment&quot;&gt;// check the existence of the component alias
&lt;/span&gt;                                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias])) {
                                    &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&apos;Unknown component alias &apos; . $componentAlias);
                                }

                                $table = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;table&apos;];

                                $def = $table-&amp;gt;getDefinitionOf($field);

                                &lt;span class=&quot;code-comment&quot;&gt;// get the actual field name from alias
&lt;/span&gt;                                $field = $table-&amp;gt;getColumnName($field);

                                &lt;span class=&quot;code-comment&quot;&gt;// check column existence
&lt;/span&gt;                                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $def) {
                                    &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&apos;Unknown column &apos; . $field);
                                }

                                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($def[&apos;owner&apos;])) {
                                    $componentAlias = $componentAlias . &apos;.&apos; . $def[&apos;owner&apos;];
                                }

                                $tableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias);

                                &lt;span class=&quot;code-comment&quot;&gt;// build sql expression
&lt;/span&gt;                                $term[0] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias)
                                         . &apos;.&apos;
                                         . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($field);
                            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                                &lt;span class=&quot;code-comment&quot;&gt;// build sql expression
&lt;/span&gt;                                $field = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRoot()-&amp;gt;getColumnName($field);
                                $term[0] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($field);
                            }
                        }
                    } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($term[0]) &amp;amp;&amp;amp; ! in_array(strtoupper($term[0]), self::$_keywords) &amp;amp;&amp;amp;
                             ! is_numeric($term[0]) &amp;amp;&amp;amp; $term[0] !== &apos;?&apos; &amp;amp;&amp;amp; substr($term[0], 0, 1) !== &apos;:&apos;) {

                            $componentAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootAlias();

                            $found = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;

                            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($componentAlias !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt; &amp;amp;&amp;amp; $componentAlias !== &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;) {
                                $table = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;table&apos;];

                                &lt;span class=&quot;code-comment&quot;&gt;// check column existence
&lt;/span&gt;                                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($table-&amp;gt;hasField($term[0])) {
                                    $found = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;

                                    $def = $table-&amp;gt;getDefinitionOf($term[0]);

                                    &lt;span class=&quot;code-comment&quot;&gt;// get the actual column name from field name
&lt;/span&gt;                                    $term[0] = $table-&amp;gt;getColumnName($term[0]);


                                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($def[&apos;owner&apos;])) {
                                        $componentAlias = $componentAlias . &apos;.&apos; . $def[&apos;owner&apos;];
                                    }

                                    $tableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias);

                                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getType() === Doctrine_Query::SELECT) {
                                        &lt;span class=&quot;code-comment&quot;&gt;// build sql expression
&lt;/span&gt;                                        $term[0] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias)
                                                 . &apos;.&apos;
                                                 . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($term[0]);
                                    } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                                        &lt;span class=&quot;code-comment&quot;&gt;// build sql expression
&lt;/span&gt;                                        $term[0] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($term[0]);
                                    }
                                } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                                    $found = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
                                }
                            }

                            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $found) {
                                $term[0] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlAggregateAlias($term[0]);
                            }
                        }
                    }
                }
            }

            $str .= $term[0] . $term[1];
        }
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $str;
    }

    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function parseIdentifierReference($expr)
    {

    }

    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function parseFunctionExpression($expr)
    {
        $pos = strpos($expr, &apos;(&apos;);
        $name = substr($expr, 0, $pos);

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($name === &apos;&apos;) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;parseSubquery($expr);
        }

        $argStr = substr($expr, ($pos + 1), -1);
        $args   = array();
        &lt;span class=&quot;code-comment&quot;&gt;// parse args
&lt;/span&gt;
        foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;sqlExplode($argStr, &apos;,&apos;) as $arg) {
           $args[] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;parseClause($arg);
        }

        &lt;span class=&quot;code-comment&quot;&gt;// convert DQL function to its RDBMS specific equivalent
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;try&lt;/span&gt; {
            $expr = call_user_func_array(array($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;expression, $name), $args);
        } &lt;span class=&quot;code-keyword&quot;&gt;catch&lt;/span&gt; (Doctrine_Expression_Exception $e) {
            &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&apos;Unknown function &apos; . $name . &apos;.&apos;);
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $expr;
    }


    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function parseSubquery($subquery)
    {
        $trimmed = trim($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;bracketTrim($subquery));

        &lt;span class=&quot;code-comment&quot;&gt;// check &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; possible subqueries
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (substr($trimmed, 0, 4) == &apos;FROM&apos; || substr($trimmed, 0, 6) == &apos;SELECT&apos;) {
            &lt;span class=&quot;code-comment&quot;&gt;// parse subquery
&lt;/span&gt;            $q = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;createSubquery()-&amp;gt;parseDqlQuery($trimmed);
            $trimmed = $q-&amp;gt;getSqlQuery();
            $q-&amp;gt;free();
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (substr($trimmed, 0, 4) == &apos;SQL:&apos;) {
            $trimmed = substr($trimmed, 4);
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            $e = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;sqlExplode($trimmed, &apos;,&apos;);

            $value = array();
            $index = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;

            foreach ($e as $part) {
                $value[] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;parseClause($part);
            }

            $trimmed = implode(&apos;, &apos;, $value);
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &apos;(&apos; . $trimmed . &apos;)&apos;;
    }


    /**
     * processPendingSubqueries
     * processes pending subqueries
     *
     * subqueries can only be processed when the query is fully constructed
     * since some subqueries may be correlated
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; void
     * @todo Better description. i.e. What is a &apos;pending subquery&apos;? What does &apos;processed&apos; mean?
     *       (parsed? sql is constructed? some information is gathered?)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function processPendingSubqueries()
    {
        foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingSubqueries as $value) {
            list($dql, $alias) = $value;

            $subquery = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;createSubquery();

            $sql = $subquery-&amp;gt;parseDqlQuery($dql, &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;)-&amp;gt;getQuery();
            $subquery-&amp;gt;free();

            reset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents);
            $componentAlias = key($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents);
            $tableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias);

            $sqlAlias = $tableAlias . &apos;__&apos; . count($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap);

            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;select&apos;][] = &apos;(&apos; . $sql . &apos;) AS &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($sqlAlias);

            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap[$alias] = $sqlAlias;
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;agg&apos;][] = $alias;
        }
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingSubqueries = array();
    }

    /**
     * processPendingAggregates
     * processes pending aggregate values &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; given component alias
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; void
     * @todo Better description. i.e. What is a &apos;pending aggregate&apos;? What does &apos;processed&apos; mean?
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function processPendingAggregates()
    {
        &lt;span class=&quot;code-comment&quot;&gt;// iterate trhough all aggregates
&lt;/span&gt;        foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingAggregates as $aggregate) {
            list ($expression, $components, $alias) = $aggregate;

            $tableAliases = array();

            &lt;span class=&quot;code-comment&quot;&gt;// iterate through the component references within the aggregate function
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty ($components)) {
                foreach ($components as $component) {

                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (is_numeric($component)) {
                        &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
                    }

                    $e = explode(&apos;.&apos;, $component);

                    $field = array_pop($e);
                    $componentAlias = implode(&apos;.&apos;, $e);

                    &lt;span class=&quot;code-comment&quot;&gt;// check the existence of the component alias
&lt;/span&gt;                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias])) {
                        &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&apos;Unknown component alias &apos; . $componentAlias);
                    }

                    $table = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;table&apos;];

                    $field = $table-&amp;gt;getColumnName($field);

                    &lt;span class=&quot;code-comment&quot;&gt;// check column existence
&lt;/span&gt;                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $table-&amp;gt;hasColumn($field)) {
                        &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&apos;Unknown column &apos; . $field);
                    }

                    $sqlTableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias);

                    $tableAliases[$sqlTableAlias] = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;

                    &lt;span class=&quot;code-comment&quot;&gt;// build sql expression
&lt;/span&gt;
                    $identifier = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($sqlTableAlias . &apos;.&apos; . $field);
                    $expression = str_replace($component, $identifier, $expression);
                }
            }

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($tableAliases) !== 1) {
                $componentAlias = reset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tableAliasMap);
                $tableAlias = key($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tableAliasMap);
            }

            $index    = count($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap);
            $sqlAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias . &apos;__&apos; . $index);

            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;select&apos;][] = $expression . &apos; AS &apos; . $sqlAlias;

            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap[$alias] = $sqlAlias;
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_expressionMap[$alias][0] = $expression;

            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;agg&apos;][$index] = $alias;

            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_neededTables[] = $tableAlias;
        }
        &lt;span class=&quot;code-comment&quot;&gt;// reset the state
&lt;/span&gt;        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingAggregates = array();
    }

    /**
     * _buildSqlQueryBase
     * returns the base of the generated sql query
     * On mysql driver special strategy has to be used &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; DELETE statements
     * (where is &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; special strategy??)
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string       the base of the generated sql query
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; function _buildSqlQueryBase()
    {
        &lt;span class=&quot;code-keyword&quot;&gt;switch&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_type) {
            &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; self::DELETE:
                $q = &apos;DELETE FROM &apos;;
            &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
            &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; self::UPDATE:
                $q = &apos;UPDATE &apos;;
            &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
            &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; self::SELECT:
                $distinct = ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;distinct&apos;]) ? &apos;DISTINCT &apos; : &apos;&apos;;
                $q = &apos;SELECT &apos; . $distinct . implode(&apos;, &apos;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;select&apos;]) . &apos; FROM &apos;;
            &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
        }
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $q;
    }

    /**
     * _buildSqlFromPart
     * builds the from part of the query and returns it
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string   the query sql from part
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; function _buildSqlFromPart($ignorePending = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;)
    {
        $q = &apos;&apos;;

        foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;from&apos;] as $k =&amp;gt; $part) {
            $e = explode(&apos; &apos;, $part);

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($k === 0) {
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $ignorePending &amp;amp;&amp;amp; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_type == self::SELECT) {
                    &lt;span class=&quot;code-comment&quot;&gt;// We may still have pending conditions
&lt;/span&gt;                    $alias = count($e) &amp;gt; 1
                        ? $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getComponentAlias($e[1])
                        : &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;;
                    $where = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_processPendingJoinConditions($alias);

                    &lt;span class=&quot;code-comment&quot;&gt;// apply inheritance to WHERE part
&lt;/span&gt;                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($where)) {
                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;]) &amp;gt; 0) {
                            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;][] = &apos;AND&apos;;
                        }

                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (substr($where, 0, 1) === &apos;(&apos; &amp;amp;&amp;amp; substr($where, -1) === &apos;)&apos;) {
                            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;][] = $where;
                        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;][] = &apos;(&apos; . $where . &apos;)&apos;;
                        }
                    }
                }

                $q .= $part;

                &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
            }

            &lt;span class=&quot;code-comment&quot;&gt;// preserve LEFT JOINs only &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; needed
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;// Check &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; it&apos;s JOIN, &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; not add a comma separator instead of space
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! preg_match(&apos;/\bJOIN\b/i&apos;, $part) &amp;amp;&amp;amp; ! isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingJoinConditions[$k])) {
                $q .= &apos;, &apos; . $part;
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (substr($part, 0, 9) === &apos;LEFT JOIN&apos;) {
                    $aliases = array_merge($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_subqueryAliases,
                                array_keys($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_neededTables));

                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! in_array($e[3], $aliases) &amp;amp;&amp;amp; ! in_array($e[2], $aliases) &amp;amp;&amp;amp; ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingFields)) {
                        &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
                    }

                }

                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $ignorePending &amp;amp;&amp;amp; isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingJoinConditions[$k])) {
                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($part, &apos; ON &apos;) !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                        $part .= &apos; AND &apos;;
                    } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                        $part .= &apos; ON &apos;;
                    }

                    $part .= $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_processPendingJoinConditions($k);
                }

                $componentAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getComponentAlias($e[3]);
                $string = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getInheritanceCondition($componentAlias);

                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($string) {
                    $part = $part . &apos; AND &apos; . $string;
                }
                $q .= &apos; &apos; . $part;
            }

            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;from&apos;][$k] = $part;
        }
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $q;
    }

    /**
     * Processes the pending join conditions, used &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; dynamically add conditions
     * to root component/joined components without interfering in the main dql
     * handling.
     *
     * @param string $alias Component Alias
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; Processed pending conditions
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; function _processPendingJoinConditions($alias)
    {
        $parts = array();

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($alias !== &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt; &amp;amp;&amp;amp; isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingJoinConditions[$alias])) {
            $parser = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_JoinCondition($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer);

            foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingJoinConditions[$alias] as $joinCondition) {
                $parts[] = $parser-&amp;gt;parse($joinCondition);
            }

            &lt;span class=&quot;code-comment&quot;&gt;// FIX #1860 and #1876: Cannot unset them, otherwise query cannot be reused later
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;//unset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingJoinConditions[$alias]);
&lt;/span&gt;        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; (count($parts) &amp;gt; 0 ? &apos;(&apos; . implode(&apos;) AND (&apos;, $parts) . &apos;)&apos; : &apos;&apos;);
    }

    /**
     * builds the sql query from the given parameters and applies things such as
     * column aggregation inheritance and limit subqueries &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; needed
     *
     * @param array $params             an array of prepared statement params (needed only in mysql driver
     *                                  when limit subquery algorithm is used)
     * @param bool $limitSubquery Whether or not to &lt;span class=&quot;code-keyword&quot;&gt;try&lt;/span&gt; and apply the limit subquery algorithm
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string                   the built sql query
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getSqlQuery($params = array(), $limitSubquery = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;)
    {
        &lt;span class=&quot;code-comment&quot;&gt;// Assign building/execution specific params
&lt;/span&gt;        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_params[&apos;exec&apos;] = $params;

        &lt;span class=&quot;code-comment&quot;&gt;// Initialize prepared parameters array
&lt;/span&gt;        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_execParams = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getFlattenedParams();

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_state !== self::STATE_DIRTY) {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;fixArrayParameterValues($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getInternalParams());

            &lt;span class=&quot;code-comment&quot;&gt;// Return compiled SQL
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sql;
        }
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;buildSqlQuery($limitSubquery);
    }

    /**
     * Build the SQL query from the DQL
     *
     * @param bool $limitSubquery Whether or not to &lt;span class=&quot;code-keyword&quot;&gt;try&lt;/span&gt; and apply the limit subquery algorithm
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string $sql The generated SQL string
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function buildSqlQuery($limitSubquery = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;)
    {
        &lt;span class=&quot;code-comment&quot;&gt;// reset the state
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;isSubquery()) {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents = array();
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingAggregates = array();
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap = array();
        }

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;reset();

        &lt;span class=&quot;code-comment&quot;&gt;// invoke the preQuery hook
&lt;/span&gt;        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_preQuery();

        &lt;span class=&quot;code-comment&quot;&gt;// process the DQL parts =&amp;gt; generate the SQL parts.
&lt;/span&gt;        &lt;span class=&quot;code-comment&quot;&gt;// &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; will also populate the $_queryComponents.
&lt;/span&gt;        foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_dqlParts as $queryPartName =&amp;gt; $queryParts) {
            &lt;span class=&quot;code-comment&quot;&gt;// If we are parsing FROM clause, we&apos;ll need to diff the queryComponents later
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($queryPartName == &apos;from&apos;) {
                &lt;span class=&quot;code-comment&quot;&gt;// Pick queryComponents before processing
&lt;/span&gt;                $queryComponentsBefore = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getQueryComponents();
            }

            &lt;span class=&quot;code-comment&quot;&gt;// FIX #1667: _sqlParts are cleaned inside _processDqlQueryPart.
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($queryPartName != &apos;forUpdate&apos;) {
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_processDqlQueryPart($queryPartName, $queryParts);
            }

            &lt;span class=&quot;code-comment&quot;&gt;// We need to define the root alias
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($queryPartName == &apos;from&apos;) {
                &lt;span class=&quot;code-comment&quot;&gt;// Pick queryComponents aftr processing
&lt;/span&gt;                $queryComponentsAfter = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getQueryComponents();

                &lt;span class=&quot;code-comment&quot;&gt;// Root alias is the key of difference of query components
&lt;/span&gt;                $diffQueryComponents = array_diff_key($queryComponentsAfter, $queryComponentsBefore);
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_rootAlias = key($diffQueryComponents);
            }
        }
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_state = self::STATE_CLEAN;

        &lt;span class=&quot;code-comment&quot;&gt;// Proceed with the generated SQL
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;from&apos;])) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
        }

        $needsSubQuery = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
        $subquery = &apos;&apos;;
        $map = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootDeclaration();
        $table = $map[&apos;table&apos;];
        $rootAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootAlias();

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;limit&apos;]) &amp;amp;&amp;amp; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_needsSubquery &amp;amp;&amp;amp;
                $table-&amp;gt;getAttribute(Doctrine_Core::ATTR_QUERY_LIMIT) == Doctrine_Core::LIMIT_RECORDS) {
            &lt;span class=&quot;code-comment&quot;&gt;// We &lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt; not need a limit-subquery &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; DISTINCT is used
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;// and the selected fields are either from the root component or from a localKey relation (hasOne)
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;// (i.e. DQL: SELECT DISTINCT u.id FROM User u LEFT JOIN u.phonenumbers LIMIT 5).
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt;(!$&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;distinct&apos;]) {
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_isLimitSubqueryUsed = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;
                $needsSubQuery = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                foreach( array_keys($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingFields) as $alias){
                    &lt;span class=&quot;code-comment&quot;&gt;//no subquery &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; root fields
&lt;/span&gt;                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt;($alias == $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootAlias()){
                        &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
                    }

                    &lt;span class=&quot;code-comment&quot;&gt;//no subquery &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; ONE relations
&lt;/span&gt;                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt;(isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$alias][&apos;relation&apos;]) &amp;amp;&amp;amp;
                        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$alias][&apos;relation&apos;]-&amp;gt;getType() == Doctrine_Relation::ONE){
                        &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
                    }

                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_isLimitSubqueryUsed = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;
                    $needsSubQuery = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;
                }
            }
        }

        $sql = array();

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingFields)) {
            foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents as $alias =&amp;gt; $map) {
                $fieldSql = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;processPendingFields($alias);
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($fieldSql)) {
                    $sql[] = $fieldSql;
                }
            }
        }

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($sql)) {
            array_unshift($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;select&apos;], implode(&apos;, &apos;, $sql));
        }

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingFields = array();

        &lt;span class=&quot;code-comment&quot;&gt;// build the basic query
&lt;/span&gt;        $q  = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_buildSqlQueryBase();
        $q .= $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_buildSqlFromPart();

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;set&apos;])) {
            $q .= &apos; SET &apos; . implode(&apos;, &apos;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;set&apos;]);
        }

        $string = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getInheritanceCondition($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootAlias());

        &lt;span class=&quot;code-comment&quot;&gt;// apply inheritance to WHERE part
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($string)) {
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;]) &amp;gt; 0) {
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;][] = &apos;AND&apos;;
            }

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (substr($string, 0, 1) === &apos;(&apos; &amp;amp;&amp;amp; substr($string, -1) === &apos;)&apos;) {
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;][] = $string;
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;][] = &apos;(&apos; . $string . &apos;)&apos;;
            }
        }

        $modifyLimit = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;
        $limitSubquerySql = &apos;&apos;;

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ( ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;limit&apos;]) || ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;offset&apos;])) &amp;amp;&amp;amp; $needsSubQuery &amp;amp;&amp;amp; $limitSubquery) {
            $subquery = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getLimitSubquery();

            &lt;span class=&quot;code-comment&quot;&gt;// what about composite keys?
&lt;/span&gt;            $idColumnName = $table-&amp;gt;getColumnName($table-&amp;gt;getIdentifier());

            &lt;span class=&quot;code-keyword&quot;&gt;switch&lt;/span&gt; (strtolower($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;getDriverName())) {
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;mysql&apos;:
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;useQueryCache(&lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;);

                    &lt;span class=&quot;code-comment&quot;&gt;// mysql doesn&apos;t support LIMIT in subqueries
&lt;/span&gt;                    $list = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;execute($subquery, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_execParams)-&amp;gt;fetchAll(Doctrine_Core::FETCH_COLUMN);
                    $subquery = implode(&apos;, &apos;, array_map(array($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn, &apos;quote&apos;), $list));

                    &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;

                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;pgsql&apos;:
                    $subqueryAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier(&apos;doctrine_subquery_alias&apos;);

                    &lt;span class=&quot;code-comment&quot;&gt;// pgsql needs special nested LIMIT subquery
&lt;/span&gt;                    $subquery = &apos;SELECT &apos; . $subqueryAlias . &apos;.&apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($idColumnName)
                            . &apos; FROM (&apos; . $subquery . &apos;) AS &apos; . $subqueryAlias;

                    &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
            }

            $field = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($rootAlias) . &apos;.&apos; . $idColumnName;

            &lt;span class=&quot;code-comment&quot;&gt;// FIX #1868: If not ID under MySQL is found to be restricted, restrict pk column &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;//            (which will lead to a &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; of 0 items)
&lt;/span&gt;            $limitSubquerySql = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($field)
                              . (( ! empty($subquery)) ? &apos; IN (&apos; . $subquery . &apos;)&apos; : &apos; IS NULL&apos;)
                              . ((count($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;]) &amp;gt; 0) ? &apos; AND &apos; : &apos;&apos;);

            $modifyLimit = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
        }

        &lt;span class=&quot;code-comment&quot;&gt;// FIX #DC-26: Include limitSubquerySql as major relevance in conditions
&lt;/span&gt;        $emptyWhere = empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;]);

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! ($emptyWhere &amp;amp;&amp;amp; $limitSubquerySql == &apos;&apos;)) {
            $where = implode(&apos; &apos;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;]);
            $where = ($where == &apos;&apos; || (substr($where, 0, 1) === &apos;(&apos; &amp;amp;&amp;amp; substr($where, -1) === &apos;)&apos;))
                ? $where : &apos;(&apos; . $where . &apos;)&apos;;

            $q .= &apos; WHERE &apos; . $limitSubquerySql . $where;
            &lt;span class=&quot;code-comment&quot;&gt;//   .  (($limitSubquerySql == &apos;&apos; &amp;amp;&amp;amp; count($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;]) == 1) ? substr($where, 1, -1) : $where);
&lt;/span&gt;        }

        &lt;span class=&quot;code-comment&quot;&gt;// Fix the orderbys so we only have one orderby per value
&lt;/span&gt;        foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;] as $k =&amp;gt; $orderBy) {
            $e = explode(&apos;, &apos;, $orderBy);
            unset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;][$k]);
            foreach ($e as $v) {
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;][] = $v;
            }
        }

        &lt;span class=&quot;code-comment&quot;&gt;// Add the &lt;span class=&quot;code-keyword&quot;&gt;default&lt;/span&gt; orderBy statements defined in the relationships and table classes
&lt;/span&gt;        &lt;span class=&quot;code-comment&quot;&gt;// Only &lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; SELECT queries
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_type === self::SELECT) {
            foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents as $alias =&amp;gt; $map) {
                $sqlAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($alias);
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($map[&apos;relation&apos;])) {
                    $orderBy = $map[&apos;relation&apos;]-&amp;gt;getOrderByStatement($sqlAlias, &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;);
                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($orderBy == $map[&apos;relation&apos;][&apos;orderBy&apos;]) {
                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($map[&apos;ref&apos;])) {
                            $orderBy = $map[&apos;relation&apos;][&apos;refTable&apos;]-&amp;gt;processOrderBy($sqlAlias, $map[&apos;relation&apos;][&apos;orderBy&apos;], &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;);
                        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                            $orderBy = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;;
                        }
                    }
				} &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
					$orderBy = $map[&apos;table&apos;]-&amp;gt;getOrderByStatement($sqlAlias, &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;);
				}

                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($orderBy) {
                    $e = explode(&apos;,&apos;, $orderBy);
                    $e = array_map(&apos;trim&apos;, $e);
                    foreach ($e as $v) {
                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! in_array($v, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;])) {
                            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;][] = $v;
                        }
                    }
                }
            }
        }

        $q .= ( ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;groupby&apos;])) ? &apos; GROUP BY &apos; . implode(&apos;, &apos;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;groupby&apos;])  : &apos;&apos;;
        $q .= ( ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;having&apos;])) ?  &apos; HAVING &apos;   . implode(&apos; AND &apos;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;having&apos;]): &apos;&apos;;
        $q .= ( ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;])) ? &apos; ORDER BY &apos; . implode(&apos;, &apos;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;])  : &apos;&apos;;

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($modifyLimit) {
            $q = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;modifyLimitQuery($q, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;limit&apos;], $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;offset&apos;]);
        }

        $q .= $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;forUpdate&apos;] === &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt; ? &apos; FOR UPDATE &apos; : &apos;&apos;;

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sql = $q;

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;clear();

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $q;
    }

    /**
     * getLimitSubquery
     * &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; is method is used by the record limit algorithm
     *
     * when fetching one-to-many, many-to-many associated data with LIMIT clause
     * an additional subquery is needed &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; limiting the number of returned records instead
     * of limiting the number of sql result set rows
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string       the limit subquery
     * @todo A little refactor to make the method easier to understand &amp;amp; maybe shorter?
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getLimitSubquery()
    {
        $map = reset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents);
        $table = $map[&apos;table&apos;];
        $componentAlias = key($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents);

        &lt;span class=&quot;code-comment&quot;&gt;// get &lt;span class=&quot;code-object&quot;&gt;short&lt;/span&gt; alias
&lt;/span&gt;        $alias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias);
        &lt;span class=&quot;code-comment&quot;&gt;// what about composite keys?
&lt;/span&gt;        $primaryKey = $alias . &apos;.&apos; . $table-&amp;gt;getColumnName($table-&amp;gt;getIdentifier());

        $driverName = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;getAttribute(Doctrine_Core::ATTR_DRIVER_NAME);

        &lt;span class=&quot;code-comment&quot;&gt;// initialize the base of the subquery
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (($driverName == &apos;oracle&apos; || $driverName == &apos;oci&apos;) &amp;amp;&amp;amp; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_isOrderedByJoinedColumn()) {
            $subquery = &apos;SELECT &apos;;
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            $subquery = &apos;SELECT DISTINCT &apos;;
        }
        $subquery .= $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($primaryKey);

        &lt;span class=&quot;code-comment&quot;&gt;// pgsql &amp;amp; oracle need the order by fields to be preserved in select clause
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($driverName == &apos;pgsql&apos; || $driverName == &apos;oracle&apos; || $driverName == &apos;oci&apos; || $driverName == &apos;mssql&apos; || $driverName == &apos;odbc&apos;) {
            foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;] as $part) {
                &lt;span class=&quot;code-comment&quot;&gt;// Remove identifier quoting &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; it exists
&lt;/span&gt;                $e = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;bracketExplode($part, &apos; &apos;);
                foreach ($e as $f) {
                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($f == 0 || $f % 2 == 0) {
                        $partOriginal = str_replace(&apos;,&apos;, &apos;&apos;, trim($f));
                        $callback = create_function(&apos;$e&apos;, &apos;&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; trim($e, \&apos;[]`&quot;\&apos;);&apos;);
                        $part = trim(implode(&apos;.&apos;, array_map($callback, explode(&apos;.&apos;, $partOriginal))));
                
                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($part, &apos;.&apos;) === &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                            &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
                        }
                
                        &lt;span class=&quot;code-comment&quot;&gt;// don&apos;t add functions
&lt;/span&gt;                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($part, &apos;(&apos;) !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                            &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
                        }
                
                        &lt;span class=&quot;code-comment&quot;&gt;// don&apos;t add primarykey column (its already in the select clause)
&lt;/span&gt;                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($part !== $primaryKey) {
                            $subquery .= &apos;, &apos; . $partOriginal;
                        }
                    }
                }
            }
        }

        $orderby = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;];
        $having = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;having&apos;];
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($driverName == &apos;mysql&apos; || $driverName == &apos;pgsql&apos;) {
            foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_expressionMap as $dqlAlias =&amp;gt; $expr) {
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($expr[1])) {
                    $subquery .= &apos;, &apos; . $expr[0] . &apos; AS &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap[$dqlAlias];
                }
            }
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_expressionMap as $dqlAlias =&amp;gt; $expr) {
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($expr[1])) {
                    foreach ($having as $k =&amp;gt; $v) {
                        $having[$k] = str_replace($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap[$dqlAlias], $expr[0], $v);
                    }
                    foreach ($orderby as $k =&amp;gt; $v) {
                        $e = explode(&apos; &apos;, $v);
                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($e[0] == $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_aggregateAliasMap[$dqlAlias]) {
                            $orderby[$k] = $expr[0];
                        }
                    }
                }
            }
        }

        &lt;span class=&quot;code-comment&quot;&gt;// Add having fields that got stripped out of select
&lt;/span&gt;        preg_match_all(&apos;/`[a-z0-9_]+`\.`[a-z0-9_]+`/i&apos;, implode(&apos; &apos;, $having), $matches, PREG_PATTERN_ORDER);
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($matches[0]) &amp;gt; 0) {
            $subquery .= &apos;, &apos; . implode(&apos;, &apos;, array_unique($matches[0]));
        }

        $subquery .= &apos; FROM&apos;;

        foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;from&apos;] as $part) {
            &lt;span class=&quot;code-comment&quot;&gt;// preserve LEFT JOINs only &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; needed
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (substr($part, 0, 9) === &apos;LEFT JOIN&apos;) {
                $e = explode(&apos; &apos;, $part);
			&lt;span class=&quot;code-comment&quot;&gt;//Patched by Will Ferrer to also check &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; groupBys. Fixes Bug -- DC-594
&lt;/span&gt;                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;]) &amp;amp;&amp;amp; empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;]) &amp;amp;&amp;amp; empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;having&apos;]) &amp;amp;&amp;amp; empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;groupby&apos;])) {
             &lt;span class=&quot;code-comment&quot;&gt;//End Patch
&lt;/span&gt;				   &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
                }
            }

            $subquery .= &apos; &apos; . $part;
        }

        &lt;span class=&quot;code-comment&quot;&gt;// all conditions must be preserved in subquery
&lt;/span&gt;        $subquery .= ( ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;]))?   &apos; WHERE &apos;    . implode(&apos; &apos;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;])  : &apos;&apos;;
        $subquery .= ( ! empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;groupby&apos;]))? &apos; GROUP BY &apos; . implode(&apos;, &apos;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;groupby&apos;])   : &apos;&apos;;
        $subquery .= ( ! empty($having))?  &apos; HAVING &apos;   . implode(&apos; AND &apos;, $having) : &apos;&apos;;
        $subquery .= ( ! empty($orderby))? &apos; ORDER BY &apos; . implode(&apos;, &apos;, $orderby)  : &apos;&apos;;

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (($driverName == &apos;oracle&apos; || $driverName == &apos;oci&apos;) &amp;amp;&amp;amp; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_isOrderedByJoinedColumn()) {
            &lt;span class=&quot;code-comment&quot;&gt;// When using &lt;span class=&quot;code-quote&quot;&gt;&quot;ORDER BY x.foo&quot;&lt;/span&gt; where x.foo is a column of a joined table,
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;// we may get duplicate primary keys because all columns in ORDER BY must appear
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;// in the SELECT list when using DISTINCT. Hence we need to filter out the
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;// primary keys with an additional DISTINCT subquery.
&lt;/span&gt;            &lt;span class=&quot;code-comment&quot;&gt;// #1038
&lt;/span&gt;            $quotedIdentifierColumnName = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($table-&amp;gt;getColumnName($table-&amp;gt;getIdentifier()));
            $subquery = &apos;SELECT doctrine_subquery_alias.&apos; . $quotedIdentifierColumnName
                    . &apos; FROM (&apos; . $subquery . &apos;) doctrine_subquery_alias&apos;
                    . &apos; GROUP BY doctrine_subquery_alias.&apos; . $quotedIdentifierColumnName
                    . &apos; ORDER BY MIN(ROWNUM)&apos;;
        }

        &lt;span class=&quot;code-comment&quot;&gt;// add driver specific limit clause
&lt;/span&gt;        $subquery = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;modifyLimitSubquery($table, $subquery, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;limit&apos;], $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;offset&apos;]);

        $parts = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;quoteExplode($subquery, &apos; &apos;, &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&quot;&lt;/span&gt;, &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&quot;&lt;/span&gt;);

        foreach ($parts as $k =&amp;gt; $part) {
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($part, &apos; &apos;) !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
            }

            $part = str_replace(array(&apos;&lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;, &quot;&lt;/span&gt;&apos;&lt;span class=&quot;code-quote&quot;&gt;&quot;, &apos;`&apos;), &quot;&lt;/span&gt;&quot;, $part);

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;hasSqlTableAlias($part)) {
                $parts[$k] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;generateNewSqlTableAlias($part));
                &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
            }

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($part, &apos;.&apos;) === &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
            }

            preg_match_all(&lt;span class=&quot;code-quote&quot;&gt;&quot;/[a-zA-Z0-9_]+\.[a-z0-9_]+/i&quot;&lt;/span&gt;, $part, $m);

            foreach ($m[0] as $match) {
                $e = explode(&apos;.&apos;, $match);

                &lt;span class=&quot;code-comment&quot;&gt;// Rebuild the original part without the newly generate alias and with quoting reapplied
&lt;/span&gt;                $e2 = array();
                foreach ($e as $k2 =&amp;gt; $v2) {
                  $e2[$k2] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($v2);
                }
                $match = implode(&apos;.&apos;, $e2);

                &lt;span class=&quot;code-comment&quot;&gt;// Generate &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; table alias
&lt;/span&gt;                $e[0] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;generateNewSqlTableAlias($e[0]);

                &lt;span class=&quot;code-comment&quot;&gt;// Requote the part with the newly generated alias
&lt;/span&gt;                foreach ($e as $k2 =&amp;gt; $v2) {
                  $e[$k2] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($v2);
                }

                $replace = implode(&apos;.&apos; , $e);

                &lt;span class=&quot;code-comment&quot;&gt;// Replace the original part with the &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; part with &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; sql table alias
&lt;/span&gt;                $parts[$k] = str_replace($match, $replace, $parts[$k]);
            }
        }

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($driverName == &apos;mysql&apos; || $driverName == &apos;pgsql&apos;) {
            foreach ($parts as $k =&amp;gt; $part) {
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($part, &lt;span class=&quot;code-quote&quot;&gt;&quot;&apos;&quot;&lt;/span&gt;) !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                    &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
                }
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($part, &apos;__&apos;) == &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                    &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
                }

                preg_match_all(&lt;span class=&quot;code-quote&quot;&gt;&quot;/[a-zA-Z0-9_]+\_\_[a-z0-9_]+/i&quot;&lt;/span&gt;, $part, $m);

                foreach ($m[0] as $match) {
                    $e = explode(&apos;__&apos;, $match);
                    $e[0] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;generateNewSqlTableAlias($e[0]);

                    $parts[$k] = str_replace($match, implode(&apos;__&apos;, $e), $parts[$k]);
                }
            }
        }

        $subquery = implode(&apos; &apos;, $parts);
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $subquery;
    }

    /**
     * Checks whether the query has an ORDER BY on a column of a joined table.
     * This information is needed in special scenarios like the limit-offset when its
     * used with an Oracle database.
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt;  TRUE &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; the query is ordered by a joined column, FALSE otherwise.
     */
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; function _isOrderedByJoinedColumn() {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents) {
            &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&lt;span class=&quot;code-quote&quot;&gt;&quot;The query is in an invalid state &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; &quot;&lt;/span&gt;
                    . &lt;span class=&quot;code-quote&quot;&gt;&quot;operation. It must have been fully parsed first.&quot;&lt;/span&gt;);
        }
        $componentAlias = key($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents);
        $mainTableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias);
        foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;] as $part) {
            $part = trim($part);
            $e = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;bracketExplode($part, &apos; &apos;);
            $part = trim($e[0]);
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($part, &apos;.&apos;) === &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                &lt;span class=&quot;code-keyword&quot;&gt;continue&lt;/span&gt;;
            }
            list($tableAlias, $columnName) = explode(&apos;.&apos;, $part);
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($tableAlias != $mainTableAlias) {
                &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;return&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
    }

    /**
     * DQL PARSER
     * parses a DQL query
     * first splits the query in parts and then uses individual
     * parsers &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; each part
     *
     * @param string $query                 DQL query
     * @param &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt; $clear                whether or not to clear the aliases
     * @&lt;span class=&quot;code-keyword&quot;&gt;throws&lt;/span&gt; Doctrine_Query_Exception     &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; some &lt;span class=&quot;code-keyword&quot;&gt;generic&lt;/span&gt; parsing error occurs
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; Doctrine_Query
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function parseDqlQuery($query, $clear = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($clear) {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;clear();
        }

        $query = trim($query);
        $query = str_replace(&lt;span class=&quot;code-quote&quot;&gt;&quot;\r&quot;&lt;/span&gt;, &lt;span class=&quot;code-quote&quot;&gt;&quot;\n&quot;&lt;/span&gt;, str_replace(&lt;span class=&quot;code-quote&quot;&gt;&quot;\r\n&quot;&lt;/span&gt;, &lt;span class=&quot;code-quote&quot;&gt;&quot;\n&quot;&lt;/span&gt;, $query));
        $query = str_replace(&lt;span class=&quot;code-quote&quot;&gt;&quot;\n&quot;&lt;/span&gt;, &apos; &apos;, $query);

        $parts = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;tokenizeQuery($query);

        foreach ($parts as $partName =&amp;gt; $subParts) {
            $subParts = trim($subParts);
            $partName = strtolower($partName);
            &lt;span class=&quot;code-keyword&quot;&gt;switch&lt;/span&gt; ($partName) {
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;create&apos;:
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_type = self::CREATE;
                &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;insert&apos;:
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_type = self::INSERT;
                &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;delete&apos;:
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_type = self::DELETE;
                &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;select&apos;:
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_type = self::SELECT;
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_addDqlQueryPart($partName, $subParts);
                &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;update&apos;:
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_type = self::UPDATE;
                    $partName = &apos;from&apos;;
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;from&apos;:
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_addDqlQueryPart($partName, $subParts);
                &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;set&apos;:
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_addDqlQueryPart($partName, $subParts, &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;);
                &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;group&apos;:
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;order&apos;:
                    $partName .= &apos;by&apos;;
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;where&apos;:
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;having&apos;:
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;limit&apos;:
                &lt;span class=&quot;code-keyword&quot;&gt;case&lt;/span&gt; &apos;offset&apos;:
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_addDqlQueryPart($partName, $subParts);
                &lt;span class=&quot;code-keyword&quot;&gt;break&lt;/span&gt;;
            }
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;;
    }

    /**
     * @todo Describe &amp;amp; refactor... too &lt;span class=&quot;code-object&quot;&gt;long&lt;/span&gt; and nested.
     * @param string $path          component alias
     * @param &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt; $loadFields
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function load($path, $loadFields = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$path])) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$path];
        }

        $e = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tokenizer-&amp;gt;quoteExplode($path, &apos; INDEXBY &apos;);

        $mapWith = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;;
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($e) &amp;gt; 1) {
            $mapWith = trim($e[1]);

            $path = $e[0];
        }

        &lt;span class=&quot;code-comment&quot;&gt;// parse custom join conditions
&lt;/span&gt;        $e = explode(&apos; ON &apos;, str_ireplace(&apos; on &apos;, &apos; ON &apos;, $path));

        $joinCondition = &apos;&apos;;

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($e) &amp;gt; 1) {
            $joinCondition = substr($path, strlen($e[0]) + 4, strlen($e[1]));
            $path = substr($path, 0, strlen($e[0]));

            $overrideJoin = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            $e = explode(&apos; WITH &apos;, str_ireplace(&apos; with &apos;, &apos; WITH &apos;, $path));

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($e) &amp;gt; 1) {
                $joinCondition = substr($path, strlen($e[0]) + 6, strlen($e[1]));
                $path = substr($path, 0, strlen($e[0]));
            }

            $overrideJoin = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;
        }

        $tmp            = explode(&apos; &apos;, $path);
        $componentAlias = $originalAlias = (count($tmp) &amp;gt; 1) ? end($tmp) : &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;;

        $e = preg_split(&lt;span class=&quot;code-quote&quot;&gt;&quot;/[.:]/&quot;&lt;/span&gt;, $tmp[0], -1);

        $fullPath = $tmp[0];
        $prevPath = &apos;&apos;;
        $fullLength = strlen($fullPath);

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$e[0]])) {
            $table = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$e[0]][&apos;table&apos;];
            $componentAlias = $e[0];

            $prevPath = $parent = array_shift($e);
        }

        foreach ($e as $key =&amp;gt; $name) {
            &lt;span class=&quot;code-comment&quot;&gt;// get length of the previous path
&lt;/span&gt;            $length = strlen($prevPath);

            &lt;span class=&quot;code-comment&quot;&gt;// build the current component path
&lt;/span&gt;            $prevPath = ($prevPath) ? $prevPath . &apos;.&apos; . $name : $name;

            $delimeter = substr($fullPath, $length, 1);

            &lt;span class=&quot;code-comment&quot;&gt;// &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; an alias is not given use the current path as an alias identifier
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strlen($prevPath) === $fullLength &amp;amp;&amp;amp; isset($originalAlias)) {
                $componentAlias = $originalAlias;
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                $componentAlias = $prevPath;
            }

            &lt;span class=&quot;code-comment&quot;&gt;// &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; the current alias already exists, skip it
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias])) {
                &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&lt;span class=&quot;code-quote&quot;&gt;&quot;Duplicate alias &apos;$componentAlias&apos; in query.&quot;&lt;/span&gt;);
            }

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! isset($table)) {
                &lt;span class=&quot;code-comment&quot;&gt;// process the root of the path
&lt;/span&gt;
                $table = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;loadRoot($name, $componentAlias);
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                $join = ($delimeter == &apos;:&apos;) ? &apos;INNER JOIN &apos; : &apos;LEFT JOIN &apos;;

                $relation = $table-&amp;gt;getRelation($name);
                $localTable = $table;

                $table = $relation-&amp;gt;getTable();
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias] = array(&apos;table&apos; =&amp;gt; $table,
                                                                 &apos;parent&apos;   =&amp;gt; $parent,
                                                                 &apos;relation&apos; =&amp;gt; $relation,
                                                                 &apos;map&apos;      =&amp;gt; &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;);
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $relation-&amp;gt;isOneToOne()) {
                   $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_needsSubquery = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;
                }

                $localAlias   = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($parent, $localTable-&amp;gt;getTableName());
                $foreignAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias, $relation-&amp;gt;getTable()-&amp;gt;getTableName());

                $foreignSql   = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($relation-&amp;gt;getTable()-&amp;gt;getTableName())
                              . &apos; &apos;
                              . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($foreignAlias);

                $map = $relation-&amp;gt;getTable()-&amp;gt;inheritanceMap;

                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $loadFields || ! empty($map) || $joinCondition) {
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_subqueryAliases[] = $foreignAlias;
                }

                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($relation &lt;span class=&quot;code-keyword&quot;&gt;instanceof&lt;/span&gt; Doctrine_Relation_Association) {
                    $asf = $relation-&amp;gt;getAssociationTable();

                    $assocTableName = $asf-&amp;gt;getTableName();

                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $loadFields || ! empty($map) || $joinCondition) {
                        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_subqueryAliases[] = $assocTableName;
                    }

                    $assocPath = $prevPath . &apos;.&apos; . $asf-&amp;gt;getComponentName() . &apos; &apos; . $componentAlias;

                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$assocPath] = array(
                        &apos;parent&apos; =&amp;gt; $prevPath,
                        &apos;relation&apos; =&amp;gt; $relation,
                        &apos;table&apos; =&amp;gt; $asf,
                        &apos;ref&apos; =&amp;gt; &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;);

                    $assocAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($assocPath, $asf-&amp;gt;getTableName());

                    $queryPart = $join
                            . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($assocTableName)
                            . &apos; &apos;
                            . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($assocAlias);

                    $queryPart .= &apos; ON (&apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($localAlias
                                . &apos;.&apos;
                                . $localTable-&amp;gt;getColumnName($localTable-&amp;gt;getIdentifier())) &lt;span class=&quot;code-comment&quot;&gt;// what about composite keys?
&lt;/span&gt;                                . &apos; = &apos;
                                . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($assocAlias . &apos;.&apos; . $relation-&amp;gt;getLocalRefColumnName());

                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($relation-&amp;gt;isEqual()) {
                        &lt;span class=&quot;code-comment&quot;&gt;// equal nest relation needs additional condition
&lt;/span&gt;                        $queryPart .= &apos; OR &apos;
                                    . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($localAlias
                                    . &apos;.&apos;
                                    . $table-&amp;gt;getColumnName($table-&amp;gt;getIdentifier()))
                                    . &apos; = &apos;
                                    . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($assocAlias . &apos;.&apos; . $relation-&amp;gt;getForeignRefColumnName());
                    }

                    $queryPart .= &apos;)&apos;;

                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;from&apos;][] = $queryPart;

                    $queryPart = $join . $foreignSql;

                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $overrideJoin) {
                        $queryPart .= $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;buildAssociativeRelationSql($relation, $assocAlias, $foreignAlias, $localAlias);
                    }
                } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                    $queryPart = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;buildSimpleRelationSql($relation, $foreignAlias, $localAlias, $overrideJoin, $join);
                }

                $queryPart .= $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;buildInheritanceJoinSql($table-&amp;gt;getComponentName(), $componentAlias);
                $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;from&apos;][$componentAlias] = $queryPart;

                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($joinCondition)) {
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;addPendingJoinCondition($componentAlias, $joinCondition);
                }
            }

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($loadFields) {
                $restoreState = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;

                &lt;span class=&quot;code-comment&quot;&gt;// load fields &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; necessary
&lt;/span&gt;                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($loadFields &amp;amp;&amp;amp; empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_dqlParts[&apos;select&apos;])) {
                    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_pendingFields[$componentAlias] = array(&apos;*&apos;);
                }
            }

            $parent = $prevPath;
        }

        $table = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;table&apos;];

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;buildIndexBy($componentAlias, $mapWith);
    }

    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; function buildSimpleRelationSql(Doctrine_Relation $relation, $foreignAlias, $localAlias, $overrideJoin, $join)
    {
        $queryPart = $join . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($relation-&amp;gt;getTable()-&amp;gt;getTableName())
                           . &apos; &apos;
                           . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($foreignAlias);

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $overrideJoin) {
            $queryPart .= &apos; ON &apos;
                       . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($localAlias . &apos;.&apos; . $relation-&amp;gt;getLocalColumnName())
                       . &apos; = &apos;
                       . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($foreignAlias . &apos;.&apos; . $relation-&amp;gt;getForeignColumnName());
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $queryPart;
    }

    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; function buildIndexBy($componentAlias, $mapWith = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;)
    {
        $table = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;table&apos;];

        $indexBy = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;;
        $column = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;;

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($mapWith)) {
            $terms = explode(&apos;.&apos;, $mapWith);

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($terms) == 1) {
                $indexBy = $terms[0];
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($terms) == 2) {
                $column = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;
                $indexBy = $terms[1];
            }
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($table-&amp;gt;getBoundQueryPart(&apos;indexBy&apos;) !== &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;) {
            $indexBy = $table-&amp;gt;getBoundQueryPart(&apos;indexBy&apos;);
        }

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($indexBy !== &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;) {
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( $column &amp;amp;&amp;amp; ! $table-&amp;gt;hasColumn($table-&amp;gt;getColumnName($indexBy))) {
                &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Query_Exception(&lt;span class=&quot;code-quote&quot;&gt;&quot;Couldn&apos;t use key mapping. Column &quot;&lt;/span&gt; . $indexBy . &lt;span class=&quot;code-quote&quot;&gt;&quot; does not exist.&quot;&lt;/span&gt;);
            }

            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias][&apos;map&apos;] = $indexBy;
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias];
    }


    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; function buildAssociativeRelationSql(Doctrine_Relation $relation, $assocAlias, $foreignAlias, $localAlias)
    {
        $table = $relation-&amp;gt;getTable();

        $queryPart = &apos; ON &apos;;

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($relation-&amp;gt;isEqual()) {
            $queryPart .= &apos;(&apos;;
        }

        $localIdentifier = $table-&amp;gt;getColumnName($table-&amp;gt;getIdentifier());

        $queryPart .= $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($foreignAlias . &apos;.&apos; . $localIdentifier)
                    . &apos; = &apos;
                    . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($assocAlias . &apos;.&apos; . $relation-&amp;gt;getForeignRefColumnName());

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($relation-&amp;gt;isEqual()) {
            $queryPart .= &apos; OR &apos;
                        . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($foreignAlias . &apos;.&apos; . $localIdentifier)
                        . &apos; = &apos;
                        . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($assocAlias . &apos;.&apos; . $relation-&amp;gt;getLocalRefColumnName())
                        . &apos;) AND &apos;
                        . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($foreignAlias . &apos;.&apos; . $localIdentifier)
                        . &apos; != &apos;
                        . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($localAlias . &apos;.&apos; . $localIdentifier);
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $queryPart;
    }

    /**
     * loadRoot
     *
     * @param string $name
     * @param string $componentAlias
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; Doctrine_Table
     * @todo DESCRIBE ME!
     * @todo &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; method is called only in Doctrine_Query class. Shouldn&apos;t be &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; or &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt;?
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function loadRoot($name, $componentAlias)
    {
        &lt;span class=&quot;code-comment&quot;&gt;// get the connection &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; the component
&lt;/span&gt;        $manager = Doctrine_Manager::getInstance();
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_passedConn &amp;amp;&amp;amp; $manager-&amp;gt;hasConnectionForComponent($name)) {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn = $manager-&amp;gt;getConnectionForComponent($name);
        }

        $table = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;getTable($name);
        $tableName = $table-&amp;gt;getTableName();

        &lt;span class=&quot;code-comment&quot;&gt;// get the &lt;span class=&quot;code-object&quot;&gt;short&lt;/span&gt; alias &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; table
&lt;/span&gt;        $tableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias, $tableName);
        &lt;span class=&quot;code-comment&quot;&gt;// quote table name
&lt;/span&gt;        $queryPart = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableName);

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_type === self::SELECT) {
            $queryPart .= &apos; &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias);
        }

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_tableAliasMap[$tableAlias] = $componentAlias;

        $queryPart .= $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;buildInheritanceJoinSql($name, $componentAlias);

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;from&apos;][] = $queryPart;

        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents[$componentAlias] = array(&apos;table&apos; =&amp;gt; $table, &apos;map&apos; =&amp;gt; &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;);

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $table;
    }

    /**
     * @todo DESCRIBE ME!
     * @param string $name              component class name
     * @param string $componentAlias    alias of the component in the dql
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string                   query part
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function buildInheritanceJoinSql($name, $componentAlias)
    {
        &lt;span class=&quot;code-comment&quot;&gt;// get the connection &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; the component
&lt;/span&gt;        $manager = Doctrine_Manager::getInstance();
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_passedConn &amp;amp;&amp;amp; $manager-&amp;gt;hasConnectionForComponent($name)) {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn = $manager-&amp;gt;getConnectionForComponent($name);
        }

        $table = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;getTable($name);
        $tableName = $table-&amp;gt;getTableName();

        &lt;span class=&quot;code-comment&quot;&gt;// get the &lt;span class=&quot;code-object&quot;&gt;short&lt;/span&gt; alias &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; table
&lt;/span&gt;        $tableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($componentAlias, $tableName);

        $queryPart = &apos;&apos;;

        foreach ($table-&amp;gt;getOption(&apos;joinedParents&apos;) as $parent) {
            $parentTable = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;getTable($parent);

            $parentAlias = $componentAlias . &apos;.&apos; . $parent;

            &lt;span class=&quot;code-comment&quot;&gt;// get the &lt;span class=&quot;code-object&quot;&gt;short&lt;/span&gt; alias &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; the parent table
&lt;/span&gt;            $parentTableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($parentAlias, $parentTable-&amp;gt;getTableName());

            $queryPart .= &apos; LEFT JOIN &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($parentTable-&amp;gt;getTableName())
                        . &apos; &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($parentTableAlias) . &apos; ON &apos;;

            &lt;span class=&quot;code-comment&quot;&gt;//Doctrine_Core::dump($table-&amp;gt;getIdentifier());
&lt;/span&gt;            foreach ((array) $table-&amp;gt;getIdentifier() as $identifier) {
                $column = $table-&amp;gt;getColumnName($identifier);

                $queryPart .= $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias)
                            . &apos;.&apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($column)
                            . &apos; = &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($parentTableAlias)
                            . &apos;.&apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($column);
            }
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $queryPart;
    }

    /**
     * Get count sql query &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; Doctrine_Query instance.
     *
     * This method is used in Doctrine_Query::count() &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; returning an integer
     * &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; the number of records which will be returned when executed.
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; string $q
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getCountSqlQuery()
    {
        &lt;span class=&quot;code-comment&quot;&gt;// triggers dql parsing/processing
&lt;/span&gt;        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlQuery(array(), &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;); &lt;span class=&quot;code-comment&quot;&gt;// &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; is ugly
&lt;/span&gt;
        &lt;span class=&quot;code-comment&quot;&gt;// initialize temporary variables
&lt;/span&gt;        $where   = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;];
        $having  = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;having&apos;];
        $groupby = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;groupby&apos;];

        $rootAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootAlias();
        $tableAlias = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getSqlTableAlias($rootAlias);

        &lt;span class=&quot;code-comment&quot;&gt;// Build the query base
&lt;/span&gt;        $q = &apos;SELECT COUNT(*) AS &apos; . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier(&apos;num_results&apos;) . &apos; FROM &apos;;

        &lt;span class=&quot;code-comment&quot;&gt;// Build the from clause
&lt;/span&gt;        $from = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_buildSqlFromPart(&lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;);

        &lt;span class=&quot;code-comment&quot;&gt;// Build the where clause
&lt;/span&gt;        $where = ( ! empty($where)) ? &apos; WHERE &apos; . implode(&apos; &apos;, $where) : &apos;&apos;;

        &lt;span class=&quot;code-comment&quot;&gt;// Build the group by clause
&lt;/span&gt;        $groupby = ( ! empty($groupby)) ? &apos; GROUP BY &apos; . implode(&apos;, &apos;, $groupby) : &apos;&apos;;

        &lt;span class=&quot;code-comment&quot;&gt;// Build the having clause
&lt;/span&gt;        $having = ( ! empty($having)) ? &apos; HAVING &apos; . implode(&apos; AND &apos;, $having) : &apos;&apos;;

        &lt;span class=&quot;code-comment&quot;&gt;// Building the from clause and finishing query
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_queryComponents) == 1 &amp;amp;&amp;amp; empty($having)) {
            $q .= $from . $where . $groupby . $having;
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            &lt;span class=&quot;code-comment&quot;&gt;// Subselect fields will contain only the pk of root entity
&lt;/span&gt;            $ta = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier($tableAlias);

            $map = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getRootDeclaration();
            $idColumnNames = $map[&apos;table&apos;]-&amp;gt;getIdentifierColumnNames();

            $pkFields = $ta . &apos;.&apos; . implode(&apos;, &apos; . $ta . &apos;.&apos;, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteMultipleIdentifier($idColumnNames));

            &lt;span class=&quot;code-comment&quot;&gt;// We need to &lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt; some magic in select fields &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; the query contain anything in having clause
&lt;/span&gt;            $selectFields = $pkFields;

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! empty($having)) {
                &lt;span class=&quot;code-comment&quot;&gt;// For each field defined in select clause
&lt;/span&gt;                foreach ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;select&apos;] as $field) {
                    &lt;span class=&quot;code-comment&quot;&gt;// We only include aggregate expressions to count query
&lt;/span&gt;                    &lt;span class=&quot;code-comment&quot;&gt;// This is needed because HAVING clause will use field aliases
&lt;/span&gt;                    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($field, &apos;(&apos;) !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                        $selectFields .= &apos;, &apos; . $field;
                    }
                }
                &lt;span class=&quot;code-comment&quot;&gt;// Add having fields that got stripped out of select
&lt;/span&gt;                preg_match_all(&apos;/`[a-z0-9_]+`\.`[a-z0-9_]+`/i&apos;, $having, $matches, PREG_PATTERN_ORDER);
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($matches[0]) &amp;gt; 0) {
                    $selectFields .= &apos;, &apos; . implode(&apos;, &apos;, array_unique($matches[0]));
                }
            }

            &lt;span class=&quot;code-comment&quot;&gt;// If we &lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt; not have a custom group by, apply the &lt;span class=&quot;code-keyword&quot;&gt;default&lt;/span&gt; one
&lt;/span&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (empty($groupby)) {
                $groupby = &apos; GROUP BY &apos; . $pkFields;
            }

            $q .= &apos;(SELECT &apos; . $selectFields . &apos; FROM &apos; . $from . $where . $groupby . $having . &apos;) &apos;
                . $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;quoteIdentifier(&apos;dctrn_count_query&apos;);
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $q;
    }

    /**
     * Fetches the count of the query.
     *
     * This method executes the main query without all the
     * selected fields, ORDER BY part, LIMIT part and OFFSET part.
     *
     * Example:
     * Main query:
     *      SELECT u.*, p.phonenumber FROM User u
     *          LEFT JOIN u.Phonenumber p
     *          WHERE p.phonenumber = &apos;123 123&apos; LIMIT 10
     *
     * The modified DQL query:
     *      SELECT COUNT(DISTINCT u.id) FROM User u
     *          LEFT JOIN u.Phonenumber p
     *          WHERE p.phonenumber = &apos;123 123&apos;
     *
     * @param array $params        an array of prepared statement parameters
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; integer             the count of &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; query
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function count($params = array())
    {
        $q = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getCountSqlQuery();
        $params = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getCountQueryParams($params);
        $params = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_conn-&amp;gt;convertBooleans($params);

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_resultCache) {
            $conn = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getConnection(); 
            $cacheDriver = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getResultCacheDriver();
            $hash = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getResultCacheHash($params).&apos;_count&apos;;
            $cached = ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_expireResultCache) ? &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt; : $cacheDriver-&amp;gt;fetch($hash);

            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($cached === &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                &lt;span class=&quot;code-comment&quot;&gt;// cache miss
&lt;/span&gt;                $results = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getConnection()-&amp;gt;fetchAll($q, $params);
                $cacheDriver-&amp;gt;save($hash, serialize($results), $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getResultCacheLifeSpan());
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                $results = unserialize($cached);
            }
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            $results = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getConnection()-&amp;gt;fetchAll($q, $params);
        }

        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($results) &amp;gt; 1) {
            $count = count($results);
        } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($results[0])) {
                $results[0] = array_change_key_case($results[0], CASE_LOWER);
                $count = $results[0][&apos;num_results&apos;];
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                $count = 0;
            }
        }

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; (&lt;span class=&quot;code-object&quot;&gt;int&lt;/span&gt;) $count;
    }

    /**
     * Queries the database with DQL (Doctrine Query Language).
     *
     * This methods parses a Dql query and builds the query parts.
     *
     * @param string $query      Dql query
     * @param array $params      prepared statement parameters
     * @param &lt;span class=&quot;code-object&quot;&gt;int&lt;/span&gt; $hydrationMode Doctrine_Core::HYDRATE_ARRAY or Doctrine_Core::HYDRATE_RECORD
     * @see Doctrine_Core::FETCH_* constants
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; mixed
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function query($query, $params = array(), $hydrationMode = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;)
    {
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;parseDqlQuery($query);
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;execute($params, $hydrationMode);
    }

    /**
     * Copies a Doctrine_Query object.
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; Doctrine_Query  Copy of the Doctrine_Query instance.
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function copy(Doctrine_Query $query = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! $query) {
            $query = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;;
        }

        $&lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; = clone $query;

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt;;
    }

    /**
     * Magic method called after cloning process.
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; void
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function __clone()
    {
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_parsers = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_hydrator = clone $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_hydrator;

        &lt;span class=&quot;code-comment&quot;&gt;// Subqueries share some information from the parent so it can intermingle
&lt;/span&gt;        &lt;span class=&quot;code-comment&quot;&gt;// with the dql of the main query. So when a subquery is cloned we need to
&lt;/span&gt;        &lt;span class=&quot;code-comment&quot;&gt;// kill those references or it causes problems
&lt;/span&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;isSubquery()) {
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_killReference(&apos;_params&apos;);
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_killReference(&apos;_tableAliasMap&apos;);
            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_killReference(&apos;_queryComponents&apos;);
        }
    }

    /**
     * Kill the reference &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; the passed class property.
     * This method simply copies the value to a temporary variable and then unsets
     * the reference and re-assigns the old value but not by reference
     *
     * @param string $key
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; function _killReference($key)
    {
        $tmp = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;$key;
        unset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;$key);
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;$key = $tmp;
    }

    /**
     * Frees the resources used by the query object. It especially breaks a
     * cyclic reference between the query object and it&apos;s parsers. This enables
     * PHP&apos;s current GC to reclaim the memory.
     * This method can therefore be used to reduce memory usage when creating
     * a lot of query objects during a request.
     *
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; Doctrine_Query   &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; object
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function free()
    {
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;reset();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_parsers = array();
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_dqlParts = array();
    }
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I have loved working with Doctrine and would be happy to contribute back to the code base any patches I resolve for my project in the future.&lt;/p&gt;

&lt;p&gt;Best regards&lt;/p&gt;

&lt;p&gt;Will Ferrer&lt;/p&gt;</comment>
                    <comment id="13073" author="jwage" created="Thu, 27 May 2010 22:20:02 +0000"  >&lt;p&gt;Hi, in order to apply your changes we need a patch and not the whole file. Thanks, Jon&lt;/p&gt;</comment>
                    <comment id="13094" author="willf1976" created="Wed, 2 Jun 2010 20:07:19 +0000"  >&lt;p&gt;Hi Jonathan&lt;/p&gt;

&lt;p&gt;I tried using winmerge to make a patch file but it seems contain both the entire before and after files in it. I am not sure if I am doing something wrong with the software or if this is just what a patch file looks like.&lt;/p&gt;

&lt;p&gt;At any rate I have attached the patch file to this issue.&lt;/p&gt;

&lt;p&gt;Please let me know if this patch file is correct.&lt;/p&gt;

&lt;p&gt;Best Regards&lt;/p&gt;

&lt;p&gt;Will Ferrer&lt;/p&gt;</comment>
                    <comment id="13146" author="jwage" created="Tue, 8 Jun 2010 09:59:59 +0000"  >&lt;p&gt;Hi, the patch is not correct. Just go into your svn checkout where the changes are and run the command svn diff. Output that to a file and attach it here. Thanks, Jon&lt;/p&gt;</comment>
                    <comment id="13147" author="jwage" created="Tue, 8 Jun 2010 10:09:09 +0000"  >&lt;p&gt;I was able to generate a patch. It had some errors in our test suite but I fixed them. Since we don&apos;t have a test case for it I am not sure if the changes I made affected anything for you. Can you test the patch or provide a test case?&lt;/p&gt;</comment>
                    <comment id="13233" author="willf1976" created="Tue, 8 Jun 2010 18:51:26 +0000"  >&lt;p&gt;Hi Jon&lt;/p&gt;

&lt;p&gt;I checked out the svn branch 1.2.2 and noticed that you had my original/broken patch in the code (that one failed some tests for me so I fixed it and tried to upload it in the last patch file I attached to this thread &amp;#8211; the patch file that didn&apos;t work).&lt;/p&gt;

&lt;p&gt;Using the technique you described I made a working patch to put the correct version of my code into the 1.2.2 branch.&lt;/p&gt;

&lt;p&gt;I also added a test case for this fix in my patch.&lt;/p&gt;

&lt;p&gt;Please see the new patch I have attached to this thread.&lt;/p&gt;

&lt;p&gt;Thanks for all your help.&lt;/p&gt;

&lt;p&gt;Will Ferrer&lt;/p&gt;
</comment>
                    <comment id="13234" author="willf1976" created="Tue, 8 Jun 2010 18:52:02 +0000"  >&lt;p&gt;Here is the correct patch for the bug fix, along with the test case for it.&lt;/p&gt;</comment>
                    <comment id="13235" author="willf1976" created="Tue, 8 Jun 2010 18:54:07 +0000"  >&lt;p&gt;I reopened the issue to call attention to the fixed patch/test case I added to the thread.&lt;/p&gt;</comment>
                    <comment id="13236" author="jwage" created="Tue, 8 Jun 2010 18:59:30 +0000"  >&lt;p&gt;That one works and looks better. Just had a few tabs vs spaces problems that I fixed. Thanks for your work on this. It is much appreciated!!!!!&lt;/p&gt;</comment>
                    <comment id="13238" author="willf1976" created="Tue, 8 Jun 2010 19:09:33 +0000"  >&lt;p&gt;Hi Jon&lt;/p&gt;

&lt;p&gt;No problem &amp;#8211; I am very glad to contribute back to the project &lt;img class=&quot;emoticon&quot; src=&quot;http://www.doctrine-project.org/jira/images/icons/emoticons/smile.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;. Doctrine has really been invaluable to me in my development, thanks for building it.&lt;/p&gt;

&lt;p&gt;Hope you are well.&lt;/p&gt;

&lt;p&gt;Will Ferrer&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10624" name="Query.php.patch" size="181078" author="willf1976" created="Wed, 2 Jun 2010 20:07:34 +0000" />
                    <attachment id="10633" name="ticketDC706.patch" size="2588" author="willf1976" created="Tue, 8 Jun 2010 18:52:02 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-705] synchronizeWithArray does not properly set foreign key  validation</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-705</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;I&apos;ve discovered a variation of the problem tested in tests/Validator/ForeignKeysTestCase.php. This happens when you synchronizeWithArray and a foreign relation is set - isValid will trigger the isnull validator. &lt;/p&gt;

&lt;p&gt;This is probably better explained through two new test cases. I&apos;ve included them below. The first test case passes. However, the second test case (testSynchronizedForeignKeyIsValidIfForeignRelationIsSet) fails.&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeHeader panelHeader&quot; style=&quot;border-bottom-width: 1px;&quot;&gt;&lt;b&gt;tests/Validator/ForeignKeysTestCase.php - also attached as patch&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;&lt;span class=&quot;code-comment&quot;&gt;// Place in tests/Validator/ForeignKeysTestCase.php
&lt;/span&gt;    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function testSynchronizedForeignKeyIsValidIfLocalRelationIsSet()
    {
        $person = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; TestPerson();
        $person-&amp;gt;synchronizeWithArray(array(&apos;Addresses&apos; =&amp;gt; array(array())));

        $address = $person-&amp;gt;Addresses[0];
        $table = $address-&amp;gt;getTable();
        
        $errors = $table-&amp;gt;validateField(&apos;person_id&apos;, $address-&amp;gt;person_id, $address);
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;assertEqual(0, $errors-&amp;gt;count());
    }

    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function testSynchronizedForeignKeyIsValidIfForeignRelationIsSet()
    {
        $address = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; TestAddress();
        $address-&amp;gt;synchronizeWithArray(array(&apos;Person&apos; =&amp;gt; array()));

        $table = $address-&amp;gt;getTable();
        $errors = $table-&amp;gt;validateField(&apos;person_id&apos;, $address-&amp;gt;person_id, $address);
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;assertEqual(0, $errors-&amp;gt;count());
    }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I&apos;ve discovered a workaround, if you reassign the value it will work.&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;$address-&amp;gt;synchronizeWithArray(array(&apos;Person&apos; =&amp;gt; array()));
$address-&amp;gt;Person = $address-&amp;gt;Person;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;A quick and likely terrible (or wrong?) fix is to have the synchronizeWithArray function do it for you. I&apos;ve attached a patch does just that.&lt;/p&gt;
</description>
                <environment></environment>
            <key id="11416">DC-705</key>
            <summary>synchronizeWithArray does not properly set foreign key  validation</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="jochu">Jeff Chu</reporter>
                        <labels>
                    </labels>
                <created>Tue, 25 May 2010 16:32:39 +0000</created>
                <updated>Tue, 8 Jun 2010 10:19:23 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 10:19:23 +0000</resolved>
                            <version>1.2.2</version>
                <version>1.2.3</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Relations</component>
                <component>Validators</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="13065" author="jochu" created="Tue, 25 May 2010 17:25:58 +0000"  >&lt;p&gt;Just as a note - I was looking at this further and noticed that doing this also fails:&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;&lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function testGetForeignKeyIsValidIfForeignRelationIsSet()
{
    $address = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; TestAddress();
    $address-&amp;gt;Person;

    $table = $address-&amp;gt;getTable();
    $errors = $table-&amp;gt;validateField(&apos;person_id&apos;, $address-&amp;gt;person_id, $address);
    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;assertEqual(0, $errors-&amp;gt;count());
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;But oddly enough, the following works:&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;$address-&amp;gt;Person;
$address-&amp;gt;Person = $address-&amp;gt;Person;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I think this has to do with the inconsistencies in whether get should create a real relation or fake it until it&apos;s actually set with a setter. From what I can tell, this all stems from the support for the following behavior:&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;$address = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Address();
$address-&amp;gt;Person-&amp;gt;first_name = &lt;span class=&quot;code-quote&quot;&gt;&quot;Bob&quot;&lt;/span&gt;;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This behavior is taken advantage of from within synchronizeWithArray:&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;$&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;$key-&amp;gt;synchronizeWithArray($value);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;However, because it doesn&apos;t create a real relation this way - the original issue comes up. Updating record&apos;s get to create a real relation requires us to update Doctrine_Record&apos;s _get to use coreSetRelated (instead of directly modifying $this-&amp;gt;_references). However, doing this will conflict directly with test Ticket 1072.&lt;/p&gt;

&lt;p&gt;What is the intended behavior of all of this?&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10614" name="doctrine-syncarray-test.patch" size="1252" author="jochu" created="Tue, 25 May 2010 16:32:39 +0000" />
                    <attachment id="10613" name="doctrine-syncarray.patch" size="610" author="jochu" created="Tue, 25 May 2010 16:32:39 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-703] [PATCH] Doctrine_Connection_Oracle unquoted query aliases in _createLimitSubquery</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-703</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;When using identifier quoting with oracle driver, the _createLimitSubquery is giving into the select statement unquoted subquery aliases. That leads to Oracle errors.&lt;/p&gt;

&lt;p&gt;Simple patch:&lt;br/&gt;
{{&lt;br/&gt;
diff --git a/lib/Doctrine/Connection/Oracle.php b/lib/Doctrine/Connection/Oracle.php&lt;br/&gt;
index db538fb..6e5f629 100644&lt;br/&gt;
&amp;#8212; a/lib/Doctrine/Connection/Oracle.php&lt;br/&gt;
+++ b/lib/Doctrine/Connection/Oracle.php&lt;br/&gt;
@@ -108,8 +108,8 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection_Common&lt;br/&gt;
                 $column = $column === null ? &apos;*&apos; : $this-&amp;gt;quoteIdentifier($column);&lt;br/&gt;
                 if ($offset &amp;gt; 0) &lt;/p&gt;
{
                     $min = $offset + 1;
-                    $query = &apos;SELECT b.&apos;.$column.&apos; FROM ( &apos;.
-                                 &apos;SELECT a.*, ROWNUM AS doctrine_rownum FROM ( &apos;
+                    $query = &apos;SELECT &apos;.$this-&amp;gt;quoteIdentifier(&apos;b&apos;).&apos;.&apos;.$column.&apos; FROM ( &apos;.
+                                 &apos;SELECT &apos;.$this-&amp;gt;quoteIdentifier(&apos;a&apos;).&apos;.*, ROWNUM AS doctrine_rownum FROM ( &apos;
                                    . $query . &apos; ) &apos; . $this-&amp;gt;quoteIdentifier(&apos;a&apos;) . &apos; &apos;.
                               &apos; ) &apos; . $this-&amp;gt;quoteIdentifier(&apos;b&apos;) . &apos; &apos;.
                               &apos;WHERE doctrine_rownum BETWEEN &apos; . $min .  &apos; AND &apos; . $max;

}
&lt;p&gt;}&lt;/p&gt;</description>
                <environment></environment>
            <key id="11413">DC-703</key>
            <summary>[PATCH] Doctrine_Connection_Oracle unquoted query aliases in _createLimitSubquery</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="adrive">Miloslav &quot;adrive&quot; Kmet</reporter>
                        <labels>
                    </labels>
                <created>Tue, 25 May 2010 09:09:06 +0000</created>
                <updated>Tue, 8 Jun 2010 10:23:01 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 10:23:01 +0000</resolved>
                            <version>1.2.0-RC1</version>
                <version>1.2.0</version>
                <version>1.2.1</version>
                <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Connection</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="13064" author="adrive" created="Tue, 25 May 2010 16:47:21 +0000"  >&lt;p&gt;Fixed in &lt;a href=&quot;http://github.com/milokmet/doctrine1/tree/DC-703&quot; class=&quot;external-link&quot;&gt;http://github.com/milokmet/doctrine1/tree/DC-703&lt;/a&gt;&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10612" name="Doctrine_Connection_Oracle.patch" size="1003" author="adrive" created="Tue, 25 May 2010 09:10:08 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-699] DC292 test doesn&apos;t pass due to missing &apos;migrations&apos; directory</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-699</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;After downloading Doctrine 1.2.2 from &lt;span class=&quot;error&quot;&gt;&amp;#91;1&amp;#93;&lt;/span&gt; and unpacking it, when trying to run the tests by:&lt;/p&gt;

&lt;ol&gt;
	&lt;li&gt;cd Doctrine-1.2.2/tests&lt;/li&gt;
	&lt;li&gt;php ./run.php&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;i get:&lt;/p&gt;

&lt;p&gt;Unexpected UnexpectedValueException thrown in &lt;span class=&quot;error&quot;&gt;&amp;#91;Doctrine_Ticket_DC292_TestCase&amp;#93;&lt;/span&gt; with message &lt;span class=&quot;error&quot;&gt;&amp;#91;RecursiveDirectoryIterator::__construct(/home/fgimenez/alioth/doctrine_test/Doctrine-1.2.2/tests/Ticket/DC292/migrations): failed to open dir: No such file or directory&amp;#93;&lt;/span&gt; in /home/fgimenez/alioth/doctrine_test/Doctrine-1.2.2/lib/Doctrine/Migration.php on line 137&lt;/p&gt;

&lt;p&gt;If i create a &apos;migrations&apos; directory under Doctrine-1.2.2/tests/Ticket/DC292 all tests pass.&lt;/p&gt;

&lt;p&gt;Cheers,&lt;br/&gt;
Federico&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;1&amp;#93;&lt;/span&gt; &lt;a href=&quot;http://www.doctrine-project.org/downloads/Doctrine-1.2.2.tgz&quot; class=&quot;external-link&quot;&gt;http://www.doctrine-project.org/downloads/Doctrine-1.2.2.tgz&lt;/a&gt;&lt;/p&gt;</description>
                <environment>Debian Lenny</environment>
            <key id="11406">DC-699</key>
            <summary>DC292 test doesn&apos;t pass due to missing &apos;migrations&apos; directory</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="fgimenez">Federico Gimenez Nieto</reporter>
                        <labels>
                    </labels>
                <created>Mon, 24 May 2010 13:46:35 +0000</created>
                <updated>Tue, 8 Jun 2010 10:31:39 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 10:31:39 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="13154" author="jwage" created="Tue, 8 Jun 2010 10:31:07 +0000"  >&lt;p&gt;SVN contains an empty directory named migrations already. I will add some code to ensure the directory is created though.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-698] Record::link method does not work with setting null one-to-one</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-698</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;I have an Issue model with one owner User (relation Owner). I have this code:&lt;/p&gt;

&lt;p&gt;$issue-&amp;gt;link( &apos;Owner&apos;, array( $owner_id ) );&lt;/p&gt;

&lt;p&gt;At the time of calling this code, the $issue-&amp;gt;Owner is null. When this is called, the link fails to assign the new owner to the relation. I&apos;ve tried to hotfix it changing line around 2516 in Record.php:&lt;/p&gt;

&lt;p&gt;                    $this-&amp;gt;get($alias)-&amp;gt;add($record);&lt;/p&gt;

&lt;p&gt;to this:&lt;/p&gt;

&lt;p&gt;                    if( $c = $this-&amp;gt;get($alias) )&lt;/p&gt;
                    {
                        $c-&amp;gt;add($record);
                    }
&lt;p&gt;                    else&lt;/p&gt;
                    {
                    	$this-&amp;gt;set( $alias, $record );
                    }

&lt;p&gt;In this case the $this-&amp;gt;get($alias) returns NULL, so the subsequent add($record) fails.&lt;/p&gt;</description>
                <environment></environment>
            <key id="11401">DC-698</key>
            <summary>Record::link method does not work with setting null one-to-one</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="martincohen">Martin Cohen</reporter>
                        <labels>
                    </labels>
                <created>Sat, 22 May 2010 09:16:06 +0000</created>
                <updated>Tue, 8 Jun 2010 10:35:04 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 10:35:04 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-697] Doctrine Support of custom enum types in Pgsql</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-697</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;In postgres with existing schema you can have custom enum types. To support this with our current code base (symfony w/ doctrine 1.2.2) I had to make changes to doctrine import and datadict for pgsql driver. The patches attached are from the git tree. &lt;/p&gt;

&lt;p&gt;0001-Postgresql-custome-enum-types-as-native-enum.patch &lt;br/&gt;
0002-Update-Pgsql-test-case-to-include-enum-changes-to-ta.patch&lt;/p&gt;

&lt;p&gt;The patches are formatted from the git tree.&lt;/p&gt;

&lt;p&gt;Thanks for an excellent ORM for php!&lt;/p&gt;</description>
                <environment></environment>
            <key id="11397">DC-697</key>
            <summary>Doctrine Support of custom enum types in Pgsql</summary>
                <type id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/improvement.png">Improvement</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="ljackson">Leif Jackson</reporter>
                        <labels>
                    </labels>
                <created>Thu, 20 May 2010 17:22:28 +0000</created>
                <updated>Tue, 8 Jun 2010 10:50:36 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 10:50:36 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Import/Export</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                    <attachment id="10610" name="0001-Postgresql-custome-enum-types-as-native-enum.patch" size="7912" author="ljackson" created="Thu, 20 May 2010 17:22:28 +0000" />
                    <attachment id="10611" name="0002-Update-Pgsql-test-case-to-include-enum-changes-to-ta.patch" size="2466" author="ljackson" created="Thu, 20 May 2010 17:22:28 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-696] Sluggable behavior doesn&apos;t work properly with french accents in utf8</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-696</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;In UTF8, &quot;L&#233;gislation 2008&quot; was &quot;slugged&quot; as &quot;legislation-ta-2-8&quot; which is not correct.&lt;/p&gt;

&lt;p&gt;It is caused as a bug in the Doctrine_Inflector::unaccent function.&lt;/p&gt;

&lt;p&gt;If $string seems to be UTF8, we use the $chars array to replace accents. But the last line of the $chars array (Norwegian characters replacements) is incorrect :&lt;/p&gt;

&lt;p&gt;          &apos;&#197;&apos;=&amp;gt;&apos;Aa&apos;,&apos;&#198;&apos;=&amp;gt;&apos;Ae&apos;,&apos;&#216;&apos;=&amp;gt;&apos;O&apos;,&apos;&#230;&apos;=&amp;gt;&apos;a&apos;,&apos;&#248;&apos;=&amp;gt;&apos;o&apos;,&apos;&#229;&apos;,&apos;aa&apos;&lt;/p&gt;

&lt;p&gt;should be replaced by&lt;/p&gt;

&lt;p&gt;          &apos;&#197;&apos;=&amp;gt;&apos;Aa&apos;,&apos;&#198;&apos;=&amp;gt;&apos;Ae&apos;,&apos;&#216;&apos;=&amp;gt;&apos;O&apos;,&apos;&#230;&apos;=&amp;gt;&apos;a&apos;,&apos;&#248;&apos;=&amp;gt;&apos;o&apos;,&apos;&#229;&apos; =&amp;gt; &apos;aa&apos;&lt;/p&gt;</description>
                <environment>Windows XP, Symfony 1.4.4, PHP 5.2.8, MySQL 5.0.x</environment>
            <key id="11396">DC-696</key>
            <summary>Sluggable behavior doesn&apos;t work properly with french accents in utf8</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="nicod">Nicolas Deguine</reporter>
                        <labels>
                    </labels>
                <created>Thu, 20 May 2010 11:39:24 +0000</created>
                <updated>Tue, 8 Jun 2010 10:50:57 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 10:50:57 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Behaviors</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-695] Fixtures created badly when primary key is not autonumber</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-695</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;When exporting data where the primary key is not an autonumber the export function will hide the field anyway, merging the keys to the text identifier of the resulting record. &lt;/p&gt;

&lt;p&gt;This creates two problems: &lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;the original value is lost due to size limit of the record identifier&lt;/li&gt;
	&lt;li&gt;the database is unable to generate the primary key when data-loading.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;A fix is attached that prevents the export function of hiding the said field from the fixture.&lt;/p&gt;</description>
                <environment>Tested on Linux/Mysql</environment>
            <key id="11395">DC-695</key>
            <summary>Fixtures created badly when primary key is not autonumber</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="jasonsantos">Lu&#237;s Eduardo Jason Santos</reporter>
                        <labels>
                    </labels>
                <created>Thu, 20 May 2010 11:23:36 +0000</created>
                <updated>Tue, 8 Jun 2010 11:07:36 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 10:53:52 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Import/Export</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="13159" author="jwage" created="Tue, 8 Jun 2010 10:53:52 +0000"  >&lt;p&gt;Thanks for the issue and patch!&lt;/p&gt;</comment>
                </comments>
                <issuelinks>
                        <issuelinktype id="10000">
                <name>Duplicate</name>
                                                <inwardlinks description="is duplicated by">
                            <issuelink>
            <issuekey id="11382">DC-688</issuekey>
        </issuelink>
                    </inwardlinks>
                            </issuelinktype>
                    </issuelinks>
                <attachments>
                    <attachment id="10609" name="fix.diff" size="904" author="jasonsantos" created="Thu, 20 May 2010 11:23:36 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-694] Doctrine_Record::replace() discards Doctrine_Expression values, uses empty value instead</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-694</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;I experienced a bug when working with a datetime field that only rears its head when I use $record-&amp;gt;replace()&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;
&lt;span class=&quot;code-comment&quot;&gt;//  BUG!!
&lt;/span&gt;$record-&amp;gt;date_created = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Expression(&apos;NOW()&apos;);
$record-&amp;gt;replace();
&lt;span class=&quot;code-comment&quot;&gt;// date_created will be 0000-00-00 00:00:00, i.e. empty
&lt;/span&gt;
&lt;span class=&quot;code-comment&quot;&gt;// WORKS FINE!
&lt;/span&gt;$record-&amp;gt;date_created = &apos;2022-12-23 14:14:12&apos;;
$record-&amp;gt;replace();

&lt;span class=&quot;code-comment&quot;&gt;// WORKS FINE!
&lt;/span&gt;$record-&amp;gt;date_created = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Doctrine_Expression(&apos;NOW()&apos;);
$record-&amp;gt;insert();

&lt;span class=&quot;code-comment&quot;&gt;// WORKS FINE!
&lt;/span&gt;$record-&amp;gt;date_created = &apos;2022-12-23 14:14:12&apos;;
$record-&amp;gt;insert();

&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</description>
                <environment>php 5.3.0 @ Windows XP SP3 &lt;br/&gt;
MySQL 5.1.40 @ Windows XP SP3 </environment>
            <key id="11394">DC-694</key>
            <summary>Doctrine_Record::replace() discards Doctrine_Expression values, uses empty value instead</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="exceptione">Exception e</reporter>
                        <labels>
                    </labels>
                <created>Thu, 20 May 2010 09:25:37 +0000</created>
                <updated>Tue, 8 Jun 2010 11:02:54 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 11:02:54 +0000</resolved>
                            <version>1.2.1</version>
                <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Record</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="13160" author="jwage" created="Tue, 8 Jun 2010 11:02:54 +0000"  >&lt;p&gt;Thanks for the issue and description. I committed a fix that addresses the problem.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-691] No sequence_id increment after fixtures loaded, while setting their ids</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-691</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;If I force id in fixtures (they are autoincremented in model), the sequence is not set correctly in postgresql.&lt;/p&gt;

&lt;p&gt;Model :&lt;br/&gt;
T_Company:&lt;br/&gt;
  actAs:                    &lt;br/&gt;
    Timestampable: ~&lt;br/&gt;
    Searchable:&lt;br/&gt;
      fields: &lt;span class=&quot;error&quot;&gt;&amp;#91;name&amp;#93;&lt;/span&gt;&lt;br/&gt;
  columns:&lt;br/&gt;
    company_id:             &lt;/p&gt;
{ type: integer, notnull: true, autoincrement: true, primary: true }
&lt;p&gt;    dn:                     &lt;/p&gt;
{ type: string(255) }
&lt;p&gt;    name:                   &lt;/p&gt;
{ type: string(127), notnull: true}
&lt;p&gt;  relations:&lt;br/&gt;
    RssSettings:            &lt;/p&gt;
{ local: company_id, foreign: rsssettings_id, foreignAlias: CompanySettings, refClass: J_Company_Rsssettings, class: T_RssSettings }
&lt;p&gt;    ParentCompany:          &lt;/p&gt;
{ local: company_id, foreign: parent_company_id, foreignAlias: ChildCompany, refClass: J_Company_Company, class: T_Company }
&lt;p&gt;    ParentLinkType:         &lt;/p&gt;
{ local: company_id, foreign: parent_company_id, refClass: J_Company_Company, class: S_CompanyLinkType }

&lt;p&gt;Fixtures :&lt;br/&gt;
T_Company:&lt;br/&gt;
  A:&lt;br/&gt;
    company_id: 1&lt;br/&gt;
    name: A&lt;br/&gt;
    dn: A&lt;br/&gt;
  B:&lt;br/&gt;
    company_id: 2&lt;br/&gt;
    name: B&lt;br/&gt;
    dn: B&lt;br/&gt;
  C:&lt;br/&gt;
    company_id: 3&lt;br/&gt;
    name: C&lt;br/&gt;
    dn: C&lt;/p&gt;

&lt;p&gt;Postgresql :&lt;br/&gt;
sl3dev=# select * from t__company;&lt;br/&gt;
 company_id |                              dn                              |                   name                    |     created_at      |     updated_at      &lt;br/&gt;
-----------&lt;del&gt;&lt;ins&gt;&lt;/del&gt;------------------------------------------------------------&lt;del&gt;&lt;/ins&gt;&lt;/del&gt;-----------------------------------------&lt;del&gt;&lt;ins&gt;&lt;/del&gt;-------------------&lt;del&gt;&lt;/ins&gt;&lt;/del&gt;--------------------&lt;br/&gt;
          1 |      A                                                                   | A                                              | 2010-05-18 16:55:12 | 2010-05-18 16:55:12&lt;br/&gt;
          2 |      B                                                                   | B                                              | 2010-05-18 16:55:12 | 2010-05-18 16:55:12&lt;br/&gt;
          3 |      C                                                                  | C                                              | 2010-05-18 16:55:12 | 2010-05-18 16:55:12&lt;/p&gt;

&lt;p&gt;sl3dev=# select nextval(&apos;t__company_company_id_seq&apos;::regclass);&lt;br/&gt;
 nextval &lt;br/&gt;
---------&lt;br/&gt;
       1&lt;br/&gt;
(1 ligne)&lt;/p&gt;

&lt;p&gt;1 instead of 4 naturally.&lt;/p&gt;</description>
                <environment>Ubuntu lucid up to date - Symfony 1.4.4 - Postgresql 8.4</environment>
            <key id="11385">DC-691</key>
            <summary>No sequence_id increment after fixtures loaded, while setting their ids</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="xanadonf">A. Simonneau</reporter>
                        <labels>
                    </labels>
                <created>Tue, 18 May 2010 11:20:58 +0000</created>
                <updated>Tue, 8 Jun 2010 17:33:43 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 17:15:46 +0000</resolved>
                                            <fixVersion>1.2.3</fixVersion>
                                <component>Data Fixtures</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>1</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-688] data-load don&apos;t work when the primary key is a string</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-688</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;The export/import system don&apos;t work if a table have a primary key string.&lt;/p&gt;

&lt;p&gt;I have this schema :&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; 
TypeChampPerso:
  columns:
    id: { type: string(20), primary: &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt; }
    description: { type: string(100), notnull: &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt; }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; 

&lt;p&gt;Here is the result when I extract data with data-dump :&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; 
TypeChampPerso:
  TypeChampPerso_date:
    description: Date
  TypeChampPerso_numeric:
    description: Num&#233;rique
  TypeChampPerso_text:
    description: Texte
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; 

&lt;p&gt;Then, I&apos;ve got an error when I used data-load :&lt;br/&gt;
SQLSTATE&lt;span class=&quot;error&quot;&gt;&amp;#91;23000&amp;#93;&lt;/span&gt;: Integrity constraint violation: 1062 Duplicate entry &apos;&apos; for key &apos;PRIMARY&apos;&lt;/p&gt;

&lt;p&gt;The id column is empty is the DB.&lt;/p&gt;

&lt;p&gt;It works if I add manually the id value in the yml file :&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; 
TypeChampPerso:
  TypeChampPerso_date:
    id: date
    description: Date
  TypeChampPerso_numeric:
    id: numeric
    description: Num&#233;rique
  TypeChampPerso_text:
    id: text
    description: Texte
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; </description>
                <environment>Windows 7&lt;br/&gt;
MySQL 5.1&lt;br/&gt;
Apache 2.2&lt;br/&gt;
PHP 5.3&lt;br/&gt;
Symphony 1.4.4</environment>
            <key id="11382">DC-688</key>
            <summary>data-load don&apos;t work when the primary key is a string</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="thegillou">Gilles</reporter>
                        <labels>
                    </labels>
                <created>Tue, 18 May 2010 05:51:30 +0000</created>
                <updated>Tue, 8 Jun 2010 11:07:41 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 11:07:41 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Import/Export</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>1</watches>
                            <issuelinks>
                        <issuelinktype id="10000">
                <name>Duplicate</name>
                                <outwardlinks description="duplicates">
                            <issuelink>
            <issuekey id="11395">DC-695</issuekey>
        </issuelink>
                    </outwardlinks>
                                            </issuelinktype>
                    </issuelinks>
                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-687] Doctrine_Inflector::unaccent replaces UTF8-Chars - 0 with &#229;, 1 with aa</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-687</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Changeset 7359 which fixes #&lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-543&quot; title=&quot;Doctrine_Inflector::unaccent does not replace the norwegian characters &#230;&#248;&#229;&quot;&gt;&lt;del&gt;DC-543&lt;/del&gt;&lt;/a&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;Doctrine_Inflector::unaccent does not replace the norwegian characters &#230;&#248;&#229;&amp;#93;&lt;/span&gt; introduces a new bug ... 0 and 1 are now replaced with &#229; and aa&lt;/p&gt;</description>
                <environment></environment>
            <key id="11381">DC-687</key>
            <summary>Doctrine_Inflector::unaccent replaces UTF8-Chars - 0 with &#229;, 1 with aa</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="steffkes">Steffkes</reporter>
                        <labels>
                    </labels>
                <created>Tue, 18 May 2010 05:01:52 +0000</created>
                <updated>Tue, 8 Jun 2010 11:08:31 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 11:08:31 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Sluggable</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                    <attachment id="10607" name="100518_Doctrine_Inflector.patch" size="544" author="steffkes" created="Tue, 18 May 2010 05:01:52 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-685] Invalid conditions in Import/Mysql.php</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-685</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Lines 68 and 190 have the following conditional&lt;br/&gt;
if ($this-&amp;gt;conn-&amp;gt;getAttribute(Doctrine_Core::ATTR_PORTABILITY) &amp;amp; Doctrine_Core::PORTABILITY_FIX_CASE) {&lt;/p&gt;

&lt;p&gt;Should read: &lt;br/&gt;
if ($this-&amp;gt;conn-&amp;gt;getAttribute(Doctrine_Core::ATTR_FIELD_CASE) &amp;amp;&amp;amp; &lt;br/&gt;
            ($this-&amp;gt;conn-&amp;gt;getAttribute(Doctrine_Core::ATTR_PORTABILITY) &amp;amp; Doctrine_Core::PORTABILITY_FIX_CASE)) {&lt;/p&gt;</description>
                <environment></environment>
            <key id="11369">DC-685</key>
            <summary>Invalid conditions in Import/Mysql.php</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="drak">Karma Dordrak (Drak)</reporter>
                        <labels>
                    </labels>
                <created>Sat, 15 May 2010 18:07:31 +0000</created>
                <updated>Tue, 8 Jun 2010 11:12:15 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 11:12:15 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Import/Export</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="13164" author="jwage" created="Tue, 8 Jun 2010 11:12:15 +0000"  >&lt;p&gt;Thanks for the issue and required change!&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-683] orderBy many field defined in yml files doesnt work</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-683</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Hi,&lt;br/&gt;
When you have defined orderBy table option in yml file, like:&lt;/p&gt;

&lt;p&gt;orderBy[ field1 ASC, field2 DESC ]&lt;/p&gt;

&lt;p&gt;and models build by doctrine:build --model&lt;/p&gt;

&lt;p&gt;Doctrine_Table class reports warnings, when executing select query i.e.:&lt;br/&gt;
Warning: array_map() &lt;span class=&quot;error&quot;&gt;&amp;#91;function.array-map&amp;#93;&lt;/span&gt;: Argument #2 should be an array in ....\doctrine\Doctrine\Table.php  on line 1134&lt;/p&gt;

&lt;p&gt;that&apos;s causes no order at all in sql query&lt;/p&gt;

&lt;p&gt;quick solution for this problem is change file \doctrine\Doctrine\Table.php, function processOrderBy() - around line 1134&lt;/p&gt;

&lt;p&gt;from:&lt;/p&gt;

&lt;p&gt;$e1 = explode(&apos;,&apos;, $orderBy);&lt;/p&gt;

&lt;p&gt;to:&lt;/p&gt;

&lt;p&gt;if( !is_array($orderBy)){&lt;br/&gt;
  $e1 = explode(&apos;,&apos;, $orderBy);&lt;br/&gt;
}else{&lt;br/&gt;
  $e1 = $orderBy;&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;hope it helps to someone&lt;/p&gt;

&lt;p&gt;best,&lt;br/&gt;
Wojtek&lt;/p&gt;</description>
                <environment>symfony - sfDoctrinePlugin, MySQL</environment>
            <key id="11360">DC-683</key>
            <summary>orderBy many field defined in yml files doesnt work</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/trivial.png">Trivial</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="wojtek">wojtek kolodziejczyk</reporter>
                        <labels>
                    </labels>
                <created>Fri, 14 May 2010 08:06:54 +0000</created>
                <updated>Tue, 8 Jun 2010 11:15:33 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 11:15:33 +0000</resolved>
                            <version>1.2.0</version>
                <version>1.2.1</version>
                <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-681] Command-line option rebuild-db is touching the models </title>
                <link>http://www.doctrine-project.org/jira/browse/DC-681</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;The command-line option &quot;rebuild-db&quot; is doing the following tasks: ( from the constructor )&lt;/p&gt;

&lt;p&gt;$this-&amp;gt;dropDb = new Doctrine_Task_DropDb($this-&amp;gt;dispatcher);&lt;br/&gt;
$this-&amp;gt;buildAll = new Doctrine_Task_BuildAll($this-&amp;gt;dispatcher);&lt;/p&gt;

&lt;p&gt;But the BuildAll tasks is executing three tasks including one which is regenerating the models. ( from the constructor )&lt;br/&gt;
$this-&amp;gt;models = new Doctrine_Task_GenerateModelsYaml($this-&amp;gt;dispatcher);&lt;br/&gt;
$this-&amp;gt;createDb = new Doctrine_Task_CreateDb($this-&amp;gt;dispatcher);&lt;br/&gt;
$this-&amp;gt;tables = new Doctrine_Task_CreateTables($this-&amp;gt;dispatcher);&lt;/p&gt;


&lt;p&gt;My suggestion is to replace the build-all in the rebuild-db task with just the following. This would make more sense.&lt;/p&gt;

&lt;p&gt;$this-&amp;gt;createDb = new Doctrine_Task_CreateDb($this-&amp;gt;dispatcher);&lt;br/&gt;
$this-&amp;gt;tables = new Doctrine_Task_CreateTables($this-&amp;gt;dispatcher);&lt;/p&gt;


</description>
                <environment></environment>
            <key id="11356">DC-681</key>
            <summary>Command-line option rebuild-db is touching the models </summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="lucard">Jerry Verhoef</reporter>
                        <labels>
                    </labels>
                <created>Thu, 13 May 2010 16:05:25 +0000</created>
                <updated>Tue, 8 Jun 2010 11:17:42 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 11:17:42 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Cli</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-678] Need case-insensitive checks for dupes in the $options[&apos;indexes&apos;] array</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-678</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;I ran into a bug where there were two duplicate indexes that Doctrine was trying to create. &lt;/p&gt;

&lt;p&gt;Not too sure what the cause is yet but this fix took care of the problem for me.&lt;/p&gt;

&lt;p&gt;Line 161 of Doctrine/Export/MySQL.php&lt;/p&gt;

&lt;p&gt;		// Case Insensitive checking for duplicate indexes...&lt;br/&gt;
		$dupes = array();&lt;br/&gt;
		foreach ($options&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;indexes&amp;#39;&amp;#93;&lt;/span&gt; as $key =&amp;gt; $index) {&lt;br/&gt;
			if (in_array(strtolower($key), $dupes)) &lt;/p&gt;
{
				unset($options[&apos;indexes&apos;][$key]);
			}
&lt;p&gt; else &lt;/p&gt;
{
				$dupes[] = strtolower($key);
			}
&lt;p&gt;		}&lt;br/&gt;
		unset($dupes);&lt;/p&gt;</description>
                <environment>PHP 5.3, OSX, APC</environment>
            <key id="11352">DC-678</key>
            <summary>Need case-insensitive checks for dupes in the $options[&apos;indexes&apos;] array</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="bzarzuela">Bryan Zarzuela</reporter>
                        <labels>
                    </labels>
                <created>Thu, 13 May 2010 06:37:01 +0000</created>
                <updated>Tue, 8 Jun 2010 11:26:05 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 11:26:05 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Import/Export</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>1</watches>
                        <comments>
                    <comment id="12936" author="jwage" created="Thu, 13 May 2010 08:10:27 +0000"  >&lt;p&gt;I don&apos;t think this is a good change. You should instead fix it by identifying why you have 2 indexes with the same name, instead of this hack.&lt;/p&gt;</comment>
                    <comment id="12942" author="bzarzuela" created="Thu, 13 May 2010 22:03:07 +0000"  >&lt;p&gt;I&apos;ll try to debug why there were two indexes named employeecode and employeeCode. I think there&apos;s a bug somewhere in the MySQL drivers where the case-conversions failed. &lt;/p&gt;

&lt;p&gt;Had no time yesterday as I was focused more on getting my work done than actually fixing the problem&lt;/p&gt;</comment>
                    <comment id="12943" author="bzarzuela" created="Thu, 13 May 2010 23:11:11 +0000"  >&lt;p&gt;If you do this in the base model, note the capital C in the employeeCode index:&lt;/p&gt;

&lt;p&gt;$this-&amp;gt;hasColumn(&apos;employeeCode&apos;, &apos;string&apos;, 11);&lt;br/&gt;
$this-&amp;gt;index(&apos;employeeCode&apos;, array(&apos;fields&apos; =&amp;gt; array(&apos;employeeCode&apos;)));&lt;/p&gt;

&lt;p&gt;It will result in this SQL statement for the table creation:&lt;/p&gt;

&lt;p&gt;CREATE TABLE employees (id BIGINT AUTO_INCREMENT, employeecode VARCHAR(11), first VARCHAR(50), last VARCHAR(50), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX employeeCode_idx (employeecode), INDEX employeecode_idx (employeecode), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB&lt;/p&gt;

&lt;p&gt;Note that it tries to create 2 indexes named employeeCode_idx and employeecode_idx.&lt;/p&gt;

&lt;p&gt;If I change the declaration to $this-&amp;gt;index(&apos;employeecode&apos;, array(&apos;fields&apos; =&amp;gt; array(&apos;employeeCode&apos;)));, then it works:&lt;/p&gt;

&lt;p&gt;CREATE TABLE employees (id BIGINT AUTO_INCREMENT, first VARCHAR(50), last VARCHAR(50), employeecode VARCHAR(11), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX employeecode_idx (employeecode), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB&lt;/p&gt;

&lt;p&gt;Still not sure what the cause is. I&apos;m not too familiar with the flow of the Export Drivers yet.&lt;/p&gt;</comment>
                    <comment id="12955" author="jwage" created="Fri, 14 May 2010 10:26:28 +0000"  >&lt;p&gt;I see, I think we have some problems when you have columns which are camel case. I would recommend using underscores to avoid any issues until this can be resolved.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-677] Incorrect property uset before Collection serialize</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-677</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;On line 155 (Doctrine/Collection.php) should unset &quot;referenceFiled&quot; property not &quot;reference_field&quot;. It causes problems after Collection unserialize.&lt;/p&gt;</description>
                <environment></environment>
            <key id="11345">DC-677</key>
            <summary>Incorrect property uset before Collection serialize</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="dbojdo">Daniel Bojdo</reporter>
                        <labels>
                    </labels>
                <created>Tue, 11 May 2010 07:34:04 +0000</created>
                <updated>Tue, 8 Jun 2010 11:27:13 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 11:27:13 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-675] Doctrine_Connection_Mssql charset problem</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-675</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Recently I got problems with converting UTF-8 data to iso ISO-8859-1 while trying to insert/update a Microsoft SQL Server database.&lt;br/&gt;
I wrote a task that exports data from an UTF-8 MySQL database to a latin1 Microsoft SQL Server database. When converting the data from UTF-8 to ISO-8859-1 the insert/update fails:&lt;/p&gt;

&lt;p&gt;SQLSTATE&lt;span class=&quot;error&quot;&gt;&amp;#91;HY000&amp;#93;&lt;/span&gt;: General error: trying to execute an empty query&lt;/p&gt;

&lt;p&gt;As i tracked the error down I realized, that the exception only occurs if I try to insert/update data with special characters like &quot;&#252;&quot;, &quot;&#246;&quot;, &quot;&#228;&quot;, &quot;&#223;&quot; etc.&lt;br/&gt;
The error&apos;s origin seems to lie in the Doctrine_Connection_Mssql class, more precisely in the replaceBoundParamsWithInlineValuesInQuery() method.&lt;br/&gt;
Debugging this method shows that after replacing a bound param with data containing a special character (see above), the replace action for the next bound param replaces the whole query string with an empty string. Therefore the parent class&apos;s method exec() throws an exception as it tries to execute an empty query.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;Task snippet:&lt;br/&gt;
// $src is UTF-8 data (MySQL DB)&lt;br/&gt;
// $dest ist latin1 data (MSSQL DB)&lt;/p&gt;

&lt;p&gt;$dest-&amp;gt;setZip($src-&amp;gt;getZip());&lt;br/&gt;
$dest-&amp;gt;setCity(iconv(&quot;UTF-8&quot;, &quot;ISO-8859-1//TRANSLIT&quot;, $src-&amp;gt;getCity());&lt;br/&gt;
$dest-&amp;gt;setStreet(iconv(&quot;UTF-8&quot;, &quot;ISO-8859-1//TRANSLIT&quot;, $src-&amp;gt;getStreet());&lt;br/&gt;
$dest-&amp;gt;save();&lt;/p&gt;

&lt;p&gt;RESULTING DQL: UPDATE table SET zip = ?, city = ?, street = ? WHERE id = ?;&lt;/p&gt;

&lt;p&gt;Params:&lt;br/&gt;
array(&lt;br/&gt;
    &apos;22307&apos;,&lt;br/&gt;
    &apos;M&#252;nchen&apos;,&lt;br/&gt;
    &apos;Dummystreet 18&apos;&lt;br/&gt;
    &apos;1&apos;&lt;br/&gt;
)&lt;/p&gt;

&lt;p&gt;After replaceBoundParamsWithInlineValuesInQuery() replaces param &apos;M&#252;nchen&apos;, the query string is replaced by an empty string in the following iteration.&lt;/p&gt;

&lt;p&gt;The root of the Problem seems to lie in the regex modifier &apos;u&apos; which treats the pattern as UTF-8 in the param replacements. Removing this modifier solves the problem for me. What purpose has this modifier?&lt;/p&gt;</description>
                <environment></environment>
            <key id="11342">DC-675</key>
            <summary>Doctrine_Connection_Mssql charset problem</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="deeky">Steve M&#252;ller</reporter>
                        <labels>
                    </labels>
                <created>Mon, 10 May 2010 07:58:14 +0000</created>
                <updated>Tue, 8 Jun 2010 11:52:28 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 11:52:28 +0000</resolved>
                                            <fixVersion>1.2.3</fixVersion>
                                        <due></due>
                    <votes>0</votes>
                        <watches>2</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-673] Doctrine_Export::dropForeignKey() doesn&apos;t format foreign key names</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-673</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Doctrine_Export::createForeignKey() formats foreign key names, but Doctrine_Export::dropForeignKey() doesn&apos;t. It is a problem.&lt;/p&gt;

&lt;p&gt;I tested following:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;echo &quot;&amp;lt;?php&lt;/p&gt;

&lt;p&gt;class addForeignKey extends Doctrine_Migration_Base&lt;br/&gt;
{&lt;br/&gt;
  public function up()&lt;/p&gt;
  &lt;div class=&quot;error&quot;&gt;&lt;span class=&quot;error&quot;&gt;Unknown macro: {    $this-&amp;gt;createForeignKey(&amp;#39;user&amp;#39;, &amp;#39;dotted.foreign.key&amp;#39;, array(      &amp;#39;local&amp;#39;        =&amp;gt; &amp;#39;category_id&amp;#39;,      &amp;#39;foreign&amp;#39;      =&amp;gt; &amp;#39;id&amp;#39;,      &amp;#39;foreignTable&amp;#39; =&amp;gt; &amp;#39;category&amp;#39;,    ));  }&lt;/span&gt; &lt;/div&gt;
&lt;p&gt;}&quot; &amp;gt; migrations/1_add_foreign_key.php&lt;/p&gt;

&lt;p&gt;echo &quot;&amp;lt;?php&lt;/p&gt;

&lt;p&gt;class removeForeignKey extends Doctrine_Migration_Base&lt;br/&gt;
{&lt;br/&gt;
  public function up()&lt;/p&gt;
  &lt;div class=&quot;error&quot;&gt;&lt;span class=&quot;error&quot;&gt;Unknown macro: {    $this-&amp;gt;dropForeignKey(&amp;#39;user&amp;#39;, &amp;#39;dotted.foreign.key&amp;#39;);  }&lt;/span&gt; &lt;/div&gt;
&lt;p&gt;}&quot; &amp;gt; migrations/2_add_foreign_key.php&lt;/p&gt;

&lt;p&gt;./doctrine migrate 1  # successful&lt;/p&gt;

&lt;p&gt;./doctrine migrate 2  # failed&lt;/p&gt;

&lt;p&gt;1 error(s) encountered during migration&lt;br/&gt;
=======================================&lt;br/&gt;
 Error #1 - SQLSTATE&lt;span class=&quot;error&quot;&gt;&amp;#91;42000&amp;#93;&lt;/span&gt;: Syntax error or access violation: 1103 Incorrect table name &apos;dotted&apos;. Failing Query: &quot;ALTER TABLE user DROP FOREIGN KEY dotted.foreign&quot;&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;I have a patch to fix this problem.&lt;/p&gt;</description>
                <environment>PHP 5.3.3-dev, mysql 5.1.41</environment>
            <key id="11340">DC-673</key>
            <summary>Doctrine_Export::dropForeignKey() doesn&apos;t format foreign key names</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="co3k">Kousuke Ebihara</reporter>
                        <labels>
                    </labels>
                <created>Mon, 10 May 2010 03:06:31 +0000</created>
                <updated>Tue, 8 Jun 2010 11:54:34 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 11:54:34 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Import/Export</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="12938" author="co3k" created="Thu, 13 May 2010 09:51:44 +0000"  >&lt;p&gt;&lt;a href=&quot;http://github.com/ebihara/doctrine1/commit/6ae3d28a44796dad13d8387b390515ad45fd26aa&quot; class=&quot;external-link&quot;&gt;http://github.com/ebihara/doctrine1/commit/6ae3d28a44796dad13d8387b390515ad45fd26aa&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I commited a patch to fix this issue to my fork.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10599" name="drop-foreign-key-does-not-format.diff" size="1829" author="co3k" created="Mon, 10 May 2010 03:06:31 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-671] Record could be saved, even tough a NotNull column is null</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-671</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Strange behavior: The record could be saved without getting validation exception even tough a NotNull column is empty. &lt;/p&gt;

&lt;p&gt;If you use Sqlite as mock driver you get validation exception. Test case is added into ticket! &lt;/p&gt;</description>
                <environment>OS X 10.6.3 -&amp;#xA0;php 5.3.1</environment>
            <key id="11338">DC-671</key>
            <summary>Record could be saved, even tough a NotNull column is null</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>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="dreamcocoa">Fabian Spillner</reporter>
                        <labels>
                    </labels>
                <created>Sun, 9 May 2010 17:13:28 +0000</created>
                <updated>Mon, 10 May 2010 04:09:05 +0000</updated>
                    <resolved>Sun, 9 May 2010 17:41:17 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Validators</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="12882" author="dreamcocoa" created="Sun, 9 May 2010 17:19:04 +0000"  >&lt;p&gt;there the test case (About filename: I wonder why there is same file (empty test) on the doctrine ticket tests - please rename this test case if I call it wrong) &lt;/p&gt;</comment>
                    <comment id="12883" author="jwage" created="Sun, 9 May 2010 17:32:25 +0000"  >&lt;p&gt;Do you have validation enabled? It is off by default.&lt;/p&gt;</comment>
                    <comment id="12884" author="dreamcocoa" created="Sun, 9 May 2010 17:40:01 +0000"  >&lt;p&gt;Ah! It works now! Thank you! It&apos;s new default behavior since 1.2? &lt;/p&gt;</comment>
                    <comment id="12885" author="dreamcocoa" created="Sun, 9 May 2010 17:41:17 +0000"  >&lt;p&gt;I forget to enable the attribute Doctrine_Core::ATTR_VALIDATE.&lt;/p&gt;</comment>
                    <comment id="12886" author="jwage" created="Sun, 9 May 2010 17:50:47 +0000"  >&lt;p&gt;No it has always been off by default.&lt;/p&gt;</comment>
                    <comment id="12889" author="dreamcocoa" created="Mon, 10 May 2010 04:09:05 +0000"  >&lt;p&gt;The reason of my confusion: &lt;/p&gt;

&lt;p&gt;On Symfony 1.2 the validation is enabled by default: &lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://trac.symfony-project.org/browser/branches/1.2/lib/plugins/sfDoctrinePlugin/config/config.php&quot; class=&quot;external-link&quot;&gt;http://trac.symfony-project.org/browser/branches/1.2/lib/plugins/sfDoctrinePlugin/config/config.php&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And nothing is talked about it: &lt;br/&gt;
&lt;a href=&quot;http://www.symfony-project.org/tutorial/1_4/en/whats-new#chapter_a2fae23c9403b0e9ec99806fccf6b53e_doctrine_integration&quot; class=&quot;external-link&quot;&gt;http://www.symfony-project.org/tutorial/1_4/en/whats-new#chapter_a2fae23c9403b0e9ec99806fccf6b53e_doctrine_integration&lt;/a&gt;&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10598" name="DC671TestCase.php" size="2744" author="dreamcocoa" created="Sun, 9 May 2010 17:19:04 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-670] Doctrine/Collection: toHierarchy() accepts not only NestedSet</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-670</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;I&apos;ve got it after trying to implement NestedSet+AjacencyList behaviour.&lt;/p&gt;</description>
                <environment></environment>
            <key id="11335">DC-670</key>
            <summary>Doctrine/Collection: toHierarchy() accepts not only NestedSet</summary>
                <type id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/improvement.png">Improvement</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="maxim.olenik">Maxim Olenik</reporter>
                        <labels>
                    </labels>
                <created>Sat, 8 May 2010 09:42:22 +0000</created>
                <updated>Tue, 8 Jun 2010 16:43:54 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 16:43:54 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Nested Set</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                    <attachment id="10597" name="0001-Doctrine-Collection-toHierarchy-accepts-not-only-Nes.patch" size="1125" author="maxim.olenik" created="Sat, 8 May 2010 09:42:22 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-669] listTableIndexes() return an empty array with doctrine-1.2.2</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-669</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;I&apos;ve a table A with 3 indexes. I would like to retrieve this list of indexes by using listTableIndexes() but I just get an empty array.&lt;/p&gt;

&lt;p&gt;I found the problem into listTableIndexes():&lt;br/&gt;
The $keyName and $nonUnique are set in lowercase in my case.&lt;br/&gt;
But the result of $indexes = $this-&amp;gt;conn-&amp;gt;fetchAssoc($query); have field names in both lower/upper case, e.g.:&lt;br/&gt;
&apos;Non_unique&apos; =&amp;gt; string &apos;1&apos; (length=1)&lt;br/&gt;
&apos;Key_name&apos; =&amp;gt; string &apos;module&apos; (length=6)&lt;/p&gt;

&lt;p&gt;But maybe that&apos;s a config problem from my part and the case of $keyName and $nonUnique should not be modified.&lt;/p&gt;</description>
                <environment>On linux fedora with MySQL 5.1.45</environment>
            <key id="11331">DC-669</key>
            <summary>listTableIndexes() return an empty array with doctrine-1.2.2</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="yokav">Christophe Beaujean</reporter>
                        <labels>
                    </labels>
                <created>Fri, 7 May 2010 08:31:17 +0000</created>
                <updated>Tue, 8 Jun 2010 11:55:16 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 11:55:16 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="12986" author="yokav" created="Mon, 17 May 2010 10:06:11 +0000"  >&lt;p&gt;Ref to &lt;br/&gt;
&lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-685&quot; class=&quot;external-link&quot;&gt;http://www.doctrine-project.org/jira/browse/DC-685&lt;/a&gt;&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-664] PATCH: Docrine_Record _isValueModified should not type check when comparing integers</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-664</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;The _isValueModified function in Record.php does the following for checking whether or not an integral value was modified:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;  ...&lt;br/&gt;
  } else if (in_array($type, array(&apos;integer&apos;, &apos;int&apos;)) &amp;amp;&amp;amp; is_numeric($old) &amp;amp;&amp;amp; is_numeric($new)) {&lt;br/&gt;
    return $old !== $new;&lt;br/&gt;
  ...&lt;br/&gt;
  } else {&lt;br/&gt;
    return $old !== $new;&lt;br/&gt;
       ...&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;This does not make sense, it implies strict type checking is always done for integers.&lt;br/&gt;
I think the first check (line 1533) should be done loosely so that a string &apos;123&apos; is equal to integer 123, and thereby such a field is not considered modified.&lt;/p&gt;</description>
                <environment></environment>
            <key id="11316">DC-664</key>
            <summary>PATCH: Docrine_Record _isValueModified should not type check when comparing integers</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="dennis.verspuij">Dennis Verspuij</reporter>
                        <labels>
                    </labels>
                <created>Tue, 4 May 2010 10:30:04 +0000</created>
                <updated>Tue, 8 Jun 2010 13:35:02 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 13:35:02 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Record</component>
                        <due></due>
                    <votes>1</votes>
                        <watches>1</watches>
                        <comments>
                    <comment id="12834" author="dennis.verspuij" created="Tue, 4 May 2010 10:31:39 +0000"  >&lt;p&gt;Attaching the simple patch to correct this.&lt;/p&gt;</comment>
                    <comment id="12939" author="jeanmonod" created="Thu, 13 May 2010 14:39:54 +0000"  >&lt;p&gt;This ticket seems to be a duplicate of this one: &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-550&quot; class=&quot;external-link&quot;&gt;http://www.doctrine-project.org/jira/browse/DC-550&lt;/a&gt;&lt;br/&gt;
Maybe we could close it... Seems to be fix in the 1.2.2&lt;/p&gt;</comment>
                    <comment id="12940" author="jeanmonod" created="Thu, 13 May 2010 15:18:33 +0000"  >&lt;p&gt;Oh no, I misunderstood the &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-550&quot; title=&quot;Cannot update record from one large integer to another large integer (severe problem for 32bit systems, due to the low upper limit of the int data type)&quot;&gt;&lt;del&gt;DC-550&lt;/del&gt;&lt;/a&gt;. In fact the problem was introduce when fixing the 550. The strict type checking is a regression that have been introduce in the 550. Before the values old and new were cast to int.&lt;/p&gt;
</comment>
                    <comment id="12941" author="jeanmonod" created="Thu, 13 May 2010 16:12:19 +0000"  >&lt;p&gt;This regression can be a real problem. With this, if we set an integer value to a record, then the record is set as modified even if the value was the same as before.&lt;br/&gt;
Here is a little test case to demonstrate the problem:&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-style: solid;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeHeader panelHeader&quot; style=&quot;border-bottom-width: 1px;border-bottom-style: solid;&quot;&gt;&lt;b&gt;TestCase for &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-664&quot; title=&quot;PATCH: Docrine_Record _isValueModified should not type check when comparing integers&quot;&gt;&lt;del&gt;DC-664&lt;/del&gt;&lt;/a&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;&amp;lt;?php
require_once(&apos;doctrine/lib/Doctrine.php&apos;);
&lt;span class=&quot;code-comment&quot;&gt;//require_once(dirname(__FILE__).&apos;/../../lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine.php&apos;);
&lt;/span&gt;spl_autoload_register(array(&apos;Doctrine&apos;, &apos;autoload&apos;));
$manager = Doctrine_Manager::getInstance();
$manager-&amp;gt;setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_ALL);
$conn = Doctrine_Manager::connection(&apos;mysql:&lt;span class=&quot;code-comment&quot;&gt;//root:root@localhost/test_doctrine&apos;);
&lt;/span&gt;echo &lt;span class=&quot;code-quote&quot;&gt;&quot;Connection is set up\n&quot;&lt;/span&gt;;

class Record &lt;span class=&quot;code-keyword&quot;&gt;extends&lt;/span&gt; Doctrine_Record {
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function setTableDefinition(){
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;setTableName(&apos;record&apos;);
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;hasColumn(&apos;number&apos;, &apos;integer&apos;);
    }
}

&lt;span class=&quot;code-keyword&quot;&gt;try&lt;/span&gt; {Doctrine::dropDatabases();}&lt;span class=&quot;code-keyword&quot;&gt;catch&lt;/span&gt;(Exception $e){} &lt;span class=&quot;code-comment&quot;&gt;// Drop &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; exist :-)
&lt;/span&gt;Doctrine::createDatabases();
Doctrine::createTablesFromArray(array(&apos;Record&apos;));
echo &lt;span class=&quot;code-quote&quot;&gt;&quot;Database table is create\n&quot;&lt;/span&gt;;

$record = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Record();
$record-&amp;gt;number = 5;
$record-&amp;gt;save();

$record = Doctrine::getTable(&apos;Record&apos;)-&amp;gt;createQuery()-&amp;gt;fetchOne();
$record-&amp;gt;number = 5;

echo &lt;span class=&quot;code-quote&quot;&gt;&quot;BEFORE:&quot;&lt;/span&gt;;
var_dump($record-&amp;gt;getModified(&lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;));

echo &lt;span class=&quot;code-quote&quot;&gt;&quot;AFTER:&quot;&lt;/span&gt;;
var_dump($record-&amp;gt;getModified());
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeHeader panelHeader&quot; style=&quot;border-bottom-width: 1px;&quot;&gt;&lt;b&gt;Output&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;Connection is set up
Database table is create
BEFORE:array(1) {
  [&lt;span class=&quot;code-quote&quot;&gt;&quot;number&quot;&lt;/span&gt;]=&amp;gt;
  string(1) &lt;span class=&quot;code-quote&quot;&gt;&quot;5&quot;&lt;/span&gt;
}
AFTHER:array(1) {
  [&lt;span class=&quot;code-quote&quot;&gt;&quot;number&quot;&lt;/span&gt;]=&amp;gt;
  &lt;span class=&quot;code-object&quot;&gt;int&lt;/span&gt;(5)
}

&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10590" name="Record.php.patch" size="681" author="dennis.verspuij" created="Tue, 4 May 2010 10:32:13 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-663] Doctrine_Table::createQuery creates a query with the default connection instead of the current connection</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-663</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;If we manually set a connection on the Doctrine_Table instance Doctrine silently ignores it when creating a Doctrine_Query instance through createQuery method&lt;/p&gt;

&lt;p&gt;$manager-&amp;gt;setConnection($defaultConnection);&lt;/p&gt;

&lt;p&gt;$table = Doctrine::getTable(&apos;Users&apos;)-&amp;gt;setConnection($newConnection);&lt;br/&gt;
$table-&amp;gt;createQuery();   // -&amp;gt; connection to $defaultConnection&lt;/p&gt;

&lt;p&gt;The code:&lt;/p&gt;

&lt;p&gt; public function createQuery($alias = &apos;&apos;)&lt;br/&gt;
    {&lt;br/&gt;
        if ( ! empty($alias)) &lt;/p&gt;
{
            $alias = &apos; &apos; . trim($alias);
        }

&lt;p&gt;        $class = $this-&amp;gt;getAttribute(Doctrine_Core::ATTR_QUERY_CLASS);&lt;/p&gt;

&lt;p&gt;        return Doctrine_Query::create(null, $class)                        &amp;lt;-- fix too quick for a patch &lt;img class=&quot;emoticon&quot; src=&quot;http://www.doctrine-project.org/jira/images/icons/emoticons/smile.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt; -&lt;del&gt;&amp;gt; return Doctrine_Query::create($this&lt;/del&gt;&amp;gt;_conn, $class)&lt;br/&gt;
            &lt;del&gt;&amp;gt;from($this&lt;/del&gt;&amp;gt;getComponentName() . $alias);&lt;br/&gt;
    }&lt;/p&gt;

</description>
                <environment>Ubuntu 9.10</environment>
            <key id="11315">DC-663</key>
            <summary>Doctrine_Table::createQuery creates a query with the default connection instead of the current connection</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="guilhermeblanco">Guilherme Blanco</assignee>
                                <reporter username="catacgc">Costache Catalin</reporter>
                        <labels>
                    </labels>
                <created>Tue, 4 May 2010 05:19:10 +0000</created>
                <updated>Tue, 28 Sep 2010 08:37:12 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 16:12:33 +0000</resolved>
                            <version>1.2.1</version>
                <version>1.2.2</version>
                <version>1.2.3</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Query</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="14482" author="cberg" created="Tue, 28 Sep 2010 08:37:12 +0000"  >&lt;p&gt;When using Table classes generated with the latest Symfony 1.4 version (1.4.8) the table gets bound to a specific connection, but Doctrine still uses the default connection. &lt;/p&gt;

&lt;p&gt;Using the above mentioned quick fix - replacing $this-&amp;gt;_conn with null - everything works as it should.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-662] Obsolete Doctrine::getTable() call in Template_Listener_Sluggable</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-662</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Subj. Found in &lt;ins&gt;Doctrine/Template/Listener/Sluggable.php&lt;/ins&gt; on line 165th:&lt;/p&gt;
&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;          $table = Doctrine::getTable($parentTable[$i]);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Should be replaced with:&lt;/p&gt;
&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;          $table = Doctrine_Core::getTable($parentTable[$i]);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</description>
                <environment></environment>
            <key id="11314">DC-662</key>
            <summary>Obsolete Doctrine::getTable() call in Template_Listener_Sluggable</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="ixti">Aleksey V. Zapprov</reporter>
                        <labels>
                    </labels>
                <created>Tue, 4 May 2010 04:46:55 +0000</created>
                <updated>Tue, 8 Jun 2010 13:35:48 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 13:35:48 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Sluggable</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-658] _setPage in Doctrine_Pager is set to Private method</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-658</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;The method _setPage is set as private. This will make extending the Doctrine_Pager unnecessary complex.&lt;/p&gt;</description>
                <environment></environment>
            <key id="11306">DC-658</key>
            <summary>_setPage in Doctrine_Pager is set to Private method</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/trivial.png">Trivial</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="guilhermeblanco">Guilherme Blanco</assignee>
                                <reporter username="lucard">Jerry Verhoef</reporter>
                        <labels>
                    </labels>
                <created>Sat, 1 May 2010 14:02:54 +0000</created>
                <updated>Tue, 8 Jun 2010 16:15:37 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 16:15:37 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Pager</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-657] EXISTS not correctly parsed if there&apos;s no space between keyword and the open bracket</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-657</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Executing a query that has an EXISTS in the WHERE clause without a space before its bracket make Doctrine ignore the EXISTS part and output it as is, this cause problems because, as an example, table aliases are not correctly resolved.&lt;/p&gt;

&lt;p&gt;For example this works&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-sql&quot;&gt;&lt;span class=&quot;code-keyword&quot;&gt;SELECT&lt;/span&gt; * &lt;span class=&quot;code-keyword&quot;&gt;FROM&lt;/span&gt; TableA a &lt;span class=&quot;code-keyword&quot;&gt;WHERE&lt;/span&gt; EXISTS (&lt;span class=&quot;code-keyword&quot;&gt;SELECT&lt;/span&gt; id &lt;span class=&quot;code-keyword&quot;&gt;FROM&lt;/span&gt; TableB b &lt;span class=&quot;code-keyword&quot;&gt;WHERE&lt;/span&gt; b.a = a.id)
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;while this doesn&apos;t&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-sql&quot;&gt;&lt;span class=&quot;code-keyword&quot;&gt;SELECT&lt;/span&gt; * &lt;span class=&quot;code-keyword&quot;&gt;FROM&lt;/span&gt; TableA a &lt;span class=&quot;code-keyword&quot;&gt;WHERE&lt;/span&gt; EXISTS(&lt;span class=&quot;code-keyword&quot;&gt;SELECT&lt;/span&gt; id &lt;span class=&quot;code-keyword&quot;&gt;FROM&lt;/span&gt; TableB b &lt;span class=&quot;code-keyword&quot;&gt;WHERE&lt;/span&gt; b.a = a.id)
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I found the error &lt;b&gt;could be&lt;/b&gt; in &lt;tt&gt;Doctrine/Query/Where.php&lt;/tt&gt; line 49:&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-javascript&quot;&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (count($terms) &amp;gt; 1) {
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (substr($where, 0, 6) == &apos;EXISTS&apos;) {
                &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;parseExists($where, &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;);
            } elseif (substr($where, 0, 10) == &apos;NOT EXISTS&apos;) {
                &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;parseExists($where, &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;);
            }
        }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;could be modified with:&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-javascript&quot;&gt;            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (substr($where, 0, 6) == &apos;EXISTS&apos;) {
                &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;parseExists($where, &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;);
            } elseif (substr($where, 0, 10) == &apos;NOT EXISTS&apos;) {
                &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;parseExists($where, &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;);
            }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;to solve the problem. As a plus, since one could write &quot;NOT     EXISTS&quot; (for some reason), I think it&apos;s better to write it this way:&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-javascript&quot;&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (substr($where, 0, 6) == &apos;EXISTS&apos;) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;parseExists($where, &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;);
        } elseif (preg_match(&apos;/^NOT\s+EXISTS\b/i&apos;, $where) !== 0) {
            &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;parseExists($where, &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;);
        }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Hope this helps.&lt;/p&gt;

&lt;p&gt;PS. Please add php code formatter &lt;img class=&quot;emoticon&quot; src=&quot;http://www.doctrine-project.org/jira/images/icons/emoticons/smile.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</description>
                <environment>Mac OS X 10.6.3, MySQL 5.1.34, PHP 5.2.10</environment>
            <key id="11304">DC-657</key>
            <summary>EXISTS not correctly parsed if there&apos;s no space between keyword and the open bracket</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="guilhermeblanco">Guilherme Blanco</assignee>
                                <reporter username="bobo_italy">Andrea Baron</reporter>
                        <labels>
                    </labels>
                <created>Sat, 1 May 2010 09:41:18 +0000</created>
                <updated>Tue, 8 Jun 2010 16:47:04 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 16:47:04 +0000</resolved>
                            <version>1.2.1</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Query</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-656] Endless loop when using HYDRATE_SINGLE_SCALAR and Oracle OCI adapter Doctrine</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-656</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Following loop inside Doctrine_Hydrator_SingleScalarDriver never terminates since fetchColumn inside Doctrine_Adapter_Statement_Oracle never returns FALSE.&lt;/p&gt;

&lt;p&gt;while (($val = $stmt-&amp;gt;fetchColumn()) !== false) &lt;/p&gt;
{
            $result[] = $val;
}

Below is the patch for Doctrine_Adapter_Statement_Oracle 
----------------------------------------------------------------------------------------------------------------------------------
Index: Oracle.php
===================================================================
--- Oracle.php	(revision 7546)
+++ Oracle.php	(working copy)
@@ -398,7 +398,7 @@
             return false;
         }
&lt;p&gt;         $row = $this-&amp;gt;fetch(Doctrine_Core::FETCH_NUM);&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;return $row&lt;span class=&quot;error&quot;&gt;&amp;#91;$columnIndex&amp;#93;&lt;/span&gt;;&lt;br/&gt;
+        return ($row===false) ? false : $row&lt;span class=&quot;error&quot;&gt;&amp;#91;$columnIndex&amp;#93;&lt;/span&gt;;&lt;br/&gt;
     }&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;     /**&lt;br/&gt;
----------------------------------------------------------------------------------------------------------------------------------&lt;/p&gt;</description>
                <environment></environment>
            <key id="11292">DC-656</key>
            <summary>Endless loop when using HYDRATE_SINGLE_SCALAR and Oracle OCI adapter Doctrine</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="vadik56">vadik56</reporter>
                        <labels>
                    </labels>
                <created>Thu, 29 Apr 2010 16:36:13 +0000</created>
                <updated>Tue, 8 Jun 2010 13:40:09 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 13:40:09 +0000</resolved>
                            <version>1.2.2</version>
                <version>1.2.3</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Connection</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="13178" author="jwage" created="Tue, 8 Jun 2010 13:40:09 +0000"  >&lt;p&gt;This appears to be already fixed by &lt;a href=&quot;http://trac.doctrine-project.org/changeset/7578&quot; class=&quot;external-link&quot;&gt;http://trac.doctrine-project.org/changeset/7578&lt;/a&gt;&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-651] [PATCH] Doctrine_Record::option(&apos;orderBy&apos;, ...) of join&apos;s right side being applied to refTable in m2m relationship</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-651</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;When using the &lt;tt&gt;Doctrine_Record::option(&apos;orderBy&apos;, ...)&lt;/tt&gt; feature on a table definition, where that table is the target of a many-to-many join, the specified orderBy columns are applied to the relation table&apos;s alias. So for example, given the following definitions:&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 User &lt;span class=&quot;code-keyword&quot;&gt;extends&lt;/span&gt; Doctrine_Record {
  &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function setTableDefinition() {
    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;hasColumn(&apos;uid&apos;, &apos;integer&apos;, &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;, array(&apos;primary&apos; =&amp;gt; &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;));
    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;option(&apos;orderBy&apos;, &apos;uid&apos;);
  }

  &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function setUp() {
    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;hasMany(&apos;Group as groups&apos;, array(&apos;refClass&apos; =&amp;gt; &apos;UserGroup&apos;, &apos;local&apos; =&amp;gt; &apos;user_uid&apos;, &apos;foreign&apos; =&amp;gt; &apos;group_id&apos;));
  }
}

class Group &lt;span class=&quot;code-keyword&quot;&gt;extends&lt;/span&gt; Doctrine_Record {
  &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function setTableDefinition() {
    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;hasColumn(&apos;gid&apos;, &apos;integer&apos;, &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;, array(&apos;primary&apos; =&amp;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 setUp() {
    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;hasMany(&apos;User as users&apos;, array(&apos;refClass&apos; =&amp;gt; &apos;UserGroup&apos;, &apos;local&apos; =&amp;gt; &apos;group_gid&apos;, &apos;foreign&apos; =&amp;gt; &apos;user_id&apos;));
  }
}

class UserGroup &lt;span class=&quot;code-keyword&quot;&gt;extends&lt;/span&gt; Doctrine_Record {
  &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function setTableDefinition() {
    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;hasColumn(&apos;user_uid&apos;, &apos;integer&apos;, &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;, array(&apos;primary&apos; =&amp;gt; &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;));
    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;hasColumn(&apos;group_gid&apos;, &apos;integer&apos;, &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;, array(&apos;primary&apos; =&amp;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 setUp() {
    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;hasOne(&apos;User as user&apos;, array(&apos;local&apos; =&amp;gt; &apos;user_uid&apos;, &apos;foreign&apos; =&amp;gt; &apos;uid&apos;));
    $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;hasOne(&apos;Group as group&apos;, array(&apos;local&apos; =&amp;gt; &apos;group_gid&apos;, &apos;foreign&apos; =&amp;gt; &apos;gid&apos;));
  }
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;the following queries:&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 = Doctrine_Query::create()
  -&amp;gt;select(&apos;u.*&apos;)
  -&amp;gt;from(&apos;User u&apos;)
  -&amp;gt;leftJoin(&apos;u.groups g WITH g.gid=?&apos;, 1);
echo $query-&amp;gt;getSqlQuery() . &lt;span class=&quot;code-quote&quot;&gt;&quot;\n&quot;&lt;/span&gt;;

$query = Doctrine_Query::create()
  -&amp;gt;select(&apos;g.*&apos;)
  -&amp;gt;from(&apos;Group g&apos;)
  -&amp;gt;leftJoin(&apos;g.users u WITH u.uid=?&apos;, 1);
echo $query-&amp;gt;getSqlQuery() . &lt;span class=&quot;code-quote&quot;&gt;&quot;\n&quot;&lt;/span&gt;;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;will output the following:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;SELECT u.uid AS u__uid FROM user u LEFT JOIN user_group u2 ON (u.uid = u2.user_uid) LEFT JOIN group g ON g.gid = u2.group_id AND (g.gid = ?) ORDER BY u.uid&lt;br/&gt;
SELECT g.gid AS g__gid FROM group g LEFT JOIN user_group u2 ON (g.gid = u2.group_gid) LEFT JOIN user u ON u.uid = u2.user_id AND (u.uid = ?) ORDER BY u.uid, u2.uid&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;The &lt;tt&gt;orderBy&lt;/tt&gt; &lt;tt&gt;option()&lt;/tt&gt; call is applied to the &lt;tt&gt;User&lt;/tt&gt; definition. The SQL for the first query is correct (where &lt;tt&gt;User&lt;/tt&gt; is on the left side of the join). The SQL for the second query (where &lt;tt&gt;User&lt;/tt&gt; is on the right-most side of the join), however, is obviously incorrect (&lt;tt&gt;UserGroup&lt;/tt&gt; doesn&apos;t even have a &lt;tt&gt;uid&lt;/tt&gt; column). Basically, &lt;tt&gt;User&lt;/tt&gt;&apos;s &lt;tt&gt;orderBy&lt;/tt&gt; option is being applied to both the &lt;tt&gt;User&lt;/tt&gt; table and its respective reference table, &lt;tt&gt;UserGroup&lt;/tt&gt;, when it is the target of a join.&lt;/p&gt;

&lt;p&gt;After digging through the source for a while, I believe I&apos;ve come up with a patch for this issue (which should be checked by someone more knowledgeable of Doctrine&apos;s internals). Basically, in the &lt;tt&gt;Doctrine_Query::buildSqlQuery()&lt;/tt&gt; function, a call is made to &lt;tt&gt;Doctrine_Relation::getOrderByStatement()&lt;/tt&gt; with the reference table (&lt;tt&gt;UserGroup&lt;/tt&gt;)&apos;s alias (&lt;tt&gt;u2&lt;/tt&gt;), which in turn makes a call to &lt;tt&gt;Doctrine_Table::getOrderByStatement()&lt;/tt&gt; on the referenced table (&lt;tt&gt;User&lt;/tt&gt;), filling in the &lt;tt&gt;ORDER BY&lt;/tt&gt; clause with &lt;tt&gt;User&lt;/tt&gt; columns using &lt;tt&gt;UserGroup&lt;/tt&gt;&apos;s alias. My solution was to reorder the logic so that the test for a reference class is made before the initial call to &lt;tt&gt;getOrderByStatement()&lt;/tt&gt; is made. It seems to work against my test case and the test cases in the repository. I&apos;ll post my patch momentarily.&lt;/p&gt;

&lt;p&gt;This bug was first mentioned in the comments in &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-313&quot; title=&quot;Ordering m2m relationship with column from related table (with orderBy option)&quot;&gt;DC-313&lt;/a&gt;, but the original ticket comes across as more of a feature request for the &lt;tt&gt;hasMany()&lt;/tt&gt; &lt;tt&gt;orderBy&lt;/tt&gt; feature.&lt;/p&gt;</description>
                <environment>CentOS 5.4&lt;br/&gt;
PHP 5.3.2&lt;br/&gt;
MySQL 5.1.44, for unknown-linux-gnu (x86_64)</environment>
            <key id="11270">DC-651</key>
            <summary>[PATCH] Doctrine_Record::option(&apos;orderBy&apos;, ...) of join&apos;s right side being applied to refTable in m2m relationship</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</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="suhock">suhock</reporter>
                        <labels>
                    </labels>
                <created>Mon, 26 Apr 2010 12:22:21 +0000</created>
                <updated>Wed, 31 Aug 2011 12:43:09 +0000</updated>
                                    <version>1.2.2</version>
                <version>1.2.3</version>
                                <fixVersion>1.2.2</fixVersion>
                <fixVersion>1.2.3</fixVersion>
                <fixVersion>1.2.4</fixVersion>
                                <component>Query</component>
                <component>Relations</component>
                        <due></due>
                    <votes>2</votes>
                        <watches>4</watches>
                        <comments>
                    <comment id="12750" author="suhock" created="Mon, 26 Apr 2010 12:45:12 +0000"  >&lt;p&gt;attached a test case for this bug&lt;/p&gt;</comment>
                    <comment id="12751" author="suhock" created="Mon, 26 Apr 2010 13:01:03 +0000"  >&lt;p&gt;patch against /branches/1.2 HEAD (should also work apply to 1.2.2 tag)&lt;/p&gt;</comment>
                    <comment id="14179" author="dordille" created="Mon, 30 Aug 2010 17:22:44 +0000"  >&lt;p&gt;I can confirm this as an issue.  However I don&apos;t think the above patch adequately fixes the problem it seems like with it an order by is still added for the ref column however the relation alias is lost.&lt;/p&gt;

&lt;p&gt;My query with the patch became&lt;br/&gt;
SELECT g.gid AS g__gid FROM group g LEFT JOIN user_group u2 ON (g.gid = u2.group_gid) LEFT JOIN user u ON u.uid = u2.user_id AND (u.uid = ?) ORDER BY u.uid, uid &lt;/p&gt;

&lt;p&gt;I made an another patch that prevents this extra order by clause from being added and have attached it.&lt;/p&gt;
</comment>
                    <comment id="14428" author="suhock" created="Tue, 21 Sep 2010 08:53:25 +0000"  >&lt;p&gt;I tried out the new patch (Query_orderby_relation.diff), but it provides a reversed diff (patching goes from a patched version to the original). After applying it manually, it fails the provided test case and several additional test cases from the repository.&lt;/p&gt;

&lt;p&gt;The original patch DOES pass the provided test case, when applied against 1.2.2, 1.2.3, or the 1.2 branch from the repository. It does not pass, however, Doctrine_Query_Orderby_TestCase. As the previous poster mentioned, it fails to resolve aliases in instances where the &apos;orderBy&apos; option is specified in a relation definition.&lt;/p&gt;

&lt;p&gt;I deleted the original patch and am providing a revised patch (Ticket_DC651.patch) against branch 1.2 HEAD (also works with 1.2.3), which fixes this issue. It passes all working test cases, including Doctrine_Query_Orderby_TestCase and DC651TestCase.&lt;/p&gt;</comment>
                    <comment id="16406" author="deraujoj" created="Wed, 31 Aug 2011 12:43:08 +0000"  >&lt;p&gt;I had this issue recently on a application I&apos;m working on as described the oderBy option was applied on the joined table on a column that even doesn&apos;t exist in it. I used the DC651 patch provided and it solved the issue, so far I haven&apos;t seen any side effect to it. &lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10585" name="DC651TestCase.php" size="3335" author="suhock" created="Mon, 26 Apr 2010 12:45:12 +0000" />
                    <attachment id="10751" name="Query_orderBy_relation.diff" size="1122" author="dordille" created="Mon, 30 Aug 2010 17:22:56 +0000" />
                    <attachment id="10806" name="Ticket_DC651.patch" size="1448" author="suhock" created="Tue, 21 Sep 2010 08:53:25 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-650] SoftDelete sets &quot;default&quot; =&gt; null for deleted_at field, causing MSSQL to silently create a Default Constraint which in turns causes Migrations to fail when reverting</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-650</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;When MSSQL receives even just a default value of null it still creates a default constraint. Said constraint prevents doctrine from removing the deleted_at field in migrations (due to the dependency on the constraint).&lt;/p&gt;

&lt;p&gt;Removing &quot;default&quot; =&amp;gt; null prevents the silent creation of the constraint.&lt;/p&gt;

&lt;p&gt;I have no machine to test the effects of this on MySQL. I would imagine that it would not materially affect MySQL as the default values are never used anyways (hence the default value of null).&lt;/p&gt;

&lt;p&gt;Attached is a patch to fix the behavior (for rev 7544 in /branches/1.2)&lt;/p&gt;


&lt;p&gt;&amp;#8212;&lt;/p&gt;

&lt;p&gt;If one is running into problems with migrations being unable to move backwards due to default constraints on SoftDelete columns, one can run the following T-SQL script to remove all default value constraints from a database (EVEN THOSE YOU SET MANUALLY, USE WITH CAUTION):&lt;/p&gt;

&lt;p&gt;{{&lt;br/&gt;
&amp;#8211; This script removes ALL default constraints&lt;/p&gt;

&lt;p&gt;USE YOURDATABASENAMEHERE;&lt;/p&gt;

&lt;p&gt;Declare @name nvarchar(155)&lt;br/&gt;
Declare @table nvarchar(155)&lt;br/&gt;
Declare @sql nvarchar(1000)&lt;/p&gt;

&lt;p&gt;&amp;#8211; find constraint names&lt;br/&gt;
DECLARE default_constraints CURSOR FOR&lt;br/&gt;
SELECT&lt;br/&gt;
	object.name,&lt;br/&gt;
	parent.name&lt;br/&gt;
FROM&lt;br/&gt;
	sys.objects AS object&lt;br/&gt;
	LEFT JOIN sys.objects AS parent ON object.parent_object_id = parent.object_id&lt;br/&gt;
WHERE&lt;br/&gt;
	object.type_desc LIKE &apos;%CONSTRAINT&apos;&lt;br/&gt;
    AND object.type_desc LIKE &apos;DEFAULT_CONSTRAINT&apos;&lt;/p&gt;

&lt;p&gt;OPEN default_constraints&lt;/p&gt;

&lt;p&gt;FETCH NEXT FROM default_constraints INTO @name, @table&lt;/p&gt;

&lt;p&gt;WHILE @@FETCH_STATUS = 0&lt;br/&gt;
BEGIN&lt;br/&gt;
	IF NOT @name IS NULL&lt;br/&gt;
	BEGIN&lt;br/&gt;
		SELECT @sql = &apos;ALTER TABLE &lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39; + @table + &amp;#39;&amp;#93;&lt;/span&gt; DROP CONSTRAINT &lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39; + @name + &amp;#39;&amp;#93;&lt;/span&gt;;&apos;&lt;br/&gt;
		--PRINT @sql&lt;br/&gt;
		EXECUTE sp_executesql @sql&lt;br/&gt;
	END&lt;/p&gt;

&lt;p&gt;	FETCH NEXT FROM default_constraints INTO @name, @table&lt;br/&gt;
END&lt;br/&gt;
CLOSE default_constraints&lt;br/&gt;
DEALLOCATE default_constraints&lt;br/&gt;
}}&lt;/p&gt;</description>
                <environment>PHP 5.2.11, Windows 7, Sql Server 2005, php_mssql extension</environment>
            <key id="11269">DC-650</key>
            <summary>SoftDelete sets &quot;default&quot; =&gt; null for deleted_at field, causing MSSQL to silently create a Default Constraint which in turns causes Migrations to fail when reverting</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="dcousineau">Daniel Cousineau</reporter>
                        <labels>
                    </labels>
                <created>Mon, 26 Apr 2010 12:09:13 +0000</created>
                <updated>Tue, 8 Jun 2010 13:47:08 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 13:47:08 +0000</resolved>
                            <version>1.2.0-ALPHA1</version>
                <version>1.2.0-ALPHA2</version>
                <version>1.2.0-ALPHA3</version>
                <version>1.2.0-BETA1</version>
                <version>1.2.0-BETA2</version>
                <version>1.2.0-BETA3</version>
                <version>1.2.0-RC1</version>
                <version>1.2.0</version>
                <version>1.2.1</version>
                <version>1.2.2</version>
                <version>1.2.3</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Behaviors</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="12749" author="dcousineau" created="Mon, 26 Apr 2010 12:12:04 +0000"  >&lt;p&gt;I should also note this affects not only rollbacks, but any sort of ability to drop a deleted_at column (say, removing the SoftDelete behavior)&lt;/p&gt;</comment>
                    <comment id="12765" author="craigmarvelley" created="Tue, 27 Apr 2010 06:29:48 +0000"  >&lt;p&gt;This is related to an issue I reported a month or so ago - &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-584&quot; class=&quot;external-link&quot;&gt;http://www.doctrine-project.org/jira/browse/DC-584&lt;/a&gt;. A solution I proposed there was to allow Doctrine to name constraints so they can be referenced and dropped later. If that were in place, the SoftDelete behaviour could manage the constraint itself?&lt;/p&gt;</comment>
                    <comment id="12768" author="dcousineau" created="Tue, 27 Apr 2010 10:41:46 +0000"  >&lt;p&gt;Craig, It maybe would if Doctrine were creating the default constraints itself. If Doctrine doesn&apos;t handle the default constraints then naming has no effect as MSSQL will silently create said constraint.&lt;/p&gt;

&lt;p&gt;And now that I think of it, this issue is going to crop up any and every time you use default values in MSSQL. Perhaps it would be best to consider this ticket more of a cleanup (the behavior isn&apos;t using default values so there&apos;s no point in creating the constraint anyways) and side effect of the problems listed in &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-584&quot; title=&quot;MSSQL Server: Cannot alter / drop columns which have indexes or constraints applied to them&quot;&gt;&lt;del&gt;DC-584&lt;/del&gt;&lt;/a&gt; which should  be the primary focus.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10584" name="fix_softdelete_mssql.diff" size="468" author="dcousineau" created="Mon, 26 Apr 2010 12:09:13 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-647] Error in Doctrine_Manager#_buildDsnPartsArray()</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-647</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;The method Doctrine_Manager#_buildDsnPartsArray() ultimately relies on PHP&apos;s native parse_url().  This method, according to the PHP documentation does not parse unix_sockets in the DSN, so the following code will not find the unix_socket because parse_url only finds at most (&lt;a href=&quot;http://us2.php.net/parse_url&quot; class=&quot;external-link&quot;&gt;http://us2.php.net/parse_url&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;scheme&lt;br/&gt;
host&lt;br/&gt;
port&lt;br/&gt;
user&lt;br/&gt;
pass&lt;br/&gt;
path&lt;br/&gt;
query - after the question mark ?&lt;br/&gt;
fragment - after the hashmark #&lt;/p&gt;

&lt;p&gt;// silence any warnings&lt;br/&gt;
        $parts = @parse_url($dsn);&lt;/p&gt;

&lt;p&gt;        $names = array(&apos;dsn&apos;, &apos;scheme&apos;, &apos;host&apos;, &apos;port&apos;, &apos;user&apos;, &apos;pass&apos;, &apos;path&apos;, &apos;query&apos;, &apos;fragment&apos;, &apos;unix_socket&apos;);&lt;/p&gt;

&lt;p&gt;        foreach ($names as $name) {&lt;br/&gt;
            if ( ! isset($parts&lt;span class=&quot;error&quot;&gt;&amp;#91;$name&amp;#93;&lt;/span&gt;)) &lt;/p&gt;
{
                $parts[$name] = null;
            }
&lt;p&gt;        }&lt;/p&gt;

&lt;p&gt;It would appear that in order to support unix sockets we have to use parsePdoDsn() instead but this is not clear because of parseDsn() which also claims to be able to find the unix_socket.  I would suggest removing &apos;unix_socket&apos; from the $names array so it is clear a unix_socket cannot be represented in the normal Dsn, but only a PdoDsn. &lt;/p&gt;</description>
                <environment></environment>
            <key id="11263">DC-647</key>
            <summary>Error in Doctrine_Manager#_buildDsnPartsArray()</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="drak">Karma Dordrak (Drak)</reporter>
                        <labels>
                    </labels>
                <created>Sat, 24 Apr 2010 01:18:00 +0000</created>
                <updated>Tue, 8 Jun 2010 13:57:17 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 13:57:17 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-641] undefined method Doctrine_Manager::getExtensionsClasses()</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-641</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;On line 589 in Doctrine_Core:&lt;br/&gt;
public static function getExtensionsClasses()&lt;/p&gt;
    {
        return Doctrine_Manager::getInstance()-&amp;gt;getExtensionsClasses();
    }
&lt;p&gt;In manager method getExtensionsClasses() doesn&apos;t exist.&lt;/p&gt;</description>
                <environment></environment>
            <key id="11253">DC-641</key>
            <summary>undefined method Doctrine_Manager::getExtensionsClasses()</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="snapshot">Witold Wasiczko</reporter>
                        <labels>
                    </labels>
                <created>Wed, 21 Apr 2010 11:44:20 +0000</created>
                <updated>Tue, 8 Jun 2010 14:07:00 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 14:07:00 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                        <due></due>
                    <votes>0</votes>
                        <watches>1</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-626] Subqueries in HAVING</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-626</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Adds support for subqueries in HAVING.&lt;/p&gt;</description>
                <environment></environment>
            <key id="11208">DC-626</key>
            <summary>Subqueries in HAVING</summary>
                <type id="2" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/newfeature.png">New Feature</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="ian">Ian Banfield</reporter>
                        <labels>
                    </labels>
                <created>Sun, 11 Apr 2010 10:47:01 +0000</created>
                <updated>Tue, 8 Jun 2010 15:23:24 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 15:23:24 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                        <due></due>
                    <votes>0</votes>
                        <watches>1</watches>
                                <attachments>
                    <attachment id="10565" name="patch.diff" size="803" author="ian" created="Sun, 11 Apr 2010 10:47:01 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-621] Doctrine_Inflector :: urlize changed behaviour</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-621</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;before when using the sluggable behavior the Doctrine_Inflector :: urlize function changed &quot;cat&#233;gorie 1&quot; to &quot;categorie-1&quot;&lt;br/&gt;
since doctrine 1.2.2 &quot;cat&#233;gorie 1&quot; becomes &quot;categorie-aa&quot;&lt;/p&gt;
</description>
                <environment></environment>
            <key id="11181">DC-621</key>
            <summary>Doctrine_Inflector :: urlize changed behaviour</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="groenewege">Gunther Groenewege</reporter>
                        <labels>
                    </labels>
                <created>Wed, 7 Apr 2010 05:59:07 +0000</created>
                <updated>Tue, 8 Jun 2010 08:50:15 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 08:50:15 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Sluggable</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="13134" author="pavel.campr" created="Tue, 8 Jun 2010 04:14:13 +0000"  >&lt;p&gt;I see a bug here:&lt;br/&gt;
Inflector.php, line 221:&lt;br/&gt;
{{          &apos;&#197;&apos;=&amp;gt;&apos;Aa&apos;,&apos;&#198;&apos;=&amp;gt;&apos;Ae&apos;,&apos;&#216;&apos;=&amp;gt;&apos;O&apos;,&apos;&#230;&apos;=&amp;gt;&apos;a&apos;,&apos;&#248;&apos;=&amp;gt;&apos;o&apos;,&apos;&#229;&apos;,&apos;aa&apos;}}&lt;/p&gt;

&lt;p&gt;probably, there is &lt;tt&gt;=&amp;gt;&lt;/tt&gt; missing and should be:&lt;/p&gt;

&lt;p&gt;{{          &apos;&#197;&apos;=&amp;gt;&apos;Aa&apos;,&apos;&#198;&apos;=&amp;gt;&apos;Ae&apos;,&apos;&#216;&apos;=&amp;gt;&apos;O&apos;,&apos;&#230;&apos;=&amp;gt;&apos;a&apos;,&apos;&#248;&apos;=&amp;gt;&apos;o&apos;,&apos;&#229;&apos;=&amp;gt;&apos;aa&apos;}}&lt;/p&gt;

&lt;p&gt;now, character &apos;0&apos; is replaced by &apos;&#229;&apos; and &apos;1&apos; is replaced by &apos;aa&apos;&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-620] Unserialize does not add entity to the table entitymap</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-620</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Hello,&lt;/p&gt;

&lt;p&gt;Considering this test script:&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;&lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (!file_exists(&lt;span class=&quot;code-quote&quot;&gt;&quot;/tmp/serialize.doctrine&quot;&lt;/span&gt;))
{
  $a = Address::getById(1);
  $b = Address::getById(2);
  $c = Address::getById(3);
  $d = Address::getById(4);
  print &lt;span class=&quot;code-quote&quot;&gt;&quot;Serialize using oid=&quot;&lt;/span&gt; . $d-&amp;gt;getOid() . &lt;span class=&quot;code-quote&quot;&gt;&quot;\n&quot;&lt;/span&gt;;
  file_put_contents(&lt;span class=&quot;code-quote&quot;&gt;&quot;/tmp/serialize.doctrine&quot;&lt;/span&gt;, serialize($d));
}
&lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt;
{
  $d = unserialize(file_get_contents(&lt;span class=&quot;code-quote&quot;&gt;&quot;/tmp/serialize.doctrine&quot;&lt;/span&gt;));
  print &lt;span class=&quot;code-quote&quot;&gt;&quot;unserialized oid = &quot;&lt;/span&gt; . $d-&amp;gt;getOid() . &lt;span class=&quot;code-quote&quot;&gt;&quot;\n&quot;&lt;/span&gt;;

  $d2 = Address::getById(4);
  print &lt;span class=&quot;code-quote&quot;&gt;&quot;&lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; object oid = &quot;&lt;/span&gt; . $d2-&amp;gt;getOid() . &lt;span class=&quot;code-quote&quot;&gt;&quot;\n&quot;&lt;/span&gt;;

  $d-&amp;gt;housenumber ++;
  print &lt;span class=&quot;code-quote&quot;&gt;&quot;{$d-&amp;gt;housenumber} versus {$d2-&amp;gt;housenumber}\n&quot;&lt;/span&gt;;
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Things are going wrong in the unserialization. In this test script, I manage to create two objects holding the same oid, but pointing at different object instances (but for the same database id). The output of this script after running it twice shows me:&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;$ php test.php
Serialize using oid=5
$ php test.php
unserialized oid = 5
&lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; object oid = 5
24 versus 23
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Looking at the unserialize() code in Doctrine_Record, the problem seems to be coming from two issues in there:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;$this-&amp;gt;_oid is generated before the data unserialization. Because of this, the generated $this-&amp;gt;_oid is overwritten with whatever was in the serialized data (this is why in above example, the oid became 5 for the unserialized record)&lt;/li&gt;
	&lt;li&gt;The unserialized record is not added to the table&apos;s identitymap, making it kind of invisible for the table&apos;s getRecord() code, resulting in two different objects that both represent the entity with id = 4 (as you can see in the &quot;24 versus 23&quot; output).&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;See the attached patch for a fix that I did on our code tree to make the test work.&lt;/p&gt;

&lt;p&gt;Note that I added some extra code in the unserialize method to cleanup any existing entitymap and table repository entry for the unserialized object. This is of course not the best route, but it helps with some unit testing code where a lot of serialize/unserialize handling is going on and objects got mixed up when not doing this cleanup.&lt;br/&gt;
IMO, better would be to add an unserialization method to the Doctrine_Table, which would, like find(), act as a factory for turning unserialized record data into a Doctrine_Record object, possibly making use of already loaded entities that are available in the table&apos;s internal caches. With unserialize being handled directly from the Doctrine_Record, there is no way AFAICS to keep up the rule of always having exactly one object in a scope that represents a certain object in the database.&lt;/p&gt;

&lt;p&gt;When running above script with this patch applied and with removing the $a, $b and $c assignments (just for making the oid&apos;s different between the two script runs), we get the following output:&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;$ php test.php
Serialize using oid=2
$ php test.php
unserialized oid = 5
&lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; object oid = 5
24 versus 24
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So here, unserializing an object and then reloading the object through the table object gives use two times the same object, representing db object with id = 4;&lt;/p&gt;

&lt;p&gt;When doing things in a different order, we still can force an issue, but this is due to the things mentioned above: to cleanly handle this, unserialization should be handled from a factory method on Table. This script shows the behavior:&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;&lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (!file_exists(&lt;span class=&quot;code-quote&quot;&gt;&quot;/tmp/serialize.doctrine&quot;&lt;/span&gt;))
{
  $d = Address::getById(4);
  print &lt;span class=&quot;code-quote&quot;&gt;&quot;Serialize using oid=&quot;&lt;/span&gt; . $d-&amp;gt;getOid() . &lt;span class=&quot;code-quote&quot;&gt;&quot;\n&quot;&lt;/span&gt;;
  file_put_contents(&lt;span class=&quot;code-quote&quot;&gt;&quot;/tmp/serialize.doctrine&quot;&lt;/span&gt;, serialize($d));
}
&lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt;
{
  $d2 = Address::getById(4);
  print &lt;span class=&quot;code-quote&quot;&gt;&quot;&lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; object oid = &quot;&lt;/span&gt; . $d2-&amp;gt;getOid() . &lt;span class=&quot;code-quote&quot;&gt;&quot;\n&quot;&lt;/span&gt;;

  $d = unserialize(file_get_contents(&lt;span class=&quot;code-quote&quot;&gt;&quot;/tmp/serialize.doctrine&quot;&lt;/span&gt;));
  print &lt;span class=&quot;code-quote&quot;&gt;&quot;unserialized oid = &quot;&lt;/span&gt; . $d-&amp;gt;getOid() . &lt;span class=&quot;code-quote&quot;&gt;&quot;\n&quot;&lt;/span&gt;;

  $d3 = Address::getById(4);
  print &lt;span class=&quot;code-quote&quot;&gt;&quot;&lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; object oid = &quot;&lt;/span&gt; . $d3-&amp;gt;getOid() . &lt;span class=&quot;code-quote&quot;&gt;&quot;\n&quot;&lt;/span&gt;;

  $d-&amp;gt;housenumber ++;
  print &lt;span class=&quot;code-quote&quot;&gt;&quot;{$d-&amp;gt;housenumber} versus {$d2-&amp;gt;housenumber} versus {$d3-&amp;gt;housenumber}\n&quot;&lt;/span&gt;;
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The output of the second run being:&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;$php test.php
&lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; object oid = 2
unserialized oid = 5
&lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; object oid = 5
24 versus 23 versus 24
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The first object that was created is still different from the unserialized object, but at least the third object that is created, is the object that was unserialized.&lt;/p&gt;

&lt;p&gt;I hope that this makes the issue clear and that my input helps in fixing things. This issue provided us with some really unexpected behavior and we&apos;re glad that we were able to track it down to here.&lt;/p&gt;</description>
                <environment></environment>
            <key id="11180">DC-620</key>
            <summary>Unserialize does not add entity to the table entitymap</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="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="mmakaay">Maurice Makaay</reporter>
                        <labels>
                    </labels>
                <created>Tue, 6 Apr 2010 18:00:49 +0000</created>
                <updated>Tue, 8 Jun 2010 16:29:50 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 16:29:50 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Record</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>1</watches>
                        <comments>
                    <comment id="12586" author="mmakaay" created="Wed, 7 Apr 2010 04:38:49 +0000"  >&lt;p&gt;FYI: we removed the &quot;Remove existing record from the repository and table entity map&quot; code from our patch. We had some issues with unit testing without this bit, but we updated the unit tests to work without this bit of code. The &quot;Add the unserialized record to repository and entity map&apos; part stays of course. I think you can ignore the cleanup code in the patch. As long as scripts unserialize data before working with it, things should be fine without it.&lt;/p&gt;</comment>
                    <comment id="12587" author="mmakaay" created="Wed, 7 Apr 2010 04:48:51 +0000"  >&lt;p&gt;New version of the patch, without the cleanup code in it.&lt;/p&gt;</comment>
                    <comment id="12589" author="mmakaay" created="Wed, 7 Apr 2010 05:33:36 +0000"  >&lt;p&gt;Trying to always use the same object for the same entity in the database, we came up with a factory method that we put on our record class as a static public. Maybe this is an idea that you want to include in Doctrine as well?&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;  &lt;span class=&quot;code-keyword&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function fromSerialized($serialized)
  {
    $entity = unserialize($serialized);

    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (!($entity &lt;span class=&quot;code-keyword&quot;&gt;instanceof&lt;/span&gt; Doctrine_Record)) &lt;span class=&quot;code-keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Exception(
      __METHOD__ . &apos;: serialized object is not a Doctrine_Record object&apos;
    );

    &lt;span class=&quot;code-comment&quot;&gt;// If the unserialized object is a persisted entity, then we must
&lt;/span&gt;    &lt;span class=&quot;code-comment&quot;&gt;// check &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; there is already an object &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; that entity available in
&lt;/span&gt;    &lt;span class=&quot;code-comment&quot;&gt;// Doctrine&apos;s table repository.
&lt;/span&gt;    &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($entity-&amp;gt;exists())
    {
      &lt;span class=&quot;code-comment&quot;&gt;// Retrieve the entity through the table repository.
&lt;/span&gt;      $table = $entity-&amp;gt;getTable();
      $repository_entity = $table-&amp;gt;find($entity-&amp;gt;id);

      &lt;span class=&quot;code-comment&quot;&gt;// If a different object was returned than our unserialized
&lt;/span&gt;      &lt;span class=&quot;code-comment&quot;&gt;// object, then there was an object loaded before unserialization.
&lt;/span&gt;      &lt;span class=&quot;code-comment&quot;&gt;// We will merge the data from the unserialized object with
&lt;/span&gt;      &lt;span class=&quot;code-comment&quot;&gt;// the existing object and &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; the existing object to the caller.
&lt;/span&gt;      &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($entity-&amp;gt;getOid() !== $repository_entity-&amp;gt;getOid()) {
        $repository_entity-&amp;gt;merge($entity);
        $entity = $repository_entity;
      }
    }

    &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $entity;
  }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For us, it&apos;s working wonders in combination with above Doctrine_Record::unserialize() patch. When letting this code handle our unserialization, the same object (checked by its oid) is used for referencing the same entity throughout the code. We call the code like this:&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;$object = Doctrine_Record::fromSerialized($serialized_data);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10549" name="Doctrine_Record.unserialize.patch" size="918" author="mmakaay" created="Wed, 7 Apr 2010 04:48:51 +0000" />
                    <attachment id="10548" name="Doctrine_Record.unserialize.patch" size="1219" author="mmakaay" created="Tue, 6 Apr 2010 18:00:49 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-613] Doctrine_Record::copy() ignores IDENTIFIER_SEQUENCE for NULLifying the id field on copy</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-613</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Doctrine_Record::copy() ignores IDENTIFIER_SEQUENCE for NULLifying the id field on copy. In our environment, it was fixed by adding Doctrine_Core::IDENTIFIER_SEQUENCE to the check at the start of the copy() method:&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;    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function copy($deep = &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;)
    {
        $data = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_data;
        $idtype = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_table-&amp;gt;getIdentifierType();
!       &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($idtype === Doctrine_Core::IDENTIFIER_AUTOINC ||
!           $idtype === Doctrine_Core::IDENTIFIER_SEQUENCE) {
            $id = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_table-&amp;gt;getIdentifier();

            unset($data[$id]);
        }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</description>
                <environment></environment>
            <key id="11164">DC-613</key>
            <summary>Doctrine_Record::copy() ignores IDENTIFIER_SEQUENCE for NULLifying the id field on copy</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="mmakaay">Maurice Makaay</reporter>
                        <labels>
                    </labels>
                <created>Thu, 1 Apr 2010 12:01:32 +0000</created>
                <updated>Tue, 8 Jun 2010 14:51:22 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 14:51:22 +0000</resolved>
                            <version>1.2.0-ALPHA1</version>
                <version>1.2.0-ALPHA2</version>
                <version>1.2.0-ALPHA3</version>
                <version>1.2.0-BETA1</version>
                <version>1.2.0-BETA2</version>
                <version>1.2.0-BETA3</version>
                <version>1.2.0-RC1</version>
                <version>1.2.0</version>
                <version>1.2.1</version>
                <version>1.2.2</version>
                <version>1.2.3</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Record</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-594] When using a combination of: a group by field referencing a table in a relation, a join to a different table via a many type relation and a limit clause, doctrine creates a broken query then throws an exception</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-594</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Hi All&lt;/p&gt;

&lt;p&gt;I have run into a very problematic Doctrine 1.2.2 bug which puts me in quite a bit of danger of having to rewrite my whole app in Doctrine 2 (hopefully if this is a bug it isn&apos;t present in Doctrine 2). &lt;/p&gt;

&lt;p&gt;The problem I am running into seems like something that probably would have been found and rectified however so hopefully there is something wrong in my execution.&lt;/p&gt;

&lt;p&gt;The problem I am running into is caused when I have a combination of the following 3 things in my query:&lt;br/&gt;
1) A group by field referencing a table in a relation&lt;br/&gt;
2) A join to a different table via a many type relation&lt;br/&gt;
3) A limit clause&lt;/p&gt;

&lt;p&gt;This combination causes Doctrine to create a broken SQL query which it then throws an exception about when I try to execute the query or call getSqlQuery() on it.&lt;/p&gt;

&lt;p&gt;Using some sample data I put together some very simple examples to illustrate the problem:&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;$q = Doctrine_Query::create(); 
$q-&amp;gt;from(&apos;Customer Customer&apos;); 
$q-&amp;gt;leftJoin(&apos;Customer.Order Order&apos;); 
$q-&amp;gt;leftJoin(&apos;Customer.Zip Zip&apos;); 
$q-&amp;gt;addGroupBy(&apos;Zip.city&apos;);
$q-&amp;gt;addSelect(&apos;Zip.city as city&apos;);
$q-&amp;gt;addSelect(&apos;Customer.customer_id&apos;); 
$q-&amp;gt;addSelect(&apos;Order.order_id&apos;);
$q-&amp;gt;offset(0);
$q-&amp;gt;limit(5);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This creates the following dql:&lt;/p&gt;

&lt;p&gt;SELECT Zip.city as city, Customer.customer_id, Order.order_id FROM Customer Customer LEFT JOIN Customer.Order Order LEFT JOIN Customer.Zip Zip GROUP BY Zip.city LIMIT 5 OFFSET 0&lt;/p&gt;

&lt;p&gt;However when I attempt to run $q-&amp;gt;getSqlQuery() an exception is thrown:&lt;br/&gt;
{&quot;type&quot;:&quot;exception&quot;,&quot;tid&quot;:3,&quot;exception&quot;:{},&quot;message&quot;:&quot;SQLSTATE&lt;span class=&quot;error&quot;&gt;&amp;#91;42S22&amp;#93;&lt;/span&gt;: Column not found: 1054 Unknown column &apos;z2.city&apos; in &apos;group statement&apos;. Failing Query: \&quot;SELECT DISTINCT c2.customer_id FROM customers c2 GROUP BY z2.city LIMIT 5\&quot;&quot;,&quot;where&quot;:&quot;#0 C:\\htdocs\\php_library\\Doctrine-1.2.1\\lib\\Doctrine&lt;br class=&quot;atl-forced-newline&quot; /&gt;Connection.php(1025): Doctrine_Connection-&amp;gt;rethrowException(Object(PDOException), Object(Doctrine_Connection_Mysql), &apos;SELECT DISTINCT...&apos;)\n#1 C:\\htdocs\\php_library\\Doctrine-1.2.1\\lib\\Doctrine&lt;br class=&quot;atl-forced-newline&quot; /&gt;Query.php(1263): Doctrine_Connection-&amp;gt;execute(&apos;SELECT DISTINCT...&apos;, Array)\n#2 C:\\htdocs\\php_library\\Doctrine-1.2.1\\lib\\Doctrine&lt;br class=&quot;atl-forced-newline&quot; /&gt;Query.php(1122): Doctrine_Query-&amp;gt;buildSqlQuery(true)\n#3............&lt;/p&gt;

&lt;p&gt;As you can see from the SQL in the exception Doctrine is trying to create a query that groups by a field from the Zip table with out first joining to it (SELECT DISTINCT c2.customer_id FROM customers c2 GROUP BY z2.city LIMIT 5).&lt;/p&gt;

&lt;p&gt;I know Doctrine works some magic to get limit statements to work with joins and I suspect that something with in that magic may be broken, but hopefully its something I am doing wrong.&lt;/p&gt;

&lt;p&gt;Take out any one of the 3 things I mentioned I above and everything works fine &amp;#8211; the following all work:&lt;/p&gt;

&lt;p&gt;Remove the limit:&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;$q = Doctrine_Query::create(); 
$q-&amp;gt;from(&apos;Customer Customer&apos;); 
$q-&amp;gt;leftJoin(&apos;Customer.Order Order&apos;); 
$q-&amp;gt;leftJoin(&apos;Customer.Zip Zip&apos;); 
$q-&amp;gt;addGroupBy(&apos;Zip.city&apos;); 
$q-&amp;gt;addSelect(&apos;Zip.city as city&apos;);
$q-&amp;gt;addSelect(&apos;Order.order_id&apos;);
$q-&amp;gt;addSelect(&apos;Customer.customer_id&apos;); 
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Remove the additional join:&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;$q = Doctrine_Query::create(); 
$q-&amp;gt;from(&apos;Customer Customer&apos;); 
$q-&amp;gt;leftJoin(&apos;Customer.Zip Zip&apos;); 
$q-&amp;gt;addGroupBy(&apos;Zip.city&apos;); 
$q-&amp;gt;addSelect(&apos;Zip.city as city&apos;);
$q-&amp;gt;addSelect(&apos;Customer.customer_id&apos;);
$q-&amp;gt;offset(0);
$q-&amp;gt;limit(5);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Remove the group by:&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;$q = Doctrine_Query::create(); 
$q-&amp;gt;from(&apos;Customer Customer&apos;); 
$q-&amp;gt;leftJoin(&apos;Customer.Order Order&apos;); 
$q-&amp;gt;leftJoin(&apos;Customer.Zip Zip&apos;); 
$q-&amp;gt;addSelect(&apos;Zip.city as city&apos;);
$q-&amp;gt;addSelect(&apos;Customer.customer_id&apos;); 
$q-&amp;gt;addSelect(&apos;Order.order_id&apos;);
$q-&amp;gt;offset(0);
$q-&amp;gt;limit(5);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Its also worth noting that the following changes also stop the problem from happening:&lt;br/&gt;
Changing the relation to the Order table to be a one relation instead of a many relation.&lt;br/&gt;
Changing the group by to a field located in the &quot;from&quot; table (such as: $q-&amp;gt;addGroupBy(&apos;Customer.customer_id&apos;)&lt;img class=&quot;emoticon&quot; src=&quot;http://www.doctrine-project.org/jira/images/icons/emoticons/wink.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;

&lt;p&gt;Here are the relevant parts of my sample data schema:&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;detect_relations: &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;
&lt;span class=&quot;code-keyword&quot;&gt;package&lt;/span&gt;: Example
options:
  type: INNODB
  charset: utf8
Order:
  tableName: orders
  columns:
    order_id:
      type: integer(4)
      primary: &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;
      notnull: &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;
    customer_id:
      type: integer(4)
    order_date: timestamp
  relations:
    OrderItem:
      type: many
      local: order_id
      foreign: order_id
    Customer:
      type: one
      local: customer_id
      foreign: customer_id
  options:
    type: InnoDB
Customer:
  tableName: customers
  columns:
    customer_id:
      type: integer(4)
      primary: &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;
      notnull: &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;
      autoincrement: &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;
    firstname:
      type: string(45)
    lastname:
      type: string(45)
    streetaddress:
      type: string(45)
    city:
      type: string(45)
    state:
      type: string(45)
    postalcode:
      type: string(45)
  relations:
    Order:
      type: many
      local: customer_id
      foreign: customer_id
    Zip:
      type: one
      local: postalcode
      foreign: postalcode
  options:
    type: InnoDB
Zip:
  connection: default_schema
  tableName: zips
  columns:
    postalcode:
      type: varchar(30)
      primary: &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;
    latitude: &apos;&lt;span class=&quot;code-object&quot;&gt;float&lt;/span&gt;(10,6)&apos;
    longitude: &apos;&lt;span class=&quot;code-object&quot;&gt;float&lt;/span&gt;(10,6)&apos;
    city: string(50)
    state: string(50)
    country: string(50)
    type: string(50)
  relations:
    Customer:
      type: many
      local: postalcode
      foreign: postalcode
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Thank for any advice or information you can give me on this.&lt;/p&gt;

&lt;p&gt;Best regards&lt;/p&gt;

&lt;p&gt;Will Ferrer&lt;/p&gt;</description>
                <environment>XP Xamp Current</environment>
            <key id="11110">DC-594</key>
            <summary>When using a combination of: a group by field referencing a table in a relation, a join to a different table via a many type relation and a limit clause, doctrine creates a broken query then throws an exception</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="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="guilhermeblanco">Guilherme Blanco</assignee>
                                <reporter username="willf1976">will ferrer</reporter>
                        <labels>
                    </labels>
                <created>Mon, 22 Mar 2010 22:13:42 +0000</created>
                <updated>Tue, 8 Jun 2010 10:26:29 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 10:26:29 +0000</resolved>
                            <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Query</component>
                <component>Relations</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>1</watches>
                        <comments>
                    <comment id="12454" author="willf1976" created="Wed, 24 Mar 2010 17:38:29 +0000"  >&lt;p&gt;I realized another crucial aspect of the problem. I am using a left join to my Zip table instead of using an inner join. When I change my code to do an inner join it works again:&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;$q = Doctrine_Query::create(); 
$q-&amp;gt;from(&apos;Customer Customer&apos;); 
$q-&amp;gt;leftJoin(&apos;Customer.Order Order&apos;); 
$q-&amp;gt;innerJoin(&apos;Customer.Zip Zip&apos;); 
$q-&amp;gt;addGroupBy(&apos;Zip.city&apos;);
$q-&amp;gt;addSelect(&apos;Zip.city as city&apos;);
$q-&amp;gt;addSelect(&apos;Customer.customer_id&apos;); 
$q-&amp;gt;addSelect(&apos;Order.order_id&apos;);
$q-&amp;gt;offset(0);
$q-&amp;gt;limit(5);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Thanks much in advance.&lt;/p&gt;

&lt;p&gt;Will Ferrer&lt;/p&gt;</comment>
                    <comment id="12563" author="willf1976" created="Sat, 3 Apr 2010 18:05:36 +0000"  >&lt;p&gt;I took a look at the doctrine 1.2.2 code to try to track down what was causing this bug and I think I have found and fixed it in my copy of the code base.&lt;/p&gt;

&lt;p&gt;The problem is on line 1459 of Doctrine_Query and looks like it was just an oversight. The code was checking if it should preserve left joins while generating the subquery based on whether or not there were any orderBys, wheres, or havings added to the query. I changed the code to also watch for groupBys and it seems to have resolved this issue. &lt;/p&gt;

&lt;p&gt;The code was:&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; &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;]) &amp;amp;&amp;amp; empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;]) &amp;amp;&amp;amp; empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;having&apos;])) {
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I changed it to:&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;&lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;orderby&apos;]) &amp;amp;&amp;amp; empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;where&apos;]) &amp;amp;&amp;amp; empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;having&apos;]) &amp;amp;&amp;amp; empty($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_sqlParts[&apos;groupby&apos;])) {
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Please let me know if I am over looking anything. If I am not then this change should probably be added to the next revision of doctrine.&lt;/p&gt;

&lt;p&gt;Sincerely&lt;/p&gt;

&lt;p&gt;Will Ferrer&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-584] MSSQL Server: Cannot alter / drop columns which have indexes or constraints applied to them</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-584</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;SQL Server will not allow attempts to alter or drop columns with indexes or constraints applied to them, because they are dependent on the column. In addition to this, SQL Server&apos;s syntax for altering columns is different for that of adding them in that it does not allow default value constraints to be present in the alter statement.&lt;/p&gt;

&lt;p&gt;I&apos;ve attached a patch which attempts to circumvent this issue by allowing the author of the changeset to provide a name for the default constraint, which SQL Server supports. Giving the constraint a name of our choosing allows us to reference and drop it before running a command against a constrained column. &lt;/p&gt;

&lt;p&gt;In the case of an ALTER query the default constraint portion is spliced and subsequently run.&lt;/p&gt;

&lt;p&gt;When dropping a column the author need only make sure they name the constraint, or know its name, then drop it before the query is run.&lt;/p&gt;</description>
                <environment>PHP 5.3&lt;br/&gt;
MSSQL Server 2008</environment>
            <key id="11084">DC-584</key>
            <summary>MSSQL Server: Cannot alter / drop columns which have indexes or constraints applied to them</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="craigmarvelley">Craig Marvelley</reporter>
                        <labels>
                    </labels>
                <created>Thu, 18 Mar 2010 14:07:48 +0000</created>
                <updated>Tue, 8 Jun 2010 14:30:27 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 14:30:27 +0000</resolved>
                            <version>1.2.1</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Migrations</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="12429" author="craigmarvelley" created="Mon, 22 Mar 2010 12:50:37 +0000"  >&lt;p&gt;Added patch and test cases for this issue.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10512" name="DC584TestCase.php" size="6841" author="craigmarvelley" created="Mon, 22 Mar 2010 12:50:37 +0000" />
                    <attachment id="10511" name="mssql_default_constraint_patch.patch" size="4853" author="craigmarvelley" created="Mon, 22 Mar 2010 12:50:37 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-583] MSSQL Server: No accounting for max varchar size when creating columns.</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-583</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;The Doctrine_Connection_Mysql and Doctrine_Datadict_Mysql classes utilise a connection property max_varchar_size so if the field length of a string column is specified and exceeds 255 chars a &apos;text&apos; column type is used instead of a &apos;varchar&apos; one.&lt;/p&gt;

&lt;p&gt;This logic is missing for MSSQL; Doctrine will attempt to create varchar columns even if greater than the max size (8000 chars).&lt;/p&gt;

&lt;p&gt;I&apos;ve attached a patch for MSSQL which mirrors the MySQL functionality, would you consider including it please?&lt;/p&gt;

&lt;p&gt;Thanks!&lt;/p&gt;</description>
                <environment>PHP 5.3&lt;br/&gt;
MSSQL Server 2008</environment>
            <key id="11083">DC-583</key>
            <summary>MSSQL Server: No accounting for max varchar size when creating columns.</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="craigmarvelley">Craig Marvelley</reporter>
                        <labels>
                    </labels>
                <created>Thu, 18 Mar 2010 11:04:03 +0000</created>
                <updated>Tue, 8 Jun 2010 14:16:21 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 14:16:21 +0000</resolved>
                            <version>1.2.1</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Migrations</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                    <attachment id="10493" name="add_mssql_max_varchar_length.patch" size="1228" author="craigmarvelley" created="Thu, 18 Mar 2010 11:04:03 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-558] CLONE -generate-migrations-diff is producing bogus migrations (drops the whole database)</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-558</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Replicating the bug:&lt;br/&gt;
1. unzip vanilla sandbox.&lt;br/&gt;
2. create schema file with entity&lt;br/&gt;
3. run ./doctrine build-all&lt;br/&gt;
4. modify schema, add column to entity.&lt;br/&gt;
5. run ./doctrine generate-migrations-diff&lt;/p&gt;

&lt;p&gt;Expected behaviour:&lt;br/&gt;
generates migration wich adds column to entity.&lt;/p&gt;

&lt;p&gt;Real behaviour:&lt;br/&gt;
Drops entity from database&lt;/p&gt;

&lt;p&gt;Similar issue: &lt;br/&gt;
&lt;a href=&quot;http://groups.google.com/group/doctrine-user/browse_thread/thread/8b4a0fc0778a388a/79446784623b8497?lnk=gst&amp;amp;q=1.2.1+migration&quot; class=&quot;external-link&quot;&gt;http://groups.google.com/group/doctrine-user/browse_thread/thread/8b4a0fc0778a388a/79446784623b8497?lnk=gst&amp;amp;q=1.2.1+migration&lt;/a&gt;&lt;/p&gt;</description>
                <environment>Vanilla sandbox on version 1.2.1 and 1.2.0&lt;br/&gt;
both sqlite and mysql, so its not driver dependant</environment>
            <key id="11013">DC-558</key>
            <summary>CLONE -generate-migrations-diff is producing bogus migrations (drops the whole database)</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="spiffyjr">Kyle Spraggs</reporter>
                        <labels>
                    </labels>
                <created>Tue, 9 Mar 2010 14:46:14 +0000</created>
                <updated>Tue, 8 Jun 2010 14:36:33 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 14:36:33 +0000</resolved>
                            <version>1.2.0</version>
                <version>1.2.1</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Migrations</component>
                        <due></due>
                    <votes>1</votes>
                        <watches>2</watches>
                        <comments>
                    <comment id="12062" author="spiffyjr" created="Tue, 9 Mar 2010 14:51:44 +0000"  >&lt;p&gt;This issue is NOT fixed for certain configurations of Doctrine (namely PEAR).&lt;/p&gt;

&lt;p&gt;See &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-475&quot; class=&quot;external-link&quot;&gt;http://www.doctrine-project.org/jira/browse/DC-475&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="12733" author="funkface" created="Thu, 22 Apr 2010 06:03:46 +0000"  >&lt;p&gt;I agree, this is an issue still in 1.2.2.&lt;/p&gt;

&lt;p&gt;The problem seems to be to do with the model class name prefix, it manifests itself in Doctrine_Migration_Diff on line 190. The keys of two arrays are compared to see what needs to be changed:&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;div class=&quot;error&quot;&gt;&lt;span class=&quot;error&quot;&gt;Unable to find source-code formatter for language: php.&lt;/span&gt; Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml&lt;/div&gt;&lt;pre&gt;$from = array (
    &apos;Model_CaseStudy&apos; =&amp;gt; array(...),
    &apos;Model_Event&apos; =&amp;gt; array(...),
    &apos;Model_Group&apos; =&amp;gt; array(...)
);

$to = array(
    &apos;CaseStudy&apos; =&amp;gt; array(...),
    &apos;Event&apos; =&amp;gt; array(...),
    &apos;Group&apos; =&amp;gt; array(...)
);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Because none of the array keys match it assumes that the $to array are all new models and so generates the migration to drop all of $from and create all of $to; as the models have the same table names, if you run the down you end up with no tables at all.&lt;/p&gt;

&lt;p&gt;So I think we need to inject the prefix into the $to models creation process somehow, as yet I haven&apos;t figured out an effective place to do this.&lt;/p&gt;</comment>
                    <comment id="12734" author="funkface" created="Thu, 22 Apr 2010 10:09:25 +0000"  >&lt;p&gt;I&apos;ve got it working. Not sure how robust or appropriate this fix is:&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;div class=&quot;error&quot;&gt;&lt;span class=&quot;error&quot;&gt;Unable to find source-code formatter for language: diff.&lt;/span&gt; Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml&lt;/div&gt;&lt;pre&gt; 
diff --git a/lib/Doctrine/Core.php b/lib/Doctrine/Core.php
index ef10b6e..2fa7a73 100644
--- a/lib/Doctrine/Core.php
+++ b/lib/Doctrine/Core.php
@@ -664,7 +664,7 @@ class Doctrine_Core
                             $className = $e[0];
                         }

-                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($classPrefix) {
+                        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($classPrefix &amp;amp;&amp;amp; $classPrefix != substr($className, 0, strlen($classPrefix))) {
                             $className = $classPrefix . $className;
                         }
diff --git a/lib/Doctrine/Migration/Diff.php b/lib/Doctrine/Migration/Diff.php
index 7f00b38..4260f27 100644
--- a/lib/Doctrine/Migration/Diff.php
+++ b/lib/Doctrine/Migration/Diff.php
@@ -112,7 +112,13 @@ class Doctrine_Migration_Diff
         $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_cleanup();

         $from = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_generateModels(self::$_fromPrefix, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_from);
-        $to = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_generateModels(self::$_toPrefix, $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_to);
+        $to = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_generateModels(
+
+            Doctrine_Manager::getInstance()-&amp;gt;getAttribute(Doctrine_Core::ATTR_MODEL_CLASS_PREFIX) .
+            self::$_toPrefix,
+
+            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_to
+        );

         &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_diff($from, $to);
     }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-538] Doctrine_Table::enumIndex() and Doctrine_Table::enumValue() should return easily distinguishable value (e.g. false) when index/value is not found</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-538</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;At the moment:&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;Doctrine_Table::enumIndex($fieldName, $value) returns $value specified as a parameter if no index for it is found&lt;/li&gt;
	&lt;li&gt;Doctrine_Table::enumValue($fieldName, $index) returns $index specified as a parameter if no value for it is found&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;This actually makes writing code which deals with enums a bit difficult as one would like to detect incorrect parameter as soon as possible (e.g. not when Doctrine validation kicks in and checks that enum value is incorrect).&lt;/p&gt;

&lt;p&gt;Current algorithm that returns index or value is not sufficient to determine error in situation when index=value, e.g. enum values are &lt;span class=&quot;error&quot;&gt;&amp;#91;0, 1, 2, 3&amp;#93;&lt;/span&gt;. Calling e.g. enumValue(&apos;sample&apos;, 4) would yield 4 - so it makes difficult to determine whether it&apos;s correct value.&lt;/p&gt;

&lt;p&gt;I hope this makes sense, let me know if anything is unclear.&lt;/p&gt;

&lt;p&gt;The workaround for this is to check whether mapped index/value exists in array returned by Doctrine_Table::getEnumValues(), but this is an extra unnecessary check.&lt;/p&gt;

&lt;p&gt;So instead of writing:&lt;/p&gt;

&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;$index = 5;
$someTable = Doctrine_Core::getTable(&apos;Sample&apos;);
$value = $someTable-&amp;gt;enumValue(&apos;sample&apos;, $index);

$values = $someTable-&amp;gt;getEnumValues(&apos;sample&apos;);
if (in_array($value, $values) == false)
{
  throw new UnexpectedValueException(&apos;illegal index specified!&apos;);
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; 

&lt;p&gt;I&apos;d like to write:&lt;/p&gt;

&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;$index = 5;
$value = Doctrine_Core::getTable(&apos;Sample&apos;)-&amp;gt;enumValue(&apos;sample&apos;, $index);
if ($value === false)
{
  throw new UnexpectedValueException(&apos;illegal index specified!&apos;);
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; 

&lt;p&gt;Simpler, eh?&lt;/p&gt;</description>
                <environment>Any</environment>
            <key id="10986">DC-538</key>
            <summary>Doctrine_Table::enumIndex() and Doctrine_Table::enumValue() should return easily distinguishable value (e.g. false) when index/value is not found</summary>
                <type id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/improvement.png">Improvement</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="m.olszewski">Michal Olszewski</reporter>
                        <labels>
                    </labels>
                <created>Wed, 3 Mar 2010 08:36:20 +0000</created>
                <updated>Tue, 8 Jun 2010 15:00:10 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 15:00:10 +0000</resolved>
                            <version>1.2.1</version>
                                <fixVersion>1.2.3</fixVersion>
                                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="12005" author="m.olszewski" created="Wed, 3 Mar 2010 09:16:41 +0000"  >&lt;p&gt;Please find patches for Doctrine/Table.php and Doctrine/Column.php against their versions from rev. 7298&lt;/p&gt;

&lt;p&gt;Patches includes proposed change (returning false instead of original parameter).&lt;/p&gt;

&lt;p&gt;Interestingly, Doctrine_Column::enumIndex() returns FALSE when index is not found for specified value as it uses array_search().&lt;br/&gt;
So - another reason why this processing should be unified &lt;img class=&quot;emoticon&quot; src=&quot;http://www.doctrine-project.org/jira/images/icons/emoticons/smile.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</comment>
                    <comment id="12206" author="jwage" created="Mon, 15 Mar 2010 14:03:23 +0000"  >&lt;p&gt;Hi, did you run your patch against the test suite? It breaks several tests so we cannot apply it. Please re-open if you have more information and a new patch. Thanks, Jon&lt;/p&gt;</comment>
                    <comment id="12457" author="m.olszewski" created="Thu, 25 Mar 2010 06:28:39 +0000"  >&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;I think I&apos;ve nailed this one down.&lt;/p&gt;

&lt;p&gt;First of all, &lt;tt&gt;Doctrine_Table::enumValue()&lt;/tt&gt; is used incorrectly in two places:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;&lt;tt&gt;Doctrine_Record::unserialize()&lt;/tt&gt; has &apos;special case&apos; for enums, which performs following conversion - from enum&apos;s &apos;index&apos; to &apos;value&apos;:
  &lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;$this-&amp;gt;_table-&amp;gt;enumValue($k, $this-&amp;gt;_data[$k]);&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;  Now this doesn&apos;t make sense because &lt;tt&gt;Doctrine_Record::serialize()&lt;/tt&gt; does not store enum&apos;s &apos;index&apos; but &apos;value&apos; so &lt;tt&gt;Doctrine_Table::enumValue()&lt;/tt&gt; always receives &apos;value&apos;. Previous implementation simply returned the same &apos;value&apos; in case when check:&lt;/p&gt;
  &lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;isset($this-&amp;gt;_columns[$columnName][&apos;values&apos;][$index])&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;  failed. And it was always failing because &apos;index&apos; is actually one of the &apos;values&apos;.&lt;/p&gt;&lt;/li&gt;
	&lt;li&gt;&lt;tt&gt;Doctrine_Table::prepareValue()&lt;/tt&gt; is the same case - it receives &apos;value&apos; and not &apos;index&apos; so there is no point in calling &lt;tt&gt;Doctrine_Table::enumValue()&lt;/tt&gt;.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;Please note I assumed two things:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;Correct use of &apos;emulated&apos; enums (second case) is to set them as strings, not integer values (it seemed reasonable after looking at test cases and documentation). Also: &apos;emulated&apos; enums are stored in DB as text, not integers.&lt;/li&gt;
	&lt;li&gt;&apos;Native&apos; enums are not mapped so they don&apos;t change anything.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;Under these assumptions I propose two changes:&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;Add special case for enums in &lt;tt&gt;Doctrine_Record::serialize()&lt;/tt&gt; so enum value is mapped to enum index&lt;/li&gt;
	&lt;li&gt;Remove special case for enums in &lt;tt&gt;Doctrine_Table::prepareValue()&lt;/tt&gt; and always return $value parameter as it was specified (move it to &apos;string&apos;/&apos;int&apos; case)&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;I&apos;ve prepared patch for these changes and will attach it soon.&lt;/p&gt;

&lt;p&gt;Thanks.&lt;/p&gt;</comment>
                    <comment id="12458" author="m.olszewski" created="Thu, 25 Mar 2010 06:46:44 +0000"  >&lt;p&gt;Attaching patch (&lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-538&quot; title=&quot;Doctrine_Table::enumIndex() and Doctrine_Table::enumValue() should return easily distinguishable value (e.g. false) when index/value is not found&quot;&gt;&lt;del&gt;DC-538&lt;/del&gt;&lt;/a&gt;_fix.patch), including:&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;&lt;tt&gt;Doctrine_Table::enumValue()&lt;/tt&gt; and &lt;tt&gt;Doctrine_Table::enumIndex()&lt;/tt&gt; now returns false if parameter cannot be mapped&lt;/li&gt;
	&lt;li&gt;&lt;tt&gt;Doctrine_Table::prepareValue()&lt;/tt&gt; does call &lt;tt&gt;Doctrine_Table::enumValue()&lt;/tt&gt; for enum type&lt;/li&gt;
	&lt;li&gt;&lt;tt&gt;Doctrine_Record::serialize()&lt;/tt&gt; serializes enum&apos;s index, not value, so unserialization works fine&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Please apply it if you agree with my previous comment.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10419" name="Column.patch" size="300" author="m.olszewski" created="Wed, 3 Mar 2010 09:16:41 +0000" />
                    <attachment id="10520" name="DC-538_fix.patch" size="4175" author="m.olszewski" created="Thu, 25 Mar 2010 06:46:44 +0000" />
                    <attachment id="10418" name="Table.patch" size="197" author="m.olszewski" created="Wed, 3 Mar 2010 09:16:41 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-470] [PATCH] Search : wrong connection used for some queries when multiples connections are defined</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-470</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;When multiples connections are defined, sometimes the Search behavior use a wrong one.&lt;/p&gt;

&lt;p&gt;This happens because the Query::loadRoot() method calls the Manager::getConnectionForComponent(), which returns the bound connection for the root component (like ModelIndex in this case), but the connection for this component is never bound.&lt;br/&gt;
The following and attached patch solved the issue for me.&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeHeader panelHeader&quot; style=&quot;border-bottom-width: 1px;&quot;&gt;&lt;b&gt;Search / connection patch&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;Index: lib/Doctrine/Search.php
===================================================================
--- lib/Doctrine/Search.php	(r&#233;vision 7080)
+++ lib/Doctrine/Search.php	(copie de travail)
@@ -76,7 +76,9 @@
         $result = parent::buildTable();

         &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ( ! isset($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_options[&apos;connection&apos;])) {
-            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_options[&apos;connection&apos;] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_options[&apos;table&apos;]-&amp;gt;getConnection();
+            $manager = Doctrine_Manager::getInstance();
+            $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_options[&apos;connection&apos;] = $manager-&amp;gt;getConnectionForComponent($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_options[&apos;table&apos;]-&amp;gt;getComponentName());
+            $manager-&amp;gt;bindComponent($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_options[&apos;className&apos;], $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_options[&apos;connection&apos;]-&amp;gt;getName());
         }

         &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $result;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Note : we can&apos;t use directly&lt;br/&gt;
$this-&amp;gt;_options&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;connection&amp;#39;&amp;#93;&lt;/span&gt; = $this-&amp;gt;_options&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;table&amp;#39;&amp;#93;&lt;/span&gt;-&amp;gt;getConnection();&lt;br/&gt;
because I sometimes found the getConnection() returns the wrong connection (I didn&apos;t looked why).&lt;/p&gt;</description>
                <environment>Debian Sid + php 5.3,  symfony 1.4.1</environment>
            <key id="10820">DC-470</key>
            <summary>[PATCH] Search : wrong connection used for some queries when multiples connections are defined</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="colin.darie">Colin Darie</reporter>
                        <labels>
                    </labels>
                <created>Mon, 1 Feb 2010 14:30:40 +0000</created>
                <updated>Tue, 6 Jul 2010 10:48:13 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 15:25:22 +0000</resolved>
                            <version>1.2.1</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Behaviors</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>1</watches>
                        <comments>
                    <comment id="11935" author="jwage" created="Mon, 1 Mar 2010 20:01:15 +0000"  >&lt;p&gt;Can you test this against the latest 1.2 SVN? I applied a fix to Generator.php that might help this issue.&lt;/p&gt;</comment>
                    <comment id="12076" author="colin.darie" created="Wed, 10 Mar 2010 16:39:21 +0000"  >&lt;p&gt;No, it doesn&apos;t work (with the very last revision, 7323).&lt;/p&gt;

&lt;p&gt;I basically did a $object = Doctrine::getTable(&apos;Foo&apos;)-&amp;gt;search(&apos;bar&apos;); and got the following error :&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;SQLSTATE[HY000]: General error: 1 no such table: foo_index.
Failing Query: &quot;SELECT COUNT(keyword) AS relevance, id FROM foo_index WHERE keyword = ?
GROUP BY id ORDER BY relevance DESC&quot;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;(the first defined connection is used).&lt;/p&gt;

&lt;p&gt;Plus if it can help, I just discovered a weird thing with the (odd) code :&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;$table = Doctrine::getTable(&apos;Foo&apos;);
$object = Doctrine::getTable(&apos;Foo&apos;)-&amp;gt;search(&apos;bar&apos;);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;returns the error :&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;Invalid argument type. Expected instance of Doctrine_Table.&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                    <comment id="12080" author="jwage" created="Thu, 11 Mar 2010 10:39:15 +0000"  >&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;Please re-open if you can provide some more information. The error you mentioned, please also include the stacktrace and other relevant information. The error message itself is useless &lt;img class=&quot;emoticon&quot; src=&quot;http://www.doctrine-project.org/jira/images/icons/emoticons/smile.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;

&lt;p&gt;Thanks, Jon&lt;/p&gt;</comment>
                    <comment id="12091" author="colin.darie" created="Thu, 11 Mar 2010 15:36:05 +0000"  >&lt;p&gt;Hi, &lt;/p&gt;

&lt;p&gt;I uploaded 2 stacktraces here (with revision 7326, in a symfony 1.4.4-dev environment) and for the simple code&lt;br/&gt;
$o = Doctrine::getTable(&apos;Athlete&apos;)-&amp;gt;search(&apos;hey&apos;) :&lt;/p&gt;

&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;a simplified one (more readable) &lt;a href=&quot;http://pastebin.org/110117&quot; class=&quot;external-link&quot;&gt;http://pastebin.org/110117&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;the full one containing all variables &lt;a href=&quot;http://pastebin.org/110114&quot; class=&quot;external-link&quot;&gt;http://pastebin.org/110114&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;The script was called by a &quot;php /path/to/my/test&quot; to have a more readable stacktrace, but of course in a &quot;normal&quot; context, the same error happens.&lt;/p&gt;

&lt;p&gt;The relevant databases.yml :&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;test:
  dbsport:
    param:
      dsn: &apos;mysql:host=localhost;dbname=db_sport&apos;
  dbclient:
    param:
      dsn: &apos;sqlite:%SF_DATA_DIR%/sqlite/db_client_test.db&apos;

all:
  dbsport:
    param:
      dsn: &apos;mysql:host=localhost;dbname=db_sport_test&apos;
      username: username
      password: &apos;password&apos;
  dbclient:
    param:
      dsn: &apos;sqlite:%SF_DATA_DIR%/sqlite/db_client.db&apos;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;A simple switch of the connections order solves the issue, but then it&apos;s no possible to search on the dbclient because the last connection defined is used instead (unlike I told in my previous comment, it&apos;s not the first one).&lt;/p&gt;

&lt;p&gt;Thanks for your time.&lt;/p&gt;</comment>
                    <comment id="12092" author="colin.darie" created="Thu, 11 Mar 2010 15:38:03 +0000"  >&lt;p&gt;Reopen with my previous comment &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-470?focusedCommentId=12091&amp;amp;page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_12091&quot; class=&quot;external-link&quot;&gt;http://www.doctrine-project.org/jira/browse/DC-470?focusedCommentId=12091&amp;amp;page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_12091&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="12183" author="jwage" created="Mon, 15 Mar 2010 10:37:23 +0000"  >&lt;p&gt;Hmm, I am not sure of the problem here. Any way to reproduce this in a Doctrine test case so that i can more clearly see the problem?&lt;/p&gt;</comment>
                    <comment id="12289" author="colin.darie" created="Tue, 16 Mar 2010 14:05:03 +0000"  >&lt;p&gt;I&apos;m unable to write a test case for this, because the problem seems to come only when the base model class has not been loaded before to perform the search.&lt;/p&gt;

&lt;p&gt;Moreover, I found this base class is &lt;b&gt;never&lt;/b&gt; loaded by the Doctrine::getTable(&apos;foo&apos;)-&amp;gt;search() method, so the bindComponent() in top of the class is never executed.&lt;/p&gt;

&lt;p&gt;Here is a scenario that fails, if it can help you :&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;Doctrine_Core::getTable(&apos;Foo&apos;)-&amp;gt;search(&apos;bar&apos;);
 -&amp;gt; Doctrine_Manager::getInstance()
 -&amp;gt; getConnectionForComponent(&apos;Foo&apos;)
      -&amp;gt; Doctrine_Core::modelsAutoload(&apos;Foo&apos;)
           At &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; point, self::$_modelsDirectory is not setted and self::$_loadedModelFiles is empty
           because no model has been loaded yet, so the BaseFoo class is not loaded and the component is not bound
      -&amp;gt; getCurrentConnection() returns the last defined connection, not the connection &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; the Foo component
  -&amp;gt; getTable(&apos;Foo&apos;) .... the following operates on the bad connection,
       so the query tries to select from the foo_index table in the wrong database.
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;(sorry for my poor english ^^)&lt;/p&gt;</comment>
                    <comment id="13524" author="pluk77" created="Tue, 6 Jul 2010 10:48:13 +0000"  >&lt;p&gt;Seems like this could be a duplicate of &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-740&quot; class=&quot;external-link&quot;&gt;DC-740&lt;/a&gt; and not an actual Doctrine bug but an sfDoctrinePlugin bug.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10336" name="Search.fix-connection.patch" size="728" author="colin.darie" created="Mon, 1 Feb 2010 14:30:40 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-439] Import of table with (silly) name &quot;index&quot;</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-439</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;In Doctrine/Import/Mssql.php are this procedure calls:&lt;/p&gt;

&lt;p&gt; 92: $sql = &apos;EXEC sp_primary_keys_rowset @table_name = &apos; . $this-&amp;gt;conn-&amp;gt;quoteIdentifier($table, true); &lt;br/&gt;
 99: $sql     = &apos;EXEC sp_columns @table_name = &apos; . $this-&amp;gt;conn-&amp;gt;quoteIdentifier($table, true);&lt;br/&gt;
219: $query = &apos;EXEC sp_statistics @table_name = &apos; . $table;&lt;br/&gt;
222: $query = &apos;EXEC sp_pkeys @table_name = &apos; . $table;&lt;/p&gt;

&lt;p&gt;which fail with sql &quot;keyword&quot; table names.&lt;/p&gt;

&lt;p&gt;Using ...&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;. $table . &amp;#39; &amp;#93;&lt;/span&gt;&apos; around the table name worked for me.&lt;br/&gt;
I don&apos;t know anything about the backend of doctrine.&lt;br/&gt;
Should this be done by quoteIdentifier, or is this fix okay?&lt;br/&gt;
.. @table_name = &lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39; . $this-&amp;gt;conn-&amp;gt;quoteIdentifier($table, true) . &amp;#39;&amp;#93;&lt;/span&gt;&apos;;&lt;/p&gt;

&lt;p&gt;Many thanx for all!&lt;br/&gt;
Jochen Bayer&lt;/p&gt;</description>
                <environment>MS-SQL-Server 2005&lt;br/&gt;
php 5.2.11&lt;br/&gt;
openSUSE 11.1</environment>
            <key id="10752">DC-439</key>
            <summary>Import of table with (silly) name &quot;index&quot;</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="jocl">Jochen Bayer</reporter>
                        <labels>
                    </labels>
                <created>Wed, 20 Jan 2010 08:43:21 +0000</created>
                <updated>Thu, 24 Mar 2011 12:51:22 +0000</updated>
                    <resolved>Wed, 9 Jun 2010 12:48:37 +0000</resolved>
                            <version>1.2.1</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Import/Export</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                        <comments>
                    <comment id="13215" author="jwage" created="Tue, 8 Jun 2010 16:58:11 +0000"  >&lt;p&gt;It is hard to understand what you changed exactly. Can you provide a diff?&lt;/p&gt;</comment>
                    <comment id="13245" author="jocl" created="Wed, 9 Jun 2010 04:31:26 +0000"  >&lt;p&gt;Index: Mssql.php&lt;br/&gt;
===================================================================&lt;br/&gt;
&amp;#8212; Mssql.php   (Revision 49)&lt;br/&gt;
+++ Mssql.php   (Arbeitskopie)&lt;br/&gt;
@@ -89,14 +89,14 @@&lt;br/&gt;
      */&lt;br/&gt;
     public function listTableColumns($table)&lt;br/&gt;
     {&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;$sql = &apos;EXEC sp_primary_keys_rowset @table_name = &apos; . $this-&amp;gt;conn-&amp;gt;quoteIdentifier($table, true);&lt;br/&gt;
+        $sql = &apos;EXEC sp_primary_keys_rowset @table_name = &lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39; . $this-&amp;gt;conn-&amp;gt;quoteIdentifier($table, true) . &amp;#39;&amp;#93;&lt;/span&gt;&apos;;&lt;br/&gt;
         $result = $this-&amp;gt;conn-&amp;gt;fetchAssoc($sql);&lt;br/&gt;
         $primary = array();&lt;br/&gt;
         foreach ($result as $key =&amp;gt; $val) 
{
             $primary[] = $val[&apos;COLUMN_NAME&apos;];
         }&lt;/li&gt;
&lt;/ul&gt;


&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;$sql     = &apos;EXEC sp_columns @table_name = &apos; . $this-&amp;gt;conn-&amp;gt;quoteIdentifier($table, true);&lt;br/&gt;
+        $sql     = &apos;EXEC sp_columns @table_name = &lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39; . $this-&amp;gt;conn-&amp;gt;quoteIdentifier($table, true) . &amp;#39;&amp;#93;&lt;/span&gt;&apos;;&lt;br/&gt;
         $result  = $this-&amp;gt;conn-&amp;gt;fetchAssoc($sql);&lt;br/&gt;
         $columns = array();&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;@@ -216,10 +216,10 @@&lt;br/&gt;
             }&lt;br/&gt;
         }&lt;br/&gt;
         $table = $this-&amp;gt;conn-&amp;gt;quote($table, &apos;text&apos;);&lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;$query = &apos;EXEC sp_statistics @table_name = &apos; . $table;&lt;br/&gt;
+        $query = &apos;EXEC sp_statistics @table_name = &lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39; . $table . &amp;#39;&amp;#93;&lt;/span&gt;&apos;;&lt;br/&gt;
         $indexes = $this-&amp;gt;conn-&amp;gt;fetchColumn($query, $keyName);&lt;/li&gt;
&lt;/ul&gt;


&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;$query = &apos;EXEC sp_pkeys @table_name = &apos; . $table;&lt;br/&gt;
+        $query = &apos;EXEC sp_pkeys @table_name = &lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39; . $table. &amp;#39;&amp;#93;&lt;/span&gt;&apos;;&lt;br/&gt;
         $pkAll = $this-&amp;gt;conn-&amp;gt;fetchColumn($query, $pkName);&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;         $result = array();&lt;/p&gt;</comment>
                    <comment id="13252" author="jwage" created="Wed, 9 Jun 2010 12:47:17 +0000"  >&lt;p&gt;You need to turn on identifier quoting. The quoteIdentifier() method takes care of this for you.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.doctrine-project.org/documentation/manual/1_2/en/configuration:identifier-quoting&quot; class=&quot;external-link&quot;&gt;http://www.doctrine-project.org/documentation/manual/1_2/en/configuration:identifier-quoting&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="13253" author="jwage" created="Wed, 9 Jun 2010 12:48:37 +0000"  >&lt;p&gt;Fixed missed calls to quoteIdentifier(). Turn on identifier quoting for identifiers to be wrapped with []&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.doctrine-project.org/documentation/manual/1_2/en/configuration:identifier-quoting&quot; class=&quot;external-link&quot;&gt;http://www.doctrine-project.org/documentation/manual/1_2/en/configuration:identifier-quoting&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="15576" author="tba99" created="Thu, 24 Mar 2011 12:51:22 +0000"  >&lt;p&gt;I have a similar problem after executing the symfony (1.4.10) build-schema task:&lt;/p&gt;

&lt;p&gt;  SQLSTATE&lt;span class=&quot;error&quot;&gt;&amp;#91;42000&amp;#93;&lt;/span&gt;: Syntax error or access violation: 2812 &lt;span class=&quot;error&quot;&gt;&amp;#91;Microsoft&amp;#93;&lt;/span&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;SQL Server Native Client 10.0&amp;#93;&lt;/span&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;SQL Server&amp;#93;&lt;/span&gt;Could not find stored procedure &apos;sp_primary_keys_rowset&apos;. (SQLExecute&lt;span class=&quot;error&quot;&gt;&amp;#91;2812&amp;#93;&lt;/span&gt; at ext\pdo_odbc\odbc_stmt.c:254). Failing Query: &quot;EXEC sp_primary_keys_rowset @table_name = Appointment&quot;&lt;/p&gt;

&lt;p&gt;I hoped ATTR_QUOTE_IDENTIFIER will also solve my problem but I get the sama error message:&lt;/p&gt;

&lt;p&gt;  SQLSTATE&lt;span class=&quot;error&quot;&gt;&amp;#91;42000&amp;#93;&lt;/span&gt;: Syntax error or access violation: 2812 &lt;span class=&quot;error&quot;&gt;&amp;#91;Microsoft&amp;#93;&lt;/span&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;SQL Server Native Client 10.0&amp;#93;&lt;/span&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;SQL Server&amp;#93;&lt;/span&gt;Could not find stored procedure &apos;sp_primary_keys_rowset&apos;. (SQLExecute&lt;span class=&quot;error&quot;&gt;&amp;#91;2812&amp;#93;&lt;/span&gt; at ext\pdo_odbc\odbc_stmt.c:254). Failing Query: &quot;EXEC sp_primary_keys_rowset @table_name = &lt;span class=&quot;error&quot;&gt;&amp;#91;Appointment&amp;#93;&lt;/span&gt;&quot;&lt;/p&gt;

</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-405] isset() via array interface does not &quot;see&quot; virtual property defined inside the model definition</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-405</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;see: &lt;a href=&quot;http://groups.google.com/group/doctrine-user/browse_thread/thread/0e41373cd46872a9?hl=en#&quot; class=&quot;external-link&quot;&gt;http://groups.google.com/group/doctrine-user/browse_thread/thread/0e41373cd46872a9?hl=en#&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The issue is caused by isset() returning false if the column is not setup via hasColumn(). The accessor method is however obviously callable on the OO interface. By preventing the isset() call in contains() we got things to work, but its obviously a hack:&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 entity &lt;span class=&quot;code-keyword&quot;&gt;extends&lt;/span&gt; base_entity 
{ 
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function setUp() 
    { 
        parent::setUp(); 
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;hasAccessor(&apos;urlizedname&apos;, &apos;getUrlizedname&apos;); 
    } 
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getUrlizedid() 
    { 
        $type = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_get(&apos;type&apos;); 
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_get(&apos;id&apos;) - $type::$idOffset; 
    } 
    /** 
     * FIXME:hackish override of the parent contains method to support array access of urlizedid, remove &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; possible 
     */ 
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function contains($fieldName) 
    { 
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($fieldName === &apos;urlizedid&apos;) { 
            &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;return&lt;/span&gt; parent::contains($fieldName); 
    } 
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</description>
                <environment></environment>
            <key id="10697">DC-405</key>
            <summary>isset() via array interface does not &quot;see&quot; virtual property defined inside the model definition</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="lsmith">Lukas Kahwe</reporter>
                        <labels>
                    </labels>
                <created>Thu, 7 Jan 2010 22:06:43 +0000</created>
                <updated>Tue, 8 Jun 2010 16:19:00 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 16:19:00 +0000</resolved>
                            <version>1.2.1</version>
                <version>1.2.2</version>
                                <fixVersion>1.2.3</fixVersion>
                                        <due></due>
                    <votes>0</votes>
                        <watches>3</watches>
                        <comments>
                    <comment id="11351" author="seldaek" created="Fri, 8 Jan 2010 09:47:02 +0000"  >&lt;p&gt;To specify a bit more, the problem is caused only if you call isset() to check if the var exists, which obviously is not really required in this case since we know it&apos;s there, but the template engine automatically adds it to prevent notices so it means we can&apos;t read the value unless we call $entity-&amp;gt;getUrlizedid() manually, which is not so great. Other than that the arrayaccess interface still works if you don&apos;t check isset() first.&lt;/p&gt;</comment>
                    <comment id="11922" author="jwage" created="Mon, 1 Mar 2010 18:50:57 +0000"  >&lt;p&gt;I&apos;ve been looking at this, and I don&apos;t think we have any possible fix. This is just how it is, unfortunately. Doctrine 1 FTW &lt;img class=&quot;emoticon&quot; src=&quot;http://www.doctrine-project.org/jira/images/icons/emoticons/smile.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</comment>
                    <comment id="12438" author="dfox" created="Tue, 23 Mar 2010 06:55:07 +0000"  >&lt;p&gt;Why not extend contains() with this simple check?&lt;/p&gt;

&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;if ($this-&amp;gt;hasAccessor($fieldName) {
  return true;
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                    <comment id="12444" author="lsmith" created="Wed, 24 Mar 2010 08:50:55 +0000"  >&lt;p&gt;hmm .. that looks indeed like it would fix the issue. do not know the code in question well enough, but this should also not break anyones code .. would it?&lt;/p&gt;</comment>
                    <comment id="12448" author="jwage" created="Wed, 24 Mar 2010 10:15:45 +0000"  >&lt;p&gt;I think that might work. Did anyone try it out against the test suite?&lt;/p&gt;</comment>
                    <comment id="12451" author="dfox" created="Wed, 24 Mar 2010 11:07:56 +0000"  >&lt;p&gt;Tests against 1.2.1 &lt;/p&gt;

&lt;p&gt;Fails in:&lt;br/&gt;
Doctrine_I18n_TestCase&lt;br/&gt;
Doctrine_Cli_TestCase&lt;/p&gt;

&lt;p&gt;Tests agains the current 1.2 branch from SVN:&lt;/p&gt;

&lt;p&gt;Fails in:&lt;br/&gt;
Doctrine_I18n_TestCase&lt;br/&gt;
Doctrine_Cache_Db_TestCase&lt;/p&gt;

&lt;p&gt;Those tests fail with and without the patch.&lt;/p&gt;</comment>
                    <comment id="12493" author="jwage" created="Mon, 29 Mar 2010 14:18:28 +0000"  >&lt;p&gt;Thanks for the issue and the idea for the patch. It seems to work fine. Hopefully it has no adverse side effects.&lt;/p&gt;</comment>
                    <comment id="12505" author="mh" created="Mon, 29 Mar 2010 16:52:43 +0000"  >&lt;p&gt;Unfortunately, this patch caused problems in my case. Sample code:&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;&lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt;($invoker-&amp;gt;contains(&apos;resource&apos;))
{
	&lt;span class=&quot;code-comment&quot;&gt;// ok, now we have value set, so &lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt; sth with it...
&lt;/span&gt;}
&lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt;
{	
	&lt;span class=&quot;code-comment&quot;&gt;// no value set yet, &lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt; it &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; the first time
&lt;/span&gt;	$invoker-&amp;gt;mapValue(&apos;resource&apos;, $someResourceValue);
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;


&lt;p&gt;Now the first condition is always met.&lt;/p&gt;</comment>
                    <comment id="12507" author="jwage" created="Mon, 29 Mar 2010 17:02:19 +0000"  >&lt;p&gt;I have reverted the change for now. I don&apos;t quite understand your use case. Are you setting a hasAccessor() somewhere?&lt;/p&gt;</comment>
                    <comment id="12508" author="mh" created="Mon, 29 Mar 2010 17:04:19 +0000"  >&lt;p&gt;Yes, sorry I forgot to mention it, I must&apos;ve thought it is obvious &lt;img class=&quot;emoticon&quot; src=&quot;http://www.doctrine-project.org/jira/images/icons/emoticons/smile.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;

&lt;p&gt;I have something like:&lt;br/&gt;
$invoker-&amp;gt;hasAccessorMutator(&apos;resource&apos;, &apos;getResource&apos;, &apos;setResource&apos;);&lt;/p&gt;

&lt;p&gt;Thank you for reverting that change. An author of this ticket could become angry, but I&apos;m sorry I think we have to find another solution.&lt;/p&gt;</comment>
                    <comment id="12509" author="dfox" created="Mon, 29 Mar 2010 17:07:20 +0000"  >&lt;p&gt;Isn&apos;t contains() just for checking if the field exist - like isset()?&lt;br/&gt;
If so, you should check for an actual value and not for the existence of your field.&lt;/p&gt;

&lt;p&gt;Alternatively, we could modify the patch with something like this (untested):&lt;/p&gt;

&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;if ($this-&amp;gt;hasAccessor($fieldName) &amp;amp;&amp;amp; $this-&amp;gt;$fieldName) {
  return true;
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                    <comment id="12511" author="dfox" created="Mon, 29 Mar 2010 17:53:12 +0000"  >&lt;p&gt;Just checked with the code-comment of contains() in Doctrine_Record&lt;/p&gt;

&lt;p&gt;&quot;test whether a field (column, mapped value, related component, accessor) is accessible by @see get()&quot;&lt;/p&gt;

&lt;p&gt;So, I guess the solution to the problem is still valid because the field is accessible. I think Maciej Ho&#322;yszko&apos;s code should be updated to check for an actual value and not just for the existence of the field itself.&lt;/p&gt;

&lt;p&gt;If not - please reopen the issue. As of now it&apos;s included in the list of fixed issues of the 1.2.2 release which is no longer correct &lt;img class=&quot;emoticon&quot; src=&quot;http://www.doctrine-project.org/jira/images/icons/emoticons/smile.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;
</comment>
                    <comment id="12512" author="mh" created="Tue, 30 Mar 2010 03:39:35 +0000"  >&lt;p&gt;Ok now I see that I did not notice hasMappedValue was introduced in rev &lt;span class=&quot;error&quot;&gt;&amp;#91;6730&amp;#93;&lt;/span&gt;, which I should use now instead of contains() in my case.&lt;/p&gt;</comment>
                    <comment id="13204" author="jwage" created="Tue, 8 Jun 2010 16:19:00 +0000"  >&lt;p&gt;The new method should take care of this problem now.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-399] Doctrine_Record::unlink() causes records to be deleted</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-399</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Using Doctrine_Record::unlink() with a One-To-Many relationship, and then saving the record will cause the related records to be deleted. Example:&lt;/p&gt;

&lt;p&gt;You have a Discount linked to many Customers. When revoking a customer&apos;s discount, you unlink the two records. $discount-&amp;gt;unlink(&quot;Customers&quot;, $customer-&amp;gt;id); if you $discount-&amp;gt;save(); afterwards, the Customer will be deleted. &lt;/p&gt;

&lt;p&gt;This seems to be caused due to unlink() not calling the collection&apos;s takeSnapshot() after removing the records, which causes the save to delete them. There didn&apos;t seem to be a clear indication in the documentation it would do this, and in version 1.0.14 it doesn&apos;t seem to do this deletion.&lt;/p&gt;</description>
                <environment>Doctrine 1.2.1 svn tag checkout (&lt;a href=&quot;http://svn.doctrine-project.org/tags/1.2.1&quot;&gt;http://svn.doctrine-project.org/tags/1.2.1&lt;/a&gt;)</environment>
            <key id="10687">DC-399</key>
            <summary>Doctrine_Record::unlink() causes records to be deleted</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="sacho">Svetoslav Shterev</reporter>
                        <labels>
                    </labels>
                <created>Tue, 5 Jan 2010 22:20:10 +0000</created>
                <updated>Wed, 9 Jun 2010 14:31:34 +0000</updated>
                    <resolved>Wed, 9 Jun 2010 14:31:34 +0000</resolved>
                            <version>1.2.1</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Record</component>
                <component>Relations</component>
                        <due></due>
                    <votes>2</votes>
                        <watches>2</watches>
                        <comments>
                    <comment id="11331" author="sacho" created="Tue, 5 Jan 2010 22:52:44 +0000"  >&lt;p&gt;Testcase attached&lt;/p&gt;</comment>
                    <comment id="11923" author="jwage" created="Mon, 1 Mar 2010 18:53:15 +0000"  >&lt;p&gt;Is this not the expected behavior?&lt;/p&gt;</comment>
                    <comment id="11965" author="sacho" created="Tue, 2 Mar 2010 12:25:00 +0000"  >&lt;p&gt;Re-uploaded the test case to show the actually reported bug(oops :/)&lt;/p&gt;

&lt;p&gt;unlink() even with $now=true only sets the foreign key in Phonenumber to null. But if you do unlink(), and then save(), the phonenumber is outright deleted.&lt;/p&gt;

&lt;p&gt;I&apos;m not sure if it is expected behavior, since in the example (Discounts and Customers), it deletes the customer record outright &lt;img class=&quot;emoticon&quot; src=&quot;http://www.doctrine-project.org/jira/images/icons/emoticons/smile.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;</comment>
                    <comment id="13209" author="jwage" created="Tue, 8 Jun 2010 16:50:43 +0000"  >&lt;p&gt;Can you provide a patch? All i see is the full UnitOfWork file and I believe it has changed since you attached your version.&lt;/p&gt;</comment>
                    <comment id="13258" author="sigma" created="Wed, 9 Jun 2010 14:21:05 +0000"  >&lt;p&gt;patch for UnitOfWork.php&lt;/p&gt;</comment>
                    <comment id="13259" author="jwage" created="Wed, 9 Jun 2010 14:31:34 +0000"  >&lt;p&gt;Thanks for the issue, patch and test case! All looks good and I committed it!&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10410" name="DC399TestCase.php" size="2369" author="sacho" created="Tue, 2 Mar 2010 12:30:32 +0000" />
                    <attachment id="10636" name="UnitOfWork.php.patch" size="1512" author="sigma" created="Wed, 9 Jun 2010 14:21:05 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-391] Connection rollback exception hides real exception</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-391</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Same issue as &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-207&quot; class=&quot;external-link&quot;&gt;http://www.doctrine-project.org/jira/browse/DC-207&lt;/a&gt; but also for the 1.1 branch. &lt;/p&gt;

&lt;p&gt;This is not only an issue when trying to talk to non-existing databases but for any exception thrown by the connection.&lt;/p&gt;

&lt;p&gt;UnitOfWork.php:133&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-xhtml&quot;&gt;        } catch (Exception $e) {
            // Make sure we roll back our internal transaction
            //$record-&amp;gt;state($state);
            $conn-&amp;gt;rollback();
            throw $e;
        }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</description>
                <environment></environment>
            <key id="10670">DC-391</key>
            <summary>Connection rollback exception hides real exception</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="spockz">Alessandro Vermeulen</reporter>
                        <labels>
                    </labels>
                <created>Fri, 1 Jan 2010 14:21:56 +0000</created>
                <updated>Tue, 8 Jun 2010 15:14:00 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 15:14:00 +0000</resolved>
                            <version>1.1.6</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Connection</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>1</watches>
                        <comments>
                    <comment id="13198" author="jwage" created="Tue, 8 Jun 2010 15:14:00 +0000"  >&lt;p&gt;This is already fixed in Doctrine 1.2&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-364] Adding the fieldName to mutator/accessor methods</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-364</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;Would it be possible to add the fieldName to the function variables when a mutator or accessor function is called. This would allow for more generalized accessor / mutator functions that can be reused easily.&lt;/p&gt;

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

&lt;p&gt;public function mutatorFunction($value, $load, $fieldName)&lt;br/&gt;
{&lt;br/&gt;
    $this-&amp;gt;_set($fieldName, someValidationFunction($value));&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;Thank you&lt;/p&gt;</description>
                <environment></environment>
            <key id="10627">DC-364</key>
            <summary>Adding the fieldName to mutator/accessor methods</summary>
                <type id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/improvement.png">Improvement</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="carlalexander">Carl Alexander</reporter>
                        <labels>
                    </labels>
                <created>Wed, 16 Dec 2009 22:32:42 +0000</created>
                <updated>Tue, 8 Jun 2010 16:49:58 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 16:49:58 +0000</resolved>
                            <version>1.2.1</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Record</component>
                        <due></due>
                    <votes>1</votes>
                        <watches>1</watches>
                        <comments>
                    <comment id="11926" author="jwage" created="Mon, 1 Mar 2010 18:57:51 +0000"  >&lt;p&gt;I don&apos;t understand the issue. Can you please provide more valid information, detailed descriptions, sample code, test cases, etc.&lt;/p&gt;</comment>
                    <comment id="12569" author="andrewcoulton" created="Mon, 5 Apr 2010 07:41:16 +0000"  >&lt;p&gt;I believe the issue is that there may be logic common to mutators across a whole record (or indeed a set of records). A classic example would be date fields. Doctrine uses the ISO 8601 format for dates entirely, but often we want a date field to be accessible directly as a DateTime object or a UNIX timestamp to allow use in date formatting functions without additional strtotime overhead. Or we might want the application to automatically convert a user-provided date from a locale based format to ISO 8601.&lt;/p&gt;

&lt;p&gt;The current pattern requires a custom accessor/mutator to each field - therefore a record with three date fields would have three accessors and mutators. I believe the OP&apos;s suggestion is that the fieldName be added as a parameter to the call to the accessor/mutator so that a single accessor/mutator pair could serve multiple fields. Indeed, we could then write a behaviour that includes the accessor/mutator and registers it on all date fields, or whatever other recurring field type/name/etc we have in the application.&lt;/p&gt;

&lt;p&gt;As PHP will allow a function to be called with additional arguments, I believe all that&apos;s needed is to add the parameter to the calls in Doctrine_Record::set and Doctrine_Record::get as per the attached patch. Mutators/Accessors that care would then be able to access the field name as a second parameter, but without breaking any existing code.&lt;/p&gt;</comment>
                    <comment id="12570" author="andrewcoulton" created="Mon, 5 Apr 2010 07:42:06 +0000"  >&lt;p&gt;Suggested patch to Doctrine_Record to implement this improvement&lt;/p&gt;</comment>
                    <comment id="12584" author="carlalexander" created="Tue, 6 Apr 2010 18:03:46 +0000"  >&lt;p&gt;Sorry meant to get back to you about this sooner.&lt;/p&gt;

&lt;p&gt;What Andrew has described is exactly the issue I am having and his suggested patch is what I would hope to see implemented.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="10543" name="accessor_mutator_fieldName.patch" size="879" author="andrewcoulton" created="Mon, 5 Apr 2010 07:42:06 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-363] Multiple connections and i18n</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-363</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;I used to work with a single database named &quot;doctrine&quot;. The query was working properly.&lt;/p&gt;

&lt;p&gt;I then decided to use 2 databases so I got my schema like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;connection: doctrine&lt;/p&gt;

&lt;p&gt;Category:&lt;br/&gt;
  actAs:&lt;br/&gt;
    I18n:&lt;br/&gt;
      actAs:&lt;br/&gt;
        Sluggable:&lt;br/&gt;
          fields: &lt;span class=&quot;error&quot;&gt;&amp;#91;name&amp;#93;&lt;/span&gt;&lt;br/&gt;
        Timestampable: ~&lt;br/&gt;
      fields: &lt;span class=&quot;error&quot;&gt;&amp;#91;name, description&amp;#93;&lt;/span&gt;&lt;br/&gt;
  columns:&lt;br/&gt;
    id: ~&lt;br/&gt;
    name:&lt;br/&gt;
      type: string(255)&lt;br/&gt;
      notnull: true&lt;br/&gt;
    description: string&lt;/p&gt;

&lt;p&gt;User:&lt;br/&gt;
  connection: second&lt;br/&gt;
  columns:&lt;br/&gt;
    id: ~&lt;br/&gt;
    name:&lt;br/&gt;
      type: string(255)&lt;br/&gt;
      notnull: true&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;I did setup my connections in config/databases.yml this way:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;all:&lt;br/&gt;
  doctrine:&lt;br/&gt;
   // ....&lt;br/&gt;
  second:&lt;br/&gt;
   // ....&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;build-model, build-forms, build-filters and cc got ran. But now, I got an exception saying the &quot;Translation&quot; relation doesn&apos;t exist. The Base Models include correctly the bindComponent line:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Doctrine_Manager::getInstance()-&amp;gt;bindComponent(&apos;Category&apos;, &apos;doctrine&apos;);&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;For now, I managed to kind of fixing it with simply swapping the databases order in my config/databases.yml and it&apos;s now working again perfectly.&lt;/p&gt;

&lt;p&gt;I forgot to mention that in the CategoryTable when i call $this-&amp;gt;getConnection()-&amp;gt;getName(), it outputs &quot;second&quot;&lt;/p&gt;</description>
                <environment>MySQL 5.1.37&lt;br/&gt;
PHP 5.2.11&lt;br/&gt;
symfony 1.2.11 DEV&lt;br/&gt;
&lt;br/&gt;
symfony 1.4.13&lt;br/&gt;
PHP 5.3.6 &lt;br/&gt;
Postgres 8.4.8&lt;br/&gt;
</environment>
            <key id="10626">DC-363</key>
            <summary>Multiple connections and i18n</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="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="xavismeh">Xav.</reporter>
                        <labels>
                    </labels>
                <created>Wed, 16 Dec 2009 19:18:24 +0000</created>
                <updated>Wed, 28 Mar 2012 08:24:28 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 15:04:20 +0000</resolved>
                            <version>1.0.14</version>
                <version>1.2.2</version>
                <version>1.2.3</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Connection</component>
                <component>I18n</component>
                        <due></due>
                    <votes>1</votes>
                        <watches>5</watches>
                        <comments>
                    <comment id="11613" author="colin.darie" created="Thu, 4 Feb 2010 23:05:56 +0000"  >&lt;p&gt;I&apos;m experiencing the same issue with 4 connections. The I18n behavior is almost unusable for models whose connection is not the last one defined. I searched for an acceptable solution but I haven&apos;t found one (IMHO the setting to the right connection before each query is not acceptable in large projects). I tried to do like in Search behavior, but it didn&apos;t work, I doesn&apos;t know enough doctrine internals to understand why.&lt;/p&gt;</comment>
                    <comment id="11931" author="jwage" created="Mon, 1 Mar 2010 19:46:40 +0000"  >&lt;p&gt;Can you test this in Doctrine 1.2? I believe it is fixed.&lt;/p&gt;</comment>
                    <comment id="15330" author="geg" created="Thu, 17 Feb 2011 08:01:33 +0000"  >&lt;p&gt;I am using the latest symfony 1.4 which is doctrine 1.2.3 afaik, and this bug still exists.&lt;br/&gt;
Try&lt;/p&gt;

&lt;p&gt;  actAs:&lt;br/&gt;
    I18n:&lt;br/&gt;
      fields: &lt;span class=&quot;error&quot;&gt;&amp;#91;name&amp;#93;&lt;/span&gt;&lt;br/&gt;
      generateFiles: true&lt;br/&gt;
      generatePath: /project/lib/model/doctrine/i18n&lt;/p&gt;

&lt;p&gt;and the resulting model base class is not bound to the correct connection.&lt;/p&gt;</comment>
                    <comment id="15890" author="jsiponen" created="Fri, 27 May 2011 14:49:51 +0000"  >&lt;p&gt;I&apos;ve just now battled with the very same problem in Doctrine 1.2 (the version bundled with symfony 1.4) and the problem seems to be caused by the fact that Doctrine_Record_Generator simply isn&apos;t written such that it is able to reinitialize generators for unloaded table instances after a connection is closed. This problem also manifests itself after a table has been loaded in a connection and one tries retrieve a table again after Doctrine_Connection-&amp;gt;evictTables() has been called. This makes it impossible to to open more than one connection at a time in a request/script when using behaviors that dynamically modify table instances (such as the i18n behavior). The issue states that this has been fixed but I looked at the latest code and the problem still seems to be very much the same. &lt;/p&gt;

&lt;p&gt;Doctrine_Record_Generator determines if it needs to run its initialization methods simply by checking if the to-be generated class, as defined by the className option, exists using a class_exists call. This means that the first time this method is called the initialization happens but for every subsequent call no initialization is made. Now, in the i18m behavior, the important initialization happens in its setTableDefinition method in which it removes any of the translated fields from the table instance that is been setup and redefines them as relations on the to-be-created Translation class. It then finishes off by dynamically declaring the new class for the translation record using its generateClassFromTable method.&lt;/p&gt;

&lt;p&gt;Thus, the first time everything goes smoothly and the i18n generator&apos;s setTableDefinition is called and the table instance is properly initialized. Everything will now work as expected while the current connection is open since the connection instance keeps the i18n modified table instances alive and well for callers.&lt;/p&gt;

&lt;p&gt;But, when the current connection is closed the i18n modified table instances it holds are also removed (goes out of scope). Then, when a new connection is opened, this new connection will start without having any table instances. This means that the next time one asks the new connection for a table instance of the same class with the i18n behavior the i18n behaviors will fail to initialize because the generator at this time believes its class has actually been initialized which, in turn, means that the table using the i18n behavior isn&apos;t properly initialized. No initialization means that this table will now include the non-existant i18n fields in the select part of its queries (those are in the translation table) causing those queries to fail miserably.&lt;/p&gt;

&lt;p&gt;I believe this could be fixed by adding a static attribute to Doctrine_Record_Generator that tracks the spl_object_hash of the underlying dbh instance variable of the doctrine connection of the table parameter. If the hash is the same the next time that the initialize method is called the generator can decide not to reinitialize itself but if it detects that the hash of the current connection is different then that is definitely a clue to the generator that it needs to reinitialize itself (i.e. run all of the initialization methods but generateClassFromTable which should&apos;t be called more than once).&lt;/p&gt;

&lt;p&gt;Maybe do it like this perhaps:&lt;/p&gt;

&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt; 
abstract class Doctrine_Record_Generator extends Doctrine_Record_Abstract
{
  public function initialize(Doctrine_Table $table)
  {
    /* ... */ 
  
    $currentConnectionHash = spl_object_hash($table-&amp;gt;getConnection()-&amp;gt;getDbh());
    
    //Next part is called if this is the first connection made or if this is a new open connection with new table instances
    if ($currentConnectionHash != self::$lastConnectionHash)
    {
      self::$lastConnectionHash = $currentConnectionHash;
      
      $this-&amp;gt;buildTable();

      $fk = $this-&amp;gt;buildForeignKeys($this-&amp;gt;_options[&apos;table&apos;]);

      $this-&amp;gt;_table-&amp;gt;setColumns($fk);

      $this-&amp;gt;buildRelation();

      $this-&amp;gt;setTableDefinition();
      $this-&amp;gt;setUp();
      
      if ($this-&amp;gt;_options[&apos;generateFiles&apos;] === false &amp;amp;&amp;amp; class_exists($this-&amp;gt;_options[&apos;className&apos;])) {
        $this-&amp;gt;generateClassFromTable($this-&amp;gt;_table); //Don&apos;t generate the class more than once ever
      }
      
      $this-&amp;gt;buildChildDefinitions();

      $this-&amp;gt;_table-&amp;gt;initIdentifier();
    }
  }
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; </comment>
                    <comment id="16369" author="sarcas" created="Tue, 23 Aug 2011 14:24:10 +0000"  >&lt;p&gt;I&apos;m also experiencing this issue, using the stable version of Symfony 1.4.13. If I define multiple database connections, the i18n Translation relations fail with this call: Doctrine_Relation_Parser-&amp;gt;getRelation(&apos;Translation&apos;, )&lt;/p&gt;

&lt;p&gt;&apos;Unknown relation alias Translation&apos;&lt;/p&gt;

&lt;p&gt;dev:&lt;br/&gt;
  mysql1:&lt;br/&gt;
      class: sfDoctrineDatabase&lt;br/&gt;
      param:&lt;br/&gt;
        dsn: &apos;mysql:host=localhost;dbname=microscooters&apos;&lt;br/&gt;
        username: microuser_uk&lt;br/&gt;
        password: sailing&lt;/p&gt;

&lt;p&gt;  mysql2:&lt;br/&gt;
    class: sfDoctrineDatabase&lt;br/&gt;
    param:&lt;br/&gt;
      dsn: &apos;mysql:host=localhost;dbname=microscooters_ie&apos;&lt;br/&gt;
      username: microuser_ie&lt;br/&gt;
      password: windy&lt;/p&gt;

&lt;p&gt;  postgresql:&lt;br/&gt;
    class: sfDoctrineDatabase&lt;br/&gt;
    param:&lt;br/&gt;
      dsn: &apos;pgsql:host=localhost;dbname=mses6&apos;&lt;br/&gt;
      username: postgres&lt;br/&gt;
      password: postgres&lt;/p&gt;

&lt;p&gt;In this case, the primary connection is the postgresql one, and that is where the i18n behaviour is defined:&lt;/p&gt;

&lt;p&gt;Category:&lt;br/&gt;
  actAs:&lt;br/&gt;
    Timestampable: ~&lt;br/&gt;
    Auditable: ~&lt;br/&gt;
    NestedSet: ~&lt;br/&gt;
    I18n:&lt;br/&gt;
      fields: &lt;span class=&quot;error&quot;&gt;&amp;#91;picture_id,  sort_type, name, handle, subheading, breadcrumb, description, enabled, meta_title, meta_keywords, meta_description&amp;#93;&lt;/span&gt;&lt;br/&gt;
      i18nField: culture&lt;br/&gt;
      length: 5&lt;br/&gt;
      actAs:&lt;br/&gt;
        Timestampable: ~&lt;br/&gt;
        Auditable: ~&lt;br/&gt;
      ...&lt;/p&gt;

&lt;p&gt;I tried to implement the suggest above (ie adding a static hash of the database handle to the Doctrine_Record_Generator class file, which does clear out the connections. However, I then have difficulty with Doctrine recognizing CategoryTranslation as a class:&lt;/p&gt;

&lt;p&gt;&quot;( ! ) Fatal error: Class &apos;CategoryTranslation&apos; not found in /sitename/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Table.php on line 545&quot;&lt;/p&gt;

&lt;p&gt;Is there anything else I can to do test/fix this?&lt;/p&gt;</comment>
                    <comment id="16371" author="jsiponen" created="Tue, 23 Aug 2011 15:15:21 +0000"  >&lt;p&gt;This is a duplicate of &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DC-373&quot; class=&quot;external-link&quot;&gt;http://www.doctrine-project.org/jira/browse/DC-373&lt;/a&gt;. I&apos;ve also added a failing test case to that issue that should reproduce the issue as described here.&lt;/p&gt;</comment>
                    <comment id="17665" author="lvqingan" created="Wed, 28 Mar 2012 08:24:28 +0000"  >&lt;p&gt;still exists in 1.2.4&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>

<item>
            <title>[DC-349] Issue with quoting of booleans in Oracle</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-349</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;I&apos;ve run into a problem where I&apos;m unable to set a default value for a boolean field when creating Oracle tables using Doctrine.  The summary of this issue is that when Doctrine quotes a &apos;0&apos; or false value for a boolean field, it comes back blank... which doesn&apos;t work as an option for the DEFAULT parameter of field definitions in table creation.&lt;/p&gt;

&lt;p&gt;Here are the hairy details.  I have a schema which looks something like this (simplified for the 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;User:

  tableName: users

  columns:

    id: {type: integer, primary: &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;, autoincrement: &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;}

    username: {type: string, length: 255, unique: &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;, notnull: &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;}

    disabled: {type: &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt;, &lt;span class=&quot;code-keyword&quot;&gt;default&lt;/span&gt;: &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;}

&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When I export the table, it&apos;s generating invalid DDL like this:&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;CREATE TABLE users (id NUMBER(8), username VARCHAR2(255) NOT NULL UNIQUE, disabled NUMBER(1) DEFAULT , PRIMARY KEY(id))
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The important part of this is the DEFAULT parameter on the &apos;disabled&apos; field definition &amp;#8211; it&apos;s missing the value.  I tracked all this down to an issue in Doctrine_Formatter-&amp;gt;quote(), which gets called when the DDL is being created.  When passed &apos;0&apos; as its input with a type of boolean, it apparently returns the empty string.  This may ultimately be a bug in the PDO_OCI driver, because the quote method is relying on the quote method of the database handle.&lt;/p&gt;

&lt;p&gt;I&apos;ve hacked around this by overriding the behaviour of the quote method in Doctrine_Connection_Oracle.  I did this by adding the following method:&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;    /**
     * Override quote behaviour &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt; to fix issues with quoting of
     * &lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt; values.
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function quote($input, $type = &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;)
    {
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($type === &apos;&lt;span class=&quot;code-object&quot;&gt;boolean&lt;/span&gt;&apos;) {
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($input === &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;) {
                &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;null&lt;/span&gt;;
            } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
                &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; (($input) ? 1 : 0);    
            }
      } &lt;span class=&quot;code-keyword&quot;&gt;else&lt;/span&gt; {
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; parent::quote($input, $type);  
      }
    }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It seems to work for me, but I&apos;d appreciate it if wiser heads than me would take a look and see if this is a sign of some larger issue, and if the way I&apos;ve fixed it seems appropriate.  I also am unsure of how/if this needs to propogate to newer versions.&lt;/p&gt;</description>
                <environment>Oracle Driver</environment>
            <key id="10598">DC-349</key>
            <summary>Issue with quoting of booleans in Oracle</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="dbrewer">David Brewer</reporter>
                        <labels>
                    </labels>
                <created>Thu, 10 Dec 2009 02:19:51 +0000</created>
                <updated>Tue, 8 Jun 2010 15:10:18 +0000</updated>
                    <resolved>Tue, 8 Jun 2010 15:10:18 +0000</resolved>
                            <version>1.0.14</version>
                                <fixVersion>1.2.3</fixVersion>
                                <component>Connection</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>0</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>