From 05d60936e6e2c5f12fdd09e6493ff7f3ea53a0e6 Mon Sep 17 00:00:00 2001 From: Thom Seddon Date: Fri, 20 Nov 2015 14:58:21 +0000 Subject: [PATCH] Remove last logical operator from generated SQL in GenGroupSQL Previously this function would output invalid SQL as a logical operator would be included after every condition. This change removes the final logical operator so the SQL is valid. For example, previously the single rule: `bgpPeers.bgpPeerRemoteAs = "6939" &&"` Would generate: ``` SELECT DISTINCT(bgpPeers.device_id) FROM bgpPeers WHERE device_id=? && (bgpPeers.bgpPeerRemoteAs = "6939" &&) LIMIT 1 ``` This changes means it will generate: ``` SELECT DISTINCT(bgpPeers.device_id) FROM bgpPeers WHERE device_id=? && (bgpPeers.bgpPeerRemoteAs = "6939") LIMIT 1 ``` --- includes/device-groups.inc.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/device-groups.inc.php b/includes/device-groups.inc.php index a1573ec03e..529cdf784a 100644 --- a/includes/device-groups.inc.php +++ b/includes/device-groups.inc.php @@ -46,6 +46,7 @@ function GenGroupSQL($pattern, $search='') { $pattern = str_replace($opt, $tmpp[0].'.'.$tmpp[1], $pattern); } } + $pattern = substr($pattern, 0, -3); $tables = array_keys(array_flip($tables)); $x = sizeof($tables);