cvs: pear /MDB MDB.php MDB_test.php common.php metabase_wrapper.php mysql.php pear_wrapper.php pgsql.php

From: Date: Thu, 22 Aug 2002 11:34:13 +0000
Subject: cvs: pear /MDB MDB.php MDB_test.php common.php metabase_wrapper.php mysql.php pear_wrapper.php pgsql.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-5879@lists.php.net to get a copy of this message
lsmith Thu Aug 22 07:34:13 2002 EDT Modified files: /pear/MDB pgsql.php pear_wrapper.php mysql.php metabase_wrapper.php MDB_test.php MDB.php common.php Log: bug fixes to the handleing of the various fetchmodes

Index: pear/MDB/pgsql.php diff -u pear/MDB/pgsql.php:1.28 pear/MDB/pgsql.php:1.29 --- pear/MDB/pgsql.php:1.28 Wed Aug 21 09:01:58 2002 +++ pear/MDB/pgsql.php Thu Aug 22 07:34:12 2002 @@ -42,7 +42,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: pgsql.php,v 1.28 2002/08/21 13:01:58 lsmith Exp $ +// $Id: pgsql.php,v 1.29 2002/08/22 11:34:12 lsmith Exp $ if (!defined('MDB_PGSQL_INCLUDED')) { define('MDB_PGSQL_INCLUDED', 1); @@ -1360,7 +1360,10 @@ if ($rownum + 1 > $this->numRows($result)) { return NULL; } - if ($fetchmode &DB_FETCHMODE_ASSOC) { + if ($fetchmode == DB_FETCHMODE_DEFAULT) { + $fetchmode = $this->fetchmode; + } + if ($fetchmode & DB_FETCHMODE_ASSOC) { $array = @pg_fetch_array($result, $rownum, PGSQL_ASSOC); } else { $array = @pg_fetch_row($result, $rownum); Index: pear/MDB/pear_wrapper.php diff -u pear/MDB/pear_wrapper.php:1.20 pear/MDB/pear_wrapper.php:1.21 --- pear/MDB/pear_wrapper.php:1.20 Mon Aug 12 15:33:20 2002 +++ pear/MDB/pear_wrapper.php Thu Aug 22 07:34:12 2002 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@dybnet.de> | // +----------------------------------------------------------------------+ // -// $Id: pear_wrapper.php,v 1.20 2002/08/12 19:33:20 lsmith Exp $ +// $Id: pear_wrapper.php,v 1.21 2002/08/22 11:34:12 lsmith Exp $ // require_once (dirname(__FILE__).'/MDB.php'); @@ -343,7 +343,7 @@ function &getCol($query, $col = 0, $params = array()) { - return $this->MDB_object->getCol($query, NULL, $params, NULL, DB_FETCHMODE_DEFAULT, $col); + return $this->MDB_object->getCol($query, NULL, $params, NULL, $col); } function &getAssoc($query, $force_array = FALSE, $params = array(), Index: pear/MDB/mysql.php diff -u pear/MDB/mysql.php:1.42 pear/MDB/mysql.php:1.43 --- pear/MDB/mysql.php:1.42 Wed Aug 21 09:01:58 2002 +++ pear/MDB/mysql.php Thu Aug 22 07:34:12 2002 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@dybnet.de> | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.42 2002/08/21 13:01:58 lsmith Exp $ +// $Id: mysql.php,v 1.43 2002/08/22 11:34:12 lsmith Exp $ // if (!defined('MDB_MYSQL_INCLUDED')) { @@ -1335,10 +1335,13 @@ } $this->highest_fetched_row[$result] = max($this->highest_fetched_row[$result], $rownum); } + if ($fetchmode == DB_FETCHMODE_DEFAULT) { + $fetchmode = $this->fetchmode; + } if ($fetchmode & DB_FETCHMODE_ASSOC) { - $array = mysql_fetch_array($result, MYSQL_ASSOC); + $array = @mysql_fetch_array($result, MYSQL_ASSOC); } else { - $array = mysql_fetch_row($result); + $array = @mysql_fetch_row($result); } if (!$array) { $errno = @mysql_errno($this->connection); Index: pear/MDB/metabase_wrapper.php diff -u pear/MDB/metabase_wrapper.php:1.32 pear/MDB/metabase_wrapper.php:1.33 --- pear/MDB/metabase_wrapper.php:1.32 Tue Aug 20 11:25:44 2002 +++ pear/MDB/metabase_wrapper.php Thu Aug 22 07:34:12 2002 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@dybnet.de> | // +----------------------------------------------------------------------+ // -// $Id: metabase_wrapper.php,v 1.32 2002/08/20 15:25:44 lsmith Exp $ +// $Id: metabase_wrapper.php,v 1.33 2002/08/22 11:34:12 lsmith Exp $ // require_once(dirname(__FILE__).'/MDB.php'); @@ -178,7 +178,7 @@ function MetabaseQueryColumn($database, $query, &$column, $type = 'text') { global $databases; - $result = $databases[$database]->queryCol($query, $type, DB_FETCHMODE_ORDERED); + $result = $databases[$database]->queryCol($query, $type); if (MDB::isError($result)) { $databases[$database]->setError('QueryColumn', $result->getMessage()); return(0); Index: pear/MDB/MDB_test.php diff -u pear/MDB/MDB_test.php:1.28 pear/MDB/MDB_test.php:1.29 --- pear/MDB/MDB_test.php:1.28 Sun Aug 11 07:56:10 2002 +++ pear/MDB/MDB_test.php Thu Aug 22 07:34:12 2002 @@ -1,5 +1,5 @@ <?php -// $Id: MDB_test.php,v 1.28 2002/08/11 11:56:10 lsmith Exp $ +// $Id: MDB_test.php,v 1.29 2002/08/22 11:34:12 lsmith Exp $ // // MDB test script. // @@ -87,8 +87,8 @@ $result = $db->query($query); $types = array('integer', 'text', 'timestamp'); $db->setResultTypes($result, $types); - $array = $db->fetchAll($result); - echo '<br>all:<br>'; + $array = $db->fetchAll($result, DB_FETCHMODE_FLIPPED); + echo '<br>all with result set flipped:<br>'; echo Var_Dump::display($array).'<br>'; // save some time with this function // lets just get all and free the result @@ -136,9 +136,13 @@ echo '<br>see getOne in action:<br>'; echo Var_Dump::display($db->getOne('SELECT trans_en FROM numbers WHERE number = ?','text',$array)).'<br>'; echo '<br>see getRow in action:<br>'; - echo Var_Dump::display($db->getRow('SELECT * FROM numbers WHERE number = ?',array('integer','text','text'),$array)).'<br>'; + $db->setFetchmode(DB_FETCHMODE_ASSOC); + echo '<br>default fetchmode ist now DB_FETCHMODE_ASSOC<br>'; + echo Var_Dump::display($db->getRow('SELECT * FROM numbers WHERE number = ?',array('integer','text','text'),$array)); + echo 'default fetchmode ist now DB_FETCHMODE_ORDERED<br>'; + $db->setFetchmode(DB_FETCHMODE_ORDERED); echo '<br>see getCol in action:<br>'; - echo Var_Dump::display($db->getCol('SELECT * FROM numbers','text', 1)).'<br>'; + echo Var_Dump::display($db->getCol('SELECT * FROM numbers','text', NULL, NULL, 1)).'<br>'; echo '<br>see getAll in action:<br>'; echo Var_Dump::display($db->getAll('SELECT * FROM test',array('integer','text','text'))).'<br>'; echo '<br>see getAssoc in action:<br>'; Index: pear/MDB/MDB.php diff -u pear/MDB/MDB.php:1.29 pear/MDB/MDB.php:1.30 --- pear/MDB/MDB.php:1.29 Wed Aug 21 09:01:58 2002 +++ pear/MDB/MDB.php Thu Aug 22 07:34:12 2002 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@dybnet.de> | // +----------------------------------------------------------------------+ // -// $Id: MDB.php,v 1.29 2002/08/21 13:01:58 lsmith Exp $ +// $Id: MDB.php,v 1.30 2002/08/22 11:34:12 lsmith Exp $ // require_once 'PEAR.php'; @@ -133,7 +133,7 @@ * any particular get mode, so the default should be used. */ -define('DB_FETCHMODE_DEFAULT', 0); +define('DB_FETCHMODE_DEFAULT', 0); /** * Column data indexed by numbers, ordered from 0 and up Index: pear/MDB/common.php diff -u pear/MDB/common.php:1.50 pear/MDB/common.php:1.51 --- pear/MDB/common.php:1.50 Wed Aug 21 09:01:59 2002 +++ pear/MDB/common.php Thu Aug 22 07:34:13 2002 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@dybnet.de> | // +----------------------------------------------------------------------+ // -// $Id: common.php,v 1.50 2002/08/21 13:01:59 lsmith Exp $ +// $Id: common.php,v 1.51 2002/08/22 11:34:13 lsmith Exp $ require_once 'PEAR.php'; @@ -3545,7 +3545,7 @@ * Fetch a row and insert the data into an existing array. * * @param resource $result result identifier - * @param int $fetchmode how the array data should be indexed + * @param int $fetchmode ignored * @param int $rownum the row number to fetch * @return int data array or NULL on success, a DB error on failure * @access public @@ -3603,13 +3603,12 @@ * Fetch and return a field of data (it uses fetchInto for that) * * @param resource $result result identifier - * @param int $fetchmode how the array data should be indexed * @return mixed data array on success, a DB error on failure * @access public */ - function fetchOne($result, $fetchmode = DB_FETCHMODE_DEFAULT) + function fetchOne($result) { - $res = $this->fetchInto($result, $fetchmode, NULL); + $res = $this->fetchInto($result); if (!$this->options['autofree'] && $res != NULL) { $this->freeResult($result); } @@ -3647,13 +3646,13 @@ * Fetch and return a column of data (it uses fetchInto for that) * * @param resource $result result identifier - * @param int $fetchmode how the array data should be indexed * @param int $colnum the row number to fetch * @return mixed data array on success, a DB error on failure * @access public */ - function fetchCol($result, $fetchmode = DB_FETCHMODE_DEFAULT, $colnum = '0') + function fetchCol($result, $colnum = 0) { + $fetchmode = is_int($colnum) ? DB_FETCHMODE_ORDERED : DB_FETCHMODE_ASSOC; $column = array(); while (is_array($res = $this->fetchInto($result, $fetchmode, NULL))) { $column[] = $res[$colnum]; @@ -3701,7 +3700,7 @@ $all = array(); while (is_array($res = $this->fetchInto($result, $fetchmode, NULL))) { if ($rekey) { - if ($fetchmode == DB_FETCHMODE_ASSOC) { + if ($fetchmode & DB_FETCHMODE_ASSOC) { reset($res); $key = current($res); unset($res[key($res)]); @@ -3717,7 +3716,13 @@ $all[$key] = $res; } } else { - $all[] = $res; + if ($fetchmode & DB_FETCHMODE_FLIPPED) { + foreach ($res as $key => $val) { + $all[$key][] = $val; + } + } else { + $all[] = $res; + } } } if (!$this->options['autofree'] && $res != NULL) { @@ -3745,7 +3750,7 @@ * @return mixed field value on success, a DB error on failure * @access public */ - function queryOne($query, $type = NULL, $fetchmode = DB_FETCHMODE_DEFAULT) + function queryOne($query, $type = NULL) { if ($type != NULL) { $type = array($type); @@ -3754,7 +3759,7 @@ if (MDB::isError($result)) { return $result; } - return ($this->fetchOne($result, $fetchmode)); + return ($this->fetchOne($result)); } // }}} @@ -3796,12 +3801,11 @@ * datatype of the result set field, so that an eventual conversion * may be performed. The default datatype is text, meaning that no * conversion is performed - * @param int $fetchmode how the array data should be indexed * @param int $colnum the row number to fetch * @return mixed data array on success, a DB error on failure * @access public */ - function queryCol($query, $type = NULL, $fetchmode = DB_FETCHMODE_DEFAULT, $colnum = '0') + function queryCol($query, $type = NULL, $colnum = 0) { if ($type != NULL) { $type = array($type); @@ -3810,7 +3814,7 @@ if (MDB::isError($result)) { return $result; } - return ($this->fetchCol($result, $fetchmode, $colnum)); + return ($this->fetchCol($result, $colnum)); } // }}} @@ -3839,7 +3843,8 @@ * @return mixed data array on success, a DB error on failure * @access public */ - function queryAll($query, $types = NULL, $fetchmode = DB_FETCHMODE_DEFAULT, $rekey = FALSE, $force_array = FALSE, $group = FALSE) + function queryAll($query, $types = NULL, $fetchmode = DB_FETCHMODE_DEFAULT, + $rekey = FALSE, $force_array = FALSE, $group = FALSE) { if (MDB::isError($result = $this->query($query, $types))) { return $result; @@ -3870,8 +3875,8 @@ if ($type != NULL) { $type = array($type); } - settype($params, 'array'); - if (sizeof($params) > 0) { + settype($params, "array"); + if (count($params) > 0) { $prepared_query = $this->prepareQuery($query); if (MDB::isError($prepared_query)) { return $prepared_query; @@ -3921,8 +3926,8 @@ */ function &getRow($query, $types = NULL, $params = array(), $param_types = NULL, $fetchmode = DB_FETCHMODE_DEFAULT) { - settype($params, 'array'); - if (sizeof($params) > 0) { + settype($params, "array"); + if (count($params) > 0) { $prepared_query = $this->prepareQuery($query); if (MDB::isError($prepared_query)) { return $prepared_query; @@ -3965,20 +3970,19 @@ * with this array as execute parameters * @param array $param_types array that contains the types of the values * defined in $params - * @param integer $fetchmode the fetch mode to use * @param mixed $colnum which column to return (integer [column number, * starting at 0] or string [column name]) * @return array an indexed array with the data from the first * row at index 0, or a DB error code. * @access public */ - function &getCol($query, $type = NULL, $params = array(), $param_types = NULL, $fetchmode = DB_FETCHMODE_DEFAULT, $colnum = '0') + function &getCol($query, $type = NULL, $params = array(), $param_types = NULL, $colnum = 0) { if ($type != NULL) { $type = array($type); } settype($params, 'array'); - if (sizeof($params) > 0) { + if (count($params) > 0) { $prepared_query = $this->prepareQuery($query); if (MDB::isError($prepared_query)) { @@ -3994,7 +3998,7 @@ return $result; } - $col = $this->fetchCol($result, $fetchmode, $colnum); + $col = $this->fetchCol($result, $colnum); if (MDB::isError($col)) { return $col; } @@ -4083,8 +4087,8 @@ function &getAssoc($query, $types = NULL, $params = array(), $param_types = NULL, $fetchmode = DB_FETCHMODE_ORDERED, $force_array = FALSE, $group = FALSE) { - settype($params, 'array'); - if (sizeof($params) > 0) { + settype($params, "array"); + if (count($params) > 0) { $prepared_query = $this->prepareQuery($query); if (MDB::isError($prepared_query)) { @@ -4132,8 +4136,8 @@ */ function &getAll($query, $types = NULL, $params = array(), $param_types = NULL, $fetchmode = DB_FETCHMODE_DEFAULT) { - settype($params, 'array'); - if (sizeof($params) > 0) { + settype($params, "array"); + if (count($params) > 0) { $prepared_query = $this->prepareQuery($query); if (MDB::isError($prepared_query)) {
« previous php.pear.cvs (#5879) next »