MediaWiki REL1_35
|
Allows iterating a large number of rows in batches transparently. More...
Public Member Functions | |
__construct (IDatabase $db, $table, $primaryKey, $batchSize) | |
Stable to call. | |
addConditions (array $conditions) | |
addJoinConditions (array $conditions) | |
addOptions (array $options) | |
current () | |
extractPrimaryKeys ( $row) | |
Extracts the primary key(s) from a database row. | |
getChildren () | |
hasChildren () | |
key () | |
next () | |
Fetch the next set of rows from the database. | |
rewind () | |
Reset the iterator to the begining of the table. | |
setFetchColumns (array $columns) | |
valid () | |
Protected Member Functions | |
buildConditions () | |
Uses the primary key list and the maximal result row from the previous iteration to build an SQL condition sufficient for selecting the next page of results. | |
buildGreaterThanCondition (array $quotedMaximumValues) | |
Given an array of column names and their maximum value generate an SQL condition where all keys except the last match $quotedMaximumValues exactly and the last column is greater than the matching value in $quotedMaximumValues. | |
Protected Attributes | |
int | $batchSize |
The number of rows to fetch per iteration. | |
array | $conditions = [] |
Array of strings containing SQL conditions to add to the query. | |
IDatabase | $db |
The database to read from. | |
array | $fetchColumns |
List of column names to select from the table suitable for use with IDatabase::select() | |
array | $joinConditions = [] |
array | $options = [] |
Additional query options. | |
string | $orderBy |
SQL Order by condition generated from $this->primaryKey. | |
array | $primaryKey |
The name of the primary key(s) | |
string array | $table |
The name or names of the table to read from. | |
Private Attributes | |
array | $current = [] |
The current iterator value. | |
int | $key = -1 |
0-indexed number of pages fetched since self::reset() | |
Allows iterating a large number of rows in batches transparently.
By default when iterated over returns the full query result as an array of rows. Can be wrapped in RecursiveIteratorIterator to collapse those arrays into a single stream of rows queried in batches.
@newable
Definition at line 33 of file BatchRowIterator.php.
BatchRowIterator::__construct | ( | IDatabase | $db, |
$table, | |||
$primaryKey, | |||
$batchSize | |||
) |
Stable to call.
IDatabase | $db | The database to read from |
string | array | $table | The name or names of the table to read from |
string | array | $primaryKey | The name or names of the primary key columns |
int | $batchSize | The number of rows to fetch per iteration |
InvalidArgumentException |
Definition at line 100 of file BatchRowIterator.php.
References $batchSize, $db, $primaryKey, and $table.
BatchRowIterator::addConditions | ( | array | $conditions | ) |
array | $conditions | Query conditions suitable for use with IDatabase::select |
Definition at line 116 of file BatchRowIterator.php.
References $conditions.
Referenced by CategoryChangesAsRdf\addTimestampConditions().
BatchRowIterator::addJoinConditions | ( | array | $conditions | ) |
array | $conditions | Query join conditions suitable for use with IDatabase::select |
Definition at line 132 of file BatchRowIterator.php.
References $conditions.
BatchRowIterator::addOptions | ( | array | $options | ) |
array | $options | Query options suitable for use with IDatabase::select |
Definition at line 124 of file BatchRowIterator.php.
References $options.
Referenced by CategoryChangesAsRdf\addIndex().
|
protected |
Uses the primary key list and the maximal result row from the previous iteration to build an SQL condition sufficient for selecting the next page of results.
All except the final key use =
conditions while the final key uses a >
condition
Example output: [ '( foo = 42 AND bar > 7 ) OR ( foo > 42 )' ]
Definition at line 246 of file BatchRowIterator.php.
|
protected |
Given an array of column names and their maximum value generate an SQL condition where all keys except the last match $quotedMaximumValues exactly and the last column is greater than the matching value in $quotedMaximumValues.
array | $quotedMaximumValues | The maximum values quoted with $this->db->addQuotes() |
Definition at line 289 of file BatchRowIterator.php.
References $keys.
BatchRowIterator::current | ( | ) |
Definition at line 170 of file BatchRowIterator.php.
BatchRowIterator::extractPrimaryKeys | ( | $row | ) |
Extracts the primary key(s) from a database row.
stdClass | $row | An individual database row from this iterator |
Definition at line 158 of file BatchRowIterator.php.
BatchRowIterator::getChildren | ( | ) |
Definition at line 207 of file BatchRowIterator.php.
BatchRowIterator::hasChildren | ( | ) |
Definition at line 200 of file BatchRowIterator.php.
BatchRowIterator::key | ( | ) |
Definition at line 177 of file BatchRowIterator.php.
BatchRowIterator::next | ( | ) |
Fetch the next set of rows from the database.
Definition at line 214 of file BatchRowIterator.php.
BatchRowIterator::rewind | ( | ) |
Reset the iterator to the begining of the table.
Definition at line 184 of file BatchRowIterator.php.
BatchRowIterator::setFetchColumns | ( | array | $columns | ) |
array | $columns | List of column names to select from the table suitable for use with IDatabase::select() |
Definition at line 140 of file BatchRowIterator.php.
BatchRowIterator::valid | ( | ) |
Definition at line 193 of file BatchRowIterator.php.
|
protected |
The number of rows to fetch per iteration.
Definition at line 53 of file BatchRowIterator.php.
Referenced by __construct().
|
protected |
Array of strings containing SQL conditions to add to the query.
Definition at line 58 of file BatchRowIterator.php.
Referenced by addConditions(), and addJoinConditions().
|
private |
The current iterator value.
Definition at line 79 of file BatchRowIterator.php.
|
protected |
The database to read from.
Definition at line 38 of file BatchRowIterator.php.
Referenced by __construct().
|
protected |
List of column names to select from the table suitable for use with IDatabase::select()
Definition at line 69 of file BatchRowIterator.php.
|
protected |
Definition at line 63 of file BatchRowIterator.php.
|
private |
0-indexed number of pages fetched since self::reset()
Definition at line 84 of file BatchRowIterator.php.
|
protected |
Additional query options.
Definition at line 89 of file BatchRowIterator.php.
Referenced by addOptions().
|
protected |
SQL Order by condition generated from $this->primaryKey.
Definition at line 74 of file BatchRowIterator.php.
|
protected |
The name of the primary key(s)
Definition at line 48 of file BatchRowIterator.php.
Referenced by __construct().
|
protected |
The name or names of the table to read from.
Definition at line 43 of file BatchRowIterator.php.
Referenced by __construct().