dblayeroo: Add alias support (AS) to displayAdd
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3821 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -744,6 +744,19 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
|||||||
$db1->sep()."group".$db1->sep().")"), $res);
|
$db1->sep()."group".$db1->sep().")"), $res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_displayAdd_NotFull5 ()
|
||||||
|
{
|
||||||
|
// With alias
|
||||||
|
$db1 = $this->db1 ();
|
||||||
|
$db1->displayAdd ("group_concat (distinct group ) ", "Group Alias");
|
||||||
|
$res = $db1->displayGet ();
|
||||||
|
$db1->disconnect ();
|
||||||
|
$this->assertSame (array (
|
||||||
|
"order1" => "GROUP_CONCAT(DISTINCT ".
|
||||||
|
$db1->sep()."group".$db1->sep().") AS ".
|
||||||
|
$db1->sep()."Group Alias".$db1->sep()), $res);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_displayAdd_Full1 ()
|
public function test_displayAdd_Full1 ()
|
||||||
{
|
{
|
||||||
$db1 = $this->db1 ();
|
$db1 = $this->db1 ();
|
||||||
@@ -790,6 +803,20 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
|||||||
$db1->sep()."group".$db1->sep().")"), $res);
|
$db1->sep()."group".$db1->sep().")"), $res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_displayAdd_Full5 ()
|
||||||
|
{
|
||||||
|
// With alias
|
||||||
|
$db1 = $this->db1 ();
|
||||||
|
$db1->displayAdd ("group_concat (distinct group ) ", "Group Alias");
|
||||||
|
$res = $db1->displayGet (true);
|
||||||
|
$db1->disconnect ();
|
||||||
|
$this->assertSame (array (
|
||||||
|
"order1" => "GROUP_CONCAT(DISTINCT ".
|
||||||
|
$db1->sep()."groupedoo".$db1->sep().".".
|
||||||
|
$db1->sep()."group".$db1->sep().") AS ".
|
||||||
|
$db1->sep()."Group Alias".$db1->sep()), $res);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_displayAdd_Multiple1 ()
|
public function test_displayAdd_Multiple1 ()
|
||||||
{
|
{
|
||||||
$db1 = $this->db1 ();
|
$db1 = $this->db1 ();
|
||||||
|
|||||||
@@ -1341,6 +1341,9 @@ class dblayeroo
|
|||||||
* correctely defined
|
* correctely defined
|
||||||
*/
|
*/
|
||||||
private $displayColumn = null;
|
private $displayColumn = null;
|
||||||
|
/** The alias associated to each displayColumn
|
||||||
|
*/
|
||||||
|
private $displayAlias = array ();
|
||||||
/** Manage the joins
|
/** Manage the joins
|
||||||
*/
|
*/
|
||||||
private $joins = array ();
|
private $joins = array ();
|
||||||
@@ -1410,6 +1413,7 @@ class dblayeroo
|
|||||||
$this->command = "";
|
$this->command = "";
|
||||||
$this->distinct = "";
|
$this->distinct = "";
|
||||||
$this->displayColumn = null;
|
$this->displayColumn = null;
|
||||||
|
$this->displayAlias = array ();
|
||||||
$this->joins = array ();
|
$this->joins = array ();
|
||||||
$this->whereExpression = array ();
|
$this->whereExpression = array ();
|
||||||
$this->whereValues = array ();
|
$this->whereValues = array ();
|
||||||
@@ -1532,19 +1536,30 @@ class dblayeroo
|
|||||||
* By default, display all the columns if this method is not called
|
* By default, display all the columns if this method is not called
|
||||||
* If the value is null or not provided or an empty array, do not display
|
* If the value is null or not provided or an empty array, do not display
|
||||||
* any field
|
* any field
|
||||||
|
* @param array|string|null $aliasNames Add the Aliases to the displayed
|
||||||
|
* columns
|
||||||
*/
|
*/
|
||||||
public function displayAdd ($columnNames = array ())
|
public function displayAdd ($columnNames = array (), $aliasNames = array ())
|
||||||
/* {{{ */
|
/* {{{ */
|
||||||
{
|
{
|
||||||
$this->debugLog ("Entering displayAdd (",$columnNames,")");
|
$this->debugLog ("Entering displayAdd (", $columnNames, ",", $aliasNames,
|
||||||
|
")");
|
||||||
if (! is_string ($columnNames) && ! is_array ($columnNames))
|
if (! is_string ($columnNames) && ! is_array ($columnNames))
|
||||||
$this->DBException (
|
$this->DBException (
|
||||||
"Invalid columnNames provided (not string and not array)");
|
"Invalid columnNames provided (not string and not array)");
|
||||||
|
if (! is_string ($aliasNames) && ! is_array ($aliasNames))
|
||||||
|
$this->DBException (
|
||||||
|
"Invalid aliasNames provided (not string and not array)");
|
||||||
if (is_string ($columnNames))
|
if (is_string ($columnNames))
|
||||||
$columnNames = explode (",", $columnNames);
|
$columnNames = explode (",", $columnNames);
|
||||||
|
if (is_string ($aliasNames))
|
||||||
|
$aliasNames = explode (",", $aliasNames);
|
||||||
|
if (count ($aliasNames) && count ($aliasNames) !== count ($columnNames))
|
||||||
|
$this->DBException (
|
||||||
|
"The number of aliasNames are not the same as the number of columns");
|
||||||
if ($this->displayColumn === null)
|
if ($this->displayColumn === null)
|
||||||
$this->displayColumn = array ();
|
$this->displayColumn = array ();
|
||||||
foreach ($columnNames as $display)
|
foreach ($columnNames as $nb => $display)
|
||||||
{
|
{
|
||||||
$display = $name = trim ($display);
|
$display = $name = trim ($display);
|
||||||
$pos = strpos ($display, "(");
|
$pos = strpos ($display, "(");
|
||||||
@@ -1602,6 +1617,8 @@ class dblayeroo
|
|||||||
}
|
}
|
||||||
unset ($aggregateFunction);
|
unset ($aggregateFunction);
|
||||||
unset ($func);
|
unset ($func);
|
||||||
|
if (key_exists ($nb, $aliasNames))
|
||||||
|
$this->displayAlias[$getSortOrder] = $aliasNames[$nb];
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -1705,6 +1722,9 @@ class dblayeroo
|
|||||||
$columns[$pos] = $this->displayConvert ($name, true);
|
$columns[$pos] = $this->displayConvert ($name, true);
|
||||||
else
|
else
|
||||||
$columns[$pos] = $this->displayConvert ($name);
|
$columns[$pos] = $this->displayConvert ($name);
|
||||||
|
if (key_exists ($pos, $this->displayAlias))
|
||||||
|
$columns[$pos] .= " AS ".
|
||||||
|
$this->sep.$this->displayAlias[$pos].$this->sep;
|
||||||
}
|
}
|
||||||
if ($this->joinObject)
|
if ($this->joinObject)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user