dblayeroo : remove the tables names if there is no collision risk. The display table is not necessary the $this->table one.

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5259 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2019-05-10 10:04:46 +00:00
parent ac85659233
commit 3473f2f0d0

View File

@@ -3235,7 +3235,7 @@ class dblayeroo
// name to the value by index.
// FETCH_ASSOC doesn't work in empty left join (return NULL instead of
// the filled value)
$fieldsAll = $this->fieldsAll (false);
$fieldsAll = $this->fieldsAll (true);
// If the displayed fields are all in the same table, remove the table
// name in the columns
$cleanable = true;
@@ -3252,18 +3252,22 @@ class dblayeroo
break;
}
}
$columns = array_values ($this->displayGet (true));
// Get the columns names that will be displayed to user.
// If the cleanable is possible, remove the table names
$columnNames = array_combine ($columns, $columns);
//if ($this->joinObject === null && count ($this->displayGet (false)))
if ($cleanable)
{
// Force the fields to local ones as there is no use of external fields
$fieldsAll = $this->fields;
// 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)
foreach ($columnNames as $key => $col)
{
$col = str_replace ($this->sep.$this->tableprefix.$this->table.
$this->sep.".", "", $col);
// Remove the table and the separator if exists
$col = preg_replace ("#".$this->sep."[^".$this->sep."]+".
$this->sep."\.#U", "", $col);
// Remove the separator if not table exists
$col = str_replace ($this->sep, "", $col);
if ($col[0] === $this->sep)
$col = substr ($col, 1);
elseif (strpos ($col, "DISTINCT ".$this->sep) === 0)
@@ -3279,14 +3283,16 @@ class dblayeroo
$col = substr ($col, 0, strpos ($col, " AS ".$this->sep) -1).
substr ($col, strpos ($col, " AS ".$this->sep));
}
$columns[] = $col;
$columnNames[$key] = $col;
}
}
else
{
$columns = $this->displayGet (true);
foreach ($columnNames as $key => $col)
{
$columnNames[$key] = str_replace ($this->sep, "", $col);
}
}
$columns = array_values ($columns);
foreach ($result as $rownb=>$row)
{
foreach ($row as $colNb=>$val)
@@ -3308,6 +3314,9 @@ class dblayeroo
if ($pos)
$name = substr ($columns[$colNb], 0, $pos);
$name = str_replace ("DISTINCT ", "", $name);
/*if ($cleanable)
$name = str_replace ($this->sep.$this->tableprefix.$this->table.
$this->sep.".", "", $name);*/
if (strtolower ($fieldsAll[$name][0]) === "integer" &&
$val !== null)
$val = intval ($val);
@@ -3318,7 +3327,7 @@ class dblayeroo
$colName = substr ($columns[$colNb], $pos, -1);
}
else
$colName = str_replace ($this->sep, "", $columns[$colNb]);
$colName = $columnNames[$columns[$colNb]];
$result[$rownb][$colName] = $val;
unset ($result[$rownb][$colNb]);
}