From 02bc20dd5da402eda13aff9e25fa6c50f11e852d Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Fri, 19 Sep 2014 11:07:29 +0000 Subject: [PATCH] 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 --- dblayer.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/dblayer.php b/dblayer.php index bc4b774..69a1ae6 100644 --- a/dblayer.php +++ b/dblayer.php @@ -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]))