Re: cvs: pear /HTML_QuickForm/Elements select.php
| From: | Tomas V.V.Cox | Date: | Mon, 21 Jan 2002 15:39:35 +0000 |
| Subject: | Re: cvs: pear /HTML_QuickForm/Elements select.php | ||
| References: | 1 | Groups: | php.pear.cvs |
| Request: | Send a blank email to pear-cvs+get-2042@lists.php.net to get a copy of this message | ||
El lun, 21-01-2002 a las 13:42, Bertrand Mansion escribió:
> mansion Mon Jan 21 07:42:15 2002 EDT
>
> Modified files:
> /pear/HTML_QuickForm/Elements select.php
> Log:
> Modification suggested by Brian Abent :
> In loadDbResult(), method now checks if fetchRow() returns a Pear error or an array. If
> neither, it returns a new Pear error.
>
> Index: pear/HTML_QuickForm/Elements/select.php
> diff -u pear/HTML_QuickForm/Elements/select.php:1.3 pear/HTML_QuickForm/Elements/select.php:1.4
> --- pear/HTML_QuickForm/Elements/select.php:1.3 Tue Dec 11 14:45:47 2001
> +++ pear/HTML_QuickForm/Elements/select.php Mon Jan 21 07:42:14 2002
> @@ -17,7 +17,7 @@
> // | Bertrand Mansion <bmansion@mamasam.com> |
> // +----------------------------------------------------------------------+
> //
> -// $Id: select.php,v 1.3 2001/12/11 19:45:47 sebastian Exp $
> +// $Id: select.php,v 1.4 2002/01/21 12:42:14 mansion Exp $
>
> require_once("HTML/QuickForm/Elements/element.php");
>
> @@ -271,11 +271,17 @@
> $this->setValue($values);
> }
> $fetchMode = ($textCol && $valueCol) ? DB_FETCHMODE_ASSOC :
> DB_FETCHMODE_DEFAULT;
> - while (is_array($row = $result->fetchRow($fetchMode)) ) {
> - if ($fetchMode == DB_FETCHMODE_ASSOC) {
> - $this->addOption($row[$textCol], $row[$valueCol]);
> + while ($row = $result->fetchRow($fetchMode)) {
> + if (PEAR::isError($row)) {
> + return $row;
> + } elseif (is_array($row)) {
> + if ($fetchMode == DB_FETCHMODE_ASSOC) {
> + $this->addOption($row[$textCol], $row[$valueCol]);
> + } else {
> + $this->addOption($row[0], $row[1]);
> + }
> } else {
> - $this->addOption($row[0], $row[1]);
> + return new PEAR_ERROR('Invalid return value from
> DB_result->fetchRow');
> }
> }
> return true;
>
The way for efficiently do that is:
$this->dbh->pushErrorHandling(PEAR_ERROR_RETURN);
while (DB_OK === ($row = $result->fetchRow($fetchmode)) {
...
}
$this->dbh->popErrorHandling();
if (PEAR::isError($row)) {
return $row;
}
...
Tomas V.V.Cox