From 8fc104b44bd71153a7eae1401b36c259c18a6c21 Mon Sep 17 00:00:00 2001 From: nate Date: Sun, 9 Mar 2008 22:15:08 +0000 Subject: [PATCH] Correcting column quoting for custom-aliased fields, fixes #4228 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6543 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/dbo_source.php | 3 +++ .../cases/libs/model/datasources/dbo_source.test.php | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 2dacdcf2d..358ed92be 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -360,6 +360,9 @@ class DboSource extends DataSource { } $data[$i] = $this->startQuote . str_replace('.', $this->endQuote . '.' . $this->startQuote, $data[$i]) . $this->endQuote; $data[$i] = str_replace($this->startQuote . $this->startQuote, $this->startQuote, $data[$i]); + if (strpos($data[$i], ' AS ')) { + $data[$i] = str_replace(' AS ', $this->endQuote . ' AS ' . $this->startQuote, $data[$i]); + } if (!empty($this->endQuote) && $this->endQuote == $this->startQuote) { if (substr_count($data[$i], $this->endQuote) % 2 == 1) { diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index e1ecb5a82..dc23b6826 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -1821,6 +1821,14 @@ class DboSourceTest extends CakeTestCase { $result = $this->db->fields($this->Model, null, array('MAX(Model.field) As Max')); $expected = array('MAX(`Model`.`field`) As Max'); $this->assertEqual($result, $expected); + + $result = $this->db->fields($this->Model, null, array('Model.field AS AnotherName')); + $expected = array('`Model`.`field` AS `AnotherName`'); + $this->assertEqual($result, $expected); + + $result = $this->db->fields($this->Model, null, array('field AS AnotherName')); + $expected = array('`TestModel`.`field` AS `AnotherName`'); + $this->assertEqual($result, $expected); } function testMergeAssociations() {