ZF2-405: PostgreSQL driver add quotes to the sentences and postgres can't resolve them

Description

Using ZF2b5

I have problems working with postgres with Zend\Db it adds quotes to the sentences and postgres can't execute them.

This is the error:

D:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Db\Adapter\Driver\Pdo\Statement.php:214

SQLSTATE[42P01]: Undefined table: 7 ERROR: no existe la relación «zf2tutorial.album» LINE 1: SELECT "zf2tutorial.album".* FROM "zf2tutorial.album" ^

I executed the same sentence in pgsql and throws that same error. Then I removed the quotes and it works fine.

Comments

What is the full reproduction of this issue? What method are you calling?

Hi,

This is the message in the browser:


An error occurred An error occurred during execution; please try again later. Additional information: Zend\Db\Adapter\Exception\InvalidQueryException File: C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Db\Adapter\Driver\Pdo\Statement.php:216 Message: Statement could not be executed Stack trace:

0 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Db\TableGateway\AbstractTableGateway.php(235): Zend\Db\Adapter\Driver\Pdo\Statement->execute()

1 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Db\TableGateway\AbstractTableGateway.php(210): Zend\Db\TableGateway\AbstractTableGateway->executeSelect(Object(Zend\Db\Sql\Select))

2 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Db\TableGateway\AbstractTableGateway.php(197): Zend\Db\TableGateway\AbstractTableGateway->selectWith(Object(Zend\Db\Sql\Select))

3 C:\Sistemas\zf\zf2\zf2-tutorial\module\Album\src\Album\Model\AlbumTable.php(24): Zend\Db\TableGateway\AbstractTableGateway->select()

4 C:\Sistemas\zf\zf2\zf2-tutorial\module\Album\src\Album\Controller\AlbumController.php(17): Album\Model\AlbumTable->fetchAll()

5 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractActionController.php(150): Album\Controller\AlbumController->indexAction()

6 [internal function]: Zend\Mvc\Controller\AbstractActionController->execute(Object(Zend\Mvc\MvcEvent))

7 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(465): call_user_func(Array, Object(Zend\Mvc\MvcEvent))

8 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(205): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))

9 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractActionController.php(117): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))

10 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Mvc\DispatchListener.php(151): Zend\Mvc\Controller\AbstractActionController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))

11 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))

12 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(465): call_user_func(Array, Object(Zend\Mvc\MvcEvent))

13 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(205): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))

14 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(317): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))

15 C:\Sistemas\zf\zf2\zf2-tutorial\public\index.php(12): Zend\Mvc\Application->run()

16 {main}

Previous exceptions: PDOException File: C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Db\Adapter\Driver\Pdo\Statement.php:214 Message: SQLSTATE[42P01]: Undefined table: 7 ERROR: no existe la relación «zf2tutorial.album» LINE 1: SELECT "zf2tutorial.album".* FROM "zf2tutorial.album" ^ Stack trace:

0 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Db\Adapter\Driver\Pdo\Statement.php(214): PDOStatement->execute()

1 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Db\TableGateway\AbstractTableGateway.php(235): Zend\Db\Adapter\Driver\Pdo\Statement->execute()

2 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Db\TableGateway\AbstractTableGateway.php(210): Zend\Db\TableGateway\AbstractTableGateway->executeSelect(Object(Zend\Db\Sql\Select))

3 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Db\TableGateway\AbstractTableGateway.php(197): Zend\Db\TableGateway\AbstractTableGateway->selectWith(Object(Zend\Db\Sql\Select))

4 C:\Sistemas\zf\zf2\zf2-tutorial\module\Album\src\Album\Model\AlbumTable.php(24): Zend\Db\TableGateway\AbstractTableGateway->select()

5 C:\Sistemas\zf\zf2\zf2-tutorial\module\Album\src\Album\Controller\AlbumController.php(17): Album\Model\AlbumTable->fetchAll()

6 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractActionController.php(150): Album\Controller\AlbumController->indexAction()

7 [internal function]: Zend\Mvc\Controller\AbstractActionController->execute(Object(Zend\Mvc\MvcEvent))

8 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(465): call_user_func(Array, Object(Zend\Mvc\MvcEvent))

9 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(205): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))

10 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractActionController.php(117): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))

11 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Mvc\DispatchListener.php(151): Zend\Mvc\Controller\AbstractActionController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))

12 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))

13 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(465): call_user_func(Array, Object(Zend\Mvc\MvcEvent))

14 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(205): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))

15 C:\Sistemas\zf\zf2\zf2-tutorial\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(317): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))

16 C:\Sistemas\zf\zf2\zf2-tutorial\public\index.php(12): Zend\Mvc\Application->run()

17 {main}


This is the error:

SQLSTATE[42P01]: Undefined table: 7 ERROR: no existe la relación «zf2tutorial.album» LINE 1: SELECT "zf2tutorial.album".* FROM "zf2tutorial.album" ^

This is the connection in zf2-tutorial\config\autoload:

<?php return array( 'db' => array( 'driver' => 'Pdo_Pgsql', 'database' => 'pruebas', 'username' => 'rusuario', 'password' => 'rusuario', 'hostname' => 'windows-db' ), 'service_manager' => array( 'factories' => array( 'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory', ), ), );

Thanks.

I realize you are using Akrabat's ZF2 Tutorial, but what exactly is the API call to Zend\Db\Sql that is causing this error?

Yes, is the akrabat's ZF2 tutorial but using postgres.

The sentence is

    return new ViewModel(array(
            'albums' => $this->getAlbumTable()->fetchAll(), 

in the AlbumController.

I'm attaching the AlbumController class, the Album class and the AlbumTable class

AlbumController is in C:\Sistemas\zf\zf2\zf2-tutorial\module\Album\src\Album\Controller

Album and AlbumTable are in C:\Sistemas\zf\zf2\zf2-tutorial\module\Album\src\Album\Model

this is the whole project. It is not complete because in the tutorial I can't continue from this test:

http://zf2-tutorial/album

this is the virtual host:

ServerName zf2-tutorial DocumentRoot c:/sistemas/zf/zf2/zf2-tutorial/public SetEnv APPLICATION_ENV "development" DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all

Thanks.

I've downloaded Akrabats tutorial and I can confirm it works on Postgresql. If you find it doesn't work still, please file issues with his project here:

https://github.com/akrabat/zf2-tutorial/

-ralph

thanks Ralph. I dowloaded all the tutorial and I works well (after some intents) when I don't use a schema. Is there a way to specify a schema in ZF2?