Index: common.php =================================================================== RCS file: /repository/pear/MDB/common.php,v retrieving revision 1.16 diff -u -r1.16 common.php --- common.php 12 Jun 2002 13:17:04 -0000 1.16 +++ common.php 19 Jun 2002 14:34:46 -0000 @@ -2118,6 +2118,9 @@ function baseFetchInto($result, &$array, $row) { + if ($row + 1 > $this->numRows($result)) { + return $this->raiseError(DB_ERROR, '', '', 'baseFetchInto: Tried to access beyond end of record set'); + } $columns = $this->numCols($result); if (MDB::isError($columns)) { return $columns; @@ -2177,18 +2180,18 @@ * used to be fetchResultField * * @param $result result identifier - * @param $row (reference) array where data from the row is stored + * @param $value (reference) array where data from the row is stored * @param $fetchmode format of fetched row array * * @return mixed DB_OK on success, a DB error on failure */ function fetchField($result, &$value, $fetchmode = DB_FETCHMODE_DEFAULT) { - if (!$result) { + if (MDB::isError($result)) { return $this->raiseError(DB_ERROR_NEED_MORE_DATA, "", "", 'Fetch field: it was not specified a valid result set'); } - if ($this->endOfResult($result)) { + if (MDB::isError($this->endOfResult($result))) { $res = $this->raiseError(DB_ERROR_NEED_MORE_DATA, "", "", 'Fetch field: result set is empty'); } else { @@ -2223,11 +2226,11 @@ */ function fetchRow($result, &$row, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum = NULL) { - if (!$result) { + if (MDB::isError($result)) { return $this->raiseError(DB_ERROR_NEED_MORE_DATA, "", "", 'Fetch row: it was not specified a valid result set'); } - if ($this->endOfResult($result)) { + if (MDB::isError($this->endOfResult($result))) { $this->freeResult($result); return $this->raiseError(DB_ERROR_NEED_MORE_DATA, "", "", 'Fetch row: result set is empty'); @@ -2257,13 +2260,15 @@ */ function fetchCol($result, &$column, $fetchmode = DB_FETCHMODE_DEFAULT, $colnum = '0') { - if (!$result) { + if (MDB::isError($result)) { return $this->raiseError(DB_ERROR_NEED_MORE_DATA, "", "", 'Fetch column: it was not specified a valid result set'); } $temp = $column = array(); - while(DB_OK === $res = $this->fetchInto($result, $temp, $fetchmode, NULL)) { + $row = 0; + while(DB_OK === $res = $this->fetchInto($result, $temp, $fetchmode, $row)) { $column[] = $temp[$colnum]; + $row++; } if(!$this->autofree) { $this->freeResult($result); @@ -2301,7 +2306,7 @@ */ function fetchAll($result, &$all, $fetchmode = DB_FETCHMODE_DEFAULT, $rekey = FALSE, $force_array = FALSE, $group = FALSE) { - if (!$result) { + if (MDB::isError($result)) { return $this->raiseError(DB_ERROR_NEED_MORE_DATA, "", "", 'Fetch All: it was not specified a valid result set'); } @@ -2315,7 +2320,7 @@ } $row = 0; $all = array(); - while (DB_OK === $res = $this->fetchInto($result, $array, $fetchmode, NULL)) { + while (DB_OK === $res = $this->fetchInto($result, $array, $fetchmode, $row)) { if ($rekey) { if ($fetchmode == DB_FETCHMODE_ASSOC) { reset($array); @@ -2754,7 +2759,7 @@ } $err = $this->fetchField($result, $value, DB_FETCHMODE_ORDERED); - if ($err !== DB_OK) { + if (MDB::isError($err)) { return $err; } @@ -2801,6 +2806,7 @@ if (MDB::isError($result)) { return $result; } + $err = $this->fetchRow($result, $row, $fetchmode); if ($err !== DB_OK) { @@ -2857,7 +2863,7 @@ $err = $this->fetchCol($result, $col, $fetchmode, $col_num); - if ($err !== DB_OK) { + if (MDB::isError($err)) { return $err; } if (isset($prepared_query)) {