Skip to content
Permalink
Browse files

Fix condition parsing in mysql specific cases.

When using collation + array values the incorrect operator would be
used. IN should be used over =.

Fixes #3772
  • Loading branch information...
markstory committed Apr 19, 2013
1 parent 3680ee0 commit 0f3d28c6ea968ca07921c5877b18d8e2ca88a620
@@ -2588,7 +2588,7 @@ protected function _parseKey($model, $key, $value) {
}
if (!preg_match($operatorMatch, trim($operator))) {
$operator .= ' =';
$operator .= is_array($value) ? ' IN' : ' =';
}
$operator = trim($operator);
@@ -2446,6 +2446,11 @@ public function testArrayConditionsParsing() {
$expected = " WHERE `id` IN (2, 5, 6, 9, 12, 45, 78, 43, 76)";
$this->assertEquals($expected, $result);
$conditions = array('`Correction`.`source` collate utf8_bin' => array('kiwi', 'pear'));
$result = $this->Dbo->conditions($conditions);
$expected = " WHERE `Correction`.`source` collate utf8_bin IN ('kiwi', 'pear')";
$this->assertEquals($expected, $result);
$conditions = array('title' => 'user(s)');
$result = $this->Dbo->conditions($conditions);
$expected = " WHERE `title` = 'user(s)'";
@@ -2499,6 +2504,23 @@ public function testArrayConditionsParsing() {
$this->assertEquals($expected, $result);
}
/**
* Test that array conditions with only one element work.
*
* @return
*/
public function testArrayConditionsOneElement() {
$conditions = array('id' => array(1));
$result = $this->Dbo->conditions($conditions);
$expected = " WHERE id = (1)";
$this->assertEquals($expected, $result);
$conditions = array('id NOT' => array(1));
$result = $this->Dbo->conditions($conditions);
$expected = " WHERE NOT (id = (1))";
$this->assertEquals($expected, $result);
}
/**
* testArrayConditionsParsingComplexKeys method
*

0 comments on commit 0f3d28c

Please sign in to comment.
You can’t perform that action at this time.