dblayeroo : Manage the GROUP_CONCAT in PgSQL without error of casting
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4289 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -550,7 +550,6 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
|||||||
->displayAdd ("group")
|
->displayAdd ("group")
|
||||||
->joinLeft ($tbl2, array ("group"=>"group"))
|
->joinLeft ($tbl2, array ("group"=>"group"))
|
||||||
->orderAdd ("group", "ASC")
|
->orderAdd ("group", "ASC")
|
||||||
->debug (1)
|
|
||||||
->execute ();
|
->execute ();
|
||||||
$tbl1->disconnect ();
|
$tbl1->disconnect ();
|
||||||
$tbl2->disconnect ();
|
$tbl2->disconnect ();
|
||||||
@@ -768,7 +767,9 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
|||||||
$tbl1->disconnect ();
|
$tbl1->disconnect ();
|
||||||
if ($this->engine === "pgsql")
|
if ($this->engine === "pgsql")
|
||||||
$this->assertSame (array (
|
$this->assertSame (array (
|
||||||
"order1" => "string_agg(".$tbl1->sep()."group".$tbl1->sep().")"), $res);
|
"order1" => "string_agg(".$tbl1->sep()."group".$tbl1->sep().
|
||||||
|
"::character varying, ',' order by \"group\"".
|
||||||
|
")"), $res);
|
||||||
else
|
else
|
||||||
$this->assertSame (array (
|
$this->assertSame (array (
|
||||||
"order1" => "GROUP_CONCAT(".$tbl1->sep()."group".$tbl1->sep().")"), $res);
|
"order1" => "GROUP_CONCAT(".$tbl1->sep()."group".$tbl1->sep().")"), $res);
|
||||||
@@ -783,7 +784,9 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
|||||||
if ($this->engine === "pgsql")
|
if ($this->engine === "pgsql")
|
||||||
$this->assertSame (array (
|
$this->assertSame (array (
|
||||||
"order1" => "string_agg(DISTINCT ".
|
"order1" => "string_agg(DISTINCT ".
|
||||||
$tbl1->sep()."group".$tbl1->sep().")"), $res);
|
$tbl1->sep()."group".$tbl1->sep().
|
||||||
|
"::character varying, ',' order by \"group\"".
|
||||||
|
")"), $res);
|
||||||
else
|
else
|
||||||
$this->assertSame (array (
|
$this->assertSame (array (
|
||||||
"order1" => "GROUP_CONCAT(DISTINCT ".
|
"order1" => "GROUP_CONCAT(DISTINCT ".
|
||||||
@@ -800,7 +803,10 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
|||||||
if ($this->engine === "pgsql")
|
if ($this->engine === "pgsql")
|
||||||
$this->assertSame (array (
|
$this->assertSame (array (
|
||||||
"order1" => "string_agg(DISTINCT ".
|
"order1" => "string_agg(DISTINCT ".
|
||||||
$tbl1->sep()."group".$tbl1->sep().") AS ".
|
$tbl1->sep()."group".$tbl1->sep().
|
||||||
|
"::character varying, ',' order by ".
|
||||||
|
$tbl1->sep()."group".$tbl1->sep().
|
||||||
|
") AS ".
|
||||||
$tbl1->sep()."Group Alias".$tbl1->sep()), $res);
|
$tbl1->sep()."Group Alias".$tbl1->sep()), $res);
|
||||||
else
|
else
|
||||||
$this->assertSame (array (
|
$this->assertSame (array (
|
||||||
@@ -841,7 +847,9 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
|||||||
if ($this->engine === "pgsql")
|
if ($this->engine === "pgsql")
|
||||||
$this->assertSame (array (
|
$this->assertSame (array (
|
||||||
"order1" => "string_agg(".$tbl1->sep()."groupedoo".$tbl1->sep().".".
|
"order1" => "string_agg(".$tbl1->sep()."groupedoo".$tbl1->sep().".".
|
||||||
$tbl1->sep()."group".$tbl1->sep().")"), $res);
|
$tbl1->sep()."group".$tbl1->sep().
|
||||||
|
"::character varying, ',' order by \"group\"".
|
||||||
|
")"), $res);
|
||||||
else
|
else
|
||||||
$this->assertSame (array (
|
$this->assertSame (array (
|
||||||
"order1" => "GROUP_CONCAT(".$tbl1->sep()."groupedoo".$tbl1->sep().".".
|
"order1" => "GROUP_CONCAT(".$tbl1->sep()."groupedoo".$tbl1->sep().".".
|
||||||
@@ -858,7 +866,9 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertSame (array (
|
$this->assertSame (array (
|
||||||
"order1" => "string_agg(DISTINCT ".
|
"order1" => "string_agg(DISTINCT ".
|
||||||
$tbl1->sep()."groupedoo".$tbl1->sep().".".
|
$tbl1->sep()."groupedoo".$tbl1->sep().".".
|
||||||
$tbl1->sep()."group".$tbl1->sep().")"), $res);
|
$tbl1->sep()."group".$tbl1->sep().
|
||||||
|
"::character varying, ',' order by \"group\"".
|
||||||
|
")"), $res);
|
||||||
else
|
else
|
||||||
$this->assertSame (array (
|
$this->assertSame (array (
|
||||||
"order1" => "GROUP_CONCAT(DISTINCT ".
|
"order1" => "GROUP_CONCAT(DISTINCT ".
|
||||||
@@ -877,7 +887,9 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertSame (array (
|
$this->assertSame (array (
|
||||||
"order1" => "string_agg(DISTINCT ".
|
"order1" => "string_agg(DISTINCT ".
|
||||||
$tbl1->sep()."groupedoo".$tbl1->sep().".".
|
$tbl1->sep()."groupedoo".$tbl1->sep().".".
|
||||||
$tbl1->sep()."group".$tbl1->sep().") AS ".
|
$tbl1->sep()."group".$tbl1->sep().
|
||||||
|
"::character varying, ',' order by \"group\"".
|
||||||
|
") AS ".
|
||||||
$tbl1->sep()."Group Alias".$tbl1->sep()), $res);
|
$tbl1->sep()."Group Alias".$tbl1->sep()), $res);
|
||||||
else
|
else
|
||||||
$this->assertSame (array (
|
$this->assertSame (array (
|
||||||
@@ -931,10 +943,6 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
|||||||
$tbl1 = $this->tbl1 ();
|
$tbl1 = $this->tbl1 ();
|
||||||
$tbl1->displayAdd ("group_concat (group ),group ",
|
$tbl1->displayAdd ("group_concat (group ),group ",
|
||||||
"Group Alias,Group2");
|
"Group Alias,Group2");
|
||||||
// PGSQL generate an exception :
|
|
||||||
// function string_agg(character varying) does not exist
|
|
||||||
if ($this->engine === "pgsql")
|
|
||||||
$this->setExpectedException ("PDOException");
|
|
||||||
$res = $tbl1->select ()
|
$res = $tbl1->select ()
|
||||||
->execute ();
|
->execute ();
|
||||||
$tbl1->disconnect ();
|
$tbl1->disconnect ();
|
||||||
@@ -1010,7 +1018,6 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
|||||||
$res = $tbl2->select ()
|
$res = $tbl2->select ()
|
||||||
->displayAdd ("MAX(uid)")
|
->displayAdd ("MAX(uid)")
|
||||||
->joinInner ($tbl1, array ("group"=>"group"))
|
->joinInner ($tbl1, array ("group"=>"group"))
|
||||||
->debug (1)
|
|
||||||
->execute ();
|
->execute ();
|
||||||
$tbl2->disconnect ();
|
$tbl2->disconnect ();
|
||||||
$this->assertSame (array (array (
|
$this->assertSame (array (array (
|
||||||
@@ -1018,4 +1025,26 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
|||||||
'MAX(usersoo.uid)' => 6,
|
'MAX(usersoo.uid)' => 6,
|
||||||
)), $res);
|
)), $res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_GROUPCONCATwithAlias1 ()
|
||||||
|
{
|
||||||
|
$tbl1 = $this->tbl1 ();
|
||||||
|
$res = $tbl1->select ()
|
||||||
|
->displayAdd ("GROUP_CONCAT(group)", "groups")
|
||||||
|
->execute ();
|
||||||
|
$this->assertSame (array (array (
|
||||||
|
'groups' => 'group1,group2'
|
||||||
|
)), $res);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_GROUPCONCATwithAlias2 ()
|
||||||
|
{
|
||||||
|
$tbl1 = $this->tbl1 ();
|
||||||
|
$res = $tbl1->select ()
|
||||||
|
->displayAdd ("GROUP_CONCAT(group,',')", "groups")
|
||||||
|
->execute ();
|
||||||
|
$this->assertSame (array (array (
|
||||||
|
'groups' => 'group1,group2'
|
||||||
|
)), $res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1621,6 +1621,17 @@ class dblayeroo
|
|||||||
if (! isset ($func))
|
if (! isset ($func))
|
||||||
$this->displayColumn[$getSortOrder] =
|
$this->displayColumn[$getSortOrder] =
|
||||||
$distinct.$this->sep.$fieldName.$this->sep;
|
$distinct.$this->sep.$fieldName.$this->sep;
|
||||||
|
elseif ($func === "string_agg")
|
||||||
|
{
|
||||||
|
// For Postgres, the entry must be :
|
||||||
|
// string_agg(distinct "group"::character varying, ',' order by "group")
|
||||||
|
if ($separator == "")
|
||||||
|
$separator = ", ','";
|
||||||
|
$this->displayColumn[$getSortOrder] =
|
||||||
|
"$func($distinct$this->sep$fieldName$this->sep".
|
||||||
|
"::character varying$separator ".
|
||||||
|
"order by $this->sep$fieldName$this->sep)";
|
||||||
|
}
|
||||||
else
|
else
|
||||||
$this->displayColumn[$getSortOrder] =
|
$this->displayColumn[$getSortOrder] =
|
||||||
"$func($distinct$this->sep$fieldName$this->sep$separator)";
|
"$func($distinct$this->sep$fieldName$this->sep$separator)";
|
||||||
|
|||||||
Reference in New Issue
Block a user