- /**
- * REPLACE query wrapper
- * Oracle simulates this with a DELETE followed by INSERT
- * $row is the row to insert, an associative array
- * $uniqueIndexes is an array of indexes. Each element may be either a
- * field name or an array of field names
- *
- * It may be more efficient to leave off unique indexes which are unlikely to collide.
- * However if you do this, you run the risk of encountering errors which wouldn't have
- * occurred in MySQL.
- *
- * @param $table String: table name
- * @param $uniqueIndexes Array: array of indexes. Each element may be
- * either a field name or an array of field names
- * @param $rows Array: rows to insert to $table
- * @param $fname String: function name, you can use __METHOD__ here
- */
- function replace( $table, $uniqueIndexes, $rows, $fname = 'DatabaseOracle::replace' ) {
- $table = $this->tableName( $table );
-
- if ( count( $rows ) == 0 ) {
- return;
- }
-
- # Single row case
- if ( !is_array( reset( $rows ) ) ) {
- $rows = array( $rows );
- }
-
- $sequenceData = $this->getSequenceData( $table );
-
- foreach ( $rows as $row ) {
- # Delete rows which collide
- if ( $uniqueIndexes ) {
- $condsDelete = array();
- foreach ( $uniqueIndexes as $index ) {
- $condsDelete[$index] = $row[$index];
- }
- if ( count( $condsDelete ) > 0 ) {
- $this->delete( $table, $condsDelete, $fname );
- }
- }
-
- if ( $sequenceData !== false && !isset( $row[$sequenceData['column']] ) ) {
- $row[$sequenceData['column']] = $this->nextSequenceValue( $sequenceData['sequence'] );
- }
-
- # Now insert the row
- $this->insert( $table, $row, $fname );
- }
- }
-
- # DELETE where the condition is a join
- function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = 'DatabaseOracle::deleteJoin' ) {
- if ( !$conds ) {
- throw new DBUnexpectedError( $this, 'DatabaseOracle::deleteJoin() called with empty $conds' );
- }
-
- $delTable = $this->tableName( $delTable );
- $joinTable = $this->tableName( $joinTable );
- $sql = "DELETE FROM $delTable WHERE $delVar IN (SELECT $joinVar FROM $joinTable ";
- if ( $conds != '*' ) {
- $sql .= 'WHERE ' . $this->makeList( $conds, LIST_AND );
- }
- $sql .= ')';
-
- $this->query( $sql, $fname );
- }
-