<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Wed Jun 19 00:47:32 UTC 2013

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

<item>
            <title>[DBAL-406] PostgreSqlSchemaManager::tablesExist() misses schema-qualified table names if they exist in the first schema on the search path</title>
                <link>http://www.doctrine-project.org/jira/browse/DBAL-406</link>
                <project id="10040" key="DBAL">Doctrine DBAL</project>
                        <description>&lt;p&gt;Please see &lt;a href=&quot;https://github.com/doctrine/migrations/issues/99&quot; class=&quot;external-link&quot;&gt;https://github.com/doctrine/migrations/issues/99&lt;/a&gt; for additional background.&lt;/p&gt;

&lt;p&gt;To reproduce:&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;
CREATE SCHEMA test_schema;
CREATE TABLE test_schema.test_table (test_column TEXT);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then in Doctrine:&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;
$connection-&amp;gt;executeUpdate(&apos;SET search_path=test_schema;&apos;);
$result = $connection-&amp;gt;getSchemaManager()-&amp;gt;tablesExist(array(&apos;test_schema.test_table&apos;));
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;tt&gt;$result&lt;/tt&gt; is false when it should be true.&lt;/p&gt;

&lt;p&gt;The error occurs because &lt;tt&gt;PostgreSqlSchemaManager&lt;/tt&gt; returns the bare table name from &lt;tt&gt;getPortableTablesList()&lt;/tt&gt; if the schema is the first one in the search path.&lt;/p&gt;

&lt;p&gt;The full explanation is...&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;AbstractSchemaManager::tablesExist()&lt;/tt&gt; calls &lt;tt&gt;$this-&amp;gt;getPortableTablesList()&lt;/tt&gt; before checking if the tables exist.&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;PostgreSqlSchemaManager&lt;/tt&gt; overrides this in &lt;tt&gt;_getPortableTableDefinition()&lt;/tt&gt;  by comparing the schema for the table with the search path for the connection. If the table schema is the first one in the search path, then it returns the bare table name, if it isn&apos;t then it returns the schema-qualified table name (i.e. schema.table).&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;tablesExist()&lt;/tt&gt; does an array_intersect to check that all the tables in the search array exist in the database.&lt;/p&gt;

&lt;p&gt;If one of the tables in the search array was schema-qualified but also in the first schema on the search path, then you end up checking:&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;array_intersect(array(&apos;test_schema.test_table&apos;), array(&apos;test_table&apos;))&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;which fails.&lt;/p&gt;

&lt;p&gt;One way to fix it would be to override &lt;tt&gt;tablesExist()&lt;/tt&gt; in &lt;tt&gt;PostgreSqlSchemaManager&lt;/tt&gt; so that it passes the search array through &lt;tt&gt;getPortableTableDefinition()&lt;/tt&gt; before doing the array_intersect:&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;
    /**
     * Return &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; all the given tables exist.
     *
     * @param array $tableNames
     * @&lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; bool
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function tablesExist($tableNames)
    {
        foreach ($tableNames as $key =&amp;gt; $tableName) {
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (strpos($tableName, &apos;.&apos;) !== &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;) {
                $tableName = explode(&apos;.&apos;, $tableName, 2);
                $tableNames[$key] = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_getPortableTableDefinition(array(&apos;schema_name&apos;=&amp;gt;$tableName[0], &apos;table_name&apos;=&amp;gt;$tableName[1]));
            }
        }
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; parent::tablesExist($tableNames);
    }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I&apos;m happy to provide a PR on GitHub if you want.&lt;/p&gt;</description>
                <environment>Postgresql 9.1</environment>
            <key id="14352">DBAL-406</key>
            <summary>PostgreSqlSchemaManager::tablesExist() misses schema-qualified table names if they exist in the first schema on the search path</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="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/open.png">Open</status>
                    <resolution id="-1">Unresolved</resolution>
                    <security id="10000">All</security>
                        <assignee username="beberlei">Benjamin Eberlei</assignee>
                                <reporter username="rhunwicks">Roger Hunwicks</reporter>
                        <labels>
                        <label>postgresql</label>
                    </labels>
                <created>Mon, 7 Jan 2013 08:33:41 +0000</created>
                <updated>Mon, 7 Jan 2013 08:33:41 +0000</updated>
                                    <version>2.3.1</version>
                                                <component>Schema Managers</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>1</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>