diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index 8a9b548a1..aa33572a8 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -214,7 +214,7 @@ class DboMysql extends DboSource { if ($parent != null) { return $parent; - } elseif ($data === null) { + } elseif ($data === null || (is_array($data) && empty($data))) { return 'NULL'; } elseif ($data === '') { return "''"; diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index e823d3262..0efcd06b8 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -132,7 +132,7 @@ class DboSource extends DataSource { * @return mixed Prepared value or array of values. */ function value($data, $column = null) { - if (is_array($data)) { + if (is_array($data) && !empty($data)) { return array_map(array(&$this, 'value'), $data, array_fill(0, count($data), $column)); } elseif (is_object($data)) { if (isset($data->type) && $data->type == 'identifier') { @@ -1833,7 +1833,7 @@ class DboSource extends DataSource { } if ( - (is_array($value) && is_string($value[0]) && strpos($value[0], '-!') === 0) || + (is_array($value) && !empty($value) && is_string($value[0]) && strpos($value[0], '-!') === 0) || (is_string($value) && strpos($value, '-!') === 0) ) { trigger_error(__('Escape flag (-!) deprecated, use Model::query()', true), E_USER_WARNING); diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index b2767a7c6..b46905dd5 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -2350,6 +2350,14 @@ class DboSourceTest extends CakeTestCase { $expected = " WHERE `score` IN (1, 2, 10)"; $this->assertEqual($result, $expected); + $result = $this->testDb->conditions(array('score' => array())); + $expected = " WHERE `score` IS NULL"; + $this->assertEqual($result, $expected); + + $result = $this->testDb->conditions(array('score !=' => array())); + $expected = " WHERE `score` IS NOT NULL"; + $this->assertEqual($result, $expected); + $result = $this->testDb->conditions(array('score !=' => '20')); $expected = " WHERE `score` != '20'"; $this->assertEqual($result, $expected);