[Solar-svn] Revision 3175
pmjones at solarphp.com
pmjones at solarphp.com
Sat May 24 17:06:31 CDT 2008
Solar_Sql_Select: [FIX] In countPages(), track DISTINCT on the original query. DISTINCT with JOINs doesn't always work the same when you just have the one column (the counting column).
Modified: trunk/Solar/Sql/Select.php
===================================================================
--- trunk/Solar/Sql/Select.php 2008-05-24 14:45:12 UTC (rev 3174)
+++ trunk/Solar/Sql/Select.php 2008-05-24 22:06:31 UTC (rev 3175)
@@ -1202,6 +1202,14 @@
} else {
+ // track distinctness
+ if ($select->_parts['distinct']) {
+ $distinct = 'DISTINCT ';
+ $select->distinct(false);
+ } else {
+ $distinct = '';
+ }
+
// "normal" case (no grouping, and no count condition in WHERE or
// HAVING). add the one column we're counting on...
$select->_addSource(
@@ -1210,7 +1218,7 @@
null, // orig
null, // join
null, // cond
- "COUNT($col)"
+ "COUNT($distinct$col)"
);
// ... and do the count.
@@ -1273,12 +1281,20 @@
$alias = 'subselect';
}
+ // track distinctness
+ if ($inner->_parts['distinct']) {
+ $distinct = 'DISTINCT ';
+ $inner->distinct(false);
+ } else {
+ $distinct = '';
+ }
+
// build the outer select, which will do the actual count.
// wrapping with an outer select lets us have all manner of weirdness
// in the inner query, so that it doesn't conflict with the count.
$outer = clone($this);
$outer->clear();
- $outer->fromSelect($inner, $alias, "COUNT($alias.$col)");
+ $outer->fromSelect($inner, $alias, "COUNT($distinct$alias.$col)");
// get the count
return $outer->fetchValue();
More information about the Solar-svn
mailing list