diff options
author | Simon Rettberg | 2022-07-06 16:11:55 +0200 |
---|---|---|
committer | Simon Rettberg | 2022-07-06 16:11:55 +0200 |
commit | 8355096282c0b1491416111ae5ff35aba4bf5b70 (patch) | |
tree | 1f50f4c0bd0e389fd97d32f8ef32edd10557108f /modules-available/statistics/inc | |
parent | [permissionmanager] Shorten permissionid to 100 chars (diff) | |
download | slx-admin-8355096282c0b1491416111ae5ff35aba4bf5b70.tar.gz slx-admin-8355096282c0b1491416111ae5ff35aba4bf5b70.tar.xz slx-admin-8355096282c0b1491416111ae5ff35aba4bf5b70.zip |
[statistics] Fix problems with unusual column names in query builder
Diffstat (limited to 'modules-available/statistics/inc')
-rw-r--r-- | modules-available/statistics/inc/hardwarequery.inc.php | 7 | ||||
-rw-r--r-- | modules-available/statistics/inc/hardwarequerycolumn.inc.php | 6 |
2 files changed, 9 insertions, 4 deletions
diff --git a/modules-available/statistics/inc/hardwarequery.inc.php b/modules-available/statistics/inc/hardwarequery.inc.php index e458599d..4f0ec344 100644 --- a/modules-available/statistics/inc/hardwarequery.inc.php +++ b/modules-available/statistics/inc/hardwarequery.inc.php @@ -136,6 +136,11 @@ class HardwareQuery } elseif (!is_array($groupBy)) { $groupBy = [$groupBy]; } + foreach ($groupBy as &$gb) { + if ($gb[0] !== '`') { + $gb = "`$gb`"; + } + } $columns = []; foreach ($this->columns as $column) { if ($column instanceof HardwareQueryColumn) { @@ -154,7 +159,7 @@ class HardwareQuery } if (!empty($groupBy)) { $columns[] = 'Count(*) AS group_count'; - $groupBy = " GROUP BY `" . implode('`, `', $groupBy) . '`'; + $groupBy = " GROUP BY " . implode(', ', $groupBy); } else { $groupBy = ''; } diff --git a/modules-available/statistics/inc/hardwarequerycolumn.inc.php b/modules-available/statistics/inc/hardwarequerycolumn.inc.php index 07e7ecec..8aab6a54 100644 --- a/modules-available/statistics/inc/hardwarequerycolumn.inc.php +++ b/modules-available/statistics/inc/hardwarequerycolumn.inc.php @@ -24,7 +24,7 @@ class HardwareQueryColumn $this->global = $global; $this->tableAlias = self::getId(); $this->virtualColumnName = $column; - $this->alias = $alias ?? $column; + $this->alias = '`' . ($alias ?? $column) . '`'; } /** @@ -54,9 +54,9 @@ class HardwareQueryColumn $type = count($this->conditions) === 1 ? 'LEFT' : 'INNER'; $joins[] = "$type JOIN $table $tid ON (" . implode(' AND ', $this->conditions) . ")"; if (!empty($groupConcat) && !in_array($this->alias, $groupConcat)) { - $columns[] = "Group_Concat(DISTINCT $tid.`value` SEPARATOR ', ') AS `{$this->alias}`"; + $columns[] = "Group_Concat(DISTINCT $tid.`value` SEPARATOR ', ') AS {$this->alias}"; } else { - $columns[] = "$tid.`value` AS `{$this->alias}`"; + $columns[] = "$tid.`value` AS {$this->alias}"; } $params += $this->params; } |