From 0e3143d45df485e7f24b87f766ae7959c8680f56 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 31 Jul 2020 13:38:46 +0200 Subject: [PATCH] fix SQL error in ranking caused by automatic added ambigous column which app code had already aliased "$table.$col AS $col" --- api/src/Storage/Base.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/api/src/Storage/Base.php b/api/src/Storage/Base.php index c2f9a11330..706cfa2d51 100644 --- a/api/src/Storage/Base.php +++ b/api/src/Storage/Base.php @@ -946,7 +946,20 @@ class Base if (is_array($colums) && ($key = array_search('*', $colums)) !== false) { unset($colums[$key]); - $colums = array_merge($colums, array_keys($this->db_cols)); + // don't add colums already existing incl. aliased colums (AS $name) + $as_columns = array_map(function($col) + { + $as = null; + list(, $as) = preg_split('/ +AS +/i', $col); + return empty($as) ? $col : $as; + }, $colums); + foreach(array_keys($this->db_cols) as $col) + { + if (!in_array($col, $colums) && !in_array($col, $as_columns)) + { + $colums[] = $col; + } + } } if (is_array($colums) && ($key = array_search($this->autoinc_id, $colums)) !== false) {