From 8136a1be337853397b066a07d476f1d55c806656 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Fri, 16 Mar 2018 23:30:51 +0000 Subject: [PATCH] Fixed LIKE parsing to work (#8406) * Fixed LIKE parsing to work * Do not add quotes for values that will already have them --- LibreNMS/Alerting/QueryBuilderParser.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/LibreNMS/Alerting/QueryBuilderParser.php b/LibreNMS/Alerting/QueryBuilderParser.php index d1abfb79d3..9087f5e9dd 100644 --- a/LibreNMS/Alerting/QueryBuilderParser.php +++ b/LibreNMS/Alerting/QueryBuilderParser.php @@ -43,18 +43,16 @@ class QueryBuilderParser implements \JsonSerializable private static $operators = [ 'equal' => "=", 'not_equal' => "!=", - 'in' => "IN (?)", - 'not_in' => "NOT IN (?)", 'less' => "<", 'less_or_equal' => "<=", 'greater' => ">", 'greater_or_equal' => ">=", - 'begins_with' => "ILIKE", - 'not_begins_with' => "NOT ILIKE", - 'contains' => "ILIKE", - 'not_contains' => "NOT ILIKE", - 'ends_with' => "ILIKE", - 'not_ends_with' => "NOT ILIKE", + 'begins_with' => "LIKE (\"%?\")", + 'not_begins_with' => "NOT LIKE (\"%?\")", + 'contains' => "LIKE (\"%?%\")", + 'not_contains' => "NOT LIKE (\"%?%\")", + 'ends_with' => "LIKE (\"?%\")", + 'not_ends_with' => "NOT LIKE (\"?%\")", 'is_empty' => "=''", 'is_not_empty' => "!=''", 'is_null' => "IS NULL", @@ -272,7 +270,7 @@ class QueryBuilderParser implements \JsonSerializable // pass through value such as field $value = trim($value, '`'); $value = $this->expandMacro($value); // check for macros - } elseif ($rule['type'] != 'integer') { + } elseif ($rule['type'] != 'integer' && !str_contains($op, '?')) { $value = "\"$value\""; }