From bd575e67ed710ff9e032591feb519ecec3da03c7 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Sun, 23 Mar 2014 19:09:42 +0000 Subject: [PATCH] A little bug : if we don't modify the uniq columns, no need to check if there is a constrain violation git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1239 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- dblayer.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/dblayer.php b/dblayer.php index e88a233..fa4926f 100644 --- a/dblayer.php +++ b/dblayer.php @@ -246,21 +246,29 @@ class dblayer extends PDO if (is_array ($columns)) { $select = array (); + $select[] = array ($this->primary, $updatekey, "!="); foreach ($columns as $col) { if (!array_key_exists ($col, $datasOK)) continue; $select[] = array ($col, $datasOK[$col]); } - $rc = $this->read ($select, array ($this->primary)); - if (count ($rc) > 0) - throw new Exception (sprintf ( + + // If there is only the primary key, there is no chance to have a + // conflict + if (count ($select) >= 2) + { + $rc = $this->read ($select, array ($this->primary)); + if (count ($rc) > 0) + throw new Exception (sprintf ( _("The provided value for columns '%s' already exists"), implode (",", $columns)), 405); + } } else { if (!array_key_exists ($columns, $datasOK)) continue; - $rc = $this->read (array (array ($columns, $datasOK[$columns])), + $rc = $this->read (array (array ($columns, $datasOK[$columns]), + array ($this->primary, $updatekey, "!=")), array ($this->primary)); if (count ($rc) > 0) throw new Exception (sprintf (