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
This commit is contained in:
2014-10-02 13:57:19 +00:00
parent 0b08bfa5de
commit 153c58a39c

View File

@@ -398,16 +398,13 @@ class dblayer extends PDO
} }
// If there is only the primary key, there is no chance to have a // If there is only the primary key, there is no chance to have a
// conflict // 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)); $errors[] = array ("error", dgettext("domframework",
if (count ($rc) > 0) "An entry with these values already exists"));
{ continue;
$errors[] = array ("error", sprintf (dgettext("domframework",
"The provided values for columns '%s' already exists"),
implode (",", $columns)));
continue;
}
} }
} }
else else
@@ -426,9 +423,8 @@ class dblayer extends PDO
array ($this->primary)); array ($this->primary));
if (count ($rc) > 0) if (count ($rc) > 0)
{ {
$errors[] = array ("error", sprintf (dgettext("domframework", $errors[] = array ("error", dgettext("domframework",
"The column '%s' with this value already exists"), "An entry with this value already exists"));
$columns));
continue; continue;
} }
} }
@@ -452,8 +448,8 @@ class dblayer extends PDO
if (! isset ($datas[$foreign][0])) if (! isset ($datas[$foreign][0]))
{ {
$errors[] = array ("error", sprintf (dgettext("domframework", $errors[] = array ("error", sprintf (dgettext("domframework",
"The field type for column '%s' is not provided"), "The field type for column '%s' is not provided"),
$foreign)); $foreign));
return $errors; return $errors;
continue; continue;
} }