From 153c58a39c7b134e13c919391bb4eea09fff14a7 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Thu, 2 Oct 2014 13:57:19 +0000 Subject: [PATCH] dblayer : Check before update if multiple unique keys are not used before doing the update git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1858 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- dblayer.php | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/dblayer.php b/dblayer.php index 88043d4..032e24a 100644 --- a/dblayer.php +++ b/dblayer.php @@ -398,16 +398,13 @@ class dblayer extends PDO } // If there is only the primary key, there is no chance to have a // conflict - if ($updatekey === false && count ($select) >= 2) + // Before updating, check if the new values are not creating an error + $rc = $this->read ($select, array ($this->primary)); + if (count ($rc) > 0) { - $rc = $this->read ($select, array ($this->primary)); - if (count ($rc) > 0) - { - $errors[] = array ("error", sprintf (dgettext("domframework", - "The provided values for columns '%s' already exists"), - implode (",", $columns))); - continue; - } + $errors[] = array ("error", dgettext("domframework", + "An entry with these values already exists")); + continue; } } else @@ -426,9 +423,8 @@ class dblayer extends PDO array ($this->primary)); if (count ($rc) > 0) { - $errors[] = array ("error", sprintf (dgettext("domframework", - "The column '%s' with this value already exists"), - $columns)); + $errors[] = array ("error", dgettext("domframework", + "An entry with this value already exists")); continue; } } @@ -452,8 +448,8 @@ class dblayer extends PDO if (! isset ($datas[$foreign][0])) { $errors[] = array ("error", sprintf (dgettext("domframework", - "The field type for column '%s' is not provided"), - $foreign)); + "The field type for column '%s' is not provided"), + $foreign)); return $errors; continue; }