Expanded class hierarchy of Select
class Select extends QuerySelect {
public function orderRandom() {
$alias = $this
->addExpression('RANDOM()', 'random_field');
$this
->orderBy($alias);
return $this;
}
/**
* 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.
*
* @code
* $query = db_select('example', 'e');
* $query->join('example_revision', 'er', 'e.vid = er.vid');
* $query
* ->distinct()
* ->fields('e')
* ->orderBy('timestamp');
* @endcode
*
* 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().
*/
public function orderBy($field, $direction = 'ASC') {
// Call parent function to order on this.
$return = parent::orderBy($field, $direction);
// If there is a table alias specified, split it up.
if (strpos($field, '.') !== FALSE) {
list($table, $table_field) = explode('.', $field);
}
// Figure out if the field has already been added.
foreach ($this->fields as $existing_field) {
if (!empty($table)) {
// If table alias is given, check if field and table exists.
if ($existing_field['table'] == $table && $existing_field['field'] == $table_field) {
return $return;
}
}
else {
// If there is no table, simply check if the field exists as a field or
// an aliased field.
if ($existing_field['alias'] == $field) {
return $return;
}
}
}
// Also check expression aliases.
foreach ($this->expressions as $expression) {
if ($expression['alias'] == $field) {
return $return;
}
}
// If a table loads all fields, it can not be added again. It would
// result in an ambigious alias error because that field would be loaded
// twice: Once through table_alias.* and once directly. If the field
// actually belongs to a different table, it must be added manually.
foreach ($this->tables as $table) {
if (!empty($table['all_fields'])) {
return $return;
}
}
// If $field contains an characters which are not allowed in a field name
// it is considered an expression, these can't be handeld automatically
// either.
if ($this->connection
->escapeField($field) != $field) {
return $return;
}
// This is a case that can be handled automatically, add the field.
$this
->addField(NULL, $field);
return $return;
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Query:: |
protected | property | An array of comments that can be prepended to a query. | |
Query:: |
protected | property | The connection object on which to run this query. | |
Query:: |
protected | property | The key of the connection object. | |
Query:: |
protected | property | The target of the connection object. | |
Query:: |
protected | property | The placeholder counter. | |
Query:: |
protected | property | The query options to pass on to the connection object. | |
Query:: |
protected | property | A unique identifier for this query object. | |
Query:: |
public | function | Adds a comment to the query. | |
Query:: |
public | function | Returns a reference to the comments array for the query. | |
Query:: |
public | function |
Gets the next placeholder value for this query object. Overrides PlaceholderInterface:: |
|
Query:: |
public | function |
Returns a unique identifier for this object. Overrides PlaceholderInterface:: |
|
Query:: |
public | function | Implements the magic __sleep function to disconnect from the database. | |
Query:: |
public | function | Implements the magic __wakeup function to reconnect to the database. | |
Select:: |
protected | property | Whether or not this query should be DISTINCT | |
Select:: |
protected | property | The expressions to SELECT as virtual fields. | |
Select:: |
protected | property | The fields to SELECT. | |
Select:: |
protected | property | The FOR UPDATE status | 1 |
Select:: |
protected | property | The fields by which to group. | |
Select:: |
protected | property | The conditional object for the HAVING clause. | |
Select:: |
protected | property | The fields by which to order this query. | |
Select:: |
protected | property | Indicates if preExecute() has already been called. | |
Select:: |
protected | property | The range limiters for this query. | |
Select:: |
protected | property | The tables against which to JOIN. | |
Select:: |
protected | property | An array whose elements specify a query to UNION, and the UNION type. The 'type' key may be '', 'ALL', or 'DISTINCT' to represent a 'UNION', 'UNION ALL', or 'UNION DISTINCT'… | |
Select:: |
protected | property | The conditional object for the WHERE clause. | |
Select:: |
public | function |
Adds an expression to the list of "fields" to be SELECTed. Overrides SelectInterface:: |
|
Select:: |
public | function |
Adds a field to the list to be SELECTed. Overrides SelectInterface:: |
|
Select:: |
public | function |
Join against another table in the database. Overrides SelectInterface:: |
|
Select:: |
public | function |
Adds additional metadata to the query. Overrides AlterableInterface:: |
|
Select:: |
public | function |
Adds a tag to a query. Overrides AlterableInterface:: |
|
Select:: |
public | function |
Gets a complete list of all values to insert into the prepared statement. Overrides ConditionInterface:: |
|
Select:: |
public | function |
Compiles the saved conditions for later retrieval. Overrides ConditionInterface:: |
|
Select:: |
public | function |
Check whether a condition has been previously compiled. Overrides ConditionInterface:: |
|
Select:: |
public | function |
Helper function: builds the most common conditional clauses. Overrides ConditionInterface:: |
|
Select:: |
public | function |
Gets a complete list of all conditions in this conditional clause. Overrides ConditionInterface:: |
|
Select:: |
public | function |
Implements SelectInterface::countQuery(). Overrides SelectInterface:: |
|
Select:: |
public | function |
Sets this query to be DISTINCT. Overrides SelectInterface:: |
|
Select:: |
public | function |
Runs the query against the database. Overrides Query:: |
|
Select:: |
public | function |
Sets a condition that the specified subquery returns values. Overrides ConditionInterface:: |
|
Select:: |
public | function |
Enhance this object by wrapping it in an extender object. Overrides ExtendableInterface:: |
|
Select:: |
public | function |
Add multiple fields from the same table to be SELECTed. Overrides SelectInterface:: |
|
Select:: |
public | function |
Add FOR UPDATE to the query. Overrides SelectInterface:: |
1 |
Select:: |
public | function |
Compiles and returns an associative array of the arguments for this prepared statement. Overrides SelectInterface:: |
|
Select:: |
public | function |
Returns a reference to the expressions array for this query. Overrides SelectInterface:: |
|
Select:: |
public | function |
Returns a reference to the fields array for this query. Overrides SelectInterface:: |
|
Select:: |
public | function |
Returns a reference to the group-by array for this query. Overrides SelectInterface:: |
|
Select:: |
public | function |
Retrieves a given piece of metadata. Overrides AlterableInterface:: |
|
Select:: |
public | function |
Returns a reference to the order by array for this query. Overrides SelectInterface:: |
|
Select:: |
public | function |
Returns a reference to the tables array for this query. Overrides SelectInterface:: |
|
Select:: |
public | function |
Returns a reference to the union queries for this query. This include
queries for UNION, UNION ALL, and UNION DISTINCT. Overrides SelectInterface:: |
|
Select:: |
public | function |
Groups the result set by the specified field. Overrides SelectInterface:: |
|
Select:: |
public | function |
Determines if a given query has all specified tags. Overrides AlterableInterface:: |
|
Select:: |
public | function |
Determines if a given query has any specified tag. Overrides AlterableInterface:: |
|
Select:: |
public | function |
Determines if a given query has a given tag. Overrides AlterableInterface:: |
|
Select:: |
public | function | ||
Select:: |
public | function | ||
Select:: |
public | function | ||
Select:: |
public | function |
Helper function to build most common HAVING conditional clauses. Overrides SelectInterface:: |
|
Select:: |
public | function | ||
Select:: |
public | function | ||
Select:: |
public | function | ||
Select:: |
public | function | ||
Select:: |
public | function | ||
Select:: |
public | function |
Inner Join against another table in the database. Overrides SelectInterface:: |
|
Select:: |
public | function |
Sets a condition that the specified field be NOT NULL. Overrides ConditionInterface:: |
|
Select:: |
public | function |
Sets a condition that the specified field be NULL. Overrides ConditionInterface:: |
|
Select:: |
public | function |
Indicates if preExecute() has already been called on that object. Overrides SelectInterface:: |
|
Select:: |
public | function |
Default Join against another table in the database. Overrides SelectInterface:: |
|
Select:: |
public | function |
Left Outer Join against another table in the database. Overrides SelectInterface:: |
|
Select:: |
public | function |
Sets a condition that the specified subquery returns no values. Overrides ConditionInterface:: |
|
Select:: |
public | function |
Overrides SelectQuery::orderBy(). Overrides Select:: |
|
Select:: |
public | function |
Orders the result set by a random value. Overrides Select:: |
|
Select:: |
public | function |
Generic preparation and validation for a SELECT query. Overrides SelectInterface:: |
|
Select:: |
protected | function | Prepares a count query from the current query object. | |
Select:: |
public | function |
Restricts a query to a given range in the result set. Overrides SelectInterface:: |
|
Select:: |
public | function |
Right Outer Join against another table in the database. Overrides SelectInterface:: |
|
Select:: |
public | function |
Add another Select query to UNION to this one. Overrides SelectInterface:: |
|
Select:: |
public | function |
Adds an arbitrary WHERE clause to the query. Overrides ConditionInterface:: |
|
Select:: |
public | function |
Implements the magic __clone function. Overrides Query:: |
|
Select:: |
public | function |
Constructs a Query object. Overrides Query:: |
|
Select:: |
public | function |
Implements PHP magic __toString method to convert the query to a string. Overrides Query:: |