ZF-7070: Zend_Db_Adapter_Pdo_Pgsql - improved describeTable()

Description

Hi, Today I started to to work with ZF and I followed some tutorial from Pro PHP book. Unfortunately I made some spelling error, which was really hard to debug.

The problem was I made a one letter misspell in following class:

class Customers extends Zend_Db_Table { protected $name = 'customers'; protected $_primary = 'customer_id'; protected $_sequence = 'customers_customer_id_seq'; }

The problem was of course: protected $name = 'customers';

Because of above error I got following Exception: Zend_Db_Table_Exception: Primary key column(s) (customer_id) are not columns in this table () in /usr/share/php/ZendFramework/ZendFramework-1.8.3/library/Zend/Db/Table/Abstract.php on line 796

I didn't know why there is no columns for my table.

The problem is, that in my case ZF setted up table name for me: 'Customers' - using class name. PostgreSQL is case sensitive, so if my table was: 'customers', not 'Customers' - it did not find anything. Method describeTable() from Zend_Db_Adapter_Pdo_Pgsql class will return empty array.

For me it should check if specified table really exists in database. It is very easy:

$sql = "SELECT c.relname FROM pg_class AS c WHERE c.relname = " . $this->quote($tableName);

If above query returns no data, it means that there is no such table, so you could raise an exception! And my advice is to add such exception to method describeTable()

Best regards, Tomasz Kuter

Comments

It seems as though you are following a faulty tutorial. Please see the Zend_Db_Table documentation for proper usage. It appears that protected $name should be protected $_name. Also, you should not set the $_primary or $_cols members of the class as that information will be setup for you by the Table class during _setup() and _setupPrimaryKey().

If you feel there is still an issue after proper usage, feel free to reopen with more information.