Merge "Don't use isset() to check whether an existing variable is null"
[lhc/web/wiklou.git] / includes / db / DatabaseOracle.php
index d304444..6e0490d 100644 (file)
@@ -220,6 +220,7 @@ class DatabaseOracle extends DatabaseBase {
                                'dbname' => isset( $args[3] ) ? $args[3] : false,
                                'flags' => isset( $args[4] ) ? $args[4] : 0,
                                'tablePrefix' => isset( $args[5] ) ? $args[5] : 'get from global',
+                               'schema' => 'get from global',
                                'foreign' => isset( $args[6] ) ? $args[6] : false
                        );
                }
@@ -641,8 +642,12 @@ class DatabaseOracle extends DatabaseBase {
                        } else {
                                $first = false;
                        }
-
-                       $sql .= $this->fieldBindStatement( $table, $col, $val );
+                       if ( $this->isQuotedIdentifier( $val ) ) {
+                               $sql .= $this->removeIdentifierQuotes( $val );
+                               unset( $row[$col] );
+                       } else {
+                               $sql .= $this->fieldBindStatement( $table, $col, $val );
+                       }
                }
                $sql .= ')';
 
@@ -773,6 +778,32 @@ class DatabaseOracle extends DatabaseBase {
                return $retval;
        }
 
+       public function upsert( $table, array $rows, array $uniqueIndexes, array $set,
+               $fname = __METHOD__
+       ) {
+               if ( !count( $rows ) ) {
+                       return true; // nothing to do
+               }
+
+               if ( !is_array( reset( $rows ) ) ) {
+                       $rows = array( $rows );
+               }
+
+               $sequenceData = $this->getSequenceData( $table );
+               if ( $sequenceData !== false ) {
+                       // add sequence column to each list of columns, when not set
+                       foreach ( $rows as &$row ) {
+                               if ( !isset( $row[$sequenceData['column']] ) ) {
+                                       $row[$sequenceData['column']] =
+                                               $this->addIdentifierQuotes( 'GET_SEQUENCE_VALUE(\'' .
+                                                       $sequenceData['sequence'] . '\')' );
+                               }
+                       }
+               }
+
+               return parent::upsert( $table, $rows, $uniqueIndexes, $set, $fname );
+       }
+
        function tableName( $name, $format = 'quoted' ) {
                /*
                Replace reserved words with better ones
@@ -1003,8 +1034,8 @@ class DatabaseOracle extends DatabaseBase {
                $table = strtoupper( $this->removeIdentifierQuotes( $table ) );
                $index = strtoupper( $index );
                $owner = strtoupper( $this->mDBname );
-               $SQL = "SELECT 1 FROM all_indexes WHERE owner='$owner' AND index_name='{$table}_{$index}'";
-               $res = $this->doQuery( $SQL );
+               $sql = "SELECT 1 FROM all_indexes WHERE owner='$owner' AND index_name='{$table}_{$index}'";
+               $res = $this->doQuery( $sql );
                if ( $res ) {
                        $count = $res->numRows();
                        $res->free();
@@ -1025,8 +1056,8 @@ class DatabaseOracle extends DatabaseBase {
                $table = $this->tableName( $table );
                $table = $this->addQuotes( strtoupper( $this->removeIdentifierQuotes( $table ) ) );
                $owner = $this->addQuotes( strtoupper( $this->mDBname ) );
-               $SQL = "SELECT 1 FROM all_tables WHERE owner=$owner AND table_name=$table";
-               $res = $this->doQuery( $SQL );
+               $sql = "SELECT 1 FROM all_tables WHERE owner=$owner AND table_name=$table";
+               $res = $this->doQuery( $sql );
                if ( $res && $res->numRows() > 0 ) {
                        $exists = true;
                } else {