Issue Type: Bug Created: 2012-03-07T20:31:47.000+0000 Last Updated: 2012-07-08T20:59:46.000+0000 Status: Resolved Fix version(s): Reporter: Roger Hunwicks (rhunwicks) Assignee: Ralph Schindler (ralph) Tags: - Zend\Db
Related issues: Attachments:
There is a fatal error in Zend\Db\Adapter\Driver\Pdo\Connection::getDefaultSchema() when using a Postgresql database:
PHP Fatal error: Call to a member function fetch_row() on a non-object in /vendor/ZendFramework/library/Zend/Db/Adapter/Driver/Pdo/Connection.php on line 114
It happens because getDefaultSchema() executes "SELECT DATABASE()" to get the default schema and this function does not exist in Postgresql.
You can fix it by checking that the query was successful before attempting the fetch_row(). I will submit a pull request to that effect.
However, it is not clear that this code belongs here at all. Is the "default schema" concept generic enough to be here. I know that Postgresql has a schema search path, rather than a single schema. Consequently the default schema that new objects are created in will be the first schema in the search path that exists (there is normally a $user entry in the search path that is ignored if there is no schema matching the database username). However if you address an existing object without schema qualification then you will get the first object with the correct name that can be found along the search path.
We could attempt to be more complicated by checking for the first real schema in the search path, but there are performance implications to this and getDefaultSchema may be called a lot (I'm only guessing). In any case, my preference would be for getDefaultSchema() to return false (which is what my pull request does), or possibly null, on the basis that Postgresql doesn't really have a default schema.
Note that this solution doesnt address the question of whether database-specific SQL ("SELECT DATABASE()")should appear in the generic PDO driver.
Posted by Ralph Schindler (ralph) on 2012-03-26T19:19:45.000+0000
Fixed and merged into pull request 934
Posted by Hasan H. Gürsoy (hhgag) on 2012-05-24T16:52:42.000+0000
bugfix has been overwritten, see:
Posted by Maks 3w (maks3w) on 2012-06-06T15:50:08.000+0000
What's the problem?
Your patch is intact.
Posted by Chris Testroet (leftbrained) on 2012-06-21T18:03:24.000+0000
I see two existing problems with Pdo\Connection::getDefaultSchema()
It uses "SELECT DATABASE()" to get the current schema, afaik this only works on MySQL. The SQL Standard says it should be "SELECT CURRENT_SCHEMA". PostgreSQL follows the standard in this respect.
It uses the method PDOStatement::fetch_row() , which doesn't exist. This appears to have been copy/pasted from Mysqli\Connection. This method should use PDOStatement::fetchColumn()
Both of these are addressed in PR 1485. The PR is having a tough time getting reviewed by Ralph, as it's so large.
Posted by Chris Testroet (leftbrained) on 2012-07-08T20:57:29.000+0000
This issue was resolved in PR #1613
Have you found an issue?
See the Overview section for more details.