cvs: pear /MDB/MDB Common.php fbsql.php ibase.php mssql.php mysql.php oci8.php pgsql.php querysim.php
| From: | Lukas Smith | Date: | Thu, 31 Jul 2003 10:31:04 +0000 |
| Subject: | cvs: pear /MDB/MDB Common.php fbsql.php ibase.php mssql.php mysql.php oci8.php pgsql.php querysim.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-11819@lists.php.net to get a copy of this message | ||
lsmith Thu Jul 31 06:31:04 2003 EDT
Modified files:
/pear/MDB/MDB querysim.php pgsql.php oci8.php mysql.php mssql.php
ibase.php fbsql.php Common.php
Log:
- fetch* methods now dont always free result
- removed fetchInto because fetchRow can handle thisd job now
- started to clean up storage of meta data for open results
Index: pear/MDB/MDB/querysim.php diff -u pear/MDB/MDB/querysim.php:1.7 pear/MDB/MDB/querysim.php:1.8 --- pear/MDB/MDB/querysim.php:1.7 Thu Jul 24 06:53:01 2003 +++ pear/MDB/MDB/querysim.php Thu Jul 31 06:31:03 2003 @@ -60,7 +60,7 @@ // | please contact Alan Richmond. | // +----------------------------------------------------------------------+ // -// $Id: querysim.php,v 1.7 2003/07/24 10:53:01 lsmith Exp $ +// $Id: querysim.php,v 1.8 2003/07/31 10:31:03 lsmith Exp $ // /* @@ -82,7 +82,7 @@ <history author="Alan Richmond" email="arichmond@bigfoot.com" type="Create" date="10-July-2002"> Rewrote in PHP as an extention to the PEAR DB API. Functions supported: - connect, disconnect, query, fetchRow, fetchInto, freeResult, + connect, disconnect, query, fetchRow, freeResult, numCols, numRows, getSpecialQuery David Huyck (bombusbee.com) added ability to escape special characters (i.e., delimiters) using a '\'. @@ -140,7 +140,7 @@ Ported to PEAR MDB. Methods supported: connect, query, getColumnNames, numCols, endOfResult, fetch, - numRows, freeResult, fetchInto, nextResult, setLimit + numRows, freeResult, fetchRow, nextResult, setLimit (inherited). </history> <history @@ -716,7 +716,7 @@ } // }}} - // {{{ fetchInto() + // {{{ fetchRow() /** * Fetch a row and return data in an array. @@ -727,7 +727,7 @@ * @return mixed data array or null on success, a MDB error on failure * @access public */ - function fetchInto(&$result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) + function fetchRow(&$result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) { $result_link = $this->_querySimSignature($result); //if specific rownum request @@ -753,6 +753,9 @@ $arraytemp[$result[0][$key]] = $value; } $array = $arraytemp; + } + if (isset($this->results[$result]['types'])) { + $array = $this->datatype->convertResultRow($this, $result, $array); } return $array; } Index: pear/MDB/MDB/pgsql.php diff -u pear/MDB/MDB/pgsql.php:1.63 pear/MDB/MDB/pgsql.php:1.64 --- pear/MDB/MDB/pgsql.php:1.63 Thu Jul 24 06:55:13 2003 +++ pear/MDB/MDB/pgsql.php Thu Jul 31 06:31:03 2003 @@ -42,7 +42,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: pgsql.php,v 1.63 2003/07/24 10:55:13 lsmith Exp $ +// $Id: pgsql.php,v 1.64 2003/07/31 10:31:03 lsmith Exp $ require_once 'MDB/Common.php'; @@ -483,7 +483,7 @@ $this->affected_rows = @pg_cmdtuples($result); return MDB_OK; } elseif (preg_match('/^\s*\(?\s*SELECT\s+/si', $query) && !preg_match('/^\s*\(?\s*SELECT\s+INTO\s/si', $query)) { - $this->highest_fetched_row[$result] = -1; + $this->results[$result]['highest_fetched_row'] = -1; if ($types != null) { if (!is_array($types)) { $types = array($types); @@ -519,17 +519,17 @@ */ function getColumnNames($result) { - if (!isset($this->highest_fetched_row[$result])) { + if (!isset($this->results[$result]['highest_fetched_row'])) { return $this->raiseError(MDB_ERROR, null, null, 'Get Column Names: specified an nonexistant result set'); } - if (!isset($this->columns[$result])) { - $this->columns[$result] = array(); + if (!isset($this->results[$result]['columns'])) { + $this->results[$result]['columns'] = array(); $columns = pg_numfields($result); for($column = 0; $column < $columns; $column++) { - $this->columns[$result][strtolower(pg_fieldname($result, $column))] = $column; + $this->results[$result]['columns'][strtolower(pg_fieldname($result, $column))] = $column; } } - return $this->columns[$result]; + return $this->results[$result]['columns']; } // }}} @@ -545,7 +545,7 @@ */ function numCols($result) { - if (!isset($this->highest_fetched_row[$result])) { + if (!isset($this->results[$result]['highest_fetched_row'])) { return $this->raiseError(MDB_ERROR, null, null, 'numCols: specified an nonexistant result set'); } return pg_numfields($result); @@ -563,10 +563,10 @@ */ function endOfResult($result) { - if (!isset($this->highest_fetched_row[$result])) { + if (!isset($this->results[$result]['highest_fetched_row'])) { return $this->RaiseError(MDB_ERROR, null, null, 'End of result attempted to check the end of an unknown result'); } - return $this->highest_fetched_row[$result] >= $this->numRows($result) - 1; + return $this->results[$result]['highest_fetched_row'] >= $this->numRows($result) - 1; } // }}} @@ -584,7 +584,7 @@ */ function resultIsNull($result, $row, $field) { - $this->highest_fetched_row[$result] = max($this->highest_fetched_row[$result], $row); + $this->results[$result]['highest_fetched_row'] = max($this->results[$result]['highest_fetched_row'], $row); return @pg_FieldIsNull($result, $row, $field); } @@ -615,14 +615,14 @@ */ function freeResult($result) { - if (isset($this->highest_fetched_row[$result])) { - unset($this->highest_fetched_row[$result]); + if (isset($this->results[$result]['highest_fetched_row'])) { + unset($this->results[$result]['highest_fetched_row']); } - if (isset($this->columns[$result])) { - unset($this->columns[$result]); + if (isset($this->results[$result]['columns'])) { + unset($this->results[$result]['columns']); } - if (isset($this->result_types[$result])) { - unset($this->result_types[$result]); + if (isset($this->results[$result]['types'])) { + unset($this->results[$result]['types']); } return pg_freeresult($result); } @@ -662,9 +662,9 @@ if (MDB::isError($result)) { return $this->raiseError($result); } - $arr = $this->fetchInto($result, MDB_FETCHMODE_ORDERED); + $next_id = $this->fetchOne($result, MDB_FETCHMODE_ORDERED); $this->freeResult($result); - return $arr[0]; + return $next_id; } // }}} @@ -691,7 +691,7 @@ // }}} - // {{{ fetchInto() + // {{{ fetchRow() /** * Fetch a row and return data in an array. @@ -702,13 +702,13 @@ * @return mixed data array or null on success, a MDB error on failure * @access public */ - function fetchInto($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) + function fetchRow($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) { if ($rownum == null) { - ++$this->highest_fetched_row[$result]; - $rownum = $this->highest_fetched_row[$result]; + ++$this->results[$result]['highest_fetched_row']; + $rownum = $this->results[$result]['highest_fetched_row']; } else { - $this->highest_fetched_row[$result] = max($this->highest_fetched_row[$result], $rownum); + $this->results[$result]['highest_fetched_row'] = max($this->results[$result]['highest_fetched_row'], $rownum); } if ($rownum + 1 > $this->numRows($result)) { return null; @@ -731,8 +731,8 @@ } return $this->pgsqlRaiseError($errno); } - if (isset($this->result_types[$result])) { - $array = $this->convertResultRow($result, $array); + if (isset($this->results[$result]['types'])) { + $array = $this->datatype->convertResultRow($this, $result, $array); } return $array; } Index: pear/MDB/MDB/oci8.php diff -u pear/MDB/MDB/oci8.php:1.22 pear/MDB/MDB/oci8.php:1.23 --- pear/MDB/MDB/oci8.php:1.22 Thu Jul 24 06:55:13 2003 +++ pear/MDB/MDB/oci8.php Thu Jul 31 06:31:03 2003 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ -// $Id: oci8.php,v 1.22 2003/07/24 10:55:13 lsmith Exp $ +// $Id: oci8.php,v 1.23 2003/07/31 10:31:03 lsmith Exp $ require_once 'MDB/Common.php'; @@ -738,8 +738,8 @@ if (MDB::isError($column = $this->_getColumn($result, $field))) { return $column; } - if (MDB::isError($fetchinto = $this->fetchInto($result, MDB_FETCHMODE_ORDERED, $row))) { - return $fetchInto; + if (MDB::isError($fetchrow = $this->fetchRow($result, MDB_FETCHMODE_ORDERED, $row))) { + return $fetchrow; } $this->highest_fetched_row[$result_value] = max($this->highest_fetched_row[$result_value], $row); return !isset($this->results[$result_value][$row][$column]); @@ -805,8 +805,8 @@ return $this->raiseError(MDB_ERROR, null, null, 'Free result: attemped to free an unknown query result'); } - if (isset($this->highest_fetched_row[$result])) { - unset($this->highest_fetched_row[$result]); + if (isset($this->results[$result])) { + unset($this->results[$result]); } if (isset($this->row_buffer[$result_value])) { unset($this->row_buffer[$result_value]); @@ -820,15 +820,9 @@ if (isset($this->results[$result_value])) { unset($this->results[$result_value]); } - if (isset($this->columns[$result])) { - unset($this->columns[$result]); - } if (isset($this->rows[$result_value])) { unset($this->rows[$result_value]); } - if (isset($this->result_types[$result])) { - unset($this->result_types[$result]); - } return @OCIFreeCursor($result); } @@ -857,7 +851,7 @@ } // }}} - // {{{ fetchInto() + // {{{ fetchRow() /** * Fetch a row and insert the data into an existing array. @@ -868,7 +862,7 @@ * @return int data array on success, a MDB error on failure * @access public */ - function fetchInto($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) + function fetchRow($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) { $result_value = intval($result); if (!isset($this->current_row[$result_value])) { @@ -918,8 +912,8 @@ $result_value = intval($result); $array = $this->results[$result_value][$rownum]; $this->highest_fetched_row[$result_value] = max($this->highest_fetched_row[$result_value], $rownum); - if (isset($this->result_types[$result])) { - $array = $this->convertResultRow($result, $array); + if (isset($this->results[$result]['types'])) { + $array = $this->datatype->convertResultRow($this, $result, $array); } return $array; } Index: pear/MDB/MDB/mysql.php diff -u pear/MDB/MDB/mysql.php:1.81 pear/MDB/MDB/mysql.php:1.82 --- pear/MDB/MDB/mysql.php:1.81 Thu Jul 24 06:55:13 2003 +++ pear/MDB/MDB/mysql.php Thu Jul 31 06:31:03 2003 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.81 2003/07/24 10:55:13 lsmith Exp $ +// $Id: mysql.php,v 1.82 2003/07/31 10:31:03 lsmith Exp $ // require_once 'MDB/Common.php'; @@ -450,7 +450,7 @@ $this->affected_rows = mysql_affected_rows($this->connection); return MDB_OK; } else { - $this->highest_fetched_row[$result] = -1; + $this->results[$result]['highest_fetched_row'] = -1; if ($types != null) { if (!is_array($types)) { $types = array($types); @@ -702,11 +702,11 @@ */ function endOfResult($result) { - if (!isset($this->highest_fetched_row[$result])) { + if (!isset($this->results[$result]['highest_fetched_row'])) { return $this->raiseError(MDB_ERROR, null, null, 'End of result: attempted to check the end of an unknown result'); } - return $this->highest_fetched_row[$result] >= $this->numRows($result)-1; + return $this->results[$result]['highest_fetched_row'] >= $this->numRows($result)-1; } // }}} @@ -736,14 +736,8 @@ */ function freeResult($result) { - if (isset($this->highest_fetched_row[$result])) { - unset($this->highest_fetched_row[$result]); - } - if (isset($this->columns[$result])) { - unset($this->columns[$result]); - } - if (isset($this->result_types[$result])) { - unset($this->result_types[$result]); + if (isset($this->results[$result])) { + unset($this->results[$result]); } return mysql_free_result($result); } @@ -794,7 +788,7 @@ } // }}} - // {{{ fetchInto() + // {{{ fetchRow() /** * Fetch a row and insert the data into an existing array. @@ -805,15 +799,15 @@ * @return int data array on success, a MDB error on failure * @access public */ - function fetchInto($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) + function fetchRow($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) { if ($rownum == null) { - ++$this->highest_fetched_row[$result]; + ++$this->results[$result]['highest_fetched_row']; } else { if (!@mysql_data_seek($result, $rownum)) { return null; } - $this->highest_fetched_row[$result] = max($this->highest_fetched_row[$result], $rownum); + $this->results[$result]['highest_fetched_row'] = max($this->results[$result]['highest_fetched_row'], $rownum); } if ($fetchmode == MDB_FETCHMODE_DEFAULT) { $fetchmode = $this->fetchmode; @@ -833,8 +827,8 @@ } return $this->mysqlRaiseError($errno); } - if (isset($this->result_types[$result])) { - $array = $this->convertResultRow($result, $array); + if (isset($this->results[$result]['types'])) { + $array = $this->datatype->convertResultRow($this, $result, $array); } return $array; } Index: pear/MDB/MDB/mssql.php diff -u pear/MDB/MDB/mssql.php:1.7 pear/MDB/MDB/mssql.php:1.8 --- pear/MDB/MDB/mssql.php:1.7 Thu Jul 24 06:55:13 2003 +++ pear/MDB/MDB/mssql.php Thu Jul 31 06:31:03 2003 @@ -43,7 +43,7 @@ // | Author: Frank M. Kromann <frank@kromann.info> | // +----------------------------------------------------------------------+ // -// $Id: mssql.php,v 1.7 2003/07/24 10:55:13 lsmith Exp $ +// $Id: mssql.php,v 1.8 2003/07/31 10:31:03 lsmith Exp $ // require_once 'MDB/Common.php'; @@ -417,7 +417,7 @@ $this->affected_rows = mssql_affected_rows($this->connection); return MDB_OK; } else { - $this->highest_fetched_row[$result] = -1; + $this->results[$result]['highest_fetched_row'] = -1; if ($types != null) { if (!is_array($types)) { $types = array($types); @@ -503,11 +503,11 @@ */ function endOfResult($result) { - if (!isset($this->highest_fetched_row[$result])) { + if (!isset($this->results[$result]['highest_fetched_row'])) { return $this->raiseError(MDB_ERROR, null, null, 'End of result: attempted to check the end of an unknown result'); } - return $this->highest_fetched_row[$result] >= $this->numRows($result)-1; + return $this->results[$result]['highest_fetched_row'] >= $this->numRows($result)-1; } // }}} @@ -543,14 +543,8 @@ if (isset($this->ranges[$result])) { unset($this->ranges[$result]); } - if (isset($this->highest_fetched_row[$result])) { - unset($this->highest_fetched_row[$result]); - } - if (isset($this->columns[$result])) { - unset($this->columns[$result]); - } - if (isset($this->result_types[$result])) { - unset($this->result_types[$result]); + if (isset($this->results[$result])) { + unset($this->results[$result]); } return mssql_free_result($result); } @@ -620,7 +614,7 @@ } // }}} - // {{{ fetchInto() + // {{{ fetchRow() /** * Fetch a row and insert the data into an existing array. @@ -631,15 +625,15 @@ * @return int data array on success, a MDB error on failure * @access public */ - function fetchInto($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) + function fetchRow($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) { if ($rownum == null) { - ++$this->highest_fetched_row[$result]; + ++$this->results[$result]['highest_fetched_row']; } else { if (!@mssql_data_seek($result, $rownum)) { return null; } - $this->highest_fetched_row[$result] = max($this->highest_fetched_row[$result], $rownum); + $this->results[$result]['highest_fetched_row'] = max($this->results[$result]['highest_fetched_row'], $rownum); } if ($fetchmode == MDB_FETCHMODE_DEFAULT) { $fetchmode = $this->fetchmode; @@ -659,8 +653,8 @@ } return $this->mssqlRaiseError($errno); } - if (isset($this->result_types[$result])) { - $array = $this->convertResultRow($result, $array); + if (isset($this->results[$result]['types'])) { + $array = $this->datatype->convertResultRow($this, $result, $array); } return $array; } Index: pear/MDB/MDB/ibase.php diff -u pear/MDB/MDB/ibase.php:1.11 pear/MDB/MDB/ibase.php:1.12 --- pear/MDB/MDB/ibase.php:1.11 Thu Jul 24 06:55:13 2003 +++ pear/MDB/MDB/ibase.php Thu Jul 31 06:31:03 2003 @@ -42,7 +42,7 @@ // | Author: Lorenzo Alberton <l.alberton@quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.11 2003/07/24 10:55:13 lsmith Exp $ +// $Id: ibase.php,v 1.12 2003/07/31 10:31:03 lsmith Exp $ require_once 'MDB/Common.php'; @@ -664,18 +664,18 @@ //return 1; /* - if (!isset($this->highest_fetched_row[$result])) { + if (!isset($this->results[$result]['highest_fetched_row'])) { return $this->raiseError(MDB_ERROR, null, null, 'Get Column Names: specified an nonexistant result set'); } - if (!isset($this->columns[$result])) { - $this->columns[$result] = array(); + if (!isset($this->results[$result]['columns'])) { + $this->results[$result]['columns'] = array(); $columns = ibase_num_fields($result); for ($column = 0; $column < $columns; $column++) { $_fieldInfo = ibase_field_info($result, $column); - $this->columns[$result][strtolower($_fieldInfo['name'])] = $column; + $this->results[$result]['columns'][strtolower($_fieldInfo['name'])] = $column; } } - return $this->columns[$result]; + return $this->results[$result]['columns']; */ } @@ -760,7 +760,7 @@ } // }}} - // {{{ fetchInto() + // {{{ fetchRow() /** * Fetch a row and return data in an array. @@ -771,27 +771,7 @@ * @return mixed data array or null on success, a MDB error on failure * @access public */ - function fetchInto($result, $fetchmode=MDB_FETCHMODE_DEFAULT, $rownum=null) - { - if (MDB::isError($err = $this->fetchResultRow($result, $rownum))) { - //echo '<span style="background-color:red">fetchInto ERROR!</span>'; - return $err; - } - $result_value = intval($result); - - //Should I do this? Why default value is null and not 0? - if ($rownum === null) { - $rownum = 0; - } - $array = $this->results[$result_value][$rownum]; - $this->highest_fetched_row[$result_value] = max($this->highest_fetched_row[$result_value], $rownum); - return $this->convertResultRow($result, $array); - } - - // }}} - // {{{ fetchResultRow() - - function fetchResultRow($result, $rownum = null) + function fetchRow($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) { //should I do this? Why $rownum is null by default and not 0? if (is_null($rownum)) { @@ -830,9 +810,14 @@ $this->results[$result_value][$this->current_row[$result_value]+1][$key] = rtrim($valueWithSpace); } } + } + $array = $this->results[$result_value][$rownum]; + $this->highest_fetched_row[$result_value] = max($this->highest_fetched_row[$result_value], $rownum); + if (isset($this->results[$result]['types'])) { + $array = $this->datatype->convertResultRow($this, $result, $array); } - return MDB_OK; + return $array; } // }}} @@ -895,8 +880,8 @@ return $this->raiseError(MDB_ERROR, null, null, 'Free result: attemped to free an unknown query result'); } - if (isset($this->highest_fetched_row[$result])) { - unset($this->highest_fetched_row[$result]); + if (isset($this->results[$result])) { + unset($this->results[$result]); } if (isset($this->row_buffer[$result_value])) { unset($this->row_buffer[$result_value]); @@ -910,14 +895,8 @@ if (isset($this->results[$result_value])) { unset($this->results[$result_value]); } - if (isset($this->columns[$result])) { - unset($this->columns[$result]); - } if (isset($this->rows[$result_value])) { unset($this->rows[$result_value]); - } - if (isset($this->result_types[$result])) { - unset($this->result_types[$result]); } if (is_resource($result)) { return @ibase_free_result($result); Index: pear/MDB/MDB/fbsql.php diff -u pear/MDB/MDB/fbsql.php:1.17 pear/MDB/MDB/fbsql.php:1.18 --- pear/MDB/MDB/fbsql.php:1.17 Thu Jul 24 06:55:13 2003 +++ pear/MDB/MDB/fbsql.php Thu Jul 31 06:31:03 2003 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@dybnet.de> | // +----------------------------------------------------------------------+ // -// $Id: fbsql.php,v 1.17 2003/07/24 10:55:13 lsmith Exp $ +// $Id: fbsql.php,v 1.18 2003/07/31 10:31:03 lsmith Exp $ // require_once 'MDB/Common.php'; @@ -417,7 +417,7 @@ $this->affected_rows = fbsql_affected_rows($this->connection); return MDB_OK; } else { - $this->highest_fetched_row[$result] = -1; + $this->results[$result]['highest_fetched_row'] = -1; if ($types != null) { if (!is_array($types)) { $types = array($types); @@ -501,11 +501,11 @@ */ function endOfResult($result) { - if (!isset($this->highest_fetched_row[$result])) { + if (!isset($this->results[$result]['highest_fetched_row'])) { return $this->raiseError(MDB_ERROR, null, null, 'End of result: attempted to check the end of an unknown result'); } - return $this->highest_fetched_row[$result] >= $this->numRows($result)-1; + return $this->results[$result]['highest_fetched_row'] >= $this->numRows($result)-1; } // }}} @@ -535,14 +535,8 @@ */ function freeResult($result) { - if (isset($this->highest_fetched_row[$result])) { - unset($this->highest_fetched_row[$result]); - } - if (isset($this->columns[$result])) { - unset($this->columns[$result]); - } - if (isset($this->result_types[$result])) { - unset($this->result_types[$result]); + if (isset($this->results[$result])) { + unset($this->results[$result]); } return fbsql_free_result($result); } @@ -613,7 +607,7 @@ } // }}} - // {{{ fetchInto() + // {{{ fetchRow() /** * Fetch a row and return data in an array. @@ -624,15 +618,15 @@ * @return mixed data array or null on success, a MDB error on failure * @access public */ - function fetchInto($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) + function fetchRow($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) { if ($rownum == null) { - ++$this->highest_fetched_row[$result]; + ++$this->results[$result]['highest_fetched_row']; } else { if (!@fbsql_data_seek($result, $rownum)) { return null; } - $this->highest_fetched_row[$result] = max($this->highest_fetched_row[$result], $rownum); + $this->results[$result]['highest_fetched_row'] = max($this->results[$result]['highest_fetched_row'], $rownum); } if ($fetchmode == MDB_FETCHMODE_DEFAULT) { $fetchmode = $this->fetchmode; @@ -652,8 +646,8 @@ } return $this->fbsqlRaiseError($errno); } - if (isset($this->result_types[$result])) { - $array = $this->convertResultRow($result, $array); + if (isset($this->results[$result]['types'])) { + $array = $this->datatype->convertResultRow($this, $result, $array); } return $array; } Index: pear/MDB/MDB/Common.php diff -u pear/MDB/MDB/Common.php:1.116 pear/MDB/MDB/Common.php:1.117 --- pear/MDB/MDB/Common.php:1.116 Sun Jul 27 05:32:06 2003 +++ pear/MDB/MDB/Common.php Thu Jul 31 06:31:03 2003 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.116 2003/07/27 09:32:06 quipo Exp $ +// $Id: Common.php,v 1.117 2003/07/31 10:31:03 lsmith Exp $ /** * @package MDB @@ -125,12 +125,12 @@ /** * $options["persistent"] -> boolean persistent connection true|false? * $options["debug"] -> integer numeric debug level - * $options["autofree"] -> boolean - * $options["lob_buffer_length"] -> integer LOB buffer length - * $options["log_line_break"] -> string line-break format - * $options["seqname_format"] -> string pattern for sequence name - * $options["includelob"] -> boolean - * $options["includemanager"] -> boolean + * $options["autofree"] -> boolean + * $options["lob_buffer_length"] -> integer LOB buffer length + * $options["log_line_break"] -> string line-break format + * $options["seqname_format"] -> string pattern for sequence name + * $options["includelob"] -> boolean + * $options["includemanager"] -> boolean * $options["UseTransactions"] -> boolean * @var array * @access private @@ -1404,7 +1404,7 @@ * Define the list of types to be associated with the columns of a given * result set. * - * This function may be called before invoking fetchInto(), fetchOne(), + * This function may be called before invoking fetchOne(), * fetchRow(), fetchCol() and fetchAll() so that the necessary data type * conversions are performed on the data to be retrieved by them. If this * function is not called, the type of all result set columns is assumed @@ -1709,68 +1709,10 @@ } // }}} - // {{{ fetchInto() - - /** - * Fetch a row and return data in an array. - * - * @param resource $result result identifier - * @param int $fetchmode ignored - * @param int $rownum the row number to fetch - * @return mixed data array or null on success, a MDB error on failure - * @access public - */ - function fetchInto($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) - { - if (MDB::isError($result)) { - return $this->raiseError(MDB_ERROR_NEED_MORE_DATA, null, null, - 'Fetch field: it was not specified a valid result set'); - } - if (MDB::isError($this->endOfResult($result))) { - $this->freeResult($result); - $result = $this->raiseError(MDB_ERROR_NEED_MORE_DATA, null, null, - 'Fetch field: result set is empty'); - } - if ($rownum == null) { - ++$this->highest_fetched_row[$result]; - $rownum = $this->highest_fetched_row[$result]; - } else { - $this->highest_fetched_row[$result] = max($this->highest_fetched_row[$result], $row); - } - if ($rownum + 1 > $this->numRows($result)) { - return null; - } - $columns = $this->numCols($result); - if (MDB::isError($columns)) { - return $columns; - } - for($column = 0; $column < $columns; $column++) { - if (!$this->resultIsNull($result, $rownum, $column)) { - $result = $this->fetch($result, $rownum, $column); - if (MDB::isError($result)) { - if ($result->getMessage() == '') { - if ($this->options['autofree']) { - $this->freeResult($result); - } - return null; - } else { - return $result; - } - } - } - $array[$column] = $result; - } - if (isset($this->result_types[$result])) { - $array = $this->convertResultRow($result, $array); - } - return $array; - } - - // }}} // {{{ fetchOne() /** - * Fetch and return a field of data (it uses fetchInto for that) + * Fetch and return a field of data (it uses fetchRow for that) * * @param resource $result result identifier * @return mixed data on success, a MDB error on failure @@ -1778,7 +1720,7 @@ */ function fetchOne($result) { - $row = $this->fetchInto($result, MDB_FETCHMODE_ORDERED); + $row = $this->fetchRow($result, MDB_FETCHMODE_ORDERED); if (!$this->options['autofree'] || $row != null) { $this->freeResult($result); } @@ -1792,7 +1734,7 @@ // {{{ fetchRow() /** - * Fetch and return a row of data (it uses fetchInto for that) + * Fetch and return a row of data * * @param resource $result result identifier * @param int $fetchmode how the array data should be indexed @@ -1800,20 +1742,47 @@ * @return mixed data array on success, a MDB error on failure * @access public */ - function fetchRow($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) + function fetchRow($result, $fetchmode = MDB_FETCHMODE_DEFAULT) { - $row = $this->fetchInto($result, $fetchmode, $rownum); - if (!$this->options['autofree'] || $row != null) { + if (MDB::isError($this->endOfResult($result))) { $this->freeResult($result); + return null; } - return $row; + + $columns = $this->numCols($result); + if (MDB::isError($columns)) { + return $columns; + } + if ($fetchmode & MDB_FETCHMODE_ASSOC) { + $column_names = $this->getColumnNames($result); + if (MDB::isError($column_names)) { + return $column_names; + } + } + for($column = 0; $column < $columns; $column++) { + if (!$this->resultIsNull($result, $rownum, $column)) { + $result = $this->fetch($result, $rownum, $column); + if ($result == null) { + return null; + } + } + if (isset()) { + $array[$column_names[$column]] = $result; + } else { + $array[$column] = $result; + } + } + if (isset($this->results[$result]['types'])) { + $array = $this->datatype->convertResultRow($this, $result, $array); + } + return $array; } // }}} // {{{ fetchCol() /** - * Fetch and return a column of data (it uses fetchInto for that) + * Fetch and return a column of data (it uses fetchRow for that) * * @param resource $result result identifier * @param int $colnum the row number to fetch @@ -1825,12 +1794,12 @@ $fetchmode = is_numeric($colnum) ? MDB_FETCHMODE_ORDERED : MDB_FETCHMODE_ASSOC; $column = array(); $rownum = 0; - $row = $this->fetchInto($result, $fetchmode, $rownum); + $row = $this->fetchRow($result, $fetchmode, $rownum); if (is_array($row)) { if (isset($row[$colnum])) { $column[] = $row[$colnum]; ++$rownum; - while (is_array($row = $this->fetchInto($result, $fetchmode, $rownum))) { + while (is_array($row = $this->fetchRow($result, $fetchmode, $rownum))) { $column[] = $row[$colnum]; ++$rownum; } @@ -1839,9 +1808,7 @@ return $this->raiseError(MDB_ERROR_TRUNCATED); } } - if (!$this->options['autofree']) { - $this->freeResult($result); - } + if (MDB::isError($row)) { return $row; } @@ -1852,7 +1819,7 @@ // {{{ fetchAll() /** - * Fetch and return a column of data (it uses fetchInto for that) + * Fetch and return a column of data (it uses fetchRow for that) * * @param resource $result result identifier * @param int $fetchmode how the array data should be indexed @@ -1882,7 +1849,7 @@ } $all = array(); $rownum = 0; - while (is_array($row = $this->fetchInto($result, $fetchmode, $rownum))) { + while (is_array($row = $this->fetchRow($result, $fetchmode, $rownum))) { if ($rekey) { if ($fetchmode & MDB_FETCHMODE_ASSOC) { $key = reset($row); @@ -1909,9 +1876,7 @@ } ++$rownum; } - if (!$this->options['autofree']) { - $this->freeResult($result); - } + if (MDB::isError($row)) { return $row; }
Index: pear/MDB/MDB/querysim.php diff -u pear/MDB/MDB/querysim.php:1.7 pear/MDB/MDB/querysim.php:1.8 --- pear/MDB/MDB/querysim.php:1.7 Thu Jul 24 06:53:01 2003 +++ pear/MDB/MDB/querysim.php Thu Jul 31 06:31:03 2003 @@ -60,7 +60,7 @@ // | please contact Alan Richmond. | // +----------------------------------------------------------------------+ // -// $Id: querysim.php,v 1.7 2003/07/24 10:53:01 lsmith Exp $ +// $Id: querysim.php,v 1.8 2003/07/31 10:31:03 lsmith Exp $ // /* @@ -82,7 +82,7 @@ <history author="Alan Richmond" email="arichmond@bigfoot.com" type="Create" date="10-July-2002"> Rewrote in PHP as an extention to the PEAR DB API. Functions supported: - connect, disconnect, query, fetchRow, fetchInto, freeResult, + connect, disconnect, query, fetchRow, freeResult, numCols, numRows, getSpecialQuery David Huyck (bombusbee.com) added ability to escape special characters (i.e., delimiters) using a '\'. @@ -140,7 +140,7 @@ Ported to PEAR MDB. Methods supported: connect, query, getColumnNames, numCols, endOfResult, fetch, - numRows, freeResult, fetchInto, nextResult, setLimit + numRows, freeResult, fetchRow, nextResult, setLimit (inherited). </history> <history @@ -716,7 +716,7 @@ } // }}} - // {{{ fetchInto() + // {{{ fetchRow() /** * Fetch a row and return data in an array. @@ -727,7 +727,7 @@ * @return mixed data array or null on success, a MDB error on failure * @access public */ - function fetchInto(&$result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) + function fetchRow(&$result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) { $result_link = $this->_querySimSignature($result); //if specific rownum request @@ -753,6 +753,9 @@ $arraytemp[$result[0][$key]] = $value; } $array = $arraytemp; + } + if (isset($this->results[$result]['types'])) { + $array = $this->datatype->convertResultRow($this, $result, $array); } return $array; } Index: pear/MDB/MDB/pgsql.php diff -u pear/MDB/MDB/pgsql.php:1.63 pear/MDB/MDB/pgsql.php:1.64 --- pear/MDB/MDB/pgsql.php:1.63 Thu Jul 24 06:55:13 2003 +++ pear/MDB/MDB/pgsql.php Thu Jul 31 06:31:03 2003 @@ -42,7 +42,7 @@ // | Author: Paul Cooper <pgc@ucecom.com> | // +----------------------------------------------------------------------+ // -// $Id: pgsql.php,v 1.63 2003/07/24 10:55:13 lsmith Exp $ +// $Id: pgsql.php,v 1.64 2003/07/31 10:31:03 lsmith Exp $ require_once 'MDB/Common.php'; @@ -483,7 +483,7 @@ $this->affected_rows = @pg_cmdtuples($result); return MDB_OK; } elseif (preg_match('/^\s*\(?\s*SELECT\s+/si', $query) && !preg_match('/^\s*\(?\s*SELECT\s+INTO\s/si', $query)) { - $this->highest_fetched_row[$result] = -1; + $this->results[$result]['highest_fetched_row'] = -1; if ($types != null) { if (!is_array($types)) { $types = array($types); @@ -519,17 +519,17 @@ */ function getColumnNames($result) { - if (!isset($this->highest_fetched_row[$result])) { + if (!isset($this->results[$result]['highest_fetched_row'])) { return $this->raiseError(MDB_ERROR, null, null, 'Get Column Names: specified an nonexistant result set'); } - if (!isset($this->columns[$result])) { - $this->columns[$result] = array(); + if (!isset($this->results[$result]['columns'])) { + $this->results[$result]['columns'] = array(); $columns = pg_numfields($result); for($column = 0; $column < $columns; $column++) { - $this->columns[$result][strtolower(pg_fieldname($result, $column))] = $column; + $this->results[$result]['columns'][strtolower(pg_fieldname($result, $column))] = $column; } } - return $this->columns[$result]; + return $this->results[$result]['columns']; } // }}} @@ -545,7 +545,7 @@ */ function numCols($result) { - if (!isset($this->highest_fetched_row[$result])) { + if (!isset($this->results[$result]['highest_fetched_row'])) { return $this->raiseError(MDB_ERROR, null, null, 'numCols: specified an nonexistant result set'); } return pg_numfields($result); @@ -563,10 +563,10 @@ */ function endOfResult($result) { - if (!isset($this->highest_fetched_row[$result])) { + if (!isset($this->results[$result]['highest_fetched_row'])) { return $this->RaiseError(MDB_ERROR, null, null, 'End of result attempted to check the end of an unknown result'); } - return $this->highest_fetched_row[$result] >= $this->numRows($result) - 1; + return $this->results[$result]['highest_fetched_row'] >= $this->numRows($result) - 1; } // }}} @@ -584,7 +584,7 @@ */ function resultIsNull($result, $row, $field) { - $this->highest_fetched_row[$result] = max($this->highest_fetched_row[$result], $row); + $this->results[$result]['highest_fetched_row'] = max($this->results[$result]['highest_fetched_row'], $row); return @pg_FieldIsNull($result, $row, $field); } @@ -615,14 +615,14 @@ */ function freeResult($result) { - if (isset($this->highest_fetched_row[$result])) { - unset($this->highest_fetched_row[$result]); + if (isset($this->results[$result]['highest_fetched_row'])) { + unset($this->results[$result]['highest_fetched_row']); } - if (isset($this->columns[$result])) { - unset($this->columns[$result]); + if (isset($this->results[$result]['columns'])) { + unset($this->results[$result]['columns']); } - if (isset($this->result_types[$result])) { - unset($this->result_types[$result]); + if (isset($this->results[$result]['types'])) { + unset($this->results[$result]['types']); } return pg_freeresult($result); } @@ -662,9 +662,9 @@ if (MDB::isError($result)) { return $this->raiseError($result); } - $arr = $this->fetchInto($result, MDB_FETCHMODE_ORDERED); + $next_id = $this->fetchOne($result, MDB_FETCHMODE_ORDERED); $this->freeResult($result); - return $arr[0]; + return $next_id; } // }}} @@ -691,7 +691,7 @@ // }}} - // {{{ fetchInto() + // {{{ fetchRow() /** * Fetch a row and return data in an array. @@ -702,13 +702,13 @@ * @return mixed data array or null on success, a MDB error on failure * @access public */ - function fetchInto($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) + function fetchRow($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) { if ($rownum == null) { - ++$this->highest_fetched_row[$result]; - $rownum = $this->highest_fetched_row[$result]; + ++$this->results[$result]['highest_fetched_row']; + $rownum = $this->results[$result]['highest_fetched_row']; } else { - $this->highest_fetched_row[$result] = max($this->highest_fetched_row[$result], $rownum); + $this->results[$result]['highest_fetched_row'] = max($this->results[$result]['highest_fetched_row'], $rownum); } if ($rownum + 1 > $this->numRows($result)) { return null; @@ -731,8 +731,8 @@ } return $this->pgsqlRaiseError($errno); } - if (isset($this->result_types[$result])) { - $array = $this->convertResultRow($result, $array); + if (isset($this->results[$result]['types'])) { + $array = $this->datatype->convertResultRow($this, $result, $array); } return $array; } Index: pear/MDB/MDB/oci8.php diff -u pear/MDB/MDB/oci8.php:1.22 pear/MDB/MDB/oci8.php:1.23 --- pear/MDB/MDB/oci8.php:1.22 Thu Jul 24 06:55:13 2003 +++ pear/MDB/MDB/oci8.php Thu Jul 31 06:31:03 2003 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ -// $Id: oci8.php,v 1.22 2003/07/24 10:55:13 lsmith Exp $ +// $Id: oci8.php,v 1.23 2003/07/31 10:31:03 lsmith Exp $ require_once 'MDB/Common.php'; @@ -738,8 +738,8 @@ if (MDB::isError($column = $this->_getColumn($result, $field))) { return $column; } - if (MDB::isError($fetchinto = $this->fetchInto($result, MDB_FETCHMODE_ORDERED, $row))) { - return $fetchInto; + if (MDB::isError($fetchrow = $this->fetchRow($result, MDB_FETCHMODE_ORDERED, $row))) { + return $fetchrow; } $this->highest_fetched_row[$result_value] = max($this->highest_fetched_row[$result_value], $row); return !isset($this->results[$result_value][$row][$column]); @@ -805,8 +805,8 @@ return $this->raiseError(MDB_ERROR, null, null, 'Free result: attemped to free an unknown query result'); } - if (isset($this->highest_fetched_row[$result])) { - unset($this->highest_fetched_row[$result]); + if (isset($this->results[$result])) { + unset($this->results[$result]); } if (isset($this->row_buffer[$result_value])) { unset($this->row_buffer[$result_value]); @@ -820,15 +820,9 @@ if (isset($this->results[$result_value])) { unset($this->results[$result_value]); } - if (isset($this->columns[$result])) { - unset($this->columns[$result]); - } if (isset($this->rows[$result_value])) { unset($this->rows[$result_value]); } - if (isset($this->result_types[$result])) { - unset($this->result_types[$result]); - } return @OCIFreeCursor($result); } @@ -857,7 +851,7 @@ } // }}} - // {{{ fetchInto() + // {{{ fetchRow() /** * Fetch a row and insert the data into an existing array. @@ -868,7 +862,7 @@ * @return int data array on success, a MDB error on failure * @access public */ - function fetchInto($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) + function fetchRow($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) { $result_value = intval($result); if (!isset($this->current_row[$result_value])) { @@ -918,8 +912,8 @@ $result_value = intval($result); $array = $this->results[$result_value][$rownum]; $this->highest_fetched_row[$result_value] = max($this->highest_fetched_row[$result_value], $rownum); - if (isset($this->result_types[$result])) { - $array = $this->convertResultRow($result, $array); + if (isset($this->results[$result]['types'])) { + $array = $this->datatype->convertResultRow($this, $result, $array); } return $array; } Index: pear/MDB/MDB/mysql.php diff -u pear/MDB/MDB/mysql.php:1.81 pear/MDB/MDB/mysql.php:1.82 --- pear/MDB/MDB/mysql.php:1.81 Thu Jul 24 06:55:13 2003 +++ pear/MDB/MDB/mysql.php Thu Jul 31 06:31:03 2003 @@ -43,7 +43,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.81 2003/07/24 10:55:13 lsmith Exp $ +// $Id: mysql.php,v 1.82 2003/07/31 10:31:03 lsmith Exp $ // require_once 'MDB/Common.php'; @@ -450,7 +450,7 @@ $this->affected_rows = mysql_affected_rows($this->connection); return MDB_OK; } else { - $this->highest_fetched_row[$result] = -1; + $this->results[$result]['highest_fetched_row'] = -1; if ($types != null) { if (!is_array($types)) { $types = array($types); @@ -702,11 +702,11 @@ */ function endOfResult($result) { - if (!isset($this->highest_fetched_row[$result])) { + if (!isset($this->results[$result]['highest_fetched_row'])) { return $this->raiseError(MDB_ERROR, null, null, 'End of result: attempted to check the end of an unknown result'); } - return $this->highest_fetched_row[$result] >= $this->numRows($result)-1; + return $this->results[$result]['highest_fetched_row'] >= $this->numRows($result)-1; } // }}} @@ -736,14 +736,8 @@ */ function freeResult($result) { - if (isset($this->highest_fetched_row[$result])) { - unset($this->highest_fetched_row[$result]); - } - if (isset($this->columns[$result])) { - unset($this->columns[$result]); - } - if (isset($this->result_types[$result])) { - unset($this->result_types[$result]); + if (isset($this->results[$result])) { + unset($this->results[$result]); } return mysql_free_result($result); } @@ -794,7 +788,7 @@ } // }}} - // {{{ fetchInto() + // {{{ fetchRow() /** * Fetch a row and insert the data into an existing array. @@ -805,15 +799,15 @@ * @return int data array on success, a MDB error on failure * @access public */ - function fetchInto($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) + function fetchRow($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) { if ($rownum == null) { - ++$this->highest_fetched_row[$result]; + ++$this->results[$result]['highest_fetched_row']; } else { if (!@mysql_data_seek($result, $rownum)) { return null; } - $this->highest_fetched_row[$result] = max($this->highest_fetched_row[$result], $rownum); + $this->results[$result]['highest_fetched_row'] = max($this->results[$result]['highest_fetched_row'], $rownum); } if ($fetchmode == MDB_FETCHMODE_DEFAULT) { $fetchmode = $this->fetchmode; @@ -833,8 +827,8 @@ } return $this->mysqlRaiseError($errno); } - if (isset($this->result_types[$result])) { - $array = $this->convertResultRow($result, $array); + if (isset($this->results[$result]['types'])) { + $array = $this->datatype->convertResultRow($this, $result, $array); } return $array; } Index: pear/MDB/MDB/mssql.php diff -u pear/MDB/MDB/mssql.php:1.7 pear/MDB/MDB/mssql.php:1.8 --- pear/MDB/MDB/mssql.php:1.7 Thu Jul 24 06:55:13 2003 +++ pear/MDB/MDB/mssql.php Thu Jul 31 06:31:03 2003 @@ -43,7 +43,7 @@ // | Author: Frank M. Kromann <frank@kromann.info> | // +----------------------------------------------------------------------+ // -// $Id: mssql.php,v 1.7 2003/07/24 10:55:13 lsmith Exp $ +// $Id: mssql.php,v 1.8 2003/07/31 10:31:03 lsmith Exp $ // require_once 'MDB/Common.php'; @@ -417,7 +417,7 @@ $this->affected_rows = mssql_affected_rows($this->connection); return MDB_OK; } else { - $this->highest_fetched_row[$result] = -1; + $this->results[$result]['highest_fetched_row'] = -1; if ($types != null) { if (!is_array($types)) { $types = array($types); @@ -503,11 +503,11 @@ */ function endOfResult($result) { - if (!isset($this->highest_fetched_row[$result])) { + if (!isset($this->results[$result]['highest_fetched_row'])) { return $this->raiseError(MDB_ERROR, null, null, 'End of result: attempted to check the end of an unknown result'); } - return $this->highest_fetched_row[$result] >= $this->numRows($result)-1; + return $this->results[$result]['highest_fetched_row'] >= $this->numRows($result)-1; } // }}} @@ -543,14 +543,8 @@ if (isset($this->ranges[$result])) { unset($this->ranges[$result]); } - if (isset($this->highest_fetched_row[$result])) { - unset($this->highest_fetched_row[$result]); - } - if (isset($this->columns[$result])) { - unset($this->columns[$result]); - } - if (isset($this->result_types[$result])) { - unset($this->result_types[$result]); + if (isset($this->results[$result])) { + unset($this->results[$result]); } return mssql_free_result($result); } @@ -620,7 +614,7 @@ } // }}} - // {{{ fetchInto() + // {{{ fetchRow() /** * Fetch a row and insert the data into an existing array. @@ -631,15 +625,15 @@ * @return int data array on success, a MDB error on failure * @access public */ - function fetchInto($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) + function fetchRow($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) { if ($rownum == null) { - ++$this->highest_fetched_row[$result]; + ++$this->results[$result]['highest_fetched_row']; } else { if (!@mssql_data_seek($result, $rownum)) { return null; } - $this->highest_fetched_row[$result] = max($this->highest_fetched_row[$result], $rownum); + $this->results[$result]['highest_fetched_row'] = max($this->results[$result]['highest_fetched_row'], $rownum); } if ($fetchmode == MDB_FETCHMODE_DEFAULT) { $fetchmode = $this->fetchmode; @@ -659,8 +653,8 @@ } return $this->mssqlRaiseError($errno); } - if (isset($this->result_types[$result])) { - $array = $this->convertResultRow($result, $array); + if (isset($this->results[$result]['types'])) { + $array = $this->datatype->convertResultRow($this, $result, $array); } return $array; } Index: pear/MDB/MDB/ibase.php diff -u pear/MDB/MDB/ibase.php:1.11 pear/MDB/MDB/ibase.php:1.12 --- pear/MDB/MDB/ibase.php:1.11 Thu Jul 24 06:55:13 2003 +++ pear/MDB/MDB/ibase.php Thu Jul 31 06:31:03 2003 @@ -42,7 +42,7 @@ // | Author: Lorenzo Alberton <l.alberton@quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.11 2003/07/24 10:55:13 lsmith Exp $ +// $Id: ibase.php,v 1.12 2003/07/31 10:31:03 lsmith Exp $ require_once 'MDB/Common.php'; @@ -664,18 +664,18 @@ //return 1; /* - if (!isset($this->highest_fetched_row[$result])) { + if (!isset($this->results[$result]['highest_fetched_row'])) { return $this->raiseError(MDB_ERROR, null, null, 'Get Column Names: specified an nonexistant result set'); } - if (!isset($this->columns[$result])) { - $this->columns[$result] = array(); + if (!isset($this->results[$result]['columns'])) { + $this->results[$result]['columns'] = array(); $columns = ibase_num_fields($result); for ($column = 0; $column < $columns; $column++) { $_fieldInfo = ibase_field_info($result, $column); - $this->columns[$result][strtolower($_fieldInfo['name'])] = $column; + $this->results[$result]['columns'][strtolower($_fieldInfo['name'])] = $column; } } - return $this->columns[$result]; + return $this->results[$result]['columns']; */ } @@ -760,7 +760,7 @@ } // }}} - // {{{ fetchInto() + // {{{ fetchRow() /** * Fetch a row and return data in an array. @@ -771,27 +771,7 @@ * @return mixed data array or null on success, a MDB error on failure * @access public */ - function fetchInto($result, $fetchmode=MDB_FETCHMODE_DEFAULT, $rownum=null) - { - if (MDB::isError($err = $this->fetchResultRow($result, $rownum))) { - //echo '<span style="background-color:red">fetchInto ERROR!</span>'; - return $err; - } - $result_value = intval($result); - - //Should I do this? Why default value is null and not 0? - if ($rownum === null) { - $rownum = 0; - } - $array = $this->results[$result_value][$rownum]; - $this->highest_fetched_row[$result_value] = max($this->highest_fetched_row[$result_value], $rownum); - return $this->convertResultRow($result, $array); - } - - // }}} - // {{{ fetchResultRow() - - function fetchResultRow($result, $rownum = null) + function fetchRow($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) { //should I do this? Why $rownum is null by default and not 0? if (is_null($rownum)) { @@ -830,9 +810,14 @@ $this->results[$result_value][$this->current_row[$result_value]+1][$key] = rtrim($valueWithSpace); } } + } + $array = $this->results[$result_value][$rownum]; + $this->highest_fetched_row[$result_value] = max($this->highest_fetched_row[$result_value], $rownum); + if (isset($this->results[$result]['types'])) { + $array = $this->datatype->convertResultRow($this, $result, $array); } - return MDB_OK; + return $array; } // }}} @@ -895,8 +880,8 @@ return $this->raiseError(MDB_ERROR, null, null, 'Free result: attemped to free an unknown query result'); } - if (isset($this->highest_fetched_row[$result])) { - unset($this->highest_fetched_row[$result]); + if (isset($this->results[$result])) { + unset($this->results[$result]); } if (isset($this->row_buffer[$result_value])) { unset($this->row_buffer[$result_value]); @@ -910,14 +895,8 @@ if (isset($this->results[$result_value])) { unset($this->results[$result_value]); } - if (isset($this->columns[$result])) { - unset($this->columns[$result]); - } if (isset($this->rows[$result_value])) { unset($this->rows[$result_value]); - } - if (isset($this->result_types[$result])) { - unset($this->result_types[$result]); } if (is_resource($result)) { return @ibase_free_result($result); Index: pear/MDB/MDB/fbsql.php diff -u pear/MDB/MDB/fbsql.php:1.17 pear/MDB/MDB/fbsql.php:1.18 --- pear/MDB/MDB/fbsql.php:1.17 Thu Jul 24 06:55:13 2003 +++ pear/MDB/MDB/fbsql.php Thu Jul 31 06:31:03 2003 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@dybnet.de> | // +----------------------------------------------------------------------+ // -// $Id: fbsql.php,v 1.17 2003/07/24 10:55:13 lsmith Exp $ +// $Id: fbsql.php,v 1.18 2003/07/31 10:31:03 lsmith Exp $ // require_once 'MDB/Common.php'; @@ -417,7 +417,7 @@ $this->affected_rows = fbsql_affected_rows($this->connection); return MDB_OK; } else { - $this->highest_fetched_row[$result] = -1; + $this->results[$result]['highest_fetched_row'] = -1; if ($types != null) { if (!is_array($types)) { $types = array($types); @@ -501,11 +501,11 @@ */ function endOfResult($result) { - if (!isset($this->highest_fetched_row[$result])) { + if (!isset($this->results[$result]['highest_fetched_row'])) { return $this->raiseError(MDB_ERROR, null, null, 'End of result: attempted to check the end of an unknown result'); } - return $this->highest_fetched_row[$result] >= $this->numRows($result)-1; + return $this->results[$result]['highest_fetched_row'] >= $this->numRows($result)-1; } // }}} @@ -535,14 +535,8 @@ */ function freeResult($result) { - if (isset($this->highest_fetched_row[$result])) { - unset($this->highest_fetched_row[$result]); - } - if (isset($this->columns[$result])) { - unset($this->columns[$result]); - } - if (isset($this->result_types[$result])) { - unset($this->result_types[$result]); + if (isset($this->results[$result])) { + unset($this->results[$result]); } return fbsql_free_result($result); } @@ -613,7 +607,7 @@ } // }}} - // {{{ fetchInto() + // {{{ fetchRow() /** * Fetch a row and return data in an array. @@ -624,15 +618,15 @@ * @return mixed data array or null on success, a MDB error on failure * @access public */ - function fetchInto($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) + function fetchRow($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) { if ($rownum == null) { - ++$this->highest_fetched_row[$result]; + ++$this->results[$result]['highest_fetched_row']; } else { if (!@fbsql_data_seek($result, $rownum)) { return null; } - $this->highest_fetched_row[$result] = max($this->highest_fetched_row[$result], $rownum); + $this->results[$result]['highest_fetched_row'] = max($this->results[$result]['highest_fetched_row'], $rownum); } if ($fetchmode == MDB_FETCHMODE_DEFAULT) { $fetchmode = $this->fetchmode; @@ -652,8 +646,8 @@ } return $this->fbsqlRaiseError($errno); } - if (isset($this->result_types[$result])) { - $array = $this->convertResultRow($result, $array); + if (isset($this->results[$result]['types'])) { + $array = $this->datatype->convertResultRow($this, $result, $array); } return $array; } Index: pear/MDB/MDB/Common.php diff -u pear/MDB/MDB/Common.php:1.116 pear/MDB/MDB/Common.php:1.117 --- pear/MDB/MDB/Common.php:1.116 Sun Jul 27 05:32:06 2003 +++ pear/MDB/MDB/Common.php Thu Jul 31 06:31:03 2003 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@backendmedia.com> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.116 2003/07/27 09:32:06 quipo Exp $ +// $Id: Common.php,v 1.117 2003/07/31 10:31:03 lsmith Exp $ /** * @package MDB @@ -125,12 +125,12 @@ /** * $options["persistent"] -> boolean persistent connection true|false? * $options["debug"] -> integer numeric debug level - * $options["autofree"] -> boolean - * $options["lob_buffer_length"] -> integer LOB buffer length - * $options["log_line_break"] -> string line-break format - * $options["seqname_format"] -> string pattern for sequence name - * $options["includelob"] -> boolean - * $options["includemanager"] -> boolean + * $options["autofree"] -> boolean + * $options["lob_buffer_length"] -> integer LOB buffer length + * $options["log_line_break"] -> string line-break format + * $options["seqname_format"] -> string pattern for sequence name + * $options["includelob"] -> boolean + * $options["includemanager"] -> boolean * $options["UseTransactions"] -> boolean * @var array * @access private @@ -1404,7 +1404,7 @@ * Define the list of types to be associated with the columns of a given * result set. * - * This function may be called before invoking fetchInto(), fetchOne(), + * This function may be called before invoking fetchOne(), * fetchRow(), fetchCol() and fetchAll() so that the necessary data type * conversions are performed on the data to be retrieved by them. If this * function is not called, the type of all result set columns is assumed @@ -1709,68 +1709,10 @@ } // }}} - // {{{ fetchInto() - - /** - * Fetch a row and return data in an array. - * - * @param resource $result result identifier - * @param int $fetchmode ignored - * @param int $rownum the row number to fetch - * @return mixed data array or null on success, a MDB error on failure - * @access public - */ - function fetchInto($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) - { - if (MDB::isError($result)) { - return $this->raiseError(MDB_ERROR_NEED_MORE_DATA, null, null, - 'Fetch field: it was not specified a valid result set'); - } - if (MDB::isError($this->endOfResult($result))) { - $this->freeResult($result); - $result = $this->raiseError(MDB_ERROR_NEED_MORE_DATA, null, null, - 'Fetch field: result set is empty'); - } - if ($rownum == null) { - ++$this->highest_fetched_row[$result]; - $rownum = $this->highest_fetched_row[$result]; - } else { - $this->highest_fetched_row[$result] = max($this->highest_fetched_row[$result], $row); - } - if ($rownum + 1 > $this->numRows($result)) { - return null; - } - $columns = $this->numCols($result); - if (MDB::isError($columns)) { - return $columns; - } - for($column = 0; $column < $columns; $column++) { - if (!$this->resultIsNull($result, $rownum, $column)) { - $result = $this->fetch($result, $rownum, $column); - if (MDB::isError($result)) { - if ($result->getMessage() == '') { - if ($this->options['autofree']) { - $this->freeResult($result); - } - return null; - } else { - return $result; - } - } - } - $array[$column] = $result; - } - if (isset($this->result_types[$result])) { - $array = $this->convertResultRow($result, $array); - } - return $array; - } - - // }}} // {{{ fetchOne() /** - * Fetch and return a field of data (it uses fetchInto for that) + * Fetch and return a field of data (it uses fetchRow for that) * * @param resource $result result identifier * @return mixed data on success, a MDB error on failure @@ -1778,7 +1720,7 @@ */ function fetchOne($result) { - $row = $this->fetchInto($result, MDB_FETCHMODE_ORDERED); + $row = $this->fetchRow($result, MDB_FETCHMODE_ORDERED); if (!$this->options['autofree'] || $row != null) { $this->freeResult($result); } @@ -1792,7 +1734,7 @@ // {{{ fetchRow() /** - * Fetch and return a row of data (it uses fetchInto for that) + * Fetch and return a row of data * * @param resource $result result identifier * @param int $fetchmode how the array data should be indexed @@ -1800,20 +1742,47 @@ * @return mixed data array on success, a MDB error on failure * @access public */ - function fetchRow($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = null) + function fetchRow($result, $fetchmode = MDB_FETCHMODE_DEFAULT) { - $row = $this->fetchInto($result, $fetchmode, $rownum); - if (!$this->options['autofree'] || $row != null) { + if (MDB::isError($this->endOfResult($result))) { $this->freeResult($result); + return null; } - return $row; + + $columns = $this->numCols($result); + if (MDB::isError($columns)) { + return $columns; + } + if ($fetchmode & MDB_FETCHMODE_ASSOC) { + $column_names = $this->getColumnNames($result); + if (MDB::isError($column_names)) { + return $column_names; + } + } + for($column = 0; $column < $columns; $column++) { + if (!$this->resultIsNull($result, $rownum, $column)) { + $result = $this->fetch($result, $rownum, $column); + if ($result == null) { + return null; + } + } + if (isset()) { + $array[$column_names[$column]] = $result; + } else { + $array[$column] = $result; + } + } + if (isset($this->results[$result]['types'])) { + $array = $this->datatype->convertResultRow($this, $result, $array); + } + return $array; } // }}} // {{{ fetchCol() /** - * Fetch and return a column of data (it uses fetchInto for that) + * Fetch and return a column of data (it uses fetchRow for that) * * @param resource $result result identifier * @param int $colnum the row number to fetch @@ -1825,12 +1794,12 @@ $fetchmode = is_numeric($colnum) ? MDB_FETCHMODE_ORDERED : MDB_FETCHMODE_ASSOC; $column = array(); $rownum = 0; - $row = $this->fetchInto($result, $fetchmode, $rownum); + $row = $this->fetchRow($result, $fetchmode, $rownum); if (is_array($row)) { if (isset($row[$colnum])) { $column[] = $row[$colnum]; ++$rownum; - while (is_array($row = $this->fetchInto($result, $fetchmode, $rownum))) { + while (is_array($row = $this->fetchRow($result, $fetchmode, $rownum))) { $column[] = $row[$colnum]; ++$rownum; } @@ -1839,9 +1808,7 @@ return $this->raiseError(MDB_ERROR_TRUNCATED); } } - if (!$this->options['autofree']) { - $this->freeResult($result); - } + if (MDB::isError($row)) { return $row; } @@ -1852,7 +1819,7 @@ // {{{ fetchAll() /** - * Fetch and return a column of data (it uses fetchInto for that) + * Fetch and return a column of data (it uses fetchRow for that) * * @param resource $result result identifier * @param int $fetchmode how the array data should be indexed @@ -1882,7 +1849,7 @@ } $all = array(); $rownum = 0; - while (is_array($row = $this->fetchInto($result, $fetchmode, $rownum))) { + while (is_array($row = $this->fetchRow($result, $fetchmode, $rownum))) { if ($rekey) { if ($fetchmode & MDB_FETCHMODE_ASSOC) { $key = reset($row); @@ -1909,9 +1876,7 @@ } ++$rownum; } - if (!$this->options['autofree']) { - $this->freeResult($result); - } + if (MDB::isError($row)) { return $row; }