oci8.php Patch
| From: | Paul Edmondson | Date: | Thu, 25 Oct 2001 15:56:08 +0000 |
| Subject: | oci8.php Patch | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-2377@lists.php.net to get a copy of this message | ||
Hi there,
I've been using the PEAR libs that come with PHP 4.0.6 and have found a couple
of problems.
The first is that when using DB_FETCHMODE_ASSOC the key names returned are all
in uppercase. Now this does not seem much of a problem to begin with. However
when writing or porting applications that are database independent this
becomes an issue. The fix for this is quite dirty but does however work for
some situations by creating copies of the data in the hash with lowercase
names.
The second fix is very important as the numRows() function did not work all
that well. The problem is that if you query for a result set with more than
one column in, the reissued count query does not work. Also there was a problem
if the query was spread over multiple lines.
Below is the patch to fix these problems.
<PATCH>
*** oci8.php Thu Apr 19 03:37:47 2001
--- /usr/local/lib/php/DB/oci8.php Thu Oct 25 16:45:54 2001
***************
*** 202,207 ****
--- 202,217 ----
}
if ($fetchmode & DB_FETCHMODE_ASSOC) {
$moredata = @OCIFetchInto($result,$arr,OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS);
+ /**
+ * When using 'AS' clauses Oracle by default uppercases the field names.+
* This create a copy of the fields with lowercase characters when
+ * DB_FETCHMODE_ASSOC is used.
+ */
+ if ($moredata) {
+ foreach ($arr as $key => $val) {
+ $arr[strtolower($key)] = $val;
+ }
+ }
} else {
$moredata = @OCIFetchInto($result,$arr,OCI_RETURN_NULLS+OCI_RETURN_LOBS);
}
***************
*** 243,249 ****
// emulate numRows for Oracle. yuck.
if ($this->options['optimize'] == 'portability' &&
$result === $this->last_stmt) {
! $countquery = preg_replace('/^\s*SELECT\s+(.*)\s+FROM\s+/i',
'SELECT COUNT(\1) FROM ',
$this->last_query);
$save_query = $this->last_query;
--- 253,259 ----
// emulate numRows for Oracle. yuck.
if ($this->options['optimize'] == 'portability' &&
$result === $this->last_stmt) {
! $countquery = preg_replace('/^\s*SELECT\s+(.*?)[,\s].*\s+FROM\s+/is',
'SELECT COUNT(\1) FROM ',
$this->last_query);
$save_query = $this->last_query;
</PATCH>
------------------------------------------------------------
Paul Edmondson, Software Engineer
Yospace: Creating Value for Wireless
7 The Courtyard, High Street, Staines, UK, TW18 4DR
Tel: +44 1784 466388
Fax: +44 1784 466387
http://www.yospace.com