ZF-7758: Zend_Db_Table and join = table/alias lowercased

Description

Adapter used: Pdo_Pgsql Tablename: camelCase Code:

 
$select = $xTable->select()
            ->setIntegrityCheck(false)
            ->from($xTable, array('action' => 'name'))
            ->joinInner...

Error: SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table "camelcase" #table is lowercased

Manual query

 
$select = $xTable->select()
            ->setIntegrityCheck(false)
            ->from('camelCase', array('action' => 'name'))
            ->joinInner...

will work as expected.

Edit: Same problem with aliasing.


->joinLeft(array('pGroups' => 'groups')... #pGroups will become pgroups

Comments

Why it's not a ZF issue? Postgresql error code 42P01 means UNDEFINED TABLE. Table is defined as protected $_name = 'camelCase'; Query generated by ZF tries to access table which name is lowercased to "camelcase" and thus exception is thrown. As You can see this only happens when object is passed to select->from method.

I performed several tests.

In version 1.9.2 and in trunk no problem.

Analize the string generated Zend_Db_Table_Select.

Can help.

--query error SELECT "camelCase".* FROM camelCase; --error: SQL state: 42P01

--query error SELECT camelCase.* FROM "camelCase"; --error: SQL state: 42P01

--query success SELECT "camelCase".* FROM "camelCase";

Note quotation marks in the table.

Yes, with simple select this is ok, but try inner join.


CREATE TABLE some."teSt"
(
  id integer NOT NULL DEFAULT nextval('some."teSt_id_seq"'::regclass),
  CONSTRAINT "teSt_pkey" PRIMARY KEY (id)
)

class Default_Model_DbTable_Test extends Zend_Db_Table_Abstract {
  protected $_name = 'teSt';
}

$xTable = new Default_Model_DbTable_Test();
$select = $xTable->select()
            ->setIntegrityCheck(false)
            ->from($xTable, array('action' => 'name'))
#fetch - this is ok, profiler: SELECT "teSt"."name" AS "action" FROM "some"."teSt"

$select = $xTable->select()
            ->setIntegrityCheck(false)
            ->from($xTable, array('action' => 'name'))
            ->joinInner('a', 'a.id = teSt.id');
#fetch - SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table "test" LINE 2: INNER JOIN...

Please ask if You need some more info.

your code

  
$select = $table->select()
           ->setIntegrityCheck(false)
           ->from($table, array('action' => 'name'))
           ->joinInner('a', 'a.id = teSt.id');

alter for


$select = $table->select()
           ->setIntegrityCheck(false)
           ->from($table, array('action' => 'name'))
           ->joinInner('a', 'a.id = "teSt".id');

problem in ->joinInner('a', 'a.id = teSt.id');