From 2dc621fd82000ccb968b4e747d793dde98f6749b Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 15 Feb 2017 12:02:41 -0800 Subject: [PATCH] Move ORAResult to /db Change-Id: I9be89faef693343a4071d7c29b6ca0c021e7fb63 --- autoload.php | 2 +- includes/db/DatabaseOracle.php | 107 ---------------------------------------- includes/db/ORAResult.php | 108 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 108 deletions(-) create mode 100644 includes/db/ORAResult.php diff --git a/autoload.php b/autoload.php index 35ccf8edeb7..b21310e04cd 100644 --- a/autoload.php +++ b/autoload.php @@ -1003,7 +1003,7 @@ $wgAutoloadLocalClasses = [ 'NumericUppercaseCollation' => __DIR__ . '/includes/collation/NumericUppercaseCollation.php', 'OOUIHTMLForm' => __DIR__ . '/includes/htmlform/OOUIHTMLForm.php', 'ORAField' => __DIR__ . '/includes/db/ORAField.php', - 'ORAResult' => __DIR__ . '/includes/db/DatabaseOracle.php', + 'ORAResult' => __DIR__ . '/includes/db/ORAResult.php', 'ObjectCache' => __DIR__ . '/includes/objectcache/ObjectCache.php', 'ObjectFactory' => __DIR__ . '/includes/libs/ObjectFactory.php', 'OldChangesList' => __DIR__ . '/includes/changes/OldChangesList.php', diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index 4aab8111c2c..344aa3d939c 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -23,113 +23,6 @@ use Wikimedia\Rdbms\Blob; /** - * The oci8 extension is fairly weak and doesn't support oci_num_rows, among - * other things. We use a wrapper class to handle that and other - * Oracle-specific bits, like converting column names back to lowercase. - * @ingroup Database - */ -class ORAResult { - private $rows; - private $cursor; - private $nrows; - - private $columns = []; - - private function array_unique_md( $array_in ) { - $array_out = []; - $array_hashes = []; - - foreach ( $array_in as $item ) { - $hash = md5( serialize( $item ) ); - if ( !isset( $array_hashes[$hash] ) ) { - $array_hashes[$hash] = $hash; - $array_out[] = $item; - } - } - - return $array_out; - } - - /** - * @param IDatabase $db - * @param resource $stmt A valid OCI statement identifier - * @param bool $unique - */ - function __construct( &$db, $stmt, $unique = false ) { - $this->db =& $db; - - $this->nrows = oci_fetch_all( $stmt, $this->rows, 0, -1, OCI_FETCHSTATEMENT_BY_ROW | OCI_NUM ); - if ( $this->nrows === false ) { - $e = oci_error( $stmt ); - $db->reportQueryError( $e['message'], $e['code'], '', __METHOD__ ); - $this->free(); - - return; - } - - if ( $unique ) { - $this->rows = $this->array_unique_md( $this->rows ); - $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; - oci_free_statement( $stmt ); - } - - public function free() { - unset( $this->db ); - } - - public function seek( $row ) { - $this->cursor = min( $row, $this->nrows ); - } - - public function numRows() { - return $this->nrows; - } - - public function numFields() { - return count( $this->columns ); - } - - public function fetchObject() { - if ( $this->cursor >= $this->nrows ) { - return false; - } - $row = $this->rows[$this->cursor++]; - $ret = new stdClass(); - foreach ( $row as $k => $v ) { - $lc = $this->columns[$k]; - $ret->$lc = $v; - } - - return $ret; - } - - public function fetchRow() { - if ( $this->cursor >= $this->nrows ) { - return false; - } - - $row = $this->rows[$this->cursor++]; - $ret = []; - foreach ( $row as $k => $v ) { - $lc = $this->columns[$k]; - $ret[$lc] = $v; - $ret[$k] = $v; - } - - return $ret; - } -} - -/** * @ingroup Database */ class DatabaseOracle extends Database { diff --git a/includes/db/ORAResult.php b/includes/db/ORAResult.php new file mode 100644 index 00000000000..07c6fc7cf88 --- /dev/null +++ b/includes/db/ORAResult.php @@ -0,0 +1,108 @@ +db =& $db; + + $this->nrows = oci_fetch_all( $stmt, $this->rows, 0, -1, OCI_FETCHSTATEMENT_BY_ROW | OCI_NUM ); + if ( $this->nrows === false ) { + $e = oci_error( $stmt ); + $db->reportQueryError( $e['message'], $e['code'], '', __METHOD__ ); + $this->free(); + + return; + } + + if ( $unique ) { + $this->rows = $this->array_unique_md( $this->rows ); + $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; + oci_free_statement( $stmt ); + } + + public function free() { + unset( $this->db ); + } + + public function seek( $row ) { + $this->cursor = min( $row, $this->nrows ); + } + + public function numRows() { + return $this->nrows; + } + + public function numFields() { + return count( $this->columns ); + } + + public function fetchObject() { + if ( $this->cursor >= $this->nrows ) { + return false; + } + $row = $this->rows[$this->cursor++]; + $ret = new stdClass(); + foreach ( $row as $k => $v ) { + $lc = $this->columns[$k]; + $ret->$lc = $v; + } + + return $ret; + } + + public function fetchRow() { + if ( $this->cursor >= $this->nrows ) { + return false; + } + + $row = $this->rows[$this->cursor++]; + $ret = []; + foreach ( $row as $k => $v ) { + $lc = $this->columns[$k]; + $ret[$lc] = $v; + $ret[$k] = $v; + } + + return $ret; + } +} -- 2.11.4.GIT