Home » Database » DB » Bug #4388
[PATCH] DB Error if calling numRows() before tableInfo() (ORACLE)
Details
| Submitted | 2005-05-19 15:16 UTC |
|---|---|
| From | kori at atlas dot cz |
| Assigned | aharvey |
| Status | Closed |
| Package | DB |
| PHP Version | Irrelevant |
| OS | Windows 2000 |
| Roadmaps | (Not assigned) |
Comments
[2005-05-19 15:16 UTC] kori at atlas dot cz
Description:
------------
I found a minor bug in DB:numRows() method in file oci8.php.
There is an error 'DB Error: DB backend not capable' if calling method numRows() before tableInfo().
I think you forgot add 2 lines of code to numRows() method.
With my code It works as expected.
-- Michal
PEAR DB: Release: 1.7.6
Reproduce code:
---------------
$options = array('debug' => 2, 'portability' => DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_NUMROWS, 'persistent' => TRUE);
$dsn = "oci8://username:pass@ORACLE";
$db =& DB::connect($dsn, $options);
$res =& $db -> query('SELECT col1, col2 FROM table');
$count = $res -> numRows();
$info = $db -> tableInfo($res); //returns DB:Error but should be an array
print_r($info);
Expected result:
----------------
My solution:
function numRows($result)
{
// emulate numRows for Oracle. yuck.
if ($this->options['portability'] & DB_PORTABILITY_NUMROWS &&
$result === $this->last_stmt)
{
$countquery = 'SELECT COUNT(*) FROM ('.$this->last_query.')';
$save_query = $this->last_query;
$save_stmt = $this->last_stmt;
if (count($this->_data)) {
$smt = $this->prepare('SELECT COUNT(*) FROM ('.$this->last_query.')');
$count = $this->execute($smt, $this->_data);
} else {
$count =& $this->query($countquery);
}
if (DB::isError($count) ||
DB::isError($row = $count->fetchRow(DB_FETCHMODE_ORDERED)))
{
$this->last_query = $save_query;
$this->last_stmt = $save_stmt;
return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
// ----- THERE SHOULD BE THESE 2 LINES OF CODE
$this->last_query = $save_query;
$this->last_stmt = $save_stmt;
// ------------------
return $row[0];
}
return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
[2005-05-19 16:10 UTC] kori at atlas dot cz
I looked to older and probably similar bug #739 "oci8 numRows only works once for a result" and my "fix" solve this problem also (bad last statement resource id after calling numRows()).
...but maybe I'm wrong :-)
-- Michal
[2006-03-11 20:15 UTC] kori at atlas dot cz
I'm sorry, I'm not familiar with CVS :-( I can send you whole file by e-mail...
--Michal
[2006-03-30 20:19 UTC] aschapiro at gmail dot com
When you want to use DB_DataObject with oci8, how can you set the portability option into DB_PORTABILITY_NUMROWS ?
The solution Ive found is forcing that option to DB_PORTABILITY_NUMROWS at the beggining of oci8.php numRows method.
Is there a better way???
Thanks! Ariel Schapiro.