dblayeroo: Update of multiple not unique fields should not be an exception
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3825 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -2539,36 +2539,48 @@ class dblayeroo
|
||||
if (! in_array ($this->primary, $uniques))
|
||||
$uniques = array_merge (array ($this->primary), $uniques);
|
||||
$setValues = $values;
|
||||
if (! array_key_exists ($this->primary, $setValues))
|
||||
$setValues[$this->primary] = null;
|
||||
$foundImpactedColumns = 0;
|
||||
foreach ($uniques as $k=>$columns)
|
||||
{
|
||||
if ($update !== false && ! isset ($resUpdate))
|
||||
if ($update)
|
||||
{
|
||||
// Can not update multiple UNIQUE rows with the same value
|
||||
$this->debugLog ("CLONE because of update");
|
||||
$objTmp = clone $this;
|
||||
$objTmp->debugDepth++;
|
||||
$objTmp->clearRequest ();
|
||||
$objTmp->Select ();
|
||||
$objTmp->displayAdd ($this->primary);
|
||||
$objTmp->displayAdd ($columns);
|
||||
$objTmp->whereValues = $this->whereValues;
|
||||
$objTmp->whereExpression = $this->whereExpression;
|
||||
$objTmp->limitLines (3);
|
||||
$resUpdate = $objTmp->execute ();
|
||||
unset ($objTmp);
|
||||
/* if (count ($resUpdate) > 1)
|
||||
$this->DBException (sprintf (dgettext ("domframework",
|
||||
"Can't update multiple rows with unique value"), $columns));
|
||||
*/
|
||||
if (count ($resUpdate) === 0)
|
||||
$cols = explode (",", $columns);
|
||||
foreach ($cols as $col)
|
||||
{
|
||||
if (!key_exists ($col, $setValues))
|
||||
continue;
|
||||
// One column to set is a unique column : check if the where clause
|
||||
// is filtering more than one entry. If there is more than one
|
||||
// entry, generate an exception
|
||||
$this->debugLog ("CLONE because of update");
|
||||
$objTmp = clone $this;
|
||||
$objTmp->debugDepth++;
|
||||
$objTmp->clearRequest ();
|
||||
$objTmp->Select ();
|
||||
$objTmp->displayAdd ($this->primary);
|
||||
$objTmp->displayAdd ($columns);
|
||||
$objTmp->whereValues = $this->whereValues;
|
||||
$objTmp->whereExpression = $this->whereExpression;
|
||||
$objTmp->limitLines (3);
|
||||
$resUpdate = $objTmp->execute ();
|
||||
unset ($objTmp);
|
||||
if (count ($resUpdate) > 1)
|
||||
$this->DBException (sprintf (dgettext ("domframework",
|
||||
"Can't update multiple rows with unique value on col '%s'"),
|
||||
$col));
|
||||
elseif (count ($resUpdate) === 1)
|
||||
$foundImpactedColumns++;
|
||||
}
|
||||
if ($foundImpactedColumns === 0)
|
||||
{
|
||||
// There is no row available with the WHERE clause provided
|
||||
// Skip all the UNIQUE tests as there will not have any modification
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! array_key_exists ($this->primary, $setValues))
|
||||
$setValues[$this->primary] = null;
|
||||
|
||||
$this->debugLog ("CLONE to check primary and unique constraint");
|
||||
$objTmp = clone $this;
|
||||
|
||||
Reference in New Issue
Block a user