From 634a69aec9c20d0ff2e1b589b0e22b7e2b5bc51b Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 11 Nov 2016 09:17:58 +0100 Subject: [PATCH] DbConnection: Explicitly check for NULL when rendering unequal filters resolves #12852 --- library/Icinga/Data/Db/DbConnection.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/library/Icinga/Data/Db/DbConnection.php b/library/Icinga/Data/Db/DbConnection.php index 81afb2c3d..9705bff19 100644 --- a/library/Icinga/Data/Db/DbConnection.php +++ b/library/Icinga/Data/Db/DbConnection.php @@ -444,7 +444,7 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible, Insp if ($sign === '=') { return $column . ' IN (' . $this->dbAdapter->quote($value) . ')'; } elseif ($sign === '!=') { - return $column . ' NOT IN (' . $this->dbAdapter->quote($value) . ')'; + return sprintf('(%1$s NOT IN (%2$s) OR %1$s IS NULL)', $column, $this->dbAdapter->quote($value)); } throw new ProgrammingError( @@ -467,9 +467,15 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible, Insp return $this->dbAdapter->quote(0); } - return $column . ' NOT LIKE ' . $this->dbAdapter->quote(preg_replace('~\*~', '%', $value)); + return sprintf( + '(%1$s NOT LIKE %2$s OR %1$s IS NULL)', + $column, + $this->dbAdapter->quote(preg_replace('~\*~', '%', $value)) + ); + } elseif ($sign === '!=') { + return sprintf('(%1$s != %2$s OR %1$s IS NULL)', $column, $this->dbAdapter->quote($value)); } else { - return $column . ' ' . $sign . ' ' . $this->dbAdapter->quote($value); + return sprintf('%s %s %s', $column, $sign, $this->dbAdapter->quote($value)); } }