cvs: php4 /pear/Cache DB.php
| From: | Sebastian Bergmann | Date: | Tue, 14 Aug 2001 21:16:12 +0000 |
| Subject: | cvs: php4 /pear/Cache DB.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-519@lists.php.net to get a copy of this message | ||
sebastian Tue Aug 14 17:16:12 2001 EDT
Modified files:
/php4/pear/Cache DB.php
Log:
Implement setFetchMode() and DB_FETCHMODE_OBJECT mechanism.
Index: php4/pear/Cache/DB.php
diff -u php4/pear/Cache/DB.php:1.5 php4/pear/Cache/DB.php:1.6
--- php4/pear/Cache/DB.php:1.5 Tue Aug 14 16:44:34 2001
+++ php4/pear/Cache/DB.php Tue Aug 14 17:16:12 2001
@@ -15,7 +15,7 @@
// | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de> |
// +----------------------------------------------------------------------+
//
-// $Id: DB.php,v 1.5 2001/08/14 20:44:34 sebastian Exp $
+// $Id: DB.php,v 1.6 2001/08/14 21:16:12 sebastian Exp $
require_once 'Cache.php';
require_once 'DB.php';
@@ -27,7 +27,7 @@
* @module Cache_DB
* @modulegroup Cache_DB
* @package Cache
-* @version $Revision: 1.5 $
+* @version $Revision: 1.6 $
* @access public
*/
class Cache_DB extends Cache {
@@ -60,6 +60,20 @@
var $options = false;
/**
+ * Fetchmode
+ *
+ * @var integer
+ */
+ var $fetchmode = DB_FETCHMODE_ASSOC;
+
+ /**
+ * Fetchmode Object Class
+ *
+ * @var string
+ */
+ var $fetchmode_object_class = 'DB_row';
+
+ /**
* Constructor
*
* @param string Name of container class
@@ -117,6 +131,34 @@
}
/**
+ * Sets which fetch mode should be used by default on queries
+ * on this connection.
+ *
+ * @param integer DB_FETCHMODE_ORDERED or
+ * DB_FETCHMODE_ASSOC, possibly bit-wise OR'ed
+ * with DB_FETCHMODE_FLIPPED.
+ *
+ * @param string The class of the object to be returned by the
+ * fetch methods when the DB_FETCHMODE_OBJECT
+ * mode is selected.
+ */
+ function setFetchMode($fetchmode, $object_class = null) {
+ switch ($fetchmode) {
+ case DB_FETCHMODE_OBJECT: {
+ if ($object_class) {
+ $this->fetchmode_object_class = $object_class;
+ }
+ }
+
+ case DB_FETCHMODE_ORDERED:
+ case DB_FETCHMODE_ASSOC: {
+ $this->fetchmode = $fetchmode;
+ }
+ break;
+ }
+ }
+
+ /**
* Perform an SQL query
*
* @param string SQL Query String
@@ -151,7 +193,7 @@
$rows[] = $row;
}
- $result = new Cache_DB_Result($rows);
+ $result = new Cache_DB_Result($rows, $this->fetchmode,
$this->fetchmode_object_class);
$this->save($cache_id, $result, $this->expires, 'db_cache');
} else {
@@ -185,18 +227,11 @@
* @module Cache_DB
* @modulegroup Cache_DB
* @package Cache
-* @version $Revision: 1.5 $
+* @version $Revision: 1.6 $
* @access public
*/
class Cache_DB_Result {
/**
- * Rows of the result set
- *
- * @var array
- */
- var $rows = array();
-
- /**
* Names of the result set's columns
*
* @var array
@@ -211,6 +246,20 @@
var $cursor = 0;
/**
+ * Fetchmode
+ *
+ * @var integer
+ */
+ var $fetchmode = DB_FETCHMODE_ASSOC;
+
+ /**
+ * Fetchmode Object Class
+ *
+ * @var string
+ */
+ var $fetchmode_object_class = 'DB_row';
+
+ /**
* Number of columns in the result set
*
* @var integer
@@ -225,17 +274,26 @@
var $num_rows = 0;
/**
+ * Rows of the result set
+ *
+ * @var array
+ */
+ var $rows = array();
+
+ /**
* Constructor
*
* @param array Rows
*/
- function Cache_DB_Result(&$rows) {
- $this->rows = $rows;
- $this->column_names = array_keys($this->rows[0]);
- $this->cursor = 0;
-
- $this->num_columns = sizeof($this->column_names);
- $this->num_rows = sizeof($this->rows);
+ function Cache_DB_Result(&$rows, $fetchmode, $fetchmode_object_class) {
+ $this->rows = $rows;
+ $this->fetchmode = $fetchmode;
+ $this->fetchmode_object_class = $fetchmode_object_class;
+
+ $this->column_names = array_keys($this->rows[0]);
+ $this->cursor = 0;
+ $this->num_columns = sizeof($this->column_names);
+ $this->num_rows = sizeof($this->rows);
}
/**
@@ -245,11 +303,15 @@
* @return array a row of data, NULL on no more rows or PEAR_Error on error
*/
function fetchRow($fetchmode = DB_FETCHMODE_DEFAULT, $rownum = null) {
-/* if ($fetchmode === DB_FETCHMODE_OBJECT) {
+ if ($fetchmode === DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->fetchmode;
+ }
+
+ if ($fetchmode === DB_FETCHMODE_OBJECT) {
$fetchmode = DB_FETCHMODE_ASSOC;
$return_object = true;
}
-*/
+
if ($rownum === null) {
$rownum = $this->cursor++;
}
@@ -280,14 +342,14 @@
}
}
-/* if (isset($return_object)) {
- $class = $this->db->fetchmode_object_class;
+ if (isset($return_object)) {
+ $class = $this->fetchmode_object_class;
$object =& new $class($row);
return $object;
} else {
-*/ return $row;
-// }
+ return $row;
+ }
}
/**