dblayeroo : when testing the UNIQUE constraints, do not generate an exception if the value already exists in the table, return the error with the associated column name.
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4634 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -2837,8 +2837,21 @@ class dblayeroo
|
||||
$resUpdate[0][$this->primary]);
|
||||
}
|
||||
if (count ($errors) == 0 && count ($objTmp->execute ()))
|
||||
$this->DBException (dgettext ("domframework",
|
||||
"An entry with these values already exists"), 406);
|
||||
{
|
||||
if (is_array ($columns))
|
||||
{
|
||||
foreach ($columns as $column)
|
||||
{
|
||||
$errors[$column] = dgettext ("domframework",
|
||||
"An entry with this value already exists");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$errors[$columns] = dgettext ("domframework",
|
||||
"An entry with this value already exists");
|
||||
}
|
||||
}
|
||||
unset ($objTmp);
|
||||
}
|
||||
|
||||
@@ -2902,19 +2915,24 @@ class dblayeroo
|
||||
/** Check the values before doing really the modification of the database
|
||||
* @param boolean|null $update if true UPDATE request, else INSERT request
|
||||
*/
|
||||
public function checkValues ($update = false)
|
||||
public function checkValues ($values, $update = false)
|
||||
/* {{{ */
|
||||
{
|
||||
$this->debugLog ("Entering checkValues (",$update,")");
|
||||
if (! is_array ($values))
|
||||
{
|
||||
$this->DBException ("checkValues fields : ".
|
||||
"values provided are not an array", 406);
|
||||
}
|
||||
$update = !! $update;
|
||||
$values = $this->setValues;
|
||||
$errors = $this->checkRealTypes ($values, $update);
|
||||
if (count ($errors))
|
||||
$this->DBException (reset ($errors), 406);
|
||||
$errors = $this->verify ($values, $update);
|
||||
if (count ($errors))
|
||||
$this->DBException (reset ($errors), 406);
|
||||
$this->debugLog ("End of checkValues (",$update,") : Nothing in error");
|
||||
$errors = array_merge ($this->checkRealTypes ($values, $update),
|
||||
$this->verify ($values, $update));
|
||||
if (count ($errors) === 0)
|
||||
$this->debugLog ("End of checkValues (",$update,") : Nothing in error");
|
||||
else
|
||||
$this->debugLog ("End of checkValues (",$update,") : ".count ($errors).
|
||||
"errors");
|
||||
return $errors;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@@ -2988,10 +3006,20 @@ class dblayeroo
|
||||
case "SELECT":
|
||||
break;
|
||||
case "INSERT":
|
||||
$this->checkValues (false);
|
||||
$errors = $this->checkValues ($this->setValues, false);
|
||||
if (count ($errors))
|
||||
{
|
||||
$val = reset ($errors);
|
||||
$this->DBException (key ($errors)." : $val", 406);
|
||||
}
|
||||
break;
|
||||
case "UPDATE":
|
||||
$this->checkValues (true);
|
||||
$errors = $this->checkValues ($this->setValues, true);
|
||||
if (count ($errors))
|
||||
{
|
||||
$val = reset ($errors);
|
||||
$this->DBException (key ($errors)." : $val", 406);
|
||||
}
|
||||
break;
|
||||
case "DELETE":
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user