mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
forcing the db layer to make an WHERE field IS NULL when find statements are called with empty arrays, closes #4845
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7155 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
3c518c182f
commit
e221e9fb61
3 changed files with 11 additions and 3 deletions
|
@ -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 "''";
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue