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 (