cvs: pear /MDB_QueryTool package.xml /MDB_QueryTool/QueryTool Result.php
| From: | Lorenzo Alberton | Date: | Mon, 30 Oct 2006 19:29:07 +0000 |
| Subject: | cvs: pear /MDB_QueryTool package.xml /MDB_QueryTool/QueryTool Result.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-42896@lists.php.net to get a copy of this message | ||
quipo Mon Oct 30 19:29:07 2006 UTC
Modified files:
/pear/MDB_QueryTool/QueryTool Result.php
/pear/MDB_QueryTool package.xml
Log:
fixed handling of returned values in MDB_QueryTool_Result
http://cvs.php.net/viewvc.cgi/pear/MDB_QueryTool/QueryTool/Result.php?r1=1.11&r2=1.12&diff_format=u
Index: pear/MDB_QueryTool/QueryTool/Result.php
diff -u pear/MDB_QueryTool/QueryTool/Result.php:1.11 pear/MDB_QueryTool/QueryTool/Result.php:1.12
--- pear/MDB_QueryTool/QueryTool/Result.php:1.11 Mon May 1 15:27:08 2006
+++ pear/MDB_QueryTool/QueryTool/Result.php Mon Oct 30 19:29:07 2006
@@ -32,7 +32,7 @@
* @author Lorenzo Alberton <l dot alberton at quipo dot it>
* @copyright 2003-2006 Lorenzo Alberton
* @license http://www.debian.org/misc/bsd.license BSD
License (3 Clause)
- * @version CVS: $Id: Result.php,v 1.11 2006/05/01 15:27:08 quipo Exp $
+ * @version CVS: $Id: Result.php,v 1.12 2006/10/30 19:29:07 quipo Exp $
* @link http://pear.php.net/package/MDB_QueryTool
*/
@@ -77,6 +77,12 @@
* @var array
*/
var $_counter = null;
+
+ /**
+ * True if the data is a collection of rows, false if it's a single record
+ * @var boolean
+ */
+ var $_is_collection_of_rows;
// }}}
// {{{ MDB_QueryTool_Result()
@@ -89,11 +95,11 @@
*/
function MDB_QueryTool_Result($data)
{
+ $this->_checkIfCollectionOfRows($data);
if (!count($data)) {
$this->_count = 0;
} else {
- list($firstElement) = $data;
- if (is_array($firstElement)) { // is the array a collection of rows?
+ if ($this->_is_collection_of_rows) {
$this->_count = sizeof($data);
} else {
if (sizeof($data) > 0) {
@@ -107,6 +113,35 @@
}
// }}}
+ // {{{ _checkIfCollectionOfRows
+
+ /**
+ * Check if the result is a single record or a collection of rows
+ * @access private
+ */
+ function _checkIfCollectionOfRows($data)
+ {
+ $this->_is_collection_of_rows = is_array(array_pop($data));
+ }
+
+ // }}}
+ // {{{ _returnRowOrValue
+
+ /**
+ * Check if the row is a single value with a numeric index.
+ * If so, return the value straight away, since the user probably
+ * called getCol() or getOne().
+ * @access protected
+ */
+ function _returnRowOrValue($data)
+ {
+ if ((count($data) == 1) && is_numeric(key($data))) {
+ return array_pop($data);
+ }
+ return $data;
+ }
+
+ // }}}
// {{{ numRows
/**
@@ -169,9 +204,12 @@
function getFirst()
{
if ($this->getCount() > 0) {
- $this->_dataKeys = array_keys($this->_data);
- $this->_counter = 0;
- return $this->_data[$this->_dataKeys[$this->_counter]];
+ if ($this->_is_collection_of_rows) {
+ $this->_dataKeys = array_keys($this->_data);
+ $this->_counter = 0;
+ return
$this->_returnRowOrValue($this->_data[$this->_dataKeys[$this->_counter]]);
+ }
+ return $this->_returnRowOrValue($this->_data);
}
return new PEAR_Error('there are no elements!');
}
@@ -193,7 +231,7 @@
}
if ($this->hasMore()) {
$this->_counter++;
- return $this->_data[$this->_dataKeys[$this->_counter]];
+ return
$this->_returnRowOrValue($this->_data[$this->_dataKeys[$this->_counter]]);
}
return new PEAR_Error('there are no more elements!');
}
http://cvs.php.net/viewvc.cgi/pear/MDB_QueryTool/package.xml?r1=1.49&r2=1.50&diff_format=u
Index: pear/MDB_QueryTool/package.xml
diff -u pear/MDB_QueryTool/package.xml:1.49 pear/MDB_QueryTool/package.xml:1.50
--- pear/MDB_QueryTool/package.xml:1.49 Mon Oct 30 19:22:37 2006
+++ pear/MDB_QueryTool/package.xml Mon Oct 30 19:29:07 2006
@@ -33,6 +33,7 @@
- fixed bug #8319: add $options['idxname_format'] to connect() to bypass
MDB2 default index format
- added save() method to MDB_QueryTool_Result_Row (thanks to Elmar Pitschke)
+ - fixed handling of returned values in MDB_QueryTool_Result
</notes>
<filelist>
<dir name="/" baseinstalldir="MDB">
@@ -113,6 +114,7 @@
- fixed bug #8319: add $options['idxname_format'] to connect() to bypass
MDB2 default index format
- added save() method to MDB_QueryTool_Result_Row (thanks to Elmar Pitschke)
+ - fixed handling of returned values in MDB_QueryTool_Result
</notes>
</release>
<release>