From: Ilia Alshanetsky Date: Tue, 26 Jun 2007 01:24:10 +0000 (+0000) Subject: Fixed bug #41698 (float parameters truncated to integer in prepared X-Git-Tag: php-5.2.4RC1~292 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dc1c6f74c8a5ba8c3ca9f2579cea23a989c92742;p=php Fixed bug #41698 (float parameters truncated to integer in prepared statements). --- diff --git a/NEWS b/NEWS index a8496037ae..499a01e493 100644 --- a/NEWS +++ b/NEWS @@ -45,6 +45,8 @@ PHP NEWS - Fixed bug #41717 (imagepolygon does not respect thickness). (Pierre) - Fixed bug #41711 (NULL temporary lobs not supported in OCI8). (Chris Jones, Tony) +- Fixed bug #41698 (float parameters truncated to integer in prepared + statements). (Ilia) - Fixed bug #41686 (Omitting length param in array_slice not possible). (Ilia) - Fixed bug #41685 (array_push() fails to warn when next index is already diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index 90f3b023b3..87b972449c 100755 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -280,7 +280,13 @@ static int really_register_bound_param(struct pdo_bound_param_data *param, pdo_s } if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_STR && param->max_value_len <= 0 && ! ZVAL_IS_NULL(param->parameter)) { - convert_to_string(param->parameter); + if (Z_TYPE_P(param->parameter) == IS_DOUBLE) { + char *p; + int len = spprintf(&p, 0, "%F", Z_DVAL_P(param->parameter)); + ZVAL_STRINGL(param->parameter, p, len, 0); + } else { + convert_to_string(param->parameter); + } } else if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_INT && Z_TYPE_P(param->parameter) == IS_BOOL) { convert_to_long(param->parameter); } else if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_BOOL && Z_TYPE_P(param->parameter) == IS_LONG) { diff --git a/ext/pdo_mysql/tests/bug_41698.phpt b/ext/pdo_mysql/tests/bug_41698.phpt new file mode 100644 index 0000000000..b2dee60d74 --- /dev/null +++ b/ext/pdo_mysql/tests/bug_41698.phpt @@ -0,0 +1,37 @@ +--TEST-- +PDO MySQL Bug #41698 (float parameters truncated to integer in prepared statements) +--SKIPIF-- + +--FILE-- +exec('CREATE TABLE test(floatval DECIMAL(8,6))'); +$db->exec('INSERT INTO test VALUES(2.34)'); +$value=4.56; +$stmt = $db->prepare('INSERT INTO test VALUES(?)'); +$stmt->execute(array($value)); +var_dump($db->query('SELECT * from test')->fetchAll(PDO::FETCH_ASSOC)); +?> +--EXPECT-- +array(2) { + [0]=> + array(1) { + ["floatval"]=> + string(8) "2.340000" + } + [1]=> + array(1) { + ["floatval"]=> + string(8) "4.560000" + } +} \ No newline at end of file