dblayeroo: Add DISTINCT feature to displayAdd

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3819 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2017-07-20 09:50:42 +00:00
parent db06724fa9
commit 36de4b3600
2 changed files with 147 additions and 12 deletions

View File

@@ -1231,6 +1231,15 @@ class dblayeroo
}
/* }}} */
/** Get the sep property
*/
public function sep ()
{
/* {{{ */
return $this->sep;
/* }}} */
}
/** Get/Set the dsn property
* @param string|null $dsn Set the DSN property of PDO
*/
@@ -1557,23 +1566,32 @@ class dblayeroo
if ($func === "GROUP_CONCAT" && $this->driver === "psql")
$func = "string_agg";
}
$display = "$func($name)";
}
if (! array_key_exists ($name, $this->fields))
$fieldName = $name;
$distinct = "";
if (stripos ($name, "DISTINCT ") === 0)
{
$distinct = "DISTINCT ";
$fieldName = substr ($name, strlen ("DISTINCT "));
}
if (! array_key_exists ($fieldName, $this->fields))
$this->DBException (sprintf (
"Invalid field to display '%s' : not defined in table", $name));
"Invalid field to display '%s' : not defined in table", $fieldName));
$getSortOrder = $this->getSortOrder();
if (! isset ($func))
$this->displayColumn[$getSortOrder] = $this->sep.$display.$this->sep;
$this->displayColumn[$getSortOrder] =
$distinct.$this->sep.$fieldName.$this->sep;
else
$this->displayColumn[$getSortOrder] =
"$func($this->sep$name$this->sep$separator)";
"$func($distinct$this->sep$fieldName$this->sep$separator)";
if ($this->groupByExpression !== array () && ! isset ($aggregateFunction))
{
// 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.$fieldName.$this->sep;
}
unset ($aggregateFunction);
unset ($func);
}
return $this;
}
@@ -1581,10 +1599,19 @@ class dblayeroo
/** Return the name of the display field, with $this->sep
* Add the table prefix/name if full is set
* Allow name, $this->sep.$name.$this->sep, func(name),
* func($this->sep.$name.$this->sep),
* func($this->sep.$this->tableprefix.$this->table.$this->sep.".".
* $this->sep.$name.$this->sep)
* Allow :
* name,
* DISTINCT name,
* $this->sep.$name.$this->sep,
* DISTINCT $this->sep.$name.$this->sep,
* func(name),
* func(DISTINCT name),
* func($this->sep.$name.$this->sep),
* func(DISTINCT $this->sep.$name.$this->sep),
* func($this->sep.$this->tableprefix.$this->table.$this->sep.".".
* $this->sep.$name.$this->sep)
* func(DISTINCT $this->sep.$this->tableprefix.$this->table.$this->sep.".".
* $this->sep.$name.$this->sep)
* @param string $name The name of the field
* @param boolean|null $full Add the table prefix/name if set
*/
@@ -1597,6 +1624,12 @@ class dblayeroo
$func = strtoupper (trim (substr ($name, 0, $pos)));
$name = trim (substr ($name, $pos+1, -1));
}
$distinct = "";
if (strpos ($name, "DISTINCT ") === 0)
{
$distinct = "DISTINCT ";
$name = substr ($name, strlen ("DISTINCT "));
}
if ($name[0] !== $this->sep)
$name = $this->sep.$name;
if (! isset ($func) && substr ($name, -1) !== $this->sep)
@@ -1604,12 +1637,14 @@ class dblayeroo
if ($full !== false)
$name = $this->sep.$this->tableprefix.$this->table.$this->sep.".".$name;
if (isset ($func))
$name = "$func($name)";
$name = "$func($distinct$name)";
else
$name = "$distinct$name";
return $name;
}
/* }}} */
/** Get the columns set in the query by displayColumn. If the $full parameter
/** Get the columns set in the query by displayAdd. If the $full parameter
* is set, add the table prefix/name to the result.
* If the join object is set, ask to it the columns too
* @param boolean $full Add the table prefix/name if set