dblayeroo : review the join process and add the unit tests for it
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3495 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -1165,6 +1165,7 @@ class dblayeroo
|
||||
$this->setValues = array ();
|
||||
$this->setType = array ();
|
||||
$this->setForeignObj = array ();
|
||||
unset ($this->fieldsTmp);
|
||||
}
|
||||
|
||||
/** Define a new foreign object
|
||||
@@ -1374,6 +1375,25 @@ class dblayeroo
|
||||
$this->whereExpression = array_merge ($object->whereExpression,
|
||||
$this->whereExpression);
|
||||
$this->whereValues = array_merge ($object->whereValues, $this->whereValues);
|
||||
// Add the new object fields to the this. The fields must be available to
|
||||
// be normalized at the end
|
||||
$tmp = array ();
|
||||
foreach ($object->fields as $key=>$data)
|
||||
{
|
||||
$tmp[$this->sep.$object->tableprefix.$object->table.$this->sep.".".
|
||||
$this->sep.$key.$this->sep] = $data;
|
||||
}
|
||||
if (!isset ($this->fieldsTmp))
|
||||
{
|
||||
$tmpThis = array ();
|
||||
foreach ($this->fields as $key=>$data)
|
||||
{
|
||||
$tmpThis[$this->sep.$this->tableprefix.$this->table.$this->sep.".".
|
||||
$this->sep.$key.$this->sep] = $data;
|
||||
}
|
||||
$this->fieldsTmp = $tmpThis;
|
||||
}
|
||||
$this->fieldsTmp = array_merge ($this->fieldsTmp, $tmp);
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -1575,7 +1595,12 @@ class dblayeroo
|
||||
$sql .= " ".$this->distinct;
|
||||
$displayColumns = implode (",", $this->displayColumn);
|
||||
if ($displayColumns === "")
|
||||
$displayColumns = "*";
|
||||
{
|
||||
if (isset ($this->fieldsTmp))
|
||||
$displayColumns = implode (",", array_keys ($this->fieldsTmp));
|
||||
else
|
||||
$displayColumns = "*";
|
||||
}
|
||||
$sql .= " $displayColumns FROM $this->sep$this->tableprefix".
|
||||
"$this->table$this->sep";
|
||||
if (! empty ($this->joins))
|
||||
@@ -2011,22 +2036,57 @@ class dblayeroo
|
||||
switch ($this->command)
|
||||
{
|
||||
case "SELECT":
|
||||
$result = $st->fetchAll (\PDO::FETCH_ASSOC);
|
||||
// Harmonize the fetchAll result between all the databases drivers
|
||||
foreach ($result as &$row)
|
||||
$result = $st->fetchAll (\PDO::FETCH_NUM);
|
||||
// There is no fetchAll corresponding to the columnName->value. Assign the
|
||||
// name to the value by index.
|
||||
// FETCH_ASSOC doesn't work in empty left join (return NULL instead of
|
||||
// the filled value)
|
||||
if (isset ($this->fieldsTmp))
|
||||
$columns = array_keys ($this->fieldsTmp);
|
||||
else
|
||||
$columns = array_keys ($this->fields);
|
||||
foreach ($result as $rownb=>$row)
|
||||
{
|
||||
foreach ($row as $col=>&$val)
|
||||
foreach ($row as $colNb=>$val)
|
||||
{
|
||||
// The fields defined with "integer" type are translated to PHP
|
||||
// integer type (Already done by PostgreSQL driver, but not by MySQL
|
||||
// and SQLite
|
||||
if (strtolower ($this->fields[$col][0]) === "integer")
|
||||
$val = intval ($val);
|
||||
// Harmonize the fetchAll result between all the databases drivers
|
||||
if (isset ($this->fieldsTmp))
|
||||
{
|
||||
if (strtolower ($this->fieldsTmp[$columns[$colNb]][0]) ===
|
||||
"integer")
|
||||
$val = intval ($val);
|
||||
}
|
||||
elseif (isset ($this->fields))
|
||||
{
|
||||
if (strtolower ($this->fields[$columns[$colNb]][0]) === "integer")
|
||||
$val = intval ($val);
|
||||
}
|
||||
$colName = str_replace ($this->sep, "", $columns[$colNb]);
|
||||
$result[$rownb][$colName] = $val;
|
||||
unset ($result[$rownb][$colNb]);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
case "INSERT":
|
||||
return self::$instance[$this->dsn]->lastInsertId ();
|
||||
// PostGres need the name of the column autoincrement to return something
|
||||
// If there is no autoincrement column, do not request the lastInsertId
|
||||
$autoInc = null;
|
||||
if ($this->driver === "pgsql")
|
||||
{
|
||||
foreach ($this->fields as $col=>$params)
|
||||
{
|
||||
if (in_array ("autoincrement", $params))
|
||||
{
|
||||
$autoInc = $col;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($autoInc !== null)
|
||||
$autoInc = $this->table."_${col}_seq";
|
||||
}
|
||||
$this->debugLog ("INSERT: lastInsertId=",
|
||||
self::$instance[$this->dsn]->lastInsertId ($autoInc));
|
||||
return self::$instance[$this->dsn]->lastInsertId ($autoInc);
|
||||
case "UPDATE":
|
||||
case "DELETE":
|
||||
return $st->rowCount ();
|
||||
|
||||
Reference in New Issue
Block a user