MediaWiki master
Wikimedia\Rdbms\UnionQueryBuilder Class Reference

A query builder for UNION queries takes SelectQueryBuilder objects. More...

Public Member Functions

 __construct (IDatabase $db)
 To create a UnionQueryBuilder instance, use $db->newUnionQueryBuilder() instead.
 
 add (SelectQueryBuilder $selectQueryBuilder)
 Add a select query builder object to the list of union.
 
 all ()
 Enable UNION_ALL option, the default is UNION_DISTINCT.
 
 caller ( $fname)
 Set the method name to be included in an SQL comment.
 
 fetchField ()
 Run the constructed UNION query, and return a single field extracted from the first result row.
 
 fetchFieldValues ()
 Run the constructed UNION query, and extract a single field from each result row, returning an array containing all the values.
 
 fetchResultSet ()
 Run the constructed UNION query and return all results.
 
 fetchRow ()
 Run the constructed UNION query, and return the first result row.
 
 getSQL ()
 Get the SQL query string which would be used by fetchResultSet().
 
 limit ( $limit)
 Set the query limit.
 
 offset ( $offset)
 Set the offset.
 
 orderBy ( $fields, $direction=null)
 Set the ORDER BY clause.
 

Detailed Description

A query builder for UNION queries takes SelectQueryBuilder objects.

Any particular query builder object should only be used for a single database query, and not be reused afterwards.

Since
1.41

Definition at line 16 of file UnionQueryBuilder.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Rdbms\UnionQueryBuilder::__construct ( IDatabase $db)

To create a UnionQueryBuilder instance, use $db->newUnionQueryBuilder() instead.

Parameters
IDatabase$db

Definition at line 45 of file UnionQueryBuilder.php.

Member Function Documentation

◆ add()

Wikimedia\Rdbms\UnionQueryBuilder::add ( SelectQueryBuilder $selectQueryBuilder)

Add a select query builder object to the list of union.

Returns
$this

Definition at line 54 of file UnionQueryBuilder.php.

◆ all()

Wikimedia\Rdbms\UnionQueryBuilder::all ( )

Enable UNION_ALL option, the default is UNION_DISTINCT.

Returns
$this

Definition at line 64 of file UnionQueryBuilder.php.

References Wikimedia\Rdbms\UnionQueryBuilder\all().

Referenced by Wikimedia\Rdbms\UnionQueryBuilder\all(), and Wikimedia\Rdbms\UnionQueryBuilder\getSQL().

◆ caller()

Wikimedia\Rdbms\UnionQueryBuilder::caller ( $fname)

Set the method name to be included in an SQL comment.

Parameters
string$fname
Returns
$this

Definition at line 163 of file UnionQueryBuilder.php.

References Wikimedia\Rdbms\UnionQueryBuilder\caller().

Referenced by Wikimedia\Rdbms\UnionQueryBuilder\caller(), and Wikimedia\Rdbms\UnionQueryBuilder\fetchResultSet().

◆ fetchField()

Wikimedia\Rdbms\UnionQueryBuilder::fetchField ( )

Run the constructed UNION query, and return a single field extracted from the first result row.

If there were no result rows, false is returned. This may only be called when only one field has been added to the constituent queries.

Since
1.42
Returns
mixed

Definition at line 188 of file UnionQueryBuilder.php.

References Wikimedia\Rdbms\UnionQueryBuilder\fetchResultSet(), and Wikimedia\Rdbms\UnionQueryBuilder\limit().

◆ fetchFieldValues()

Wikimedia\Rdbms\UnionQueryBuilder::fetchFieldValues ( )

Run the constructed UNION 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 constituent queries.

Since
1.42
Returns
array

Definition at line 210 of file UnionQueryBuilder.php.

References Wikimedia\Rdbms\UnionQueryBuilder\fetchResultSet().

◆ fetchResultSet()

Wikimedia\Rdbms\UnionQueryBuilder::fetchResultSet ( )

◆ fetchRow()

Wikimedia\Rdbms\UnionQueryBuilder::fetchRow ( )

Run the constructed UNION query, and return the first result row.

If there were no results, return false.

Since
1.42
Returns
\stdClass|false

Definition at line 231 of file UnionQueryBuilder.php.

References Wikimedia\Rdbms\UnionQueryBuilder\fetchResultSet(), and Wikimedia\Rdbms\UnionQueryBuilder\limit().

◆ getSQL()

Wikimedia\Rdbms\UnionQueryBuilder::getSQL ( )

Get the SQL query string which would be used by fetchResultSet().

Since
1.42
Returns
string

Definition at line 245 of file UnionQueryBuilder.php.

References Wikimedia\Rdbms\UnionQueryBuilder\all().

Referenced by Wikimedia\Rdbms\UnionQueryBuilder\fetchResultSet().

◆ limit()

Wikimedia\Rdbms\UnionQueryBuilder::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. This would be also ignored if the DB does not support limit in union queries.

Parameters
int$limit
Returns
$this

Definition at line 80 of file UnionQueryBuilder.php.

Referenced by Wikimedia\Rdbms\UnionQueryBuilder\fetchField(), and Wikimedia\Rdbms\UnionQueryBuilder\fetchRow().

◆ offset()

Wikimedia\Rdbms\UnionQueryBuilder::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. This would be also ignored if the DB does not support offset in union queries.

Parameters
int$offset
Returns
$this

Definition at line 99 of file UnionQueryBuilder.php.

◆ orderBy()

Wikimedia\Rdbms\UnionQueryBuilder::orderBy ( $fields,
$direction = null )

Set the ORDER BY clause.

If it has already been set, append the additional fields to it.

This would be ignored if the DB does not support order by in union queries.

Parameters
string[] | string$fieldsThe field or list of fields to order by.
string | null$directionself::SORT_ASC or self::SORT_DESC. If this is null then $fields is assumed to optionally contain ASC or DESC after each field name.
Returns
$this

Definition at line 121 of file UnionQueryBuilder.php.


The documentation for this class was generated from the following file: