Browse files

Fix COUNT(DISTINCT x) queries from getting corrupted in Sqlserver.

Add into the tower of hacks that is the SQL generation and stop breaking
COUNT(DISTINCT foo) style queries. Previously these would be converted
into DISTINCT COUNT(foo) which will give the non-distinct results.
  • Loading branch information...
1 parent 0f8dae5 commit 16be5722ba06e178050e4b8a568b124925cc7c4d @markstory markstory committed Oct 29, 2013
Showing with 1 addition and 1 deletion.
  1. +1 −1 lib/Cake/Model/Datasource/Database/Sqlserver.php
View
2 lib/Cake/Model/Datasource/Database/Sqlserver.php
@@ -278,7 +278,7 @@ public function fields(Model $model, $alias = null, $fields = array(), $quote =
for ($i = 0; $i < $count; $i++) {
$prepend = '';
- if (strpos($fields[$i], 'DISTINCT') !== false) {
+ if (strpos($fields[$i], 'DISTINCT') !== false && strpos($fields[$i], 'COUNT') === false) {
$prepend = 'DISTINCT ';
$fields[$i] = trim(str_replace('DISTINCT', '', $fields[$i]));
}

0 comments on commit 16be572

Please sign in to comment.