Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3485117
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
drupal-3485117
Commits
fbd6ffbf
Commit
fbd6ffbf
authored
14 years ago
by
Angie Byron
Browse files
Options
Downloads
Patches
Plain Diff
#1005674
by solotandem: Fixed SelectQuery::countQuery() fails with a group by expression
parent
c719b1a5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
includes/database/select.inc
+2
-2
2 additions, 2 deletions
includes/database/select.inc
modules/simpletest/tests/database_test.test
+4
-1
4 additions, 1 deletion
modules/simpletest/tests/database_test.test
with
6 additions
and
3 deletions
includes/database/select.inc
+
2
−
2
View file @
fbd6ffbf
...
...
@@ -1354,7 +1354,7 @@ public function union(SelectQueryInterface $query, $type = '') {
}
public
function
groupBy
(
$field
)
{
$this
->
group
[]
=
$field
;
$this
->
group
[
$field
]
=
$field
;
return
$this
;
}
...
...
@@ -1362,7 +1362,7 @@ public function countQuery() {
// 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
...
...
This diff is collapsed.
Click to expand it.
modules/simpletest/tests/database_test.test
+
4
−
1
View file @
fbd6ffbf
...
...
@@ -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
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment