From 3b916c3763e620bd3c46021c01de5444215722eb Mon Sep 17 00:00:00 2001 From: Jure Kajzer Date: Fri, 15 Apr 2011 10:48:02 +0000 Subject: [PATCH] * updated tableName function changed addIdentifierQuotes, added isQuotedIdentifier and removeIdentifierQuotes * quoting objects in Oracle is poorly supported prior to 10g (it still has bugs in 10g) so i wish to avoid it for as long as possible * i've added /*Q*/ marker to avoid double-prefixing of table names * tableName quoted parameter is usable only in cases where you call it directly in functions where it might occur that tableName can get called twice it is unusable as the tableName gets prefixed twice Oracle documentation is generally crappy. They claim a lot of things but some of those claims depend on a gazillion of factors and in case of one of this factors being a bit off have no general solution. Object name quoting is one of such things and is general practice amongst oracle DBAs that if you write the code directly you can use them but if you write abstracted or embedded code it's best to stay away if you can. --- includes/db/DatabaseOracle.php | 28 +++++++++++++++------------- includes/search/SearchOracle.php | 4 ++-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index 53d2547cbe..40664504a5 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -463,7 +463,7 @@ class DatabaseOracle extends DatabaseBase { private function fieldBindStatement ( $table, $col, &$val, $includeCol = false ) { $col_info = $this->fieldInfoMulti( $table, $col ); $col_type = $col_info != false ? $col_info->type() : 'CONSTANT'; - + $bind = ''; if ( is_numeric( $col ) ) { $bind = $val; @@ -633,7 +633,7 @@ class DatabaseOracle extends DatabaseBase { return $retval; } - function tableName( $name, $quoted ) { + function tableName( $name, $quoted = true ) { /* Replace reserved words with better ones Using uppercase because that's the only way Oracle can handle @@ -877,7 +877,7 @@ class DatabaseOracle extends DatabaseBase { * Query whether a given table exists (in the given schema, or the default mw one if not given) */ function tableExists( $table ) { - $table = trim($this->tableName($table), '"'); + $table = $this->removeIdentifierQuotes($table); $SQL = "SELECT 1 FROM user_tables WHERE table_name='$table'"; $res = $this->doQuery( $SQL ); if ( $res ) { @@ -905,7 +905,7 @@ class DatabaseOracle extends DatabaseBase { $table = array_map( array( &$this, 'tableName' ), $table ); $tableWhere = 'IN ('; foreach( $table as &$singleTable ) { - $singleTable = strtoupper( trim( $singleTable, '"' ) ); + $singleTable = $this->removeIdentifierQuotes($singleTable); if ( isset( $this->mFieldInfoCache["$singleTable.$field"] ) ) { return $this->mFieldInfoCache["$singleTable.$field"]; } @@ -913,7 +913,7 @@ class DatabaseOracle extends DatabaseBase { } $tableWhere = rtrim( $tableWhere, ',' ) . ')'; } else { - $table = strtoupper( trim( $this->tableName( $table ), '"' ) ); + $table = $this->removeIdentifierQuotes($table); if ( isset( $this->mFieldInfoCache["$table.$field"] ) ) { return $this->mFieldInfoCache["$table.$field"]; } @@ -1078,18 +1078,20 @@ class DatabaseOracle extends DatabaseBase { } public function addIdentifierQuotes( $s ) { - return parent::addIdentifierQuotes( $s ); - - /* Does this old code make any sense? - * We could always use quoted identifier. - * See http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements008.htm - */ - if ( !$this->mFlags & DBO_DDLMODE ) { - $s = '"' . str_replace( '"', '""', $s ) . '"'; + if ( !$this->getFlag( DBO_DDLMODE ) ) { + $s = '/*Q*/' . $s; } return $s; } + public function removeIdentifierQuotes( $s ) { + return strpos($s, '/*Q*/') === FALSE ? $s : substr($s, 5); ; + } + + public function isQuotedIdentifier( $s ) { + return strpos($s, '/*Q*/') !== FALSE; + } + function selectRow( $table, $vars, $conds, $fname = 'DatabaseOracle::selectRow', $options = array(), $join_conds = array() ) { global $wgContLang; diff --git a/includes/search/SearchOracle.php b/includes/search/SearchOracle.php index 64e93e03fc..edd19dd94a 100644 --- a/includes/search/SearchOracle.php +++ b/includes/search/SearchOracle.php @@ -254,9 +254,9 @@ class SearchOracle extends SearchEngine { // ALTER SESSION SET CURRENT_SCHEMA = ... // was used. $dbw->query( "CALL ctx_ddl.sync_index(" . - $dbw->addQuotes( $dbw->getDBname() . '.' . trim( $dbw->tableName( 'si_text_idx' ), '"' ) ) . ")" ); + $dbw->addQuotes( $dbw->getDBname() . '.' . $dbw->tableName( 'si_text_idx', false ) ) . ")" ); $dbw->query( "CALL ctx_ddl.sync_index(" . - $dbw->addQuotes( $dbw->getDBname() . '.' . trim( $dbw->tableName( 'si_title_idx' ), '"' ) ) . ")" ); + $dbw->addQuotes( $dbw->getDBname() . '.' . $dbw->tableName( 'si_title_idx', false ) ) . ")" ); } /** -- 2.20.1