cvs: php4 /pear/DB common.php

From: Date: Tue, 24 Apr 2001 11:47:01 +0000
Subject: cvs: php4 /pear/DB common.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-86@lists.php.net to get a copy of this message
cox Tue Apr 24 04:47:01 2001 EDT Modified files: /php4/pear/DB common.php Log: -updated getXxx methods to use the DB_result interface, also some improvements in error checking and updated inline doc. From this moment fetchRow on DB_extentions is no longer needed. Index: php4/pear/DB/common.php diff -u php4/pear/DB/common.php:1.47 php4/pear/DB/common.php:1.48 --- php4/pear/DB/common.php:1.47 Fri Apr 20 08:12:14 2001 +++ php4/pear/DB/common.php Tue Apr 24 04:47:01 2001 @@ -431,7 +431,7 @@ } $err = $res->fetchInto($row, DB_FETCHMODE_ORDERED); - if ($err === null || DB::isError($err)) { + if ($err !== DB_OK) { return $err; } @@ -452,6 +452,9 @@ * of doing the query and freeing the results when finished. * * @param $query the SQL query + * @param $fetchmode the fetch mode to use + * @param $params array if supplied, prepare/execute will be used + * with this array as execute parameters * @access public * @return array the first row of results as an array indexed from * 0, or a DB error code. @@ -460,13 +463,9 @@ function &getRow($query, $fetchmode = DB_FETCHMODE_DEFAULT, $params = array()) { - if ($fetchmode === DB_FETCHMODE_DEFAULT) { - $fetchmode = $this->fetchmode; - } - settype($params, "array"); if (sizeof($params) > 0) { - $sth = $this->prepare( $query ); + $sth = $this->prepare($query); if (DB::isError($sth)) { return $sth; } @@ -481,10 +480,9 @@ $err = $res->fetchInto($row, $fetchmode); - if ($err === null || DB::isError($err)) { + if ($err !== DB_OK) { return $err; } - $res->free(); if (isset($sth)) { @@ -506,6 +504,8 @@ * @param $col which column to return (integer [column number, * starting at 0] or string [column name]) * + * @param $params array if supplied, prepare/execute will be used + * with this array as execute parameters * @access public * * @return array an indexed array with the data from the first @@ -524,7 +524,7 @@ $res = $this->execute($sth, $params); } else { - $res = $this->simpleQuery($query); + $res = $this->query($query); } if (DB::isError($res)) { @@ -533,17 +533,14 @@ $fetchmode = is_int($col) ? DB_FETCHMODE_ORDERED : DB_FETCHMODE_ASSOC; $ret = array(); - - while ($row = $this->fetchRow($res, $fetchmode)) { - if (DB::isError($row)) { - $ret = $row; - break; - } + while (is_array($row = $res->fetchRow($fetchmode))) { $ret[] = $row[$col]; } - - $this->freeResult($res); + if (DB::isError($row)) { + $ret = $row; + } + $res->free(); if (isset($sth)) { $this->freeResult($sth); @@ -614,14 +611,14 @@ $res = $this->execute($sth, $params); } else { - $res = $this->simpleQuery($query); + $res = $this->query($query); } if (DB::isError($res)) { return $res; } - $cols = $this->numCols($res); + $cols = $res->numCols(); if ($cols < 2) { return $this->raiseError(DB_ERROR_TRUNCATED); @@ -632,22 +629,26 @@ if ($cols > 2 || $force_array) { // return array values // XXX this part can be optimized - while (($row = $this->fetchRow($res, DB_FETCHMODE_ORDERED)) && - !DB::isError($row)) { + while (is_array($row = $res->fetchRow(DB_FETCHMODE_ORDERED))) { reset($row); // we copy the row of data into a new array // to get indices running from 0 again $results[$row[0]] = array_slice($row, 1); } + if (DB::isError($row)) { + $results = $row; + } } else { // return scalar values - while (($row = $this->fetchRow($res, DB_FETCHMODE_ORDERED)) && - !DB::isError($row)) { + while (is_array($row = $res->fetchRow(DB_FETCHMODE_ORDERED))) { $results[$row[0]] = $row[1]; } + if (DB::isError($row)) { + $results = $row; + } } - $this->freeResult($res); + $res->free(); if (isset($sth)) { $this->freeResult($sth); @@ -670,10 +671,6 @@ function &getAll($query, $fetchmode = DB_FETCHMODE_DEFAULT, $params = array()) { - if ($fetchmode == DB_FETCHMODE_DEFAULT) { - $fetchmode = $this->fetchmode; - } - settype($params, "array"); if (sizeof($params) > 0) { $sth = $this->prepare($query); @@ -684,7 +681,7 @@ $res = $this->execute($sth, $params); } else { - $res = $this->simpleQuery($query); + $res = $this->query($query); } if (DB::isError($res)) { @@ -693,8 +690,7 @@ $results = array(); - while (($row = $this->fetchRow($res, $fetchmode)) && - !DB::isError($row)) { + while (is_array($row = $res->fetchRow($fetchmode))) { if ($fetchmode & DB_FETCHMODE_FLIPPED) { foreach ($row as $key => $val) { $results[$key][] = $val; @@ -703,8 +699,10 @@ $results[] = $row; } } - - $this->freeResult($res); + if (DB::isError($row)) { + $results = $row; + } + $res->free(); if (isset($sth)) { $this->freeResult($sth);

« previous php.pear.cvs (#86) next »