Skip to content
Permalink
Browse files

Fix missing field identifier quoting for COUNT(DISTINCT in SQLServer.

Refs #11186
  • Loading branch information...
markstory committed Jan 9, 2018
1 parent ab272b0 commit 45695b6b5cc358f12811fcadbdfe3c0b1a7e6b15
@@ -302,6 +302,10 @@ public function fields(Model $model, $alias = null, $fields = array(), $quote =
$prepend = 'DISTINCT ';
$fields[$i] = trim(str_replace('DISTINCT', '', $fields[$i]));
}
if (strpos($fields[$i], 'COUNT(DISTINCT') !== false) {
$prepend = 'COUNT(DISTINCT ';
$fields[$i] = trim(str_replace('COUNT(DISTINCT', '', $this->_quoteFields($fields[$i])));
}
if (!preg_match('/\s+AS\s+/i', $fields[$i])) {
if (substr($fields[$i], -1) === '*') {
@@ -383,6 +383,10 @@ public function testDistinctFields() {
$result = $this->db->fields($this->model, null, 'DISTINCT Car.country_code');
$expected = array('DISTINCT [Car].[country_code] AS [Car__country_code]');
$this->assertEquals($expected, $result);
$result = $this->db->fields($this->model, null, 'COUNT(DISTINCT Car.country_code)');
$expected = array('COUNT(DISTINCT [Car].[country_code]) AS [Car__country_code]');
$this->assertEquals($expected, $result);
}
/**

0 comments on commit 45695b6

Please sign in to comment.
You can’t perform that action at this time.