mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Adding DboSource fix for SELECT DISTINCT, fixes #4101
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6472 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
3140144a1f
commit
c1251c8265
2 changed files with 11 additions and 4 deletions
|
@ -1595,20 +1595,20 @@ class DboSource extends DataSource {
|
|||
$prepend = '';
|
||||
|
||||
if (strpos($fields[$i], 'DISTINCT') !== false) {
|
||||
$prepend = 'DISTINCT ';
|
||||
$prepend = 'DISTINCT ';
|
||||
$fields[$i] = trim(str_replace('DISTINCT', '', $fields[$i]));
|
||||
}
|
||||
$dot = strpos($fields[$i], '.');
|
||||
|
||||
if ($dot === false) {
|
||||
$fields[$i] = $prepend . $this->name($alias . '.' . $fields[$i]);
|
||||
$fields[$i] = $this->name($alias . '.' . $fields[$i]);
|
||||
} else {
|
||||
$value = array();
|
||||
$comma = strpos($fields[$i], ',');
|
||||
if ($comma === false) {
|
||||
$build = explode('.', $fields[$i]);
|
||||
if (!Set::numeric($build)) {
|
||||
$fields[$i] = $prepend . $this->name($build[0] . '.' . $build[1]);
|
||||
$fields[$i] = $this->name($build[0] . '.' . $build[1]);
|
||||
}
|
||||
$comma = String::tokenize($fields[$i]);
|
||||
foreach ($comma as $string) {
|
||||
|
@ -1616,12 +1616,13 @@ class DboSource extends DataSource {
|
|||
$value[] = $string;
|
||||
} else {
|
||||
$build = explode('.', $string);
|
||||
$value[] = $prepend . $this->name(trim($build[0]) . '.' . trim($build[1]));
|
||||
$value[] = $this->name(trim($build[0]) . '.' . trim($build[1]));
|
||||
}
|
||||
}
|
||||
$fields[$i] = implode(', ', $value);
|
||||
}
|
||||
}
|
||||
$fields[$i] = $prepend . $fields[$i];
|
||||
} elseif (preg_match('/\(([\.\w]+)\)/', $fields[$i], $field)) {
|
||||
if (isset($field[1])) {
|
||||
if (strpos($field[1], '.') === false) {
|
||||
|
|
|
@ -1326,6 +1326,12 @@ class DboSourceTest extends CakeTestCase {
|
|||
return $result;
|
||||
}
|
||||
|
||||
function testSelectDistict() {
|
||||
$result = $this->db->fields($this->Model, 'Vendor', "DISTINCT Vendor.id, Vendor.name");
|
||||
$expected = array('DISTINCT `Vendor`.`id`', '`Vendor`.`name`');
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
function testStringConditionsParsing() {
|
||||
$result = $this->db->conditions("ProjectBid.project_id = Project.id");
|
||||
$expected = " WHERE `ProjectBid`.`project_id` = `Project`.`id`";
|
||||
|
|
Loading…
Add table
Reference in a new issue