Fix incorrectly quoted fields when using the || operator.

Fixes #3404
This commit is contained in:
mark_story 2012-12-02 20:59:56 -05:00
parent 0b508b887a
commit 002700071d
2 changed files with 11 additions and 1 deletions

View file

@ -2574,7 +2574,11 @@ class DboSource extends DataSource {
$value = $this->value($value, $type);
if (!$virtual && $key !== '?') {
$isKey = (strpos($key, '(') !== false || strpos($key, ')') !== false);
$isKey = (
strpos($key, '(') !== false ||
strpos($key, ')') !== false ||
strpos($key, '|') !== false
);
$key = $isKey ? $this->_quoteFields($key) : $this->name($key);
}

View file

@ -2207,6 +2207,12 @@ class MysqlTest extends CakeTestCase {
$expected = " WHERE `HardCandy`.`name` LIKE 'to be or%' AND `Candy`.`name` LIKE '%not to be%'";
$this->assertEquals($expected, $result);
$result = $this->Dbo->conditions(array(
"Person.name || ' ' || Person.surname ILIKE" => '%mark%'
));
$expected = " WHERE `Person`.`name` || ' ' || `Person`.`surname` ILIKE '%mark%'";
$this->assertEquals($expected, $result);
$result = $this->Dbo->conditions(array('score BETWEEN ? AND ?' => array(90.1, 95.7)));
$expected = " WHERE `score` BETWEEN 90.1 AND 95.7";
$this->assertEquals($expected, $result);