r89253 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89252‎ | r89253 | r89254 >
Date:11:38, 1 June 2011
Author:freakolowsky
Status:deferred (Comments)
Tags:
Comment:
* unified where clause parameter wrapping for delete, update and selectRow
* fixed replace where clause handling
Modified paths:
  • /trunk/phase3/includes/db/DatabaseOracle.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/DatabaseOracle.php
@@ -733,15 +733,23 @@
734734 foreach ( $rows as $row ) {
735735 # Delete rows which collide
736736 if ( $uniqueIndexes ) {
737 - $condsDelete = array();
738 - foreach ( $uniqueIndexes as $index ) {
739 - $condsDelete[$index] = $row[$index];
 737+ $deleteConds = array();
 738+ foreach ( $uniqueIndexes as $key=>$index ) {
 739+ if ( is_array( $index ) ) {
 740+ $deleteConds2 = array();
 741+ foreach ( $index as $col ) {
 742+ $deleteConds2[$col] = $row[$col];
 743+ }
 744+ $deleteConds[$key] = $this->makeList( $deleteConds2, LIST_AND );
 745+ } else {
 746+ $deleteConds[$index] = $row[$index];
 747+ }
740748 }
741 - if ( count( $condsDelete ) > 0 ) {
742 - $this->delete( $table, $condsDelete, $fname );
743 - }
 749+ $deleteConds = array( $this->makeList( $deleteConds, LIST_OR ) );
 750+ $this->delete( $table, $deleteConds, $fname );
744751 }
745752
 753+
746754 if ( $sequenceData !== false && !isset( $row[$sequenceData['column']] ) ) {
747755 $row[$sequenceData['column']] = $this->nextSequenceValue( $sequenceData['sequence'] );
748756 }
@@ -1143,28 +1151,41 @@
11441152 return strpos($s, '/*Q*/') !== FALSE;
11451153 }
11461154
1147 - function selectRow( $table, $vars, $conds, $fname = 'DatabaseOracle::selectRow', $options = array(), $join_conds = array() ) {
 1155+ private function wrapFieldForWhere( $table, &$col, &$val ) {
11481156 global $wgContLang;
 1157+
 1158+ $col_info = $this->fieldInfoMulti( $table, $col );
 1159+ $col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
 1160+ if ( $col_type == 'CLOB' ) {
 1161+ $col = 'TO_CHAR(' . $col . ')';
 1162+ $val = $wgContLang->checkTitleEncoding( $val );
 1163+ } elseif ( $col_type == 'VARCHAR2' && !mb_check_encoding( $val ) ) {
 1164+ $val = $wgContLang->checkTitleEncoding( $val );
 1165+ }
 1166+ }
11491167
1150 - if ($conds != null) {
1151 - $conds2 = array();
1152 - $conds = ( !is_array( $conds ) ) ? array( $conds ) : $conds;
1153 - foreach ( $conds as $col => $val ) {
1154 - $col_info = $this->fieldInfoMulti( $table, $col );
1155 - $col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
1156 - if ( $col_type == 'CLOB' ) {
1157 - $conds2['TO_CHAR(' . $col . ')'] = $wgContLang->checkTitleEncoding( $val );
1158 - } elseif ( $col_type == 'VARCHAR2' && !mb_check_encoding( $val ) ) {
1159 - $conds2[$col] = $wgContLang->checkTitleEncoding( $val );
 1168+ private function wrapConditionsForWhere ( $table, $conds, $parentCol = null ) {
 1169+ $conds2 = array();
 1170+ foreach ( $conds as $col => $val ) {
 1171+ if ( is_array( $val ) ) {
 1172+ $conds2[$col] = $this->wrapConditionsForWhere ( $table, $val, $col );
 1173+ } else {
 1174+ if ( is_numeric( $col ) && $parentCol != null ) {
 1175+ $this->wrapFieldForWhere ( $table, $parentCol, $val );
11601176 } else {
1161 - $conds2[$col] = $val;
 1177+ $this->wrapFieldForWhere ( $table, $col, $val );
11621178 }
 1179+ $conds2[$col] = $val;
11631180 }
 1181+ }
 1182+ return $conds2;
 1183+ }
11641184
1165 - return parent::selectRow( $table, $vars, $conds2, $fname, $options, $join_conds );
1166 - } else {
1167 - return parent::selectRow( $table, $vars, $conds, $fname, $options, $join_conds );
 1185+ function selectRow( $table, $vars, $conds, $fname = 'DatabaseOracle::selectRow', $options = array(), $join_conds = array() ) {
 1186+ if ( is_array($conds) ) {
 1187+ $conds = $this->wrapConditionsForWhere( $table, $conds );
11681188 }
 1189+ return parent::selectRow( $table, $vars, $conds, $fname, $options, $join_conds );
11691190 }
11701191
11711192 /**
@@ -1211,32 +1232,10 @@
12121233 }
12131234
12141235 public function delete( $table, $conds, $fname = 'DatabaseOracle::delete' ) {
1215 - global $wgContLang;
1216 -
1217 - if ( $wgContLang != null && $conds != null && $conds != '*' ) {
1218 - $conds2 = array();
1219 - $conds = ( !is_array( $conds ) ) ? array( $conds ) : $conds;
1220 - foreach ( $conds as $col => $val ) {
1221 - $col_info = $this->fieldInfoMulti( $table, $col );
1222 - $col_type = $col_info != false ? $col_info->type() : 'CONSTANT';
1223 - if ( $col_type == 'CLOB' ) {
1224 - $conds2['TO_CHAR(' . $col . ')'] = $wgContLang->checkTitleEncoding( $val );
1225 - } else {
1226 - if ( is_array( $val ) ) {
1227 - $conds2[$col] = $val;
1228 - foreach ( $conds2[$col] as &$val2 ) {
1229 - $val2 = $wgContLang->checkTitleEncoding( $val2 );
1230 - }
1231 - } else {
1232 - $conds2[$col] = $wgContLang->checkTitleEncoding( $val );
1233 - }
1234 - }
1235 - }
1236 -
1237 - return parent::delete( $table, $conds2, $fname );
1238 - } else {
1239 - return parent::delete( $table, $conds, $fname );
 1236+ if ( is_array($conds) ) {
 1237+ $conds = $this->wrapConditionsForWhere( $table, $conds );
12401238 }
 1239+ return parent::delete( $table, $conds, $fname );
12411240 }
12421241
12431242 function update( $table, $values, $conds, $fname = 'DatabaseOracle::update', $options = array() ) {
@@ -1259,6 +1258,7 @@
12601259 }
12611260
12621261 if ( $conds != '*' ) {
 1262+ $conds = $this->wrapConditionsForWhere( $table, $conds );
12631263 $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND );
12641264 }
12651265

Follow-up revisions

RevisionCommit summaryAuthorDate
r96557MFT r80167, r81689, r87498, r89253reedy12:38, 8 September 2011

Comments

#Comment by Freakolowsky (talk | contribs)   07:48, 18 July 2011

the foreach loop part of the replace function should be merged into 1.17 ... using two dimensional array in $uniqueIndexes breaks the delete part.

Status & tagging log