Skip to content

Commit

Permalink
Modifying quoting method used in conditions with array values in DboS…
Browse files Browse the repository at this point in the history
…ource, fixes #6519

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8243 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
nateabele committed Jul 22, 2009
1 parent caeac73 commit a75d1fa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cake/libs/model/datasources/dbo_source.php
Original file line number Diff line number Diff line change
Expand Up @@ -1842,9 +1842,9 @@ function conditionKeysToString($conditions, $quoteValues = true, $model = null)
if (array_keys($value) === array_values(array_keys($value))) {
$count = count($value);
if ($count === 1) {
$data = $this->name($key) . ' = (';
$data = $this->__quoteFields($key) . ' = (';
} else {
$data = $this->name($key) . ' IN (';
$data = $this->__quoteFields($key) . ' IN (';
}
if ($quoteValues || strpos($value[0], '-!') !== 0) {
if (is_object($model)) {
Expand Down
18 changes: 13 additions & 5 deletions cake/tests/cases/libs/model/datasources/dbo_source.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2133,7 +2133,7 @@ function testStringConditionsParsing() {
$this->assertEqual($result, $expected);

$result = $this->testDb->conditions(array('score' => array(2=>1, 2, 10)));
$expected = " WHERE `score` IN (1, 2, 10)";
$expected = " WHERE score IN (1, 2, 10)";
$this->assertEqual($result, $expected);

$result = $this->testDb->conditions("Aro.rght = Aro.lft + 1.1");
Expand Down Expand Up @@ -2385,7 +2385,7 @@ function testArrayConditionsParsing() {
$this->assertEqual($result, $expected);

$result = $this->testDb->conditions(array('score' => array(1, 2, 10)));
$expected = " WHERE `score` IN (1, 2, 10)";
$expected = " WHERE score IN (1, 2, 10)";
$this->assertEqual($result, $expected);

$result = $this->testDb->conditions(array('score' => array()));
Expand Down Expand Up @@ -2476,7 +2476,7 @@ function testArrayConditionsParsing() {
'NOT' => array('Course.id' => null, 'Course.vet' => 'N', 'level_of_education_id' => array(912,999)),
'Enrollment.yearcompleted >' => '0')
);
$this->assertPattern('/^\s*WHERE\s+\(NOT\s+\(`Course`\.`id` IS NULL\)\s+AND NOT\s+\(`Course`\.`vet`\s+=\s+\'N\'\)\s+AND NOT\s+\(`level_of_education_id` IN \(912, 999\)\)\)\s+AND\s+`Enrollment`\.`yearcompleted`\s+>\s+\'0\'\s*$/', $result);
$this->assertPattern('/^\s*WHERE\s+\(NOT\s+\(`Course`\.`id` IS NULL\)\s+AND NOT\s+\(`Course`\.`vet`\s+=\s+\'N\'\)\s+AND NOT\s+\(level_of_education_id IN \(912, 999\)\)\)\s+AND\s+`Enrollment`\.`yearcompleted`\s+>\s+\'0\'\s*$/', $result);

$result = $this->testDb->conditions(array('id <>' => '8'));
$this->assertPattern('/^\s*WHERE\s+`id`\s+<>\s+\'8\'\s*$/', $result);
Expand All @@ -2495,16 +2495,24 @@ function testArrayConditionsParsing() {
"Listing.description LIKE" => "%term_2%"
);
$result = $this->testDb->conditions($conditions);
$expected = " WHERE NOT (`Listing`.`expiration` BETWEEN '1' AND '100') AND ((`Listing`.`title` LIKE '%term%') OR (`Listing`.`description` LIKE '%term%')) AND ((`Listing`.`title` LIKE '%term_2%') OR (`Listing`.`description` LIKE '%term_2%'))";
$expected = " WHERE NOT (`Listing`.`expiration` BETWEEN '1' AND '100') AND" .
" ((`Listing`.`title` LIKE '%term%') OR (`Listing`.`description` LIKE '%term%')) AND" .
" ((`Listing`.`title` LIKE '%term_2%') OR (`Listing`.`description` LIKE '%term_2%'))";
$this->assertEqual($result, $expected);

$result = $this->testDb->conditions(array('MD5(CONCAT(Reg.email,Reg.id))' => 'blah'));
$expected = " WHERE MD5(CONCAT(`Reg`.`email`,`Reg`.`id`)) = 'blah'";
$this->assertEqual($result, $expected);

$result = $this->testDb->conditions(array(
'MD5(CONCAT(Reg.email,Reg.id))' => array('blah', 'blahblah')
));
$expected = " WHERE MD5(CONCAT(`Reg`.`email`,`Reg`.`id`)) IN ('blah', 'blahblah')";
$this->assertEqual($result, $expected);

$conditions = array('id' => array(2, 5, 6, 9, 12, 45, 78, 43, 76));
$result = $this->testDb->conditions($conditions);
$expected = " WHERE `id` IN (2, 5, 6, 9, 12, 45, 78, 43, 76)";
$expected = " WHERE id IN (2, 5, 6, 9, 12, 45, 78, 43, 76)";
$this->assertEqual($result, $expected);

$conditions = array('title' => 'user(s)');
Expand Down

0 comments on commit a75d1fa

Please sign in to comment.