diff --git a/dblayeroo.php b/dblayeroo.php index 8786935..4ec3370 100644 --- a/dblayeroo.php +++ b/dblayeroo.php @@ -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;