cvs: pear /MDB2/MDB2/Wrapper peardb.php
| From: | Lukas Smith | Date: | Fri, 30 Apr 2004 14:32:24 +0000 |
| Subject: | cvs: pear /MDB2/MDB2/Wrapper peardb.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-19022@lists.php.net to get a copy of this message | ||
lsmith Fri Apr 30 10:32:24 2004 EDT
Modified files:
/pear/MDB2/MDB2/Wrapper peardb.php
Log:
- fixed issues due to:
DB_PORTABILITY_NULL_TO_EMPTY
DB_FETCHMODE_OBJECT
BC hacks in getRow() and getAll()
http://cvs.php.net/diff.php/pear/MDB2/MDB2/Wrapper/peardb.php?r1=1.8&r2=1.9&ty=u
Index: pear/MDB2/MDB2/Wrapper/peardb.php
diff -u pear/MDB2/MDB2/Wrapper/peardb.php:1.8 pear/MDB2/MDB2/Wrapper/peardb.php:1.9
--- pear/MDB2/MDB2/Wrapper/peardb.php:1.8 Thu Apr 29 18:40:31 2004
+++ pear/MDB2/MDB2/Wrapper/peardb.php Fri Apr 30 10:32:24 2004
@@ -42,7 +42,7 @@
// | Author: Lukas Smith <smith@backendmedia.com> |
// +----------------------------------------------------------------------+
//
-// $Id: peardb.php,v 1.8 2004/04/29 22:40:31 lsmith Exp $
+// $Id: peardb.php,v 1.9 2004/04/30 14:32:24 lsmith Exp $
//
/**
@@ -128,7 +128,7 @@
define('DB_PORTABILITY_DELETE_COUNT', MDB2_PORTABILITY_DELETE_COUNT);
define('DB_PORTABILITY_NUMROWS', MDB2_PORTABILITY_NUMROWS);
define('DB_PORTABILITY_ERRORS', MDB2_PORTABILITY_ERRORS);
-define('DB_PORTABILITY_EMPTY_TO_NULL', MDB2_PORTABILITY_EMPTY_TO_NULL);
+define('DB_PORTABILITY_NULL_TO_EMPTY', MDB2_PORTABILITY_EMPTY_TO_NULL);
define('DB_PORTABILITY_ALL', MDB2_PORTABILITY_ALL);
/**
@@ -247,15 +247,33 @@
function &fetchrow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
{
- return $this->result->fetchRow($fetchmode);
+ $arr = $this->result->fetchRow($fetchmode);
+ if ($this->result->mdb->options['portability'] &
DB_PORTABILITY_NULL_TO_EMPTY) {
+ $this->_convertNullArrayValuesToEmpty($arr);
+ }
+ return $arr;
}
function fetchInto(&$arr, $fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
{
$arr = $this->fetchRow($fetchmode, $rownum);
+ if ($this->result->mdb->options['portability'] &
DB_PORTABILITY_NULL_TO_EMPTY) {
+ $this->_convertNullArrayValuesToEmpty($arr);
+ }
return DB_OK;
}
+ function _convertNullArrayValuesToEmpty(&$array)
+ {
+ if (is_array($array)) {
+ foreach ($array as $key => $value) {
+ if (is_null($value)) {
+ $array[$key] = '';
+ }
+ }
+ }
+ }
+
function numCols()
{
return $this->result->numCols();
@@ -308,6 +326,7 @@
var $MDB2_object;
var $phptype;
var $connection;
+ var $dsn;
function MDB2_PEARProxy(&$MDB2_object)
{
@@ -317,6 +336,7 @@
$this->MDB2_object->setOption('result_wrap_class', 'DB_result');
$this->phptype = $this->MDB2_object->phptype;
$this->connection = $this->MDB2_object->connection;
+ $this->dsn = $this->MDB2_object->getDSN();
}
function connect($dsninfo, $persistent = false)
@@ -400,7 +420,7 @@
return $this->MDB2_object->raiseError($code, $mode, $options, $userinfo,
$nativecode);
}
- function setFetchMode($fetchmode, $object_class = null)
+ function setFetchMode($fetchmode, $object_class = 'stdClass')
{
return $this->MDB2_object->setFetchMode($fetchmode, $object_class);
}
@@ -490,39 +510,123 @@
return $result;
}
+ function _convertNullArrayValuesToEmpty(&$array)
+ {
+ if (is_array($array)) {
+ foreach ($array as $key => $value) {
+ if (is_null($value)) {
+ $array[$key] = '';
+ }
+ }
+ }
+ }
+
function &getOne($query, $params = array())
{
$result = $this->query($query, $params);
- return $result->result->fetch();
+ $one = $result->result->fetch();
+ if (is_null($one)) {
+ $one = '';
+ }
+ return $one;
}
function &getRow($query,
$params = array(),
$fetchmode = MDB2_FETCHMODE_DEFAULT)
{
+ if (!is_array($params)) {
+ if (is_array($fetchmode)) {
+ if ($params === null) {
+ $tmp = DB_FETCHMODE_DEFAULT;
+ } else {
+ $tmp = $params;
+ }
+ $params = $fetchmode;
+ $fetchmode = $tmp;
+ } elseif ($params !== null) {
+ $fetchmode = $params;
+ $params = array();
+ }
+ }
$result = $this->query($query, $params);
- return $result->result->fetchRow($fetchmode);
+ $row = $result->result->fetchRow($fetchmode);
+ return $row;
}
function &getCol($query, $col = 0, $params = array())
{
$result = $this->query($query, $params);
- return $result->result->fetchCol($col);
+ $col = $result->result->fetchCol($col);
+ $this->_convertNullArrayValuesToEmpty($col);
+ return $col;
}
function &getAssoc($query, $force_array = false, $params = array(),
$fetchmode = MDB2_FETCHMODE_ORDERED, $group = false)
{
$result = $this->query($query, $params);
- return $result->result->fetchAll($fetchmode, true, $force_array, $group);
+ $all = $result->result->fetchAll($fetchmode, true, $force_array, $group);
+ $first = reset($all);
+ if (isset($first) && $this->MDB2_object->options['portability']
& DB_PORTABILITY_NULL_TO_EMPTY) {
+ if(is_array($first)) {
+ foreach($all as $key => $arr) {
+ $this->_convertNullArrayValuesToEmpty($all[$key]);
+ }
+ } elseif(is_object($first)) {
+ foreach($all as $key => $arr) {
+ $tmp = get_object_vars($all[$key]);
+ if(is_array($tmp)) {
+ $this->_convertNullArrayValuesToEmpty($tmp);
+ foreach($tmp as $key2 => $column) {
+ $all[$key]->{$key2} = $column;
+ }
+ }
+ }
+ }
+ }
+ return $all;
}
function &getAll($query,
$params = null,
$fetchmode = MDB2_FETCHMODE_DEFAULT)
{
+ if (!is_array($params)) {
+ if (is_array($fetchmode)) {
+ if ($params === null) {
+ $tmp = DB_FETCHMODE_DEFAULT;
+ } else {
+ $tmp = $params;
+ }
+ $params = $fetchmode;
+ $fetchmode = $tmp;
+ } elseif ($params !== null) {
+ $fetchmode = $params;
+ $params = array();
+ }
+ }
$result = $this->query($query, $params);
- return $result->result->fetchAll($fetchmode);
+ $all = $result->result->fetchAll($fetchmode);
+ $first = reset($all);
+ if (isset($first) && $this->MDB2_object->options['portability']
& DB_PORTABILITY_NULL_TO_EMPTY) {
+ if(is_array($first)) {
+ foreach($all as $key => $arr) {
+ $this->_convertNullArrayValuesToEmpty($all[$key]);
+ }
+ } elseif(is_object($first)) {
+ foreach($all as $key => $arr) {
+ $tmp = get_object_vars($all[$key]);
+ if(is_array($tmp)) {
+ $this->_convertNullArrayValuesToEmpty($tmp);
+ foreach($tmp as $key2 => $column) {
+ $all[$key]->{$key2} = $column;
+ }
+ }
+ }
+ }
+ }
+ return $all;
}
function autoCommit($onoff = false)