Home » Database » DB_DataObject » Bug #8876
Oracle session persist when using count() on an DB_DataObject instance
Details
| Submitted | 2006-10-06 14:21 UTC |
|---|---|
| From | renaud dot l at free dot fr |
| Assigned | alan_k |
| Status | Closed |
| Package | DB_DataObject |
| PHP Version | 5.1.1 |
| OS | windows, Solaris (5.9) |
| Roadmaps | (Not assigned) |
Comments
[2006-10-06 14:21 UTC] renaud dot l at free dot fr
Description:
------------
Using oracle 9i (on solaris) with oci8 and a tns name.
On windows with xampp 1.5.1 and custom php on solaris.
With or without oci8 persistent at true.
With or without DB or MDB2 driver.
Each time we using count() on an instance of DataObject we create a new oracle session which persist until apache is shutdown.
Test script:
---------------
$dbdoCal =& DB_DataObject::factory('calendrier');
$dbdoCal->whereAdd("CAL_DATE is not null");
$calCount = $dbdoCal->count();
$dbdoCal->free();
The oracle session created when we call the count() will not end until apache is shutdown.
In the count() method of DataObject we clone the current instance and then query the "select count".
function count($countWhat = false,$whereAddOnly = false)
{
...
$t = clone($this);
...
$result = &$_DB_DATAOBJECT['RESULTS'][$t->_DB_resultid];
$l = $result->fetchRow(DB_DATAOBJECT_FETCHMODE_ORDERED);
return (int) $l[0];
}
Workaround : applying free() on the $t instance let the session released as expected.
function count($countWhat = false,$whereAddOnly = false)
{
...
$t = clone($this);
...
$result = &$_DB_DATAOBJECT['RESULTS'][$t->_DB_resultid];
$l = $result->fetchRow(DB_DATAOBJECT_FETCHMODE_ORDERED);
// to let the db connection released with oci8 (only?)
$t->free();
return (int) $l[0];
}
Have we to $t->free() there ? A better place would be in the DataObject free() method (but $t must be a class attribute then).