From fc69f8f47b01f27aacd32812a104b710934e3fa5 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 2 Oct 2008 09:01:38 +0000 Subject: [PATCH] - fixed float numbers decimal separator vs. setlocale --- dibi/dibi.php | 15 +++++++++++++++ dibi/libs/DibiTranslator.php | 12 ++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/dibi/dibi.php b/dibi/dibi.php index f7b89658..f9788b19 100644 --- a/dibi/dibi.php +++ b/dibi/dibi.php @@ -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() diff --git a/dibi/libs/DibiTranslator.php b/dibi/libs/DibiTranslator.php index dacf6390..91d9fcc8 100644 --- a/dibi/libs/DibiTranslator.php +++ b/dibi/libs/DibiTranslator.php @@ -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);