dblayeroo: in GROUP_CONCAT, allow the Separator to be set (use sqlite syntax, with a comma and the second optional parameter is the separator string)

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3818 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2017-07-19 14:11:28 +00:00
parent 0ac0fa75a5
commit db06724fa9

View File

@@ -1533,16 +1533,29 @@ class dblayeroo
{ {
$func = strtoupper (trim (substr ($name, 0, $pos))); $func = strtoupper (trim (substr ($name, 0, $pos)));
$name = trim (substr ($name, $pos+1, -1)); $name = trim (substr ($name, $pos+1, -1));
$separator = "";
if (in_array ($func, array ("AVG", "COUNT", "GROUP_CONCAT", "MAX", if (in_array ($func, array ("AVG", "COUNT", "GROUP_CONCAT", "MAX",
"MIN","SUM"))) "MIN","SUM")))
{ {
$aggregateFunction = true;
// Aggregate function. Add the non aggregate fields to the GROUP BY // Aggregate function. Add the non aggregate fields to the GROUP BY
// expression, if not already done // expression, if not already done
if ($this->groupByExpression === array ()) if ($this->groupByExpression === array ())
{ {
$aggregateFunction = true;
$this->groupByExpression = $this->displayColumn; $this->groupByExpression = $this->displayColumn;
} }
if ($func === "GROUP_CONCAT" && ($pos = strpos ($name, ",'")))
{
// There is a comma: the developper add the separator string
$separator = addslashes (substr ($name, $pos + 2, -1));
$name = substr ($name, 0, $pos);
if ($this->driver === "sqlite" || $this->driver === "psql")
$separator = ",'$separator'";
elseif ($this->driver === "mysql")
$separator = " SEPARATOR '$separator'";
}
if ($func === "GROUP_CONCAT" && $this->driver === "psql")
$func = "string_agg";
} }
$display = "$func($name)"; $display = "$func($name)";
} }
@@ -1554,12 +1567,13 @@ class dblayeroo
$this->displayColumn[$getSortOrder] = $this->sep.$display.$this->sep; $this->displayColumn[$getSortOrder] = $this->sep.$display.$this->sep;
else else
$this->displayColumn[$getSortOrder] = $this->displayColumn[$getSortOrder] =
"$func($this->sep$name$this->sep)"; "$func($this->sep$name$this->sep$separator)";
if ($this->groupByExpression !== array () && ! isset ($aggregateFunction)) if ($this->groupByExpression !== array () && ! isset ($aggregateFunction))
{ {
// Not a aggregate function, but groupBy is set : add the new field name // Not a aggregate function, but groupBy is set : add the new field name
$this->groupByExpression[$getSortOrder] = $this->sep.$name.$this->sep; $this->groupByExpression[$getSortOrder] = $this->sep.$name.$this->sep;
} }
unset ($aggregateFunction);
} }
return $this; return $this;
} }
@@ -1585,7 +1599,7 @@ class dblayeroo
} }
if ($name[0] !== $this->sep) if ($name[0] !== $this->sep)
$name = $this->sep.$name; $name = $this->sep.$name;
if (substr ($name, -1) !== $this->sep) if (! isset ($func) && substr ($name, -1) !== $this->sep)
$name = $name.$this->sep; $name = $name.$this->sep;
if ($full !== false) if ($full !== false)
$name = $this->sep.$this->tableprefix.$this->table.$this->sep.".".$name; $name = $this->sep.$this->tableprefix.$this->table.$this->sep.".".$name;