Re: cvs: pear /DB package.xml /DB/DB common.php
| From: | Lorenzo Alberton | Date: | Fri, 30 Apr 2004 22:56:12 +0000 |
| Subject: | Re: cvs: pear /DB package.xml /DB/DB common.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-19048@lists.php.net to get a copy of this message | ||
http://cvs.php.net/diff.php/pear/DB/DB/common.php?r1=1.100&r2=1.101&ty=h&num=10
> danielc Wed Apr 28 15:58:29 2004 EDT
>
> Modified files:
> /pear/DB package.xml
> /pear/DB/DB common.php
> Log:
> Fix notice caused by passing invalid $col to getCol().
>
> //
> -// $Id: common.php,v 1.100 2004/04/28 18:38:07 danielc Exp $
> +// $Id: common.php,v 1.101 2004/04/28 19:58:29 danielc Exp $
>
> require_once 'PEAR.php';
>
> @@ -27,7 +27,7 @@
> * inherited by all such
> *
> $fetchmode = is_int($col) ? DB_FETCHMODE_ORDERED :
> DB_FETCHMODE_ASSOC;
> - $ret = array();
>
> - while (is_array($row = $res->fetchRow($fetchmode))) {
> - $ret[] = $row[$col];
> + if (!is_array($row = $res->fetchRow($fetchmode)) ||
> + !array_key_exists($col, $row))
> + {
> + $ret =& $this->raiseError(DB_ERROR_TRUNCATED);
> + } else {
> + $ret = array($row[$col]);
> + while (is_array($row = $res->fetchRow($fetchmode))) {
> + $ret[] = $row[$col];
> + }
> }
>
> $res->free();
This one made me lose > 1 hour debugging...
I was running the DB_QueryTool testsuite after applying some changes,
and one test was mysteriously failing. After banging my head against
every single line of code, and finding nothing wrong, then I had
the "eureka" moment, and tried using a previous DB release...
everything was fine again.
Why the above patch is wrong? Because when you (successfully)
execute a query returning no results, then you'd expect to
have an empty array back, not a false value (that indicates that
something went wrong).
"query ok but empty result" != DB_ERROR_TRUNCATED !!!
Please fix it, this is a BC break!
Thanks
--
Lorenzo Alberton
http://pear.php.net/user/quipo