dblayeroo: manage correctely the PGSQL string_agg (instead of GROUP_CONCAT)

dblayeroo: Manage correctely the Aliases (do not emit Notice in execute)


git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3899 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2017-08-04 08:03:14 +00:00
parent 9af6d7402d
commit 439513f65d
2 changed files with 84 additions and 26 deletions

View File

@@ -765,8 +765,12 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
$tbl1->displayAdd ("group_concat ( group ) ");
$res = $tbl1->displayGet ();
$tbl1->disconnect ();
$this->assertSame (array (
"order1" => "GROUP_CONCAT(".$tbl1->sep()."group".$tbl1->sep().")"), $res);
if ($this->engine === "pgsql")
$this->assertSame (array (
"order1" => "string_agg(".$tbl1->sep()."group".$tbl1->sep().")"), $res);
else
$this->assertSame (array (
"order1" => "GROUP_CONCAT(".$tbl1->sep()."group".$tbl1->sep().")"), $res);
}
public function test_displayAdd_NotFull4 ()
@@ -775,9 +779,14 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
$tbl1->displayAdd ("group_concat (distinct group ) ");
$res = $tbl1->displayGet ();
$tbl1->disconnect ();
$this->assertSame (array (
"order1" => "GROUP_CONCAT(DISTINCT ".
$tbl1->sep()."group".$tbl1->sep().")"), $res);
if ($this->engine === "pgsql")
$this->assertSame (array (
"order1" => "string_agg(DISTINCT ".
$tbl1->sep()."group".$tbl1->sep().")"), $res);
else
$this->assertSame (array (
"order1" => "GROUP_CONCAT(DISTINCT ".
$tbl1->sep()."group".$tbl1->sep().")"), $res);
}
public function test_displayAdd_NotFull5 ()
@@ -787,10 +796,16 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
$tbl1->displayAdd ("group_concat (distinct group ) ", "Group Alias");
$res = $tbl1->displayGet ();
$tbl1->disconnect ();
$this->assertSame (array (
"order1" => "GROUP_CONCAT(DISTINCT ".
$tbl1->sep()."group".$tbl1->sep().") AS ".
$tbl1->sep()."Group Alias".$tbl1->sep()), $res);
if ($this->engine === "pgsql")
$this->assertSame (array (
"order1" => "string_agg(DISTINCT ".
$tbl1->sep()."group".$tbl1->sep().") AS ".
$tbl1->sep()."Group Alias".$tbl1->sep()), $res);
else
$this->assertSame (array (
"order1" => "GROUP_CONCAT(DISTINCT ".
$tbl1->sep()."group".$tbl1->sep().") AS ".
$tbl1->sep()."Group Alias".$tbl1->sep()), $res);
}
public function test_displayAdd_Full1 ()
@@ -822,9 +837,14 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
$tbl1->displayAdd ("group_concat ( group ) ");
$res = $tbl1->displayGet (true);
$tbl1->disconnect ();
$this->assertSame (array (
"order1" => "GROUP_CONCAT(".$tbl1->sep()."groupedoo".$tbl1->sep().".".
$tbl1->sep()."group".$tbl1->sep().")"), $res);
if ($this->engine === "pgsql")
$this->assertSame (array (
"order1" => "string_agg(".$tbl1->sep()."groupedoo".$tbl1->sep().".".
$tbl1->sep()."group".$tbl1->sep().")"), $res);
else
$this->assertSame (array (
"order1" => "GROUP_CONCAT(".$tbl1->sep()."groupedoo".$tbl1->sep().".".
$tbl1->sep()."group".$tbl1->sep().")"), $res);
}
public function test_displayAdd_Full4 ()
@@ -833,10 +853,16 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
$tbl1->displayAdd ("group_concat (distinct group ) ");
$res = $tbl1->displayGet (true);
$tbl1->disconnect ();
$this->assertSame (array (
"order1" => "GROUP_CONCAT(DISTINCT ".
$tbl1->sep()."groupedoo".$tbl1->sep().".".
$tbl1->sep()."group".$tbl1->sep().")"), $res);
if ($this->engine === "pgsql")
$this->assertSame (array (
"order1" => "string_agg(DISTINCT ".
$tbl1->sep()."groupedoo".$tbl1->sep().".".
$tbl1->sep()."group".$tbl1->sep().")"), $res);
else
$this->assertSame (array (
"order1" => "GROUP_CONCAT(DISTINCT ".
$tbl1->sep()."groupedoo".$tbl1->sep().".".
$tbl1->sep()."group".$tbl1->sep().")"), $res);
}
public function test_displayAdd_Full5 ()
@@ -846,11 +872,18 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
$tbl1->displayAdd ("group_concat (distinct group ) ", "Group Alias");
$res = $tbl1->displayGet (true);
$tbl1->disconnect ();
$this->assertSame (array (
"order1" => "GROUP_CONCAT(DISTINCT ".
$tbl1->sep()."groupedoo".$tbl1->sep().".".
$tbl1->sep()."group".$tbl1->sep().") AS ".
$tbl1->sep()."Group Alias".$tbl1->sep()), $res);
if ($this->engine === "pgsql")
$this->assertSame (array (
"order1" => "string_agg(DISTINCT ".
$tbl1->sep()."groupedoo".$tbl1->sep().".".
$tbl1->sep()."group".$tbl1->sep().") AS ".
$tbl1->sep()."Group Alias".$tbl1->sep()), $res);
else
$this->assertSame (array (
"order1" => "GROUP_CONCAT(DISTINCT ".
$tbl1->sep()."groupedoo".$tbl1->sep().".".
$tbl1->sep()."group".$tbl1->sep().") AS ".
$tbl1->sep()."Group Alias".$tbl1->sep()), $res);
}
public function test_displayAdd_Multiple1 ()
@@ -865,6 +898,7 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
$res);
}
public function test_update5 ()
{
// Manage to update the non unique fields
@@ -890,4 +924,14 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
->execute ();
$tbl1->disconnect ();
}
public function test_displayAdd_ComaFields1 ()
{
$tbl1 = $this->tbl1 ();
$tbl1->displayAdd ("group_concat (group ),group ",
"Group Alias,Group2");
$res = $tbl1->select ()
->execute ();
$tbl1->disconnect ();
}
}

View File

@@ -1595,7 +1595,7 @@ class dblayeroo
elseif ($this->driver === "mysql")
$separator = " SEPARATOR '$separator'";
}
if ($func === "GROUP_CONCAT" && $this->driver === "psql")
if ($func === "GROUP_CONCAT" && $this->driver === "pgsql")
$func = "string_agg";
}
}
@@ -1655,7 +1655,7 @@ class dblayeroo
$pos = strpos ($name, "(");
if ($pos !== false)
{
$func = strtoupper (trim (substr ($name, 0, $pos)));
$func = trim (substr ($name, 0, $pos));
$name = trim (substr ($name, $pos+1, -1));
}
$distinct = "";
@@ -2778,6 +2778,7 @@ class dblayeroo
if ($this->joinObject === null && count ($this->displayGet (false)))
{
// Remove the table name as there is no collisions risk
// In case of Alias, remove the $this->sep too
$columns = array ();
foreach ($this->displayGet (false) as $col)
{
@@ -2790,6 +2791,12 @@ class dblayeroo
{
$col = substr ($col, 0, -1);
}
if (strpos ($col, " AS ".$this->sep))
{
// remove the separator before the AS
$col = substr ($col, 0, strpos ($col, " AS ".$this->sep) -1).
substr ($col, strpos ($col, " AS ".$this->sep));
}
$columns[] = $col;
}
}
@@ -2812,9 +2819,16 @@ class dblayeroo
if (in_array ($func, array ("AVG", "COUNT", "MAX", "MIN", "SUM")))
$val = intval ($val);
}
elseif (strtolower ($fieldsAll[$columns[$colNb]][0]) ===
"integer")
$val = intval ($val);
else
{
$name = $columns[$colNb];
$pos = strpos ($columns[$colNb], " AS ");
if ($pos)
$name = substr ($columns[$colNb], 0, $pos);
if (strtolower ($fieldsAll[$name][0]) ===
"integer")
$val = intval ($val);
}
if (($pos = strpos ($columns[$colNb], " AS ".$this->sep)) !== false)
{
$pos += strlen (" AS ".$this->sep);