From d483b2a56484e04d19a826de54c0f7218a80f441 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 26 Jul 2013 06:57:23 +0000 Subject: [PATCH] * PostgreSQL/ProjectManager/InfoLog: invalid SQL opening a new entry InfoLog entry can not "SELECT * FROM table ... GROUP BY *" has to be "SELECT table.* ... FROM table GROUP BY table.*" --- etemplate/inc/class.so_sql.inc.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/etemplate/inc/class.so_sql.inc.php b/etemplate/inc/class.so_sql.inc.php index 1f94bbaea5..bb36057743 100644 --- a/etemplate/inc/class.so_sql.inc.php +++ b/etemplate/inc/class.so_sql.inc.php @@ -1018,7 +1018,7 @@ class so_sql // fix GROUP BY clause to contain all non-aggregate selected columns if ($order_by && stripos($order_by,'GROUP BY') !== false && $this->db->Type != 'mysql') { - $order_by = self::fix_group_by_columns($order_by, $colums); + $order_by = $this->fix_group_by_columns($order_by, $colums); } elseif ($order_by && stripos($order_by,'ORDER BY')===false && stripos($order_by,'GROUP BY')===false && stripos($order_by,'HAVING')===false) { @@ -1126,7 +1126,7 @@ class so_sql * @param string|array $columns better provide an array as exploding by comma can lead to error with functions containing one * @return string */ - public static function fix_group_by_columns($group_by, $columns) + public function fix_group_by_columns($group_by, &$columns) { if (!preg_match('/(GROUP BY .*)(HAVING.*|ORDER BY.*)?$/iU', $group_by, $matches)) { @@ -1139,8 +1139,13 @@ class so_sql { $columns = preg_split('/, */', $columns); } - foreach($columns as $col) + foreach($columns as $n => $col) { + if ($col == '*') + { + $col = $columns[$n] = $this->table_name.'.*'; + ++$changes; + } // only check columns and non-aggregate functions if (strpos($col, '(') === false || !preg_match('/(COUNT|MIN|MAX|AVG|SUM|BIT_[A-Z]+|STD[A-Z_]*|VAR[A-Z_]*)\(/i', $col)) {