diff options
Diffstat (limited to 'includes/db/DatabaseOracle.php')
-rw-r--r-- | includes/db/DatabaseOracle.php | 76 |
1 files changed, 40 insertions, 36 deletions
diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index 7d8884fb..75b3550a 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -23,7 +23,7 @@ /** * 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 + * other things. We use a wrapper class to handle that and other * Oracle-specific bits, like converting column names back to lowercase. * @ingroup Database */ @@ -69,7 +69,7 @@ class ORAResult { $this->nrows = count( $this->rows ); } - if ($this->nrows > 0) { + if ( $this->nrows > 0 ) { foreach ( $this->rows[0] as $k => $v ) { $this->columns[$k] = strtolower( oci_field_name( $stmt, $k + 1 ) ); } @@ -80,7 +80,7 @@ class ORAResult { } public function free() { - unset($this->db); + unset( $this->db ); } public function seek( $row ) { @@ -92,7 +92,7 @@ class ORAResult { } public function numFields() { - return count($this->columns); + return count( $this->columns ); } public function fetchObject() { @@ -241,6 +241,11 @@ class DatabaseOracle extends DatabaseBase { /** * Usually aborts on failure + * @param string $server + * @param string $user + * @param string $password + * @param string $dbName + * @throws DBConnectionError * @return DatabaseBase|null */ function open( $server, $user, $password, $dbName ) { @@ -313,7 +318,7 @@ class DatabaseOracle extends DatabaseBase { protected function doQuery( $sql ) { wfDebug( "SQL: [$sql]\n" ); - if ( !mb_check_encoding( $sql ) ) { + if ( !StringUtils::isUtf8( $sql ) ) { throw new MWException( "SQL encoding is invalid\n$sql" ); } @@ -628,7 +633,7 @@ class DatabaseOracle extends DatabaseBase { } list( $startOpts, $useIndex, $tailOpts ) = $this->makeSelectOptions( $selectOptions ); if ( is_array( $srcTable ) ) { - $srcTable = implode( ',', array_map( array( &$this, 'tableName' ), $srcTable ) ); + $srcTable = implode( ',', array_map( array( &$this, 'tableName' ), $srcTable ) ); } else { $srcTable = $this->tableName( $srcTable ); } @@ -751,7 +756,7 @@ class DatabaseOracle extends DatabaseBase { function unionQueries( $sqls, $all ) { $glue = ' UNION ALL '; - return 'SELECT * ' . ( $all ? '':'/* UNION_UNIQUE */ ' ) . 'FROM (' . implode( $glue, $sqls ) . ')' ; + return 'SELECT * ' . ( $all ? '':'/* UNION_UNIQUE */ ' ) . 'FROM (' . implode( $glue, $sqls ) . ')'; } function wasDeadlock() { @@ -773,8 +778,8 @@ class DatabaseOracle extends DatabaseBase { function listTables( $prefix = null, $fname = 'DatabaseOracle::listTables' ) { $listWhere = ''; - if (!empty($prefix)) { - $listWhere = ' AND table_name LIKE \''.strtoupper($prefix).'%\''; + if ( !empty( $prefix ) ) { + $listWhere = ' AND table_name LIKE \'' . strtoupper( $prefix ) . '%\''; } $owner = strtoupper( $this->mDBname ); @@ -782,12 +787,12 @@ class DatabaseOracle extends DatabaseBase { // dirty code ... i know $endArray = array(); - $endArray[] = strtoupper($prefix.'MWUSER'); - $endArray[] = strtoupper($prefix.'PAGE'); - $endArray[] = strtoupper($prefix.'IMAGE'); + $endArray[] = strtoupper( $prefix . 'MWUSER' ); + $endArray[] = strtoupper( $prefix . 'PAGE' ); + $endArray[] = strtoupper( $prefix . 'IMAGE' ); $fixedOrderTabs = $endArray; - while (($row = $result->fetchRow()) !== false) { - if (!in_array($row['table_name'], $fixedOrderTabs)) + while ( ($row = $result->fetchRow()) !== false ) { + if ( !in_array( $row['table_name'], $fixedOrderTabs ) ) $endArray[] = $row['table_name']; } @@ -795,7 +800,7 @@ class DatabaseOracle extends DatabaseBase { } public function dropTable( $tableName, $fName = 'DatabaseOracle::dropTable' ) { - $tableName = $this->tableName($tableName); + $tableName = $this->tableName( $tableName ); if( !$this->tableExists( $tableName ) ) { return false; } @@ -841,7 +846,7 @@ class DatabaseOracle extends DatabaseBase { function getServerVersion() { //better version number, fallback on driver $rset = $this->doQuery( 'SELECT version FROM product_component_version WHERE UPPER(product) LIKE \'ORACLE DATABASE%\'' ); - if ( !( $row = $rset->fetchRow() ) ) { + if ( !( $row = $rset->fetchRow() ) ) { return oci_server_version( $this->mConn ); } return $row['version']; @@ -902,7 +907,7 @@ class DatabaseOracle extends DatabaseBase { $table = array_map( array( &$this, 'tableNameInternal' ), $table ); $tableWhere = 'IN ('; foreach( $table as &$singleTable ) { - $singleTable = $this->removeIdentifierQuotes($singleTable); + $singleTable = $this->removeIdentifierQuotes( $singleTable ); if ( isset( $this->mFieldInfoCache["$singleTable.$field"] ) ) { return $this->mFieldInfoCache["$singleTable.$field"]; } @@ -910,14 +915,14 @@ class DatabaseOracle extends DatabaseBase { } $tableWhere = rtrim( $tableWhere, ',' ) . ')'; } else { - $table = $this->removeIdentifierQuotes( $this->tableNameInternal( $table ) ); + $table = $this->removeIdentifierQuotes( $this->tableNameInternal( $table ) ); if ( isset( $this->mFieldInfoCache["$table.$field"] ) ) { return $this->mFieldInfoCache["$table.$field"]; } $tableWhere = '= \''.$table.'\''; } - $fieldInfoStmt = oci_parse( $this->mConn, 'SELECT * FROM wiki_field_info_full WHERE table_name '.$tableWhere.' and column_name = \''.$field.'\'' ); + $fieldInfoStmt = oci_parse( $this->mConn, 'SELECT * FROM wiki_field_info_full WHERE table_name ' . $tableWhere . ' and column_name = \'' . $field . '\'' ); if ( oci_execute( $fieldInfoStmt, $this->execFlags() ) === false ) { $e = oci_error( $fieldInfoStmt ); $this->reportQueryError( $e['message'], $e['code'], 'fieldInfo QUERY', __METHOD__ ); @@ -952,7 +957,7 @@ class DatabaseOracle extends DatabaseBase { if ( is_array( $table ) ) { throw new DBUnexpectedError( $this, 'DatabaseOracle::fieldInfo called with table array!' ); } - return $this->fieldInfoMulti ($table, $field); + return $this->fieldInfoMulti( $table, $field ); } protected function doBegin( $fname = 'DatabaseOracle::begin' ) { @@ -1061,7 +1066,7 @@ class DatabaseOracle extends DatabaseBase { if ( $db == null || $db == $this->mUser ) { return true; } - $sql = 'ALTER SESSION SET CURRENT_SCHEMA=' . strtoupper($db); + $sql = 'ALTER SESSION SET CURRENT_SCHEMA=' . strtoupper( $db ); $stmt = oci_parse( $this->mConn, $sql ); wfSuppressWarnings(); $success = oci_execute( $stmt ); @@ -1096,11 +1101,11 @@ class DatabaseOracle extends DatabaseBase { } public function removeIdentifierQuotes( $s ) { - return strpos($s, '/*Q*/') === FALSE ? $s : substr($s, 5); + return strpos( $s, '/*Q*/' ) === false ? $s : substr( $s, 5 ); } public function isQuotedIdentifier( $s ) { - return strpos($s, '/*Q*/') !== FALSE; + return strpos( $s, '/*Q*/' ) !== false; } private function wrapFieldForWhere( $table, &$col, &$val ) { @@ -1111,7 +1116,7 @@ class DatabaseOracle extends DatabaseBase { if ( $col_type == 'CLOB' ) { $col = 'TO_CHAR(' . $col . ')'; $val = $wgContLang->checkTitleEncoding( $val ); - } elseif ( $col_type == 'VARCHAR2' && !mb_check_encoding( $val ) ) { + } elseif ( $col_type == 'VARCHAR2' ) { $val = $wgContLang->checkTitleEncoding( $val ); } } @@ -1134,7 +1139,7 @@ class DatabaseOracle extends DatabaseBase { } function selectRow( $table, $vars, $conds, $fname = 'DatabaseOracle::selectRow', $options = array(), $join_conds = array() ) { - if ( is_array($conds) ) { + if ( is_array( $conds ) ) { $conds = $this->wrapConditionsForWhere( $table, $conds ); } return parent::selectRow( $table, $vars, $conds, $fname, $options, $join_conds ); @@ -1146,7 +1151,7 @@ class DatabaseOracle extends DatabaseBase { * * @private * - * @param $options Array: an associative array of options to be turned into + * @param array $options an associative array of options to be turned into * an SQL query, valid keys are listed in the function. * @return array */ @@ -1161,15 +1166,14 @@ class DatabaseOracle extends DatabaseBase { } } - if ( isset( $options['GROUP BY'] ) ) { - $preLimitTail .= " GROUP BY {$options['GROUP BY']}"; - } - if ( isset( $options['ORDER BY'] ) ) { - $preLimitTail .= " ORDER BY {$options['ORDER BY']}"; + $preLimitTail .= $this->makeGroupByWithHaving( $options ); + + $preLimitTail .= $this->makeOrderBy( $options ); + + if ( isset( $noKeyOptions['FOR UPDATE'] ) ) { + $postLimitTail .= ' FOR UPDATE'; } - # if ( isset( $noKeyOptions['FOR UPDATE'] ) ) $tailOpts .= ' FOR UPDATE'; - # if ( isset( $noKeyOptions['LOCK IN SHARE MODE'] ) ) $tailOpts .= ' LOCK IN SHARE MODE'; if ( isset( $noKeyOptions['DISTINCT'] ) || isset( $noKeyOptions['DISTINCTROW'] ) ) { $startOpts .= 'DISTINCT'; } @@ -1184,13 +1188,13 @@ class DatabaseOracle extends DatabaseBase { } public function delete( $table, $conds, $fname = 'DatabaseOracle::delete' ) { - if ( is_array($conds) ) { + if ( is_array( $conds ) ) { $conds = $this->wrapConditionsForWhere( $table, $conds ); } // a hack for deleting pages, users and images (which have non-nullable FKs) // all deletions on these tables have transactions so final failure rollbacks these updates $table = $this->tableName( $table ); - if ( $table == $this->tableName( 'user' ) ) { + if ( $table == $this->tableName( 'user' ) ) { $this->update( 'archive', array( 'ar_user' => 0 ), array( 'ar_user' => $conds['user_id'] ), $fname ); $this->update( 'ipblocks', array( 'ipb_user' => 0 ), array( 'ipb_user' => $conds['user_id'] ), $fname ); $this->update( 'image', array( 'img_user' => 0 ), array( 'img_user' => $conds['user_id'] ), $fname ); @@ -1200,7 +1204,7 @@ class DatabaseOracle extends DatabaseBase { $this->update( 'uploadstash', array( 'us_user' => 0 ), array( 'us_user' => $conds['user_id'] ), $fname ); $this->update( 'recentchanges', array( 'rc_user' => 0 ), array( 'rc_user' => $conds['user_id'] ), $fname ); $this->update( 'logging', array( 'log_user' => 0 ), array( 'log_user' => $conds['user_id'] ), $fname ); - } elseif ( $table == $this->tableName( 'image' ) ) { + } elseif ( $table == $this->tableName( 'image' ) ) { $this->update( 'oldimage', array( 'oi_name' => 0 ), array( 'oi_name' => $conds['img_name'] ), $fname ); } return parent::delete( $table, $conds, $fname ); |