r58277 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58276‎ | r58277 | r58278 >
Date:19:15, 28 October 2009
Author:freakolowsky
Status:ok
Tags:
Comment:
* Replaced LIMIT with limitResult call in rebuildrecentchanges.php
* Added a wrapper-function for sequence number generation and modified insertSelect in DatabaseOracle to fill missing ID-field references
Modified paths:
  • /trunk/phase3/includes/db/DatabaseOracle.php (modified) (history)
  • /trunk/phase3/maintenance/ora/tables.sql (modified) (history)
  • /trunk/phase3/maintenance/rebuildrecentchanges.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/rebuildrecentchanges.php
@@ -115,7 +115,8 @@
116116 $emit = $obj->rc_timestamp;
117117 $sql2 = "SELECT rev_id,rev_len FROM $revision " .
118118 "WHERE rev_page={$lastCurId} ".
119 - "AND rev_timestamp<'{$emit}' ORDER BY rev_timestamp DESC LIMIT 1";
 119+ "AND rev_timestamp<'{$emit}' ORDER BY rev_timestamp DESC";
 120+ $sql2 = $dbw->limitResult($sql2, 1, false);
120121 $res2 = $dbw->query( $sql2 );
121122 if( $row = $dbw->fetchObject( $res2 ) ) {
122123 $lastOldId = intval($row->rev_id);
Index: trunk/phase3/maintenance/ora/tables.sql
@@ -680,3 +680,11 @@
681681 END;
682682 /*$mw$*/
683683
 684+/*$mw$*/
 685+CREATE OR REPLACE FUNCTION GET_SEQUENCE_VALUE(seq IN VARCHAR2) RETURN NUMBER AS
 686+ v_value NUMBER;
 687+BEGIN
 688+ EXECUTE IMMEDIATE 'SELECT '||seq||'.NEXTVAL INTO :outVar FROM DUAL' INTO v_value;
 689+ RETURN v_value;
 690+END;
 691+/*$mw$*/
Index: trunk/phase3/includes/db/DatabaseOracle.php
@@ -33,7 +33,21 @@
3434 private $nrows;
3535
3636 private $unique;
 37+ private function array_unique_md($array_in) {
 38+ $array_out = array();
 39+ $array_hashes = array();
3740
 41+ foreach($array_in as $key => $item) {
 42+ $hash = md5(serialize($item));
 43+ if (!isset($array_hashes[$hash])) {
 44+ $array_hashes[$hash] = $hash;
 45+ $array_out[] = $item;
 46+ }
 47+ }
 48+
 49+ return $array_out;
 50+ }
 51+
3852 function __construct(&$db, $stmt, $unique = false) {
3953 $this->db =& $db;
4054
@@ -44,7 +58,7 @@
4559 }
4660
4761 if ($unique) {
48 - $this->rows = array_unique($this->rows);
 62+ $this->rows = $this->array_unique_md($this->rows);
4963 $this->nrows = count($this->rows);
5064 }
5165
@@ -162,6 +176,7 @@
163177 var $mAffectedRows;
164178
165179 var $ignore_DUP_VAL_ON_INDEX = false;
 180+ var $sequenceData = null;
166181
167182 function DatabaseOracle($server = false, $user = false, $password = false, $dbName = false,
168183 $failFunction = false, $flags = 0, $tablePrefix = 'get from global' )
@@ -513,11 +528,15 @@
514529 $srcTable = $this->tableName( $srcTable );
515530 }
516531
 532+ if (($sequenceData = $this->getSequenceData($destTable)) !== false &&
 533+ !isset($varMap[$sequenceData['column']]))
 534+ $varMap[$sequenceData['column']] = 'GET_SEQUENCE_VALUE(\''.$sequenceData['sequence'].'\')';
 535+
517536 // count-alias subselect fields to avoid abigious definition errors
518537 $i=0;
519538 foreach($varMap as $key=>&$val)
520539 $val=$val.' field'.($i++);
521 -
 540+
522541 $sql = "INSERT INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ')' .
523542 " SELECT $startOpts " . implode( ',', $varMap ) .
524543 " FROM $srcTable $useIndex ";
@@ -525,12 +544,12 @@
526545 $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND );
527546 }
528547 $sql .= " $tailOpts";
529 -
 548+
530549 if (in_array('IGNORE', $insertOptions))
531550 $this->ignore_DUP_VAL_ON_INDEX = true;
532 -
 551+
533552 $retval = $this->query( $sql, $fname );
534 -
 553+
535554 if (in_array('IGNORE', $insertOptions))
536555 $this->ignore_DUP_VAL_ON_INDEX = false;
537556
@@ -595,6 +614,21 @@
596615 return $this->mInsertId;
597616 }
598617
 618+ /**
 619+ * Return sequence_name if table has a sequence
 620+ */
 621+ function getSequenceData($table) {
 622+ if ($this->sequenceData == NULL) {
 623+ $result = $this->query("SELECT lower(us.sequence_name), lower(utc.table_name), lower(utc.column_name) from user_sequences us, user_tab_columns utc where us.sequence_name = utc.table_name||'_'||utc.column_name||'_SEQ'");
 624+
 625+ while(($row = $result->fetchRow()) !== false)
 626+ $this->sequenceData[$this->tableName($row[1])] = array('sequence' => $row[0], 'column' => $row[2]);
 627+ }
 628+
 629+ return (isset($this->sequenceData[$table])) ? $this->sequenceData[$table] : false;
 630+ }
 631+
 632+
599633 # REPLACE query wrapper
600634 # Oracle simulates this with a DELETE followed by INSERT
601635 # $row is the row to insert, an associative array

Status & tagging log