Skip to content

Commit

Permalink
Fix incorrectly quoted fields when using the || operator.
Browse files Browse the repository at this point in the history
Fixes #3404
  • Loading branch information
markstory committed Dec 3, 2012
1 parent 0b508b8 commit 0027000
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -2574,7 +2574,11 @@ protected function _parseKey($model, $key, $value) {
$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

This comment has been minimized.

Copy link
@dereuromark

dereuromark Dec 3, 2012

Member

wouldn't other operators like && etc still fail? or are they not supposed to used in this context?

This comment has been minimized.

Copy link
@markstory

markstory Dec 3, 2012

Author Member

|| is the concat operator in Postgres and SQLite. From what I remember && doesn't do anything special.

);
$key = $isKey ? $this->_quoteFields($key) : $this->name($key);
}

Expand Down
6 changes: 6 additions & 0 deletions lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
Expand Up @@ -2207,6 +2207,12 @@ public function testArrayConditionsParsing() {
$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);
Expand Down

0 comments on commit 0027000

Please sign in to comment.