mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API CHANGE: Added DataQuery::aggregate() to allow for aggregates beyond Min, Max, Avg, Sum.
This commit is contained in:
parent
5499079c1c
commit
780f2d2b16
@ -326,8 +326,8 @@ class DataQuery {
|
|||||||
*
|
*
|
||||||
* @param String $field Unquoted database column name (will be escaped automatically)
|
* @param String $field Unquoted database column name (will be escaped automatically)
|
||||||
*/
|
*/
|
||||||
function max($field) {
|
function max($field) {
|
||||||
return $this->getFinalisedQuery()->aggregate(sprintf('MAX("%s")', Convert::raw2sql($field)))->execute()->value();
|
return $this->aggregate(sprintf('MAX("%s")', Convert::raw2sql($field)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -336,7 +336,7 @@ class DataQuery {
|
|||||||
* @param String $field Unquoted database column name (will be escaped automatically)
|
* @param String $field Unquoted database column name (will be escaped automatically)
|
||||||
*/
|
*/
|
||||||
function min($field) {
|
function min($field) {
|
||||||
return $this->getFinalisedQuery()->aggregate(sprintf('MIN("%s")', Convert::raw2sql($field)))->execute()->value();
|
return $this->aggregate(sprintf('MIN("%s")', Convert::raw2sql($field)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -345,7 +345,7 @@ class DataQuery {
|
|||||||
* @param String $field Unquoted database column name (will be escaped automatically)
|
* @param String $field Unquoted database column name (will be escaped automatically)
|
||||||
*/
|
*/
|
||||||
function avg($field) {
|
function avg($field) {
|
||||||
return $this->getFinalisedQuery()->aggregate(sprintf('AVG("%s")', Convert::raw2sql($field)))->execute()->value();
|
return $this->aggregate(sprintf('AVG("%s")', Convert::raw2sql($field)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -354,7 +354,14 @@ class DataQuery {
|
|||||||
* @param String $field Unquoted database column name (will be escaped automatically)
|
* @param String $field Unquoted database column name (will be escaped automatically)
|
||||||
*/
|
*/
|
||||||
function sum($field) {
|
function sum($field) {
|
||||||
return $this->getFinalisedQuery()->aggregate(sprintf('SUM("%s")', Convert::raw2sql($field)))->execute()->value();
|
return $this->aggregate(sprintf('SUM("%s")', Convert::raw2sql($field)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs a raw aggregate expression. Please handle escaping yourself
|
||||||
|
*/
|
||||||
|
function aggregate($expression) {
|
||||||
|
return $this->getFinalisedQuery()->aggregate($expression)->execute()->value();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user