Index: trunk/phase3/maintenance/rebuildrecentchanges.php |
— | — | @@ -115,7 +115,8 @@ |
116 | 116 | $emit = $obj->rc_timestamp; |
117 | 117 | $sql2 = "SELECT rev_id,rev_len FROM $revision " . |
118 | 118 | "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); |
120 | 121 | $res2 = $dbw->query( $sql2 ); |
121 | 122 | if( $row = $dbw->fetchObject( $res2 ) ) { |
122 | 123 | $lastOldId = intval($row->rev_id); |
Index: trunk/phase3/maintenance/ora/tables.sql |
— | — | @@ -680,3 +680,11 @@ |
681 | 681 | END; |
682 | 682 | /*$mw$*/ |
683 | 683 | |
| 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 @@ |
34 | 34 | private $nrows; |
35 | 35 | |
36 | 36 | private $unique; |
| 37 | + private function array_unique_md($array_in) { |
| 38 | + $array_out = array(); |
| 39 | + $array_hashes = array(); |
37 | 40 | |
| 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 | + |
38 | 52 | function __construct(&$db, $stmt, $unique = false) { |
39 | 53 | $this->db =& $db; |
40 | 54 | |
— | — | @@ -44,7 +58,7 @@ |
45 | 59 | } |
46 | 60 | |
47 | 61 | if ($unique) { |
48 | | - $this->rows = array_unique($this->rows); |
| 62 | + $this->rows = $this->array_unique_md($this->rows); |
49 | 63 | $this->nrows = count($this->rows); |
50 | 64 | } |
51 | 65 | |
— | — | @@ -162,6 +176,7 @@ |
163 | 177 | var $mAffectedRows; |
164 | 178 | |
165 | 179 | var $ignore_DUP_VAL_ON_INDEX = false; |
| 180 | + var $sequenceData = null; |
166 | 181 | |
167 | 182 | function DatabaseOracle($server = false, $user = false, $password = false, $dbName = false, |
168 | 183 | $failFunction = false, $flags = 0, $tablePrefix = 'get from global' ) |
— | — | @@ -513,11 +528,15 @@ |
514 | 529 | $srcTable = $this->tableName( $srcTable ); |
515 | 530 | } |
516 | 531 | |
| 532 | + if (($sequenceData = $this->getSequenceData($destTable)) !== false && |
| 533 | + !isset($varMap[$sequenceData['column']])) |
| 534 | + $varMap[$sequenceData['column']] = 'GET_SEQUENCE_VALUE(\''.$sequenceData['sequence'].'\')'; |
| 535 | + |
517 | 536 | // count-alias subselect fields to avoid abigious definition errors |
518 | 537 | $i=0; |
519 | 538 | foreach($varMap as $key=>&$val) |
520 | 539 | $val=$val.' field'.($i++); |
521 | | - |
| 540 | + |
522 | 541 | $sql = "INSERT INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ')' . |
523 | 542 | " SELECT $startOpts " . implode( ',', $varMap ) . |
524 | 543 | " FROM $srcTable $useIndex "; |
— | — | @@ -525,12 +544,12 @@ |
526 | 545 | $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND ); |
527 | 546 | } |
528 | 547 | $sql .= " $tailOpts"; |
529 | | - |
| 548 | + |
530 | 549 | if (in_array('IGNORE', $insertOptions)) |
531 | 550 | $this->ignore_DUP_VAL_ON_INDEX = true; |
532 | | - |
| 551 | + |
533 | 552 | $retval = $this->query( $sql, $fname ); |
534 | | - |
| 553 | + |
535 | 554 | if (in_array('IGNORE', $insertOptions)) |
536 | 555 | $this->ignore_DUP_VAL_ON_INDEX = false; |
537 | 556 | |
— | — | @@ -595,6 +614,21 @@ |
596 | 615 | return $this->mInsertId; |
597 | 616 | } |
598 | 617 | |
| 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 | + |
599 | 633 | # REPLACE query wrapper |
600 | 634 | # Oracle simulates this with a DELETE followed by INSERT |
601 | 635 | # $row is the row to insert, an associative array |