From 5449ecc27afeeebccad1e867258106eb1ef70217 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Wed, 21 May 2014 20:01:24 +0000 Subject: [PATCH] Skip the primary key in update tests if it is provided git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1331 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- dblayer.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/dblayer.php b/dblayer.php index f5df20b..e52c0b1 100644 --- a/dblayer.php +++ b/dblayer.php @@ -28,6 +28,8 @@ Optionnaly, you can add the - protected $debug = TRUE : enable the debug on screen (NOT FOR PROD !!) */ +require_once ("domframework/verify.php"); + /** Permit abstraction on the differents SQL databases available */ class dblayer extends PDO { @@ -269,21 +271,21 @@ class dblayer extends PDO // Check for missing parameters foreach ($this->fields as $key=>$params) { - // Check for type inconsistancies before create $datasOK - if (in_array ("autoincrement", $params)) - $datas[$key] = null; - if (in_array ("not null", $params) && !array_key_exists ($key, $datas)) - throw new Exception ("Mandatory field '$key' not provided", 405); // Verify the fields, if $verify is defined, before doing insertion - $verify = $this->verifyOne ($key, $datas[$key]); - if (is_array ($verify) && count ($verify)) - throw new Exception ($verify[0]." ".$verify[1]." in ".$key); if (array_key_exists ($key, $datas)) $datasOK[$key] = $datas[$key]; } if (count ($datasOK) === 0) throw new Exception (_("Don't receive any field to display"), 501); + // Check for type inconsistancies before using $datasOK + foreach ($datasOK as $key=>$params) + { + $verify = $this->verifyOne ($key, $datas[$key]); + if (is_array ($verify) && count ($verify)) + throw new Exception ($verify[0]." ".$verify[1]." in ".$key); + } + // Check if the unique constrain is valid before doing the insertion // 1. Read the actual state $before = $this->read (array (array ($this->primary, $updatekey))); @@ -320,7 +322,7 @@ class dblayer extends PDO } else { - if (!array_key_exists ($columns, $datasOK)) continue; + if (array_key_exists ($columns, $datasOK)) continue; $select = array (); if ($columns !== $this->primary) $select[] = array ($this->primary, $updatekey, "!=");