Also make upsert() match replace() for consistency.
Change-Id: I208f3ab810a61c6949ac0050436767675f99a60b
}
}
- public function upsert( $table, array $rows, array $uniqueIndexes, array $set,
+ public function upsert( $table, array $rows, $uniqueIndexes, array $set,
$fname = __METHOD__
) {
if ( $rows === [] ) {
}
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() );
}
return;
}
+ $uniqueIndexes = (array)$uniqueIndexes;
// Single row case
if ( !is_array( reset( $rows ) ) ) {
$rows = [ $rows ];
$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 ];
}
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 );
}
$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
* 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
*
* @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().
* @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__
);
/**