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
This commit is contained in:
nate 2008-03-09 22:15:08 +00:00
parent be09e5a90d
commit 8fc104b44b
2 changed files with 11 additions and 0 deletions

View file

@ -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) {

View file

@ -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() {