[icinga-checkins] icinga.org: icingaweb2/master: DbQuery: Fix wrong operator precedence when rendering unequal filters

git at icinga.org git at icinga.org
Thu Nov 10 13:10:48 CET 2016


Module: icingaweb2
Branch: master
Commit: 0152a5941dae39903a9ad21258fe2bc0b4f21d07
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=0152a5941dae39903a9ad21258fe2bc0b4f21d07

Author: Johannes Meyer <johannes.meyer at netways.de>
Date:   Thu Nov 10 13:10:31 2016 +0100

DbQuery: Fix wrong operator precedence when rendering unequal filters

fixes #13107
refs #12852

---

 library/Icinga/Data/Db/DbQuery.php |   15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/library/Icinga/Data/Db/DbQuery.php b/library/Icinga/Data/Db/DbQuery.php
index 966e094..78605b7 100644
--- a/library/Icinga/Data/Db/DbQuery.php
+++ b/library/Icinga/Data/Db/DbQuery.php
@@ -301,7 +301,7 @@ class DbQuery extends SimpleQuery
             if ($sign === '=') {
                 return $col . ' IN (' . $this->escapeForSql($expression) . ')';
             } elseif ($sign === '!=') {
-                return $col . ' NOT IN (' . $this->escapeForSql($expression) . ') OR ' . $col . ' IS NULL';
+                return sprintf('(%1$s NOT IN (%2$s) OR %1$s IS NULL)', $col, $this->escapeForSql($expression));
             }
 
             throw new QueryException('Unable to render array expressions with operators other than equal or not equal');
@@ -316,12 +316,15 @@ class DbQuery extends SimpleQuery
                 return new Zend_Db_Expr('FALSE');
             }
 
-            return $col . ' NOT LIKE ' . $this->escapeForSql($this->escapeWildcards($expression))
-                . ' OR ' . $col . ' IS NULL';
-        } else {
-            return $col . ' ' . $sign . ' ' . $this->escapeForSql($expression) . (
-                $sign === '!=' ? ' OR ' . $col . ' IS NULL' : ''
+            return sprintf(
+                '(%1$s NOT LIKE %2$s OR %1$s IS NULL)',
+                $col,
+                $this->escapeForSql($this->escapeWildcards($expression))
             );
+        } elseif ($sign === '!=') {
+            return sprintf('(%1$s %2$s %3$s OR %1$s IS NULL)', $col, $sign, $this->escapeForSql($expression));
+        } else {
+            return sprintf('%s %s %s', $col, $sign, $this->escapeForSql($expression));
         }
     }
 



More information about the icinga-checkins mailing list