dblayeroo : Add FLOAT support

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4655 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2018-10-29 12:53:09 +00:00
parent f490507966
commit fc56c52628

View File

@@ -361,6 +361,10 @@ class dblayeroo
$sql .= "DATE";
$params = array_slice ($params, 1);
break;
case "float":
$sql .= "FLOAT";
$params = array_slice ($params, 1);
break;
case "integer":
$sql .= "INTEGER";
$params = array_slice ($params, 1);
@@ -460,6 +464,10 @@ class dblayeroo
$sql .= "VARCHAR($length)";
$params = array_slice ($params, 1);
break;
case "float":
$sql .= "FLOAT";
$params = array_slice ($params, 1);
break;
case "datetime":
$sql .= "DATETIME";
$params = array_slice ($params, 1);
@@ -565,14 +573,18 @@ class dblayeroo
$sql .= "VARCHAR($length)";
$params = array_slice ($params, 1);
break;
case "float":
$sql .= "FLOAT";
$params = array_slice ($params, 1);
break;
case "datetime":
$sql .= "timestamp with time zone";
$params = array_slice ($params, 1);
break;
case "date":
$sql .= "DATE";
$params = array_slice ($params, 1);
break;
case "date":
$sql .= "DATE";
$params = array_slice ($params, 1);
break;
default:
$this->DBException (sprintf (
dgettext("domframework",
@@ -1053,7 +1065,7 @@ class dblayeroo
if (! array_key_exists (0, $params))
$this->DBException ("Parameter fields invalid: ".
"No type of column provided for '$field'");
if (preg_match ("#^(date|datetime|integer|time|".
if (preg_match ("#^(date|datetime|float|integer|time|".
"varchar\(\d+\))$#i",
$params[0]) !== 1)
$this->DBException ("Parameter fields invalid: ".
@@ -1987,9 +1999,10 @@ class dblayeroo
$this->DBException ("Invalid field provided (not string)");
if (! is_string ($operator))
$this->DBException ("Invalid operator provided (not string)");
if (! is_string ($value) && ! is_null ($value) && ! is_integer ($value))
if (! is_string ($value) && ! is_null ($value) &&
! is_integer ($value) && ! is_float ($value))
$this->DBException ("Invalid value provided (not string nor null ".
"nor integer)");
"nor integer not float)");
if (! array_key_exists ($field, $this->fields))
$this->DBException (sprintf (
"Invalid field to whereAdd '%s' : not defined in table", $field));
@@ -2352,9 +2365,10 @@ class dblayeroo
if (! array_key_exists ($key, $this->fields))
$this->DBException (sprintf (
"Invalid field to setValues '%s' : not defined in table", $key));
if (! is_string ($val) && ! is_int ($val) && ! is_null ($val))
if (! is_string ($val) && ! is_int ($val) && ! is_null ($val) &&
! is_float ($val))
$this->DBException (sprintf (
"Invalid field to setValues '%s': not string and not integer", $key));
"Invalid field to setValues '%s': not string and not numeric", $key));
$tmpValues[$key] = $val;
$tmpType[md5 ("$key, $val")] = $this->fieldTypeLight ($key);
$this->debugLog ("setValues : Type for $key = ".
@@ -2516,6 +2530,7 @@ class dblayeroo
$text .= "DEBUG BIND WHERE : $hash ($field)->$value ";
if ($value === null) $text .= "NULL (null)\n";
elseif ($type === "integer") $text .= "(integer)\n";
elseif ($type === "float") $text .= "(float)\n";
elseif ($type === "varchar") $text .= "(varchar)\n";
elseif ($type === "datetime") $text .= "(datetime)\n";
elseif ($type === "date") $text .= "(date)\n";
@@ -2530,6 +2545,8 @@ class dblayeroo
$st->bindValue (":$hash", $value, \PDO::PARAM_NULL);
elseif ($type === "integer")
$st->bindValue (":$hash", $value, \PDO::PARAM_INT);
elseif ($type === "float")
$st->bindValue (":$hash", $value, \PDO::PARAM_STR);
elseif ($type === "varchar")
$st->bindValue (":$hash", "$value", \PDO::PARAM_STR);
elseif ($type === "datetime")
@@ -2551,6 +2568,7 @@ class dblayeroo
$text .= "DEBUG BIND SET : $hash ($field)->$value ";
if ($value === null) $text .= "NULL (null)\n";
elseif ($type === "integer") $text .= "(integer)\n";
elseif ($type === "float") $text .= "(float)\n";
elseif ($type === "varchar") $text .= "(varchar)\n";
elseif ($type === "datetime") $text .= "(datetime)\n";
elseif ($type === "date") $text .= "(date)\n";
@@ -2565,6 +2583,8 @@ class dblayeroo
$st->bindValue (":$hash", $value, \PDO::PARAM_NULL);
elseif ($this->setType[$hash] === "integer")
$st->bindValue (":$hash", $value, \PDO::PARAM_INT);
elseif ($this->setType[$hash] === "float")
$st->bindValue (":$hash", "$value", \PDO::PARAM_STR);
elseif ($this->setType[$hash] === "varchar")
$st->bindValue (":$hash", "$value", \PDO::PARAM_STR);
elseif ($this->setType[$hash] === "datetime")
@@ -2687,9 +2707,9 @@ class dblayeroo
continue;
}
if (! is_string ($values[$field]) && ! is_integer ($values[$field]) &&
! is_null ($values[$field]))
! is_null ($values[$field]) && ! is_float ($values[$field]))
$errors[$field] = dgettext ("domframework",
"Field not a string nor a integer");
"Field not a string nor numeric");
// Do not check the format if the value to store is null. It will never
// matche any format.
if ($values[$field] === null)
@@ -2701,6 +2721,12 @@ class dblayeroo
$errors[$field] = dgettext ("domframework",
"Field not in integer format");
break;
case "float":
if (strspn ($values[$field], "0123456789.") !==
strlen ($values[$field]))
$errors[$field] = dgettext ("domframework",
"Field not in float format");
break;
case "varchar":
$length = $this->fieldLength ($field);
if (mb_strlen ($values[$field]) > $length)