From c5c033dc059b1c293779ff224023d51edb26dead Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Sun, 7 Mar 2010 07:53:15 +0000 Subject: #728730 by Damien Tournoud: Fixed Precision loss in DatabaseStatement_sqlite()::getStatement(). --- includes/database/sqlite/database.inc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'includes/database/sqlite') diff --git a/includes/database/sqlite/database.inc b/includes/database/sqlite/database.inc index 5889fafe7..dbfb4ef95 100644 --- a/includes/database/sqlite/database.inc +++ b/includes/database/sqlite/database.inc @@ -216,7 +216,12 @@ class DatabaseStatement_sqlite extends DatabaseStatementPrefetch implements Iter $count = 0; $new_args = array(); foreach ($args as $value) { - if (is_numeric($value)) { + if (is_float($value) || is_int($value)) { + if (is_float($value)) { + // Force the conversion to float so as not to loose precision + // in the automatic cast. + $value = sprintf('%F', $value); + } $query = substr_replace($query, $value, strpos($query, '?'), 1); } else { @@ -231,7 +236,13 @@ class DatabaseStatement_sqlite extends DatabaseStatementPrefetch implements Iter // Else, this is using named placeholders. foreach ($args as $placeholder => $value) { if (is_float($value) || is_int($value)) { - // We will remove this placeholder from the query and PDO throws an + if (is_float($value)) { + // Force the conversion to float so as not to loose precision + // in the automatic cast. + $value = sprintf('%F', $value); + } + + // We will remove this placeholder from the query as PDO throws an // exception if the number of placeholders in the query and the // arguments does not match. unset($args[$placeholder]); -- cgit v1.2.3