zendframework / zend-db

Db component from Zend Framework
BSD 3-Clause "New" or "Revised" License
101 stars 122 forks source link

Functions as table part in Zend\Db\Sql\Select not quoted correctly when using pdo_pgsql driver #45

Open pdizz opened 9 years ago

pdizz commented 9 years ago

I'm trying to use a function as a table in Zend\Db\Sql\Select and it appears to be quoting incorrectly. The entire function including parens is wrapped in quotes and I get an error saying the table doesnt exist.

<?php

require_once 'vendor/autoload.php';

$config = [
    'driver'   => 'pdo_pgsql',
    'host'     => 'postgresvm.dev',
    'username' => 'user',
    'password' => 'pass',
    'dbname'   => 'mydb',
    'port'     => 5432
];

$dbAdapter  = new \Zend\Db\Adapter\Adapter($config);
$sqlAdapter = new \Zend\Db\Sql\Sql($dbAdapter);

$select = new \Zend\Db\Sql\Select();
$select->from("my_schema.ufn_user_client(2, 3)");

$results =  $dbAdapter->query(
    $sqlAdapter->buildSqlString($select),
    \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
)->toArray();

var_dump($results);

PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "my_schema.ufn_user_client(2, 3)" does not exist. I've tried wrapping it in a Zend\Db\Sql\Expression but it requires the table name to be a string.

vaclavvanik commented 9 years ago

You have to wrap from part into \Zend\Db\Sql\Expression

michalbundyra commented 4 years ago

This repository has been closed and moved to laminas/laminas-db; a new issue has been opened at https://github.com/laminas/laminas-db/issues/138.