MediaWiki master
|
Build SELECT queries with a fluent interface. More...
Inherits Wikimedia\Rdbms\JoinGroupBase.
Inherited by MediaWiki\FileRepo\File\FileSelectQueryBuilder, MediaWiki\Logging\LoggingSelectQueryBuilder, MediaWiki\Page\PageSelectQueryBuilder, MediaWiki\Revision\ArchiveSelectQueryBuilder, MediaWiki\Revision\RevisionSelectQueryBuilder, and MediaWiki\User\UserSelectQueryBuilder.
Public Member Functions | |
__construct (IReadableDatabase $db) | |
Only for use in subclasses. | |
acquireRowLocks () | |
Execute the query, but throw away the results. | |
andWhere ( $conds) | |
Add conditions to the query. | |
bigResult () | |
Enable the SQL_BIG_RESULT option. | |
bufferResult () | |
Enable the SQL_BUFFER_RESULT option. | |
buildGroupConcatField ( $delim) | |
Build a GROUP_CONCAT or equivalent statement for a query. | |
calcFoundRows () | |
Enable the SQL_CALC_FOUND_ROWS option. | |
caller ( $fname) | |
Set the method name to be included in an SQL comment. | |
clearFields () | |
Remove all fields from the query. | |
conds ( $conds) | |
Add conditions to the query. | |
connection (IReadableDatabase $db) | |
Change the IReadableDatabase object the query builder is bound to. | |
distinct () | |
Enable the DISTINCT option. | |
estimateRowCount () | |
Estimate the number of rows in dataset. | |
explain () | |
Make the query be an EXPLAIN SELECT query instead of a SELECT query. | |
fetchField () | |
Run the constructed SELECT query, and return a single field extracted from the first result row. | |
fetchFieldValues () | |
Run the constructed SELECT query, and extract a single field from each result row, returning an array containing all the values. | |
fetchResultSet () | |
Run the constructed SELECT query and return all results. | |
fetchRow () | |
Run the constructed SELECT query, and return the first result row. | |
fetchRowCount () | |
Run the SELECT query, and return the number of results. | |
field ( $field, $alias=null) | |
Add a single field to the query, optionally with an alias. | |
fields ( $fields) | |
Add a field or an array of fields to the query. | |
forUpdate () | |
Enable the FOR UPDATE option. | |
from ( $table, $alias=null) | |
Add a single table to the SELECT query. | |
getQueryInfo ( $joinsName='join_conds') | |
Get an associative array describing the query in terms of its raw parameters to IReadableDatabase::select(). | |
getSQL () | |
Get the SQL query string which would be used by fetchResultSet(). | |
groupBy ( $group) | |
Add a GROUP BY clause. | |
having ( $having) | |
Add a HAVING clause. | |
ignoreIndex ( $index) | |
Set the IGNORE INDEX option. | |
joinConds (array $joinConds) | |
Manually append to the $join_conds array which will be passed to IReadableDatabase::select(). | |
limit ( $limit) | |
Set the query limit. | |
lockInShareMode () | |
Enable the LOCK IN SHARE MODE option. | |
merge (SelectQueryBuilder $builder) | |
Merge another query builder with this one. | |
newJoinGroup () | |
Create a parenthesized group of joins which can be added to the object like a table. | |
newSubquery () | |
Get an empty SelectQueryBuilder which can be used to build a subquery of this query. | |
offset ( $offset) | |
Set the offset. | |
option ( $name, $value=null) | |
Manually set an option in the $options array to be passed to IReadableDatabase::select() | |
options (array $options) | |
Manually set multiple options in the $options array to be passed to IReadableDatabase::select(). | |
orderBy ( $fields, $direction=null) | |
Set the ORDER BY clause. | |
queryInfo ( $info) | |
Set the query parameters to the given values, appending to the values which were already set. | |
rawTables ( $tables) | |
Given a table or table array as might be passed to IReadableDatabase::select(), append it to the existing tables, interpreting nested arrays as join groups. | |
recency ( $recency) | |
select ( $fields) | |
Add a field or an array of fields to the query. | |
setMaxExecutionTime (int $time) | |
Set MAX_EXECUTION_TIME for queries. | |
smallResult () | |
Enable the SQL_SMALL_RESULT option. | |
straightJoinOption () | |
Enable the STRAIGHT_JOIN query option. | |
tables ( $tables) | |
Add multiple tables. | |
useIndex ( $index) | |
Set a USE INDEX option. | |
where ( $conds) | |
Add conditions to the query. | |
Public Member Functions inherited from Wikimedia\Rdbms\JoinGroupBase | |
join ( $table, $alias=null, $conds=[]) | |
Inner join a table or group of tables. | |
leftJoin ( $table, $alias=null, $conds=[]) | |
Left join a table or group of tables. | |
straightJoin ( $table, $alias=null, $conds=[]) | |
Straight join a table or group of tables. | |
table ( $table, $alias=null) | |
Add a single table or a single parenthesized group. | |
Public Attributes | |
const | SORT_ASC = 'ASC' |
sort the results in ascending order | |
const | SORT_DESC = 'DESC' |
sort the results in descending order | |
Protected Member Functions | |
getAutoAlias () | |
Get a table alias which is unique to this SelectQueryBuilder. | |
getCaller () | |
get the method name of the caller, for use in sub classes | |
Protected Attributes | |
IReadableDatabase IReadableDatabase | $db |
array | $options = [] |
The options to be passed to IReadableDatabase::select() | |
Protected Attributes inherited from Wikimedia\Rdbms\JoinGroupBase | |
array | $joinConds = [] |
string null | $lastAlias |
array | $tables = [] |
Build SELECT queries with a fluent interface.
Each query builder object must be used for a single database query only, and not be reused afterwards. To run multiple similar queries, you can create a query builder to set up most of your query, which you can use as a "template" to clone. You can then modify the cloned object for each individual query.
Note that the methods in this class are not stable to override. This class may be extended to create query builders for specific database tables, such \\MediaWiki\\Page\\PageSelectQueryBuilder
, whilst still providing the same fluent interface for adding arbitrary additional conditions and such.
Definition at line 30 of file SelectQueryBuilder.php.
Wikimedia\Rdbms\SelectQueryBuilder::__construct | ( | IReadableDatabase | $db | ) |
Only for use in subclasses.
To create a SelectQueryBuilder instance, use $db->newSelectQueryBuilder()
instead.
IReadableDatabase | $db |
Reimplemented in MediaWiki\Logging\LoggingSelectQueryBuilder, MediaWiki\Revision\ArchiveSelectQueryBuilder, and MediaWiki\Revision\RevisionSelectQueryBuilder.
Definition at line 77 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\$db.
Wikimedia\Rdbms\SelectQueryBuilder::acquireRowLocks | ( | ) |
Execute the query, but throw away the results.
This is intended for locking select queries. By calling this method, the caller is indicating that the query is only done to acquire locks on the selected rows. The field list is optional.
Either forUpdate() or lockInShareMode() must be called before calling this method.
Definition at line 922 of file SelectQueryBuilder.php.
Wikimedia\Rdbms\SelectQueryBuilder::andWhere | ( | $conds | ) |
Add conditions to the query.
Alias for where().
string|IExpression|array<string,?scalar|non-empty-array<int,?scalar>|RawSQLValue>|array<int,string|IExpression> | $conds |
Definition at line 353 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\where().
Referenced by SearchMySQL\queryFeatures().
Wikimedia\Rdbms\SelectQueryBuilder::bigResult | ( | ) |
Enable the SQL_BIG_RESULT option.
Definition at line 639 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\options().
Wikimedia\Rdbms\SelectQueryBuilder::bufferResult | ( | ) |
Enable the SQL_BUFFER_RESULT option.
Definition at line 649 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\options().
Wikimedia\Rdbms\SelectQueryBuilder::buildGroupConcatField | ( | $delim | ) |
Build a GROUP_CONCAT or equivalent statement for a query.
This is useful for combining a field for several rows into a single string. NULL values will not appear in the output, duplicated values will appear, and the resulting delimiter-separated values have no defined sort order. Code using the results may need to use the PHP unique() or sort() methods.
string | $delim |
Definition at line 857 of file SelectQueryBuilder.php.
Wikimedia\Rdbms\SelectQueryBuilder::calcFoundRows | ( | ) |
Enable the SQL_CALC_FOUND_ROWS option.
Definition at line 669 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\options().
Wikimedia\Rdbms\SelectQueryBuilder::caller | ( | $fname | ) |
Set the method name to be included in an SQL comment.
string | $fname |
Definition at line 723 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\caller().
Referenced by Wikimedia\Rdbms\SelectQueryBuilder\caller(), Wikimedia\Rdbms\SelectQueryBuilder\merge(), Wikimedia\Rdbms\SelectQueryBuilder\queryInfo(), and ApiQueryBase\select().
Wikimedia\Rdbms\SelectQueryBuilder::clearFields | ( | ) |
Remove all fields from the query.
Definition at line 284 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\fields().
Wikimedia\Rdbms\SelectQueryBuilder::conds | ( | $conds | ) |
Add conditions to the query.
Alias for where().
string|IExpression|array<string,?scalar|non-empty-array<int,?scalar>|RawSQLValue>|array<int,string|IExpression> | $conds |
Definition at line 364 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\where().
Referenced by Wikimedia\Rdbms\SelectQueryBuilder\merge(), Wikimedia\Rdbms\SelectQueryBuilder\where(), and MediaWiki\Page\PageSelectQueryBuilder\wherePageIds().
Wikimedia\Rdbms\SelectQueryBuilder::connection | ( | IReadableDatabase | $db | ) |
Change the IReadableDatabase object the query builder is bound to.
The specified IReadableDatabase will subsequently be used to execute the query.
IReadableDatabase | $db |
Definition at line 88 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\$db, and Wikimedia\Rdbms\IReadableDatabase\getType().
Wikimedia\Rdbms\SelectQueryBuilder::distinct | ( | ) |
Enable the DISTINCT option.
Return only unique result rows.
Definition at line 459 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\options().
Referenced by MediaWiki\ChangeTags\ChangeTagsStore\modifyDisplayQueryBuilder().
Wikimedia\Rdbms\SelectQueryBuilder::estimateRowCount | ( | ) |
Estimate the number of rows in dataset.
MySQL allows you to estimate the number of rows that would be returned by a SELECT query, using EXPLAIN SELECT. The estimate is provided using index cardinality statistics, and is notoriously inaccurate, especially when large numbers of rows have recently been added or deleted.
Definition at line 824 of file SelectQueryBuilder.php.
Wikimedia\Rdbms\SelectQueryBuilder::explain | ( | ) |
Make the query be an EXPLAIN SELECT query instead of a SELECT query.
Definition at line 619 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\options().
Wikimedia\Rdbms\SelectQueryBuilder::fetchField | ( | ) |
Run the constructed SELECT query, and return a single field extracted from the first result row.
This may only be called when only one field has been added to the builder.
Definition at line 757 of file SelectQueryBuilder.php.
Wikimedia\Rdbms\SelectQueryBuilder::fetchFieldValues | ( | ) |
Run the constructed SELECT query, and extract a single field from each result row, returning an array containing all the values.
This may only be called when only one field has been added to the builder.
Definition at line 775 of file SelectQueryBuilder.php.
Wikimedia\Rdbms\SelectQueryBuilder::fetchResultSet | ( | ) |
Run the constructed SELECT query and return all results.
Definition at line 744 of file SelectQueryBuilder.php.
Referenced by ApiQueryBase\select().
Wikimedia\Rdbms\SelectQueryBuilder::fetchRow | ( | ) |
Run the constructed SELECT query, and return the first result row.
If there were no results, return false.
Definition at line 792 of file SelectQueryBuilder.php.
Wikimedia\Rdbms\SelectQueryBuilder::fetchRowCount | ( | ) |
Run the SELECT query, and return the number of results.
This typically uses a subquery to discard the actual results on the server side, and is useful when counting rows with a limit.
To count rows without a limit, it's more efficient to use a normal COUNT() expression, for example:
$queryBuilder->select( 'COUNT(*)' )->from( 'page' )->fetchField()
Definition at line 809 of file SelectQueryBuilder.php.
Wikimedia\Rdbms\SelectQueryBuilder::field | ( | $field, | |
$alias = null ) |
Add a single field to the query, optionally with an alias.
The field is an SQL fragment. It is unsafe to pass user input to this function.
string | $field | |
string | null | $alias |
Definition at line 270 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\fields().
Referenced by MediaWiki\Revision\RevisionSelectQueryBuilder\joinUser(), and MediaWiki\ChangeTags\ChangeTagsStore\modifyDisplayQueryBuilder().
Wikimedia\Rdbms\SelectQueryBuilder::fields | ( | $fields | ) |
Add a field or an array of fields to the query.
Each field is an SQL fragment. If the array key is non-numeric, the key is taken to be an alias for the field.
string | string[] | $fields |
Definition at line 240 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\fields().
Referenced by Wikimedia\Rdbms\SelectQueryBuilder\clearFields(), Wikimedia\Rdbms\SelectQueryBuilder\field(), Wikimedia\Rdbms\SelectQueryBuilder\fields(), MediaWiki\Revision\ArchiveSelectQueryBuilder\joinComment(), MediaWiki\Revision\RevisionSelectQueryBuilder\joinComment(), MediaWiki\Revision\RevisionSelectQueryBuilder\joinPage(), Wikimedia\Rdbms\SelectQueryBuilder\merge(), Wikimedia\Rdbms\SelectQueryBuilder\queryInfo(), Wikimedia\Rdbms\SelectQueryBuilder\select(), and ApiQueryBase\select().
Wikimedia\Rdbms\SelectQueryBuilder::forUpdate | ( | ) |
Enable the FOR UPDATE option.
Lock the returned rows so that they can't be changed until the next COMMIT. Cannot be used with aggregate functions (COUNT, MAX, etc., but also DISTINCT).
Definition at line 449 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\options().
Referenced by Wikimedia\Rdbms\SelectQueryBuilder\recency().
Wikimedia\Rdbms\SelectQueryBuilder::from | ( | $table, | |
$alias = null ) |
Add a single table to the SELECT query.
Alias for table().
string | JoinGroup | SelectQueryBuilder | $table | Table reference; see table for details |
string | null | $alias | The table alias, or null for no alias |
Definition at line 206 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\JoinGroupBase\table().
|
protected |
Get a table alias which is unique to this SelectQueryBuilder.
Reimplemented from Wikimedia\Rdbms\JoinGroupBase.
Definition at line 386 of file SelectQueryBuilder.php.
Referenced by Wikimedia\Rdbms\SelectQueryBuilder\newJoinGroup().
|
finalprotected |
get the method name of the caller, for use in sub classes
Definition at line 734 of file SelectQueryBuilder.php.
Wikimedia\Rdbms\SelectQueryBuilder::getQueryInfo | ( | $joinsName = 'join_conds' | ) |
Get an associative array describing the query in terms of its raw parameters to IReadableDatabase::select().
This can be used to interface with legacy code.
string | $joinsName | The name of the join_conds key |
Definition at line 894 of file SelectQueryBuilder.php.
Referenced by ApiQueryBase\select().
Wikimedia\Rdbms\SelectQueryBuilder::getSQL | ( | ) |
Get the SQL query string which would be used by fetchResultSet().
Definition at line 872 of file SelectQueryBuilder.php.
Wikimedia\Rdbms\SelectQueryBuilder::groupBy | ( | $group | ) |
Add a GROUP BY clause.
May be either an SQL fragment string naming a field or expression to group by, or an array of such SQL fragments.
If there is an existing GROUP BY clause, the new one will be appended.
string | string[] | $group |
Definition at line 485 of file SelectQueryBuilder.php.
Wikimedia\Rdbms\SelectQueryBuilder::having | ( | $having | ) |
Add a HAVING clause.
May be either a string containing a HAVING clause or an array of conditions building the HAVING clause. If an array is given, the conditions constructed from each element are combined with AND.
If there is an existing HAVING clause, the new one will be appended.
string | string[] | $having |
Definition at line 502 of file SelectQueryBuilder.php.
Wikimedia\Rdbms\SelectQueryBuilder::ignoreIndex | ( | $index | ) |
Set the IGNORE INDEX option.
If a string is given, the index hint is applied to the most recently appended table or alias. If an array is given, it is assumed to be an associative array with the alias names in the keys and the indexes in the values, as in the IGNORE INDEX option to IReadableDatabase::select(). The array will be merged with the existing value.
string | string[] | $index |
Definition at line 583 of file SelectQueryBuilder.php.
Wikimedia\Rdbms\SelectQueryBuilder::joinConds | ( | array | $joinConds | ) |
Manually append to the $join_conds array which will be passed to IReadableDatabase::select().
This is not recommended for new code. Instead, join() and leftJoin() should be used.
array | $joinConds |
Definition at line 376 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\joinConds().
Referenced by Wikimedia\Rdbms\SelectQueryBuilder\joinConds(), Wikimedia\Rdbms\SelectQueryBuilder\merge(), Wikimedia\Rdbms\SelectQueryBuilder\queryInfo(), and ApiQueryBase\select().
Wikimedia\Rdbms\SelectQueryBuilder::limit | ( | $limit | ) |
Set the query limit.
Return at most this many rows. The rows are sorted and then the first rows are taken until the limit is reached. Limit is applied to a result set after offset.
If the query builder already has a limit, the old limit will be discarded.
int | $limit |
Definition at line 425 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\options().
Wikimedia\Rdbms\SelectQueryBuilder::lockInShareMode | ( | ) |
Enable the LOCK IN SHARE MODE option.
Lock the returned rows so that they can't be changed until the next COMMIT. Cannot be used with aggregate functions (COUNT, MAX, etc., but also DISTINCT).
Definition at line 437 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\options().
Referenced by Wikimedia\Rdbms\SelectQueryBuilder\recency().
Wikimedia\Rdbms\SelectQueryBuilder::merge | ( | SelectQueryBuilder | $builder | ) |
Merge another query builder with this one.
Append the other builder's tables, joins, fields, conditions and options to this one.
SelectQueryBuilder | $builder |
Definition at line 175 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\caller(), Wikimedia\Rdbms\SelectQueryBuilder\conds(), Wikimedia\Rdbms\SelectQueryBuilder\fields(), Wikimedia\Rdbms\SelectQueryBuilder\joinConds(), Wikimedia\Rdbms\SelectQueryBuilder\options(), Wikimedia\Rdbms\SelectQueryBuilder\rawTables(), Wikimedia\Rdbms\SelectQueryBuilder\tables(), and Wikimedia\Rdbms\SelectQueryBuilder\where().
Wikimedia\Rdbms\SelectQueryBuilder::newJoinGroup | ( | ) |
Create a parenthesized group of joins which can be added to the object like a table.
The group is initially empty.
Definition at line 396 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\getAutoAlias().
Wikimedia\Rdbms\SelectQueryBuilder::newSubquery | ( | ) |
Get an empty SelectQueryBuilder which can be used to build a subquery of this query.
Definition at line 192 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\$db.
Referenced by MediaWiki\Block\HideUserUtils\addFieldToBuilder().
Wikimedia\Rdbms\SelectQueryBuilder::offset | ( | $offset | ) |
Set the offset.
Skip this many rows at the start of the result set. Offset with limit() can theoretically be used for paging through a result set, but this is discouraged for performance reasons.
If the query builder already has an offset, the old offset will be discarded.
int | $offset |
Definition at line 410 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\options().
Wikimedia\Rdbms\SelectQueryBuilder::option | ( | $name, | |
$value = null ) |
Manually set an option in the $options array to be passed to IReadableDatabase::select()
string | $name | The option name |
mixed | $value | The option value, or null for a boolean option |
Definition at line 682 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\options().
Wikimedia\Rdbms\SelectQueryBuilder::options | ( | array | $options | ) |
Manually set multiple options in the $options array to be passed to IReadableDatabase::select().
array | $options |
Definition at line 698 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\options().
Referenced by Wikimedia\Rdbms\SelectQueryBuilder\bigResult(), Wikimedia\Rdbms\SelectQueryBuilder\bufferResult(), Wikimedia\Rdbms\SelectQueryBuilder\calcFoundRows(), Wikimedia\Rdbms\SelectQueryBuilder\distinct(), Wikimedia\Rdbms\SelectQueryBuilder\explain(), Wikimedia\Rdbms\SelectQueryBuilder\forUpdate(), Wikimedia\Rdbms\SelectQueryBuilder\limit(), Wikimedia\Rdbms\SelectQueryBuilder\lockInShareMode(), Wikimedia\Rdbms\SelectQueryBuilder\merge(), Wikimedia\Rdbms\SelectQueryBuilder\offset(), Wikimedia\Rdbms\SelectQueryBuilder\option(), Wikimedia\Rdbms\SelectQueryBuilder\options(), Wikimedia\Rdbms\SelectQueryBuilder\queryInfo(), ApiQueryBase\select(), Wikimedia\Rdbms\SelectQueryBuilder\setMaxExecutionTime(), Wikimedia\Rdbms\SelectQueryBuilder\smallResult(), and Wikimedia\Rdbms\SelectQueryBuilder\straightJoinOption().
Wikimedia\Rdbms\SelectQueryBuilder::orderBy | ( | $fields, | |
$direction = null ) |
Set the ORDER BY clause.
If it has already been set, append the additional fields to it.
string[] | string | $fields | The field or list of fields to order by. |
string | null | $direction | Sorting direction applied to all fields, self::SORT_ASC or self::SORT_DESC. If different fields need to be sorted in opposite directions, then this parameter must be omitted, and $fields must contain 'ASC' or 'DESC' after each field name. |
Definition at line 520 of file SelectQueryBuilder.php.
Wikimedia\Rdbms\SelectQueryBuilder::queryInfo | ( | $info | ) |
Set the query parameters to the given values, appending to the values which were already set.
This can be used to interface with legacy code. If a key is omitted, the previous value will be retained.
The parameters must be formatted as required by IReadableDatabase::select. For example, JoinGroup cannot be used.
array | $info | Associative array of query info, with keys:
|
Definition at line 117 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\caller(), Wikimedia\Rdbms\SelectQueryBuilder\fields(), Wikimedia\Rdbms\SelectQueryBuilder\joinConds(), Wikimedia\Rdbms\SelectQueryBuilder\options(), Wikimedia\Rdbms\SelectQueryBuilder\rawTables(), and Wikimedia\Rdbms\SelectQueryBuilder\where().
Referenced by ApiQueryBase\select().
Wikimedia\Rdbms\SelectQueryBuilder::rawTables | ( | $tables | ) |
Given a table or table array as might be passed to IReadableDatabase::select(), append it to the existing tables, interpreting nested arrays as join groups.
This can be used to interface with existing code that expresses join groups as nested arrays. In new code, join groups should generally be created with newJoinGroup(), which provides a fluent interface.
string | array | $tables | Table references; see IReadableDatabase::select for details |
Definition at line 155 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\JoinGroupBase\$tables, and Wikimedia\Rdbms\SelectQueryBuilder\tables().
Referenced by Wikimedia\Rdbms\SelectQueryBuilder\merge(), Wikimedia\Rdbms\SelectQueryBuilder\queryInfo(), and ApiQueryBase\select().
Wikimedia\Rdbms\SelectQueryBuilder::recency | ( | $recency | ) |
int | $recency | Bitfield of IDBAccessObject::READ_* constants |
Definition at line 707 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\forUpdate(), and Wikimedia\Rdbms\SelectQueryBuilder\lockInShareMode().
Wikimedia\Rdbms\SelectQueryBuilder::select | ( | $fields | ) |
Add a field or an array of fields to the query.
Alias for fields().
string | string[] | $fields |
Definition at line 256 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\fields().
Referenced by MediaWiki\Logging\LoggingSelectQueryBuilder\__construct(), MediaWiki\Revision\ArchiveSelectQueryBuilder\__construct(), MediaWiki\Revision\RevisionSelectQueryBuilder\__construct(), and MediaWiki\Block\HideUserUtils\addFieldToBuilder().
Wikimedia\Rdbms\SelectQueryBuilder::setMaxExecutionTime | ( | int | $time | ) |
Set MAX_EXECUTION_TIME for queries.
int | $time | maximum allowed time in milliseconds |
Definition at line 470 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\options().
Wikimedia\Rdbms\SelectQueryBuilder::smallResult | ( | ) |
Enable the SQL_SMALL_RESULT option.
Definition at line 659 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\options().
Wikimedia\Rdbms\SelectQueryBuilder::straightJoinOption | ( | ) |
Enable the STRAIGHT_JOIN query option.
Definition at line 629 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\options().
Wikimedia\Rdbms\SelectQueryBuilder::tables | ( | $tables | ) |
Add multiple tables.
It's recommended to use join() and leftJoin() instead in new code.
string[] | $tables | Table references (string keys are aliases). See table for details. |
Definition at line 218 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\JoinGroupBase\$tables, and Wikimedia\Rdbms\JoinGroupBase\table().
Referenced by Wikimedia\Rdbms\SelectQueryBuilder\merge(), and Wikimedia\Rdbms\SelectQueryBuilder\rawTables().
Wikimedia\Rdbms\SelectQueryBuilder::useIndex | ( | $index | ) |
Set a USE INDEX option.
If a string is given, the index hint is applied to the most recently appended table or alias. If an array is given, it is assumed to be an associative array with the alias names in the keys and the indexes in the values, as in the USE INDEX option to IReadableDatabase::select(). The array will be merged with the existing value.
string | string[] | $index |
Definition at line 565 of file SelectQueryBuilder.php.
Wikimedia\Rdbms\SelectQueryBuilder::where | ( | $conds | ) |
Add conditions to the query.
The supplied conditions will be appended to the existing conditions, separated by AND.
string|IExpression|array<string,?scalar|non-empty-array<int,?scalar>|RawSQLValue>|array<int,string|IExpression> | $conds |
May be either a string containing a single condition, or an array of conditions. If an array is given, the conditions constructed from each element are combined with AND.
Array elements may take one of two forms:
Note that expressions are often DBMS-dependent in their syntax. DBMS-independent wrappers are provided for constructing several types of expression commonly used in condition queries. See:
Untrusted user input is safe in the values of string keys, however untrusted input must not be used in the array key names or in the values of numeric keys. Escaping of untrusted input used in values of numeric keys should be done via IReadableDatabase::addQuotes()
Definition at line 326 of file SelectQueryBuilder.php.
References Wikimedia\Rdbms\SelectQueryBuilder\conds(), and Wikimedia\Rdbms\Platform\ISQLPlatform\LIST_AND.
Referenced by Wikimedia\Rdbms\SelectQueryBuilder\andWhere(), Wikimedia\Rdbms\SelectQueryBuilder\conds(), Wikimedia\Rdbms\SelectQueryBuilder\merge(), MediaWiki\ChangeTags\ChangeTagsStore\modifyDisplayQueryBuilder(), Wikimedia\Rdbms\SelectQueryBuilder\queryInfo(), and ApiQueryBase\select().
|
protected |
Definition at line 69 of file SelectQueryBuilder.php.
Referenced by Wikimedia\Rdbms\SelectQueryBuilder\__construct(), MediaWiki\Logging\LoggingSelectQueryBuilder\__construct(), MediaWiki\Revision\ArchiveSelectQueryBuilder\__construct(), MediaWiki\Revision\RevisionSelectQueryBuilder\__construct(), MediaWiki\User\UserSelectQueryBuilder\__construct(), MediaWiki\Page\PageSelectQueryBuilder\__construct(), MediaWiki\FileRepo\File\FileSelectQueryBuilder\__construct(), Wikimedia\Rdbms\SelectQueryBuilder\connection(), and Wikimedia\Rdbms\SelectQueryBuilder\newSubquery().
|
protected |
The options to be passed to IReadableDatabase::select()
Definition at line 56 of file SelectQueryBuilder.php.
Referenced by MediaWiki\FileRepo\File\FileSelectQueryBuilder\__construct().
const Wikimedia\Rdbms\SelectQueryBuilder::SORT_ASC = 'ASC' |
sort the results in ascending order
Definition at line 33 of file SelectQueryBuilder.php.
const Wikimedia\Rdbms\SelectQueryBuilder::SORT_DESC = 'DESC' |
sort the results in descending order
Definition at line 36 of file SelectQueryBuilder.php.