cvs: pear /DB DB.php

From: Date: Sat, 07 Jun 2003 18:33:04 +0000
Subject: cvs: pear /DB DB.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-10755@lists.php.net to get a copy of this message
cox Sat Jun 7 14:33:04 2003 EDT Modified files: /pear/DB DB.php Log: Added function DB_Result->setOption(), an interface to some private vars fix 'autofree' when no native limitQuery support is avaible Index: pear/DB/DB.php diff -u pear/DB/DB.php:1.20 pear/DB/DB.php:1.21 --- pear/DB/DB.php:1.20 Wed May 7 12:54:45 2003 +++ pear/DB/DB.php Sat Jun 7 14:33:04 2003 @@ -17,7 +17,7 @@ // | Tomas V.V.Cox <cox@idecnet.com> | // +----------------------------------------------------------------------+ // -// $Id: DB.php,v 1.20 2003/05/07 16:54:45 mj Exp $ +// $Id: DB.php,v 1.21 2003/06/07 18:33:04 cox Exp $ // // Database independent query interface. // @@ -682,20 +682,32 @@ /** * DB_result constructor. * @param resource &$dbh DB object reference - * @param resource $result result resource id + * @param resource $result result resource id + * @param array $options assoc array with optional result options */ function DB_result(&$dbh, $result, $options = array()) - { + { $this->dbh = &$dbh; - $this->result = $result; - $this->limit_from = isset($options['limit_from']) ? $options['limit_from'] : null; - $this->limit_count = isset($options['limit_count']) ? $options['limit_count'] : null; + $this->result = $result; + foreach ($options as $key => $value) { + $this->setOption($key, $value); + } $this->limit_type = $dbh->features['limit']; $this->autofree = $dbh->options['autofree']; $this->fetchmode = $dbh->fetchmode; $this->fetchmode_object_class = $dbh->fetchmode_object_class; } + + function setOption($key, $value = null) + { + switch ($key) { + case 'limit_from': + $this->limit_from = $value; break; + case 'limit_count'; + $this->limit_count = $value; break; + } + } // }}} // {{{ fetchRow() @@ -716,7 +728,7 @@ if ($fetchmode === DB_FETCHMODE_OBJECT) { $fetchmode = DB_FETCHMODE_ASSOC; $object_class = $this->fetchmode_object_class; - } + } if ($this->limit_from !== null) { if ($this->row_counter === null) { $this->row_counter = $this->limit_from; @@ -730,15 +742,17 @@ } if ($this->row_counter >= ( $this->limit_from + $this->limit_count)) - { + { + if ($this->autofree) { + $this->free(); + } return null; } if ($this->limit_type == 'emulate') { $rownum = $this->row_counter; } - $this->row_counter++; - } + } $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum); if ($res !== DB_OK) { if ($res == null && $this->autofree) { @@ -802,7 +816,7 @@ } $this->row_counter++; - } + } $res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum); if (($res === DB_OK) && isset($object_class)) { // default mode specified in DB_common::fetchmode_object_class property

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