rdbms: clarify $uniqueIndexes argument to replace()/upsert()
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 13 Mar 2019 03:09:21 +0000 (20:09 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 13 Mar 2019 03:09:21 +0000 (20:09 -0700)
Also make upsert() match replace() for consistency.

Change-Id: I208f3ab810a61c6949ac0050436767675f99a60b

includes/db/DatabaseOracle.php
includes/libs/rdbms/database/DBConnRef.php
includes/libs/rdbms/database/Database.php
includes/libs/rdbms/database/DatabaseMysqlBase.php
includes/libs/rdbms/database/IDatabase.php

index bb2d3f7..a051d83 100644 (file)
@@ -591,7 +591,7 @@ class DatabaseOracle extends Database {
                }
        }
 
-       public function upsert( $table, array $rows, array $uniqueIndexes, array $set,
+       public function upsert( $table, array $rows, $uniqueIndexes, array $set,
                $fname = __METHOD__
        ) {
                if ( $rows === [] ) {
index ab70fc8..4fdac81 100644 (file)
@@ -417,7 +417,7 @@ class DBConnRef implements IDatabase {
        }
 
        public function upsert(
-               $table, array $rows, array $uniqueIndexes, array $set, $fname = __METHOD__
+               $table, array $rows, $uniqueIndexes, array $set, $fname = __METHOD__
        ) {
                return $this->__call( __FUNCTION__, func_get_args() );
        }
index 49b2792..3077fbe 100644 (file)
@@ -2782,6 +2782,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                        return;
                }
 
+               $uniqueIndexes = (array)$uniqueIndexes;
                // Single row case
                if ( !is_array( reset( $rows ) ) ) {
                        $rows = [ $rows ];
@@ -2861,13 +2862,14 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                $this->query( $sql, $fname );
        }
 
-       public function upsert( $table, array $rows, array $uniqueIndexes, array $set,
+       public function upsert( $table, array $rows, $uniqueIndexes, array $set,
                $fname = __METHOD__
        ) {
                if ( $rows === [] ) {
                        return true; // nothing to do
                }
 
+               $uniqueIndexes = (array)$uniqueIndexes;
                if ( !is_array( reset( $rows ) ) ) {
                        $rows = [ $rows ];
                }
index 62110ef..7fbd34d 100644 (file)
@@ -489,12 +489,6 @@ abstract class DatabaseMysqlBase extends Database {
                return $errno == 2062;
        }
 
-       /**
-        * @param string $table
-        * @param array $uniqueIndexes
-        * @param array $rows
-        * @param string $fname
-        */
        public function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__ ) {
                $this->nativeReplace( $table, $rows, $fname );
        }
@@ -1326,16 +1320,8 @@ abstract class DatabaseMysqlBase extends Database {
                $this->query( $sql, $fname );
        }
 
-       /**
-        * @param string $table
-        * @param array $rows
-        * @param array $uniqueIndexes
-        * @param array $set
-        * @param string $fname
-        * @return bool
-        */
-       public function upsert( $table, array $rows, array $uniqueIndexes,
-               array $set, $fname = __METHOD__
+       public function upsert(
+               $table, array $rows, $uniqueIndexes, array $set, $fname = __METHOD__
        ) {
                if ( $rows === [] ) {
                        return true; // nothing to do
index 7d9eac1..3401541 100644 (file)
@@ -1232,8 +1232,10 @@ interface IDatabase {
         * errors which wouldn't have occurred in MySQL.
         *
         * @param string $table The table to replace the row(s) in.
-        * @param array $uniqueIndexes Either a list of fields that define a unique index or
-        *   an array of such lists if there are multiple unique indexes defined in the schema
+        * @param array[]|string[]|string $uniqueIndexes All unique indexes. One of the following:
+        *   a) the one unique field in the table (when no composite unique key exist)
+        *   b) a list of all unique fields in the table (when no composite unique key exist)
+        *   c) a list of all unique indexes in the table (each as a list of the indexed fields)
         * @param array $rows Can be either a single row to insert, or multiple rows,
         *   in the same format as for IDatabase::insert()
         * @param string $fname Calling function name (use __METHOD__) for logs/profiling
@@ -1267,8 +1269,10 @@ interface IDatabase {
         *
         * @param string $table Table name. This will be passed through Database::tableName().
         * @param array $rows A single row or list of rows to insert
-        * @param array $uniqueIndexes Either a list of fields that define a unique index or
-        *   an array of such lists if there are multiple unique indexes defined in the schema
+        * @param array[]|string[]|string $uniqueIndexes All unique indexes. One of the following:
+        *   a) the one unique field in the table (when no composite unique key exist)
+        *   b) a list of all unique fields in the table (when no composite unique key exist)
+        *   c) a list of all unique indexes in the table (each as a list of the indexed fields)
         * @param array $set 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 IDatabase::addQuotes().
@@ -1279,7 +1283,7 @@ interface IDatabase {
         * @return bool Return true if no exception was thrown (deprecated since 1.33)
         */
        public function upsert(
-               $table, array $rows, array $uniqueIndexes, array $set, $fname = __METHOD__
+               $table, array $rows, $uniqueIndexes, array $set, $fname = __METHOD__
        );
 
        /**