From 43e9d51b0ee996a28964764d9acdc93d0192b944 Mon Sep 17 00:00:00 2001 From: Jure Kajzer Date: Thu, 18 Nov 2010 13:17:16 +0000 Subject: [PATCH] * Oracle: prefetching column names in ORAResult so i can release statement after constructor. This fixes too many open cursors issue, importing of large sets now works. --- includes/db/DatabaseOracle.php | 59 +++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index 5fa9c8ef82..b1f34f06fe 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -30,8 +30,9 @@ class ORABlob { class ORAResult { private $rows; private $cursor; - private $stmt; private $nrows; + + private $columns = array(); private function array_unique_md( $array_in ) { $array_out = array(); @@ -63,12 +64,18 @@ class ORAResult { $this->nrows = count( $this->rows ); } + if ($this->nrows > 0) { + foreach ( $this->rows[0] as $k => $v ) { + $this->columns[$k] = strtolower( oci_field_name( $stmt, $k + 1 ) ); + } + } + $this->cursor = 0; - $this->stmt = $stmt; + oci_free_statement( $stmt ); } public function free() { - oci_free_statement( $this->stmt ); + unset($this->db); } public function seek( $row ) { @@ -80,7 +87,7 @@ class ORAResult { } public function numFields() { - return oci_num_fields( $this->stmt ); + return count($this->columns); } public function fetchObject() { @@ -90,7 +97,7 @@ class ORAResult { $row = $this->rows[$this->cursor++]; $ret = new stdClass(); foreach ( $row as $k => $v ) { - $lc = strtolower( oci_field_name( $this->stmt, $k + 1 ) ); + $lc = $this->columns[$k]; $ret->$lc = $v; } @@ -105,7 +112,7 @@ class ORAResult { $row = $this->rows[$this->cursor++]; $ret = array(); foreach ( $row as $k => $v ) { - $lc = strtolower( oci_field_name( $this->stmt, $k + 1 ) ); + $lc = $this->columns[$k]; $ret[$lc] = $v; $ret[$k] = $v; } @@ -349,43 +356,43 @@ class DatabaseOracle extends DatabaseBase { } function freeResult( $res ) { - if ( $res instanceof ORAResult ) { - $res->free(); - } else { - $res->result->free(); + if ( $res instanceof ResultWrapper ) { + $res = $res->result; } + + $res->free(); } function fetchObject( $res ) { - if ( $res instanceof ORAResult ) { - return $res->numRows(); - } else { - return $res->result->fetchObject(); + if ( $res instanceof ResultWrapper ) { + $res = $res->result; } + + return $res->fetchObject(); } function fetchRow( $res ) { - if ( $res instanceof ORAResult ) { - return $res->fetchRow(); - } else { - return $res->result->fetchRow(); + if ( $res instanceof ResultWrapper ) { + $res = $res->result; } + + return $res->fetchRow(); } function numRows( $res ) { - if ( $res instanceof ORAResult ) { - return $res->numRows(); - } else { - return $res->result->numRows(); + if ( $res instanceof ResultWrapper ) { + $res = $res->result; } + + return $res->numRows(); } function numFields( $res ) { - if ( $res instanceof ORAResult ) { - return $res->numFields(); - } else { - return $res->result->numFields(); + if ( $res instanceof ResultWrapper ) { + $res = $res->result; } + + return $res->numFields(); } function fieldName( $stmt, $n ) { -- 2.20.1