summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngie Byron2010-12-28 18:49:51 (GMT)
committerAngie Byron2010-12-28 18:49:51 (GMT)
commitfbd6ffbf52fad02951b3f37fd3bf1341f3670830 (patch)
tree2e98cefa3005f1d871fbcf24ee866d665dd8bf35
parentc719b1a5b332ea1051b612c5f8ffb99e789f4589 (diff)
#1005674 by solotandem: Fixed SelectQuery::countQuery() fails with a group by expression
-rw-r--r--includes/database/select.inc4
-rw-r--r--modules/simpletest/tests/database_test.test5
2 files changed, 6 insertions, 3 deletions
diff --git a/includes/database/select.inc b/includes/database/select.inc
index 9046afb..7f44063 100644
--- a/includes/database/select.inc
+++ b/includes/database/select.inc
@@ -1354,7 +1354,7 @@ class SelectQuery extends Query implements SelectQueryInterface {
}
public function groupBy($field) {
- $this->group[] = $field;
+ $this->group[$field] = $field;
return $this;
}
@@ -1362,7 +1362,7 @@ class SelectQuery extends Query implements SelectQueryInterface {
// Create our new query object that we will mutate into a count query.
$count = clone($this);
- $group_by = drupal_map_assoc(array_values($count->getGroupBy()));
+ $group_by = $count->getGroupBy();
if (!$count->distinct) {
// When not executing a distinct query, we can zero-out existing fields
diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test
index 32742e0..bfd67de 100644
--- a/modules/simpletest/tests/database_test.test
+++ b/modules/simpletest/tests/database_test.test
@@ -2033,10 +2033,13 @@ class DatabaseSelectComplexTestCase extends DatabaseTestCase {
$this->assertEqual($count, 3, t('Counted the correct number of records.'));
- // Test wth an alias.
+ // Use a column alias as, without one, the query can succeed for the wrong
+ // reason.
$query = db_select('test_task');
$pid_field = $query->addField('test_task', 'pid', 'pid_alias');
+ $query->addExpression('COUNT(test_task.task)', 'count');
$query->groupBy('pid_alias');
+ $query->orderBy('pid_alias', 'asc');
$count = $query->countQuery()->execute()->fetchField();