diff --git a/phpgwapi/inc/class.egw_db.inc.php b/phpgwapi/inc/class.egw_db.inc.php index a93a51409b..96fd290f46 100644 --- a/phpgwapi/inc/class.egw_db.inc.php +++ b/phpgwapi/inc/class.egw_db.inc.php @@ -674,7 +674,8 @@ class egw_db if (!$this->Query_ID) { throw new egw_exception_db_invalid_sql("Invalid SQL: ".(is_array($Query_String)?$Query_String[0]:$Query_String). - ($inputarr ? "
Parameters: '".implode("','",$inputarr)."'":'')); + "\n$this->Error ($this->Errno)". + ($inputarr ? "\nParameters: '".implode("','",$inputarr)."'":'')); } return $this->Query_ID; } @@ -1173,6 +1174,37 @@ class egw_db return call_user_func_array(array(&$this->Link_ID,'concat'),$args); } + /** + * Concat grouped values of an expression with optional order and separator + * + * @param string $expr column-name or expression optional prefixed with "DISTINCT" + * @param string $order_by='' optional order + * @param string $separator=',' optional separator, default is comma + * @return string + */ + function group_concat($expr, $order_by='', $separator=',') + { + switch($this->Type) + { + case 'mysql': + $sql = 'GROUP_CONCAT('.$expr; + if ($order_by) $sql .= ' ORDER BY '.$order_by; + if ($separator != ',') $sql .= ' SEPARATOR '.$this->quote($separator); + $sql .= ')'; + break; + + case 'pgsql': // requires for Postgresql < 8.4 to have a custom ARRAY_AGG method installed! + $sql = 'ARRAY_TO_STRING(ARRAY_AGG('.$expr; + if ($order_by) $sql .= ' ORDER BY '.$order_by; + $sql .= '), '.$this->quote($separator).')'; + break; + + default: // probably gives an sql error anyway + $sql = $expr; + } + return $sql; + } + /** * Convert a DB specific timestamp in a unix timestamp stored as integer, like MySQL: UNIX_TIMESTAMP(ts) * @@ -1192,7 +1224,6 @@ class egw_db case 'mssql': return "DATEDIFF(second,'1970-01-01',($expr))"; } - } /**