mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Fixing boolean conditions expression handling in DboSource::conditionKeysToString() and added test case (Ticket #2268)
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4647 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
086a9cd97f
commit
c65f2a1fd2
2 changed files with 11 additions and 1 deletions
|
@ -1442,6 +1442,8 @@ class DboSource extends DataSource {
|
|||
$data = ' ' . $value;
|
||||
} elseif ($value === null || (is_array($value) && empty($value))) {
|
||||
$data = $this->name($key) . ' IS NULL';
|
||||
} elseif ($value === false || $value === true) {
|
||||
$data = $this->name($key) . " = " . $this->boolean($value);
|
||||
} elseif ($value === '') {
|
||||
$data = $this->name($key) . " = ''";
|
||||
} elseif (preg_match('/^([a-z]*\\([a-z0-9]*\\)\\x20?|(?:' . join('\\x20)|(?:', $this->__sqlOps) . '\\x20)|<=?(?![^>]+>)\\x20?|[>=!]{1,3}(?!<)\\x20?)?(.*)/i', $value, $match)) {
|
||||
|
@ -1563,7 +1565,6 @@ class DboSource extends DataSource {
|
|||
} else {
|
||||
$dir = '';
|
||||
}
|
||||
|
||||
$key = trim($this->name(trim($key)) . ' ' . trim($dir));
|
||||
}
|
||||
$order[] = $this->order($key . $value);
|
||||
|
|
|
@ -702,6 +702,15 @@ class DboSourceTest extends UnitTestCase {
|
|||
$result = $this->db->conditions(array('published' => 1, 'or' => array('score' => '< 2', array('score' => '> 20')) ));
|
||||
$expected = " WHERE `published` = 1 AND (`score` < 2) OR (`score` > 20)";
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->db->conditions(array(array('Project.removed' => false)));
|
||||
$this->assertPattern('/^\s*WHERE\s+`Project`.`removed`\s+=\s+0\s*$/', $result);
|
||||
|
||||
$result = $this->db->conditions(array(array('Project.removed' => true)));
|
||||
$this->assertPattern('/^\s*WHERE\s+`Project`.`removed`\s+=\s+1\s*$/', $result);
|
||||
|
||||
$result = $this->db->conditions(array(array('Project.removed' => null)));
|
||||
$this->assertPattern('/^\s*WHERE\s+`Project`.`removed`\s+IS\s+NULL\s*$/', $result);
|
||||
}
|
||||
|
||||
function testFieldParsing() {
|
||||
|
|
Loading…
Reference in a new issue