mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Allow SQL json selects without defining table name
This commit is contained in:
parent
990d0a962f
commit
55324c0b2a
2 changed files with 12 additions and 3 deletions
|
@ -2958,10 +2958,11 @@ class DboSource extends DataSource {
|
|||
if (!empty($this->endQuote)) {
|
||||
$end = preg_quote($this->endQuote);
|
||||
}
|
||||
|
||||
// Remove quotes and requote all the Model.field names.
|
||||
$conditions = str_replace(array($start, $end), '', $conditions);
|
||||
$conditions = preg_replace_callback(
|
||||
'/(?:[\'\"][^\'\"\\\]*(?:\\\.[^\'\"\\\]*)*[\'\"])|([a-z0-9_][a-z0-9\\-_]*\\.[a-z0-9_][a-z0-9_\\-]*[a-z0-9_])/i',
|
||||
'/(?:[\'\"][^\'\"\\\]*(?:\\\.[^\'\"\\\]*)*[\'\"])|([a-z0-9_][a-z0-9\\-_]*\\.[a-z0-9_][a-z0-9_\\-]*[a-z0-9_])|([a-z0-9_][a-z0-9_\\-]*)(?=->)/i',
|
||||
array(&$this, '_quoteMatchedField'),
|
||||
$conditions
|
||||
);
|
||||
|
|
|
@ -249,12 +249,20 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testColumnHyphenOperator() {
|
||||
//PostgreSQL style
|
||||
$result = $this->testDb->conditions(array('Foo.bar->>\'fieldName\'' => 42));
|
||||
$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');
|
||||
}
|
||||
|
||||
// MYSQL style
|
||||
$result = $this->testDb->conditions(array('Foo.bar->>\'$.fieldName\'' => 42));
|
||||
$this->assertEquals(' WHERE `Foo`.`bar`->>\'$.fieldName\' = 42', $result, 'SQL JSON operator failed');
|
||||
|
||||
//Without defining table name.
|
||||
$result = $this->testDb->conditions(array('bar->>\'$.fieldName\'' => 42));
|
||||
$this->assertEquals(' WHERE `bar`->>\'$.fieldName\' = 42', $result, 'SQL JSON operator failed');
|
||||
}
|
||||
|
||||
/**
|
||||
* test that order() will accept objects made from DboSource::expression
|
||||
|
|
Loading…
Reference in a new issue