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]);
|
$resUpdate[0][$this->primary]);
|
||||||
}
|
}
|
||||||
if (count ($errors) == 0 && count ($objTmp->execute ()))
|
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);
|
unset ($objTmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2902,19 +2915,24 @@ class dblayeroo
|
|||||||
/** Check the values before doing really the modification of the database
|
/** Check the values before doing really the modification of the database
|
||||||
* @param boolean|null $update if true UPDATE request, else INSERT request
|
* @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,")");
|
$this->debugLog ("Entering checkValues (",$update,")");
|
||||||
|
if (! is_array ($values))
|
||||||
|
{
|
||||||
|
$this->DBException ("checkValues fields : ".
|
||||||
|
"values provided are not an array", 406);
|
||||||
|
}
|
||||||
$update = !! $update;
|
$update = !! $update;
|
||||||
$values = $this->setValues;
|
$errors = array_merge ($this->checkRealTypes ($values, $update),
|
||||||
$errors = $this->checkRealTypes ($values, $update);
|
$this->verify ($values, $update));
|
||||||
if (count ($errors))
|
if (count ($errors) === 0)
|
||||||
$this->DBException (reset ($errors), 406);
|
$this->debugLog ("End of checkValues (",$update,") : Nothing in error");
|
||||||
$errors = $this->verify ($values, $update);
|
else
|
||||||
if (count ($errors))
|
$this->debugLog ("End of checkValues (",$update,") : ".count ($errors).
|
||||||
$this->DBException (reset ($errors), 406);
|
"errors");
|
||||||
$this->debugLog ("End of checkValues (",$update,") : Nothing in error");
|
return $errors;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@@ -2988,10 +3006,20 @@ class dblayeroo
|
|||||||
case "SELECT":
|
case "SELECT":
|
||||||
break;
|
break;
|
||||||
case "INSERT":
|
case "INSERT":
|
||||||
$this->checkValues (false);
|
$errors = $this->checkValues ($this->setValues, false);
|
||||||
|
if (count ($errors))
|
||||||
|
{
|
||||||
|
$val = reset ($errors);
|
||||||
|
$this->DBException (key ($errors)." : $val", 406);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "UPDATE":
|
case "UPDATE":
|
||||||
$this->checkValues (true);
|
$errors = $this->checkValues ($this->setValues, true);
|
||||||
|
if (count ($errors))
|
||||||
|
{
|
||||||
|
$val = reset ($errors);
|
||||||
|
$this->DBException (key ($errors)." : $val", 406);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "DELETE":
|
case "DELETE":
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user