mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #11616 from cakephp/issue-11186
Fix missing field identifier quoting for COUNT(DISTINCT in SQLServer.
This commit is contained in:
commit
df9c7fd96e
2 changed files with 8 additions and 0 deletions
|
@ -302,6 +302,10 @@ class Sqlserver extends DboSource {
|
|||
$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 @@ class SqlserverTest extends CakeTestCase {
|
|||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue