cvs: pear /DB DB.php
| From: | Tomas V.V.Cox | Date: | Tue, 04 Jun 2002 14:11:39 +0000 |
| Subject: | cvs: pear /DB DB.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-4407@lists.php.net to get a copy of this message | ||
cox Tue Jun 4 10:11:39 2002 EDT
Modified files:
/pear/DB DB.php
Log:
Work on DB_Result:
- New "autofree" feature implemented:
$db = DB::connect($dsn, array('autofree' => true));
- Avoid proxying db_object vars from db_result in fetch methods
- Make the DB_Result constructor accept a new specific options
assoc array
Index: pear/DB/DB.php
diff -u pear/DB/DB.php:1.9 pear/DB/DB.php:1.10
--- pear/DB/DB.php:1.9 Sun May 26 12:14:14 2002
+++ pear/DB/DB.php Tue Jun 4 10:11:39 2002
@@ -17,7 +17,7 @@
// | Tomas V.V.Cox <cox@idecnet.com> |
// +----------------------------------------------------------------------+
//
-// $Id: DB.php,v 1.9 2002/05/26 16:14:14 cox Exp $
+// $Id: DB.php,v 1.10 2002/06/04 14:11:39 cox Exp $
//
// Database independent query interface.
//
@@ -633,10 +633,16 @@
* @param resource $result result resource id
*/
- function DB_result(&$dbh, $result)
+ 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->limit_type = $dbh->features['limit'];
+ $this->autofree = $dbh->options['autofree'];
+ $this->fetchmode = $dbh->fetchmode;
+ $this->fetchmode_object_class = $dbh->fetchmode_object_class;
}
/**
@@ -651,17 +657,17 @@
function fetchRow($fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null)
{
if ($fetchmode === DB_FETCHMODE_DEFAULT) {
- $fetchmode = $this->dbh->fetchmode;
+ $fetchmode = $this->fetchmode;
}
if ($fetchmode === DB_FETCHMODE_OBJECT) {
$fetchmode = DB_FETCHMODE_ASSOC;
- $object_class = $this->dbh->fetchmode_object_class;
+ $object_class = $this->fetchmode_object_class;
}
if ($this->limit_from !== null) {
if ($this->row_counter === null) {
$this->row_counter = $this->limit_from;
- // For Interbase
- if ($this->dbh->features['limit'] == false) {
+ // Skip rows
+ if ($this->limit_type == false) {
$i = 0;
while ($i++ < $this->limit_from) {
$this->dbh->fetchInto($this->result, $arr, $fetchmode);
@@ -673,7 +679,7 @@
{
return null;
}
- if ($this->dbh->features['limit'] == 'emulate') {
+ if ($this->limit_type == 'emulate') {
$rownum = $this->row_counter;
}
@@ -681,6 +687,9 @@
}
$res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
if ($res !== DB_OK) {
+ if ($res == null && $this->autofree) {
+ $this->free();
+ }
return $res;
}
if (isset($object_class)) {
@@ -710,17 +719,17 @@
function fetchInto(&$arr, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null)
{
if ($fetchmode === DB_FETCHMODE_DEFAULT) {
- $fetchmode = $this->dbh->fetchmode;
+ $fetchmode = $this->fetchmode;
}
if ($fetchmode === DB_FETCHMODE_OBJECT) {
$fetchmode = DB_FETCHMODE_ASSOC;
- $object_class = $this->dbh->fetchmode_object_class;
+ $object_class = $this->fetchmode_object_class;
}
if ($this->limit_from !== null) {
if ($this->row_counter === null) {
$this->row_counter = $this->limit_from;
- // For Interbase
- if ($this->dbh->features['limit'] == false) {
+ // Skip rows
+ if ($this->limit_type == false) {
$i = 0;
while ($i++ < $this->limit_from) {
$this->dbh->fetchInto($this->result, $arr, $fetchmode);
@@ -732,7 +741,7 @@
{
return null;
}
- if ($this->dbh->features['limit'] == 'emulate') {
+ if ($this->limit_type == 'emulate') {
$rownum = $this->row_counter;
}
@@ -746,6 +755,8 @@
} else {
$arr = new $object_class($arr);
}
+ } elseif ($res == null && $this->autofree) {
+ $this->free();
}
return $res;
}
@@ -811,7 +822,7 @@
}
/**
- * returns the actual rows number
+ * returns the actual row number
* @return integer
*/
function getRowCounter()