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
This commit is contained in:
20
dblayer.php
20
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, "!=");
|
||||
|
||||
Reference in New Issue
Block a user