mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: Make TableListField rely on SQLQuery for its count-generation.
BUGFIX: Make SQLQuery return an appropriate count if a HAVING clause is used. (from r95814) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@98094 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
afe433c9ab
commit
ce4067608c
@ -426,6 +426,12 @@ class SQLQuery {
|
|||||||
* TODO Respect HAVING and GROUPBY, which can affect the result-count
|
* TODO Respect HAVING and GROUPBY, which can affect the result-count
|
||||||
*/
|
*/
|
||||||
function unlimitedRowCount( $column = null) {
|
function unlimitedRowCount( $column = null) {
|
||||||
|
// we can't clear the select if we're relying on its output by a HAVING clause
|
||||||
|
if(count($this->having)) {
|
||||||
|
$records = $this->execute();
|
||||||
|
return $records->numRecords();
|
||||||
|
}
|
||||||
|
|
||||||
// Choose a default column
|
// Choose a default column
|
||||||
if($column == null) {
|
if($column == null) {
|
||||||
if($this->groupby) {
|
if($this->groupby) {
|
||||||
|
@ -852,23 +852,8 @@ JS
|
|||||||
if($this->customSourceItems) {
|
if($this->customSourceItems) {
|
||||||
return $this->customSourceItems->Count();
|
return $this->customSourceItems->Count();
|
||||||
}
|
}
|
||||||
$countQuery = $this->getQuery();
|
|
||||||
$countQuery->orderby = array();
|
|
||||||
$baseClass = ClassInfo::baseDataClass($this->sourceClass);
|
|
||||||
|
|
||||||
// we can't clear the select if we're relying on its output by a HAVING clause
|
$this->totalCount = $this->getQuery()->unlimitedRowCount();
|
||||||
if(count($countQuery->having) || count($countQuery->groupby)) {
|
|
||||||
$records = $countQuery->execute();
|
|
||||||
// TODO figure out how to use COUNT and GROUBY together to produce a single rowcount
|
|
||||||
$this->totalCount = $records->numRecords();
|
|
||||||
} else {
|
|
||||||
$countQuery->select = array();
|
|
||||||
$countQuery->groupby = array();
|
|
||||||
$countQuery->select[] = "COUNT(DISTINCT \"{$baseClass}\".\"ID\") AS \"TotalCount\"";
|
|
||||||
$records = $countQuery->execute();
|
|
||||||
$record = $records->nextRecord();
|
|
||||||
$this->totalCount = $record['TotalCount'];
|
|
||||||
}
|
|
||||||
return $this->totalCount;
|
return $this->totalCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user