Issue 1023 - Bug when paging query with outer join and distinct.

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@10299 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ucorina 2012-03-02 15:17:18 +00:00
parent fef0e92afd
commit ad88ec5f8c
4 changed files with 38 additions and 1 deletions

View file

@ -467,7 +467,16 @@
// Total count
$temp_where = $queryObject->getWhereString(true, false);
$count_query = sprintf('select count(*) as "count" %s %s', 'FROM ' . $queryObject->getFromString(), ($temp_where === '' ? '' : ' WHERE '. $temp_where));
if ($queryObject->getGroupByString() != '') {
// Check for distinct query and if found update count query structure
$temp_select = $queryObject->getSelectString();
if(strpos(strtolower($temp_select), "distinct") !== false) {
$count_query = sprintf('select %s %s %s', 'FROM ' . $queryObject->getFromString(), $temp_select, ($temp_where === '' ? '' : ' WHERE '. $temp_where));
$uses_distinct = true;
}
// If query uses grouping or distinct, count from original select
if ($queryObject->getGroupByString() != '' || $uses_distinct) {
$count_query = sprintf('select count(*) as "count" from (%s) xet', $count_query);
}