r86112 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86111‎ | r86112 | r86113 >
Date:10:48, 15 April 2011
Author:freakolowsky
Status:ok
Tags:
Comment:
* 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.
Modified paths:
  • /trunk/phase3/includes/db/DatabaseOracle.php (modified) (history)
  • /trunk/phase3/includes/search/SearchOracle.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/search/SearchOracle.php
@@ -254,9 +254,9 @@
255255 // ALTER SESSION SET CURRENT_SCHEMA = ...
256256 // was used.
257257 $dbw->query( "CALL ctx_ddl.sync_index(" .
258 - $dbw->addQuotes( $dbw->getDBname() . '.' . trim( $dbw->tableName( 'si_text_idx' ), '"' ) ) . ")" );
 258+ $dbw->addQuotes( $dbw->getDBname() . '.' . $dbw->tableName( 'si_text_idx', false ) ) . ")" );
259259 $dbw->query( "CALL ctx_ddl.sync_index(" .
260 - $dbw->addQuotes( $dbw->getDBname() . '.' . trim( $dbw->tableName( 'si_title_idx' ), '"' ) ) . ")" );
 260+ $dbw->addQuotes( $dbw->getDBname() . '.' . $dbw->tableName( 'si_title_idx', false ) ) . ")" );
261261 }
262262
263263 /**
Index: trunk/phase3/includes/db/DatabaseOracle.php
@@ -463,7 +463,7 @@
464464 private function fieldBindStatement ( $table, $col, &$val, $includeCol = false ) {
465465 $col_info = $this->fieldInfoMulti( $table, $col );
466466 $col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
467 -
 467+
468468 $bind = '';
469469 if ( is_numeric( $col ) ) {
470470 $bind = $val;
@@ -633,7 +633,7 @@
634634 return $retval;
635635 }
636636
637 - function tableName( $name, $quoted ) {
 637+ function tableName( $name, $quoted = true ) {
638638 /*
639639 Replace reserved words with better ones
640640 Using uppercase because that's the only way Oracle can handle
@@ -877,7 +877,7 @@
878878 * Query whether a given table exists (in the given schema, or the default mw one if not given)
879879 */
880880 function tableExists( $table ) {
881 - $table = trim($this->tableName($table), '"');
 881+ $table = $this->removeIdentifierQuotes($table);
882882 $SQL = "SELECT 1 FROM user_tables WHERE table_name='$table'";
883883 $res = $this->doQuery( $SQL );
884884 if ( $res ) {
@@ -905,7 +905,7 @@
906906 $table = array_map( array( &$this, 'tableName' ), $table );
907907 $tableWhere = 'IN (';
908908 foreach( $table as &$singleTable ) {
909 - $singleTable = strtoupper( trim( $singleTable, '"' ) );
 909+ $singleTable = $this->removeIdentifierQuotes($singleTable);
910910 if ( isset( $this->mFieldInfoCache["$singleTable.$field"] ) ) {
911911 return $this->mFieldInfoCache["$singleTable.$field"];
912912 }
@@ -913,7 +913,7 @@
914914 }
915915 $tableWhere = rtrim( $tableWhere, ',' ) . ')';
916916 } else {
917 - $table = strtoupper( trim( $this->tableName( $table ), '"' ) );
 917+ $table = $this->removeIdentifierQuotes($table);
918918 if ( isset( $this->mFieldInfoCache["$table.$field"] ) ) {
919919 return $this->mFieldInfoCache["$table.$field"];
920920 }
@@ -1078,18 +1078,20 @@
10791079 }
10801080
10811081 public function addIdentifierQuotes( $s ) {
1082 - return parent::addIdentifierQuotes( $s );
1083 -
1084 - /* Does this old code make any sense?
1085 - * We could always use quoted identifier.
1086 - * See http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements008.htm
1087 - */
1088 - if ( !$this->mFlags & DBO_DDLMODE ) {
1089 - $s = '"' . str_replace( '"', '""', $s ) . '"';
 1082+ if ( !$this->getFlag( DBO_DDLMODE ) ) {
 1083+ $s = '/*Q*/' . $s;
10901084 }
10911085 return $s;
10921086 }
10931087
 1088+ public function removeIdentifierQuotes( $s ) {
 1089+ return strpos($s, '/*Q*/') === FALSE ? $s : substr($s, 5); ;
 1090+ }
 1091+
 1092+ public function isQuotedIdentifier( $s ) {
 1093+ return strpos($s, '/*Q*/') !== FALSE;
 1094+ }
 1095+
10941096 function selectRow( $table, $vars, $conds, $fname = 'DatabaseOracle::selectRow', $options = array(), $join_conds = array() ) {
10951097 global $wgContLang;
10961098

Status & tagging log