* (bug 8859) Database::update should take array of tables too
authorSam Reed <reedy@users.mediawiki.org>
Sat, 19 Nov 2011 20:17:29 +0000 (20:17 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Sat, 19 Nov 2011 20:17:29 +0000 (20:17 +0000)
Original patch by Andrew Dunbar

Also apply in DatabaseOracle and DB2 code as they override update

includes/db/Database.php
includes/db/DatabaseIbm_db2.php
includes/db/DatabaseOracle.php

index 4b54b8e..8dc2a9e 100644 (file)
@@ -1683,28 +1683,32 @@ abstract class DatabaseBase implements DatabaseType {
        /**
         * UPDATE wrapper. Takes a condition array and a SET array.
         *
-        * @param $table  String name of the table to UPDATE. This will be passed through
+        * @param $table  String|array name of the table to UPDATE. This will be passed through
         *                DatabaseBase::tableName().
         *
-        * @param $values Array An array of values to SET. For each array element,
+        * @param $values Array An array of values to SET. For each array element,
         *                the key gives the field name, and the value gives the data
         *                to set that field to. The data will be quoted by
         *                DatabaseBase::addQuotes().
         *
-        * @param $conds  Array:  An array of conditions (WHERE). See
+        * @param $conds  Array  An array of conditions (WHERE). See
         *                DatabaseBase::select() for the details of the format of
         *                condition arrays. Use '*' to update all rows.
         *
-        * @param $fname  String: The function name of the caller (from __METHOD__),
+        * @param $fname  String The function name of the caller (from __METHOD__),
         *                for logging and profiling.
         *
-        * @param $options Array: An array of UPDATE options, can be:
+        * @param $options Array An array of UPDATE options, can be:
         *                   - IGNORE: Ignore unique key conflicts
         *                   - LOW_PRIORITY: MySQL-specific, see MySQL manual.
         * @return Boolean
         */
        function update( $table, $values, $conds, $fname = 'DatabaseBase::update', $options = array() ) {
-               $table = $this->tableName( $table );
+               if ( is_array( $table ) ) {
+                       $table =  implode( ',', array_map( array( $this, 'tableName' ), $table ) );
+               } else {
+                       $table = $this->tableName( $table );
+               }
                $opts = $this->makeUpdateOptions( $options );
                $sql = "UPDATE $opts $table SET " . $this->makeList( $values, LIST_SET );
 
index 67ca80a..eb91478 100644 (file)
@@ -984,7 +984,11 @@ class DatabaseIbm_db2 extends DatabaseBase {
        public function update( $table, $values, $conds, $fname = 'DatabaseIbm_db2::update',
                $options = array() )
        {
-               $table = $this->tableName( $table );
+               if ( is_array( $table ) ) {
+                       $table =  implode( ',', array_map( array( $this, 'tableName' ), $table ) );
+               } else {
+                       $table = $this->tableName( $table );
+               }
                $opts = $this->makeUpdateOptions( $options );
                $sql = "UPDATE $opts $table SET "
                        . $this->makeList( $values, LIST_SET_PREPARED );
index 664e7da..d807201 100644 (file)
@@ -1197,7 +1197,11 @@ class DatabaseOracle extends DatabaseBase {
        function update( $table, $values, $conds, $fname = 'DatabaseOracle::update', $options = array() ) {
                global $wgContLang;
 
-               $table = $this->tableName( $table );
+               if ( is_array( $table ) ) {
+                       $table =  implode( ',', array_map( array( $this, 'tableName' ), $table ) );
+               } else {
+                       $table = $this->tableName( $table );
+               }
                $opts = $this->makeUpdateOptions( $options );
                $sql = "UPDATE $opts $table SET ";