DataQuery
class DataQuery
An object representing a query of data from the DataObject's supporting database.
Acts as a wrapper over {@link SQLQuery} and performs all of the query generation. Used extensively by {@link DataList}.
Unlike DataList, modifiers on DataQuery modify the object rather than returning a clone. DataList is immutable, DataQuery is mutable.
Methods
Create a new DataQuery.
Clone this object
Return the {@link DataObject} class that is being queried.
Return the {@link SQLQuery} object that represents the current query; note that it will be a clone of the object.
Remove a filter from the query
Set up the simplest initial query
No description
Ensure that the query is ready to execute.
Return this query's SQL
Return the number of records in this query.
Return the maximum value of the given field in this DataList
Return the minimum value of the given field in this DataList
Return the average value of the given field in this DataList
Return the sum of the values of the given field in this DataList
Runs a raw aggregate expression. Please handle escaping yourself
Return the first row that would be returned by this full DataQuery Note that this will issue a separate SELECT .
Return the last row that would be returned by this full DataQuery Note that this will issue a separate SELECT .
Append a GROUP BY clause to this query.
Append a HAVING clause to this query.
Create a disjunctive subgroup.
Create a conjunctive subgroup
Set the ORDER BY clause of this query
Reverse order by clause
Set the limit of this query.
Set whether this query should be distinct or not.
Add an INNER JOIN clause to this query.
Add a LEFT JOIN clause to this query.
Traverse the relationship fields, and add the table mappings to the query object state. This has to be called in any overloaded {@link SearchFilter->apply()} methods manually.
Select only the given fields from the given table.
Add the given fields from the given table to the select statement.
Query the given field column from the database and return as an array.
Set an arbitrary query parameter, that can be used by decorators to add additional meta-data to the query.
Set an arbitrary query parameter, that can be used by decorators to add additional meta-data to the query.
Returns all query parameters
Details
at line 48
__construct(string $dataClass)
Create a new DataQuery.
at line 56
__clone()
Clone this object
at line 65
string
dataClass()
Return the {@link DataObject} class that is being queried.
at line 75
SQLQuery
query()
Return the {@link SQLQuery} object that represents the current query; note that it will be a clone of the object.
at line 88
$this
removeFilterOn(string|array $fieldExpression)
Remove a filter from the query
at line 133
initialiseQuery()
Set up the simplest initial query
at line 170
$this
setQueriedColumns(array $queriedColumns)
at line 181
SQLQuery
getFinalisedQuery(array|null $queriedColumns = null)
Ensure that the query is ready to execute.
at line 377
SS_Query
execute()
Execute the query and return the result as {@link Query} object.
at line 387
string
sql(array $parameters = array())
Return this query's SQL
at line 397
int
count()
Return the number of records in this query.
Note that this will issue a separate SELECT COUNT() query.
at line 409
string
max(string $field)
Return the maximum value of the given field in this DataList
at line 424
string
min(string $field)
Return the minimum value of the given field in this DataList
at line 439
string
avg(string $field)
Return the average value of the given field in this DataList
at line 454
string
sum(string $field)
Return the sum of the values of the given field in this DataList
at line 468
string
aggregate(string $expression)
Runs a raw aggregate expression. Please handle escaping yourself
at line 478
SQLSelect
firstRow()
Return the first row that would be returned by this full DataQuery Note that this will issue a separate SELECT .
.. LIMIT 1 query.
at line 488
SQLSelect
lastRow()
Return the last row that would be returned by this full DataQuery Note that this will issue a separate SELECT .
.. LIMIT query.
at line 530
$this
groupby(string $groupby)
Append a GROUP BY clause to this query.
at line 541
$this
having(string $having)
Append a HAVING clause to this query.
at line 553
DataQuery_SubGroup
disjunctiveGroup()
Create a disjunctive subgroup.
That is a subgroup joined by OR
at line 564
DataQuery_SubGroup
conjunctiveGroup()
Create a conjunctive subgroup
That is a subgroup joined by AND
at line 578
$this
where(string|array|SQLConditionGroup $filter)
Adds a WHERE clause.
at line 595
$this
whereAny(string|array|SQLConditionGroup $filter)
Append a WHERE with OR.
at line 612
$this
sort(string $sort = null, string $direction = null, boolean $clear = true)
Set the ORDER BY clause of this query
at line 627
$this
reverseSort()
Reverse order by clause
at line 638
limit(int $limit, int $offset)
Set the limit of this query.
at line 649
$this
distinct(bool $value)
Set whether this query should be distinct or not.
at line 666
$this
innerJoin(string $table, string $onClause, string $alias = null, int $order = 20, array $parameters = array())
Add an INNER JOIN clause to this query.
at line 685
$this
leftJoin(string $table, string $onClause, string $alias = null, int $order = 20, array $parameters = array())
Add a LEFT JOIN clause to this query.
at line 700
string
applyRelation(string|array $relation)
Traverse the relationship fields, and add the table mappings to the query object state. This has to be called in any overloaded {@link SearchFilter->apply()} methods manually.
at line 784
$this
subtract(DataQuery $subtractQuery, string $field = 'ID')
Removes the result of query from this query.
at line 803
$this
selectFromTable(string $table, array $fields)
Select only the given fields from the given table.
at line 820
$this
addSelectFromTable(string $table, array $fields)
Add the given fields from the given table to the select statement.
at line 836
array
column(string $field = 'ID')
Query the given field column from the database and return as an array.
at line 895
$this
setQueryParam(string $key, mixed $value)
Set an arbitrary query parameter, that can be used by decorators to add additional meta-data to the query.
It's expected that the $key will be namespaced, e.g, 'Versioned.stage' instead of just 'stage'.
at line 906
mixed
getQueryParam(string $key)
Set an arbitrary query parameter, that can be used by decorators to add additional meta-data to the query.
at line 915
array
getQueryParams()
Returns all query parameters