1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-06 06:07:39 +02:00

- fixed float numbers decimal separator vs. setlocale

This commit is contained in:
David Grudl
2008-10-02 09:01:38 +00:00
parent 44f281de27
commit fc69f8f47b
2 changed files with 21 additions and 6 deletions

View File

@@ -360,6 +360,21 @@ class dibi
/**
* Executes SQL query and fetch pairs - Monostate for DibiConnection::query() & fetchPairs().
*
* @param array|mixed one or more arguments
* @return string
* @throws DibiException
*/
public static function fetchPairs($args)
{
$args = func_get_args();
return self::getConnection()->query($args)->fetchPairs();
}
/**
* Gets the number of affected rows.
* Monostate for DibiConnection::affectedRows()

View File

@@ -293,18 +293,18 @@ final class DibiTranslator extends DibiObject
case 'i': // signed int
case 'u': // unsigned int, ignored
// support for numbers - keep them unchanged
// support for long numbers - keep them unchanged
if (is_string($value) && preg_match('#[+-]?\d+(e\d+)?$#A', $value)) {
return $value;
}
return (string) (int) ($value + 0);
case 'f': // float
// support for numbers - keep them unchanged
if (is_numeric($value) && (!is_string($value) || strpos($value, 'x') === FALSE)) {
return $value; // something like -9E-005 is accepted by SQL, HEX values is not
// support for extreme numbers - keep them unchanged
if (is_string($value) && is_numeric($value) && strpos($value, 'x') === FALSE) {
return $value; // something like -9E-005 is accepted by SQL, HEX values are not
}
return (string) ($value + 0);
return rtrim(rtrim(number_format($value, 5, '.', ''), '0'), '.');
case 'd': // date
case 't': // datetime
@@ -348,7 +348,7 @@ final class DibiTranslator extends DibiObject
return $this->driver->escape($value, dibi::FIELD_TEXT);
if (is_int($value) || is_float($value))
return (string) $value; // something like -9E-005 is accepted by SQL
return rtrim(rtrim(number_format($value, 5, '.', ''), '0'), '.');
if (is_bool($value))
return $this->driver->escape($value, dibi::FIELD_BOOL);