97 throw new InvalidArgumentException(
'Batch size must be at least 1 row.' );
103 $this->orderBy = implode(
' ASC,', $this->primaryKey ) .
' ASC';
112 $this->conditions = array_merge( $this->conditions,
$conditions );
120 $this->options = array_merge( $this->options,
$options );
128 $this->joinConditions = array_merge( $this->joinConditions,
$conditions );
137 if ( count( $columns ) === 1 && reset( $columns ) ===
'*' ) {
138 $this->fetchColumns = $columns;
140 $this->fetchColumns = array_unique( array_merge(
155 foreach ( $this->primaryKey as $alias => $column ) {
156 $name = is_numeric( $alias ) ? $column : $alias;
157 $pk[$name] = $row->{$name};
166 return $this->current;
189 return (
bool)$this->current;
196 return $this->current && count( $this->current );
210 $res = $this->db->select(
213 $this->buildConditions(),
216 'LIMIT' => $this->batchSize,
217 'ORDER BY' => $this->orderBy,
219 $this->joinConditions
225 $this->current = iterator_to_array(
$res );
242 if ( !$this->current ) {
243 return $this->conditions;
246 $maxRow = end( $this->current );
248 foreach ( $this->primaryKey as $alias => $column ) {
249 $name = is_numeric( $alias ) ? $column : $alias;
250 $maximumValues[$column] = $this->db->addQuotes( $maxRow->{$name} );
261 while ( $maximumValues ) {
262 $pkConditions[] = $this->buildGreaterThanCondition( $maximumValues );
263 array_pop( $maximumValues );
266 $conditions = $this->conditions;
267 $conditions[] = sprintf(
'( %s )', implode(
' ) OR ( ', $pkConditions ) );
285 $keys = array_keys( $quotedMaximumValues );
286 $lastColumn = end(
$keys );
287 $lastValue = array_pop( $quotedMaximumValues );
289 foreach ( $quotedMaximumValues as $column => $value ) {
290 $conditions[] =
"$column = $value";
292 $conditions[] =
"$lastColumn > $lastValue";
294 return implode(
' AND ', $conditions );
next()
Fetch the next set of rows from the database.
addConditions(array $conditions)
rewind()
Reset the iterator to the begining of the table.
array $options
Additional query options.
addJoinConditions(array $conditions)
setFetchColumns(array $columns)
extractPrimaryKeys( $row)
Extracts the primary key(s) from a database row.
addOptions(array $options)
int $key
key 0-indexed number of pages fetched since self::reset()
buildGreaterThanCondition(array $quotedMaximumValues)
Given an array of column names and their maximum value generate an SQL condition where all keys excep...
buildConditions()
Uses the primary key list and the maximal result row from the previous iteration to build an SQL cond...
__construct(IDatabase $db, $table, $primaryKey, $batchSize)