dblayer : correct tue verify in updates : must pass the key

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1838 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2014-09-19 11:07:29 +00:00
parent e81452a782
commit 02bc20dd5d

View File

@@ -202,11 +202,10 @@ class dblayer extends PDO
*/
public function verify ($datas, $updatekey=false)
{
// TODO : See if the edited key is needed in UPDATE mode
$errors = array ();
foreach ($this->fields as $key=>$params)
{
if ($updatekey !== false)
if ($updatekey === false)
{
// Don't check if there is an update : the database is already filled
if (in_array ("not null", $params) && !array_key_exists ($key, $datas))
@@ -370,14 +369,14 @@ class dblayer extends PDO
else
{
// One column in unique
if (!array_key_exists ($columns, $datasOK)) continue;
if (!array_key_exists ($columns, $after)) continue;
$select = array ();
if ($updatekey !== false)
{
if ($columns === $this->primary)
$select[] = array ($this->primary, $updatekey, "!=");
}
$select[] = array ($columns, $datasOK[$columns]);
$select[] = array ($columns, $after[$columns]);
$rc = $this->read ($select,
array ($this->primary));
if (count ($rc) > 0)
@@ -647,9 +646,12 @@ class dblayer extends PDO
if ($this->primary === null)
throw new Exception (dgettext("domframework", "No Primary defined"), 500);
$datasOK = array ();
$errors = $this->verify ($datas);
$errors = $this->verify ($datas, $updatekey);
if (count ($errors) !== 0)
throw new Exception (reset ($errors), 405);
{
$errors = reset ($errors);
throw new Exception ($errors[1], 405);
}
foreach ($this->fields as $field=>$desc)
{
if (isset ($datas[$field]))