From 16be5722ba06e178050e4b8a568b124925cc7c4d Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 29 Oct 2013 23:01:20 -0400 Subject: [PATCH] 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. --- lib/Cake/Model/Datasource/Database/Sqlserver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Model/Datasource/Database/Sqlserver.php b/lib/Cake/Model/Datasource/Database/Sqlserver.php index cdf59610f..fac56101c 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlserver.php +++ b/lib/Cake/Model/Datasource/Database/Sqlserver.php @@ -278,7 +278,7 @@ class Sqlserver extends DboSource { 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])); }