protected $db;
/**
- * @var string $table The name of the table to read from
+ * @var string|array $table The name or names of the table to read from
*/
protected $table;
* @var array $conditions Array of strings containing SQL conditions
* to add to the query
*/
- protected $conditions = array();
+ protected $conditions = [];
/**
* @var array $joinConditions
*/
- protected $joinConditions = array();
+ protected $joinConditions = [];
/**
* @var array $fetchColumns List of column names to select from the
/**
* @var array $current The current iterator value
*/
- private $current = array();
+ private $current = [];
/**
* @var integer key 0-indexed number of pages fetched since self::reset()
/**
* @param IDatabase $db The database to read from
- * @param string $table The name of the table to read from
+ * @param string|array $table The name or names of the table to read from
* @param string|array $primaryKey The name or names of the primary key columns
* @param integer $batchSize The number of rows to fetch per iteration
* @throws MWException
* @return array Map of primary key column to value within the row
*/
public function extractPrimaryKeys( $row ) {
- $pk = array();
- foreach ( $this->primaryKey as $column ) {
- $pk[$column] = $row->$column;
+ $pk = [];
+ foreach ( $this->primaryKey as $alias => $column ) {
+ $name = is_numeric( $alias ) ? $column : $alias;
+ $pk[$name] = $row->{$name};
}
return $pk;
}
*/
public function rewind() {
$this->key = -1; // self::next() will turn this into 0
- $this->current = array();
+ $this->current = [];
$this->next();
}
/**
- * @return boolean True when the iterator is in a valid state
+ * @return bool True when the iterator is in a valid state
*/
public function valid() {
return (bool)$this->current;
}
/**
- * @return boolean True when this result set has rows
+ * @return bool True when this result set has rows
*/
public function hasChildren() {
return $this->current && count( $this->current );
$this->fetchColumns,
$this->buildConditions(),
__METHOD__,
- array(
+ [
'LIMIT' => $this->batchSize,
'ORDER BY' => $this->orderBy,
- ),
+ ],
$this->joinConditions
);
}
$maxRow = end( $this->current );
- $maximumValues = array();
- foreach ( $this->primaryKey as $column ) {
- $maximumValues[$column] = $this->db->addQuotes( $maxRow->$column );
+ $maximumValues = [];
+ foreach ( $this->primaryKey as $alias => $column ) {
+ $name = is_numeric( $alias ) ? $column : $alias;
+ $maximumValues[$column] = $this->db->addQuotes( $maxRow->{$name} );
}
- $pkConditions = array();
+ $pkConditions = [];
// For example: If we have 3 primary keys
// first run through will generate
// col1 = 4 AND col2 = 7 AND col3 > 1
$keys = array_keys( $quotedMaximumValues );
$lastColumn = end( $keys );
$lastValue = array_pop( $quotedMaximumValues );
- $conditions = array();
+ $conditions = [];
foreach ( $quotedMaximumValues as $column => $value ) {
$conditions[] = "$column = $value";
}