dblayeroo: Accept only one setValues

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3481 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2017-03-29 12:40:30 +00:00
parent 7845dbfe70
commit 3f44445ede

View File

@@ -1525,10 +1525,8 @@ class dblayeroo
}
/** Set INSERT/UPDATE values
* - If the provided array is a associative array, the field name must be
* - The provided array must be an associative array, the field name must be
* provided as key and the value as value. Each field=>val will be updated
* - It the provided array is a numeric array, it must be 2 long. The first
* is the field name, and the second the value
* @param array $values The values to INSERT or UPDATE
*/
public function setValues ($values)
@@ -1539,38 +1537,15 @@ class dblayeroo
$associative = null;
$tmpValues = array ();
$tmpType = array ();
$tmpField = array ();
foreach ($values as $key=>$val)
{
if ($associative === null)
{
if ($key === 0)
$associative = false;
elseif (is_string ($key) && strlen (trim ($key)) !== 0)
$associative = true;
}
elseif ($associative === false &&
is_string ($key) && strlen (trim ($key)) !== 0)
$this->DBException ("Invalid values to setValues : mixed array");
elseif ($associative === true && is_int ($key))
$this->DBException ("Invalid values to setValues : mixed array");
if ($associative === true)
{
if (! array_key_exists ($key, $this->fields))
$this->DBException (sprintf (
"Invalid field to setValues '%s' : not defined in table", $key));
$tmpValues[$key] = $val;
$tmpField[md5 ("$key, $val")] = $key;
$tmpType[md5 ("$key, $val")] = $this->fieldTypeLight ($key);
$this->debugLog ("setValues : Type for $key = ".
$this->fieldTypeLight ($key));
}
else
{
$values = array_values ($values);
$tmpValues[$values[0]] = $values[1];
}
if (! array_key_exists ($key, $this->fields))
$this->DBException (sprintf (
"Invalid field to setValues '%s' : not defined in table", $key));
$tmpValues[$key] = $val;
$tmpType[md5 ("$key, $val")] = $this->fieldTypeLight ($key);
$this->debugLog ("setValues : Type for $key = ".
$this->fieldTypeLight ($key));
}
$this->setValues = $tmpValues;
$this->setType = $tmpType;