Query
class Query extends QueryBase implements QueryInterface (View source)
The SQL storage entity query class.
Properties
| protected string | $entityTypeId | The entity type this query runs against. |
from QueryBase |
| protected EntityTypeInterface | $entityType | Information about the entity type. |
from QueryBase |
| protected array | $sort | The list of sorts. |
from QueryBase |
| protected bool | $count | TRUE if this is a count query, FALSE if it isn't. |
from QueryBase |
| protected ConditionInterface | $condition | Conditions. | from QueryBase |
| protected array | $aggregate | The list of aggregate expressions. |
from QueryBase |
| protected array | $groupBy | The list of columns to group on. |
from QueryBase |
| protected ConditionAggregateInterface | $conditionAggregate | Aggregate Conditions |
from QueryBase |
| protected array | $sortAggregate | The list of sorts over the aggregate results. |
from QueryBase |
| protected array | $range | The query range. |
from QueryBase |
| protected array | $alterMetaData | The query metadata for alter purposes. |
from QueryBase |
| protected array | $alterTags | The query tags. |
from QueryBase |
| protected bool | $accessCheck | Whether access check is requested or not. Defaults to TRUE. |
from QueryBase |
| protected bool | $allRevisions | Flag indicating whether to query the current revision or all revisions. |
from QueryBase |
| protected bool | $latestRevision | Flag indicating whether to query the latest revision. |
from QueryBase |
| protected array | $pager | The query pager data. |
from QueryBase |
| protected array | $namespaces | List of potential namespaces of the classes belonging to this query. |
from QueryBase |
| protected SelectInterface | $sqlQuery | The build sql select query. |
|
| protected TablesInterface | $tables | The Tables object for this query. |
|
| protected array | $sqlFields | An array of fields keyed by the field alias. |
|
| protected array | $sqlGroupBy | An array of strings added as to the group by, keyed by the string to avoid duplicates. |
|
| protected Connection | $connection |
Methods
Constructs a query object.
Add a condition to the query or a condition group.
Creates an object holding a group of conditions.
Creates a new group of conditions ANDed together.
Creates a new group of conditions ORed together.
Gets the total number of results and initialize a pager for the query.
Implements the magic __clone method.
{@inheritdoc}
Generates an alias for a field and its aggregated function.
Gets a list of namespaces of the ancestors of a class.
Finds a class in a list of namespaces.
Execute the query.
Prepares the basic query with proper metadata/tags and base fields.
Compiles the conditions.
Adds the sort to the build query.
Finish the query by adding fields, GROUP BY and range.
Executes the query and returns the result.
Constructs a select expression for a given field and language.
Determines whether the query requires GROUP BY and ORDER BY MIN/MAX.
Implements the magic __toString method.
Details
__construct(EntityTypeInterface $entity_type, string $conjunction, Connection $connection, array $namespaces)
Constructs a query object.
string
getEntityTypeId()
Gets the ID of the entity type for this query.
$this
condition($property, $value = NULL, $operator = NULL, $langcode = NULL)
Add a condition to the query or a condition group.
For example, to find all entities containing both the Turkish 'merhaba' and the Polish 'siema' within a 'greetings' text field:
$this
exists($property, $langcode = NULL)
Queries for a non-empty value on a field.
$this
notExists($property, $langcode = NULL)
Queries for an empty field.
$this
range(null $start = NULL, null $length = NULL)
No description
protected ConditionInterface
conditionGroupFactory(string $conjunction = 'AND')
Creates an object holding a group of conditions.
See andConditionGroup() and orConditionGroup() for more.
ConditionInterface
andConditionGroup()
Creates a new group of conditions ANDed together.
For example, consider a drawing entity type with a 'figures' multi-value field containing 'shape' and 'color' columns. To find all drawings containing both a red triangle and a blue circle:
ConditionInterface
orConditionGroup()
Creates a new group of conditions ORed together.
For example, consider a map entity with an 'attributes' field containing 'building_type' and 'color' columns. To find all green and red bikesheds:
$this
sort($field, string $direction = 'ASC', $langcode = NULL)
No description
$this
count()
Makes this a count query.
For count queries, execute() returns the number entities found.
$this
accessCheck($access_check = TRUE)
No description
$this
currentRevision()
Queries the current revision.
$this
latestRevision()
Queries the latest revision.
The latest revision is the most recent revision of an entity. This will be either the default revision, or a pending revision if one exists and it is newer than the default.
$this
allRevisions()
Queries all the revisions.
$this
pager($limit = 10, $element = NULL)
Enables a pager for the query.
protected
initializePager()
Gets the total number of results and initialize a pager for the query.
The pager can be disabled by either setting the pager limit to 0, or by setting this query to be a count query.
$this
tableSort($headers)
Enables sortable tables for this query.
__clone()
Implements the magic __clone method.
Reset fields and GROUP BY when cloning.
$this
addTag($tag)
Adds a tag to a query.
Tags are strings that identify a query. A query may have any number of tags. Tags are used to mark a query so that alter hooks may decide if they wish to take action. Tags should be all lower-case and contain only letters, numbers, and underscore, and start with a letter. That is, they should follow the same rules as PHP identifiers in general.
true
hasTag($tag)
Determines if a given query has a given tag.
true
hasAllTags()
Determines if a given query has all specified tags.
Each tag to check should be supplied as a separate argument.
true
hasAnyTag()
Determines if a given query has any specified tag.
Each tag to check should be supplied as a separate argument.
$this
addMetaData($key, $object)
Adds additional metadata to the query.
Often, a query may need to provide additional contextual data to alter hooks. Alter hooks may then use that information to decide if and how to take action.
The
getMetaData($key)
Retrieves a given piece of metadata.
aggregate($field, $function, $langcode = NULL, $alias = NULL)
{@inheritdoc}
conditionAggregate($field, $function = NULL, $value = NULL, $operator = '=', $langcode = NULL)
{@inheritdoc}
sortAggregate($field, $function, $direction = 'ASC', $langcode = NULL)
{@inheritdoc}
groupBy($field, $langcode = NULL)
{@inheritdoc}
protected string
getAggregationAlias(string $field, string $function)
Generates an alias for a field and its aggregated function.
static array
getNamespaces($object)
Gets a list of namespaces of the ancestors of a class.
static string
getClass(array $namespaces, string $short_class_name)
Finds a class in a list of namespaces.
int|array
execute()
Execute the query.
protected $this
prepare()
Prepares the basic query with proper metadata/tags and base fields.
protected $this
compile()
Compiles the conditions.
protected $this
addSort()
Adds the sort to the build query.
protected $this
finish()
Finish the query by adding fields, GROUP BY and range.
protected int|array
result()
Executes the query and returns the result.
protected string
getSqlField(string $field, string $langcode)
Constructs a select expression for a given field and language.
protected bool
isSimpleQuery()
Determines whether the query requires GROUP BY and ORDER BY MIN/MAX.
TablesInterface
getTables(SelectInterface $sql_query)
Gets the Tables object for this query.
__toString()
Implements the magic __toString method.