cvs: pear /MDB2 MDB2.php
| From: | Lukas Smith | Date: | Sun, 20 Feb 2005 17:44:53 +0000 |
| Subject: | cvs: pear /MDB2 MDB2.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-29544@lists.php.net to get a copy of this message | ||
lsmith Sun Feb 20 12:44:53 2005 EDT
Modified files:
/pear/MDB2 MDB2.php
Log:
- applied performance tweaks to fetchAll()
http://cvs.php.net/diff.php/pear/MDB2/MDB2.php?r1=1.78&r2=1.79&ty=u
Index: pear/MDB2/MDB2.php
diff -u pear/MDB2/MDB2.php:1.78 pear/MDB2/MDB2.php:1.79
--- pear/MDB2/MDB2.php:1.78 Wed Jan 12 15:05:28 2005
+++ pear/MDB2/MDB2.php Sun Feb 20 12:44:53 2005
@@ -43,7 +43,7 @@
// | Author: Lukas Smith <smith@backendmedia.com> |
// +----------------------------------------------------------------------+
//
-// $Id: MDB2.php,v 1.78 2005/01/12 20:05:28 lsmith Exp $
+// $Id: MDB2.php,v 1.79 2005/02/20 17:44:53 lsmith Exp $
//
/**
@@ -2559,27 +2559,40 @@
function fetchAll($fetchmode = MDB2_FETCHMODE_DEFAULT, $rekey = false,
$force_array = false, $group = false)
{
- $all = array();
- while (!MDB2::isError($row = $this->fetchRow($fetchmode)) && $row) {
- if ($rekey) {
- if ((is_array($row) && count($row) < 2)
- || (is_object($row) && count(get_object_vars($row)) < 2)
- ) {
- return $this->db->raiseError(MDB2_ERROR_TRUNCATED);
- }
+ $row = $this->fetchRow($fetchmode);
+ if (MDB2::isError($row) || !$row) {
+ return $row;
+ }
+
+ $shift_array = $rekey ? false : null;
+ if (is_null($shift_array)) {
+ if(is_object($row)) {
+ $colnum = count(get_object_vars($row));
+ } else {
+ $colnum = count($row);
}
- if ($rekey) {
- if ($fetchmode == MDB2_FETCHMODE_ASSOC) {
- $key = reset($row);
- unset($row[key($row)]);
- } elseif ($fetchmode === MDB2_FETCHMODE_OBJECT) {
+
+ if ($colnum < 2) {
+ return $this->db->raiseError(MDB2_ERROR_TRUNCATED);
+ }
+ $shift_array = (!$force_array && $colnum == 2);
+ }
+
+ $all = array();
+ if ($rekey) {
+ do {
+ if (is_object($row)) {
$arr = get_object_vars($row);
$key = reset($arr);
+ unset($row->{$key});
} else {
- $key = array_shift($row);
- }
- if (!$force_array) {
- if (is_array($row) && count($row) == 1) {
+ if ($fetchmode & MDB2_FETCHMODE_ASSOC) {
+ $key = reset($row);
+ unset($row[key($row)]);
+ } else {
+ $key = array_shift($row);
+ }
+ if ($shift_array) {
$row = array_shift($row);
}
}
@@ -2588,20 +2601,19 @@
} else {
$all[$key] = $row;
}
- } else {
- if ($fetchmode & MDB2_FETCHMODE_FLIPPED) {
- foreach ($row as $key => $val) {
- $all[$key][] = $val;
- }
- } else {
- $all[] = $row;
+ } while (($row = $this->fetchRow($fetchmode)));
+ } elseif ($fetchmode & MDB2_FETCHMODE_FLIPPED) {
+ do {
+ foreach ($row as $key => $val) {
+ $all[$key][] = $val;
}
- }
+ } while (($row = $this->fetchRow($fetchmode)));
+ } else {
+ do {
+ $all[] = $row;
+ } while (($row = $this->fetchRow($fetchmode)));
}
- if (MDB2::isError($row)) {
- return $row;
- }
return $all;
}