Edit report at https://bugs.php.net/bug.php?id=43203&edit=1
ID: 43203
Comment by: r dot wilczek at web-appz dot de
Reported by: lafriks at inbox dot lv
Summary: PDO better support for float bind values
Status: Open
Type: Feature/Change Request
Package: PDO related
PHP Version: 5.2.4
Block user comment: N
Private report: N
New Comment:
The missing PDO::PARAM_DOUBLE actually leads to very annoying problems.
SQLite considers a NUMERIC to be always less than a TEXT or REAL.
So string '1' is not less than double 1.1.
The following unparameterized statement shows this behaviour:
$rs = $sqlite->prepare('SELECT '1' < 1.1 as "result"');
$stmt->execute();
$rs = $stmt->fetch();
$stmt->closeCursor();
print_r($rs['result']); // 0 works as expected (and the same way as SQLite CLI.)
Now we try to perform the same operation using a parameterized statement:
$stmt = $sqlite->prepare('SELECT :left < :right as "result"');
Option A. Binding double as string:
$stmt->bindValue(':left', '1', PDO::PARAM_STR);
$stmt->bindValue(':right', 1.1, PDO::PARAM_STR);
$stmt->execute();
$rs = $stmt->fetch();
$stmt->closeCursor();
print_r($rs['result']); // 1 failure.
Option B. Binding double as integer:
$stmt->bindValue(':left', '1', PDO::PARAM_STR);
$stmt->bindValue(':right', 1.1, PDO::PARAM_INT);
$stmt->execute();
$rs = $stmt->fetch();
$stmt->closeCursor();
print_r($rs['result']); // 0 Seems to work, but ...
... this way we cannot tell double from integer. SQLite would consider
integer 1 to be less than double 1.1.
$stmt->bindValue(':left', 1, PDO::PARAM_INT);
$stmt->bindValue(':right', 1.1, PDO::PARAM_INT);
$stmt->execute();
$rs = $stmt->fetch();
$stmt->closeCursor();
print_r($rs['result']); // 0 Failure
So there is no way with PDO to correctly parameterize double values.
I request to provide PDO::PARAM_DOUBLE.
Previous Comments:
------------------------------------------------------------------------
[2007-11-06 09:22:33] lafriks at inbox dot lv
Description:
------------
It would be way easier to work with PDO if there was PDO::PARAM_FLOAT.
Otherwise there is always need to check for comma and point if in different
locales and that just makes it unnecessary hard to work with float numbers and
binding to prepared statements.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=43203&edit=1