Drupal 8  8.0.2
Select Class Reference
Inheritance diagram for Select:

Public Member Functions

 orderRandom ()
 
 orderBy ($field, $direction= 'ASC')
 
 addExpression ($expression, $alias=NULL, $arguments=array())
 
 execute ()
 
- Public Member Functions inherited from Select
 __construct ($table, $alias=NULL, Connection $connection, $options=array())
 
 addTag ($tag)
 
 hasTag ($tag)
 
 hasAllTags ()
 
 hasAnyTag ()
 
 addMetaData ($key, $object)
 
 getMetaData ($key)
 
 arguments ()
 
 compile (Connection $connection, PlaceholderInterface $queryPlaceholder)
 
 compiled ()
 
 havingCondition ($field, $value=NULL, $operator=NULL)
 
havingConditions ()
 
 havingArguments ()
 
 having ($snippet, $args=array())
 
 havingCompile (Connection $connection)
 
 extend ($extender_name)
 
 havingIsNull ($field)
 
 havingIsNotNull ($field)
 
 havingExists (SelectInterface $select)
 
 havingNotExists (SelectInterface $select)
 
 forUpdate ($set=TRUE)
 
getFields ()
 
getExpressions ()
 
getOrderBy ()
 
getGroupBy ()
 
getTables ()
 
getUnion ()
 
 escapeLike ($string)
 
 escapeField ($string)
 
 getArguments (PlaceholderInterface $queryPlaceholder=NULL)
 
 isPrepared ()
 
 preExecute (SelectInterface $query=NULL)
 
 execute ()
 
 distinct ($distinct=TRUE)
 
 addField ($table_alias, $field, $alias=NULL)
 
 fields ($table_alias, array $fields=array())
 
 addExpression ($expression, $alias=NULL, $arguments=array())
 
 join ($table, $alias=NULL, $condition=NULL, $arguments=array())
 
 innerJoin ($table, $alias=NULL, $condition=NULL, $arguments=array())
 
 leftJoin ($table, $alias=NULL, $condition=NULL, $arguments=array())
 
 rightJoin ($table, $alias=NULL, $condition=NULL, $arguments=array())
 
 addJoin ($type, $table, $alias=NULL, $condition=NULL, $arguments=array())
 
 orderBy ($field, $direction= 'ASC')
 
 orderRandom ()
 
 range ($start=NULL, $length=NULL)
 
 union (SelectInterface $query, $type= '')
 
 groupBy ($field)
 
 countQuery ()
 
 __toString ()
 
 __clone ()
 
- Public Member Functions inherited from Query
 __construct (Connection $connection, $options)
 
 __sleep ()
 
 __wakeup ()
 
 __clone ()
 
 __toString ()
 
 uniqueIdentifier ()
 
 nextPlaceholder ()
 
 comment ($comment)
 
getComments ()
 
- Public Member Functions inherited from ConditionInterface
 condition ($field, $value=NULL, $operator= '=')
 
 where ($snippet, $args=array())
 
 isNull ($field)
 
 isNotNull ($field)
 
 exists (SelectInterface $select)
 
 notExists (SelectInterface $select)
 
conditions ()
 
 conditionGroupFactory ($conjunction= 'AND')
 
 andConditionGroup ()
 
 orConditionGroup ()
 

Additional Inherited Members

- Protected Member Functions inherited from Select
 prepareCountQuery ()
 
- Protected Member Functions inherited from Query
 execute ()
 
- Protected Attributes inherited from Select
 $fields = array()
 
 $expressions = array()
 
 $tables = array()
 
 $order = array()
 
 $group = array()
 
 $having
 
 $distinct = FALSE
 
 $range
 
 $union = array()
 
 $prepared = FALSE
 
 $forUpdate = FALSE
 
- Protected Attributes inherited from Query
 $connection
 
 $connectionTarget
 
 $connectionKey
 
 $queryOptions
 
 $uniqueIdentifier
 
 $nextPlaceholder = 0
 
 $comments = array()
 

Detailed Description

PostgreSQL implementation of .

Member Function Documentation

addExpression (   $expression,
  $alias = NULL,
  $arguments = array() 
)

{Adds an expression to the list of "fields" to be SELECTed.An expression can be any arbitrary string that is valid SQL. That includes various functions, which may in some cases be database-dependent. This method makes no effort to correct for database-specific functions.

Parameters
$expressionThe expression string. May contain placeholders.
$aliasThe alias for this expression. If not specified, one will be generated automatically in the form "expression_#". The alias will be checked for uniqueness, so the requested alias may not be the alias that is assigned in all cases.
$argumentsAny placeholder arguments needed for this expression.
Returns
The unique alias that was assigned for this expression.
}

Implements SelectInterface.

Referenced by Select\orderRandom().

Here is the caller graph for this function:

execute ( )

{Runs the query against the database.

Returns
|null A prepared statement, or NULL if the query is not valid.
}

Implements SelectInterface.

orderBy (   $field,
  $direction = 'ASC' 
)

Overrides SelectQuery::orderBy().

PostgreSQL adheres strictly to the SQL-92 standard and requires that when using DISTINCT or GROUP BY conditions, fields and expressions that are ordered on also need to be selected. This is a best effort implementation to handle the cases that can be automated by adding the field if it is not yet selected.

$query = db_select('example', 'e');
$query->join('example_revision', 'er', 'e.vid = er.vid');
$query
->distinct()
->fields('e')
->orderBy('timestamp');

In this query, it is not possible (without relying on the schema) to know whether timestamp belongs to example_revision and needs to be added or belongs to node and is already selected. Queries like this will need to be corrected in the original query by adding an explicit call to SelectQuery::addField() or SelectQuery::fields().

Since this has a small performance impact, both by the additional processing in this function and in the database that needs to return the additional fields, this is done as an override instead of implementing it directly in SelectQuery::orderBy().

Implements SelectInterface.

References Select\addField(), Select\fields(), and Select\hasTag().

Referenced by Select\orderRandom().

Here is the call graph for this function:

Here is the caller graph for this function:

orderRandom ( )

Orders the result set by a random value.

This may be stacked with other orderBy() calls. If so, the query will order by each specified field, including this one, in the order called. Although this method may be called multiple times on the same query, doing so is not particularly useful.

Note: The method used by most drivers may not scale to very large result sets. If you need to work with extremely large data sets, you may create your own database driver by subclassing off of an existing driver and implementing your own randomization mechanism. See

http://jan.kneschke.de/projects/mysql/order-by-rand/

for an example of such an alternate sorting mechanism.

Returns
The called object

Implements SelectInterface.

References Select\addExpression(), and Select\orderBy().

Here is the call graph for this function:


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