cvs: php4 /pear PEAR.php.in /pear/DB common.php storage.php /pear/tests DB_Error.phpt

From: Date: Thu, 07 Sep 2000 16:36:23 +0000
Subject: cvs: php4 /pear PEAR.php.in /pear/DB common.php storage.php /pear/tests DB_Error.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-1621@lists.php.net to get a copy of this message
andrei Thu Sep 7 09:36:23 2000 EDT Modified files: /php4/pear PEAR.php.in /php4/pear/DB common.php storage.php /php4/pear/tests DB_Error.phpt Log: - Converted __string_value() to toString(), since the former is obsolete. - Made sure DB results are freed where necessary. - Made DB::getAssoc() use $params if passed. - Implemented DB::getAll(). Index: php4/pear/PEAR.php.in diff -u php4/pear/PEAR.php.in:1.4 php4/pear/PEAR.php.in:1.5 --- php4/pear/PEAR.php.in:1.4 Mon Aug 28 16:09:36 2000 +++ php4/pear/PEAR.php.in Thu Sep 7 09:36:22 2000 @@ -17,7 +17,7 @@ // | Stig Bakken <ssb@fast.no> | // +----------------------------------------------------------------------+ // -// $Id: PEAR.php.in,v 1.4 2000/08/28 23:09:36 ssb Exp $ +// $Id: PEAR.php.in,v 1.5 2000/09/07 16:36:22 andrei Exp $ // define('PEAR_ERROR_RETURN', 0); @@ -233,14 +233,14 @@ } // }}} - // {{{ __string_value() + // {{{ toString() /** * Make a string representation of this object. * * @return string a string with an object "summary" */ - function __string_value() { + function toString() { $modes = array(PEAR_ERROR_RETURN => "return", PEAR_ERROR_PRINT => "print", PEAR_ERROR_TRIGGER => "trigger", Index: php4/pear/DB/common.php diff -u php4/pear/DB/common.php:1.16 php4/pear/DB/common.php:1.17 --- php4/pear/DB/common.php:1.16 Mon Aug 28 16:09:36 2000 +++ php4/pear/DB/common.php Thu Sep 7 09:36:22 2000 @@ -24,10 +24,6 @@ // XXX legend: // // XXX ERRORMSG: Needs a better way of dealing with errors. -// XXX ADDREF: As soon as Zend/PHP gets support for returning -// references, this return value should be made into -// a reference. -// if (!empty($GLOBALS['USED_PACKAGES']['DB/common'])) return; $GLOBALS['USED_PACKAGES']['DB/common'] = true; @@ -47,9 +43,9 @@ var $prepare_maxstmt; // }}} - // {{{ __string_value() + // {{{ toString() - function __string_value() { + function toString() { $info = get_class($this); $info .= ": (phptype=" . $this->phptype . @@ -305,6 +301,9 @@ return $row; } $this->freeResult($res); + if (isset($sth)) { + $this->freeResult($sth); + } return $row; } @@ -346,6 +345,9 @@ $ret[] = $row[$col]; } $this->freeResult($res); + if (isset($sth)) { + $this->freeResult($sth); + } return $ret; } @@ -397,7 +399,15 @@ * values for results regardless of the database's internal type. */ function &getAssoc($query, $force_array = false, $params = array()) { - $res = $this->simpleQuery($query); + if (sizeof($params) > 0) { + $sth = $this->prepare($query); + if (DB::isError($sth)) { + return $sth; + } + $res = $this->execute($sth, $params); + } else { + $res = $this->simpleQuery($query); + } if (DB::isError($res)) { return $res; } @@ -421,14 +431,50 @@ $results[$row[0]] = $row[1]; } } - return $results; // XXX ADDREF + $this->freeResult($res); + if (isset($sth)) { + $this->freeResult($sth); + } + return $results; } // }}} // {{{ getAll() + /** + * Fetch all the rows returned from a query. The resulting array is indexed + * either by column names from the query or numerically with the numbers + * corresponding to the order of columns from the query. Each key contains + * an array of all the rows for that column. + * + * @param $query the SQL query + * + * @return array an indexed array, or a DB error + */ function &getAll($query, $getmode = DB_GETMODE_DEFAULT, $params = array()) { - + if (sizeof($params) > 0) { + $sth = $this->prepare($query); + if (DB::isError($sth)) { + return $sth; + } + $res = $this->execute($sth, $params); + } else { + $res = $this->simpleQuery($query); + } + if (DB::isError($res)) { + return $res; + } + $results = array(); + while (($row = $this->fetchRow($res, $getmode)) && !DB::isError($row)) { + foreach ($row as $key => $val) { + $results[$key][] = $val; + } + } + $this->freeResult($res); + if (isset($sth)) { + $this->freeResult($sth); + } + return $results; } // }}} Index: php4/pear/DB/storage.php diff -u php4/pear/DB/storage.php:1.7 php4/pear/DB/storage.php:1.8 --- php4/pear/DB/storage.php:1.7 Mon Aug 28 16:09:36 2000 +++ php4/pear/DB/storage.php Thu Sep 7 09:36:22 2000 @@ -124,7 +124,7 @@ * Output a simple description of this DB_storage object. * @return string object description */ - function __string_value() { + function toString() { $info = get_class(&$this); $info .= " (table="; $info .= $this->_table; @@ -132,7 +132,7 @@ $info .= $this->_keycolumn; $info .= ", dbh="; if (is_object($this->_dbh)) { - $info .= $this->_dbh->__string_value(); + $info .= $this->_dbh->toString(); } else { $info .= "null"; } Index: php4/pear/tests/DB_Error.phpt diff -u php4/pear/tests/DB_Error.phpt:1.2 php4/pear/tests/DB_Error.phpt:1.3 --- php4/pear/tests/DB_Error.phpt:1.2 Tue Aug 29 02:10:44 2000 +++ php4/pear/tests/DB_Error.phpt Thu Sep 7 09:36:22 2000 @@ -29,20 +29,20 @@ print "testing different error codes...\n"; -$e = new DB_Error(); print $e->__string_value()."\n"; -$e = new DB_Error("test error"); print $e->__string_value()."\n"; -$e = new DB_Error(DB_OK); print $e->__string_value()."\n"; -$e = new DB_Error(DB_ERROR); print $e->__string_value()."\n"; -$e = new DB_Error(DB_ERROR_SYNTAX); print $e->__string_value()."\n"; -$e = new DB_Error(DB_ERROR_DIVZERO); print $e->__string_value()."\n"; -$e = new DB_Warning(); print $e->__string_value()."\n"; -$e = new DB_Warning("test warning"); print $e->__string_value()."\n"; -$e = new DB_Warning(DB_WARNING_READ_ONLY); print $e->__string_value()."\n"; +$e = new DB_Error(); print $e->toString()."\n"; +$e = new DB_Error("test error"); print $e->toString()."\n"; +$e = new DB_Error(DB_OK); print $e->toString()."\n"; +$e = new DB_Error(DB_ERROR); print $e->toString()."\n"; +$e = new DB_Error(DB_ERROR_SYNTAX); print $e->toString()."\n"; +$e = new DB_Error(DB_ERROR_DIVZERO); print $e->toString()."\n"; +$e = new DB_Warning(); print $e->toString()."\n"; +$e = new DB_Warning("test warning"); print $e->toString()."\n"; +$e = new DB_Warning(DB_WARNING_READ_ONLY); print $e->toString()."\n"; ini_alter("html_errors", false); print "testing different error modes...\n"; -$e = new DB_Error(DB_ERROR, PEAR_ERROR_PRINT); print $e->__string_value()."\n"; +$e = new DB_Error(DB_ERROR, PEAR_ERROR_PRINT); print $e->toString()."\n"; $e = new DB_Error(DB_ERROR_SYNTAX, PEAR_ERROR_TRIGGER); print "testing different error serverities...\n";

« previous php.cvs (#1621) next »