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. More...
 
 add (SelectQueryBuilder $selectQueryBuilder)
 Add a select query builder object to the list of union. More...
 
 all ()
 Enable UNION_ALL option, the default is UNION_DISTINCT. More...
 
 caller ( $fname)
 Set the method name to be included in an SQL comment. More...
 
 fetchResultSet ()
 Run the constructed UNION query and return all results. More...
 
 limit ( $limit)
 Set the query limit. More...
 
 offset ( $offset)
 Set the offset. More...
 
 orderBy ( $fields, $direction=null)
 Set the ORDER BY clause. More...
 

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 39 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 48 of file UnionQueryBuilder.php.

◆ all()

Wikimedia\Rdbms\UnionQueryBuilder::all ( )

Enable UNION_ALL option, the default is UNION_DISTINCT.

Returns
$this

Definition at line 58 of file UnionQueryBuilder.php.

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

◆ 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 154 of file UnionQueryBuilder.php.

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

◆ fetchResultSet()

Wikimedia\Rdbms\UnionQueryBuilder::fetchResultSet ( )

Run the constructed UNION query and return all results.

Returns
IResultWrapper

Definition at line 164 of file UnionQueryBuilder.php.

References Wikimedia\Rdbms\UnionQueryBuilder\all(), and Wikimedia\Rdbms\UnionQueryBuilder\caller().

◆ 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 74 of file UnionQueryBuilder.php.

◆ 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 93 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 113 of file UnionQueryBuilder.php.


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