ZF-5535: Zend_Db_Table does not work with IBM DB/2

Issue Type: Bug Created: 2009-01-13T07:39:21.000+0000 Last Updated: 2011-12-08T07:54:48.000+0000 Status: Resolved Fix version(s): Reporter: Michael Mest (michael.mest) Assignee: Satoru Yoshida (satoruyoshida) Tags: - Zend_Db_Table

Related issues: - ZF-4553



I try to use Zend_Db_Table with DB/2.

My Table class looks like this:

<pre class="highlight">
class Mitarbeiter extends Zend_Db_Table_Abstract{
    protected $_name = 'mitarbeiter';
    protected $_schema = 'orga';
    protected $_primary = 'id';
    protected $_referenceMap = array(
        'Anrede' => array(
            'refTableClass' => 'Anrede',
            'refColumns' => 'id')

When I run a simple select, i should get the following SQL-Statement:

<pre class="highlight">
"SELECT * FROM orga.mitarbeiter" but instead I get "SELECT mitarbeiter.* FROM orga.mitarbeiter"

This kind of SELECT-Statement is not allowed in DB/2.

It would work, if the name of user which is connected to the database is the same that the table schema and u omit the schema name. The result of that would be a statement like

<pre class="highlight">
"SELECT mitarbeiter.* FROM mitarbeiter"

I have to add one more Information:

The Statement:

<pre class="highlight">
"SELECT orga.mitarbeiter.* FROM orga.mitarbeiter"

would work too. It's just necessary that the "Column-Prefix" is the same, as the "Table-Part" of the From-Clause


Posted by huy tran ( on 2009-02-09T11:50:30.000+0000

I too ran into this problem with the Zend_Db_Table class for DB2. Just like the ticket's description said by appending the schema name to the tablename.columnname the problem resolve. So basically your sql statement will look something like this SELECT schema.table.column FROM schema.table; OR SELECT schema.table.* FROM schema.table;

After muckling around with the ZF i've decided to abstract a couple of classes to make this possible. 1. I've created a new directory structure within the ZF architecture library folder like below library ZendExt DB Table 2. Under the Table folder i added two new php files, Abstract.php and Select.php The code for


- - - - - -

------------Select.php------------- \_parts[self::COLUMNS])) { return null; } $columns = array(); foreach ($this->\_parts[self::COLUMNS] as $columnEntry) { list($correlationName, $column, $alias) = $columnEntry; if ($column instanceof Zend\_Db\_Expr) { $columns[] = $this->\_adapter->quoteColumnAs($column, $alias, true); } else { if ($column == self::SQL\_WILDCARD) { $column = new Zend\_Db\_Expr(self::SQL\_WILDCARD); $alias = null; } if (empty($correlationName)) { $columns[] = $this->\_adapter->quoteColumnAs($column, $alias, true); } else { /\* \* @todo: \* By: Huy Tran \* Date: 20080206 \* Description: This code here is for DB2 compatibility. This allow the appendtion of the schema to the front of the column name. \* Eg. Select SELECT WEBSTUFF.ALIAS.ALNAME, WEBSTUFF.ALIAS.ALSID FROM WEBSTUFF.ALIAS \*/ $schema = $this->\_parts[self::FROM][$correlationName]["schema"]; $columns[] = $this->\_adapter->quoteColumnAs(array($schema.'.'.$correlationName, $column), $alias, true); } } } return $sql .= ' ' . implode(', ', $columns); } } ?>

  1. I then update the first 2 lines in my model from the DBTable folder to the following

require_once 'Zend/Db/Table/Abstract.php';

class Model_DbTable_Alias extends Zend_Db_Table_Abstract


require_once 'ZendExt/Db/Table/Abstract.php';

class Model_DbTable_Alias extends ZendExt_Db_Table_Abstract

  1. And thats it. The whole purpose of this abstraction is to update the _renderColumns function within the Zend_Db_Table_Select to prepend the schema name to the column name.

Of course this is a temporary solution until Zend comes up with a fix. But so far this fix has allow me to fix the problem described in the ticket.

Posted by old of Satoru Yoshida ( on 2009-05-18T00:00:23.000+0000

It seems to duplicate ZF-4553

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.