ZF-4166: findParentRow fails when foriegn key is null

Issue Type: Bug Created: 2008-09-02T19:14:27.000+0000 Last Updated: 2011-08-20T15:08:28.000+0000 Status: Resolved Fix version(s): Reporter: Grady Kuhnline (heygrady2) Assignee: Satoru Yoshida (satoruyoshida) Tags: - Zend_Db_Table

Related issues: - ZF-3347



Using the examples from the manual for fetching parent rows which uses the example database, the following code will result in a SQL error when the reported_by field is null for a record. Assume the DB Table classes are set up exactly as they are in the manual.

<pre class="highlight">
$bugsTable = new Bugs();
$bugsRowset = $bugsTable->fetchAll(array('bug_status = ?' => 'NEW'));
$bug1 = $bugsRowset->current();

$reporter = $bug1->findParentRow('Accounts', 'Reporter');

When the reported_by field is null, the generated Statement does not get any values bound to it which results in a where statement similar to "where account_name = ?" with no parameters to bind to the question mark. With a MySQLi adapter the error says: Zend_Db_Statement_Mysqli_Exception: Mysqli statement execute error : No data supplied for parameters in prepared statement in ... library/Zend/Db/Statement/Mysqli.php on line 215

Expected Behavior: I would expect any of the following options: * generate an exception about having a null value in the foreign key column. * gracefully fail similar to the result returned from something like $bugsTable->find('bogus'). * correctly bind a null value and execute the query and hope for the best.


Posted by Claude Duvergier (cduv) on 2008-10-23T09:01:37.000+0000

I did run into the same exception. With a pdo_mysql adapter, the message is: {quote} exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[HY093]: Invalid parameter number: no parameters were bound' in [...]library\Zend\Db\Statement\Pdo.php:238 {quote}

I disagree with Grady Kuhnline about generating an exception to warn about a null value in the foreign key column: why would it be an error?

What I would expect is Zend_Db_Table_Row_Abstract::findParentRow() to return null (no parent found). So an Exception could be thrown by Zend_Db_Statement_Pdo and caught by Zend_Db_Table_Row_Abstract::findParentRow() for it to be aware there is no parent on that Row.

Posted by old of Satoru Yoshida ( on 2009-06-06T04:53:42.000+0000

It seems to duplicate ZF-3347

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.