Allow database JSON operations in conditions

This commit is contained in:
Cory Thompson 2017-01-24 19:33:12 +11:00
parent 82a64a3729
commit 990d0a962f
2 changed files with 7 additions and 5 deletions

View file

@ -2897,7 +2897,8 @@ class DboSource extends DataSource {
$isKey = (
strpos($key, '(') !== false ||
strpos($key, ')') !== false ||
strpos($key, '|') !== false
strpos($key, '|') !== false ||
strpos($key, '->') !== false
);
$key = $isKey ? $this->_quoteFields($key) : $this->name($key);
}

View file

@ -244,15 +244,16 @@ class DboSourceTest extends CakeTestCase {
}
/**
* test that PostgreSQL json operators can be used.
* test that SQL JSON operators can be used.
*
* @return void
*/
public function testColumnHyphenOperator() {
$result = $this->testDb->conditions(array('Foo.bar->>\'fieldName\'' => 42));
echo "Result is: ";
echo $result;
$this->assertEquals(' WHERE `Foo`.`bar`->>\'fieldName\' = 42', $result, 'pgsql json operator failed');
$this->assertEquals(' WHERE `Foo`.`bar`->>\'fieldName\' = 42', $result, 'SQL JSON operator failed');
$result = $this->testDb->conditions(array('Foo.bar->\'fieldName\'' => 42));
$this->assertEquals(' WHERE `Foo`.`bar`->\'fieldName\' = 42', $result, 'SQL JSON operator failed');
}
/**