Re: common::getXxx update

From: Date: Tue, 24 Apr 2001 07:47:21 +0000
Subject: Re: common::getXxx update
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-301@lists.php.net to get a copy of this message
Hi Tomas, Looks good. Did you run "make test TESTS=DB/tests" with it? If you need help setting up your test environment, let me know (DB/tests/{pgsql,mysql}/README describe what you need to do.) If all tests pass, feel free to commit. - Stig ["Tomas V.V.Cox" <cox@idecnet.com>] > Hi, > > I've made some work to get* methods, basically to use the DB_result > interface. With this, we not longer need fetchRow on extensions. I'll > commit if noone have any inconvenient. > > Tomas V.V.Cox--- common.php.orig Tue Apr 24 01:51:06 2001 > +++ common.php Tue Apr 24 02:32:31 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)) { > @@ -534,16 +534,13 @@ > $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); > > -- > PEAR Development Mailing List (http://pear.php.net/) > To unsubscribe, e-mail: pear-dev-unsubscribe@lists.php.net > For additional commands, e-mail: pear-dev-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net -- Stig Sæther Bakken <ssb@fast.no> Fast Search & Transfer ASA, Trondheim, Norway

« previous php.pear.dev (#301) next »